### Navigation

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

# 4. `script` — Basic pyFormex script functions

The `script` module provides the basic functions available in all pyFormex scripts. These functions are available in GUI and NONGUI applications, without the need to explicitely importing the `script` module.

`Classes defined in module script`

`Functions defined in module script`

`script.``Globals`()

  Return the globals that are passed to the scripts on execution.

  This basically contains the globals defined in draw.py, colors.py, and formex.py, as well as the globals from numpy. It also contains the definitions put into the pyformex.PF, by preference using the export() function. During execution of the script, the global variable __name__ will be set to either ‘draw’ or ‘script’ depending on whether the script was executed in the ‘draw’ module (–gui option) or the ‘script’ module (–nogui option).

`script.``export`(dic)

  Export the variables in the given dictionary.

`script.``export2`(names, values)

  Export a list of names and values.

`script.``forget`(names)

  Remove the global variables specified in list.

`script.``forgetAll`()

  Delete all the global variables.

`script.``rename`(oldnames, newnames)

  Rename the global variables in oldnames to newnames.

`script.``listAll`(clas=None, like=None, filter=None, dic=None)

  Return a list of all objects in dictionay that match criteria.

  - dic: a dictionary object, defaults to pyformex.PF
  - clas: a class name: if specified, only instances of this class will be returned
  - like: a string: if given, only object names starting with this string will be returned
  - filter: a function taking an object name as parameter and returning True or False. If specified, only objects passing the test will be returned.

  The return value is a list of keys from dic.

`script.``named`(name)

  Returns the global object named name.

`script.``getcfg`(name)

  Return a value from the configuration.

`script.``ask`(question, choices=None, default='')

  Ask a question and present possible answers.

  If no choices are presented, anything will be accepted. Else, the question is repeated until one of the choices is selected. If a default is given and the value entered is empty, the default is substituted. Case is not significant, but choices are presented unchanged. If no choices are presented, the string typed by the user is returned. Else the return value is the lowest matching index of the users answer in the choices list. Thus, ask(‘Do you agree’,[‘Y’,’n’]) will return 0 on either ‘y’ or ‘Y’ and 1 on either ‘n’ or ‘N’.

`script.``ack`(question)

  Show a Yes/No question and return True/False depending on answer.

`script.``error`(message)

  Show an error message and wait for user acknowlegement.

`script.``system`(cmdline, result='output')

  Run a command and return its output.

  If result == ‘status’, the exit status of the command is returned. If result == ‘output’, the output of the command is returned. If result == ‘both’, a tuple of status and output is returned.

`script.``executeScript`(scr, glob)

  Execute a Python script in specified globals.

`script.``playScript`(scr, name=None, filename=None, argv=[], pye=False)

  Play a pyformex script scr. scr should be a valid Python text.

  There is a lock to prevent multiple scripts from being executed at the same time. This implies that pyFormex scripts can currently not be recurrent. If a name is specified, set the global variable pyformex.scriptName to it when the script is started. If a filename is specified, set the global variable __file__ to it.

  If step==True, an indefinite pause will be started after each line of the script that starts with ‘draw’. Also (in this case), each line (including comments) is echoed to the message board.

`script.``breakpt`(msg=None)

  Set a breakpoint where the script can be halted on a signal.

  If an argument is specified, it will be written to the message board.

  The exitrequested signal is usually emitted by pressing a button in the GUI.

`script.``stopatbreakpt`()

  Set the exitrequested flag.

`script.``playFile`(fn, argv=[])

  Play a formex script from file fn.

  fn is the name of a file holding a pyFormex script. A list of arguments can be passed. They will be available under the name argv. This variable can be changed by the script and the resulting argv is returned to the caller.

`script.``play`(fn=None, argv=[], step=False)

  Play the pyFormex script with filename fn or the current script file.

  This function does nothing if no filename is passed or no current scriptfile was set. If arguments are given, they are passed to the script. If step is True, the script is executed in step mode.

`script.``exit`(all=False)

  Exit from the current script or from pyformex if no script running.

`script.``quit`()

  Quit the pyFormex program

  This is a hard exit from pyFormex. It is normally not called directly, but results from an exit(True) call.

`script.``processArgs`(args)

  Run the application without gui.

  Arguments are interpreted as names of script files, possibly interspersed with arguments for the scripts. Each running script should pop the required arguments from the list.

`script.``setPrefs`(res, save=False)

  Update the current settings (store) with the values in res.

  res is a dictionary with configuration values. The current settings will be update with the values in res.

  If save is True, the changes will be stored to the user’s configuration file.

`script.``printall`()

  Print all Formices in globals()

`script.``writable`(path)

  Returns True if the specified path is writeable

`script.``chdir`(fn)

  Change the current working directory.

  If fn is a directory name, the current directory is set to fn. If fn is a file name, the current directory is set to the directory holding fn. In either case, the current directory is stored in the user’s preferences for persistence between pyFormex invocations.

  If fn does not exist, nothing is done.

`script.``runtime`()

  Return the time elapsed since start of execution of the script.

`script.``startGui`(args=[])

  Start the gui

`script.``isWritable`(path)

  Check that the specified path is writeable.

  BEWARE: this only works if the path exists!

`script.``checkRevision`(rev, comp='>=')

  Check the pyFormex revision number.

  - rev: a positive integer.
  - comp: a string specifying a comparison operator.

  By default, this function returns True if the pyFormex revision number is equal or larger than the specified number.

  The comp argument may specify another comparison operator.

  If pyFormex is unable to find its revision number (this is the case on very old versions) the test returns False.

`script.``requireRevision`(rev, comp='>=')

  Require a specified pyFormex revision number.

  The arguments are like checkRevision. Ho9wever, this function will raise an error if the requirement fails.

`script.``grepSource`(pattern, options='', quiet=False)

  Finds pattern in the pyFormex source .py files.

  Uses the grep program to find all occurrences of some specified pattern text in the pyFormex source .py files (including the examples). Extra options can be passed to the grep command. See man grep for more info.

  Returns the output of the grep command.

`script.``writeGeomFile`(filename, objects, sep=' ', mode='w', shortlines=False)

  Save geometric objects to a pyFormex Geometry File.

  A pyFormex Geometry File can store multiple geometrical objects in a native format that can be efficiently read back into pyformex. The format is portable over different pyFormex versions and even to other software.

  - filename: the name of the file to be written
  - objects: a list or a dictionary. If it is a dictionary, the objects will be saved with the key values as there names. Objects that can not be exported to a Geometry File will be silently ignored.
  - mode: can be set to ‘a’ to append to an existing file.
  - sep: the string used to separate data. If set to an empty string, the data will be written in binary format and the resulting file will be smaller but less portable.

  Returns the number of objects written to the file.

`script.``readGeomFile`(filename)

  Read a pyFormex Geometry File.

  A pyFormex Geometry File can store multiple geometrical objects in a native format that can be efficiently read back into pyformex. The format is portable over different pyFormex versions and even to other software.

  - filename: the name of an exisiting pyFormex Geometry File.

  Returns a dictionary with the geometric objects read from the file. If object names were stored in the file, they will be used as the keys. Else, default names will be provided.

### Navigation

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