diff options
author | florent <florent.pigout@gmail.com> | 2011-04-26 21:13:06 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-04-26 21:13:06 (GMT) |
commit | 605067ba5279b06d0852dd6e70e6debd41cc4287 (patch) | |
tree | cd35a0c1664c1ff6df18f07b74b31dfc7fc7d826 | |
parent | 0bce2460d1a8baeddb8a751bc55b326934734c95 (diff) |
add 2 registries to ensure unique pixbuf or info loading
-rw-r--r-- | activity.py | 5 | ||||
-rw-r--r-- | atoidejouer/tools/image.py | 29 |
2 files changed, 24 insertions, 10 deletions
diff --git a/activity.py b/activity.py index dbfb465..488b0b3 100644 --- a/activity.py +++ b/activity.py @@ -69,7 +69,10 @@ class ThreadAnim(threading.Thread): # do pause on toolbar if pause is True: # .. - _s.toolbar.pause() + if hasattr(_s, 'pause'): + _s.toolbar.pause() + else: + pass else: # update scene if hasattr(_s, 'scene'): diff --git a/atoidejouer/tools/image.py b/atoidejouer/tools/image.py index 9b9d47c..310c308 100644 --- a/atoidejouer/tools/image.py +++ b/atoidejouer/tools/image.py @@ -3,7 +3,7 @@ import gtk, logging, os, struct, StringIO # atoidejouer import -from atoidejouer.tools import storage +from atoidejouer.tools import registry, storage # get application logger logger = logging.getLogger('atoidejouer') @@ -11,7 +11,11 @@ logger = logging.getLogger('atoidejouer') def get_pixbuf(file_path, max_width, max_height, use_max=False): # little check - if os.path.exists(file_path): + _pixbuf = registry.PixRegistry().get_pix(file_path, max_width, max_height) + # already exist + if _pixbuf is not None: + return _pixbuf + elif os.path.exists(file_path): pass else: return None @@ -24,13 +28,14 @@ def get_pixbuf(file_path, max_width, max_height, use_max=False): max_width, max_height, use_max=use_max) # prepare preview _pixbuf = gtk.gdk.pixbuf_new_from_file(file_path) - # DEBUG - logger.debug('[image] get_pixbuf - _width: %s' % _width) - logger.debug('[image] get_pixbuf - _height: %s' % _height) - # DEBUG # .. - return _pixbuf.scale_simple(_width, _height, + _pixbuf = _pixbuf.scale_simple(_width, _height, gtk.gdk.INTERP_BILINEAR) + # udpate registry + registry.PixRegistry().set_pix(file_path, max_width, max_height, + _pixbuf) + # .. + return _pixbuf else: # TODO log something return None @@ -85,7 +90,11 @@ def get_image_info(path): raw image data. """ # little check - if os.path.exists(path): + _info = registry.InfoRegistry().get_info(path) + # already exist + if _info is not None: + return _info + elif os.path.exists(path): pass else: return None, 0, 0 @@ -149,5 +158,7 @@ def get_image_info(path): pass except ValueError: pass - + # udpate registry + registry.InfoRegistry().set_info(path, (content_type, width, height)) + # .. return content_type, width, height |