diff options
author | florent <florent.pigout@gmail.com> | 2011-02-24 02:09:07 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-02-24 02:09:07 (GMT) |
commit | 1bca40986ceccc80afb2c314fe70d6cb71d1e415 (patch) | |
tree | 40361b8f042f52ae2b3a97a476450c4af63a886b /atoidepoc/ui/screens.py | |
parent | 1229ea068cba7a91b1459cc4ebd0cb638b33b68a (diff) |
play with the graphics in default resolution 1024x468
Diffstat (limited to 'atoidepoc/ui/screens.py')
-rw-r--r-- | atoidepoc/ui/screens.py | 155 |
1 files changed, 137 insertions, 18 deletions
diff --git a/atoidepoc/ui/screens.py b/atoidepoc/ui/screens.py index 2db1f99..0371c45 100644 --- a/atoidepoc/ui/screens.py +++ b/atoidepoc/ui/screens.py @@ -1,6 +1,6 @@ # python import -import logging, os +import logging, os, threading, time from gettext import gettext as _ # gtk import @@ -11,7 +11,7 @@ from sugar.activity import activity from sugar.graphics import style # atoidepoc import -from atoidepoc.tools import sound, storage +from atoidepoc.tools import image, sound, storage # get application logger logger = logging.getLogger('atoidepoc') @@ -105,6 +105,64 @@ class ScreenBrowserSounds(ScreenBrowser): 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): @@ -113,36 +171,79 @@ class ScreenStory(gtk.Fixed): 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('demo.png', align=(0,0)) - self._add_image('demo.png', align=(200, 0), size=(100, 100)) - # png check - self._add_image('demo.svg', align=(0, 200)) - self._add_image('demo.svg', align=(200, 200), size=(100, 100)) + 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 _add_image(self, filename, align=None, size=None): - # get graphics path - _path = os.path.join(activity.get_bundle_path(), - 'static', 'graphics', filename) - # add a picture here - _image = gtk.Image() + def _move_image(self, filename, align=None): + # get graphic from dict + _image = self.__graphics[filename] # set alignment if align is None: - _x = 0 - _y = 0 + # 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 @@ -151,16 +252,34 @@ class ScreenStory(gtk.Fixed): # do resize and set image _image.set_from_pixbuf( _pixbuf.scale_simple(_w, _h, gtk.gdk.INTERP_BILINEAR)) - # TODO manage cb for dnd + # 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) @@ -202,8 +321,8 @@ class ScreenPlayerSounds(ScreenPlayer): def render(self): # init 2 players - _s_player_1 = sound.Player(soundfile='/home/florent/shared/demo1.ogg') - _s_player_2 = sound.Player(soundfile='/home/florent/shared/demo2.ogg') + _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() |