Attachment 'Frame-1.5.4-5.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Frame Parser
   4 
   5     This parser is used to align enclosed wiki markup.
   6         
   7     Syntax:
   8         {{{#!frame align=align,thick=thick,style=style,color=color,
   9         background=background,background_image=background_image,
  10         position=position,width=width,padding=padding,
  11         margin=margin,text_align=text_align,text_font_size=text_font_size,
  12         text_color=text_color, div_type=div_type,div_name=div_name
  13         wiki markup
  14         }}}
  15     
  16     Parameters:
  17         align:      one of ['left', 'right', 'center', 'justify', 'float:left','float:right', 'clear:both', 'clear:left', 'clear:right']
  18                     default: left
  19                     
  20         thick:      one of ['thin', 'medium','thick'] or any value with a unit of px
  21                     default: thin
  22                     
  23         style:      one of ['none','hidden', 'dotted', 'dashed', 'solid', 'double',
  24                             'groove', 'ridge', 'inset',  'outset']
  25                     default: solid
  26                     
  27         color:      each color which could be verified by web.Color(str(name))
  28                     default: black
  29                        
  30         background: each color which could be verified by web.Color(str(name))
  31                     default: transparent
  32                     
  33         background_image: the name of an attachment 
  34                           default: ''
  35                           
  36         background_repeat: one of ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
  37                            default: no-repeat               
  38                                          
  39         position:   one of ['static','absolute','relative','fixed','inherit']
  40                     default: relative
  41                           
  42         width:      a value with the unit % 
  43                     default: 'auto'
  44                           
  45         padding:    has to be a value with the unit 'pt', 'pc','in', 'mm', 'cm', 'px', 'em', 'ex'
  46                     default: 0
  47                           
  48         margin:     has to be a value with the unit 'pt', 'pc','in', 'mm', 'cm', 'px', 'em', 'ex'
  49                     default: 0                 
  50         
  51         text_align: one of ['left', 'right', 'center', 'justify']                              
  52                     default: left
  53                     
  54         text_font_size: one of ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large',
  55                                 'smaller', 'larger'] or each value of a unit of 'pt', 'pc','in', 'mm', 'cm', 'px', 'em', 'ex', '%'
  56                         default: ''        
  57         text_color: each which could be verified by web.Color(str(name))
  58                     default: black
  59                     
  60         div_type: one of ['id', 'class']                    
  61                   default: '' needs to be used together with div_name
  62                   
  63         div_name: one of  ['header', 'locationline', 'pageline', 'footer', 'sidepanel', 'pagebottom']
  64                   default: '' needs to be used together with div_type    
  65                   
  66                           
  67         wiki markup: could any wiki markup 
  68 
  69     Procedure:
  70         Please remove the version number.
  71         
  72         The units are limited for numbers. And only one value for padding or margin 
  73         
  74         
  75 
  76     Examples:
  77         {{{
  78         #!frame align=float:right
  79         attachment:moinmoin.png
  80         ||A||B||
  81         ||C||D||
  82         ||C||D||
  83         }}}
  84     
  85         {{{ 
  86 #!frame align=float:left,position=relative,width=48%,margin=0em,thick=2px,color=blue,background=yellow
  87 A WikiName is a word that uses capitalized words. WikiNames automagically become hyperlinks to the WikiName's page. What exactly is an uppercase or lowercase letter is determined by the configuration, the default configuration should work for UTF-8 characters (digits are treated like lowercase characters). 
  88 
  89 
  90 When you click on the highlighted page title (i.e. WikiName on this page), you will see a list of all pages that link to the current page. This even works on pages that are not defined yet.
  91 }}}{{{
  92 #!frame align=float:right,position=relative,width=50%,margin=0em,thick=2px,color=blue
  93 When you click on the highlighted page title (i.e. WikiName on this page), you will see a list of all pages that link to the current page. This even works on pages that are not defined yet. 
  94 
  95 
  96 A question mark before a link or a different rendering in grey means that the page is not yet defined: you can click the question mark or page name to offer a definition (e.g., ?NoSuchPageForReal). If you click on such a link, you will see a default page that you can edit; only after you save the page will it be created for real. A list of all pages that are not yet created but referred on another page is on WantedPages. 
  97 
  98 
  99 To escape a WikiName, i.e. if you want to write the word WikiName without linking it, use an "empty" bold sequence (a sequence of six single quotes) like this: Wiki''''''Name. Alternatively, you can use the shorter sequence "``" (two backticks), i.e. Wiki``Name.
 100 }}}
 101 {{{ 
 102 #!frame align=clear
 103 }}}
 104         
 105 = Album =
 106 {{{
 107 #!Frame align=float:right,background=gray,width=20%
 108 #!Gallery2 album=1,front_image=100_1194.JPG,album_name=Bremen,front_image=100_1189.JPG,show_tools=0,show_text=0,show_date=0
 109 }}}
 110 Some images from the trip to Bremen in 2004
 111 
 112  * SpaceCenter 
 113  * ScienceCenter
 114 {{{
 115 #!Frame align=clear
 116 }}}
 117         
 118     Modification History:
 119         @copyright: 2006 by Reimar Bauer
 120         @license: GNU GPL, see COPYING for details.
 121         
 122        1.6.0-2 2006-08-14 removed frame_ from paramter names
 123                           column:left and column:right removed becuse they are only floating elements
 124                           background_image, background_repeat, text_color, text_font_size added
 125        1.6.0-3 2006-08-15 bug fixes: position of float element wrong used and thick command failed for float
 126        1.6.0-4 2006-08-22 extended to use it for parsers too 
 127        1.6.0-5 2006-09-03 extended to use more as em as unit for text_font_size, thick, margin and padding 
 128                           margin and padding extended to have up to 4 values
 129                           clear changed to clear:both, clear:left, clear:right
 130                           align=clear is an alias for clear:both
 131                           error exception for wrong written color name added
 132                           request of ZhangYunfeng to use existing CSS code added (you have to add your own css names)
 133        backport to 1.5.4-5                    
 134 """
 135 import StringIO, os, mimetypes
 136 from random import randint
 137 from MoinMoin.parser import wiki
 138 from MoinMoin import wikiutil
 139 from MoinMoin.action import AttachFile
 140 from MoinMoin.webapi.color import Color
 141 
 142 Dependencies = []
 143 
 144 class Parser:
 145 
 146     extensions = ['*']
 147     Dependencies = Dependencies
 148 
 149     def __init__(self, raw, request, **kw):
 150         self.raw = raw
 151         self.request = request
 152 
 153         self.align = 'left'
 154 
 155         self.text_align = 'left'
 156         self.text_font_size = ''
 157         self.text_color = 'black'
 158         self.thick = 'thin'
 159         self.style = 'solid'
 160         self.color = 'black'
 161         self.background = 'transparent'
 162         self.background_image = None
 163         self.background_repeat = 'no-repeat'
 164         self.position = 'relative'
 165         self.width = 'auto'
 166         self.padding = '0em'
 167         self.margin = '0em'
 168         self.div_type = ''
 169         self.div_name = ''
 170 
 171         for arg in kw.get('format_args', '').split(','):
 172             if arg.find('=') > -1:
 173                 key, value = arg.split('=')
 174                 setattr(self, key, wikiutil.escape(value.strip(), quote=1))
 175 
 176 
 177     def value_check(self, text, units, maxlen, default):
 178         unit_length = 2
 179         value = text.strip().split(' ')
 180         rlen = min([maxlen, len(value)])
 181         value = value[0:rlen]
 182         result = ''
 183         for single_value in value:
 184              if single_value.endswith('%'):
 185                  unit_length = 1
 186              used_unit = single_value[-unit_length:]
 187              if used_unit in units:
 188                  if single_value.endswith(used_unit):
 189                      result += str(float(single_value[:-unit_length]))+ used_unit + ' '
 190                  else:
 191                      result += '%(default)s ' % {"default": str(default)}
 192              else:
 193                  result += '%(default)s ' % {"default": str(default)}
 194 
 195         return(result)
 196 
 197 
 198     def format(self, formatter):
 199         raw = self.raw
 200         raw = raw.split('\n')
 201         parser_name = ''
 202         for line in raw:
 203             if line.strip().startswith("#!"):
 204                 parser_name = line.strip()[2:].split()[0]
 205 
 206                 for arg in line.split(','):
 207                     if arg.find('=') > -1:
 208                         key, value = arg.split('=')
 209                         setattr(self, key, wikiutil.escape(value.strip(), quote=1))
 210 
 211         pagename = formatter.page.page_name
 212 
 213         out = StringIO.StringIO()
 214         self.request.redirect(out)
 215         if parser_name != '':
 216             self.request.write(formatter.parser(parser_name, raw))
 217         else:
 218             wikiizer = wiki.Parser(self.raw, self.request)
 219             wikiizer.format(formatter)
 220         result = out.getvalue()
 221         self.request.redirect()
 222         del out
 223 
 224 
 225         if self.div_type in ['id,', 'class'] and self.div_name in ['header',
 226                                                                    'logo',
 227                                                                    'pagetrail',
 228                                                                    'navibar',
 229                                                                    'editbar',
 230                                                                    'pagelocation',
 231                                                                    'locationline',
 232                                                                    'pageline',
 233                                                                    'footer',
 234                                                                    'sidepanel',
 235                                                                    'pagebottom']: # needs to be changed to your css code
 236             div = '<div %(type)s="%(val)s">' % {
 237                   "val": self.div_name,
 238                   "type": self.div_type}
 239             self.request.write("%(div)s%(result)s</div>" % {
 240                   "div": div,
 241                   "result": result})
 242             return
 243 
 244         if self.position in ['static', 'absolute', 'relative', 'fixed', 'inherit']:
 245             position = self.position
 246         else:
 247             position = 'relative'
 248 
 249         if self.thick in ['thin', 'medium', 'thick']:
 250             thick = self.thick
 251         else:
 252             units = ['px']
 253             thick = self.value_check(self.thick, units, 1, 0)
 254 
 255         if self.text_align in ['left', 'right', 'center', 'justify']:
 256             text_align = self.text_align
 257         else:
 258            text_align = 'left'
 259 
 260         if self.style in ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
 261                           'groove', 'ridge', 'inset', 'outset']:
 262             style = self.style
 263         else:
 264             style = 'solid'
 265 
 266         if self.color != 'transparent':
 267             try:
 268                 color = Color(str(self.color))
 269             except StandardError:
 270                 color = 'black'
 271         else:
 272             color = 'black'
 273 
 274         if self.background != 'transparent':
 275             try:
 276                 background = Color(str(self.background))
 277             except StandardError:
 278                 background = 'transparent'
 279         else:
 280             background = 'transparent'
 281 
 282         if self.width:
 283             units = ['%']
 284             width = self.value_check(self.width, units, 1, 0)
 285           
 286         if self.padding:
 287             units = ['pt', 'pc', 'in', 'mm', 'cm', 'px', 'em', 'ex']
 288             padding = self.value_check(self.padding, units, 4, 0)
 289 
 290         if self.margin:
 291             units = ['pt', 'pc', 'in', 'mm', 'cm', 'px', 'em', 'ex']
 292             margin = self.value_check(self.margin, units, 4, 0)
 293 
 294         if self.text_font_size in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large',
 295                                    'smaller', 'larger']:
 296             text_font_size = self.text_font_size
 297         else:
 298             units = ['pt', 'pc', 'in', 'mm', 'cm', 'px', 'em', 'ex', '%']
 299             text_font_size = self.value_check(self.text_font_size, units, 1, '')
 300 
 301         if self.text_color != 'transparent':
 302             try:
 303                 text_color = Color(str(self.text_color))
 304             except StandardError:
 305                 text_color = 'black'
 306         else:
 307             text_color = 'black'
 308 
 309         url = ''
 310         if self.background_image != None:
 311             attachment_path = AttachFile.getAttachDir(self.request, pagename)
 312             file = os.path.join(attachment_path, self.background_image)
 313             if os.path.exists(file):
 314                 mime_type, enc = mimetypes.guess_type(file)
 315                 if mime_type.startswith('image'):
 316                     url = AttachFile.getAttachUrl(pagename, self.background_image, self.request)
 317 
 318         if self.background_repeat in ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']:
 319             background_repeat = self.background_repeat
 320         else:
 321             background_repeat = 'no-repeat'
 322 
 323         if self.align in ['left', 'right', 'center', 'justify']:
 324             div = '<div align="%(align)s" style="border-width:%(thick)s; border-color:%(color)s; border-style:%(style)s; position:%(position)s; padding:%(padding)s; margin:%(margin)s; background-color:%(background)s; font-size:%(text_font_size)s; color:%(text_color)s; background-image:url(%(background_image)s); background-repeat:%(background_repeat)s;" width="%(width)s">' % {
 325                     "thick": thick,
 326                     "style": style,
 327                     "color": color,
 328                     "position": position,
 329                     "padding": padding,
 330                     "margin": margin,
 331                     "background": background,
 332                     "width": width,
 333                     "text_align": text_align,
 334                     "text_font_size": text_font_size,
 335                     "text_color": text_color,
 336                     "background_image": url,
 337                     "background_repeat": background_repeat,
 338                     "align": self.align,
 339                     }
 340             self.request.write("%(div)s%(result)s</div>" % {
 341                  "div": div,
 342                  "result": result})
 343 
 344         if self.align in ['float:left', 'float:right']:
 345             tab = '<table style="%(align)s; font-size:%(text_font_size)s; color:%(text_color)s; text-align:%(text_align)s; background-image:url(%(background_image)s); background-repeat:%(background_repeat)s; position:%(position)s; padding:%(padding)s; margin:%(margin)s;" width="%(width)s" border="%(thick)s" bgcolor="%(background)s"><tbody><tr><td style="border-style:none;">' % {
 346                     "align": self.align,
 347                     "text_font_size": text_font_size,
 348                     "text_align": text_align,
 349                     "text_color": text_color,
 350                     "position": position,
 351                     "padding": padding,  
 352                     "margin": margin,
 353                     "width": width,
 354                     "thick": thick,
 355                     "background": background,
 356                     "background_image": url,
 357                     "background_repeat": background_repeat,
 358                 }
 359             self.request.write("%(tab)s%(result)s</td></tr></tbody></table>" % {
 360                                "tab": tab,
 361                                "result": result})
 362 
 363         if self.align in ['clear:both', 'clear:left', 'clear:right']:
 364             self.request.write('<br style=%(align)s;>' % {"align": self.align})
 365 
 366 
 367         if self.align == 'clear':
 368             self.request.write('<br style="clear:both;">')

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-15 19:58:26, 11.9 KB) [[attachment:Frame-1.5.4-3.py]]
  • [get | view] (2006-08-22 20:38:27, 12.8 KB) [[attachment:Frame-1.5.4-4.py]]
  • [get | view] (2006-09-04 06:51:24, 15.7 KB) [[attachment:Frame-1.5.4-5.py]]
  • [get | view] (2006-08-13 21:29:52, 9.7 KB) [[attachment:text_x_frame-1.6.0-1.py]]
  • [get | view] (2006-08-14 18:38:28, 11.7 KB) [[attachment:text_x_frame-1.6.0-2.py]]
  • [get | view] (2006-08-15 20:45:50, 11.4 KB) [[attachment:text_x_frame-1.6.0-3.py]]
  • [get | view] (2006-08-22 20:23:17, 12.4 KB) [[attachment:text_x_frame-1.6.0-4.py]]
  • [get | view] (2006-09-03 14:18:49, 15.7 KB) [[attachment:text_x_frame-1.6.0-5.py]]
 All files | Selected Files: delete move to page copy to page

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