Classes defined in module appMenu
A menu of pyFormex applications in a directory or list.
This class creates a menu of pyFormex applications or scripts collected from a directory or specified as a list of modules. It is used in the pyFormex GUI to create the examples menu, and for the apps history. The pyFormex apps can then be run from the menu or from the button toolbar. The user may use this class to add his own apps/scripts into the pyFormex GUI.
Apps are simply Python modules that have a ‘run’ function. Only these modules will be added to the menu. 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 three most frequent uses of this class:
AppMenu('My Apps',dir="/path/to/my/appsdir")
creates a menu with all pyFormex apps in the specified path and its subdirectories.
ApptMenu('My Scripts',dir="/path/to/my/sciptsdir",mode='scripts')
creates a menu with all pyFormex scripts in the specified path and its subdirectories.
AppMenu('History',files=["/my/script1.py","/some/other/script.pye"], mode='script',recursive=False)
is typically used to create a history menu of previously visited script 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.
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.
Get a list of scripts in self.dir
Filter a list of scripts
Load the app/script files in this menu
Return the full pathname for a script.
Return the pkg.module name for an app.
Run the selected app.
This function is executed when the menu item is selected.
Set/Run the specified app.
Set the specified app as the current app, and run it if play==True.
Run all apps in the range [first,last].
Runs the apps in the range first:last. If last is None, the length of the file list is used. If count is positive, at most count scripts per submenu are executed. Notice that the range is Python style. If random is True, the files are shuffled before running. If recursive is True, also the files in submenu are played. The first and last arguments do not apply to the submenus.
Run a sequence of apps, starting with the current plus offset.
If a positive count is specified, at most count scripts will be run. A nonzero offset may be specified to not start with the current script.
Run the current app, or the first if none was played yet.
Run the next app, or the first if none was played yet.
Run a random script.
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.
This function is used to add app/scripts to the history menus. By default, only legal pyFormex apps or scripts can be added, and scripts from the user config will not be added. Setting strict and or skipconfig to False will skip the filter(s).
Return a list with the current actions.
Return a list with the current actions of given class.
Return a list with the submenus
Return the index of the specified item in the actionlist.
If the requested item is not in the actionlist, -1 is returned.
Return the action with specified text.
First, a normal action is tried. If none is found, a separator is tried.
Return the item with specified text.
For a normal action or a separator, an action is returned. For a menu action, a menu is returned.
Returns the name of the next item.
This can be used to replace the current item with another menu. If the item is the last, None is returned.
Remove an item from this menu.
Create and insert a separator
Insert an existing menu.
Insert an action.
Create and insert an action.
Insert a list of items in the menu.
Parameters:
Functions defined in module appMenu
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.
Classify the files in submenus according to keywords.
Split a series of strings in alphabetic collections.
The strings are split over a series of bins in alphabetical order. Each bin can contain strings starting with multiple successive characters, but not more than n items. Items starting with the same character are always in the same bin. If any starting character occurs more than n times, the maximum will be exceeded.
Returns: a tuple of
Create the menu(s) with pyFormex apps
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 app directories through the configuration settings. In that case the ‘Examples’ menu and menus for all the configured app paths will be gathered in a top level popup menu labeled ‘Apps’.
The menu will be placed in the top menu bar before the specified item. If a menu item named ‘Examples’ or ‘Apps’ already exists, it is replaced.
Reload the named menu.