10.10 Installing Python scripts in the ``Run script" menu

Python scripts can be installed as menu entries in the ``Run script" submenu. For this to work the Python script needs to implement a class with the same name as the script. This class needs to provide at least the methods register and run. The register method is passed a language setting as abbreviation of a locale (currently en_US, fr, de, hu, pl, ru, or es). The method needs to call the registerMenuItem function implemented in the viewmol module to pass a string back which will appear as the identification of this script in the submenu.

The run method does not take any argument, but is the entry point for the script when the user selects the corresponding menu item in the ``Run script" submenu.

A minimal Python script which will install itself in the ``Run script" menu would be the following (available at $VIEWMOLPATH/scripts/template.py):

import viewmol

class template:
  def run(self):
    print "This is a script template which just prints this silly message."

  def register(self, language):
    viewmol.registerMenuItem("Script template")

# The following three lines are not necessary for running this script
# from the "Run script" menu, but allow the script to also be run
# standalone
if __name__ == '__main__':

All scripts which are to appear in the ``Run script" menu have to be installed in the scripts subdirectory under VIEWMOLPATH.

Jörg-Rüdiger Hill Fri Oct 31 14:19:21 CET 2003