<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!--**************************************************************************** * * * Viewmol * * * * N O D E 2 8 . H T M L * * * * Copyright (c) Joerg-R. Hill, October 2003 * * * ******************************************************************************** *--> <html> <head> <title>10.10 Installing Python scripts in the ``Run script" menu</title> <META NAME="description" CONTENT="10.10 Installing Python scripts in the ``Run script" menu"> <META NAME="keywords" CONTENT="viewmol"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="STYLESHEET" href="viewmol.css"> <link rel="first" href="viewmol.html"> </head> <body> <H2><A NAME="SECTION00010100000000000000000"> 10.10 Installing Python scripts in the ``Run script" menu</A> </H2> 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 <code>register</code> and <code>run</code>. The <code>register</code> method is passed a language setting as abbreviation of a locale (currently <code>en_US</code>, <code>fr</code>, <code>de</code>, <code>hu</code>, <code>pl</code>, <code>ru</code>, or <code>es</code>). The method needs to call the <code>registerMenuItem</code> function implemented in the <code>viewmol</code> module to pass a string back which will appear as the identification of this script in the submenu. <P> The <code>run</code> 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. <P> A minimal Python script which will install itself in the ``Run script" menu would be the following (available at <code>$VIEWMOLPATH/scripts/template.py</code>): <dl><dd><pre class="verbatim"> 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__': script=template() script.run() </pre></dl> <P> All scripts which are to appear in the ``Run script" menu have to be installed in the <code>scripts</code> subdirectory under <code>VIEWMOLPATH</code>. <P> <p><hr> <ADDRESS> <a href="mailto:joehill@users.sourceforge.net"><i>Jörg-Rüdiger Hill</i></a> Fri Oct 31 14:19:21 CET 2003 </ADDRESS> </BODY> </HTML>