Sugar.activity.registry: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
= Class: ActivityInfo =
= ActivityRegistry =


= Class: ActivityRegistry =
The ActivityRegistry class can be used to help you get information about the activities that are installed on the current XO.
The ActivityRegistry class can be used to help you get information about the activities that are installed on the current XO.


Line 15: Line 18:
for ai in ar.get_activities():
for ai in ar.get_activities():
print ai.name
print ai.name
</pre>


=== How do I find all the activities whose name matches a certain string? ===
The find_activity() method in ActivityRegistry takes a string and returns a list of ActivityInfo objects, each of which represents an activity whose name matches the string passed. You can pass the full name of an activity (eg. 'Terminal', or 'Web') or you can pass part of the name (eg. 'term'). Note that this method may find multiple activities that match your search, so make sure you check for how many have been returned if you are looking for a specific activity. The find_activity() method is not case sensitive.

<pre>
from sugar.activity import registry
...
#Create a new ActivityRegistry object
ar = registry.ActivityRegistry()

# search for activities with a name like 'annot'
aiList = ar.find_activity('terminal')
# for each ActivityInfo object (representing each activity) found, print out the activity name.
for ai in aiList:
print ai.name

</pre>
</pre>

Revision as of 20:03, 30 June 2008

Class: ActivityInfo

Class: ActivityRegistry

The ActivityRegistry class can be used to help you get information about the activities that are installed on the current XO.

How do I get a list of all the activities that are available on an XO?

Use the get_activities() method in ActivityRegistry. This will return a list of ActivityInfo objects - one for each activity installed. You can then iterate through this list.

from sugar.activity import registry
...
        #Create a new ActivityRegistry object
        ar = registry.ActivityRegistry()

        # use get_activities() to get a list of ActivityInfo objects and iterate through each
        for ai in ar.get_activities():
            print ai.name


How do I find all the activities whose name matches a certain string?

The find_activity() method in ActivityRegistry takes a string and returns a list of ActivityInfo objects, each of which represents an activity whose name matches the string passed. You can pass the full name of an activity (eg. 'Terminal', or 'Web') or you can pass part of the name (eg. 'term'). Note that this method may find multiple activities that match your search, so make sure you check for how many have been returned if you are looking for a specific activity. The find_activity() method is not case sensitive.

from sugar.activity import registry
...
        #Create a new ActivityRegistry object
        ar = registry.ActivityRegistry()

        # search for activities with a name like 'annot'
        aiList = ar.find_activity('terminal')
        # for each ActivityInfo object (representing each activity) found, print out the activity name. 
        for ai in aiList:
            print ai.name