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-04-20 09:31:57 (GMT)
committer florent <florent.pigout@gmail.com>2011-04-20 09:31:57 (GMT)
commit0727ad5bc453bfdeddf6729bb4054ed1f4451142 (patch)
treeb3b15d38f26dcdb9f2e8caa350359881406e1b62
parentb739d17e4198024cbb0ae45869fdf348d9cd6769 (diff)
add first sequence image preview in timeline titles
-rw-r--r--atoidejouer/tools/image.py21
-rw-r--r--atoidejouer/tools/storage.py14
-rw-r--r--atoidejouer/tools/ui.py17
-rw-r--r--atoidejouer/ui/notebook.py29
-rw-r--r--atoidejouer/ui/timeline.py12
5 files changed, 59 insertions, 34 deletions
diff --git a/atoidejouer/tools/image.py b/atoidejouer/tools/image.py
index c29d730..5f0ec2d 100644
--- a/atoidejouer/tools/image.py
+++ b/atoidejouer/tools/image.py
@@ -2,6 +2,9 @@
# python import
import gtk, os, struct, StringIO
+# atoidejouer import
+from atoidejouer.tools import storage
+
def get_pixbuf(file_path, max_width, max_height):
# little check
@@ -26,6 +29,24 @@ def get_pixbuf(file_path, max_width, max_height):
return None
+def get_sequence_first_graphic(type_, sequence_name, size=None):
+ # ..
+ _filename = storage.get_sequence_first_graphic_name(type_, sequence_name)
+ if type_ == 'graphics':
+ _path = storage.get_image_path(_filename)
+ elif type_ == 'sounds':
+ _path = storage.get_image_path('sound', dir_='data')
+ else:
+ _path = storage.get_image_path('blank', dir_='data')
+ # ensure size
+ if size is None:
+ size = (64, 48)
+ else:
+ pass
+ # ..
+ return get_pixbuf(_path, *size)
+
+
def compute_width_height(width, height, max_width, max_height):
# compute ratio
_ratio_scr = max_width / float(max_height)
diff --git a/atoidejouer/tools/storage.py b/atoidejouer/tools/storage.py
index 06c2421..d9e3cc4 100644
--- a/atoidejouer/tools/storage.py
+++ b/atoidejouer/tools/storage.py
@@ -27,6 +27,20 @@ def get_config_path():
return os.path.join(_bundle_path, 'static', 'data', 'config', 'config.ini')
+def get_sequence_path(type_, sequence_name):
+ return os.path.join(activity.get_activity_root(), 'data',
+ 'sequences', type_, '%s.seq' % sequence_name)
+
+
+def get_sequence_first_graphic_name(type_, sequence_name):
+ # seq file
+ _f = open(get_sequence_path(type_, sequence_name))
+ _name = _f.readlines()[0]
+ _f.close()
+ # ..
+ return _name.strip()
+
+
def get_sound_path(filename, dir_='sounds'):
# return path
return os.path.join(activity.get_activity_root(), 'data', dir_,
diff --git a/atoidejouer/tools/ui.py b/atoidejouer/tools/ui.py
index 3568480..9c9ecd4 100644
--- a/atoidejouer/tools/ui.py
+++ b/atoidejouer/tools/ui.py
@@ -7,7 +7,7 @@ from gettext import gettext as _
import gtk
# atoidejouer import
-from atoidejouer.tools import storage
+from atoidejouer.tools import image, storage
# get application logger
logger = logging.getLogger('atoidejouer')
@@ -22,9 +22,10 @@ def get_color(red, green, blue):
return gtk.gdk.Color(red, green, blue)
-def get_button(label=None, stock_id=None, width=-1, padding=None):
+def get_button(label=None, stock_id=None, img_name=None, width=-1,
+ padding=None, img_size=None):
# little check:
- if label is None and stock_id is None:
+ if label is None and stock_id is None and img_name is None:
return None
else:
pass
@@ -37,14 +38,20 @@ def get_button(label=None, stock_id=None, width=-1, padding=None):
else:
_expand = False
# use stock?
- if stock_id is None:
+ if stock_id is None and img_name is None:
pass
else:
# image stuff
_img = gtk.Image()
_img.show()
# get img path
- _img.set_from_file(storage.get_icon_path(stock_id))
+ _i_path = storage.get_icon_path(stock_id) if img_name is None\
+ else storage.get_image_path(img_name)
+ # set image
+ if img_size is None:
+ _img.set_from_file(_i_path)
+ else:
+ _img.set_from_pixbuf(image.get_pixbuf(_i_path, *img_size))
# manage padding
if padding is None:
pass
diff --git a/atoidejouer/ui/notebook.py b/atoidejouer/ui/notebook.py
index dcf0566..704dff7 100644
--- a/atoidejouer/ui/notebook.py
+++ b/atoidejouer/ui/notebook.py
@@ -169,26 +169,6 @@ class ResourceNotebook(gtk.Frame):
# and remove
_model.remove(_iter)
- def _get_sequence_first_graphic_name(self, sequence_path):
- # seq file
- _f = open(sequence_path)
- _filename = _f.readlines()[0]
- _f.close()
- # ..
- return _filename.strip()
-
- def _get_sequence_first_graphic(self, sequence_path):
- # ..
- _filename = self._get_sequence_first_graphic_name(sequence_path)
- if self._type == 'graphics':
- _path = storage.get_image_path(_filename)
- elif self._type == 'sounds':
- _path = storage.get_image_path('sound', dir_='data')
- else:
- _path = storage.get_image_path('blank', dir_='data')
- # ..
- return image.get_pixbuf(_path, 64, 48)
-
def update_store_sequence(self):
# ..
if self.current_sequence is None:
@@ -196,11 +176,9 @@ class ResourceNotebook(gtk.Frame):
else:
# ..
_seq_filename = '%s.seq' % self.current_sequence
- # prepare dir path
- _seq_path = os.path.join(activity.get_activity_root(), 'data',
- 'sequences', self._type, _seq_filename)
# ..
- _gfx_filename = self._get_sequence_first_graphic_name(_seq_path)
+ _gfx_filename = storage.get_sequence_first_graphic_name(
+ self._type, _seq_filename)
# set current
self.screen.sequence_preview.set_current(_gfx_filename)
@@ -232,7 +210,8 @@ class ResourceNotebook(gtk.Frame):
# TODO log something
continue
# ...
- _pixbuf = self._get_sequence_first_graphic(_path)
+ _pixbuf = image.get_sequence_first_graphic(self._type,
+ _filename)
# do update
self._store_sequence.append([_pixbuf, _filename, _path])
# return the store
diff --git a/atoidejouer/ui/timeline.py b/atoidejouer/ui/timeline.py
index 04513ad..5953f9c 100644
--- a/atoidejouer/ui/timeline.py
+++ b/atoidejouer/ui/timeline.py
@@ -9,7 +9,7 @@ from gettext import gettext as _
import gtk, glib
# atoidejouer import
-from atoidejouer.tools import ui
+from atoidejouer.tools import storage, ui
# get application logger
logger = logging.getLogger('atoidejouer')
@@ -54,7 +54,7 @@ class Timeline(gtk.Frame):
# ..
self.add(self.scrolled_window)
# ..
- if screen.toolbar.name == 'graphics':
+ if self.screen.toolbar.name == 'graphics':
self.story_keys = self.screen.toolbar.activity.graphic_keys
else:
self.story_keys = self.screen.toolbar.activity.sound_keys
@@ -126,8 +126,12 @@ class Timeline(gtk.Frame):
return len(self._titles_box.get_children())
def _add_title(self, sequence_name):
+ # get first image name
+ _img_name = storage.get_sequence_first_graphic_name(
+ self.screen.toolbar.name, sequence_name)
# get button
- _title = ui.get_button(label=sequence_name)
+ _title = ui.get_button(label=sequence_name, img_name=_img_name,
+ width=0, padding=(4, 0), img_size=(16, 16))
# _title.set_size_request(-1, 28)
# set color
_title.modify_bg(gtk.STATE_NORMAL, ui.get_color(0.3, 0.5, 0.6)) # TODO manage common colors like a theme
@@ -307,7 +311,7 @@ class Timeline(gtk.Frame):
# ...
for _i, _r in enumerate(_t_children):
# title row | row - eventbox - button - label
- _label_wid = _r.get_children()[0].get_children()[0].get_children()[0]
+ _label_wid = _r.get_children()[0].get_children()[0].get_children()[1]
_label_str = _label_wid.get_label()
# ...
for _frame, _c_key in enumerate(_k_children[_i].get_children()[0]):