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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# python import
import logging
from gettext import gettext as _
# gtk import
import gtk
# sugar import
from sugar.graphics.toolbutton import ToolButton
# atoidepoc import
from atoidepoc.storage import utils
from atoidepoc.ui import screens
# get application logger
logger = logging.getLogger('atoidepoc')
def _cb_add(widget, toolbar):
# browser screen factory
if toolbar.name == 'graphic':
_cls = screens.ScreenBrowserGraphics
elif toolbar.name == 'sound':
_cls = screens.ScreenBrowserSounds
# ??
else:
# DEBUG
return logger.debug('[toolbar] _cb_add - unknown: %s' % toolbar.name)
# do switch
_cls(toolbar)
def _cb_open(widget, toolbar):
# DEBUG
logger.debug('[toolbar] _cb_open - name: %s' % toolbar.name)
def _cb_play(widget, toolbar):
# DEBUG
logger.debug('[toolbar] _cb_play - name: %s' % toolbar.name)
BUTTONS = {
'add' : ['list-add', _cb_add],
'open' : ['media', _cb_open],
'play' : ['player_play', _cb_play],
}
TOOLBARS = {
'graphic' : ['add'],
'sound' : ['add'],
'story' : ['open', 'play', ],
}
TITLES = {
'graphic' : {
'toolbar': _('Graphic'),
'buttons': {
'add': _('Add Graphic'),
}
},
'sound' : {
'toolbar': _('Sound'),
'buttons': {
'add': _('Add Sound'),
}
},
'story' : {
'toolbar': _('Story'),
'buttons': {
'open': _('Open Story'),
'play': _('Play Story'),
}
},
}
class Toolbar(gtk.Toolbar):
def __init__(self, activity, name='player'):
# init parent
gtk.Toolbar.__init__(self)
# keep activity
self.activity = activity
# keep the name
self.set_name(name)
# add buttons
for _b in TOOLBARS[self.name]:
self._add_button(_b)
# add to parent
_toolbox = self.activity.get_toolbox()
_toolbox.add_toolbar(TITLES[self.name]['toolbar'], self)
# show
self.show()
def _add_button(self, button_id):
# little check
if button_id in BUTTONS:
# get button icon and cb
_icon, _cb = BUTTONS[button_id]
# get tooltip
_tooltip = TITLES[self.name]['buttons'][button_id]
# set icon
_buton = ToolButton(_icon)
# set tooltip
_buton.set_tooltip(_tooltip)
# do connect
_buton.connect('clicked', _cb, self)
# add to the toolbar
self.insert(_buton, -1)
# show it
_buton.show()
# ??
else:
# DEBUG
logger.debug('[toolbar] _add_button - unknown: %s' % button_id)
|