44. gui.guimain — Graphical User Interface for pyFormex.

This module contains the main functions responsible for constructing and starting the pyFormex GUI.

44.1. Classes defined in module gui.guimain

class gui.guimain.Board(parent=None)[source]

Message board for displaying read-only plain text messages.

write(s, color='black')[source]

Write a string to the message board.

If a color is specified, the text is shown in the specified color, but the default board color remains unchanged.


Save the contents of the board to a file


Redirect standard and error output to this message board

class gui.guimain.FileWatcher(*args)[source]

Watch for changes in files and then execute the associated function.

addWatch(path, func)[source]

Watch for changes in file and the execute func.

When the specified file is changed, func is executed.


  • path: path of the file to be watched.
  • func: function to be executed.

Remove the watch for file path

class gui.guimain.Gui(windowname, size=(800, 600), pos=(0, 0), bdsize=(0, 0))[source]

Implements a GUI for pyformex.


Create the message board and console

config should be one of the following:

‘b’ : only board, no console ‘bc’: a board and separate console ‘c’ : only console, taking ove the board functions


Close the doc_dialog if it is open.


Clear the view buttons in views toolbar and views menu.

This is typically use from setViewButtons to change the current buttons to a new set.


Set view buttons in views toolbar and views menu.

defviews can be on of ‘xy’ or ‘xz’, or else it is a list of tuple (viewname, viewicon)

createView(name, angles)[source]

Create a new view and add it to the list of predefined views.

This creates a named view with specified angles or, if the name already exists, changes its angles to the new values.

It adds the view to the views Menu and Toolbar, if these exist and do not have the name yet.

saveView(name=None, addtogui=True)[source]

Save the current view and optionally create a button for it.

This saves the current viewport ModelView and Projection matrices under the specified name.

It adds the view to the views Menu and Toolbar, if these exist and do not have the name yet.


Apply a saved view to the current camera.


Change the view of the current GUI viewport, keeping the bbox.

view is the name of one of the defined views.

updateToolBar(shortname, fullname=None)[source]

Add a toolbar or change its position.

This function adds a toolbar to the GUI main window at the position specified in the configuration. If the toolbar already exists, it is moved from its previous location to the requested position. If the toolbar does not exist, it is created with the given fullname, or the shortname by default.

The full name is the name as displayed to the user. The short name is the name as used in the config settings.

The config setting for the toolbar determines its placement: - None: the toolbar is not created - ‘left’, ‘right’, ‘top’ or ‘bottom’: a separate toolbar is created - ‘default’: the default top toolbar is used and a separator is added.


Return the maximum canvas size.

The maximum canvas size is the size of the central space in the main window, occupied by the OpenGL viewports.


Start the editor.


Close the editor.


Show the current project name.


Set the current application or script.

appname is either an application module name or a script file.


Show the current workdir.


Clear the override cursor stack.

This will reset the application cursor to the initial default.


Top level key press event handler.

Events get here if they are not handled by a lower level handler. Every key press arriving here generates a WAKEUP signal, and if a dedicated signal for the key was installed in the keypress table, that signal is emitted too. Finally, the event is removed.


Get the main window position from the xwininfo command.

The Qt position does not get updated when changing the window size from the left. This substitute function will find the correct position from the xwininfo command output.


Get the main window position and size from the xwininfo command.


Store the GUI settings


Process interactive GUI events.


Find the InputDialog with the specified name.

Returns the list with maching dialogs, possibly empty.


Close the InputDialog with the specified name.

Closest all the InputDialogs with the specified caption owned by the GUI.

enableButtons(toolbar, buttons, enable)[source]

Enable or disable a button in a toolbar.

toolbar is a toolbar dict. buttons is a list of button names. For each button in the list:

  • If it exists in toolbar, en/disables the button.
  • Else does nothing

Change the GUI when an app/script starts running.

This method enables/disables the parts of the GUI that should or should not be available while a script is running It is called by the application executor.


Change the GUI when an app/script stops running.

This method enables/disables the parts of the GUI that should or should not be available when no script is being executed. It is called by the application executor when an application stops.


Cleanup the GUI (restore default state).


Register a function for execution on exit


Override the close event handler.

We override the default close event handler for the main window, to allow the user to cancel the exit, and to save the latest settings.


Toggle the canvas full screen mode.

Fullscreen mode hides all the components of the main window, except for the central canvas, maximizes the main window, and removes the window decorations, thus leaving only the OpenGL canvas on the full screen. (Currently there is also still a small border remaining.)

This mode is activated by pressing the F5 key. A second F5 press will revert to normal display mode.


En/disable the toolbars.

class gui.guimain.Application(args)[source]

The interactive Qt application

44.2. Functions defined in module gui.guimain


Check whether the OpenGL canvas has DRI enabled.


Set the main application style.


Set the main application font.

font is either a QFont or a string resulting from the QFont.toString() method


Set the main application font family to the given family.


Set the main application font size to the given point size.


Set all the GUI appearance elements.

Sets the GUI appearance from the current configuration values ‘gui/style’, ‘gui/font’, ‘gui/fontfamily’, ‘gui/fontsize’.


Show the exit dialog to the user.

gui.guimain.xwininfo(windowid=None, name=None)[source]

Returns the X window info parsed as a dict.

Either the windowid or the window name has to be specified.


Returns the PID of the process that has created the window.

Remark: Not all processes store the PID information in the way it is retrieved here. In many cases (X over network) the PID can not be retrieved. However, the intent of this function is just to find a dangling pyFormex process, and should probably work on a normal desktop configuration.


Check if a GUI window with the given name exists.

On X-Window systems, we can use the xwininfo command to find out whether a window with the specified name exists.


Find old pyFormex GUI processes still running.

There is a maximum to the number of processes that can be detected. 16 will suffice largely, because there is no sane reason to open that many pyFormex GUI’s on the same screen.

Returns the next available main window name, and a list of running pyFormex GUI processes, if any.


Kill the processes in the pids list.


Show the splash screen


Create the Qt application and GUI.

A (possibly empty) list of command line options should be provided. Qt wil remove the recognized Qt and X11 options.


Create unified database objects for all menus.


Go into interactive mode