28. scriptMenu — Menu with pyFormex scripts. — pyFormex v0.8.6 documentation

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >

make[2]: Map ‘/home/bene/prj’ wordt binnengegaan make[2]: Map ‘/home/bene/prj’ wordt verlaten .. $Id$ -- rst -- .. pyformex reference manual — scriptMenu .. CREATED WITH py2rst.py: DO NOT EDIT

# 28. `scriptMenu` — Menu with pyFormex scripts.

`Classes defined in module scriptMenu`

class `scriptMenu.` `ScriptMenu`(title, dir=None, files=None, ext=None, recursive=None, max=0, autoplay=False, toplevel=True)

  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:

  - title: the top level label for the menu
  - files: a list of file names of pyFormex scripts. If no dir nor ext arguments are given, these should be the full path names to the script files. If omitted, all files in the directory dir whose name is ending with ext and do not start with either ‘.’ or ‘_’, will be selected.
  - dir: an optional directory path. If given, it will be prepended to each file name in files and recursive will be True by default.
  - ext: an extension to be added to each filename. If dir was specified, the default extension is ‘.py’. If no dir was specified, the default extension is an empty string.
  - recursive: if True, a cascading menu of all pyFormex scripts in the directory and below will be constructed.
  - max: if specified, the list of files will be truncated to this number of items. Adding more files to the menu will then be done at the top and the surplus number of files will be dropped from the bottom of the list.

  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:

  - Run next script
  - Run all following scripts
  - Run all scripts
  - Run a random script
  - Run all in random order

  Furthermore, if the menu is a toplevel one, it will have the following extra options:

  - Classify scripts
  - Remove catalog
  - Reload scripts

  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.

  `fileName`(scriptname)

    Return the full pathname for a scriptname.

  `getFiles`()

    Get a list of scripts in self.dir

  `filterFiles`(files)

    Filter a list of scripts

  `loadFiles`(files=None)

    Load the script files in this menu

  `run`(action)

    Run the selected script.

  `runScript`(filename)

    Run the specified script.

  `runNext`()

    Run the next script.

  `runAllNext`()

    Run the current and all following scripts.

  `runAll`()

    Run all scripts.

  `runAllFiles`(files, randomize=False, pause=0.0)

    Run all the scripts in given list.

  `runRandom`()

    Run a random script.

  `runAllRandom`()

    Run all scripts in a random order.

  `reload`()

    Reload the scripts from dir.

    This is only available if a directory path was specified and no files.

  `add`(filename, strict=True)

    Add a new filename to the front of the menu.

    By default, only legal pyFormex scripts can be added.

  `classify`()

    Classify the files in submenus according to keywords.

`Functions defined in 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 = 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.

`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.` `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.

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >