Calico: calico object

From IPRE Wiki
Revision as of 03:10, 9 July 2014 by Doug Blank (Talk | contribs) (IDE Operations)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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)

Example:

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

Evaluating Expressions

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

Example:

 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
print(dir(Gdk.Key))

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.

ICalico Notebook

You can control the blocking behavior of the engine by:

session = calico.GetSession()
session.SetBlocking(False)

That will allow cells to run simultaneously.

Display Information

Printing

  • 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

Widgets

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

Documents

  • 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

Spreadsheet

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.