Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorent Pigout <florent.pigout@gmail.com>2011-11-09 00:58:19 (GMT)
committer Florent Pigout <florent.pigout@gmail.com>2011-11-09 00:58:19 (GMT)
commitbcae501e0449595ffe44c423146640e8eb211023 (patch)
tree947b878ba920d6f65f079c6ce771a3c8b9549599
parentb10eff973ee3efd893aaa6a2247f75cb50bccee1 (diff)
manage included storie + fix some performance issues
-rw-r--r--atoidejouer/tools/storage.py26
-rw-r--r--atoidejouer/tools/ui.py2
-rw-r--r--atoidejouer/ui/screen/activity.py44
-rw-r--r--atoidejouer/ui/screen/story.py49
4 files changed, 92 insertions, 29 deletions
diff --git a/atoidejouer/tools/storage.py b/atoidejouer/tools/storage.py
index 59e1e79..834ed46 100644
--- a/atoidejouer/tools/storage.py
+++ b/atoidejouer/tools/storage.py
@@ -245,8 +245,13 @@ def png_from_pixbuf(filename, timestamp):
def journal_query(query):
if not datastore:
return
- # find in ds
- _results, _count = datastore.find(query, sorting='timestamp')
+ try:
+ _results, _count = datastore.find(query, sorting='timestamp')
+ except Exception, e:
+ # Oops
+ logger.debug('[tools.storage] journal_query - e: %s' % e)
+ # break
+ _results = []
for _r in _results:
if 'title' in query\
and query['title'] != str(_r.metadata['title']):
@@ -407,12 +412,13 @@ def __check_file_in_journal(sub_path, file_name, mime_type=None):
return
# is already in the journal
elif is_in_journal(file_name, mime_type):
- pass
+ return True
else:
# file path
_path = os.path.join(BUND, 'static', 'ext', sub_path, file_name)
# ensure dir exist in bundle
add_file_to_journal(file_name, _path, mime_type)
+ return False
def __check_dir_files(sub_path, mime_type=None, in_journal=False):
@@ -421,17 +427,19 @@ def __check_dir_files(sub_path, mime_type=None, in_journal=False):
# file by file
for _f in os.listdir(_path):
if in_journal is True:
- __check_file_in_journal(sub_path, _f, mime_type=mime_type)
+ if __check_file_in_journal(sub_path, _f, mime_type=mime_type):
+ return True
else:
__check_file_in_bundle(sub_path, _f)
+ return False
def init_activity_files():
- __check_dir_files('db')
- __check_dir_files('stories')
- # add embedded resources to the journal for common usage
- __check_dir_files('graphics', mime_type='image/png', in_journal=True)
- __check_dir_files('sounds', mime_type='audio/ogg', in_journal=True)
+ # add embedded resources to the journal for common usage (if not already loaded)
+ if not __check_dir_files('graphics', mime_type='image/png', in_journal=True):
+ __check_dir_files('sounds', mime_type='audio/ogg', in_journal=True)
+ # ..
+ # __check_dir_files('db', mime_type='atoidejouer/db', in_journal=True)
def __show_in_out_result_message(label, message):
diff --git a/atoidejouer/tools/ui.py b/atoidejouer/tools/ui.py
index 0b0fa76..7a5b69e 100644
--- a/atoidejouer/tools/ui.py
+++ b/atoidejouer/tools/ui.py
@@ -45,7 +45,7 @@ def get_button(label=None, stock_id=None, img_name=None, width=-1,
_img.show()
# get img path
_i_path = storage.get_icon_path(stock_id) if img_name is None\
- else storage.get_image_path(img_name)
+ else storage.get_image_path(img_name, dir_="data")
# set image
if img_size is None:
_img.set_from_file(_i_path)
diff --git a/atoidejouer/ui/screen/activity.py b/atoidejouer/ui/screen/activity.py
index b44f604..423d7cd 100644
--- a/atoidejouer/ui/screen/activity.py
+++ b/atoidejouer/ui/screen/activity.py
@@ -56,13 +56,27 @@ def _on_button_click(button, screen, name, msg_label, value):
else:
pass
+
+def __load_story(screen, path):
+ # little check
+ if os.path.exists(path):
+ # read db
+ screen._activity.read_file(path)
+ # switch to story
+ screen._activity.change_screen('story')
+
+
+def _on_included_click(button, screen, file_):
+ # get bundle path
+ bund = os.path.join(storage.BUND, 'static', 'ext', 'db')
+ path = os.path.join(bund, file_)
+ __load_story(screen, path)
+
+
def _on_recent_click(button, screen, timestamp):
# db path
- _path = storage.get_path_from_journal(timestamp, 'atoidejouer/db')
- # read db
- screen._activity.read_file(_path)
- # switch to story
- screen._activity.change_screen('story')
+ path = storage.get_path_from_journal(timestamp, 'atoidejouer/db')
+ __load_story(screen, path)
[
@@ -154,6 +168,17 @@ class ScreenActivity(gtk.ScrolledWindow):
# return it
return _label
+ def _get_included_button(self, file_):
+ # prepare label
+ _img_name = file_.replace('.db', '')
+ _label = _img_name.replace('_', ' ')
+ # ..
+ _button = ui.get_button(label=_label, img_name=_img_name,
+ width=100, padding=(10, 0), img_size=(100, 100))
+ _button.connect('clicked', _on_included_click, self, file_)
+ _button.show()
+ return _button
+
def _get_included_part(self):
_vbox = gtk.VBox(homogeneous=False, spacing=5)
_vbox.set_border_width(5)
@@ -161,6 +186,15 @@ class ScreenActivity(gtk.ScrolledWindow):
# add first part title
_vbox.pack_start(self._get_title(_('INCLUDED STORIES')),
expand=False, fill=True)
+ # get bundle path
+ _path = os.path.join(storage.BUND, 'static', 'ext', 'db')
+ # file by file
+ for _f in os.listdir(_path):
+ if _f == 'blank':
+ continue
+ _vbox.pack_start(self._get_included_button(_f), expand=False,
+ fill=True)
+ # return part
return _vbox
def _add_left_part(self):
diff --git a/atoidejouer/ui/screen/story.py b/atoidejouer/ui/screen/story.py
index 4e66e82..57853c4 100644
--- a/atoidejouer/ui/screen/story.py
+++ b/atoidejouer/ui/screen/story.py
@@ -61,6 +61,7 @@ class ScreenStory(graphics.Scene):
# init image dicts
self.__sizes = dict()
self.__graphics = dict()
+ self.__paths = dict()
self.__sounds = dict()
self.__dd_signals = dict()
# init fullscreen flag
@@ -72,6 +73,7 @@ class ScreenStory(graphics.Scene):
# ..
self._screen_height = None
self._screen_width = None
+ # ensure valid screen size
self._refresh_screen_size()
def set_fullscreen(self, fullscreen):
@@ -79,6 +81,8 @@ class ScreenStory(graphics.Scene):
self.fullscreen = fullscreen
# has changed
self._fullscreen_changed = True
+ # ensure valid screen size
+ self._refresh_screen_size()
# refresh
self.refresh()
@@ -109,11 +113,13 @@ class ScreenStory(graphics.Scene):
else:
return False
+ def __code(self, key):
+ return '%s%s' % (key.title,
+ '' if key.timestamp is None else key.timestamp)
+
def refresh(self, **kargs):
# clear?
self._check_clear()
- # ensure valid screen size
- self._refresh_screen_size()
# get the current frame
_time = 0.0 if self.activity._thread is None\
else self.activity._thread._time
@@ -123,12 +129,12 @@ class ScreenStory(graphics.Scene):
_currents = list()
for _k in story.DB().get(story.Key(mime_type='image/png', time=_time)):
self.__refresh_image(_k, _rate)
- _currents.append(_k.id)
+ _currents.append(self.__code(_k))
# draw mask
_currents.append(self.__refresh_default('mask'))
# hide previous
- for _id, _image in self.__graphics.items():
- if _id not in _currents:
+ for _code, _image in self.__graphics.items():
+ if _code not in _currents:
_image.visible = False
self.queue_draw()
# show first
@@ -164,12 +170,21 @@ class ScreenStory(graphics.Scene):
else:
_sound.pause()
+ def __path(self, key):
+ _code = self.__code(key)
+ if _code in self.__paths:
+ return self.__paths[_code]
+ else:
+ _path = key.get_path()
+ self.__paths[_code] = _path
+ return _path
+
def _update_w_h(self, key):
if key.id in self.__sizes:
pass
else:
# get file size
- _c, _w, _h = image.get_image_info(key.get_path())
+ _c, _w, _h = image.get_image_info(self.__path(key))
# ..
if (self.fullscreen is True\
or self._screen_width < 1024)\
@@ -253,7 +268,7 @@ class ScreenStory(graphics.Scene):
# get/update width and height
_size = self._update_w_h(_key)
# ..
- self.__graphics[_key.id] =\
+ self.__graphics[_code] =\
self.__update_drawing_area(_key, _size, _align)
# and return displayed code
return _code
@@ -282,12 +297,13 @@ class ScreenStory(graphics.Scene):
_size = self._update_w_h(key)
# get align
_align = self.__get_transition_align(key, rate)
+ _code = self.__code(key)
# ensure current image
- if key.id in self.__graphics:
+ if _code in self.__graphics:
# DEBUG
# logger.debug('[ui.screen.story] __refresh_image - key: %s' % key)
# DEBUG
- _image = self.__graphics[key.id]
+ _image = self.__graphics[_code]
# update x, y
_image.x, _image.y = self._update_x_y(_size, _align)
# get z_order
@@ -299,17 +315,20 @@ class ScreenStory(graphics.Scene):
# refresh signals
self.__update_image_signals(key, _image, (_new_w, _new_h))
else:
+ # DEBUG - NOT CACHED
+ # logger.debug('[ui.screen.story] __refresh_image - key: %s' % key)
# draggable for edit only
_draggable = self._set_canvas is False\
and config.Config().use_dnd() is True
_image = self.__update_drawing_area(key, _size, _align,
draggable=_draggable)
- self.__graphics[key.id] = _image
+ self.__graphics[_code] = _image
def __update_image_signals(self, key, image, size):
+ _code = self.__code(key)
# remove existing handlers
- if key.id in self.__dd_signals:
- _h_id_drag, _h_id_click = self.__dd_signals[key.id]
+ if _code in self.__dd_signals:
+ _h_id_drag, _h_id_click = self.__dd_signals[_code]
image.disconnect(_h_id_drag)
image.disconnect(_h_id_click)
# connect
@@ -317,7 +336,7 @@ class ScreenStory(graphics.Scene):
key, size)
_h_id_click = image.connect('on-click', _on_click, self, key)
# update signal dict
- self.__dd_signals[key.id] = (_h_id_drag, _h_id_click)
+ self.__dd_signals[_code] = (_h_id_drag, _h_id_click)
def __update_drawing_area(self, key, size, align, draggable=False):
# update x, y
@@ -331,7 +350,7 @@ class ScreenStory(graphics.Scene):
# logger.debug('[ui.screen.story] __update_drawing_area - key: %s' % key)
# DEBUG
# image
- _image = graphics.Image(key.get_path(), x=_x, y=_y, scale_x=_scale,
+ _image = graphics.Image(self.__path(key), x=_x, y=_y, scale_x=_scale,
scale_y=_scale, z_order=key.layer, draggable=draggable)
# refresh signals
self.__update_image_signals(key, _image, (_new_w, _new_h))
@@ -406,6 +425,8 @@ class ScreenStory(graphics.Scene):
"""
def _show(self):
+ # ensure valid screen size
+ self._refresh_screen_size()
# first refresh
self.refresh()
# ..