[Checkins] SVN: z3c.filetype/trunk/src/z3c/filetype/ added ISized adapter

Bernd Dorn bernd.dorn at fhv.at
Thu Aug 17 16:52:03 EDT 2006


Log message for revision 69626:
  added ISized adapter

Changed:
  U   z3c.filetype/trunk/src/z3c/filetype/configure.zcml
  A   z3c.filetype/trunk/src/z3c/filetype/size.py

-=-
Modified: z3c.filetype/trunk/src/z3c/filetype/configure.zcml
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/configure.zcml	2006-08-17 20:51:08 UTC (rev 69625)
+++ z3c.filetype/trunk/src/z3c/filetype/configure.zcml	2006-08-17 20:52:02 UTC (rev 69626)
@@ -13,4 +13,8 @@
 
  
  <adapter factory=".adapters.TypedFileType"/>
+
+ <adapter factory=".size.ImageFileSized" />
+
+ 
 </configure>

Added: z3c.filetype/trunk/src/z3c/filetype/size.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/size.py	2006-08-17 20:51:08 UTC (rev 69625)
+++ z3c.filetype/trunk/src/z3c/filetype/size.py	2006-08-17 20:52:02 UTC (rev 69626)
@@ -0,0 +1,34 @@
+from zope.size.interfaces import ISized
+from zope.app.file.image import getImageInfo
+from zope.size import byteDisplay
+from interfaces.filetypes import IImageFile
+from zope import component, interface
+from zope.app.i18n import ZopeMessageFactory as _
+
+class ImageFileSized(object):
+    interface.implements(ISized)
+    component.adapts(IImageFile)
+    
+    def __init__(self, image):
+        self._image = image
+
+    def sizeForSorting(self):
+        '''See `ISized`'''
+        return ('byte', self._image.getSize())
+
+    def sizeForDisplay(self):
+        '''See `ISized`'''
+        t, w, h = getImageInfo(self._image.data.read(256))
+        if w < 0:
+            w = '?'
+        if h < 0:
+            h = '?'
+        bytes = self._image.getSize()
+        byte_size = byteDisplay(bytes)
+        mapping = byte_size.mapping
+        if mapping is None:
+            mapping = {}
+        mapping.update({'width': str(w), 'height': str(h)})
+        #TODO the way this message id is defined, it won't be picked up by
+        # i18nextract and never show up in message catalogs
+        return _(byte_size + ' ${width}x${height}', mapping=mapping)


Property changes on: z3c.filetype/trunk/src/z3c/filetype/size.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list