changeset 149:62a6c964e63b

fixed and added docstrings
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 11 Jul 2008 12:56:16 +0200
parents a8257933a22f
children 2250b8121f04 7438cd3fdfba
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 32 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Mon Jun 30 15:27:04 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Fri Jul 11 12:56:16 2008 +0200
@@ -3,22 +3,22 @@
     MoinMoin - arnica parser
 
     This parser is used to visualize a couple of images as a thumbnail gallery.
-    Optional a description of an image could be added including WikiName.
-    On default the image name and it's creation date is shown.
-    If you click on a thumbnail you get the webnails shown.
-    By a menue you are able to toggle between the slides.
+    Optionally, a description of an image can be added.
+    
+    By default the image name and its creation date is shown.
+    If you click on a thumbnail you get navigation tools shown to slide through your images.
 
-
-    MODIFICATION HISTORY:
-    based on Gallery2 by ReimarBauer 2005-2008, ThomasWaldmann 2005, FlorianFesti 2006
+    Based on Gallery2 by ReimarBauer 2005-2008, ThomasWaldmann 2005, FlorianFesti 2006
 
     @copyright: 2008 by MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
+
 import os, re
 from random import randint
+
 from MoinMoin import caching, config, wikiutil
-from MoinMoin.action import AttachFile
+from MoinMoin.action import AttachFile, sendcached
 from MoinMoin.filter import EXIF
 from MoinMoin.packages import packLine
 from MoinMoin.Page import Page
@@ -136,23 +136,23 @@
                     renew=False,
                     thumbnail_width=wikiutil.UnitArgument('128', float, ['px', ], defaultunit='px'),
                     webnail_width=wikiutil.UnitArgument('640', float, ['px', ], 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. empty pagename is current page
+    """ dummy macro to initialize all default parameters for arnica. The parameters are checked for wrong input.
+    @param target_page: page to read attachments from. empty pagename is current page.
     @param columns: number of columns for thumbnails
-    @param file_regex: regex to select images
+    @param file_regex: regex for selecting images
     @param image_for_webnail if set then the image is shown instead of the webnail
     @param show_text: default shows description
     @param show_date: default shows date from exif header if available
-    @param show_tools: default shows not icon toolbar
+    @param show_tools: default does not show the icon toolbar
     @param sort_by_name: default sorts images by name,
-    @param sort_by_date: if set sorts images by the modification time
-    @param sort_by_alias: if set sorts images by the alias name, this needs also only_items enabled
-    @param reverse_sort: if set the file list is reverse sorted
+    @param sort_by_date: if set, sorts images by the modification time
+    @param sort_by_alias: if set, sorts images by the alias name, this needs also only_items enabled
+    @param reverse_sort: if set, the file list is reverse sorted
     @param only_items: if set only images which are described in listitem are shown, e.g.
                        * [[image1.jpg|alias]]
                        * [[image2.jpg|alias]]
-    @param template_itemlist: if set an item list is shown which could be copied into the wiki page
-    @param album: if set selects album mode, only thumbnail from first image is shown, related is album title and album_image
+    @param template_itemlist: if set, an item list is shown which could be copied into the wiki page
+    @param album: if set, selects album mode, only thumbnail from first image is shown, related is album title and album_image
     @param album_title: default is pagename of the images for the album.
     @param album_image: image to show on album default is the first image 
     @param renew: if set then all selected thumbnails_* and webnails_* are removed
@@ -181,15 +181,18 @@
     """
     date = "--"
     if wikiutil.isPicture(file_name):
+        # XXX what happens if it is not a jpeg file 
         id_file = open(file_name, 'rb')
         tags = EXIF.process_file(id_file, 'DateTimeOriginal')
         id_file.close()
+        # ToDo change to "in dict"
         if tags.has_key('EXIF DateTimeOriginal'):
             date = str(tags['EXIF DateTimeOriginal'])
             date = wikiutil.escape(date.replace(':', '-', 2))
     return date
 
 def _get_files(request, pagename):
+    # ToDo AttachFile._get_files and filter result
     attach_dir = AttachFile.getAttachDir(request, pagename)
     files = []
     if os.path.isdir(attach_dir):
@@ -213,7 +216,7 @@
         self.request = request
         self.form = None
         self._ = request.getText
-
+        # ToDo add formatter 
         args = kw.get('format_args', '')
         self.init_settings = False
         # we use a macro definition to initialize the default init parameters
@@ -226,6 +229,7 @@
             self.init_settings = True
         except ValueError, err:
             msg = u"arnica: %s" % err.args[0]
+            # ToDo use formatter
             request.write(wikiutil.escape(msg))
 
         self.inner_table_style = ' style="border-style:none; margin:10px;"'
@@ -433,6 +437,7 @@
 
     def get_quotes(self):
         """  get's the qoutes from the itemlist  """
+        # ToDo make this more generic and use common libs of similiar modules
         quotes = self.raw.split('\n')
         quotes = [quote.strip() for quote in quotes]
         quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
@@ -479,11 +484,13 @@
             all_files = _get_files(self.request, self.pagename)
         if self.file_regex != u'.':
             all_files = [attfile for attfile in all_files if re.match(self.file_regex, attfile)]
+            # ToDo and not self.only_items
         if self.sort_by_name and self.only_items is False:
             all_files.sort()
         if self.sort_by_date:
             for attfile in all_files:
                 infile = os.path.join(path, attfile)
+                # ToDo take hex values 
                 ft_file = "%s%s" % (os.path.getmtime(infile), randint(0, 65535))
                 image_dict[ft_file] = attfile
             keys = image_dict.keys()
@@ -506,6 +513,7 @@
         @param thumbnail: name of thumbnail file
         @param image_type: filetype of image
         """
+        # XXX request.write always with formatter
         _ = self.request.getText
         if not Image:
             msg = _('The parser %(parser)s needs python imaging library (PIL) installed' % {'parser': parser_name})
@@ -534,6 +542,7 @@
             try:
                 im_obj = Image.open(imagef)
             except IOError:
+                # ToDo tell why
                 return
 
            # XXX later on a unit conversion method for using other units than 'px' is needed
@@ -556,7 +565,8 @@
             return
 
         if self.target_page and (not Page(self.request, self.target_page).exists() or not self.request.user.may.read(self.target_page)):
-            self.request.write(_("Page %(pagename)s does not exists or you don't have enough rights." % {"pagename": self.target_page}))
+            # ToDo look at other messages
+            self.request.write(_("Page %(pagename)s does not exist or you don't have enough rights." % {"pagename": self.target_page}))
             return
 
         if not self.select_files(formatter):
@@ -564,6 +574,7 @@
             return
 
         if self.template_itemlist:
+            # ToDo use formatter.raw_html
             self.request.write(_("""<div class="text">
             Copy the following listitems into the script.
             Replace alias with the label you want.
@@ -618,6 +629,7 @@
                     self.webimg = self.full
                 text = self.html_arrange_thumbnails(i)
             except ValueError:
+                # ToDo use """ """
                 text = _('You can''t use as album image: "%(album_image)s" because it does not exists or it is not listed in your item list!') % {"album_image": album_image, }
             result.append(''.join(text))
 
@@ -632,6 +644,7 @@
     def format(self, formatter):
         """ parser output """
         # checks if initializing of all attributes in __init__ was done
+        # ToDo use formatter
         if self.init_settings:
             self.request.write('<div class="arnica">')
             self.request.write(self.render(formatter))