Saturday, December 26, 2009

Using Etoys to Develop XO Sugar Activities

This blog describes how to use Etoys to develop a XO Sugar Activity. Let me start with a FAQ.

Blog FAQs - Using Etoys to Develop XO Sugar Activities

Changes:
February 2010 
  • added a note about different ways of installing the Sugar Operating System
  • added a note about Etoys and Squeak
What is the Goal of this Blog?

This blog will talk about development of Sugar Activities in Etoys; it will also provide introduction to Squeak/Etoys interface to DBus.

There are several Etoys components which could be converted to Sugar activities by using the approach described in future entries. The example that will be used is FreeCell, see http://activities.sugarlabs.org/en-US/sugar/search?q=freecell&cat=all.

How did this Blog Start?

Bert Freudenberg converted the Squeak Freecell activity into a Sugar activity, and suggested to add persistence of the Freecell activity statistics. The persistence will use the Etoys DBus interface. Bert also provided many of the suggestions how to do it :)

What is "Sugar"?

Sugar is the main operating system for the OLPC XO, centered on education. See http://sugarlabs.org.

What is "Squeak"?

Squeak is a FOSS implementation of Smalltalk, which goal is to create a multimedia rich environment. See Squeak home page for details.

What is "Etoys"?

Etoys is a multimedia environment running on top of Squeak. It is distributes as a core activity on the Sugar OS.

From Squeakland, the home of Etoys:

"Etoys is . . .
  • an educational tool for teaching children powerful ideas in compelling ways
  • a media-rich authoring environment and visual programming system
  • a free software program that works on almost all personal computers"
How to install and run Sugar?

The Sugar Operating system runs on multiple systems, or as a alternate desktop on some Linux distros.

Four ways to run Sugar (which does contain Etoys as a core activity):
    1. On the OLPC-XO laptop, Sugar is preinstalled - but not everyone has an OLPC laptop.
    2. Install Sugar on a USB stick from Sugarlabs (Windows, Apple, Linux, Unix).
    3. Run Sugar as alternate desktop (on Linux only) - see section "Are you a developer or Beta tester?" on sugarlabs.
    4. Run Sugar under Emulation on your operating system (Windows, Apple, Linux, Unix). I am running Sugar on VirtualBox emulator using Sugar blueberry version, so I will provide a few steps how to set it up:
    • Install VirtualBox. All Linux distros have VirtualBox available, for Window you can find it here: http://www.virtualbox.org/
    • Download Sugar Blueberry vdi here: http://wiki.sugarlabs.org/go/VirtualBox#Experimental_Prebuilt_VirtualBox_4GB_Blueberry.vdi_file . Click on the Prebuilt vdi: [1].
    • Unzip the vdi file and put it into a directory. Do not worry it is not 4Gb in size :)
    • Start VirtualBox and create a New Virtual Machine by clicking New, providing name, for example Sugar Blueberry VM, and pointing to the above blueberry VDI file.
    • Add networking to the Sugar Blueberry Virtual machine (VM). This is not absolutely necessary, but very helpful because it allows to use either FTP or SSH to copy files between your host OS and the vitrual machine. To connect the VM to your network , right click on the Blueberry VM, select a Adapter type PCnet - Fast III, Attched to = Bridged Adapter , Name = whatever adapter is in the dropdown (eth0 in my case).
    • Now, clicking on the newly created Sugar Blueberry VM, the Sugar OS should start, and present it's menu:

    What is DBus?

    DBus is a message bus system which allows applications to communicate. It is part of the Freedesktop specifications. Some DBus links:
    http://en.wikipedia.org/wiki/D-Bus
    http://www.freedesktop.org/wiki/Software/dbus

    DBus bindings for Squeak are available on squeaksource, http://www.squeaksource.com/dbus.html , and can be used to interface with KDE or Gnome desktop in interesting ways. See the above link and also http://vpri.org/pdf/tr2009001_etoys4olpc.pdf for details.

    Terminology: In the Sugar OS, what is a "Bundle" an "Activity", a "Journal", etc?

    These are Sugar terms describing what other systems would call an "application", "application instance". Brief description of activities and related terms is just below. Unfortunately, it seems there is a bit of a confusion in terminology in Sugar. We will try use the highlighted terms, terms i brackets are alternatives that seem to be also used. Read the symbol "=" as "defined as / equivalent to / similar to".


    Specifications for Sugar Activities can be found on http://wiki.laptop.org/go/Activity the low level API can be found on http://wiki.laptop.org/go/Low-level_Activity_API.
    The low level Activity API dscribes how activities interact with the Sugar OS on startup, exit, and during persistence to Journal.

    Note: To me, Sugar seem to have an unfortunate confusion of terms between what a Bundle and an Activity is. From user's perspective, every application you see in the Sugar menu is Activity. However, from developer's perspective, applications in the Sugar menu are Bundles. For example, you install an .XO file. This creates a Bundle in the filesystem, stored unfortunately in directory named "$HOME/Activity" and named Activity in various tutorials.

    What is "Etoys based Sugar Activity"?

    It is an application which:
    • Is developed in Etoys (perhaps more precisely, in the underlying Squeak Smalltalk environment).
    • Runs in Sugar, allowing interaction with the Datastore.
    • Participates in the Sugar environment, that is, can be saved/resumed in the Sugar Journal, can copy/paste onto a Journal.
    How can an "Etoys based Sugar Activity" be created and distributed?

    Etoys based Sugar Activity can be created and distributed in 2 ways:
    • By creating a "regular Etoys project", which is imported at startup, but without storing anything in Datastore (thus not persistable in Sugar). This would not create a true Sugar Activity, but probably worth trying as a start.
    • By programming the Activity as "individual Squeak classes" which are then exported as a changeset, wrapped as an XO bundle, and re-imported to Etoys on activity startup. The classes state can be programatically stored on Journal via Datastore, using the Squeak Etoys interface to DBus. A typical way to distribute a Smalltalk or Squeak project is to distribute a custom image. Because of space restrictions on Sugar, this is distributing only a script (which contains changeset), that is loaded into the default Etoys image on Activity startup, interacting with Sugar via DBus. This is the method which will be described in this blog.
    What is Etoys Freecell?

    It is the Squeak Freecell game converted into a Sugar activity by Bert Freudenberg. It will be used as an example in some follow up posts: http://activities.sugarlabs.org/en-US/sugar/search?q=freecell&cat=all.
    -
    -

    Followers