Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoidepoc
diff options
context:
space:
mode:
Diffstat (limited to 'atoidepoc')
-rw-r--r--atoidepoc/storage/__init__.py0
-rw-r--r--atoidepoc/storage/utils.py90
-rw-r--r--atoidepoc/tools/image.py69
-rw-r--r--atoidepoc/ui/screens.py155
4 files changed, 206 insertions, 108 deletions
diff --git a/atoidepoc/storage/__init__.py b/atoidepoc/storage/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/atoidepoc/storage/__init__.py
+++ /dev/null
diff --git a/atoidepoc/storage/utils.py b/atoidepoc/storage/utils.py
deleted file mode 100644
index f37b192..0000000
--- a/atoidepoc/storage/utils.py
+++ /dev/null
@@ -1,90 +0,0 @@
-
-# python import
-import logging, os
-
-# gtk import
-import gtk
-
-# sugar import
-from sugar.datastore import datastore
-
-# get application logger
-logger = logging.getLogger('atoidepoc')
-
-ACTIVITY_NAMES = {
- 'paint': 'org.laptop.Oficina'
- }
-
-
-def get_pixbuf_from_data(data, image_type=None, size=None):
- # load it
- if image_type:
- _loader = gtk.gdk.PixbufLoader(image_type=image_type)
- else:
- _loader = gtk.gdk.PixbufLoader()
- # size check
- if size is None:
- pass
- else:
- # parse size
- _w, _h = size
- # set loader size
- _loader.set_size(_w, _h)
- # load date
- _loader.write(data)
- # close loader
- _loader.close()
- # pix it
- return _loader.get_pixbuf()
-
-
-def get_journal_objects(activity_name):
- # prepare query
- _query = {'activity': ACTIVITY_NAMES[activity_name]}
- # find in ds
- _results, _count = datastore.find(_query, sorting='timestamp')
- # return it
- return _results
-
-
-def list_info_from_journal(activity_name):
- # get objects first
- _objs = get_journal_objects(activity_name)
- # make unique titles
- _titles = {}
- # return infos
- for _o in _objs:
- # get meta
- _m = _o.get_metadata()
- # get title
- _t = _m['title']
- # little check
- if _t in _titles:
- # udpate reg
- _titles[_t] += 1
- # update value to show
- _t = '%s (%s)' % (_t, _titles[_t])
- # init title reg
- else:
- _titles[_t] = 1
- # ensure info
- yield {
- 'description' : _m['description'],
- 'activity_id' : _m['activity_id'],
- 'timestamp' : _m['timestamp'],
- 'preview' : _m['preview'],
- 'title' : _t,
- }
-
-
-def list_files_from_journal(activity_name):
- # get objects first
- _objs = get_journal_objects(activity_name)
- # return paths
- for _o in _objs:
- # TODO open the files
- yield _o.get_file_path()
-
-
-def open_file_from_journal(activity_name, file_id):
- pass
diff --git a/atoidepoc/tools/image.py b/atoidepoc/tools/image.py
new file mode 100644
index 0000000..f995506
--- /dev/null
+++ b/atoidepoc/tools/image.py
@@ -0,0 +1,69 @@
+
+# python import
+import struct, StringIO
+
+def get_image_info(path):
+ """Tricky method found on Internet that returns the image info from a given
+ raw image data.
+ """
+ # read file
+ _f = open(path)
+ _data = _f.read()
+ _f.close()
+ #
+ size = len(_data)
+ height = None
+ width = None
+ content_type = None
+
+ # handle GIFs
+ if (size >= 10) and _data[:6] in ('GIF87a', 'GIF89a'):
+ # Check to see if content_type is correct
+ content_type = 'image/gif'
+ w, h = struct.unpack("<HH", _data[6:10])
+ width = int(w)
+ height = int(h)
+
+ # See PNG 2. Edition spec (http://www.w3.org/TR/PNG/)
+ # Bytes 0-7 are below, 4-byte chunk length, then 'IHDR'
+ # and finally the 4-byte width, height
+ elif ((size >= 24) and _data.startswith('\211PNG\r\n\032\n')
+ and (_data[12:16] == 'IHDR')):
+ content_type = 'image/png'
+ w, h = struct.unpack(">LL", _data[16:24])
+ width = int(w)
+ height = int(h)
+
+ # Maybe this is for an older PNG version.
+ elif (size >= 16) and _data.startswith('\211PNG\r\n\032\n'):
+ # Check to see if we have the right content type
+ content_type = 'image/png'
+ w, h = struct.unpack(">LL", _data[8:16])
+ width = int(w)
+ height = int(h)
+
+ # handle JPEGs
+ elif (size >= 2) and _data.startswith('\377\330'):
+ content_type = 'image/jpeg'
+ jpeg = StringIO.StringIO(_data)
+ jpeg.read(2)
+ b = jpeg.read(1)
+ try:
+ while (b and ord(b) != 0xDA):
+ while (ord(b) != 0xFF): b = jpeg.read(1)
+ while (ord(b) == 0xFF): b = jpeg.read(1)
+ if (ord(b) >= 0xC0 and ord(b) <= 0xC3):
+ jpeg.read(3)
+ h, w = struct.unpack(">HH", jpeg.read(4))
+ break
+ else:
+ jpeg.read(int(struct.unpack(">H", jpeg.read(2))[0])-2)
+ b = jpeg.read(1)
+ width = int(w)
+ height = int(h)
+ except struct.error:
+ pass
+ except ValueError:
+ pass
+
+ return content_type, width, height
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()