diff options
Diffstat (limited to 'nutriweb/activity.py')
-rw-r--r-- | nutriweb/activity.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/nutriweb/activity.py b/nutriweb/activity.py new file mode 100644 index 0000000..444af58 --- /dev/null +++ b/nutriweb/activity.py @@ -0,0 +1,88 @@ + +# python import +import logging +# .. +from gettext import gettext as _ + +# sugar import +from sugar.activity import activity +# hulahop import +from hulahop.webview import WebView + +# nutriweb import +import app_main +# .. +from nutriweb.ui import toolbar + +# get application logger +logger = logging.getLogger('nutriweb') + + +URL_BASE = 'http://localhost:5000/' + + +def _toolbar_changed(toolbox, page, activity_): + """Catch toolbox activity tab focus to display settings screen. + """ + # is the activity tab? + if page == 0: + # show the activity screen + activity_._change_screen(toolbar=None, name='activity') + else: + pass + # propagate it + return True + + +class NutriWebActivity(activity.Activity, app_main.nutriweb): + + def __init__(self, handle): + # init parents + app_main.nutriweb.__init__(self) + activity.Activity.__init__(self, handle) + # .. + self.max_participants = 1 + # get toolbox + self._toolbox = activity.ActivityToolbox(self) + # add tool bars + self.set_toolbox(self._toolbox) + # ... + self.web_view = WebView() + self.set_canvas(self.web_view) + self.web_view.show() + # show + self._toolbox.show() + # tmp var + _toolbar = None + # init toolbars + for _n in ['eating', 'spare-time']: + # init toolbar + _t = toolbar.Toolbar(self, name=_n) + # if default toolbar .. set default screen + if _n == 'eating': + self._change_screen(_t) + _toolbar = _t + # set default tab + self._toolbox.set_current_toolbar(1) + # .. + self._toolbox.connect('current-toolbar-changed', _toolbar_changed, self) + + def get_toolbox(self): + return self._toolbox + + def _change_screen(self, toolbar=None, name=None): + # ... + _name = toolbar.name if name is None else name + # ... + self.web_view.load_uri(URL_BASE + _name) + + def read_file(self, file_path): + app_main.nutriweb.read_file(self, file_path) + + def write_file(self, file_path): + app_main.nutriweb.write_file(self, file_path) + + def close(self, skip_save=False): + app_main.nutriweb.close(self) + activity.Activity.close(self, skip_save=True) + |