Activity Team/Compatibility Tips: Difference between revisions
| Line 51: | Line 51: | ||
[[Category:Activity Team]] | [[Category:Activity Team]] | ||
=== Sugar toolbar version === | |||
Sugar toolbars changed in Sucrose v0.86. You can detect which version you are running by checking for an ImportError: | |||
try: # 0.86 toolbar widgets | |||
from sugar.bundle.activitybundle import ActivityBundle | |||
from sugar.activity.widgets import ActivityToolbarButton | |||
from sugar.activity.widgets import StopButton | |||
from sugar.graphics.toolbarbox import ToolbarBox | |||
from sugar.graphics.toolbarbox import ToolbarButton | |||
_new_sugar_system = True | |||
except ImportError: | |||
_new_sugar_system = False | |||
Use the flag to determine whether to create old-style or new toolbars: | |||
if _new_sugar_system: | |||
# Use 0.86+ toolbar design | |||
toolbar_box = ToolbarBox() | |||
... | |||
else: | |||
# Use pre-0.86 toolbar design | |||
self.toolbox = activity.ActivityToolbox(self) | |||
... | |||
You can share callbacks between versions, but take care to make sure you are using the proper context: | |||
# 0.86+ | |||
fullscreen_button.connect('clicked', self._do_fullscreen_cb) | |||
or | |||
# pre-0.86 | |||
self.viewToolbar = ViewToolbar(self) | |||
class ViewToolbar(gtk.Toolbar): | |||
def __init__(self, pc): | |||
self.activity = pc | |||
self.activity.fullscreen_button.connect('clicked', self.activity._do_fullscreen_cb) | |||