diff data/plugin/parser/text_x_arnica.py @ 181:b19e4e36a1f2

arnica: cosmetic fixes, improve docstrings, minor i18n bugfixes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 17 Jul 2008 23:02:03 +0200
parents 17e1c3d004bf
children 4fed0b16b6fb 7e23f320ce08
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Thu Jul 17 20:25:49 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Thu Jul 17 23:02:03 2008 +0200
@@ -35,7 +35,8 @@
 
 class _DataBrowserWidget(DataBrowserWidget):
     """ we have to remove the used form in format otherwise the needed form elements
-        becomes a nested form and this do raise lot's of strict html4.01 errors"""
+        becomes a nested form and this raises lots of strict html4.01 errors.
+    """
     def format(self):
         fmt = self.request.formatter
         result = []
@@ -62,7 +63,7 @@
                 result.append(fmt.strong(0))
                 if col.autofilter:
                     result.append(fmt.linebreak(False))
-                    select = '<select %s onchange="dbw_update_search(\'%s\');">%s</select>' % (
+                    select = """<select %s onchange="dbw_update_search('%s');">%s</select>""" % (
                                       self._name('filter%d' % idx),
                                       self.data_id,
                                       self._filteroptions(idx))
@@ -117,6 +118,7 @@
 
         return ''.join(result)
 
+
 def arnica_settings(target_page=u'', columns=4, file_regex=u'.',
                     image_for_webnail=False,
                     show_text=True, show_date=True, show_tools=False,
@@ -128,27 +130,27 @@
                     thumbnail_width=wikiutil.UnitArgument('128', float, ['px', ], defaultunit='px'),
                     webnail_width=wikiutil.UnitArgument('640', float, ['px', ], defaultunit='px')):
     """ dummy function 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 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_date: default shows date from exif header, if available
     @param show_tools: default does not show the icon toolbar
-    @param sort_by_name: default sorts images by name,
+    @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 only_items: if set only images which are described in listitem are shown, e.g.
+    @param sort_by_alias: if set, sorts images by the alias name, this also needs only_items enabled
+    @param reverse_sort: if set, the file list is sorted in reverse order
+    @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 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
-                  and will be recreated
-    @param thumbnail_width: default width of thumbnails is 128px
+    @param renew: if set then all selected thumbnails_* and webnails_* are removed and will be recreated
+    @param thumbnail_width: default width of thumbnail is 128px
     @param webnail_width: default width of webnail is 640px
     """
     if thumbnail_width:
@@ -163,14 +165,16 @@
             webnail_width = '%g%s' % webnail_width
     return locals()
 
+
 # ToDo may be move to wikiutil
 def get_exif_info(file_name):
     """ gets exif info from image file
+
     @param: image file name
     """
     date = "--"
     if wikiutil.isPicture(file_name):
-        # if there is no exif data available tags is an empty dict
+        # if there is no exif data available, tags is an empty dict
         exif_file = open(file_name, 'rb')
         tags = EXIF.process_file(exif_file, 'DateTimeOriginal')
         exif_file.close()
@@ -179,6 +183,7 @@
             date = date.replace(':', '-', 2)
     return date
 
+
 def _get_files(request, pagename):
     # get files dependent on isPicture and ignores tmp. files
     # ToDo remove tmp. files check later
@@ -229,65 +234,70 @@
         """
         if not self.request.user.may.delete(self.pagename):
             return ''
-        return '''
-        <form action="%(url)s" method="POST" enctype="multipart/form-data">
-            <div class="rotate-to-left">
-                <input type="hidden" name="action" value="arnica_slides">
-                <input type="hidden" name="do" value="rotate_left">
-                <input type="hidden" name="target" value="%(this_target)s">
-                <input type="image" value="submit" src="%(htdocs)s/arnica/img/arnica_rotate_to_left.png" title="rotate to left">
-            </div>
-        </form>
-        <form action="%(url)s" method="POST" enctype="multipart/form-data">
-            <div class="rotate-to-right">
-                <input type="hidden" name="action" value="arnica_slides">
-                <input type="hidden" name="do" value="rotate_right">
-                 <input type="hidden" name="target" value="%(this_target)s">
-                <input type="image"  value="submit" src="%(htdocs)s/arnica/img/arnica_rotate_to_right.png" title="rotate to right">
-            </div>
-        </form>
-        <form action="%(url)s" method="POST" enctype="multipart/form-data">
-             <div class="delete-image">
-                 <input type="hidden" name="action" value="arnica_slides">
-                 <input type="hidden" name="do" value="delete">
-                 <input type="hidden" name="target" value="%(this_target)s">
-                 <input type="image" value="submit" src="%(htdocs)s/arnica/img/arnica_remove_image.png" title="move to bak">
-             </div>
-        </form>''' % {
+        return """
+<form action="%(url)s" method="POST" enctype="multipart/form-data">
+    <div class="rotate-to-left">
+        <input type="hidden" name="action" value="arnica_slides">
+        <input type="hidden" name="do" value="rotate_left">
+        <input type="hidden" name="target" value="%(this_target)s">
+        <input type="image" value="submit" src="%(htdocs)s/arnica/img/arnica_rotate_to_left.png" title="rotate to left">
+    </div>
+</form>
+<form action="%(url)s" method="POST" enctype="multipart/form-data">
+    <div class="rotate-to-right">
+        <input type="hidden" name="action" value="arnica_slides">
+        <input type="hidden" name="do" value="rotate_right">
+         <input type="hidden" name="target" value="%(this_target)s">
+        <input type="image"  value="submit" src="%(htdocs)s/arnica/img/arnica_rotate_to_right.png" title="rotate to right">
+    </div>
+</form>
+<form action="%(url)s" method="POST" enctype="multipart/form-data">
+     <div class="delete-image">
+         <input type="hidden" name="action" value="arnica_slides">
+         <input type="hidden" name="do" value="delete">
+         <input type="hidden" name="target" value="%(this_target)s">
+         <input type="image" value="submit" src="%(htdocs)s/arnica/img/arnica_remove_image.png" title="move to bak">
+     </div>
+</form>
+""" % {
             'url': Page(self.request, self.pagename).url(self.request),
             'style': self.td_style,
             'htdocs': self.request.cfg.url_prefix_static,
             "pagename": wikiutil.quoteWikinameURL(self.pagename),
-            "this_target": this_target}
+            "this_target": this_target,
+        }
 
     def html_tools(self, idx):
         """ html code of thumbnails view with contol
+
         @param idx: index postion of corresponding data
         """
         this_image = self.high_resolution_image[idx]
