Jump to: navigation, search

The tutorial explains step by step how to create the Hello World activity bundle.

It assumes you have already installed a Sugar development environment.

Create the bundle directory structure:

mkdir HelloWorld.activity
mkdir HelloWorld.activity/activity

Write the file, to describe your bundle in the activity sub-directory (e.g. HelloWorld.activity/activity/ The Activity Bundles specification explain in detail the meaning of each field.

 name = HelloWorld
 service_name = com.ywwg.HelloWorldActivity
 class = HelloWorldActivity.HelloWorldActivity
 icon = activity-helloworld
 activity_version = 1
 show_launcher = yes

Design an icon for your activity, according to the icon format and place it in the activity sub-directory. The file name should match the icon file name specified in the info file (e.g. activity-helloworld.svg).

 File: actividad-holamundo.svg
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "" [
   <!ENTITY fill_color "#FFFFFF">
   <!ENTITY stroke_color "#000000">
 <svg xmlns="" width="50" height="50">
   <rect x="1" y="1" width="48" height="48"

Write the script in the top level directory (e.g. HelloWorldActivity.activity/, which in most cases will look like this:

 from sugar.activity import bundlebuilder

Code your activity. The name you specified in the .info file as "class" is the name of the class which runs your code. For the file above, we specify a top-level module named HelloWorldActivity.HelloWorldActivity (please note that the use of uppercase names in module names is considered poor Python style, feel free to use an activity name with more standard style names).

 from sugar.activity import activity
 import logging
 import sys, os
 import gtk
 class HelloWorldActivity(activity.Activity):
     def hello(self, widget, data=None):'Hello World')
     def __init__(self, handle):
         print "running activity init", handle
         activity.Activity.__init__(self, handle)
         print "activity running"
         self.set_title('Hello World')
         # Creates the Toolbox. It contains the Activity Toolbar, which is the
         # bar that appears on every Sugar window and contains essential
         # functionalities, such as the 'Collaborate' and 'Close' buttons.
         toolbox = activity.ActivityToolbox(self)
         # Creates a new button with the label "Hello World".
         self.button = gtk.Button("Hello World")
         # When the button receives the "clicked" signal, it will call the
         # function hello() passing it None as its argument.  The hello()
         # function is defined above.
         self.button.connect("clicked", self.hello, None)
         # Set the button to be our canvas. The canvas is the main section of
         # every Sugar Window. It fills all the area below the toolbox.
         # The final step is to display this newly created widget.
         print "AT END OF THE CLASS"

Create a MANIFEST (e.g. HelloWorldActivity.activity/MANIFEST), containing the list of the files to include in the package. (Note: Be sure not to leave blank lines at the end of the file.)


The structure of the directory now must see as:


Setup your bundle for development

./ dev

(It appears this just creates a symlink in ~/Activities .)

If you now run sugar the activity icon should be visible on the frame. (You have to restart sugar to get it to pick up the change if you just installed it. Hit ctrl-alt-erase.)

Personal tools
  • Log in
  • Login with OpenID
About OLPC
About the laptop
About the tablet
OLPC wiki
In other languages