Difference between revisions of "Development Team/Almanac/sugar.activity.activity"

From Sugar Labs
Jump to navigation Jump to search
Line 14: Line 14:
  
  
== Class: ActivityToolbar ==
+
== Class: ActivityToolbar, ActivityToolbox ==
  
 
=== 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? ===
Line 26: Line 26:
 
         self.set_toolbox(toolbox)
 
         self.set_toolbox(toolbox)
 
         toolbox.show()
 
         toolbox.show()
 +
 +
== Class: EditToolbar ==
 +
 +
=== How do I add a standard edit toolbar to my activity? ===
 +
The activity package has a standard edit toolbar with the following Members:
 +
* undo  -- the undo button
 +
* redo  -- the redo button
 +
* copy  -- the copy button
 +
* paste -- the paste button
 +
* separator -- A separator between undo/redo and copy/paste
 +
 +
You can create a standard edit tool bar using code similar to the following in the __init__ method of your activity's class after you have created a toolbox:
 +
 +
        #### EDIT TOOLBAR
 +
        # Create the edit toolbar:
 +
        self._edit_toolbar = activity.EditToolbar()
 +
        # Add the edit toolbar:
 +
        toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
 +
        # And make it visible:
 +
        self._edit_toolbar.show()

Revision as of 11:24, 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, ActivityToolbox

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()

Class: EditToolbar

How do I add a standard edit toolbar to my activity?

The activity package has a standard edit toolbar with the following Members:

  • undo -- the undo button
  • redo -- the redo button
  • copy -- the copy button
  • paste -- the paste button
  • separator -- A separator between undo/redo and copy/paste

You can create a standard edit tool bar using code similar to the following in the __init__ method of your activity's class after you have created a toolbox:

       #### EDIT TOOLBAR
       # Create the edit toolbar:
       self._edit_toolbar = activity.EditToolbar()
       # Add the edit toolbar:
       toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
       # And make it visible:
       self._edit_toolbar.show()