--- a/degal/image.py Wed Jun 10 23:33:28 2009 +0300
+++ b/degal/image.py Thu Jun 11 00:36:19 2009 +0300
@@ -4,7 +4,7 @@
from __future__ import with_statement
-import filesystem, render, html, format
+import filesystem, format, thumbnail
from utils import lazy_load
import PIL.Image
@@ -29,20 +29,16 @@
# the .html file for this image
self.html = self.parent.subfile(self.basename + '.html')
+ # our preview/thumbnail
+ self.preview = thumbnail.Thumbnail(self, self.parent.preview_dir, self.config.preview_size)
+ self.thumb = thumbnail.Thumbnail(self, self.parent.thumb_dir, self.config.thumb_size)
+
# info
self.title = self.name
self.description = None
@lazy_load
- def stat (self) :
- """
- Load and return the os.stat info for this file
- """
-
- return super(Image, self).stat()
-
- @lazy_load
- def image (self) :
+ def pil_image (self) :
"""
Loads the image as a PIL.Image
"""
@@ -77,11 +73,11 @@
"""
# load stuff
- stat = self.stat
+ stat = self.stat()
exif = self.exif
# XXX: avoid having to open the image?
- size = self.image.size
+ size = self.pil_image.size
# build
return dict({
@@ -93,32 +89,21 @@
(name, exif[tag]) for tag, name in self.config.exif_tags if exif and tag in exif
))
- @lazy_load
- def thumb (self) :
+ def stale (self) :
"""
- Load and update the thumbnail if needed
+ Tests if this Image is stale, based on preview/thumb.
"""
- # renderer to use
- # XXX: get from elsewhere
- render_machine = self.config.get_renderer()
-
- # render if needed
- return render_machine.render_lazy(self,
- self.config.thumb_size, self.parent.thumb_dir.subnode(self.name)
- )
+ return self.preview.stale() or self.thumb.stale()
- @lazy_load
- def preview (self) :
+ def update (self) :
"""
- Load and update the preview if needed
+ Updates this Image's thumb/preview
"""
+
+ if self.preview.stale() :
+ self.preview.update()
- # renderer to use
- # XXX: get from elsewhere
- render_machine = self.config.get_renderer()
+ if self.thumb.stale() :
+ self.thumb.update()
- return render_machine.render_lazy(self,
- self.config.preview_size, self.parent.preview_dir.subnode(self.name)
- )
-