Difference between revisions of "Calico: Getting Started"

From IPRE Wiki
Jump to: navigation, search
(Starting)
(Keyboard Commands)
Line 88: Line 88:
 
== Keyboard Commands ==
 
== Keyboard Commands ==
  
Shell shortcuts:
+
=== Shell ===
 +
 
 +
General shortcuts in the shell:
  
 
* Control + Enter: newline (does not evaluate)
 
* Control + Enter: newline (does not evaluate)
Line 102: Line 104:
 
* Stop processing: Escape key
 
* Stop processing: Escape key
  
Editor shortcuts:
+
Selection shortcuts in the shell:
 +
 
 +
* Select: Shift + arrow keys; Shift + Control + arrow keys; left-click and mouse drag; double-, triple- left-mouse click
 +
* Select all: Control + A
 +
* Block select: Control + Alt + mouse drag
 +
 
 +
Movement shortcuts in the shell:
 +
 
 +
* Move by word: Control + arrow keys
 +
* To top: control + Home
 +
* to bottom: control + end
 +
* Beginning of line: home
 +
* End of line: end
 +
 
 +
=== Editor ===
 +
 
 +
General shortcuts in the editor:
  
 
* F5: evaluate highlighted text, or the entire file if nothing highlighted
 
* F5: evaluate highlighted text, or the entire file if nothing highlighted
Line 119: Line 137:
 
* Indent a line: go to begging of line, press Tab key
 
* Indent a line: go to begging of line, press Tab key
  
Searching Shortcuts in the Editor:
+
Searching Shortcuts in the editor:
  
 
* Control + F: bring up search bar
 
* Control + F: bring up search bar
Line 128: Line 146:
 
* Escape: close search bar
 
* Escape: close search bar
  
Selection shortcuts:
+
Selection shortcuts in the editor:
  
 
* Select: Shift + arrow keys; Shift + Control + arrow keys; left-click and mouse drag; double-, triple- left-mouse click
 
* Select: Shift + arrow keys; Shift + Control + arrow keys; left-click and mouse drag; double-, triple- left-mouse click
Line 134: Line 152:
 
* Block select: Control + Alt + mouse drag
 
* Block select: Control + Alt + mouse drag
  
Movement shortcuts:
+
Movement shortcuts in the editor:
  
 
* Move by word: Control + arrow keys
 
* Move by word: Control + arrow keys

Revision as of 17:47, 24 August 2011

Getting started with Calico. This document describes how to begin using the Calico scripting environment.

Overview

Calico is an environment for scripting. It is composed of three main components:

  • Scripting Languages (like Ruby, Python and Scheme)
  • Scripting Editor
  • Libraries for doing things (like robotics and graphics)

Calico is designed so that you can swap out any component, and the other two components can remain the same.

First, you should have already installed Calico at the Calico Download page.

Starting

You can start Calico up by running the ./StartCalico (Linux and Mac OSX) and StartCalico.bat (Windows).

You can pass a number of "flags" to Calico. Here we pass the --help flag to see what all of the options are:

C:\Users\dblank\Calico>StartCalico.bat --help

Calico Project, Version 0.6.4, on Unix 2.6.38.11
  Using Mono runtime version 2.6.7 (Debian 2.6.7-5ubuntu3)
----------------------------------------------------------------------------
Start calico with the following options:
  StartCalico                            Defaults to shell
  StartCalico FILENAME:LINE ...          Edits FILENAMEs, positioned on LINEs
  StartCalico --shell                    Brings up shell window
  StartCalico --editor                   Brings up editor window
  StartCalico --lang=LANGUAGE            Sets default language (python, etc.)
  StartCalico --chat                     Brings up chat window
  StartCalico --exec FILENAMEs           Run FILENAMEs standalone with graphics
  StartCalico --exec --nogui FILENAMEs   Run FILENAMEs standalone no graphics
  StartCalico --version                  Displays the version number (0.6.4)
  StartCalico --help                     Displays this message
  StartCalico --debug                    Puts Calico in debugging mode

Examples

To edit a program:

StartCalico myprog.rb

To edit a program, starting on line 200:

StartCalico myprog.rb:200

To edit a bunch of programs:

StartCalico *.py

To run a program:

StartCalico --exec myprog.rb

To run a program that takes care of its own graphics:

StartCalico --exec --nogui myprog.rb

To open up the editor and shell:

StartCalico --editor --shell

This page provides some examples of using Calico.

Calico GUI