-        text = '''
-        <form action="%(url)s" method="POST" enctype="multipart/form-data">
-            <div class="get-image">
-                <input type="hidden" name="action" value="AttachFile">
-                <input type="hidden" name="do" value="get">
-                <input type="hidden" name="target" value="%(this_target)s">
-                <input type="image" value="submit" src="%(htdocs)s/arnica/img/arnica_full_image.png" title="load image">
-            </div>
-        </form>
-        <form action="%(url)s" method="POST" enctype="multipart/form-data">
-            <div class="slide-show">
-                <input type="hidden" name="action" value="arnica_slides">
-                <input type="hidden" name="do" value="slide_show">
-                <input type="hidden" name="alias" value="%(description)s">
-                <input type="hidden" name="target" value="%(target)s">
-                <input type="hidden" name="pagename" value="%(pagename)s">
-                <input type="hidden" name="images" value="%(images)s">
-                <input type="hidden" name="original_images" value="%(original_images)s">
-                <input type="hidden" name="exif_date" value="%(exif_date)s">
-                <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
-                <input type="image" value="submit" title="slide show" src="%(htdocs)s/arnica/img/arnica_load_slide_show.png">
-            </div>
-        </form> %(html_tools_restricted)s''' % {
+        text = """
+<form action="%(url)s" method="POST" enctype="multipart/form-data">
+    <div class="get-image">
+        <input type="hidden" name="action" value="AttachFile">
+        <input type="hidden" name="do" value="get">
+        <input type="hidden" name="target" value="%(this_target)s">
+        <input type="image" value="submit" src="%(htdocs)s/arnica/img/arnica_full_image.png" title="load image">
+    </div>
+</form>
+<form action="%(url)s" method="POST" enctype="multipart/form-data">
+    <div class="slide-show">
+        <input type="hidden" name="action" value="arnica_slides">
+        <input type="hidden" name="do" value="slide_show">
+        <input type="hidden" name="alias" value="%(description)s">
+        <input type="hidden" name="target" value="%(target)s">
+        <input type="hidden" name="pagename" value="%(pagename)s">
+        <input type="hidden" name="images" value="%(images)s">
+        <input type="hidden" name="original_images" value="%(original_images)s">
+        <input type="hidden" name="exif_date" value="%(exif_date)s">
+        <input type="hidden" name="image_for_webnail" value="%(image_for_webnail)s">
+        <input type="image" value="submit" title="slide show" src="%(htdocs)s/arnica/img/arnica_load_slide_show.png">
+    </div>
+</form>
+%(html_tools_restricted)s
+""" % {
             "url": Page(self.request, self.pagename).url(self.request),
             "pagename": self.pagename,
             "htdocs": self.request.cfg.url_prefix_static,
@@ -303,8 +313,8 @@
             "original_images": packLine([self.high_resolution_image[idx]] + self.high_resolution_image),
             "this_target": self.high_resolution_image[idx],
             "thumbnail": "%s%s" % (AttachFile.getAttachUrl(self.pagename, '', self.request), self.thumb_key[idx]),
-            "html_tools_restricted": self.html_tools_restricted(this_image)
-            }
+            "html_tools_restricted": self.html_tools_restricted(this_image),
+        }
         return text
 
     def html_show_tools(self, idx):
@@ -338,7 +348,7 @@
         if self.album:
             title = '<div class="title">%(n)d images (%(album_title)s)</div>' % {"n": len(self.high_resolution_image),
                                                         "album_title": self.album_title or self.pagename}
