Menu with pyFormex scripts.
A menu of pyFormex scripts in a directory or list.
This class creates a menu of pyFormex scripts collected from a directory or specified in a list. It is e.g. used in the pyFormex GUI to create the examples menu, and for the scripts history. The pyFormex scripts can then be executed from the menu. The user may use this class to add his own scripts into the pyFormex GUI.
Only files that are recognized by utils.isPyFormex() as being pyFormex scripts will be added to the menu.
The constructor takes the following arguments:
The defaults were thus chosen to be convenient for the two most frequent uses of this class:
ScriptMenu('My Scripts',dir="/path/to/my/sciptsdir")
creates a menu will all pyFormex scripts in the specified path and its subdirectories.
ScriptMenu('History',files=["/my/script1.py","/some/other/script.pye"],recursive=False)
is typically used to create a history menu of previously visited files
With the resulting file list, a menu is created. Selecting a menu item will make the corresponding file the current script and unless the autoplay configuration variable was set to False, the script is executed.
If the file specification was done by a directory path only, some extra options will be included in the menu. They are fairly self-explaining and mainly intended for the pyFormex developers, in order to test the functionality by running a sets of example scripts:
Furthermore, if the menu is a toplevel one, it will have the following extra options:
The first option uses the keyword specifications in the scripts docstring to make a classification of the scripts according to keywords. See the scriptKeywords() function for more info. The second option removes the classification. Both options are especially useful for the pyFormex examples.
The last option reloads a ScriptMenu. This can be used to update the menu when you created a new script file.
Methods
Create a menu with pyFormex scripts to play.
Methods
ScriptMenu objects have the following methods:
Reload the scripts from dir.
This is only available if a directory path was specified and no files.
Functions defined in the module scriptMenu
- scriptMenu.extractKeyword(s)¶
Extract a keyword = value pair from a string.
If the input string s is of the form keyword = value a tuple (keyword,value) is returned, else None.
- scriptMenu.scriptKeywords(fn, keyw=None)¶
Read the script keywords from a script file.
- fn: the full path name of a pyFormex script file.
- keyw: an optional list of keywords.
Script keywords are written in the form:
key = valuein the docstring of the script. The docstring is the first non-indented multiline string of the file. A multiline string is a string delimited by triple double-quotes. Matching lines are placed in a dictionary which becomes the return value.
If a list of keywords is given, the return dictionary will only contain the matching values.
- scriptMenu.sortSets(d)¶
Turn the set values in d into sorted lists.
- d: a Python dictionary
All the values in the dictionary are checked. Those that are of type set are converted to a sorted list.
- scriptMenu.getDocString(scriptfile)¶
- scriptMenu.getDescription(doc)¶
- scriptMenu.createScriptMenu(parent=None, before=None)¶
Create the menu(s) with pyFormex scripts
This creates a menu with all examples distributed with pyFormex. By default, this menu is put in the top menu bar with menu label ‘Examples’.
The user can add his own script directories through the configuration settings. In that case the ‘Examples’ menu and menus for all the configured script paths will be gathered in a top level popup menu labeled ‘Scripts’.
The menu will be placed in the top menu bar before the specified item. If a menu item named ‘Examples’ or ‘Scripts’ already exists, it is replaced.
- scriptMenu.reloadScriptMenu()¶