This article will learn you how to develop an application for Sugar and the XO, the OLPC project machine. More precisely, In this article, I will use C# and Mono to create a new "activity" which works on the XO and on the Sugar emulator included in the downloadable virtual machine.
About the OLPC project and the XO
Torello Querci is a contributor on the Mono project. Torello wrote one year ago a C#/Sugar binding to let you use Mono to create Sugar Activities. This binding is packaged as a .NET assembly named
Sugar.dll. Most of Sugar API is callable from this assembly. Of course, the
Sugar.dll assembly is need for the sample described here.
Create the project
To create our first activity, we're going to use MonoDevelop. MonoDevelop is a Visual Studio like IDE. So MonoDevelop let you edit and package a Mono application.
- Launch MonoDevelop (Applications/Programming/MonoDevelop),
- Create a new solution (File/New Solution…) Choose a "C# / Gtk# 2.0 Project" template,
- Fill the form with "LabActivity" as name.
public class MainWindow : Sugar.Window
public new static string activityId = "";
public new static string bundleId = "";
public MainWindow(string activityId, string bundleId)
: base("Lab", activityId, bundleId)
this.DeleteEvent += new DeleteEventHandler(OnMainWindowDelete);
VBox vbox = new VBox();
vbox.BorderWidth = 8;
Label _text = new Label("Hello Lab Activity");
Button _button = new Button();
_button.Label = "Quit";
_button.Clicked += new EventHandler(OnClick);
void OnMainWindowDelete(object sender, DeleteEventArgs a)
a.RetVal = true;
void OnClick(object sender, EventArgs a)
If you are a .NET WinForm developer, the Gtk framework should look familiar to you.
MainWindow's constructor is responsible of the window initialization: it creates controls and setup event handlers. The Sugar binding adds the need to inherit from the
Sugar.Window class to access to the low level communication with the Sugar API. More precisely, the main Window should handle the activity's identifier and the instance's identifier. Both values are send to the window manager and should be retrieve from the activity entry point. Here's how:
public static void Main(string args)
if (args.Length > 0)
IEnumerator en = args.GetEnumerator();
activityId = en.Current.ToString();
bundleId = en.Current.ToString();
new MainWindow(activityId, bundleId);
We can now build and run the new application: click on "Project/Run". You should obtain this:
Activities page of the OLPC wiki, you could find all activities downloadable on the XO laptop.
The following screen capture shows a small part of this page. As you could see, downloading a new activity means downloading a .XO file. Let's see what is a ".xo" file and how we can generate this sort of file ?
The manifest file describes all files in the .XO file. The .XO file has two directories:
activity which hold activity's properties and
bin which hold binary files.
Binary files are: Mono bundle for the activity (
labactivity.exe), Gtk# shared libraries (
.so files) and a python script to start activity (
The first file in the activity directory is the activity's icon. This file use the SVG format. SVG is a vectorial format based on XML. The SVG file used here just draws a little square:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY stroke_color "#666666">
<!ENTITY fill_color "#FFFFFF">
Another important file is the
activity.info file. This file contains all properties for the activity. Here is our file:
name = LabActivity
activity_version = 1
host_version = 1
service_name = org.olpcfrance.LabActivity
icon = activity-labactivity
exec = labactivity-activity
activity.info file is just a text file containing values for each property: name, id, link to the icon file, link to the start script, ...
So, as a conclusion, to create the .xo file you should:
- Launch the build for the Mono application,
- Create a Mono bundle,
- Build a
.zip file with all binaries and config files,
- Rename the file from
deploy script included with the source file of the project build automatically the .XO file. You should launch it at the end of each build. At the end of the script, a
LabActivity-1.xo is generated:
Gbrainy application. Gbrainy is a collection of little games based on memory. The following screen capture shows you the application on the XO.
Glade is a window design tool for Gtk. Glade comes with a dedicated designing tool and use a file format based on XML to store resources.
Gettext is the localization tool for Gnome. The
Mono.Unix namespace allow call to Gettext from your C# application. Note that both Gettext and the standard localization mechanism of .NET are usable from Mono. The main advantage of Gettext is to be supported by a large community of developers and to be compliant with lot of common tools like the Pootle server or the Poedit editor.
The following source code comes from the Sugarized Gbrainy application. You could see: the Sugar features, the use of Glade properties (
[Glade.Widget]) and some calls to localization methods (
public class gbrainy
[Glade.Widget("gbrainy")] Gtk.Window app_window;
[Glade.Widget] Box drawing_vbox;
[Glade.Widget] Gtk.Label question_label;
[Glade.Widget] Gtk.Label solution_label;
[Glade.Widget] Gtk.Entry answer_entry;
[Glade.Widget] Gtk.Button answer_button;
[Glade.Widget] Gtk.Button tip_button;
[Glade.Widget] Gtk.Button next_button;
[Glade.Widget] Gtk.Statusbar statusbar;
[Glade.Widget] Gtk.Toolbar toolbar;
const int ok_buttonid = -5;
public gbrainy (string  args, params object  props)
Catalog.Init ("gbrainy", Defines.GNOME_LOCALE_DIR);
IconFactory icon_factory = new IconFactory ();
AddIcon (icon_factory, "math-games", "math-games-32.png");
AddIcon (icon_factory, "memory-games", "memory-games-32.png");
AddIcon (icon_factory, "pause", "pause-32.png");
AddIcon (icon_factory, "resume", "resume-32.png");
AddIcon (icon_factory, "endgame", "endgame-32.png");
AddIcon (icon_factory, "allgames", "allgames-32.png");
AddIcon (icon_factory, "endprogram", "endprogram-32.png");
Glade.XML gXML = new Glade.XML (null, "gbrainy.glade", "gbrainy", null);
Sugar.Activity activity=new Sugar.Activity(app_window, activityId, bundleId);
activity.SetActiveEvent += activeChanged;
toolbar.IconSize = Gtk.IconSize.Dnd;
Tooltips tooltips = new Tooltips ();
ToolButton button = new ToolButton ("allgames");
button.SetTooltip (tooltips, Catalog.GetString ("Play all the games"), null);
button.Label = Catalog.GetString ("All");
button.Clicked += OnAllGames;
toolbar.Insert (button, -1);
This article is an introduction to Sugar development using Mono. Mono allows you to use your .NET and C# skill to create software for the XO laptop, to contribute to the OLPC project and then to provide educative material for the world's poorest children. Why don't take this chance ?
This article comes from a full tutorial on the SugarLabs wiki. A French version is also available on the TechHead Brothers web site. Do not hesitate to contact me for more information on the OLPC project.