Difference between revisions of "Calico: calico object"

From IPRE Wiki
Jump to: navigation, search
Line 74: Line 74:
See also [[ICalico#Display Functions]]
See also [[ICalico#Display Functions]]
==== Widgets ====
See [[ICalico#Widgets]] for creating interactive notebooks when connected to a live ICalico kernel.
=== Documents ===
=== Documents ===

Revision as of 15:38, 30 April 2014

The calico object is an instance of the calico environment that can allow you to interact with the Calico integrated development environment, and other languages other than the one that you are writing in.

Language Interoperation

Calico provides an interface for one language to call statements and expressions in another language.

Executing Statements

calico.Execute(statement-string, language-string)


calico.Execute("x = 2", "python")

Evaluating Expressions

calico.Evaluate(expression-string, language-string)


 value = calico.Evaluate("x", "python")

IDE Operations

Key Binding

Using the calico.onKey(key-string, function) mapping, you can assign key names to functions.

Here is an example that causes the "F1" key to take a picture of the Calico IDE window each time it is pressed.

import Myro
count = 0
def func(obj, args, focus):
    global count
    Myro.makePicture(calico).savePicture("calico-%d.gif" % count)
    count += 1
calico.onKey["F1"] = func

Here are the names of the keys: http://docs.go-mono.com/?link=T%3aGdk.Key

You can also see the key names for calico.onKey programmatically:

import Gdk

And then use those directly:

calico.onKey[str(Gdk.Key.comma)] = lambda obj, args, focus: print("comma!")

calico.onKey[str(Gdk.Key.Up)] = lambda obj, args, focus: print("up")
calico.onKey[str(Gdk.Key.Down)] = lambda obj, args, focus: print("down")

You can tell when control ("Control_L" or "Control_R") is pressed with this, but this API isn't the best for doing control+character.

See also the Events library: Calico Events and Graphics onKeyPress.

Display Information


  • calico.Print(string)
  • calico.Print(Tag, string)
  • calico.PrintLine(string)
  • calico.PrintLine(Tag, string)
  • calico.ChatPrint(string)
  • calico.ChatPrint(Tag, string)

See also ICalico#Display Functions


See ICalico#Widgets for creating interactive notebooks when connected to a live ICalico kernel.


  • calico.Open() - opens an empty document in the default language
  • calico.Open(filename) - opens a document, using the language to figure out language
  • calico.Open(filename, language-string) - opens a document, specifying what language (eg, "python")
  • document = calico.GetDocument(filename) - get the document in the IDE
  • document = calico.MakeDocument(filename, language-string) - create a document not in the IDE
calico.Open("NewData.csv")              # create a new file, and open it in the IDE
doc = calico.GetDocument("NewData.csv") # get the doc
# now you could manipulate the spreadsheet programmatically
# this example receives data from distributed users:
data = calico.ReceiveData()
count = 0
for message in data:
    from_name, from_data = message
    doc[count][0] = from_name
    doc[count][1] = from_data
    count += 1


The Spreadsheet document type has additional capabilities:

doc = calico.Open("spreadsheet.csv")
doc["A"][1] = "hello"
print(doc[0][0]) # prints hello
print(doc.Cols, doc.Rows) # max columns and max rows

See Calico Spreadsheet for more details.