Difference between revisions of "CalicoDevelopment"

From IPRE Wiki
Jump to: navigation, search
Line 1: Line 1:
This page describes the planning of Pyjama Editor and Shell. The Pyjama IDE is a cross-platform environment for learning about computing. This is part of the [[Pyjama]] Project.
+
This page describes the planning of Calico Editor and Shell. The Calico IDE is a cross-platform environment for learning about computing. This is part of the [[Calico]] Project.
  
 
= Development =
 
= Development =
Line 7: Line 7:
 
For those with write permissions to the SVN Bryn Mawr College source code repository:
 
For those with write permissions to the SVN Bryn Mawr College source code repository:
  
<pre>
+
svn co http://svn.cs.brynmawr.edu/Calico/trunk Calico
svn co https://svn.cs.brynmawr.edu/Pyjama/trunk Pyjama
+
 
</pre>
+
Developers who have an Bryn Mawr College SVN account should use:
 +
 
 +
svn co https://svn.cs.brynmawr.edu/Calico-dev/trunk Calico
  
 
You can browse the source code here:
 
You can browse the source code here:
  
* http://svn.cs.brynmawr.edu/viewvc/Pyjama/trunk
+
* http://svn.cs.brynmawr.edu/viewvc/Calico/trunk
  
 
You will also need:
 
You will also need:
Line 22: Line 24:
 
== Building ==
 
== Building ==
  
You do not need to make anything. All of the libraries that you need come pre-built. But, if you want to know, this section describes what you need to do.
+
'''You do not need to make anything. All of the libraries that you need come pre-built. But, if you want to know, this section describes what you need to do.'''
  
You will need petite scheme to make Pyjama Scheme from scratch.  
+
You will need petite scheme to make Calico Scheme from scratch.  
  
 
To build everything, run "make" in the root:
 
To build everything, run "make" in the root:
  
 
<pre>
 
<pre>
cd Pyjama
+
cd Calico
 
make
 
make
 
</pre>
 
</pre>
Line 38: Line 40:
  
 
<pre>
 
<pre>
cd Pyjama
+
cd Calico
 
make
 
make
 
</pre>
 
</pre>
Line 44: Line 46:
 
== Overview ==
 
== Overview ==
  
There are 5 directories in the Pyjama folder:
+
There are 5 directories in the Calico folder:
  
 
# bin - contains the startup exe and dll files
 
# bin - contains the startup exe and dll files
 
## bin/Lib - contains the standard Python libraries
 
## bin/Lib - contains the standard Python libraries
 
# languages - contains the language definition files for Python, Ruby, Scheme, and Dinah
 
# languages - contains the language definition files for Python, Ruby, Scheme, and Dinah
# modules - Cross-language modules that can be used by all Pyjama languages
+
# modules - Cross-language modules that can be used by all Calico languages
 
# examples - sample code, broken down by language
 
# examples - sample code, broken down by language
# src - the code to run the Pyjama Project
+
# src - the code to run the Calico Project
  
Pyjama is written in IronPython, using the Gtk# graphical toolkit. The Python files for the Pyjama Project are in Pyjama/src/*.py. They are:
+
Calico is written in IronPython, using the Gtk# graphical toolkit. The Python files for the Calico Project are in Calico/src/*.py. They are:
  
 
* chat.py - the Chat window
 
* chat.py - the Chat window
Line 59: Line 61:
 
* editor.py - the Editor Window
 
* editor.py - the Editor Window
 
* engine.py - base classes for the Engine interface
 
* engine.py - base classes for the Engine interface
* pyjama.py - setup and startup code
+
* calico.py - setup and startup code
 
* reflection.py - code to read DLL data
 
* reflection.py - code to read DLL data
 
* shell.py - the Shell Window
 
* shell.py - the Shell Window
Line 65: Line 67:
 
* window.py - base class for Shell, Editor, and Chat
 
* window.py - base class for Shell, Editor, and Chat
  
