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.

Saturday, July 12, 2008

Automated Launching: Go!

Using just about the most obscure Python code I have ever written, I have just made sugarbot fully automatable.

It requires a small patch to main.py in the main Sugar directory (/usr/share/sugar/shell/main.py), and adding a file to the same directory. It launches sugarbot by simulating a click on the sugarbot icon in the frame.

Will put the code up on SVN later, it's Pizza time now!

Important Code:
# =========================================================
# The magnitude of this hack compares favorably with the
# current national debt.
boxChildren = self.shell.get_frame()._bottom_panel._bg.get_children()
tray = [k for k in boxChildren if isinstance(k,ActivitiesTray)]
if tray:
children = tray[0]._tray.get_children()
else:
return
activities = [k for k in children if isinstance(k, ActivityButton)]
sbList = [k for k in activities if k._activity_info.name=="sugarbot"]
# ========================================================

if len(sbList) > 0: sbList[0].emit('clicked')

main.py patch:
model = ShellModel()
shell = Shell(model)
service = ShellService(shell)

if os.environ.has_key("SUGARBOT_EMULATOR"):
from sugarbotlauncher import SugarbotLauncher
sbLauncher = SugarbotLauncher(model,shell,service)

try:
gtk.main()
except KeyboardInterrupt:
print 'Ctrl+C pressed, exiting...'

No comments: