diff options
author | florent <florent.pigout@gmail.com> | 2011-07-10 17:54:53 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-07-10 17:54:53 (GMT) |
commit | cad5eeaa68e96dd7fc8470e5a70a6453d3ce1c86 (patch) | |
tree | 9167129878c43387a3ac5aa8ada403dfe03e52d6 | |
parent | 17e69fa91ee9df58ca5479125087776f89228cb0 (diff) |
add simple toolbar management sample - use it or leave it!
-rwxr-xr-x | activity/activity.info | 4 | ||||
-rw-r--r-- | atoideweb/activity.py | 64 | ||||
-rw-r--r-- | atoideweb/controllers/index.py | 14 | ||||
-rw-r--r-- | atoideweb/ui/toolbar.py | 73 | ||||
-rw-r--r-- | config.ini | 5 | ||||
-rw-r--r-- | run.py | 16 | ||||
-rw-r--r-- | templates/index.html | 4 | ||||
-rw-r--r-- | templates/layout.html | 13 |
8 files changed, 102 insertions, 91 deletions
diff --git a/activity/activity.info b/activity/activity.info index 3106a37..726ff01 100755 --- a/activity/activity.info +++ b/activity/activity.info @@ -2,6 +2,6 @@ name = AToiDeWeb activity_version = 1 service_name = org.laptop.AToiDeWebActivity -icon = activity-AToiDeWeb -class = AToiDeWeb.activity.AToiDeWebActivity +icon = activity-atoideweb +class = atoideweb.activity.AToiDeWebActivity license = gplv3 diff --git a/atoideweb/activity.py b/atoideweb/activity.py index 9f34d83..5331be8 100644 --- a/atoideweb/activity.py +++ b/atoideweb/activity.py @@ -1,7 +1,6 @@ - # python import import logging -# .. +# gettext import from gettext import gettext as _ # sugar import @@ -9,13 +8,12 @@ from sugar.activity import activity # hulahop import from hulahop.webview import WebView -# atoideweb import +# atoideweb import - first to update lib path import run -# .. -from atoideweb.ui import toolbar -# get application logger -logger = logging.getLogger(run.APP_NAME) +# server import +from server import config +from server.flask import logger URL_BASE = 'http://localhost:5000/' @@ -27,55 +25,65 @@ def _toolbar_changed(toolbox, page, activity_): # is the activity tab? if page == 0: # show the activity screen - activity_._change_screen(toolbar=None, name='activity') + activity_.change_screen('activity') else: pass # propagate it return True -class AToiDeWebActivity(activity.Activity, run.atoideweb): +class AToiDeWebActivity(run.Server, activity.Activity): def __init__(self, handle): # init parents - run.atoideweb.__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) + # .. + run.Server.__init__(self) + # .. + if config.Config().get('activity>use-toolbar', type_=bool): + self.__init_toolbar() + else + pass # ... self.web_view = WebView() self.set_canvas(self.web_view) self.web_view.show() + # ... + self.change_screen('atoideweb') + + def get_toolbox(self): + return self._toolbox + + def change_screen(self, name): + self.web_view.load_uri(URL_BASE + name) + + def __init_toolbar(self): + """Keep an example of how to manage toolbar in our webapp ... + """ + # atoideweb ui imort + from atoideweb.ui import toolbar + # get toolbox + self._toolbox = activity.ActivityToolbox(self) + # add tool bars + self.set_toolbox(self._toolbox) # show self._toolbox.show() # tmp var _toolbar = None # init toolbars - for _n in ['eating', 'spare-time']: + for _n in ['menu']: # init toolbar _t = toolbar.Toolbar(self, name=_n) # if default toolbar .. set default screen - if _n == 'eating': - self._change_screen(_t) + if _n == 'post': + self.change_screen(n_) _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): # .. should be overriden pass @@ -85,5 +93,5 @@ class AToiDeWebActivity(activity.Activity, run.atoideweb): pass def close(self, skip_save=False): - run.atoideweb.close(self) + run.Server.close(self) activity.Activity.close(self, skip_save=True) diff --git a/atoideweb/controllers/index.py b/atoideweb/controllers/index.py index 7d0e1af..b961299 100644 --- a/atoideweb/controllers/index.py +++ b/atoideweb/controllers/index.py @@ -10,5 +10,15 @@ from atoideweb.controllers import post, ajax @app.route('/') def index(): - logger.debug(_('Welcome!')) - return 'Welcome!' + # prepare result + _content = {'content': _('atdw - Welcome!')} + # render result + return render('index.html', **_content) + + +@app.route('/<name>') +def page(name): + # prepare result + _content = {'content': _('atdw - Welcome on %s!' % name)} + # render result + return render('index.html', **_content) diff --git a/atoideweb/ui/toolbar.py b/atoideweb/ui/toolbar.py index 0c0bc03..5c6d820 100644 --- a/atoideweb/ui/toolbar.py +++ b/atoideweb/ui/toolbar.py @@ -14,61 +14,37 @@ from sugar.activity import activity # sugar import from sugar.graphics.toolbutton import ToolButton -# atoideweb import -from atoideweb.tools import config -# from atoideweb.ui import screens +# server import +from server.flask import logger -# get application logger -logger = logging.getLogger('atoideweb') +def _cb_next(widget, toolbar, next_): + # update current screen + toolbar.activity.change_screen(next_) -def _cb_default(widget, toolbar): - # DEBUG - logger.debug('[toolbar] cb - toolbar.name: %s' % toolbar.name) BUTTONS = { - 'add' : ['list-add', _cb_default], - 'back' : ['edit-undo', _cb_default], - 'backward' : ['media-seek-backward', _cb_default], - 'forward' : ['media-seek-forward', _cb_default], - 'open' : ['media', _cb_default], - 'pause' : ['media-playback-pause', _cb_default], - 'play' : ['media-playback-start', _cb_default], - 'remove' : ['list-remove', _cb_default], - 'separator' : [None, None], - 'stop' : ['media-playback-stop', _cb_default], + 'post' : ['document-generic', _cb_next], + 'ajax' : ['document-generic', _cb_next], + 'separator' : [None, None] } + TOOLBARS = { - 'eating' : [ - ['stop', 'play', 'slider', - 'separator', - 'add'], - [] - ], - 'spare-time' : [ - ['stop', 'play',], + 'menu' : [ + ['post', 'ajax'], [] ], } TITLES = { - 'eating' : { - 'toolbox': _('Graphic'), - 'buttons': { - 'play': _('Play'), - 'slider': _('Progress Bar'), - 'stop': _('Stop'), - 'add': _('Add'), - } - }, - 'spare-time' : { - 'toolbox': None, + 'menu' : { + 'toolbox': _('Menu'), 'buttons': { - 'play': _('Play'), - 'stop': _('Stop'), + 'post': _('Post'), + 'ajax': _('Ajax') } - }, + } } @@ -137,19 +113,8 @@ class Toolbar(gtk.Toolbar): self._add_button(_b) def _on_focus(self, widget, direction): - if self.name in ['graphics_add', 'sounds_add']: - self._switch(self.name.replace('_add', '')) - else: - # update current screen - self.activity._change_screen(self) - if 'add' in self._button_dict: - # enable or disble add - _mode = config.Config().get('activity>mode') - _conf = config.Config().get('mode>%s' % _mode, type_=list) - # .. - self._button_dict['add'].set_sensitive('remove' in _conf) - else: - pass + # update current screen + self.activity.change_screen(self.name) def _has_button(self, button_id): return button_id in self._button_dict @@ -173,7 +138,7 @@ class Toolbar(gtk.Toolbar): if _cb is None: pass else: - _buton.connect('clicked', _cb, self) + _buton.connect('clicked', _cb, self, button_id) # ?? else: # ERROR @@ -1,2 +1,7 @@ [activity] +# ... name = atoideweb +# ... +debug = False +# ... +use-toolbar = True @@ -1,13 +1,21 @@ # python import -import sys +import os, sys + +# sugar or debug root path factory +try: + from sugar.activity import activity + ROOT_PATH = activity.get_bundle_path() +except Exception, e: + ROOT_PATH = '.' + # add lib path to current python path -sys.path.append('lib') +sys.path.append(os.path.join(ROOT_PATH, 'lib')) # import server first from server import Server -# atoideweb import -from atoideweb.controllers import app +# .. +from atoideweb import controllers # simple server entry point if __name__ == "__main__": diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..69a4778 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,4 @@ +{% extends "layout.html" %} +{% block content %} +<h1>{{ content }}</h1> +{% endblock %} diff --git a/templates/layout.html b/templates/layout.html index a00af4d..19d7b93 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -4,10 +4,21 @@ {% from "_helpers.html" import options_ajax %} <head> <title>{{ title }}</title> - <script src='/static/js/jquery.js' }}" type="text/javascript"></script> + <script src="/static/js/jquery.js" type="text/javascript"></script> {% block head %}{% endblock %} </head> <body> + <ul> + <li> + <a href="/post">post-sample</a> + </li> + <li> + <a href="/ajax">ajax-sample</a> + </li> + <li> + <a href="/quit">quit</a> + </li> + </ul> {% block content %}{% endblock %} </body> |