changeset 278:03071c3569d8

refactored for macro Image to use parts of arnicas rendering
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 17 Sep 2008 11:31:29 +0200
parents 0430039fe8c5
children b0b6555e77e3
files data/plugin/action/arnica_slides.py data/plugin/macro/Image.py data/plugin/macro/arnica.py data/plugin/parser/text_x_arnica.py
diffstat 4 files changed, 47 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Tue Sep 16 12:27:06 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Wed Sep 17 11:31:29 2008 +0200
@@ -220,9 +220,9 @@
     link_to_image = AttachFile.getAttachUrl(pagename, original_images[idx], request)
     option_webnail = option_list(image_url, images, original_images, request)
     inner_table_style = ' style="border-style:none; margin:10px;"'
-
-    html = """
-<div class="arnica-slides">
+    navigation = ""
+    if len(images) > 1:
+        navigation = """\
 <div class="navigation-animation">
 <form name=slideform method="POST" action="">
 <div>
@@ -245,6 +245,18 @@
 <a class="next_slide" onClick="arnica_next_slide();"  title="next slide"></a>
 <span id="arnica_last_slide"><a class="last_slide" onClick="arnica_last_slide();" title="last slide" ></a></span>
 </div>
+""" % {
+        "this_webnail_list": this_webnail_list,
+        "this_webnail_name": packLine(images),
+        "original_images": packLine(original_images),
+        "this_alias_list": wikiutil.escape(packLine(alias), quote=1),
+        "this_exif_date_list": wikiutil.escape(packLine(exif_date), quote=1),
+        "option_webnails": option_webnail,
+    }
+
+    html = """
+<div class="arnica-slides">
+%(navigation)s
 <div class="image">
 <img src="%(server)s%(this_image)s" name="show" alt="%(this_alias_text)s,%(this_exif_date_text)s">
 </div>
@@ -255,20 +267,12 @@
 </div>
 """ % {
         "server": request.getQualifiedURL(),
-        "htdocs": request.cfg.url_prefix_static,
-        "base_url": request.getScriptname(),
         "link_url": link_to_image,
-        "this_webnail_list": this_webnail_list,
-        "this_webnail_name": packLine(images),
-        "original_images": packLine(original_images),
         "this_alias_text": wikiutil.escape(alias[idx], quote=1),
-        "this_alias_list": wikiutil.escape(packLine(alias), quote=1),
         "this_exif_date_text": wikiutil.escape(exif_date[idx], quote=1),
-        "this_exif_date_list": wikiutil.escape(packLine(exif_date), quote=1),
         "this_image": image_url,
         "pagename": pagename,
-        "tablestyle": inner_table_style,
-        "option_webnails": option_webnail,
+        "navigation": navigation,
     }
     return html
 
--- a/data/plugin/macro/Image.py	Tue Sep 16 12:27:06 2008 +0200
+++ b/data/plugin/macro/Image.py	Wed Sep 17 11:31:29 2008 +0200
@@ -66,17 +66,21 @@
         self.__description = self.attachname
 
     def _get_description(self):
-        quotes = self.raw.split('\n')
-        quotes = [quote.strip() for quote in quotes]
-        quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
-        image_alias = self.attachname
-        for line in quotes:
-            if line.startswith('[[') and line.endswith(']]'):
-                img, alias = line[2:-2].split('|', 1)
-                if img.strip() == self.attachname:
-                    self.__description = alias.strip()
-                    break
-        return self.__description
+        if self.raw is None:
+            self.__description = self.attachname
+            return self.__description
+        else:
+            quotes = self.raw.split('\n')
+            quotes = [quote.strip() for quote in quotes]
+            quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
+            image_alias = self.attachname
+            for line in quotes:
+                if line.startswith('[[') and line.endswith(']]'):
+                    img, alias = line[2:-2].split('|', 1)
+                    if img.strip() == self.attachname:
+                        self.__description = alias.strip()
+                        break
+            return self.__description
     description = property(_get_description)
 
     def _get_filename(self):
@@ -261,8 +265,16 @@
 
         <<Image(PageName/attachname,width=100,alt="sample image")>>
     """
+    arnica_parser = wikiutil.importWikiPlugin(macro.request.cfg, "parser", "text_x_arnica", function="Parser")
     if '/' not in itemname:
         itemname = macro.formatter.page.page_name + '/' + itemname
-    img = Image(macro.request, itemname, caption=alt)
-    return macro.formatter.image(src=img.url((width, height)), alt=img.caption)
-
+    raw = " * [[%s | %s]]\n" % (itemname.split('/')[1], (alt or (itemname.split('/')[1])))
+    img = Image(macro.request, itemname, caption=alt, raw=raw)
+    try:
+        exif_date = time.strftime("%Y-%m-%d %H:%M:%S", macro.request.user.getTime(img.exif["DateTimeOriginal"]))
+    except KeyError:
+        exif_date = '--'
+    # ToDo use alt attribute in arnica for one image instead of Slide Show title
+    ap = arnica_parser(raw, macro.request, image=img)
+    ap.arnica_image[img.attachname] = (img.url(), img.url(size=(width, height)), exif_date, img.description, "0")
+    return ap.render(macro.formatter)
--- a/data/plugin/macro/arnica.py	Tue Sep 16 12:27:06 2008 +0200
+++ b/data/plugin/macro/arnica.py	Wed Sep 17 11:31:29 2008 +0200
@@ -28,8 +28,4 @@
             return ap.render(self.formatter)
 
 def execute(macro, args):
-    result = arnica(macro, args).renderInPage()
-    if result:
-        return '<div class="arnica"> %s </div>' % result
-    else:
-        return u''
+    return arnica(macro, args).renderInPage()
--- a/data/plugin/parser/text_x_arnica.py	Tue Sep 16 12:27:06 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Wed Sep 17 11:31:29 2008 +0200
@@ -362,7 +362,7 @@
             self.request.write(self.formatter.text(text))
             return
 
-        if not self.select_files(formatter):
+        if not self.arnica_image and not self.select_files(formatter):
             text = _("No matching image file found!")
             self.request.write(self.formatter.text(text))
             return
@@ -407,7 +407,9 @@
                     col_count = 0
                     result.append('<br class="clearboth">')
                 col_count += 1
-
+                
+        result.insert(0, self.formatter.div(1, css_class="arnica"))
+        result.append(self.formatter.div(0))
         return ''.join(result)
 
 
@@ -415,7 +417,5 @@
         """ parser output """
         # checks if initializing of all attributes in __init__ was done
         if self.init_settings:
-            self.request.write(self.formatter.div(1, css_class="arnica"))
             self.request.write(self.render(formatter))
-            self.request.write(self.formatter.div(0))