Attachment 'EO-1.5.0-1.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - EO Macro
   4 
   5     PURPOSE:
   6         This macro is used to Embed an Object into a wiki page. Optional size of the object
   7         could be adjusted. Further keywords are dependent on the kind of application
   8 
   9     CALLING SEQUENCE:
  10         [[EO(attachment[,width=width][,height=heigt])]]
  11 
  12     INPUTS:
  13         attachment:image name of attachment
  14 
  15     KEYWORD PARAMETERS:
  16         width: width of the embedded image, default is 100% of window
  17         height: height of the embedded image, default is 100% of window
  18              
  19         application/x-shockwave-flash:
  20           play: true is default
  21           loop: true is default
  22           quality: high is default (medium,low)
  23 
  24     EXAMPLE:
  25         [[EO]]
  26         [[EO(example.swf)]]
  27         [[EO(example.swf,width=637,height=392)]]
  28         [[EO(SlideShow/example.swf,width=637,height=392)]]
  29         [[EO(SlideShow/example.swf,width=637,height=392,play=false)]]
  30         [[EO(SlideShow/example.swf,width=637,height=392,play=false,loop=false)]]
  31         [[EO(SlideShow/example.swf,width=637,height=392,play=false,loop=low)]]
  32     
  33     PROCEDURE:
  34         This routine requires attachment enabled. If the attachment isn't downloaded at all
  35         the attachment line is shown.
  36         If you give only one size argument e.g. width only the other one is calculated
  37         
  38         By the swftools it is possible to get the swf size returned. I don't know if it is 
  39         possible to get sizes for svg, pdf and others detected too, that's the reason why 
  40         I haven't added it by now.
  41         
  42         Please add needed mimetypes as objects.
  43 
  44         It must be in "MoinMoin/macro"
  45 
  46         Please remove the version number from the file name!
  47 
  48     MODIFICATION HISTORY:
  49         @copyright: 2006 by Reimar Bauer (R.Bauer@fz-juelich.de)      
  50         initial version: 1.5.0-1
  51         
  52 """    
  53 
  54 
  55 import os, string, mimetypes
  56 from MoinMoin import wikiutil
  57 from MoinMoin.action import AttachFile
  58 
  59 def execute(macro, text):
  60     kw = {} 
  61     if text:
  62         args=text.split(',')
  63     else:
  64         args=[]
  65       
  66     number_args = len(args)
  67     count = 0
  68     kw["width"] = "100%"
  69     kw["height"] = "100%"
  70     kw["play"] = "true"
  71     kw["loop"] = "true"
  72     kw["quality"] = "high"
  73 
  74     for a in args:
  75         if (a.find('=') > -1):
  76            count += 1
  77            key = a.split('=')
  78            kw[str(key[0])] = wikiutil.escape(string.join(key[1],''), quote=1)
  79 
  80     number_args = number_args - count
  81  
  82     if number_args < 1:
  83        msg='Not enough arguments to EO macro! Try [[EO(attachment [,width=width] [,height=heigt])]]'
  84        return macro.formatter.sysmsg(1) + macro.formatter.text(msg) + macro.formatter.sysmsg(0)
  85     else:    
  86        filename = args[0]
  87        
  88     if filename.find('/') > -1 and filename.find(':') == -1:
  89         pagename,filename = string.split(filename,'/')
  90     else:
  91         pagename = macro.formatter.page.page_name     
  92     
  93     
  94     attachment_file = os.path.join(AttachFile.getAttachDir(macro.request,pagename), filename)
  95     
  96     if not os.path.exists(attachment_file):
  97             import urllib
  98             linktext = macro.request.getText('Upload new attachment "%(filename)s"'%{
  99             "filename":filename})
 100             return wikiutil.link_tag(macro.request,
 101                              "%(pagename)s?action=AttachFile&amp;rename=%(newname)s" % {
 102                              "pagename":pagename,
 103                              "newname": filename},linktext)
 104 
 105     url = AttachFile.getAttachUrl(pagename,filename,macro.request)
 106     
 107     mime_type, enc = mimetypes.guess_type(filename)
 108     
 109     if mime_type == "application/x-shockwave-flash" :
 110     
 111         txt = '''
 112 <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
 113 WIDTH="%(width)s"
 114 HEIGHT="%(height)s"
 115 CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=6,0,23,0">
 116 <PARAM NAME="MOVIE" VALUE="%(file)s">
 117 <PARAM NAME="PLAY" VALUE="%(play)s">
 118 <PARAM NAME="LOOP" VALUE="%(loop)s">
 119 <PARAM NAME="QUALITY" VALUE="%(quality)s">
 120 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
 121 PLAY="%(play)s" ALIGN="" LOOP="%(loop)s" QUALITY="%(quality)s"
 122 TYPE="application/x-shockwave-flash"
 123 PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
 124 </EMBED>
 125 </OBJECT>''' % {
 126 "width": kw["width"],
 127 "height": kw["height"],
 128 "play":kw["play"],
 129 "loop": kw["loop"],
 130 "quality": kw["quality"],
 131 "file": url}
 132         
 133         return txt
 134         
 135     elif mime_type == "image/svg+xml": 
 136         txt = '''
 137 <OBJECT CLASSID="" 
 138 WIDTH="%(width)s"
 139 HEIGHT="%(height)s"
 140 CODEBASE="http://purl.org/dc/dcmitype/StillImage">
 141 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
 142 TYPE="image/svg+xml">
 143 </EMBED>
 144 </OBJECT>''' % {
 145 "width": kw["width"],
 146 "height": kw["height"],
 147 "file": url}
 148         
 149         return txt
 150 
 151     elif mime_type == "application/pdf":
 152        txt = '''
 153 <OBJECT CLASSID="" 
 154 WIDTH="%(width)s"
 155 HEIGHT="%(height)s"
 156 CODEBASE="http://www.adobe.com">
 157 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
 158 TYPE="application/pdf">
 159 </EMBED>
 160 </OBJECT>''' % {
 161 "width": kw["width"],
 162 "height": kw["height"],
 163 "file": url}
 164 
 165        return txt
 166 
 167     else: 
 168        msg = 'Not supported mimetype %(mimetype)s ' % {"mimetype":mime_type}
 169        return macro.formatter.sysmsg(1) + macro.formatter.text(msg) + macro.formatter.sysmsg(0)

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-01-01 08:08:12, 5.2 KB) [[attachment:EO-1.5.0-1.py]]
  • [get | view] (2006-05-09 18:06:19, 5.5 KB) [[attachment:EO-1.5.3-2.py]]
  • [get | view] (2006-06-29 20:40:09, 6.4 KB) [[attachment:EmbedObject-1.5.3-3.py]]
  • [get | view] (2006-01-12 01:08:52, 80.1 KB) [[attachment:Map.swf]]
  • [get | view] (2006-05-09 20:26:24, 21.8 KB) [[attachment:example.pdf]]
  • [get | view] (2007-07-19 06:46:08, 89.3 KB) [[attachment:mini1.swf]]
 All files | Selected Files: delete move to page copy to page

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