changeset 112:8438a033d483

text_x_arnica.macro_arnica: uses the unitparser for thumbnail_width, webnail_width, text_width default unit is px (because PIL thumbnail requires px)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 27 Jun 2008 08:32:00 +0200
parents 2159a14c54ea
children d126ba077c06
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Fri Jun 27 07:52:37 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Fri Jun 27 08:32:00 2008 +0200
@@ -42,8 +42,9 @@
                  only_items=False, template_itemlist=False,
                  album=False, album_title=unicode, album_image=u'',
                  renew=False,
-                 thumbnail_width=128, webnail_width=640,
-                 text_width=128):
+                 thumbnail_width=wikiutil.UnitArgument('128', float, ['px', ], defaultunit='px'), 
+                 webnail_width=wikiutil.UnitArgument('640', float, ['px', ], defaultunit='px'),
+                 text_width=wikiutil.UnitArgument('140', float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px')):
     """ dummy macro to initialize all default parameters for arnica. The definition is checked for wrong input.
     @param target_page: page to read attachments from
     @param columns: number of columns for thumbnails
@@ -68,10 +69,28 @@
                          of the album and slideshow.
     @param renew: if set then all selected thumbnails_* and webnails_* are removed
                   and will be recreated
-    @param thumbnail_width: default width of thumbnails is 128
-    @param webnail_width: default width of webnail is 640
-    @param text_width: default width of text is 140
+    @param thumbnail_width: default width of thumbnails is 128px
+    @param webnail_width: default width of webnail is 640px
+    @param text_width: default width of text is 140px
     """
+    if thumbnail_width:
+        if thumbnail_width[1] == 'px':
+            thumbnail_width = '%dpx' % int(thumbnail_width[0])
+        else:
+            thumbnail_width = '%g%s' % thumbnail_width
+
+    if webnail_width:
+        if webnail_width[1] == 'px':
+            webnail_width = '%dpx' % int(webnail_width[0])
+        else:
+            webnail_width = '%g%s' % webnail_width
+
+    if text_width:
+        if text_width[1] == 'px':
+            text_width = '%dpx' % int(text_width[0])
+        else:
+            text_width = '%g%s' % text_width
+            
     return locals()
 
 # ToDo may be move to wikiutil
@@ -440,13 +459,14 @@
             except IOError:
                 return
 
+           # XXX later on a unit conversion method for using other units than 'px' is needed
             if not cache_web.exists():
                 if not self.image_for_webnail:
-                    im_obj.thumbnail((self.webnail_width, self.webnail_width), Image.ANTIALIAS)
+                    im_obj.thumbnail((self.webnail_width, int(self.webnail_width.strip('px'))), Image.ANTIALIAS)
                     im_obj.save(webf, image_type)
 
             if not cache_thumb.exists():
-                im_obj.thumbnail((self.thumbnail_width, self.thumbnail_width), Image.ANTIALIAS)
+                im_obj.thumbnail((self.thumbnail_width, int(self.thumbnail_width.strip('px'))), Image.ANTIALIAS)
                 im_obj.save(thumbf, image_type)
 
     def render(self, formatter):