Changes

Jump to navigation Jump to search
m
Line 1: Line 1: −
{{Sugar Almanac}}
+
{{Almanac}}
{{Sugar Almanac TOC}}
+
{{Almanac TOC}}
 
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.  
   Line 40: Line 40:  
         #print out the name of this activity
 
         #print out the name of this activity
 
         print activity.get_bundle_name()
 
         print activity.get_bundle_name()
 +
 +
=== How do I get the version number of my activity? ===
 +
 +
        #print out the version number of this activity
 +
        print os.environ['SUGAR_BUNDLE_VERSION']
    
= Class: Activity =
 
= Class: Activity =
Line 54: Line 59:  
         self._top_canvas_box = gtk.VBox()
 
         self._top_canvas_box = gtk.VBox()
 
         self.set_canvas(self._top_canvas_box)
 
         self.set_canvas(self._top_canvas_box)
 +
 +
=== How do I ensure the canvas is of maximum size and how do I get the size the canvas? ===
    
=== What are activity id's? How do I obtain the activity id for an instance of my activity? ===
 
=== What are activity id's? How do I obtain the activity id for an instance of my activity? ===
Line 145: Line 152:  
=== How do I run a specific block of code (eg. for cleanup) when my activity is closed? ===
 
=== How do I run a specific block of code (eg. for cleanup) when my activity is closed? ===
   −
The activity.Activity class has a can_close() method that you should override in any of your own activities where you want to run some specific code related
+
The activity.Activity class has a can_close() method that you should override in any of your own activities where you want to run some specific code when an activity is closed.
 +
 
 +
<pre>
 +
from sugar.activity import activity
 +
...
 +
class AnnotateActivity(activity.Activity):
 +
  def __init__(self, handle):
 +
      # Put activity initialization code in here
 +
      ...
 +
 
 +
  #Override activity.Activity's can_close method
 +
  def can_close(self):     
 +
      ...
 +
      # PUT CLOSING CODE HERE
 +
      ...
 +
 
 +
      #Return True at the end to ensure activity does close properly
 +
      return True
 +
</pre>
    +
It is important to note that the can_close method will only be called when the activity is cleanly closed using the "Stop" button on the Activity Toolbar. In cases where an activity is terminated using a kill signal or through some other OS-driven method, then the can_close() method will not necessarily be called.
    
=== How do I programmatically make my activity available for sharing? ===
 
=== How do I programmatically make my activity available for sharing? ===
Line 189: Line 215:  
</pre>
 
</pre>
   −
= Class: ActivityToolbox ([[Sugar.graphics.toolbox|Toolbox]])=
+
=== How do I know if my activity is being started from the Journal? ===
 +
 
 +
You can check handle.object_id in the constructor of your Activity class:
 +
 
 +
<pre>
 +
from sugar.activity import activity
 +
...
 +
class AnnotateActivity(activity.Activity):
 +
    #### Method: __init__, initialize this AnnotateActivity instance
 +
    def __init__(self, handle):
 +
        ...
 +
        if handle.object_id is None:
 +
            print "Activity is started anew (from the home view)"
 +
        else:
 +
            print "Activity is started from the journal and the object id is %s" % handle.object_id
 +
        ...
 +
</pre>
 +
 
 +
= Class: ActivityToolbox ([[Development Team/Almanac/sugar.graphics.toolbox|Toolbox]])=
    
=== What is the standard toolbox needed in most activities and how do I create it? ===
 
=== What is the standard toolbox needed in most activities and how do I create it? ===

Navigation menu