Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoideweb/activity.py
diff options
context:
space:
mode:
Diffstat (limited to 'atoideweb/activity.py')
-rw-r--r--atoideweb/activity.py62
1 files changed, 48 insertions, 14 deletions
diff --git a/atoideweb/activity.py b/atoideweb/activity.py
index 5331be8..5215b22 100644
--- a/atoideweb/activity.py
+++ b/atoideweb/activity.py
@@ -1,5 +1,5 @@
# python import
-import logging
+import os, sys, threading, time
# gettext import
from gettext import gettext as _
@@ -8,15 +8,45 @@ from sugar.activity import activity
# hulahop import
from hulahop.webview import WebView
-# atoideweb import - first to update lib path
-import run
+# 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 logger
+from server.flask import app, run_app, logger
+# atoideweb import
+from atoideweb.controllers import app
-URL_BASE = 'http://localhost:5000/'
+
+# 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_):
@@ -25,43 +55,45 @@ def _toolbar_changed(toolbox, page, activity_):
# is the activity tab?
if page == 0:
# show the activity screen
- activity_.change_screen('activity')
+ activity_.change_screen('main')
else:
pass
# propagate it
return True
-class AToiDeWebActivity(run.Server, activity.Activity):
+class AToiDeWebActivity(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
# ..
- run.Server.__init__(self)
- # ..
if config.Config().get('activity>use-toolbar', type_=bool):
self.__init_toolbar()
- else
+ else:
pass
# ...
self.web_view = WebView()
self.set_canvas(self.web_view)
self.web_view.show()
# ...
- self.change_screen('atoideweb')
+ self.change_screen('')
def get_toolbox(self):
return self._toolbox
def change_screen(self, name):
- self.web_view.load_uri(URL_BASE + 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 ...
"""
- # atoideweb ui imort
+ # atoideweb ui import
from atoideweb.ui import toolbar
# get toolbox
self._toolbox = activity.ActivityToolbox(self)
@@ -93,5 +125,7 @@ class AToiDeWebActivity(run.Server, activity.Activity):
pass
def close(self, skip_save=False):
- run.Server.close(self)
+ # stop the thread
+ self._thread.kill()
+ # ..
activity.Activity.close(self, skip_save=True)