Tuesday, August 7, 2012

The best open source project to work with is "Sugar" primarily developed by SugarLabs and developers, contributors around the world. As a Sugar Evangelist, I take this opportunity to share this post that describes on how you can get started with your first Sugar activity. The program that runs on Sugar Desktop environment is called as an Activity.

Prerequisites:

Familiarity with Python and PyGTK(Python interface for GUI programming using GTK+)

Sugar Desktop environment( installed, build or emulator on qemu)

GTK+ packages installed on you Linux flavor.

The example Activity shared in the following section has been tested on Fedora 17( Beefy Miracle).

1. Create a directory structure :

mkdir -p KartikActivity.activity/activity

2.Create activity.info :

Create a file inside the "activity" sub directory with name "activity.info" to describe your bundle in the activity sub-directory. The Activity Bundles specification explain in detail the meaning of each field.Write downs attribute names and corresponding values in this file as :

3. Activity Icon:

Design an icon for your activity by following the instructions on making icons for Sugar and place it in the activity sub-directory. The file name should match the icon file name specified in the info file (e.g. myicon.svg).

I used the same icon as is used in paint :

4. Create setup.py:

Write the setup.py script in the top level directory (e.g. KartikActivity.activity/setup.py). The content should be like:

from sugar.activity import bundlebuilderbundlebuilder.start()

A more advanced version, which supports building activity bundles without Sugar installed, looks like this:

# 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) self.set_toolbox(toolbox) toolbox.show()

# 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. self.set_canvas(self.button)

# The final step is to display this newly created widget. self.button.show()

print "AT END OF THE CLASS"

6. Create a MANIFEST:

(e.g. KartikActivity.activity/MANIFEST), containing the list of the files (relative to the directory that the MANIFEST is in) to include in the package. (Note: Be sure not to leave blank lines at the end of the file.) This script does that in linux (run it from within the KartikActivity.activity directory):

cd KartikActivity.activityfind . -type f | sed 's,^./,,g' > MANIFEST

Content of MANIFEST should look like this:

activity/myicon.svgactivity/activity.infoMANIFESTKartik.pysetup.py

7. Give permissions:

Make sure that all your python files have the required permissions to be used.

chmod a+x setup.pychmod a+x Kartik.py

8. Bundle your Activity:

Setup your bundle for development (must be user olpc when you do this) to become user olpc, type: su - olpc

If you are prompted for a password, trying using: su

python setup.py dev

This just creates a symlink to your activity folder in ~/Activities, so that Sugar can find your activity.

9. Run your Activity !:

Restart Sugar using Ctrl-Alt-Erase and your activity will appear in the
interface! (NOTE: By default, the Home view shows only the favorite
activities. You should press Ctrl+2 or go the right-upper corner and
change to the List View)