Sugar.activity.activity: Difference between revisions

From OLPC
Jump to navigation Jump to search
Line 1: Line 1:
The sugar.activity.activity package includes several important classes that are needed to run a basic activity.
The sugar.activity.activity package includes several important classes that are needed to run a basic activity.


<h1>Class: Activity</h1>
== Class: Activity ==
=== How do I create a new activity that is derived from the base Activity class? ===
=== How do I create a new activity that is derived from the base Activity class? ===


Line 12: Line 12:
def __init__(self, handle):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
activity.Activity.__init__(self, handle)


== Class: ActivityToolbar ==


=== What is the standard toolbar needed in most activities and how do I create it? ===
=== What is the standard toolbar needed in most activities and how do I create it? ===

Revision as of 15:12, 29 May 2008

The sugar.activity.activity package includes several important classes that are needed to run a basic activity.

Class: Activity

How do I create a new activity that is derived from the base Activity class?

All activities must implement a class derived from the 'Activity' class. The convention is to call it ActivitynameActivity, but this is not required as the activity.info file associated with your activity will tell the sugar-shell which class to start.

from sugar.activity import activity
...
class ToolbarExampleActivity(activity.Activity):

    def __init__(self, handle):
        activity.Activity.__init__(self, handle)


Class: ActivityToolbar

What is the standard toolbar needed in most activities and how do I create it?

The Activity toolbar with the Journal entry title, sharing, Keep and Stop buttons is the most basic toolbar. All activities should have this toolbar. It is easiest to add it to your Activity by using the ActivityToolbox.

       #### CREATE TOOLBOX
       # 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()