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
Return the globals that are passed to the scripts on execution.
When running pyformex with the –nogui option, this contains all the globals defined in the module formex (which include those from coords, arraytools and numpy.
When running with the GUI, this also includes the globals from gui.draw (including those from gui.color).
Furthermore, the global variable __name__ will be set to either ‘draw’ or ‘script’ depending on whether the script was executed with the GUI or not.
Export the variables in the given dictionary.
Export a list of names and values.
Remove the global variables specified in list.
Delete all the global variables.
Rename the global variables in oldnames to newnames.
Return a list of all objects in dictionay that match criteria.
The return value is a list of keys from dic.
Returns the global object named name.
Return a value from the configuration.
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’.
Show a Yes/No question and return True/False depending on answer.
Show an error message and wait for user acknowlegement.
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.
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.
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.
Set the exitrequested flag.
Convert a script to using the print function
Check whether the script in the given files uses print function syntax.
Returns the compiled object if no error was found during compiling. Returns the filename if an error was found and correction has been attempted. Raises an exception if an error is found and no correction attempted.
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.
Run the current pyFormex application or script file.
This function does nothing if no appname/filename is passed or no current script/app was set. If arguments are given, they are passed to the script. If step is True, the script is executed in step mode. The ‘refresh’ parameter will reload the app.
Exit from the current script or from pyformex if no script running.
Quit the pyFormex program
This is a hard exit from pyFormex. It is normally not called directly, but results from an exit(True) call.
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.
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.
Print all Formices in globals()
Check that the specified path is writable.
BEWARE: this only works if the path exists!
Change the current working directory.
If path exists and it is a directory name, make it the current directory. If path exists and it is a file name, make the containing directory the current directory. If path does not exist and create is True, create the path and make it the current directory. If create is False, raise an Error.
Parameters:
The changed to current directory is stored in the user’s preferences for persistence between pyFormex invocations.
Print the current working directory.
Create a new directory.
Create a new directory, including any needed parent directories.
Returns True if the pathname exists (before or after).
Make sure the parent directory of path exists.
Return the time elapsed since start of execution of the script.
Start the gui
Check the pyFormex revision number.
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.
Require a specified pyFormex revision number.
The arguments are like checkRevision. Ho9wever, this function will raise an error if the requirement fails.
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.
Returns the number of objects written to the file.
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.
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.