Attachment 'Gallery2-1.3.5-12.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Gallery2 parser
   4 
   5     PURPOSE:
   6         This parser is used to visualize a couple of images as a thumbnail gallery.
   7         Optional a description of an image could be added including WikiName.
   8         On default the image name and it's creation date is shown.
   9         If you click on a thumbnail you get the webnails shown. By a menue you are able to toggle between the slides.
  10 
  11     CALLING SEQUENCE:
  12       {{{
  13       #!Gallery2 [columns=columns],[filter=filter],[mode=mode],
  14                  [show_text=show_text],[show_date=show_date], [show_tools=show_tools],
  15                  [sort_by_name=sort_by_name],[sort_by_date=sort_by_date], [sort_by_alias=sort_by_alias],
  16                  [reverse_sort=reverse_sort],
  17                  [only_items=only_items],[template_itemlist=template_itemlist],
  18                  [album=album],[album_name=album_name],[front_image=front_image],
  19                  [thumbnail_width=thumbnail_width],[webnail_width=webnail_width],[text_width=text_width],
  20                  [image_for_webnail=image_for_webnail],
  21                  [border_thick=border_thick],[renew=renew],[help=help]
  22       * [image1.jpg alias]
  23       * [image2.jpg alias]
  24       }}}
  25 
  26     KEYWORD PARAMETERS:
  27         columns:           number of columns for thumbnails
  28         filter:            regex to select images
  29         show_text:         default is 1 description is shown
  30                            any other means no description
  31         show_date:         default is 1 date info from exif header if available is shown
  32         show_tools:        default is 1 icon toolbar is show any other disables this
  33         sort_by_name:      default is 1, the images are sorted by name, but not if only_items is 1
  34         sort_by_date:      default is 0, if set to 1 the images are sorted to the modification time
  35         sort_by_alias      default is 0, if set to 1 and only_items set to 1 it is used to order the images by the alias name
  36         reverse_sort:      default is 0, if set to 1 the file list is reversed
  37                            any other means no description
  38         mode:              default is 1 this means description below the image
  39                            any other number means description right of image
  40         only_items:        default is 0 if it is set to 1 only images which are described in listitem are shown
  41                            dependend on the order of the items
  42         template_itemlist: default is 0, if set to 1 an item list is shown which could be copied into the script. 
  43         album:             default is 0 if set to 1 only the first image of a series is shown but slideshow over all images 
  44         album_name:        useful for album. default is 'album' use it as short name for the album. 
  45         front_image:       Useful for album.  default is ''. The first image is shown in front of the album and slideshow.
  46                            If set to an existing image name this is shown in front of album and slideshow. 
  47                            The slide show could start by this somewhere.
  48         border_thick:      default is 1 this is the thickness in pixeln of the outer frame
  49         renew:             default is 0 if set to 1 then all selected thumbnails_* and webnails_* removed.
  50                            Afterwards they are new created.
  51         thumbnail_width:   default is 128
  52         webnail_width:     default is 640
  53         text_width:        default is 140		   
  54         image_for_webnail  default is 0 if set to 1 then the image is shown as preview and not the webnail
  55         help:              default is 0 if set a copy of the CALLING SEQUENCE is shown, 
  56                            (there are some new ideas around to show help to an user so this will be later replaced)
  57 
  58     OPTIONAL INPUTS:
  59         itemlist : if it is used and only_items is 1 then only the images in this list are ahown.
  60                    The alias text is used as description of the image instead of the file name
  61 
  62 
  63     EXAMPLE:
  64 = GalleryTest =
  65 
  66 == all images shown, one is decribed ==
  67 {{{
  68 { { {
  69 #!Gallery2
  70 * [100_1185.JPG Bremen, SpaceCenter]
  71 } } }
  72 }}}
  73 
  74 Result: [[BR]]
  75  {{{
  76 #!Gallery2
  77 * [100_1185.JPG Bremen, SpaceCenter]
  78 }}}
  79 
  80 == only thumbnails and only_items ==
  81 {{{
  82 { { {
  83 #!Gallery2 show_text=0,show_tools=0,show_date=0,columns=2,only_items=1
  84  * [100_1185.JPG Bremen, SpaceCenter]
  85  * [100_1194.JPG Bremen]
  86 } } }
  87 }}}
  88 
  89 Result: [[BR]]
  90  {{{
  91 #!Gallery2 show_text=0,show_tools=0,show_date=0,columns=2,only_items=1
  92  * [100_1185.JPG Bremen, SpaceCenter]
  93  * [100_1194.JPG Bremen]
  94 }}}
  95 
  96 == only_items by two columns and text right ==
  97 
  98 {{{
  99 { { {
 100 #!Gallery2 mode=2,columns=2,only_items=1
 101  * [100_1185.JPG Bremen, SpaceCenter]
 102  * [100_1194.JPG Bremen]
 103 } } }
 104 }}}
 105 
 106 Result: [[BR]]
 107  {{{
 108 #!Gallery2 mode=2,columns=2,only_items=1
 109  * [100_1185.JPG Bremen, SpaceCenter]
 110  * [100_1194.JPG Bremen, behind SpaceCenter]
 111 }}}
 112 
 113 ----
 114 
 115 == only_items by two columns, date supressed ==
 116 
 117 {{{
 118 { { {
 119 #!Gallery2 columns=2,only_items=1,show_date=0
 120  * [100_1185.JPG Bremen, SpaceCenter]
 121  * [100_1194.JPG Bremen, behind SpaceCenter]
 122 } } }
 123 }}}
 124 
 125 Result: [[BR]]
 126  {{{
 127 #!Gallery2 columns=2,only_items=1,show_date=0
 128  * [100_1185.JPG Bremen, SpaceCenter]
 129  * [100_1194.JPG Bremen, behind SpaceCenter]
 130 }}}
 131 
 132 
 133 == filter regex used, mode 2, icons and date supressed, one column and border_thick=5 ==
 134 {{{
 135 { { {
 136 #!Gallery2 columns=1,filter=100_118[0-5],mode=2,show_date=0,show_tools=0,border_thick=5
 137 } } }
 138 }}}
 139 
 140 Result: [[BR]]
 141  {{{
 142 #!Gallery2 columns=1,filter=100_118[0-7],mode=2,show_date=0,show_tools=0,border_thick=5
 143 }}}
 144 
 145 == other macro calls ==
 146 {{{
 147 { { {
 148 #!Gallery2 only_items=1,show_date=0
 149  * [100_1189.JPG [[MiniPage(||Bremen||SpaceCenter||\n|| ||SpaceJump||)]]]
 150 } } }
 151 }}}
 152 
 153 Result: [[BR]]
 154  {{{
 155 #!Gallery2 only_items=1,show_date=0
 156  * [100_1189.JPG [[MiniPage(||Bremen||SpaceCenter||\n|| ||SpaceJump||)]]]
 157 }}}
 158 
 159 == renew means always new thumbnails and webnails of selection ==
 160 {{{
 161 { { {
 162 #!Gallery2 only_items=1,show_date=0,show_tools=0,renew=1
 163  * [100_1189.JPG [[MiniPage(||["Bremen"]||SpaceCenter||\n|| ||SpaceJump||)]]]
 164 } } }
 165 }}}
 166 
 167 Result: [[BR]]
 168  {{{
 169 #!Gallery2 only_items=1,show_date=0,renew=1
 170  * [100_1189.JPG [[MiniPage(||["Bremen"]||SpaceCenter||\n|| ||SpaceJump||)]]]
 171 }}}
 172 
 173 == template_itemlist ==
 174 {{{
 175 { { {
 176 #!Gallery2 template_itemlist=1
 177 * [100_1185.JPG Bremen, SpaceCenter]
 178 } } }
 179 }}}
 180 
 181 Result: [[BR]]
 182  {{{
 183 #!Gallery2 template_itemlist=1
 184 * [100_1185.JPG Bremen, SpaceCenter]
 185 }}}
 186 
 187 == help to show Calling Sequence ==
 188  {{{
 189 { { {
 190 #!Gallery2 help=1
 191 } } }
 192 }}}
 193 
 194 Result: [[BR]]
 195 {{{
 196 #!Gallery2 help=1
 197 }}}
 198 
 199 
 200     PROCEDURE:
 201       Download some images to a page and start with the examples.
 202       Aliasing of the filenames are done by adding an itemlist, see example.
 203 
 204       This routine requires the PIL (Python Imaging Library).
 205       And the EXIF routine from http://home.cfl.rr.com/genecash/digital_camera.html
 206 
 207 
 208       At the moment I have added the EXIF routine to the parsers dir.
 209       It's not the best place but during developing it is nice to have it there
 210       If you put it to another place you have to change the line
 211       from MoinMoin.parser import EXIF too.
 212 
 213       This routine requires the Action macro gallery2Image which is used to rotate or delete a selected image.
 214       Only users which have the rights to delete are able to execute this action macro.
 215       The icons of these are only shown if you have enough rights.
 216 
 217       The gallery2image macro does not take care on the EXIF header. This is lost by rotating.
 218       If a file is deleted by this macro it is moved to a bak file.
 219 
 220       Please remove the Version number from the code!
 221 
 222     RESTRICTIONS:
 223       The movie mode is not implemented at the moment. The implementation will be done in the action macro.
 224       
 225       
 226       If you rotate an image at the moment the exif is destroyed. PIL ignores the exif header.
 227       This is not a quite big problem normally files with an EXIF header are right rotated.
 228 
 229     Required Images:
 230       I have put them to wiki/modern/img/ dir. The icons were created by me. License: GPL
 231 
 232     attachment:to_bak.png
 233     attachment:to_left.png
 234     attachment:to_right.png
 235     attachment:to_slide.png
 236     attachment:to_full.png
 237 
 238     HISTORY:
 239     While recognizing how to write MiniPage I got the idea to write a Gallery Parser.
 240     We have used in our wikis in the past the Gallery macro of SimonRyan.
 241     I have tried to modify it a bit to change it for 1.3 but my python skills weren't enough
 242     or it was easier to write it completly new.
 243     So this one shows now a way how a Gallery could be used by the parser and an action Macro.
 244     Probably it is a good example for others who like to know how to do this
 245 
 246     MODIFICATION HISTORY:
 247         Version 1.3.3.-1
 248         @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
 249         @license: GNU GPL, see COPYING for details.
 250         2005-03-26: Version 1.3.3-2 keyword renew added
 251                     creation of thumbnails and webnails in two calls splitted
 252                     Version 1.3.3-3 bug fixed if itemlist is given to describe only some of the images
 253                                     but only_items is not set to 1
 254                                     Example code changed
 255         2005-03-27: Version 1.3.3-4 Action macro added and the form to call it. User which have rights to delete
 256                                     could use the functions of gallery2Image.
 257         2005-08-03: Version 1.3.3-5 theme path for icons corrected and a platform independent path joining
 258                                     os.unlink removed as suggested by CraigJohnson
 259                                     sort_by_name is default if not only_items is 1
 260                                     optional sort_by_date could be used
 261                                     keyword template_itemlist added 
 262                                     keyword help added
 263                                     extra frame by mode=2 removed 
 264         2005-08-06: Version 1.3.5-6 slideshow mode added
 265                                     keyword image_for_webnail added
 266         2005-08-13: Version 1.3.5-7 syntax changed from GET to POST
 267                                     forms instead of links
 268                                     filenames from images submitted to gallery2image too
 269                                     new keyword sort_by_alias
 270                                     internal code clean up
 271                                     this version needs: gallery2image-1.3.5-5.py
 272         2005-08-14: Version 1.3.5-8 (TW) cleanup                                    
 273         2005-08-14: Version 1.3.5-9 html code for tables changed
 274                                     because of the ugly extra space of form elements
 275                                     </div> tag removed so now we use the page style
 276                                     slide show action goes to right webnail now
 277                                     this version needs: gallery2image-1.3.5-5.py
 278        2005-08-17: Version 1.3.5-10 html code separated in functions     
 279                                     structure of code changed, now you see the thumbnails after creation
 280                                     bug removed if quote is given but file does not exist
 281        2005-09-02: Version 1.3.5-11 keyword album, album_name and front_image added          
 282                                     image urls changed to complete server url      
 283        2005-11-12: Version 1.3.5-12 bug fixed for image_for_webnail=1,renew=1              
 284                                     bug fixed at last cell table end </tr> instead of <td>
 285                                     bug fixed don't render a filename as WikiName
 286                                     bug fixed " is allowed in alias name
 287                                     bug fixed ' is allowed in alias name
 288                                     bug fixed linebreak by a space in alias  
 289                                     not quite a bug but makes it very difficult to code in gallery2image so additional id removed in alias name
 290 """
 291 Dependencies = []
 292 from MoinMoin.action import AttachFile
 293 from MoinMoin import wikiutil, config
 294 from MoinMoin.Page import Page
 295 
 296 import os,string,re,Image,StringIO
 297 
 298 from MoinMoin.parser import EXIF
 299 
 300 from MoinMoin.parser import wiki
 301 
 302 def show_tools_restricted(pagename,this_target,thumbnail_width,full,alias,target,exif_date,request):
 303     if request.user.may.delete(pagename):
 304         return tools_restricted_html(pagename,this_target,thumbnail_width,full,alias,target,exif_date,request)
 305     else:
 306         return ''    
 307 
 308 def tools_restricted_html(pagename,this_target,thumbnail_width,full,alias,target,exif_date,request):
 309     text='''
 310                    <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 311                         <td>
 312                             <input type="hidden" name="action" value="gallery2image">
 313                             <input type="hidden" name="do" value="RL">
 314                             <input type="hidden" name="target" value="%(this_target)s">
 315                             <input type="image" value="submit" src="%(server)s/wiki/modern/img/to_left.png" title="rotate to left">
 316                         </td>
 317                     </form>
 318                     <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 319                         <td>
 320                             <input type="hidden" name="action" value="gallery2image">
 321                             <input type="hidden" name="do" value="RR">
 322                             <input type="hidden" name="target" value="%(this_target)s">
 323                             <input type="image"  value="submit" src="%(server)s/wiki/modern/img/to_right.png" title="rotate to right" >
 324                         </td>
 325                     </form>
 326                     <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 327                         <td>
 328                             <input type="hidden" name="action" value="gallery2image">
 329                             <input type="hidden" name="do" value="RM">
 330                             <input type="hidden" name="target" value="%(this_target)s">
 331                             <input type="image" value="submit" src="%(server)s/wiki/modern/img/to_bak.png" title="move to bak" >
 332                         </td>
 333                     </form>''' %  {
 334             "server" : 'http://'+request.server_name+':' + str(request.server_port), 
 335             'baseurl': request.getScriptname(),
 336             "pagename":pagename,
 337             "this_target":this_target}                   
 338     return text                
 339     
 340 def tools_html(pagename,this_image,thumbnail_width,full,alias,target,exif_date,request):
 341     text='''
 342             <TABLE align="center" width="%(thumbnail_width)s">
 343                 <TR>
 344                     <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 345                         <td>
 346                             <input type="hidden" name="action" value="AttachFile">
 347                             <input type="hidden" name="do" value="get">
 348                             <input type="hidden" name="target" value='%(this_target)s'>
 349                             <input type="image" value="submit" src="%(server)s/wiki/modern/img/to_full.png" title="load image">
 350                         </td>
 351                     </form>
 352                     <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 353                         <td>
 354                             <input type="hidden" name="action" value="gallery2image">
 355                             <input type="hidden" name="do" value="VS">
 356                             <input type="hidden" name="full" value='%(full)s'>
 357                             <input type="hidden" name="alias" value='%(alias)s'>
 358                             <input type="hidden" name="target" value='%(target)s`>
 359                             <input type="hidden" name="exif_date" value='%(exif_date)s'>
 360                             <input type="image" value="submit" src="%(server)s/wiki/modern/img/to_slide.png" title="slide_show" >
 361                        </td>
 362                     </form>
 363                     %(show_tools_restricted)s
 364                 </TR>
 365             </TABLE>'''   %  {
 366             "server" : 'http://'+request.server_name+':' + str(request.server_port), 
 367             'baseurl': request.getScriptname(),
 368             "pagename":pagename,
 369             "thumbnail_width":thumbnail_width,
 370             "full":full,
 371             "alias":alias,
 372             "exif_date":exif_date,
 373             "target":target,
 374             "this_target":this_image,
 375             "show_tools_restricted":show_tools_restricted(pagename,this_image,thumbnail_width,full,alias,target,exif_date,request)
 376             } 
 377    
 378     return text
 379 
 380 def show_alias_mode2(show_alias,thumbnail_width,this_alias,text_width):
 381    if show_alias == '1': 
 382        return '''
 383         <td valign="top" width="%(text_width)s">
 384            %(this_alias)s
 385         </td>''' % {
 386         "this_alias":this_alias,
 387         "text_width":text_width}
 388    else:
 389       return ''     
 390         
 391 def show_date_mode2(show_date,this_exif_date):    
 392    if show_date == '1': 
 393        return '''
 394    <td>
 395      <p>%(this_exif_date)s</p>
 396    </td>''' % {
 397    "this_exif_date":this_exif_date }
 398    else:
 399         return '';
 400                
 401 def show_tools_mode2(show_tools,pagename,this_target,thumbnail_width,full,alias,target,exif_date,request):  
 402     if show_tools == '1' :
 403         return "<td align=""center""> %s </td>" % tools_html(pagename,this_target,thumbnail_width,full,alias,target,exif_date,request)
 404     else:
 405         return ''
 406       
 407 
 408 
 409 def mode2_html(pagename,border_thick,width,thumbnail_width,text_width,full,this_image,alias,this_alias,exif_date,this_exif_date,target,this_target,submit,show_tools,show_date,show_alias,request):
 410     text='''
 411     <tr valign="center">
 412         <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 413             <td align="center" valign="center" width="%(thumbnail_width)s">
 414                 <input type="hidden" name="action" value="gallery2image">
 415                 <input type="hidden" name="do" value="VS">
 416                 <input type="hidden" name="full" value='%(full)s'>
 417                 <input type="hidden" name="alias" value='%(alias)s'>
 418                 <input type="hidden" name="exif_date" value='%(exif_date)s'>
 419                 <input type="hidden" name="target" value='%(target)s'>
 420                 <input type="image" value="submit" src="%(server)s%(submit)s">
 421             </td>
 422         </form>
 423             %(alias_html)s 
 424     </tr>
 425     <tr>%(tools_html)s%(date_html)s</tr>'''%       {   
 426      "server" : 'http://'+request.server_name+':' + str(request.server_port), 
 427      "baseurl": request.getScriptname(),
 428      "pagename":pagename,
 429      "thumbnail_width":thumbnail_width,
 430      "full":full,
 431      "alias":alias,
 432      "exif_date":exif_date,
 433      "target":target,
 434      "submit":submit,
 435      "tools_html":show_tools_mode2(show_tools,pagename,this_image,thumbnail_width,full,alias,target,exif_date,request),
 436      "date_html": show_date_mode2(show_date,this_exif_date),
 437      "alias_html": show_alias_mode2(show_alias,thumbnail_width,this_alias,text_width)
 438      }
 439     
 440     return text
 441 
 442 def show_tools_mode1(show_tools,pagename,this_image,thumbnail_width,full,alias,target,exif_date,request):  
 443     if show_tools == '1' :
 444         text="<tr><td align=""center"">%s </td></tr>" % tools_html(pagename,this_image,thumbnail_width,full,alias,target,exif_date,request)
 445     else:
 446         text=''
 447     return text        
 448 
 449 def show_date_mode1(show_date,this_exif_date):    
 450    if show_date == '1': 
 451        return '''
 452     <TR>
 453         <td>%(this_exif_date)s</td>
 454     </TR>''' % {
 455     "this_exif_date":this_exif_date}
 456    else:
 457        return ''
 458 
 459 def show_alias_mode1(show_alias,thumbnail_width,this_alias,text_width):
 460    if show_alias == '1': 
 461        return '''
 462     <TR>
 463         <td align="left" width="%(thumbnail_width)s"> %(this_alias)s</td>
 464     </TR>''' % {
 465     "thumbnail_width": thumbnail_width,
 466     "this_alias":this_alias}
 467    else:
 468        return ''     
 469        
 470 def mode1_html(pagename,border_thick,width,thumbnail_width,text_width,full,this_image,alias,this_alias,exif_date,this_exif_date,target,this_target,submit,
 471                show_tools,show_date,show_alias,request):
 472    text='''
 473 <table width="%(thumbnail_width)s" align="center" valign="center">
 474     <TR align="center" valign="center">
 475         <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
 476             <td align="center" valign="middle" width="%(thumbnail_width)s">
 477                 <input type="hidden" name="action" value="gallery2image">
 478                 <input type="hidden" name="do" value="VS">
 479                 <input type="hidden" name="full" value='%(full)s'>
 480                 <input type="hidden" name="alias" value='%(alias)s'>
 481                 <input type="hidden" name="exif_date" value='%(exif_date)s'>
 482                 <input type="hidden" name="target" value='%(target)s'>
 483                 <input type="image" value="submit" src="%(server)s%(submit)s" >
 484             </td>
 485         </form>
 486     </TR>
 487       %(alias_html)s
 488       %(date_html)s
 489       %(tools_html)s
 490 </table>'''%       {  
 491      "server" : 'http://'+request.server_name+':' + str(request.server_port), 
 492      "baseurl": request.getScriptname() ,
 493      "pagename":pagename,
 494      "full":full,
 495      "alias":alias,
 496      "exif_date":exif_date,
 497      "target":target,
 498      "submit":submit,
 499      "thumbnail_width":thumbnail_width,
 500      "tools_html": show_tools_mode1(show_tools,pagename,this_image,thumbnail_width,full,alias,target,exif_date,request),  
 501      "date_html":show_date_mode1(show_date,this_exif_date),
 502      "alias_html": show_alias_mode1(show_alias,thumbnail_width,this_alias,text_width)
 503      }
 504 
 505    return text
 506 
 507 def get_files(kw,path,files,quotes,request):
 508     web=[]
 509     full=[]
 510     thumb=[]
 511     exif_date=[]
 512     img_type=[]
 513     description=[]
 514     
 515     
 516     ddict={}
 517     n=len(quotes['image'])
 518     if n > 0 :
 519         i = 0
 520         for txt in quotes['image']:
 521             ddict[txt]=quotes['alias'][i]
 522             i += 1    
 523     
 524     for attfile in files:
 525         # only files not thumb or webnails
 526         if attfile.find('thumbnail_') == -1 and attfile.find('webnail_') == -1:
 527             # only images
 528             if wikiutil.isPicture(attfile):
 529                 description.append(ddict.get(attfile, attfile))
 530                 full.append(attfile)
 531                 
 532                 fname, ext = os.path.splitext(attfile)
 533                 if ext in ('.gif', '.png'):
 534                     img_type.append('PNG')
 535                     webnail = 'webnail_%s.png' % fname
 536                     thumbfile = 'thumbnail_%s.png' % fname
 537                 else:
 538                     img_type.append("JPEG")
 539                     webnail = 'webnail_%s.jpg' % fname
 540                     thumbfile = 'thumbnail_%s.jpg' % fname
 541                         
 542                 
 543                     
 544                 infile = os.path.join(path, attfile)
 545                 if os.path.exists(infile):
 546                      web.append(webnail)
 547                      thumb.append(thumbfile)
 548                      
 549                 f = open(infile, 'rb')
 550                 tags = EXIF.process_file(f)
 551                 if tags.has_key('EXIF DateTimeOriginal'):
 552                     date = str(tags['EXIF DateTimeOriginal'])
 553                     date = date.replace(':', '-', 2)
 554                 else:
 555                     date = '--'
 556                 exif_date.append(date)
 557                 f.close() 
 558     
 559     return thumb,web,full,exif_date,img_type,description  
 560     
 561 def to_htmltext(text):        
 562   
 563     if text.find ("'"):   
 564         text = text.split("'")
 565         text = '&#39;'.join(text)
 566        
 567     return text
 568 
 569 def to_wikiname(request,formatter,text):
 570   ##taken from MiniPage
 571     out=StringIO.StringIO()
 572     request.redirect(out)
 573     wikiizer = wiki.Parser(text.strip(),request)
 574     wikiizer.format(formatter)
 575     result=out.getvalue()
 576     request.redirect()
 577     del out
 578     
 579    
 580     
 581     result = result.replace('<a id="line-1"></a>','')
 582     result = result.replace('<p>','')
 583     result = result.replace('</p>','')
 584     result = result.strip() 
 585     return result
 586     
 587         
 588 def get_quotes(self,formatter):
 589     quotes = self.raw.split('\n')
 590     quotes = [quote.strip() for quote in quotes]
 591     quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
 592 
 593     
 594     image=[]
 595     text=[]
 596     
 597     for line in quotes:
 598         im, na=line[1:-1].split(' ',1)
 599         na = na.strip()
 600         na = to_htmltext(na)
 601         na = to_wikiname(self.request,formatter,na)
 602         text.append(na)
 603         image.append(im.strip())
 604 
 605     return {
 606         'alias': text,
 607         'image': image,
 608     }
 609 
 610 
 611 
 612 class Parser:
 613         
 614     def __init__(self, raw, request, **kw):
 615         self.raw = raw
 616         self.request = request
 617         self.form = request.form
 618         self._ = request.getText
 619         self.kw = {
 620             'sort_by_date': '0',
 621             'sort_by_name': '1',
 622             'sort_by_alias': '0',
 623             'album': '0',
 624             'album_name': 'album',
 625             'front_image':'',
 626             'template_itemlist': '0', 
 627             'reverse_sort': '0',
 628             'border_thick': '1',
 629             'columns': '4',
 630             'filter': '.',
 631             'mode': '1',
 632             'help': '0',
 633             'show_text': '1',
 634             'show_date': '1',
 635             'show_tools': '1',
 636             'only_items': '0',
 637             'image_for_webnail': '0',
 638             'renew': '0',
 639             'thumbnail_width': '128',
 640             'webnail_width': '640',
 641             'text_width': '140',
 642         }
 643        
 644 
 645         for arg in kw.get('format_args','').split(','):
 646 
 647             if arg.find('=') > -1:
 648                 key, value=arg.split('=')
 649                 self.kw[key]=wikiutil.escape(value, quote=1)
 650 
 651 
 652         self.kw['width']=str((int(self.kw['thumbnail_width'])+int(self.kw['text_width'])))
 653 
 654 
 655     def format(self, formatter):
 656         kw=self.kw
 657         Dict = {}
 658         quotes=get_quotes(self,formatter)
 659         current_pagename=formatter.page.page_name
 660         attachment_path = AttachFile.getAttachDir(self.request, current_pagename, create=1)
 661  
 662         if kw['help'] == '1':
 663             self.request.write('''
 664 <br>
 665 {{{<br>
 666 #!Gallery2 [columns=columns],[filter=filter],[mode=mode],<br>
 667            [show_text=show_text],[show_date=show_date], [show_tools=show_tools],<br>
 668            [sort_by_name=sort_by_name],[sort_by_date=sort_by_date],[sort_by_alias=sort_by_alias]<br>
 669            [reverse_sort=reverse_sort],<br>
 670            [only_items=only_items],[template_itemlist=template_itemlist],<br>
 671            [album=album],[album_name=album_name],[front_image=front_image],<br>
 672            [thumbnail_width=thumbnail_width],[webnail_width=webnail_width],[text_width=text_width],<br>
 673            [image_for_webnail=image_for_webnail],<br>
 674            [border_thick=border_thick],[renew=renew],[help=help]<br>
 675  * [image1.jpg alias]<br>
 676  * [image2.jpg alias]<br>
 677 }}}<br>''')
 678             return    
 679             
 680         
 681         if kw['only_items'] == '1':
 682             all_files=quotes['image']
 683             result=[]
 684             for attfile in all_files:
 685                 infile=os.path.join(attachment_path,attfile)
 686                 if os.path.exists(infile):
 687                    result.append(attfile) 
 688             all_files = result        
 689             
 690             if kw['sort_by_alias'] == '1':
 691                 new_ordered_files=[]
 692                 alias_text=quotes['alias']
 693                 
 694                 i=0
 695                 for attfile in all_files:
 696                     infile=os.path.join(attachment_path,attfile)
 697                     ft_file=str(os.path.getmtime(infile))+os.tmpnam()
 698                     Dict[alias_text[i]]=attfile
 699                     i += 1
 700        
 701                 keys = Dict.keys()   
 702                 keys.sort()
 703                 for txt in keys:
 704                     new_ordered_files.append(Dict[txt])
 705                    
 706 
 707                 all_files=new_ordered_files
 708                 Dict.clear()
 709            
 710         else:
 711             all_files=os.listdir(attachment_path)
 712 
 713         result = []
 714 
 715         for test in all_files:
 716            if re.match(kw['filter'], test):
 717               result.append(test)
 718         all_files=result
 719         
 720         if not all_files:
 721             self.request.write("<br><br><h1>No matching image file found!</h1>")
 722             return
 723             
 724         
 725 
 726         if kw['sort_by_name'] == '1' and kw['only_items'] == '0': 
 727             all_files.sort()
 728           
 729         if kw['sort_by_date']=='1': 
 730            for attfile in all_files:
 731                infile=os.path.join(attachment_path,attfile)
 732                ft_file=str(os.path.getmtime(infile))+os.tmpnam()
 733                Dict[ft_file]=attfile
 734                
 735            keys = Dict.keys()
 736            keys.sort()
 737            file_mdate=[]
 738            for txt in keys:
 739                file_mdate.append(Dict[txt])
 740            all_files=file_mdate
 741            Dict.clear()
 742          
 743         if kw['reverse_sort']=='1': 
 744              all_files.reverse()   
 745 
 746  
 747         cells=[]
 748         cell_name=[]
 749         img=[]
 750       
 751         thumb, web, full, exif_date, imgtype, description = get_files(kw, attachment_path, all_files, quotes, self.request)
 752         
 753         if kw['template_itemlist'] == '1':
 754             self.request.write('Copy the following listitems into the script. Replace alias with the label you want. Afterwards disable template_itemlist by setting it to 0:<BR>')
 755             for attfile in full : 
 756                 self.request.write(' * [%(attfile)s %(date)s]<br>' % {
 757                                    'attfile' : attfile,
 758                                    'date'    : 'alias'
 759                                     })
 760                                     
 761         
 762         i = 0  
 763         z = 1
 764         cols = int(kw['columns'])
 765         
 766            
 767         n = len(full)
 768         if  kw['album'] == '0' :
 769             self.request.write("<table align='center' border='%s' >" % self.kw['border_thick'])
 770             if kw['mode'] == '1' or cols > 1   :
 771                 self.request.write('<TR valign="bottom">')      
 772                 self.request.write('<TD>') 
 773  
 774                            
 775         if kw['album'] == '1' :
 776             if kw['front_image'] == '' :
 777                 front_image = full[0]  
 778             else:
 779                 front_image =  kw['front_image']   
 780             ii = 0
 781             for tst in full : 
 782                 if tst == front_image :
 783                     break 
 784                 ii += 1   
 785             
 786         
 787         for attfile in full :
 788             if  kw['album'] == '1' :
 789                 if tst == front_image :
 790                    i = ii
 791              
 792                                  
 793             this_description=description[i]
 794             this_exif_date=exif_date[i]
 795             this_webnail=web[i]
 796             this_imgtype=imgtype[i]
 797             this_thumbfile=thumb[i]
 798             
 799            
 800             thumbf=os.path.join(attachment_path,this_thumbfile)
 801             webf=os.path.join(attachment_path,this_webnail)            
 802             
 803             
 804             if kw['renew'] == '1':
 805                 if os.path.exists(thumbf):
 806                    os.unlink(thumbf)
 807                 if os.path.exists(webf):
 808                    os.unlink(webf)
 809                    
 810             if not os.path.exists(webf) or not os.path.exists(thumbf):
 811                 infile=os.path.join(attachment_path,attfile)
 812                 im = Image.open(infile)
 813                 if not os.path.exists(webf):
 814                     im.thumbnail(((int(kw['webnail_width'])),((int(kw['webnail_width'])))), Image.ANTIALIAS)
 815                     if kw['image_for_webnail'] == '1' :
 816                        os.link(os.path.join(attachment_path,attfile),webf)
 817                     else:
 818                        im.save(webf, this_imgtype)
 819                 if not os.path.exists(thumbf):
 820                     im.thumbnail(((int(kw['thumbnail_width'])),((int(kw['thumbnail_width'])))),
 821                                    Image.ANTIALIAS)
 822                     im.save(thumbf, this_imgtype)       
 823                     
 824                     
 825             if kw['image_for_webnail'] == '1' :     
 826                  this_webnailimg = attfile
 827                  webimg = full
 828             else: 
 829                  this_webnailimg = this_webnail
 830                  webimg = web
 831                  
 832            
 833             if kw['mode'] == '1':
 834                 text=mode1_html(current_pagename,
 835                         kw['border_thick'],
 836                         kw['width'],
 837                         kw['thumbnail_width'],
 838                         kw['text_width'],
 839                         attfile + "," + ','.join(full),
 840                         attfile,
 841                         this_description + '!,!' + '!,!'.join(description),
 842                         this_description,
 843                         to_htmltext(this_exif_date + ',' + ','.join(exif_date)),
 844                         to_htmltext(this_exif_date),
 845                         this_webnailimg + ',' + ','.join(webimg),
 846                         this_webnailimg,
 847                         AttachFile.getAttachUrl(current_pagename, this_thumbfile, self.request),
 848                         kw['show_tools'],
 849                         kw['show_date'],
 850                         kw['show_text'],
 851                         self.request
 852                         )
 853                 self.request.write(''.join(text))    
 854                         
 855             if kw['mode'] == '2':
 856                 text=mode2_html(current_pagename,
 857                         kw['border_thick'],
 858                         kw['width'],
 859                         kw['thumbnail_width'],
 860                         kw['text_width'],
 861                         attfile + "," + ','.join(full),
 862                         attfile,
 863                         this_description + '!,!' + '!,!'.join(description),
 864                         this_description,
 865                         to_htmltext(this_exif_date + ',' + ','.join(exif_date)),
 866                         to_htmltext(this_exif_date),
 867                         this_webnailimg + ',' + ','.join(webimg),
 868                         this_webnailimg,
 869                         AttachFile.getAttachUrl(current_pagename, this_thumbfile, self.request),
 870                         kw['show_tools'],
 871                         kw['show_date'],
 872                         kw['show_text'],
 873                         self.request
 874                         )
 875             
 876                 if cols > 1 : self.request.write('<table valign="bottom">')
 877                 self.request.write(''.join(text))
 878                 if cols > 1 : self.request.write('</table>')
 879             
 880             if kw['mode'] == '1' or cols > 1:    
 881                 if kw['album'] == '0' :
 882                     if  z < cols :
 883                         self.request.write('</TD>')
 884                         if z <  n and  i < n - 1 :
 885                             self.request.write('<TD>')
 886                         if i == n - 1 :    
 887                             self.request.write('</TR>')
 888                     else: 
 889                         self.request.write('</TD>')
 890                         self.request.write('</TR>')
 891                         if i < n - 1 :
 892                             self.request.write('<TR valign="bottom">')
 893                             self.request.write('<TD>')
 894                             
 895             i += 1         
 896             z += 1
 897             if z > cols :
 898                 z = 1
 899             
 900             if kw['album'] == '1' :
 901                 self.request.write("%(n)s images (%(album_name)s)" % {"n": str(n), "album_name":kw['album_name']})
 902                 break
 903         if kw['album'] == '0' :        
 904             if i < n :
 905                 self.request.write('</TD>')
 906                 self.request.write('</TR>')
 907             
 908         
 909             self.request.write('</table>')       
 910             
 911         ############################################
 912         ##TODO: syntax change to formatter - later #
 913         ############################################
 914         
 915        
 916         
 917         
 918        

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-08-06 08:57:54, 41.8 KB) [[attachment:EXIF.py]]
  • [get | view] (2005-03-24 20:14:37, 10.6 KB) [[attachment:Gallery2-1.3.3-1.py]]
  • [get | view] (2005-03-26 08:39:13, 11.6 KB) [[attachment:Gallery2-1.3.3-2.py]]
  • [get | view] (2005-03-26 12:41:49, 13.1 KB) [[attachment:Gallery2-1.3.3-3.py]]
  • [get | view] (2005-03-27 20:23:01, 19.0 KB) [[attachment:Gallery2-1.3.3-4.py]]
  • [get | view] (2005-08-03 19:30:10, 23.2 KB) [[attachment:Gallery2-1.3.3-5.py]]
  • [get | view] (2005-08-18 07:58:38, 31.9 KB) [[attachment:Gallery2-1.3.5-10.py]]
  • [get | view] (2005-09-02 19:55:13, 34.1 KB) [[attachment:Gallery2-1.3.5-11.py]]
  • [get | view] (2005-11-13 18:09:11, 35.4 KB) [[attachment:Gallery2-1.3.5-12.py]]
  • [get | view] (2005-11-18 20:13:04, 46.2 KB) [[attachment:Gallery2-1.3.5-13.py]]
  • [get | view] (2005-12-03 15:33:06, 46.6 KB) [[attachment:Gallery2-1.3.5-14.py]]
  • [get | view] (2006-01-01 09:20:19, 43.3 KB) [[attachment:Gallery2-1.3.5-15.py]]
  • [get | view] (2005-08-07 15:46:28, 26.9 KB) [[attachment:Gallery2-1.3.5-6.py]]
  • [get | view] (2005-08-13 15:13:59, 28.7 KB) [[attachment:Gallery2-1.3.5-7.py]]
  • [get | view] (2005-08-14 13:02:00, 27.5 KB) [[attachment:Gallery2-1.3.5-8.py]]
  • [get | view] (2005-08-14 14:38:32, 28.7 KB) [[attachment:Gallery2-1.3.5-9.py]]
  • [get | view] (2006-08-06 08:45:47, 41.8 KB) [[attachment:Gallery2-1.5.4-16.py]]
  • [get | view] (2006-08-22 20:29:39, 42.0 KB) [[attachment:Gallery2-1.5.4-18.py]]
  • [get | view] (2006-08-06 08:57:36, 514.8 KB) [[attachment:example.swf]]
  • [get | view] (2005-08-17 18:10:27, 11.3 KB) [[attachment:gallery2image_test.py]]
  • [get | view] (2005-08-10 16:49:16, 1.3 KB) [[attachment:patchpullfromdir.diff]]
  • [get | view] (2006-08-17 16:32:50, 41.9 KB) [[attachment:text_x_gallery2-1.6.0-17.py]]
  • [get | view] (2006-08-22 20:23:06, 42.1 KB) [[attachment:text_x_gallery2-1.6.0-18.py]]
  • [get | view] (2008-02-06 10:08:05, 42.2 KB) [[attachment:text_x_gallery2-1.6.0-19.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.