Activity tutorial: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 16: Line 16:
show_launcher = yes
show_launcher = yes


Design an icon for your activity.
Design an icon for your activity. The file name should match the one specified in the info. In this case "activity-helloworld.svg".


<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
Line 26: Line 26:
<rect x="1" y="1" width="48" height="48" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2"/>
<rect x="1" y="1" width="48" height="48" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2"/>
</svg>
</svg>

Write the setup.py script, which in most cases will look like this:

#!/usr/bin/python
from sugar.activity import bundlebuilder
bundlebuilder.start()

Code your activity. Module and class names should match those specified in the exec field of the info.

import logging
from sugar.activity.Activity import Activity
import sys, os
import gtk
class HelloWorldActivity(Activity):
# This is a callback function. The data arguments are ignored
# in this example. More on callbacks below.
def hello(self, widget, data=None):
logging.info('Hello World')
def __init__(self):
Activity.__init__(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)
# This packs the button into ourselves (a Sugar window).
self.add(self.button)
# The final step is to display this newly created widget.
self.button.show()
self.set_title('Hello World')


[[Category:Sugar]]
[[Category:Sugar]]

Revision as of 10:54, 7 February 2007

  This page is monitored by the OLPC team.

Create the package directory structure.

hello.activity
hello.activity/activity

Write the activity.info file, which describes your bundle.

[Activity]
name = HelloWorld
service_name = com.ywwg.HelloWorldActivity
exec = sugar-activity-factory HelloWorldActivity.HelloWorldActivity
icon = activity-helloworld
activity_version = 1
show_launcher = yes

Design an icon for your activity. The file name should match the one specified in the info. In this case "activity-helloworld.svg".

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
  <!ENTITY fill_color "#FFFFFF">
  <!ENTITY stroke_color "#000000">
]>
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50">
  <rect x="1" y="1" width="48" height="48" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2"/>
</svg>

Write the setup.py script, which in most cases will look like this:

#!/usr/bin/python
from sugar.activity import bundlebuilder
bundlebuilder.start()

Code your activity. Module and class names should match those specified in the exec field of the info.

import logging
from sugar.activity.Activity import Activity

import sys, os
import gtk

class HelloWorldActivity(Activity):
    # This is a callback function. The data arguments are ignored
    # in this example. More on callbacks below.
    def hello(self, widget, data=None):
        logging.info('Hello World')

    def __init__(self):
        Activity.__init__(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)

        # This packs the button into ourselves (a Sugar window).
        self.add(self.button)

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

        self.set_title('Hello World')