Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoidejouer/ui/panel/notebook.py
diff options
context:
space:
mode:
Diffstat (limited to 'atoidejouer/ui/panel/notebook.py')
-rw-r--r--atoidejouer/ui/panel/notebook.py229
1 files changed, 49 insertions, 180 deletions
diff --git a/atoidejouer/ui/panel/notebook.py b/atoidejouer/ui/panel/notebook.py
index 63e1be3..f67abfc 100644
--- a/atoidejouer/ui/panel/notebook.py
+++ b/atoidejouer/ui/panel/notebook.py
@@ -12,6 +12,7 @@ import gobject, gtk, glib
from sugar.activity import activity
# atoidejouer import
+from atoidejouer.db import story
from atoidejouer.tools import image, storage, ui
from atoidejouer.ui.panel import PanelEdit
@@ -53,15 +54,10 @@ def _cb_swicth_page(widget, page, page_num, notebook):
def _cb_cursor_changed(treeview, notebook, type_):
- pass
- """
# get the current cursor and path
_path, _column = treeview.get_cursor()
- # DEBUG
if _column is None:
return
- else:
- pass
# get model
_model = treeview.get_model()
# get resource info
@@ -70,76 +66,44 @@ def _cb_cursor_changed(treeview, notebook, type_):
_iter = _model.get_iter(_path)
# update current
if type_ in ['graphics', 'sounds']:
- # get value
- _filename = _model.get_value(_iter, 1)
- # udpate preview
- notebook.screen.item_preview.set_item(filename=_filename)
- # update current
- notebook.current_item = _filename
- # update current
- elif type_ == 'journal':
- # get value
- _pixbuf = _model.get_value(_iter, 0)
- _filename = _model.get_value(_iter, 1)
- _metadata = _model.get_value(_iter, 3)
- # copy journal item to library to work on it
- if notebook._type == 'graphics':
- storage.png_from_pixbuf(_filename, _metadata['timestamp'])
- # ..
- notebook._get_store_graphic()
- # for sound
- else:
- # get source path
- _src_path = storage.get_path_from_journal(_metadata['timestamp'],
- 'audio/ogg')
- # get dst path
- _dst_path = storage.get_sound_path(_filename)
- # copy
- shutil.copy(_src_path, _dst_path)
- # ..
- notebook._get_store_sound()
- # udpate preview
- notebook.screen.item_preview.set_item(filename=_filename)
- # update current
- notebook.current_item = _filename
- elif type_ == 'sequence':
- # clear sequence preview
- notebook.screen.sequence_preview.clear()
- # get value
- _sequence_path = _model.get_value(_iter, 2)
- # update sequence ..
- _fnames = storage.get_sequence_items(_sequence_path)
- for _f in _fnames:
- notebook.screen.sequence_preview.add_item(_f.strip())
- # get sequence name
- _sequence_name = _model.get_value(_iter, 1)
- # get toolbar sequence entry
- _entry = notebook.screen.toolbar._sequence_entry
- # update toolbar entry
- _entry.set_text(_sequence_name)
- # update current
- notebook.current_sequence = _sequence_name
- # ..
- notebook.update_store_sequence()
- """
- """
- # .. add action - add column as no title
- if _column.get_title() is None:
- # get graphic name
- _item_name = notebook.current_item
- _sequence_name = notebook.current_sequence
- if _sequence_name is None\
- or _sequence_name.strip() == ''\
- or _item_name is None:
- pass
+ # shorcut
+ _activity = notebook.screen.toolbar.activity
+ # prepare key
+ _name = _model.get_value(_iter, 1)
+ _info = _model.get_value(_iter, 2)
+ _kargs = {
+ 'name': _name,
+ 'mime_type': str(_info['mime_type']),
+ 'timestamp': str(_info['timestamp']),
+ 'time': _activity._thread._time,
+ 'layout': story.DB().get_layout_max(),
+ 'x': 0,
+ 'y': 0,
+ 'duration': 0,
+ 'loop': 0,
+ 'path': _info['file_path']
+ }
+ # do add
+ story.DB().add(story.Key(**_kargs))
+ # reload key
+ _key = story.DB().one(
+ story.Key(
+ timestamp=str(_info['timestamp']),
+ mime_type=str(_info['mime_type']),
+ )
+ )
+ if _key is None:
+ raise Exception('[ui.panel.notebook] on_click - key not found: %s'\
+ % str(_info['timestamp']))
+ # set path for next use
+ _key.set_path(_info['file_path'])
+ # TODO refresh panel graphics or sounds
+ logger.debug('[ui.panel.notebook] on_clicked - _kargs: %s' % _kargs)
+ # udpate scene or panel_sound
+ if type_ == 'graphics':
+ notebook.screen.scene.refresh()
else:
- # udpate sequence preview
- notebook.screen.sequence_preview.add_item(_item_name)
- # update sequence file
- storage.sequence_save(notebook.screen.toolbar)
- else:
- pass
- """
+ notebook.screen.panel_sound.refresh()
def __remove_filename_from_sequence(type_, sequence, filename):
@@ -275,97 +239,6 @@ class PanelNotebook(gtk.Frame):
# return it
return _button, _label
- """
- def _get_store_graphic(self):
- # init/reset store
- if self._store_graphic is None:
- self._store_graphic = gtk.ListStore(
- gtk.gdk.Pixbuf,
- gobject.TYPE_STRING,
- gtk.gdk.Pixbuf,
- gobject.TYPE_PYOBJECT
- )
- else:
- self._store_graphic.clear()
- # ..
- _add_path = storage.get_icon_path('more_small')
- # ..
- _graphic_dir = os.path.join(activity.get_activity_root(), 'data',
- 'graphics')
- # ..
- for _filename in os.listdir(_graphic_dir):
- # ..
- _path = os.path.join(_graphic_dir, _filename)
- # little check
- if os.path.isfile(_path):
- # check name
- try:
- _filename, _ext = os.path.splitext(_filename)
- # check ext
- if _ext in ['.png']:
- pass
- else:
- continue
- except Exception, e:
- # TODO log something
- continue
- # ..
- _pixbuf = image.get_pixbuf(_path, 64, 48)
- _pix_a = image.get_pixbuf(_add_path, 24, 24)
- # do update
- self._store_graphic.append([_pixbuf, _filename, _pix_a, _path])
- else:
- continue
- # return the store
- return self._store_graphic
- """
-
- """
- def _get_store_sound(self):
- # init/reset store
- if self._store_sound is None:
- self._store_sound = gtk.ListStore(
- gtk.gdk.Pixbuf,
- gobject.TYPE_STRING,
- gtk.gdk.Pixbuf,
- gobject.TYPE_PYOBJECT
- )
- else:
- self._store_sound.clear()
- # prepare icon path
- _pix_path = storage.get_image_path('sound', dir_='data')
- _add_path = storage.get_icon_path('more_small')
- # ..
- _sound_dir = os.path.join(activity.get_activity_root(), 'data',
- 'sounds')
- # ..
- for _filename in os.listdir(_sound_dir):
- # ..
- _path = os.path.join(_sound_dir, _filename)
- # little check
- if os.path.isfile(_path):
- # check name
- try:
- _filename, _ext = os.path.splitext(_filename)
- # check ext
- if _ext in ['.ogg']:
- pass
- else:
- continue
- except Exception, e:
- # TODO log something
- continue
- # ..
- _pixbuf = image.get_pixbuf(_pix_path, 64, 48)
- _pix_a = image.get_pixbuf(_add_path, 24, 24)
- # do update
- self._store_sound.append([_pixbuf, _filename, _pix_a, _path])
- else:
- continue
- # return the store
- return self._store_sound
- """
-
def update_store(self, type_):
_store = self._store_graphic if type_ == 'graphics'\
else self._store_sound
@@ -374,7 +247,7 @@ class PanelNotebook(gtk.Frame):
_store = gtk.ListStore(
gtk.gdk.Pixbuf,
gobject.TYPE_STRING,
- gtk.gdk.Pixbuf,
+ # gtk.gdk.Pixbuf,
gobject.TYPE_PYOBJECT
)
else:
@@ -386,25 +259,20 @@ class PanelNotebook(gtk.Frame):
# mime type factory
_mime_type = 'image/png' if type_=='graphics' else 'audio/ogg'
# update store
- for _i in storage.list_info_from_journal(mime_type=_mime_type):
+ for _info in storage.list_info_from_journal(mime_type=_mime_type):
# DEBUG
- logger.debug('[ui.panel.notebook] update_store - title: %s' % _i['title'])
- if _i['preview'] is None:
+ logger.debug('[ui.panel.notebook] update_store - title: %s' % _info['title'])
+ if _info['preview'] is None or type_ == 'sounds':
_pixbuf = image.get_pixbuf(_default_pix_path, 64, 48)
else:
# prepare preview
- _pixbuf = storage.get_pixbuf_from_data(_i['preview'],
- size=(64, 48))
+ _pixbuf = storage.get_pixbuf_from_data(
+ _info['preview'], size=(64, 48))
# ..
_add_path = storage.get_icon_path('more_small')
- _pix_a = image.get_pixbuf(_add_path, 24, 24)
- # store info
- _store_info = {
- 'activity_id':_i['activity_id'],
- 'timestamp': _i['timestamp']
- }
+ # _pix_a = image.get_pixbuf(_add_path, 24, 24)
# do update
- _row = [_pixbuf, _i['title'], _pix_a, _store_info]
+ _row = [_pixbuf, _info['title'], _info] # , _pix_a, _info]
_store.append(_row)
# ..
return _store
@@ -431,13 +299,14 @@ class PanelNotebook(gtk.Frame):
_col_description.add_attribute(_cell_text, 'text', 1)
_col_description.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
_col_description.set_fixed_width(220)
- # ..
+ """
_cell_add = gtk.CellRendererPixbuf()
_cell_add.set_property('height', 48)
_col_add.pack_start(_cell_add, expand=False)
_col_add.add_attribute(_cell_add, 'pixbuf', 2)
_col_add.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
_col_add.set_fixed_width(28)
+ """
# update store
_store = self.update_store(type_)
# ensure sorting
@@ -452,7 +321,7 @@ class PanelNotebook(gtk.Frame):
# add columns
_treeview.append_column(_col_preview)
_treeview.append_column(_col_description)
- _treeview.append_column(_col_add)
+ # _treeview.append_column(_col_add)
# ..
_scrolled_win.add(_treeview)
# return it