# python import import os, sys # gettext import from gettext import gettext as _ # sugar import from sugar.activity import activity # add lib path to current python path BUNDLE = activity.get_bundle_path() sys.path.append(os.path.join(BUNDLE, 'parts', 'pip', 'lib', 'python2.7', 'site-packages')) sys.path.append(os.path.join(BUNDLE, 'clone', 'semanticxo', 'src')) sys.path.append(os.path.join(BUNDLE, 'clone', 'olpcfr')) # semanticxo import from semanticxo.datastore import TripleStore # triplestore runner import and start from olpcfr.semanticxo import Runner Runner().run() # {{package}} ui import from {{package}}.ui import toolbar def _toolbar_changed(toolbox, page, activity_): """Catch toolbox activity tab focus to display settings screen. """ # is the activity tab? if page == 0: pass else: pass # propagate it return True class {{package.capitalize()}}Activity(activity.Activity): def __init__(self, handle): # init parents activity.Activity.__init__(self, handle) self.max_participants = 1 # init toolbar self.__init_toolbar() # screen registry init self.__screens = dict() # init datastore self.datastore = TripleStore() # set default screen self.change_screen('default') def change_screen(self, name): # init screen if not already initialized if name not in self.__screens: mod_name = '{{package}}.ui.screens.%s' % name cls_name = ''.join([n.capitalize() for n in name.split('_')]) # import and init mod = __import__(mod_name, globals(), locals(), [""]) cls = getattr(mod, cls_name) self.__screens[name] = cls(self) # get and show the screen _scr = self.__screens[name] _scr._show() def __init_toolbar(self): """Keep an example of how to manage toolbar in our webapp ... """ # get toolbox self._toolbox = activity.ActivityToolbox(self) # add tool bars self.set_toolbox(self._toolbox) # show self._toolbox.show() # init toolbars for _n in ['default']: # init toolbar toolbar.Toolbar(self, name=_n) # set default tab self._toolbox.set_current_toolbar(1) # .. self._toolbox.connect('current-toolbar-changed', _toolbar_changed, self) def read_file(self, file_path): # .. should be overriden pass def write_file(self, file_path): # .. should be overriden pass def close(self, skip_save=False): # stop the triplestore Runner().proc.kill() # call parent activity.Activity.close(self, skip_save=True)