Attachment 'Visio.py'

Download

   1 #format python
   2 # -*- coding: iso-8859-1 -*-
   3 """
   4     MoinMoin - Visio Macro
   5 
   6     PURPOSE:
   7         This macro is used to enable an attached Visio file to be displayed
   8         in a browser. Optionally, the size of the image can be adjusted.
   9 
  10     CALLING SEQUENCE:
  11         [[visio(attachment,[width=width],[height=height])]]
  12 
  13     INPUTS:
  14         attachment:file name of attachment
  15 
  16     KEYWORD PARAMETERS:
  17         width: width of the embedded image (default is 100%)
  18 	      height: height of the embedded image (default is 100%)
  19 
  20     EXAMPLE:
  21       [[visio(organogram.vsd]]
  22       [[visio(organogram.vsd,width=800,height=600)]]
  23       [[visio(organogram.vsd,width=50%)]]
  24 
  25       This macro must be put in "[yourwiki]/data/plugin/macro/"
  26 
  27     CREDITS:
  28       This macro was built using the SVG macro as a template,
  29       which was built using the ImageLink macro as a template.
  30       Please feel free to post improved versions of it.
  31 
  32     MODIFICATION HISTORY:
  33         @license: GNU GPL, see COPYING for details.
  34 
  35 
  36 """
  37 
  38 from MoinMoin.action  import AttachFile
  39 from MoinMoin         import wikiutil, config
  40 import os,string
  41 
  42 
  43 def execute(macro, text):
  44 
  45   kw = {'width': '95%', 'height': '100%'}
  46 
  47   if text:
  48     args = text.split(',')
  49   else:
  50     args = []
  51 
  52   argCount = len(args)
  53   kwCount = 0
  54   for a in args:
  55     if (a.find('=') > -1):
  56       kwCount = kwCount + 1
  57       key = a.split('=')
  58       kw[str(key[0])] = wikiutil.escape(string.join(key[1],''), quote=1)
  59 
  60   argCount = argCount - kwCount
  61 
  62   if (argCount < 1):
  63     msg = 'Not enough arguments to visio macro! Try [[visio(attachment[,width=n][,height=n])]]'
  64     return macro.formatter.sysmsg(1) + macro.formatter.text(msg) + macro.formatter.sysmsg(0)
  65 
  66   attachmentName = wikiutil.taintfilename(macro.formatter.text(args[0]))
  67   currentPageName = macro.formatter.page.page_name
  68 
  69   kw['src'] = AttachFile.getAttachUrl(currentPageName,attachmentName,macro.request)
  70   attachmentPath = os.path.join(AttachFile.getAttachDir(macro.request,currentPageName), attachmentName)
  71 
  72   if not os.path.exists(attachmentPath):
  73     import urllib
  74     linktext = macro.request.getText('Upload new attachment "%(filename)s"')
  75     return wikiutil.link_tag(macro.request,
  76                              '%s?action=AttachFile&amp;rename=%s' %
  77                              #(wikiutil.quoteWikinameFS(currentPageName),
  78                               (wikiutil.quoteWikinameURL(currentPageName),
  79                               urllib.quote_plus(attachmentName)),
  80                              linktext % {'filename': attachmentName})
  81 
  82   if (argCount == 1):
  83     src = kw['src'].split(u'/')[-1]
  84     
  85     objectTag = '<object classid="CLSID:279D6C9A-652E-4833-BEFC-312CA8887857" codebase="http://download.microsoft.com/download/visiostandard2003/vviewer/2003/w2kxp/en-us/vviewer.exe" id="viewer1" width="%s" height="%s"> <param name="CurrentPageIndex" value="0"> <param name="Zoom" value="-1"> <param name = "SRC" value = "%s"/>Your browser cannot display Visio</object>' \
  86                 % ( kw['width'], kw['height'], wikiutil.escape(src))
  87     return macro.formatter.rawHTML(objectTag)

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] (2005-12-08 11:50:57, 3.1 KB) [[attachment:Visio.py]]
 All files | Selected Files: delete move to page copy to page

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