Classes defined in module scriptMenu
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.is_pyFormex() 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.
Return the full pathname for a scriptname.
Get a list of scripts in self.dir
Filter a list of scripts
Load the script files in this menu
Run the selected script.
Run the specified script.
Run the next script.
Run the current and all following scripts.
Run all scripts.
Run all the scripts in given list.
Run a random script.
Run all scripts in a random order.
Reload the scripts from dir.
This is only available if a directory path was specified and no files.
Add a new filename to the front of the menu.
By default, only legal pyFormex scripts can be added.
Classify the files in submenus according to keywords.
Functions defined in module scriptMenu
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.
Read the script keywords from a script file.
Script keywords are written in the form:
key = value
in 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.
Turn the set values in d into sorted lists.
All the values in the dictionary are checked. Those that are of type set are converted to a sorted list.
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.