Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorent <florent.pigout@gmail.com>2011-02-01 21:56:18 (GMT)
committer florent <florent.pigout@gmail.com>2011-02-01 21:56:18 (GMT)
commit2e4d4115c5c130be563efeefb5c83ea6d86e4e84 (patch)
tree92234d6184dbcdb34693a9e62b76b154a2ca7931
parent32c1dae13fc1d56419369437f83a3fc3e27d7695 (diff)
image add/preview .. work in progress
-rw-r--r--activity.py23
-rw-r--r--atoidepoc/storage/__init__.py0
-rw-r--r--atoidepoc/storage/utils.py91
-rw-r--r--atoidepoc/ui/screens.py114
-rw-r--r--atoidepoc/ui/toolbar.py30
5 files changed, 247 insertions, 11 deletions
diff --git a/activity.py b/activity.py
index 7aee0ef..16ba628 100644
--- a/activity.py
+++ b/activity.py
@@ -18,6 +18,7 @@ class AToiDePocActivity(activity.Activity):
def __init__(self, handle):
# init parent
activity.Activity.__init__(self, handle)
+ self.max_participants = 1
# get toolbox
_toolbox = activity.ActivityToolbox(self)
# add tool bars
@@ -26,8 +27,24 @@ class AToiDePocActivity(activity.Activity):
_toolbox.show()
# init toolbars
for _t in ['story', 'graphic', 'sound']:
- ui.Toolbar(_toolbox, name=_t)
+ ui.Toolbar(self, name=_t)
# set default tab
_toolbox.set_current_toolbar(1)
- # some logging
- logger.debug('[activity] - started ...')
+ # DEBUG
+ logger.debug('[activity] init - started ...')
+
+ def read_file(self, file_path):
+ '''Dummy overiding ...
+ '''
+ # DEBUG
+ logger.debug('[activity] read_file - file_path: %s' % file_path)
+
+ def write_file(self, file_path):
+ '''Dummy overiding ...
+ '''
+ # DEBUG
+ logger.debug('[activity] write_file - file_path: %s' % file_path)
+
+ def close(self, skip_save=False):
+ # DEBUG
+ activity.Activity.close(self, skip_save=True)
diff --git a/atoidepoc/storage/__init__.py b/atoidepoc/storage/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/atoidepoc/storage/__init__.py
diff --git a/atoidepoc/storage/utils.py b/atoidepoc/storage/utils.py
new file mode 100644
index 0000000..56a74c4
--- /dev/null
+++ b/atoidepoc/storage/utils.py
@@ -0,0 +1,91 @@
+
+# python import
+import logging, os
+
+# gtk import
+import gtk
+
+# sugar import
+from sugar.activity import activity
+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/ui/screens.py b/atoidepoc/ui/screens.py
index 46303f2..822d552 100644
--- a/atoidepoc/ui/screens.py
+++ b/atoidepoc/ui/screens.py
@@ -1,18 +1,122 @@
# python import
+import logging
from gettext import gettext as _
# gtk import
-import gtk
+import gobject, gtk
+
+# sugar import
+from sugar.graphics import style
+
+# atoidepoc import
+from atoidepoc.storage import utils
+
+# get application logger
+logger = logging.getLogger('atoidepoc')
+
+
+class ScreenBrowser(gtk.HBox):
+
+ def __init__(self, toolbar):
+ # init parent
+ gtk.HBox.__init__(self)
+ # keep toolbar
+ self.toolbar = toolbar
+ # add viewer
+ self._add_viewer()
+ self._add_list()
+ # do show
+ self._show()
+
+ def _add_viewer(self):
+ # init preview
+ self._preview_frame = gtk.Frame()
+ 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
+ return gtk.ListStore(
+ gtk.gdk.Pixbuf,
+ gobject.TYPE_STRING,
+ gobject.TYPE_PYOBJECT,
+ gobject.TYPE_PYOBJECT
+ )
+
+ def _add_list(self):
+ # prepare colums
+ _col_preview = gtk.TreeViewColumn(_('Preview'))
+ _col_description = gtk.TreeViewColumn(_('Description'))
+ # 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):
+ # update toolbar
+ self.toolbar.activity.set_canvas(self)
+ # show all
+ self.show_all()
+
+
+class ScreenBrowserGraphics(ScreenBrowser):
+
+ def __init__(self, toolbar):
+ # init parent
+ ScreenBrowser.__init__(self, toolbar)
+
+ def _get_store(self):
+ # get empty store
+ _store = ScreenBrowser._get_store(self)
+ # update store
+ for _i in utils.list_info_from_journal('paint'):
+ # prepare preview
+ _p = utils.get_pixbuf_from_data(_i['preview'], size=(64, 48))
+ # prepare description
+ _d = '%s\n%s\n%s' % (_i['title'], '-' * len(_i['title']), _i['description'])
+ # DEBUG
+ logger.debug('[screen_browser_graphics] _get_store - _d: %s' % _d)
+ logger.debug('[screen_browser_graphics] _get_store - _p: %s' % type(_p))
+ logger.debug('[screen_browser_graphics] _get_store - activity_id: %s' % _i['activity_id'])
+ logger.debug('[screen_browser_graphics] _get_store - timestamp: %s' % _i['timestamp'])
+ # DEBUG
+ # do update
+ _store.append([_p, _d, _i['activity_id'], _i['timestamp']])
+ # return it
+ return _store
+
+
+class ScreenBrowserSounds(ScreenBrowser):
+
+ def __init__(self, toolbar):
+ # init parent
+ ScreenBrowser.__init__(self, toolbar)
+
class PlayerScreen(gtk.VBox):
- def __init__(self, activity):
+ def __init__(self, toolbar):
# init parent
- gtk.Toolbar.__init__(self)
+ gtk.VBox.__init__(self)
# prepare screen
# ...
# update activity
- activity.set_canvas(self)
+ # activity.set_canvas(self)
# show all
- self.show_all()
+ # self.show_all()
diff --git a/atoidepoc/ui/toolbar.py b/atoidepoc/ui/toolbar.py
index f7e729c..9d063fc 100644
--- a/atoidepoc/ui/toolbar.py
+++ b/atoidepoc/ui/toolbar.py
@@ -9,18 +9,38 @@ 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):
- logger.debug('[toolbar] _cb_add - name: %s' % toolbar.name)
+ # 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],
@@ -55,18 +75,22 @@ TITLES = {
},
}
+
class Toolbar(gtk.Toolbar):
- def __init__(self, toolbox, name='player'):
+ 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.add_toolbar(TITLES[self.name]['toolbar'], self)
+ _toolbox = self.activity.get_toolbox()
+ _toolbox.add_toolbar(TITLES[self.name]['toolbar'], self)
# show
self.show()