Calico-ShellEditor.gif

Calico is divided into two windows:

  1. Editor
  2. Shell and Output


The Editor allows you to edit files. From the editor, you can select a section of code and press F5 to run part of your script interactively. If you don't have anything high-lighted, pressing F5 will run the entire file.

In the interactive command box, you can enter as much code as you like, ENTER will evaluate the code in the box (you may have to press ENTER twice, if you have a multi-line expression).

Example Code

See http://svn.cs.brynmawr.edu/viewvc/Calico/trunk/examples/

Keyboard Commands

Shell

General shortcuts in the shell:

  • Control + Enter: newline (does not evaluate)
  • TAB: after some text will do command completion
  • Up arrow: previous command
  • Down arrow: next command:
  • F5: evaluate the text in the command entry box
  • Block select: Control + Alt + mouse drag
  • Run the script in the command area, if a one-liner: Return key
  • Run the script in the command area, if a multi-liner: Return key on line with only white-space
  • Enter a blank line in command area: Enter key
  • Drag text to command area, then F5
  • Stop processing: Escape key

Selection shortcuts in the shell:

  • Select: Shift + arrow keys; Shift + Control + arrow keys; left-click and mouse drag; double-, triple- left-mouse click
  • Select all: Control + A
  • Block select: Control + Alt + mouse drag

Movement shortcuts in the shell:

  • Move by word: Control + arrow keys
  • To top: control + Home
  • to bottom: control + end
  • Beginning of line: home
  • End of line: end

Editor

General shortcuts in the editor:

  • F5: evaluate highlighted text, or the entire file if nothing highlighted
  • Zoom in: Control + mouse wheel forwards
  • Zoom out: Control + mouse wheel backwards
  • Indent block: select and press Tab
  • Unindent block: select and press Shift+Tab
  • Undo: Control + Z
  • Redo: Control + Shift + Z
  • Cut: Control + X
  • Copy: Control + C
  • Paste: Control + V
  • Move block: Control + left mouse drag
  • Auto indent: will automatically indent to the level of the previous line
  • Unindent a line: shift + Tab
  • Indent a line: go to begging of line, press Tab key

Searching Shortcuts in the editor:

  • Control + F: bring up search bar
  • Control + G: find next
  • Control + Shift + G: find previous
  • Enter: find next
  • Shift + Enter: find previous
  • Escape: close search bar

Selection shortcuts in the editor:

  • Select: Shift + arrow keys; Shift + Control + arrow keys; left-click and mouse drag; double-, triple- left-mouse click
  • Select all: Control + A
  • Block select: Control + Alt + mouse drag

Movement shortcuts in the editor:

  • Move by word: Control + arrow keys
  • To top: control + Home
  • to bottom: control + end
  • Beginning of line: home
  • End of line: end

Editor

Visual cues:

  • Yellow in margin: line has been edited
  • Green in margin: line has been edited and saved
  • Current line has grey background

Example 1: Draw a circle

In these examples we will use Python.

Our goals are:

  1. Import the Graphics library
  2. Create a window
  3. Create a circle, center at (150, 150) (zero is upper lefthand corner, x and y increase as they go away from upperleft hand corner). Make the radius 80 pixels.
  4. Draw the circle in the window

Here is a sample that satisfies our goals:

Example1.gif
from Graphics import *
win = Window()
circle = Circle(Point(150, 150), 80)
circle.draw(win)


In the Graphics library, you can substitute a tuple or list for a Point. So, these are equivalent:

from Graphics import *
win = Window()
circle = Circle((150, 150), 80)
circle.draw(win)

or:

from Graphics import *
win = Window()
circle = Circle([150, 150], 80)
circle.draw(win)


Example 2: Move Circle Interactively

Our goals for this example:

  1. Create a window that is 480 x 120, titled "Circles"
  2. Create a circle, as before, and draw it in the window
  3. In a loop, continue forever:
    1. if the mouse is down, make the circle black
    2. else make it white

Here is a short Python program that satisfies the goals:

Example2.gif
from Graphics import *
win = Window("Circles", 480, 120)
circle = Circle(getMouseNow(), 80)
circle.draw(win)
while True:
    circle.center.x, circle.center.y = getMouseNow()
    if getMouseState() == "down":
        circle.fill = Color("black")
    else:
        circle.fill = Color("white")


Note: This example does not end, so you need to click the red stop sign in the Shell window.

Videos

See Calico Videos for a variety of videos, including some on getting started.