1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# python import
import logging
# gettext import
from gettext import gettext as _
# sugar import
from sugar.activity import activity
# hulahop import
from hulahop.webview import WebView
# atoideweb import - first to update lib path
import run
# server import
from server import config
from server.flask import logger
# 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
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('activity')
else:
pass
# propagate it
return True
class NutrinoWebActivity(run.Server, activity.Activity):
def __init__(self, handle):
# 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:
pass
# ...
self.web_view = WebView()
self.set_canvas(self.web_view)
self.web_view.show()
# ...
self.change_screen('main')
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 ...
"""
# nutrinoweb ui import
from nutrinoweb.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):
run.Server.close(self)
activity.Activity.close(self, skip_save=True)
|