Difference between revisions of "Calico: Getting Started"

From IPRE Wiki
Jump to: navigation, search
(Example 2: Move Circle Interactively)
(Starting)
 
(35 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
Calico is an environment for scripting. It is composed of three main components:  
 
Calico is an environment for scripting. It is composed of three main components:  
  
* Scripting Languages (like Ruby, Python and Scheme)
+
* Interactive Scripting Language Shell (like Ruby, Python and Scheme)
* Scripting Editor
+
* Scripting Editor (files of scripts)
* Libraries for doing things (like robotics and graphics)
+
* Modules 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.  
 
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 [[CalicoDownload]] page.
+
First, you should have already installed Calico at the [[Calico Download]] page.
  
 
= Starting =
 
= Starting =
  
You can start Calico up by running the ./calico (Linux and Mac OSX) and calico.bat (Windows).
+
Normally, you can just double-click on the StartCalico icon in Windows, Mac, and Linux.
  
You can pass a number of "flags" to Calico. Here we pass the --help flag to see what all of the options are:
+
As a convenience, you might want to associate ".py" files with StartCalico, so that when you double-click a file, it opens it in Calico. Otherwise, you will need to start Calico, and then use menu -> File -> Open.
 +
 
 +
You can also start Calico up by running the ./StartCalico (Linux and Mac OSX) and StartCalico.bat (Windows) from the command console (also called terminal). You can pass a number of "flags" to Calico. Here we pass the --help flag to see what all of the options are:
  
 
<pre>
 
<pre>
C:\Users\dblank\Calico>calico.bat --help
+
C:\Users\dblank\Calico>StartCalico.bat --help
Loading Calico...
+
 
 +
Loading Calico version 2.4.2...
  
Calico Project, Version 0.2.4, on Microsoft Windows NT 6.1.7600.0
+
Calico Project, version 2.4.2 on Unix 3.5.0.36
 +
  Using Mono runtime version 2.10.8.1 (Debian 2.10.8.1-5ubuntu1)
 
----------------------------------------------------------------------------
 
----------------------------------------------------------------------------
 
Start calico with the following options:
 
Start calico with the following options:
   calico                            Defaults to shell
+
   StartCalico                    Standard GUI
   calico FILENAME:LINE ...         Edits FILENAMEs, positioned on LINEs
+
   StartCalico FILENAME:LINE ... Edits FILENAMEs, positioned on LINEs
   calico --shell                    Brings up shell window
+
   StartCalico --lang=LANGUAGE    Sets default language (python, etc.)
   calico --chat                    Brings up chat window
+
   StartCalico --exec FILENAMEs  Run FILENAMEs
   calico --editor                  Brings up editor window
+
   StartCalico --repl FILENAMEs  Run FILENAMEs and starts read-eval-print loop
   calico --exec FILENAMEs          Runs FILENAMEs standalone, with graphics
+
   StartCalico  --graphics      Run with graphics (with --exec or --repl)
   calico --exec --nogui FILENAMEs   Runs FILENAMEs standalone, no graphics
+
   StartCalico  --noquit        Don't quit after executing file with --exec
   calico --version                 Displays the version number (0.2.4)
+
   StartCalico --nomodules        Does not load the modules from modules/*.dll
   calico --help                     Displays this message
+
   StartCalico --version         Displays the version number (2.4.2)
 +
   StartCalico --verbose          Displays detailed information (for debugging)
 +
  StartCalico --debug            Calico output goes to console rather than GUI
 +
  StartCalico --debug-handler    Calico will not catch system errors
 +
  StartCalico --reset            Resets config settings to factory defaults
 +
  StartCalico --help             Displays this message
 
</pre>
 
</pre>
  
== Examples ==
+
There are three main modes of operation:
  
To edit a program:
+
# with the standard Calico GUI
 +
# --exec runs code; does not bring up GUI
 +
# --repl runs a console read-eval-print loop, after running any programs
  
calico myprog.rb
+
Additionally, there is the --graphics flag. By default, Calico assumes that you do not want to initiate and run the graphical event loop. --graphics only makes sense when you are using --exec or --repl.
  
To edit a program, starting on line 200:
+
If you have a graphical program, and run without the Calico GUI, then you might want to have your graphical windows exit Calico. You can do that with something like:
  
calico myprog.rb:200
+
<pre>
 +
from Graphics import Window
 +
import System
 +
win = Window()
 +
win.DeleteEvent += lambda obj, event: System.Environment.Exit(0)
 +
</pre>
  
To edit a bunch of programs:
+
== Examples ==
  
calico *.py
+
To edit a program:
  
To run a program:
+
StartCalico myprog.rb
  
calico --exec myprog.rb
+
To edit a program, starting on line 200:
  
To run a program that takes care of its own graphics:
+
StartCalico myprog.rb:200
  
calico --exec --nogui myprog.rb
+
To edit a bunch of programs:
  
To open up the editor and shell:
+
  StartCalico *.py
 
+
  calico --editor --shell
+
  
 
''This page provides some examples of using [[Calico]].''
 
''This page provides some examples of using [[Calico]].''
Line 67: Line 81:
 
== Calico GUI ==
 
== Calico GUI ==
  
[[Image:Calico-0.1.0.gif|right|thumb]]
+
[[Image:Calico2-Home.jpg|500px|right]]
  
Calico is divided into two windows:
+
Calico is divided into three parts:
  
 
# Editor  
 
# Editor  
# Shell and Output
+
# Shell
 +
# Output
  
 
<br clear="all"/>
 
<br clear="all"/>
Line 79: Line 94:
  
 
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).
 
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).
 +
 +
=== Running Scripts ===
 +
 +
There are 5 widgets involved with running a script. From left to right they are:
 +
 +
* Stop, stops the program
 +
* Run, starts the program
 +
* Speed slider, from (left) fast to single-step (right), with auto-pausing in between
 +
* Pause
 +
* Next/Resume step
 +
 +
These are used in the following ways:
 +
 +
* To start running, with stepper or fast, you press the Run button
 +
* If the slider is far to left (fast) when you press the Run button, it runs regularly (no debugging)
 +
* If the slider is in the middle, then the debugger will run with an auto-pause on (between 0.1 and 1 second pause per line). You can press the Pause button at any time.
 +
* If the slider is on the far right, then it is in single-step mode. You can press the Next button to go to next line.
 +
* You can press the Pause button when slider is in middle, and the program is running
 +
* You can press the Next/Resume button when slider is in middle (resumes), or if slider is far-right (next)
  
 
= Example Code =
 
= Example Code =
  
See http://svn.cs.brynmawr.edu/viewvc/Calico/trunk/examples/
+
You'll find the example code in Calico: menu -> File -> Examples -> pick your language.
  
 
== Keyboard Commands ==
 
== Keyboard Commands ==
  
These work for Editor and Shell.
+
=== Shell ===
  
Visual shortcuts:
+
General shortcuts in the shell:
  
* Zoom in: Control + mouse wheel forwards
+
* Control + Enter: newline (does not evaluate)
* Zoom out: Control + mouse wheel backwards
+
* TAB: after some text will do command completion
 +
* Up arrow: previous command
 +
* Down arrow: next command
 +
* Control+Up arrow: take the current command, and put it on the bottom of the previous command
 +
* Control+Down arrow: take the current command, and put it on the top of the 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
  
Editing 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
 +
* Zoom in: Control + mouse wheel forwards
 +
* Zoom out: Control + mouse wheel backwards
 
* Indent block: select and press Tab
 
* Indent block: select and press Tab
 
* Unindent block: select and press Shift+Tab
 
* Unindent block: select and press Shift+Tab
Line 107: Line 171:
 
* 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
 
* Control + G: find next
 
* Control + G: find next
* Control + Shift + G: find previous
+
* Control + R: find previous
 
* Enter: find next
 
* Enter: find next
 
* Shift + Enter: find previous
 
* Shift + Enter: find previous
 
* 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 122: Line 186:
 
* 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
Line 129: Line 193:
 
* Beginning of line: home
 
* Beginning of line: home
 
* End of line: end
 
* End of line: end
 
Running scripts shortcuts:
 
 
* Run the script in the command area: F5
 
* 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
 
* Run selected text: F5 (puts into command area; a second F5 will run it)
 
* Drag text to command area, then F5
 
* Stop processing: Escape key
 
* Previous command: Up arrow
 
* Next command: Down key
 
  
 
== Editor ==
 
== Editor ==
Line 151: Line 203:
  
 
= Example 1: Draw a circle =
 
= Example 1: Draw a circle =
 +
 +
In these examples we will use Python.
 +
 +
Our goals are:
  
 
# Import the Graphics library
 
# Import the Graphics library
Line 156: Line 212:
 
# 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.
 
# 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.
 
# Draw the circle in the window
 
# Draw the circle in the window
 +
 +
Here is a sample that satisfies our goals:
 +
 +
[[Image:Example1.gif|right]]
  
 
<pre>
 
<pre>
Line 163: Line 223:
 
circle.draw(win)
 
circle.draw(win)
 
</pre>
 
</pre>
 +
 +
<br clear="all" />
  
 
In the Graphics library, you can substitute a tuple or list for a Point. So, these are equivalent:
 
In the Graphics library, you can substitute a tuple or list for a Point. So, these are equivalent:
Line 173: Line 235:
 
</pre>
 
</pre>
  
 
+
or:
[[Image:Example1.gif|right]]
+
  
 
<pre>
 
<pre>
Line 186: Line 247:
  
 
= Example 2: Move Circle Interactively =
 
= Example 2: Move Circle Interactively =
 +
 +
Our goals for this example:
  
 
# Create a window that is 480 x 120, titled "Circles"
 
# Create a window that is 480 x 120, titled "Circles"
Line 192: Line 255:
 
## if the mouse is down, make the circle black
 
## if the mouse is down, make the circle black
 
## else make it white
 
## else make it white
 +
 +
Here is a short Python program that satisfies the goals:
  
 
[[Image:Example2.gif|right]]
 
[[Image:Example2.gif|right]]
Line 200: Line 265:
 
circle = Circle(getMouseNow(), 80)
 
circle = Circle(getMouseNow(), 80)
 
circle.draw(win)
 
circle.draw(win)
while True:
+
while win.isVisible():
     circle.center.x, circle.center.y = getMouseNow()
+
     circle.center = Point(getMouseNow())
 
     if getMouseState() == "down":
 
     if getMouseState() == "down":
 
         circle.fill = Color("black")
 
         circle.fill = Color("black")
Line 209: Line 274:
  
 
<br clear="all" />
 
<br clear="all" />
 +
 +
Note: This example code 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.

Latest revision as of 00:21, 2 August 2013

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:

  • Interactive Scripting Language Shell (like Ruby, Python and Scheme)
  • Scripting Editor (files of scripts)
  • Modules 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

Normally, you can just double-click on the StartCalico icon in Windows, Mac, and Linux.

As a convenience, you might want to associate ".py" files with StartCalico, so that when you double-click a file, it opens it in Calico. Otherwise, you will need to start Calico, and then use menu -> File -> Open.

You can also start Calico up by running the ./StartCalico (Linux and Mac OSX) and StartCalico.bat (Windows) from the command console (also called terminal). 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

Loading Calico version 2.4.2...

Calico Project, version 2.4.2 on Unix 3.5.0.36
  Using Mono runtime version 2.10.8.1 (Debian 2.10.8.1-5ubuntu1)
----------------------------------------------------------------------------
Start calico with the following options:
  StartCalico                    Standard GUI
  StartCalico FILENAME:LINE ...  Edits FILENAMEs, positioned on LINEs
  StartCalico --lang=LANGUAGE    Sets default language (python, etc.)
  StartCalico --exec FILENAMEs   Run FILENAMEs
  StartCalico --repl FILENAMEs   Run FILENAMEs and starts read-eval-print loop
  StartCalico   --graphics       Run with graphics (with --exec or --repl)
  StartCalico   --noquit         Don't quit after executing file with --exec
  StartCalico --nomodules        Does not load the modules from modules/*.dll
  StartCalico --version          Displays the version number (2.4.2)
  StartCalico --verbose          Displays detailed information (for debugging)
  StartCalico --debug            Calico output goes to console rather than GUI
  StartCalico --debug-handler    Calico will not catch system errors
  StartCalico --reset            Resets config settings to factory defaults
  StartCalico --help             Displays this message

There are three main modes of operation:

  1. with the standard Calico GUI
  2. --exec runs code; does not bring up GUI
  3. --repl runs a console read-eval-print loop, after running any programs

Additionally, there is the --graphics flag. By default, Calico assumes that you do not want to initiate and run the graphical event loop. --graphics only makes sense when you are using --exec or --repl.

If you have a graphical program, and run without the Calico GUI, then you might want to have your graphical windows exit Calico. You can do that with something like:

from Graphics import Window
import System
win = Window()
win.DeleteEvent += lambda obj, event: System.Environment.Exit(0)

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

This page provides some examples of using Calico.

Calico GUI

Calico2-Home.jpg

Calico is divided into three parts:

  1. Editor
  2. Shell
  3. 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).

Running Scripts

There are 5 widgets involved with running a script. From left to right they are:

  • Stop, stops the program
  • Run, starts the program
  • Speed slider, from (left) fast to single-step (right), with auto-pausing in between
  • Pause
  • Next/Resume step

These are used in the following ways:

  • To start running, with stepper or fast, you press the Run button
  • If the slider is far to left (fast) when you press the Run button, it runs regularly (no debugging)
  • If the slider is in the middle, then the debugger will run with an auto-pause on (between 0.1 and 1 second pause per line). You can press the Pause button at any time.
  • If the slider is on the far right, then it is in single-step mode. You can press the Next button to go to next line.
  • You can press the Pause button when slider is in middle, and the program is running
  • You can press the Next/Resume button when slider is in middle (resumes), or if slider is far-right (next)

Example Code

You'll find the example code in Calico: menu -> File -> Examples -> pick your language.

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
  • Control+Up arrow: take the current command, and put it on the bottom of the previous command
  • Control+Down arrow: take the current command, and put it on the top of the 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 + R: 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 win.isVisible():
    circle.center = Point(getMouseNow())
    if getMouseState() == "down":
        circle.fill = Color("black")
    else:
        circle.fill = Color("white")


Note: This example code 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.