changeset 155:3d5773a1e24b

text_x_arnica: output text by the formatter
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 11 Jul 2008 19:17:44 +0200
parents 67697aaa2b88
children a6ff4cf3dbc2
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 32 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Fri Jul 11 17:48:42 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Fri Jul 11 19:17:44 2008 +0200
@@ -4,7 +4,7 @@
 
     This parser is used to visualize a couple of images as a thumbnail gallery.
     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.
 
@@ -154,7 +154,7 @@
     @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 album_image: image to show on album default is the first image
     @param renew: if set then all selected thumbnails_* and webnails_* are removed
                   and will be recreated
     @param thumbnail_width: default width of thumbnails is 128px
@@ -181,7 +181,7 @@
     """
     date = "--"
     if wikiutil.isPicture(file_name):
-        # XXX what happens if it is not a jpeg file 
+        # 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()
@@ -194,7 +194,7 @@
 def _get_files(request, pagename):
     # get files dependent on isPicture and ignores tmp. files
     # ToDo remove tmp. files check later
-    
+
     files = AttachFile._get_files(request, pagename)
     files = [fn for fn in files if wikiutil.isPicture(fn) and not fn.startswith('tmp.')]
     return files
@@ -216,7 +216,7 @@
         self.formatter = request.formatter
         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
@@ -490,7 +490,7 @@
         if self.sort_by_date:
             for attfile in all_files:
                 infile = os.path.join(path, attfile)
-                # ToDo take hex values 
+                # ToDo take hex values
                 ft_file = "%s%s" % (os.path.getmtime(infile), randint(0, 65535))
                 image_dict[ft_file] = attfile
             keys = image_dict.keys()
@@ -513,11 +513,10 @@
         @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})
-            self.request.write(msg)
+            self.request.write(self.formatter.text(msg))
             return
 
         path = AttachFile.getAttachDir(self.request, self.pagename, create=1)
@@ -565,27 +564,33 @@
             return
 
         if self.target_page and (not Page(self.request, self.target_page).exists() or not self.request.user.may.read(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}))
+            text = _("""Page '%(new_pagename)s' does not exist or you don't have enough rights.""") % {"pagename": self.target_page}
+            self.request.write(self.formatter.text(text))
             return
 
         if not self.select_files(formatter):
-            self.request.write(_("No matching image file found!"))
+            text = _("No matching image file found!")
+            self.request.write(self.formatter.text(text))
             return
 
         if self.template_itemlist:
-            # ToDo use formatter.raw_html
-            self.request.write(_("""<div class="text">
+            # XXX remove from css template-itemlist
+            self.request.write(self.formatter.div(1, css_class="text"))
+            text = _("""
             Copy the following listitems into the script.
             Replace alias with the label you want.
-            Afterwards disable template_itemlist by setting it to False:"""))
-            self.request.write('<div class="template-itemlist">')
+            Afterwards disable template_itemlist by setting it to False:""")
+            self.request.write(self.formatter.text(text))
+            self.request.write(self.formatter.div(1))
+            self.request.write(self.formatter.preformatted(1))
             for image in self.full:
-                self.request.write('<br> * [[%(image)s|%(alias)s]]\n' % {
-                                   'image': image,
-                                   'alias': 'alias'
-                                    })
-            self.request.write('</div></div>')
+                text = ' * [[%(image)s|alias]]\n' % {
+                           'image': image,
+                        }
+                self.request.write(self.formatter.text(text))
+            self.request.write(self.formatter.preformatted(0))
+            self.request.write(self.formatter.div(0))
+            self.request.write(self.formatter.div(0))
 
         COLUMNS = min([self.columns, len(self.full)])
         if self.album:
@@ -630,8 +635,11 @@
                 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))
+                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(self.formatter.text(text)))
 
         # adds the last row if it is not filled up
         if result:
@@ -644,8 +652,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.formatter.div(1, css_class="arnica"))
             self.request.write(self.render(formatter))
-            self.request.write('</div>')
+            self.request.write(self.formatter.div(0))