Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/creactistore/_templates/+package+/activity.py_tmpl~
blob: 30d1f2dd13d478578bcec80bd8a025b59d40b5c0 (plain)
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
# python import
import os, sys
# gettext import
from gettext import gettext as _

# sugar import
from sugar.activity import activity

# add lib path to current python path
sys.path.append(os.path.join(activity.get_bundle_path(), 'lib'))

# peak import
from peak.util.imports import importString

# semanticxo import
from semanticxo.datastore import TripleStore

# triplestore runner import and start
from server.semanticxo import Runner
Runner().run()

# {{package}} ui import
from {{package}}.ui import toolbar


def _toolbar_changed(toolbox, page, activity_):
    """Catch toolbox activity tab focus to display settings screen.
    """
    # is the activity tab?
    if page == 0:
        pass
    else:
        pass
    # propagate it
    return True


class {{package.capitalize()}}Activity(activity.Activity):

    def __init__(self, handle):
        # init parents
        activity.Activity.__init__(self, handle)
        self.max_participants = 1
        # init toolbar
        self.__init_toolbar()
        # screen registry init
        self.__screens = dict()
        # init datastore
        self.datastore = TripleStore()
        # set default screen
        self.change_screen('default')

    def change_screen(self, name):
        # init screen if not already initialized
        if name not in self.__screens:
            _cls = importString('{{package}}.ui.screens.%s.%s' % (
                                name,
                                ''.join([n.capitalize()
                                         for n in name.split('_')])))
            self.__screens[name] = _cls(self)
        # get and show the screen
        _scr = self.__screens[name]
        _scr._show()

    def __init_toolbar(self):
        """Keep an example of how to manage toolbar in our webapp ...
        """
        # get toolbox
        self._toolbox = activity.ActivityToolbox(self)
        # add tool bars
        self.set_toolbox(self._toolbox)
        # show
        self._toolbox.show()
        # init toolbars
        for _n in ['default']:
            # init toolbar
            toolbar.Toolbar(self, name=_n)
        # 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 triplestore
        Runner().proc.kill()
        # call parent
        activity.Activity.close(self, skip_save=True)