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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
# python import
import logging, os, threading, time
from gettext import gettext as _
# gtk import
import gobject, gtk
# sugar import
from sugar.activity import activity
from sugar.graphics import style
# atoidepoc import
from atoidepoc.tools import image, sound, storage
# get application logger
logger = logging.getLogger('atoidepoc')
class ScreenBrowser(gtk.HBox):
def __init__(self, toolbar, title=None, _type=None):
# init parent
gtk.HBox.__init__(self)
# keep toolbar
self.toolbar = toolbar
# keep name
self._type = _type
# add viewer
self._add_viewer()
self._add_list(title)
# do show
self._show()
def _add_viewer(self):
# init preview
self._preview_frame = gtk.Frame()
self._preview_frame.set_shadow_type(gtk.SHADOW_NONE)
self._preview_frame.set_size_request(400, -1)
self._preview_frame.show()
# add it
self.pack_start(self._preview_frame, expand=True, fill=True)
def _get_store(self):
# model: preview - description - activity_id - timestamp
_store = gtk.ListStore(
gtk.gdk.Pixbuf,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT,
gobject.TYPE_PYOBJECT
)
# app to get the journal entries
_app_name = 'paint' if self._type=='graphic' else 'record'
# update store
for _i in storage.list_info_from_journal(_app_name):
# prepare preview
_p = storage.get_pixbuf_from_data(_i['preview'], size=(64, 48))
# do update
_store.append([_p, _i['title'], _i['activity_id'], _i['timestamp']])
# return it
return _store
def _add_list(self, title):
# prepare colums
_col_preview = gtk.TreeViewColumn(title)
_col_description = gtk.TreeViewColumn()
# set renderers
_cell_pix = gtk.CellRendererPixbuf()
_col_preview.pack_start(_cell_pix)
_col_preview.add_attribute(_cell_pix, 'pixbuf', 0)
# ..
_cell_text = gtk.CellRendererText()
_col_description.pack_start(_cell_text, True)
_col_description.add_attribute(_cell_text, 'text', 1)
# init treeview
self._list_treeview = gtk.TreeView(self._get_store())
self._list_treeview.set_reorderable(False)
# add columns
self._list_treeview.append_column(_col_preview)
self._list_treeview.append_column(_col_description)
# show it
self._list_treeview.show()
# add it
self.pack_start(self._list_treeview)
def _show(self):
# show all
self.show()
# update toolbar
self.toolbar.activity.set_canvas(self)
class ScreenBrowserGraphics(ScreenBrowser):
def __init__(self, toolbar):
# init parent
ScreenBrowser.__init__(self, toolbar, title=_('Graphics'),
_type='graphic')
class ScreenBrowserSounds(ScreenBrowser):
def __init__(self, toolbar):
# init parent
ScreenBrowser.__init__(self, toolbar, title=_('Sounds'),
_type='sound')
PROMENEUR_KEYS = [(20, 12), (40, 12), (60, 12), (80, 12), (100, 12), (80, 12),
(100, 12), (120, 12), (100, 12), (80, 12), (60, 12), (80, 12),
(100, 12), (120, 12), (140, 12), (160, 12), (120, 12), (200, 12),
(120, 12), (200, 12), (220, 12), (220, 12), (220, 12), (220, 12)]
CHIEN_KEYS = [(80, 54), (100, 32), (80, 54), (100, 32), (120, 54), (140, 32),
(140, 54), (160, 32), (200, 54), (200, 32), (220, 54), (240, 32),
(260, 54), (240, 32), (220, 54), (200, 32), (180, 54), (160, 32),
(200, 54), (200, 32), (220, 54), (240, 32), (160, 54), (280, 32)]
MAISONS_KEYS = [(0, 0), (0, 2), (2, 4), (0, 2), (2, 0), (2, 2),
(0, 4), (0, 6), (-2, 8), (0, 6), (-2, 4), (0, 2),
(0, 2), (2, 2), (0, 0), (-2, 2), (0, 4), (2, 6),
(0, 8), (0, 6), (0, 4), (-2, 2), (-2, 2), (0, 0)]
CIEL_KEYS = [(0, -9) for _i in range(24)]
BOTTOM_KEYS = [(0, 16) for _i in range(24)]
DEFAULT_KEYS = [(0, 0) for _i in range(24)]
ALL_KEYS = {
'CIEL': CIEL_KEYS,
'MAISONS': MAISONS_KEYS,
'ROUTE': DEFAULT_KEYS,
'PROMENEUR': PROMENEUR_KEYS,
'CHIEN': CHIEN_KEYS,
'OVERLAY': DEFAULT_KEYS,
'mask_default': DEFAULT_KEYS,
}
NAMES = [
'CIEL',
'MAISONS',
'ROUTE',
'PROMENEUR',
'CHIEN',
'OVERLAY',
'mask_default',
]
class ThreadMove(threading.Thread):
def __init__(self, fixed, filename):
# init parent
threading.Thread.__init__(self)
# ...
self._fixed = fixed
self._filename = filename
def run(self):
for _align in ALL_KEYS[self._filename]:
# ...
self._fixed._move_image(self._filename, align=_align)
# ...
time.sleep(1)
class ScreenStory(gtk.Fixed):
def __init__(self, toolbar):
# init parent
gtk.Fixed.__init__(self)
# keep toolbar
self.toolbar = toolbar
# init image dict
self.__graphics = dict()
self.__sizes = dict()
self.__positions = dict()
# keep some info
self._screen_height = gtk.gdk.screen_height()
self._screen_width = gtk.gdk.screen_width()
# render
self._render()
# and show
self._show()
# do anim
for _n in NAMES:
self._anim(_n)
def _anim(self, filename):
# init thread
_t = ThreadMove(self, filename)
# start it
_t.start()
def _render(self):
# png check
self._add_image('CIEL', align=(0, -10))
self._add_image('MAISONS', align=(0, 0))
self._add_image('ROUTE', align=(0, 16))
self._add_image('PROMENEUR', align=(0, 16))
self._add_image('CHIEN', align=(0, 16))
self._add_image('OVERLAY', align=(0, 0))
# add border
self._add_image('mask_default', align=(0, 0))
def _get_image_path(self, filename):
return os.path.join(activity.get_bundle_path(),
'static', 'graphics', '%s.png' % filename)
def _update_x_y(self, width, height, x, y):
# update x
x = ((gtk.gdk.screen_width() - width) / 2) + x
# update y
y = ((gtk.gdk.screen_height() - height - + 88) / 2) + y
# return it
return x, y
def _move_image(self, filename, align=None):
# get graphic from dict
_image = self.__graphics[filename]
# set alignment
if align is None:
# use current position by default
_x , _y = self.__positions[filename]
else:
# parse align value
_x, _y = align
# get image size
_w, _h = self.__sizes[filename]
# update x, y
_x, _y = self._update_x_y(_w, _h, _x, _y)
self.__positions[filename] = (_x, _y)
# move
self.move(_image, _x, _y)
def _add_image(self, filename, align=None, size=None):
# get graphics path
_path = self._get_image_path(filename)
# add a picture here
_image = gtk.Image()
# set size
if size is None:
# set file
_image.set_from_file(_path)
# get file size
_c, _w, _h = image.get_image_info(_path)
else:
# parse size value
_w, _h = size
# get pixbuff
_pixbuf = gtk.gdk.pixbuf_new_from_file(_path)
# do resize and set image
_image.set_from_pixbuf(
_pixbuf.scale_simple(_w, _h, gtk.gdk.INTERP_BILINEAR))
# set alignment
if align is None:
_x = 0
_y = 0
else:
# parse align value
_x, _y = align
# TODO manage cb for click or dnd
# ...
# show
_image.show()
# update graphic dict
self.__graphics[filename] = _image
self.__sizes[filename] = (_w, _h)
# update x, y
_x, _y = self._update_x_y(_w, _h, _x, _y)
self.__positions[filename] = (_x, _y)
# add
self.put(_image, _x, _y)
def _show(self):
# show self
self.show()
# DEBUG
logger.debug('[screen_story] _show - width: %s' % gtk.gdk.screen_width())
# DEBUG
# update toolbar
self.toolbar.activity.set_canvas(self)
class ScreenPlayer(gtk.Fixed):
def __init__(self, toolbar):
# init parent
gtk.Fixed.__init__(self)
# keep toolbar
self.toolbar = toolbar
# render
self.render()
# and show
self._show()
def render(self):
pass
def _show(self):
# show self
self.show()
# update toolbar
self.toolbar.activity.set_canvas(self)
class ScreenPlayerGraphics(ScreenPlayer):
def __init__(self, toolbar):
# init parent
ScreenPlayer.__init__(self, toolbar)
class ScreenPlayerSounds(ScreenPlayer):
def __init__(self, toolbar):
# init parent
ScreenPlayer.__init__(self, toolbar)
def render(self):
# init 2 players
_s_player_1 = sound.Player(soundfile='/home/sugar/shared/demo1.ogg')
_s_player_2 = sound.Player(soundfile='/home/sugar/shared/demo2.ogg')
# get duration
_d1 = _s_player_1.get_duration()
# DEBUG
logger.debug('[player_sound] render - _d1: %s' % _d1)
# DEBUG
_d2 = _s_player_2.get_duration()
# DEBUG
logger.debug('[player_sound] render - _d2: %s' % _d2)
# DEBUG
# play together
_s_player_1.play()
_s_player_2.play()
|