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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# 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.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)
def _cb_view_fullscreen(widget, toolbar):
# DEBUG
logger.debug('[toolbar] _cb_fullscreen - name: %s' % toolbar.name)
# remove fullscreen button
toolbar._remove_button('view_fullscreen')
# add return button
toolbar._add_button('view_return')
# get current screen
_screen = toolbar.activity.get_canvas()
# enbale fullscreen
_screen.set_fullscreen(True)
def _cb_view_return(widget, toolbar):
# DEBUG
logger.debug('[toolbar] _cb_fullscreen - name: %s' % toolbar.name)
# remove return button
toolbar._remove_button('view_return')
# add fullscreen button
toolbar._add_button('view_fullscreen')
# get current screen
_screen = toolbar.activity.get_canvas()
# disable fullscreen
_screen.set_fullscreen(False)
BUTTONS = {
'add' : ['list-add', _cb_add],
'open' : ['media', _cb_open],
'play' : ['player_play', _cb_play],
'view_fullscreen' : ['view-fullscreen', _cb_view_fullscreen],
'view_return' : ['view-return', _cb_view_return],
}
TOOLBARS = {
'graphic' : ['add',],
'sound' : ['add', 'play',],
'story' : ['view_fullscreen',], # 'open', 'play',
}
TITLES = {
'graphic' : {
'toolbar': _('Graphic'),
'buttons': {
'add': _('Add Graphic'),
}
},
'sound' : {
'toolbar': _('Sound'),
'buttons': {
'add': _('Add Sound'),
'play': _('Play Sound'),
}
},
'story' : {
'toolbar': _('Story'),
'buttons': {
# 'open': _('Open Story'),
# 'play': _('Play Story'),
'view_fullscreen': _('Fullscreen'),
'view_return': _('Default Screen'),
}
},
}
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)
# init widget dict
self._button_dict = dict()
# add buttons
for _b in TOOLBARS[self.name]:
# add button
self._add_button(_b)
# add to parent
_toolbox = self.activity.get_toolbox()
_toolbox.add_toolbar(TITLES[self.name]['toolbar'], self)
# connect focus event
# self.connect('focus', self._on_focus)
# show
self.show()
def _on_focus(self, widget, direction):
# screen factory
if self.name == 'graphic':
_cls = screens.ScreenPlayerGraphics
elif self.name == 'sound':
_cls = screens.ScreenPlayerSounds
elif self.name == 'story':
_cls = screens.ScreenStory
# do switch
_cls(self)
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.add(_buton)
# show it
_buton.show()
# update the button dict
self._button_dict[button_id] = _buton
# ??
else:
# DEBUG
logger.debug('[toolbar] _add_button - unknown: %s' % button_id)
def _remove_button(self, button_id):
# little check
if button_id in self._button_dict:
# get button
_buton = self._button_dict.pop(button_id)
# do remove
self.remove(_buton)
# ??
else:
# DEBUG
logger.debug('[toolbar] _remove_button - unknown: %s' % button_id)
|