Pyjama is an editor and executor of code from a Language. Languages are defined in Pyjama/languages and define two items: editor document, and an executor engine. Pyjama has 4 languages, in various states of completeness:
+
Calico is an editor and executor of code from a Language. Languages are defined in Calico/languages and define two items: editor document, and an executor engine. Calico has a few languages, in various states of completeness:
  
 
# Python (finished)
 
# Python (finished)
Line 74: Line 76:
 
# C# (experimental, no functions, no classes, no DLR)
 
# C# (experimental, no functions, no classes, no DLR)
  
A Language file in Pyjama/languages/*.py defines the editing document, and the shell executor API. Documents can do things like open, save, and display data for editing. Engines can do things like execute, execute_file, and parse files. Engines also allow for the languages to share data and functionality.
+
A Language file in Calico/languages/*.py defines the editing document, and the shell executor API. Documents can do things like open, save, and display data for editing. Engines can do things like execute, execute_file, and parse files. Engines also allow for the languages to share data and functionality.
  
 
= TODO =
 
= TODO =
  
See [http://svn.cs.brynmawr.edu/viewvc/Pyjama/trunk/NOTES?view=co NOTES] in the Pyjama download (package or svn).
+
See [http://svn.cs.brynmawr.edu/viewvc/Calico/trunk/NOTES?view=co NOTES] in the Calico download (package or svn).
  
 
= Screen Shots =
 
= Screen Shots =
Line 84: Line 86:
 
[[Image:Pyjama-010.gif]]
 
[[Image:Pyjama-010.gif]]
  
For more, see [[PyjamaScreenShots]]
+
For more, see [[CalicoScreenShots]]
  
 
== Python and Ruby ==
 
== Python and Ruby ==
  
Pyjama allows you to easily jump back and forth between languages. Enter this code in the command box:
+
Calico allows you to easily jump back and forth between languages. Enter this code in the command box:
  
 
<pre>
 
<pre>
Line 197: Line 199:
 
== Interacting with .NET ==
 
== Interacting with .NET ==
  
The languages of Pyjama can also interact with .NET/Mono. If you are already familiar with .NET/Mono programs (such as those written in C# or Visual Basic) then you will recognize some of these idioms and names.  
+
The languages of Calico can also interact with .NET/Mono. If you are already familiar with .NET/Mono programs (such as those written in C# or Visual Basic) then you will recognize some of these idioms and names.  
  
As a simple example, let's use the interactive abilities to directly interact with some Windows Forms. In order to do this in Pyjama, will turn the threaded ability off, so as to talk to the GUI in the same thread as Pyjama is running in. Let's create a window (called a Form in .NET parlance):
+
As a simple example, let's use the interactive abilities to directly interact with some Windows Forms. In order to do this in Calico, will turn the threaded ability off, so as to talk to the GUI in the same thread as Calico is running in. Let's create a window (called a Form in .NET parlance):
  
 
<pre>
 
<pre>
Line 206: Line 208:
 
clr.AddReference("System.Windows.Forms")
 
clr.AddReference("System.Windows.Forms")
 
from System.Windows.Forms import *
 
from System.Windows.Forms import *
import pyjama
 
pyjama.Threaded = False
 
 
win = Form()
 
win = Form()
 
win.Show()
 
win.Show()
Line 214: Line 214:
 
Importing the special module named '''clr''' is the gateway to interacting with the underlying .NET/Mono subsystem. From the clr module, you can add a reference to any Dynamic Link Library (DLL) so that you can access library functions and objects. In this example, we add a reference to the '''System.Windows.Forms''' DLL which contains a library of Graphical User Interface (GUI) objects. We then can create a Form, save it in a variable named '''win''', and call the form's '''Show()''' method.
 
Importing the special module named '''clr''' is the gateway to interacting with the underlying .NET/Mono subsystem. From the clr module, you can add a reference to any Dynamic Link Library (DLL) so that you can access library functions and objects. In this example, we add a reference to the '''System.Windows.Forms''' DLL which contains a library of Graphical User Interface (GUI) objects. We then can create a Form, save it in a variable named '''win''', and call the form's '''Show()''' method.
  
If you'd like to give the window a name, enter this in Pyjama's interactive command box:
+
If you'd like to give the window a name, enter this in Calico's interactive command box:
  
 
<pre>
 
<pre>
Line 220: Line 220:
 
</pre>
 
</pre>
  
These windows will go away when you close Pyjama, or you can close them manually.
+
These windows will go away when you close Calico, or you can close them manually.
  
 
== Developing a Language for the DLR in the DLR ==
 
== Developing a Language for the DLR in the DLR ==
Line 226: Line 226:
 
Python and Ruby are defined to interact as above by taking advantage of the Dynamic Language Runtime (DLR). To further show this off, here is an example of defining a new language, much like Lisp, called SymPL written in Python using the tools of the DLR:
 
Python and Ruby are defined to interact as above by taking advantage of the Dynamic Language Runtime (DLR). To further show this off, here is an example of defining a new language, much like Lisp, called SymPL written in Python using the tools of the DLR:
  
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/lexer.py lexer.py] - the lexer
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/lexer.py lexer.py] - the lexer
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/parser.py parser.py] - the parser
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/parser.py parser.py] - the parser
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/etgen.py etgen.py] - expression tree generators
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/etgen.py etgen.py] - expression tree generators
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/runtime.py runtime.py] - runtime helpers (e.g., lookup, import)  
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/runtime.py runtime.py] - runtime helpers (e.g., lookup, import)  
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/test.py test.py] - the Read Eval Print Loop
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/test.py test.py] - the Read Eval Print Loop
  
 
Some sample SymPL programs:
 
Some sample SymPL programs:
  
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/test.sympl test.sympl] - function tests
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/test.sympl test.sympl] - function tests
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/ops.sympl ops.sympl] - operator tests
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/ops.sympl ops.sympl] - operator tests
# [http://svn.cs.brynmawr.edu/Myro/trunk/Pyjama/sympl/lists.sympl lists.sympl] - list tests
+
# [http://svn.cs.brynmawr.edu/Myro/trunk/Calico/sympl/lists.sympl lists.sympl] - list tests
  
 
== Writing Fast Module Code Once ==
 
== Writing Fast Module Code Once ==
Line 273: Line 273:
 
or put into a Project in Visual Studio, and compiled into a library.
 
or put into a Project in Visual Studio, and compiled into a library.
  
You should then put the resulting '''Testing.dll''' somewhere will Pyjama can find it (either put in the same directory with the pyjama.exe, or put it in a directory and add the path of the directory to Python's sys.path):
+
You should then put the resulting '''Testing.dll''' somewhere will Calico can find it (either put in the same directory with the calico.exe, or put it in a directory and add the path of the directory to Python's sys.path):
  
 
<pre>
 
<pre>
Line 280: Line 280:
 
</pre>
 
</pre>
  
Finally, you can use it in Pyjama:
+
Finally, you can use it in Calico:
  
 
<pre>
 
<pre>
Line 301: Line 301:
 
== Creating Interactive Programs and Graphics for the Web ==
 
== Creating Interactive Programs and Graphics for the Web ==
  
Once you have a working program in Pyjama, you can save the program to run on the Web in a manner very much like Flash applications. The resulting program can run in a browser using Silverlight/Moonlight. Example coming soon!
+
Once you have a working program in Calico, you can save the program to run on the Web in a manner very much like Flash applications. The resulting program can run in a browser using Silverlight/Moonlight. Example coming soon!
  
 
= Troubleshooting =
 
= Troubleshooting =
Line 307: Line 307:
 
If you have any trouble, find bugs, or want to make a feature request, please do that at:
 
If you have any trouble, find bugs, or want to make a feature request, please do that at:
  
[http://pyjama.codeplex.com/WorkItem/List.aspx pyjama.codeplex.com/WorkItem/]
+
[http://calico.codeplex.com/WorkItem/List.aspx calico.codeplex.com/WorkItem/]

Revision as of 22:54, 25 May 2011

This page describes the planning of Calico Editor and Shell. The Calico IDE is a cross-platform environment for learning about computing. This is part of the Calico Project.

Development

Getting Source Code

For those with write permissions to the SVN Bryn Mawr College source code repository:

svn co http://svn.cs.brynmawr.edu/Calico/trunk Calico

Developers who have an Bryn Mawr College SVN account should use:

svn co https://svn.cs.brynmawr.edu/Calico-dev/trunk Calico

You can browse the source code here:

You will also need:

  • mono
  • gtk (and libgtk2.0-cil-dev, for package-config files)

Building

You do not need to make anything. All of the libraries that you need come pre-built. But, if you want to know, this section describes what you need to do.

You will need petite scheme to make Calico Scheme from scratch.

To build everything, run "make" in the root:

cd Calico
make

That will build platform independent modules/Myro.dll, modules/Graphics.dll, and languages/Scheme.dll.

To run code:

cd Calico
make

Overview

There are 5 directories in the Calico folder:

  1. bin - contains the startup exe and dll files
    1. bin/Lib - contains the standard Python libraries
  2. languages - contains the language definition files for Python, Ruby, Scheme, and Dinah
  3. modules - Cross-language modules that can be used by all Calico languages
  4. examples - sample code, broken down by language
  5. src - the code to run the Calico Project

Calico is written in IronPython, using the Gtk# graphical toolkit. The Python files for the Calico Project are in Calico/src/*.py. They are:

  • chat.py - the Chat window
  • document.py - base classes for Document interface
  • editor.py - the Editor Window
  • engine.py - base classes for the Engine interface
  • calico.py - setup and startup code
  • reflection.py - code to read DLL data
  • shell.py - the Shell Window
  • utils.py - utility functions and classes (chat, windows, functions, etc.)
  • window.py - base class for Shell, Editor, and Chat

Calico is an editor and executor of code from a Language. Languages are defined in Calico/languages and define two items: editor document, and an executor engine. Calico has a few languages, in various states of completeness:

  1. Python (finished)
  2. Ruby (nearly finished)
  3. Scheme (somewhat working)
  4. Dinah (drag and drop language, just started)
  5. Sympl (experimental Lisp-like language written in Python for the DLR)
  6. C# (experimental, no functions, no classes, no DLR)

A Language file in Calico/languages/*.py defines the editing document, and the shell executor API. Documents can do things like open, save, and display data for editing. Engines can do things like execute, execute_file, and parse files. Engines also allow for the languages to share data and functionality.

TODO

See NOTES in the Calico download (package or svn).

Screen Shots

Pyjama-010.gif

For more, see CalicoScreenShots

Python and Ruby

Calico allows you to easily jump back and forth between languages. Enter this code in the command box:

def fib(n):
    if n <= 2: return 1
    return fib(n - 1) + fib(n - 2)

Make sure the bottom status line has Python checked, and press the Run! button (or simply hit <enter> when in the command box).

Now, enter this code in the command box (make sure to set bottom status line has Ruby checked).

class Hello_world
  def greet
    puts "Hello World"
  end
end
hw = Hello_world.new
hw.greet

Cross-language Access

In this example, you'll see that you can access code and variables defined in other languages.

Enter the following in the Interactive Command Box:

class PythonClass:
     def hello(self, value):
         print "Python says hello to", value

This defines a PythonClass. To test it out, enter the following in the command box:

pc = PythonClass()
pc.hello("Python")

In the Output Box, you'll of course see:

Python says hello to Python

Now, switch to Ruby mode (bottom line status bar, select Ruby) and enter this in the command box:

pc = python_class().new
pc.hello "Ruby"

This uses the PythonClass (now called python_class). In Ruby, you can create an object by placing the .new after it. You call the method .hello by placing the arguments after the method name (parens are not needed in Ruby).

You will see in the output box:

Python says hello to Ruby

which is Python code running inside Ruby!

While in Ruby Mode, enter:

class Ruby_class
   def hello caller
     puts "Ruby says hello to #{caller}"
   end
end

To see that work, try:

rc = Ruby_class.new
rc.hello "Ruby"

and you'll of course see:

Ruby says hello to Ruby

Finally, switch back to Python Mode, and enter:

import Ruby_class
rc = Ruby_class()
rc.hello("Python")

and you'll see:

Ruby says hello to Python

which is Ruby code running in Python!



Interacting with .NET

The languages of Calico can also interact with .NET/Mono. If you are already familiar with .NET/Mono programs (such as those written in C# or Visual Basic) then you will recognize some of these idioms and names.

As a simple example, let's use the interactive abilities to directly interact with some Windows Forms. In order to do this in Calico, will turn the threaded ability off, so as to talk to the GUI in the same thread as Calico is running in. Let's create a window (called a Form in .NET parlance):

# file: winform.py
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import *
win = Form()
win.Show()

Importing the special module named clr is the gateway to interacting with the underlying .NET/Mono subsystem. From the clr module, you can add a reference to any Dynamic Link Library (DLL) so that you can access library functions and objects. In this example, we add a reference to the System.Windows.Forms DLL which contains a library of Graphical User Interface (GUI) objects. We then can create a Form, save it in a variable named win, and call the form's Show() method.

If you'd like to give the window a name, enter this in Calico's interactive command box:

win.Text = "This is the Window Title"

These windows will go away when you close Calico, or you can close them manually.

Developing a Language for the DLR in the DLR

Python and Ruby are defined to interact as above by taking advantage of the Dynamic Language Runtime (DLR). To further show this off, here is an example of defining a new language, much like Lisp, called SymPL written in Python using the tools of the DLR:

  1. lexer.py - the lexer
  2. parser.py - the parser
  3. etgen.py - expression tree generators
  4. runtime.py - runtime helpers (e.g., lookup, import)
  5. test.py - the Read Eval Print Loop

Some sample SymPL programs:

  1. test.sympl - function tests
  2. ops.sympl - operator tests
  3. lists.sympl - list tests

Writing Fast Module Code Once

Perhaps the nicest aspect of the DLR is that you can develop code (in CSharp, for example) that is "compiled" and used directly. Such can be imported and used by any language in the DLR suite as if it were written in that language. For example, consider this simple example:

// file: Testing.cs
public class Point {
  private int _x;
  private int _y;
  public Point(int x, int y) {
	_x = x;
	_y = y;
  }
  public int x {
	get { return _x; }
	set { _x = value; }
  }
  public int y {
	get { return _y; }
	set { _y = value; }
  }
  public string __repr__() {
	return "<Point at (" + _x + "," + _y +")>";
  }
}

This can be compiled in Mono:

gmcs Testing.cs -target:library

or put into a Project in Visual Studio, and compiled into a library.

You should then put the resulting Testing.dll somewhere will Calico can find it (either put in the same directory with the calico.exe, or put it in a directory and add the path of the directory to Python's sys.path):

import sys
sys.path.append("/path/to/folder")

Finally, you can use it in Calico:

>>> import clr
>>> clr.AddReference("Testing")
>>> import Point
>>> Point
<type 'Point'>
>>> p = Point(1,2)
>>> p
<Point at (1,2)>
>>> p.x
1
>>> p.x = 9
>>> p
<Point at (9,2)>
>>> 

Creating Interactive Programs and Graphics for the Web

Once you have a working program in Calico, you can save the program to run on the Web in a manner very much like Flash applications. The resulting program can run in a browser using Silverlight/Moonlight. Example coming soon!

Troubleshooting

If you have any trouble, find bugs, or want to make a feature request, please do that at:

calico.codeplex.com/WorkItem/