Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/creactiweb/_templates/+package+/activity.py_tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'creactiweb/_templates/+package+/activity.py_tmpl')
-rw-r--r--creactiweb/_templates/+package+/activity.py_tmpl131
1 files changed, 131 insertions, 0 deletions
diff --git a/creactiweb/_templates/+package+/activity.py_tmpl b/creactiweb/_templates/+package+/activity.py_tmpl
new file mode 100644
index 0000000..5fa7462
--- /dev/null
+++ b/creactiweb/_templates/+package+/activity.py_tmpl
@@ -0,0 +1,131 @@
+# python import
+import os, sys, threading, time
+# gettext import
+from gettext import gettext as _
+
+# sugar import
+from sugar.activity import activity
+# hulahop import
+from hulahop.webview import WebView
+
+# add lib path to current python path
+sys.path.append(os.path.join(activity.get_bundle_path(), 'lib'))
+
+# server import
+from server import config
+from server.flask import app, run_app, logger
+
+# {{package}} import
+from {{package}}.controllers import app
+
+
+# get port from config
+_port = config.Config().get('server>port', type_=int)
+_port = '5000' if _port is None or _port == '' else _port
+# ..
+URL_BASE = 'http://localhost:%s' % _port
+
+
+class ThreadServer(threading.Thread):
+
+ def __init__(self, activity_):
+ # init parent
+ threading.Thread.__init__(self)
+ # main flag
+ self._die = False
+ # start right now
+ self.start()
+
+ def kill(self):
+ self._die = True
+
+ def run(self):
+ # do run
+ run_app()
+ # ...
+ while self._die is False:
+ continue
+ # ..
+ del app
+
+
+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('/')
+ else:
+ pass
+ # propagate it
+ return True
+
+
+class {{package.capitalize()}}Activity(activity.Activity):
+
+ def __init__(self, handle):
+ # init thread server
+ self._thread = ThreadServer(self)
+ # ..
+ time.sleep(5)
+ # init parents
+ activity.Activity.__init__(self, handle)
+ self.max_participants = 1
+ # ..
+ 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('')
+
+ def get_toolbox(self):
+ return self._toolbox
+
+ def change_screen(self, name):
+ self.web_view.load_uri('%s/%s' % (URL_BASE, name))
+
+ def __init_toolbar(self):
+ """Keep an example of how to manage toolbar in our webapp ...
+ """
+ # {{package}} ui import
+ from {{package}}.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 ['menu']:
+ # init toolbar
+ _t = toolbar.Toolbar(self, name=_n)
+ # if default toolbar .. set default screen
+ 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 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 thread
+ self._thread.kill()
+ # ..
+ activity.Activity.close(self, skip_save=True)