MoinMoin Macros

From Jmol
Jump to navigation Jump to search

Miguel 2005 08 04

I wanted to build some mechanism to make it easy to put Jmol applets + controls into a Wiki. I did not realize that Oliver had already done some work on the Jmol Processor. So, this mechanism was developed independently. These two mechanism may well get integrated/combined over time ...

Jmol.js JavaScript -> MoinMoin Macros

The idea was to mimic the functionality of the File icon.gifJmol.js JavaScript library, but make it easily accessible through the Macro mechanism that is available in MoinMoin.

Below is some sample code that shows the syntax for creating a page with a bunch of controls.

== Jmol Applet test wiki page ==

[[jmolApplet(200, 'load /molecules/caffeine.xyz')]]


[[jmolCheckbox("set axes on","set axes off","display coordinate axes")]]

Click [[jmolLink("rotate x 10","here")]] to rotate by 10 degrees about the x axis

[[jmolMenu(["background black","background white","background skyblue","background yellow","background salmon","background palegreen"])]]

[[jmolButton("reset","restore original orientation")]]

[[jmolRadioGroup([ ["color atoms cpk","cpk colors","selected"],["color atoms green","green"],["color atoms yellow","yellow"] ])]]


Basically, a page author uses exactly the same syntax that they would use if they were writing in JavaScript. However, they can do this within the context of a Wiki page, where it is easy to get a fast debugging/turnaround cycle.

This is not a how-to

Warning! This is not a how-to document. It is just a place for me to remember what I did so that I can talk to other people about it.

MoinMoin setup

In order to make this work we need to do a few things:

  1. get a clean MoinMoin installed on your web server
  2. get the Jmol applet + File icon.gifJmol.js stuff installed on your web server
  3. get some molecules stored on (or accessible through) your web server
  4. The File icon.gifJmol.js library must be included on each page
  5. The jmolInitialize() function must be called exactly once for each page
  6. Get the macros in the right place for your wiki

From this point on, any page on the web site will be able to create Jmol applets and controls.

For the first 3 points above you are on your own.

You can address points 4 & 5 by putting the following code into your File icon.gifwikiconfig.py

   ################################################################
   # miguel changes 2005 07 26
   ################################################################
   html_head = '<script src="../jmolapplet/Jmol.js"></script>\n'
   page_header1 = '<script>jmolInitialize("../jmolapplet")</script><form>'
   page_footer2 = '</form>'


Here are the macros that I defined ... they go into <wikiroot>/data/plugin/macro

[mth@arcoiris macro]$ pwd
/var/www/html/wiki/jmolwiki/data/plugin/macro
[mth@arcoiris macro]$ ls jmol*.py
jmolApplet.py  jmolCheckbox.py    jmolLink.py  jmolRadioGroup.py
jmolButton.py  jmolInitialize.py  jmolMenu.py  jmolRadio.py
[mth@arcoiris macro]$ for foo in jmol*.py ; do echo $foo; echo '---'; cat $foo ; echo '---'; done
jmolApplet.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolApplet(' + args + ');</script>';

---
jmolButton.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolButton(' + args + ');</script>';

---
jmolCheckbox.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolCheckbox(' + args + ');</script>'

---
jmolInitialize.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolInitialize("/jmolapplet");</script>'

---
jmolLink.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolLink(' + args + ');</script>';

---
jmolMenu.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolMenu(' + args + ');</script>';

---
jmolRadioGroup.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolRadioGroup(' + args + ');</script>';

---
jmolRadio.py
---
Dependencies = []

def execute(macro, args):
    return '<script>jmolRadio(' + args + ');</script>';

---
[mth@arcoiris macro]$


Random thoughts/comments

  • I don't know whether it is better to put the <form></form> tags around each of the controls individually, or to wrap it around the whole page. I think that the whole page is fine.
  • I think it would be better if there were some way to only include the File icon.gifJmol.js file on the pages that actually used the Jmol macros. But I asked the MoinMoin developers and they said that there was currently no mechanism to support this.
  • I don't know if there is a mechanism for people to upload data files into a MoinMoin wiki. If so, then it would be really good to provide a mechanism for people to upload molecules and then build pages around them.
  • I think that Jmol + wikis could be very useful as a 'lab' in educational environments because one could easily provide students with an infrastructure + some sample pages.

Attachment Mechanism

I figured out how to handle attachments with MoinMoin ... it is not particularly pretty, but it works.

  1. ensure that your wiki allows attached files in File icon.gifwikiconfig.py: allowed_actions = ['DeletePage', 'AttachFile', 'RenamePage']
  2. upload your file
  3. put a link to your file in your page using attachment:<filename>
  4. preview the page and copy the URL of the underlying link
  5. paste this into your jmolApplet() macro

Example

attachment:ddt.xyz

[[jmolApplet(200, 'load FrontPage?action=AttachFile&do=get&target=ddt.xyz')]]

It seems to me that this could be cleaned up if the cgi were tweaked to allow the 'attachments' subdirectory to be visible via the web server. Today, if you try to access the page FrontPage/attachments/ddt.xyz then it will go ahead and create a page with exactly that name ... including the / chars.

Perhaps one could get around this by using the macro rewriting rules in apache to mangle the URL:

<moinmoinroot>/.../attachments/AttachmentName -> ./?action=AttachFile&do=get&target=ddt.xyz

Contributors

NicolasVervelle