-        text = '''
+        text = """
 <div class="arrange-thumbnails">
     <form action="%(url)s" method="POST" enctype="multipart/form-data">
         <div class="image"> %(title)s
@@ -357,24 +367,25 @@
     %(alias_html)s
     %(date_html)s
     %(html_tools)s
-</div>'''% {
-     "title": title,
-     "tdstyle": self.td_style,
-     "style": self.inner_table_style,
-     "url": Page(self.request, self.pagename).url(self.request),
-     "pagename": self.pagename,
-     "description": packLine([self.description[idx]] + self.description),
-     "exif_date": packLine([self.exif_date[idx]] + self.exif_date),
-     "image_for_webnail": self.image_for_webnail,
-     "target": self.webnail_image[idx],
-     "original_images": packLine([self.high_resolution_image[idx]] + self.high_resolution_image),
-     "images": packLine([self.webnail_image[idx]] + self.webnail_image),
-     "thumbnail": cache.url(self.request, self.thumb_key[idx]),
-     "thumbnail_width": self.thumbnail_width,
-     "html_tools": self.html_show_tools(idx),
-     "date_html": self.html_show_date(idx),
-     "alias_html": self.html_show_alias(idx)
-     }
+</div>
+""" % {
+            "title": title,
+            "tdstyle": self.td_style,
+            "style": self.inner_table_style,
+            "url": Page(self.request, self.pagename).url(self.request),
+            "pagename": self.pagename,
+            "description": packLine([self.description[idx]] + self.description),
+            "exif_date": packLine([self.exif_date[idx]] + self.exif_date),
+            "image_for_webnail": self.image_for_webnail,
+            "target": self.webnail_image[idx],
+            "original_images": packLine([self.high_resolution_image[idx]] + self.high_resolution_image),
+            "images": packLine([self.webnail_image[idx]] + self.webnail_image),
+            "thumbnail": cache.url(self.request, self.thumb_key[idx]),
+            "thumbnail_width": self.thumbnail_width,
+            "html_tools": self.html_show_tools(idx),
+            "date_html": self.html_show_date(idx),
+            "alias_html": self.html_show_alias(idx),
+        }
         return text
 
     def define_thumb_webnails(self, path, files, quotes):
@@ -410,8 +421,8 @@
                 self.exif_date.append(self.formatter.text(date))
 
     def to_wikitext(self, text):
-        """
-        converts text to wiki name if it is written as WikiName or [[wikiname]]
+        """ converts text to wiki name if it is written as WikiName or [[wikiname]]
+
         @param text: text to parse and render
         """
         text = ''.join(text)
@@ -419,8 +430,8 @@
         return wikiutil.renderText(self.request, WikiParser, text)
 
     def get_quotes(self):
-        """  get's the qoutes from the itemlist  """
-        # ToDo make this more generic and use common libs of similiar modules
+        """  gets the quotes from the item list  """
+        # ToDo make this more generic and use common libs of similar modules
         quotes = self.raw.split('\n')
         quotes = [quote.strip() for quote in quotes]
         quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
@@ -481,11 +492,11 @@
             all_files.reverse()
         if all_files:
             self.define_thumb_webnails(path, all_files, quotes)
-
         return all_files
 
     def create_thumbnail_and_webnail_image(self, image, webnail, thumbnail, image_type):
-        """creates thumbnails and webnails cache files for given image type
+        """ creates thumbnails and webnails cache files for given image type
+
         @param image: filename of image
         @param webnail: name of webnail file
         @param thumbnail: name of thumbnail file
@@ -493,7 +504,7 @@
         """
         _ = self.request.getText
         if not Image:
-            msg = _('The parser %(parser)s needs python imaging library (PIL) installed' % {'parser': parser_name})
+            msg = _('The parser %(parser)s needs python imaging library (PIL) installed') % {'parser': parser_name}
             self.request.write(self.formatter.text(msg))
             return
 
@@ -525,7 +536,7 @@
                 self.request.write(self.formatter.text(msg))
                 return
 
-           # XXX later on a unit conversion method for using other units than 'px' is needed
+           # XXX later, 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((int(self.webnail_width.strip('px')), int(self.webnail_width.strip('px'))), Image.ANTIALIAS)
@@ -564,10 +575,10 @@
 
         if self.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:""")
+            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(self.formatter.text(text))
             self.request.write(self.formatter.div(1))
             self.request.write(self.formatter.preformatted(1))
@@ -618,9 +629,9 @@
                     self.webnail_image = self.high_resolution_image
                 text = self.html_arrange_thumbnails(i)
             except ValueError:
-                text = self.formatter.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, })
+                text = self.formatter.text(_('You can't use as album image: '
+                         '"%(album_image)s" because it does not exist or it is not listed '
+                         'in your item list!') % {"album_image": album_image, })
 
             result.append(''.join(text))
 
@@ -638,3 +649,4 @@
             self.request.write(self.formatter.div(1, css_class="arnica"))
             self.request.write(self.render(formatter))
             self.request.write(self.formatter.div(0))
+