sugarbot's aim is to provide testing and automation facilities for the OLPC Project's Sugar GUI. The project must first identify and evaluate possible implementation options, and then implement the best choice. Although it has a Sugar focus, sugarbot should be easily extensible to other Python-based GUI's.

Sunday, June 8, 2008

Multiple-Initialization

A commenter (Michael Stone) asked for a bit more information on the multiple-initialization issues that I ran into. The issue first appeared when I first started the project, and I resolved the issue with a runtime inheritance hack. The general idea is:

The sugarbot object makes itself inherit from the other class, then calls __init__(self, self.handle) so that the Activity gets initialized the way that it normally would. This was not how it was originally set up (because it did not work the way it was originally set up). At first, I just assumed that I could do the following:
self.parentClass = someOtherActivityClass
sugarbot.bases = (self.parentClass,)
self.parentClass.init(self,self.handle)
…and have everything work. Unfortunately, certain calls (calling activity.Activity.__init__ explicitly, to initialize the activity being one of those) only like to be called by the Activity instance that it expects the call to come from. Otherwise, the excrement comes into contact with the rotary cooling device.
launchedActivity = someOtherActivity(self,handle)
An issue that I’m facing is that, with the current way of instantiating Activities, it is not possible (to my knowledge) to terminate the spawned activity without causing the whole process to terminate. I think the way to resolve this is going to (ultimately) be to automate the Sugar GUI itself, so that I can re-launch the sugarbot Activity after it terminates. It will somehow know (or perhaps have this information provided to it) to run the next automation script or the like.

Example Activity:
from sugar.activity import activity
import sys, os
import gtk
class exampleActivity(activity.Activity):
def init(self, handle):
# With or without the following call, everything freaks out.
activity.Activity.init(self,handle)
# Add the path to the activity
sys.path.append(pathToCalculateActivity)
# Import and instantiate the activity
from calculate import Calculate
launchedActivity = Calculate(self,handle)

No comments: