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

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

49.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(filename)[source]

Save the contents of the board to a file

redirect(onoff)[source]

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.

Parameters:

  • path: path of the file to be watched.

  • func: function to be executed.

removeWatch(path)[source]

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.

getMenuData(name)[source]

Get the menu data for one of the main menus

Also, register menu item enabler functions, if they exist.

dialog(caption)[source]

Return the dialog with the named caption

Parameters

caption (str) – The window caption to find.

Returns

Dialog | None – The dialog with the specified caption, or None if there is no such dialog.

addStatusbarButtons(name, actions, **kargs)[source]

Install a group of buttons in the statusbar

createConsole(config)[source]

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_doc_dialog()[source]

Close the doc_dialog if it is open.

clearViewButtons()[source]

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.

setViewButtons(defviews)[source]

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.

applyView(name)[source]

Apply a saved view to the current camera.

setView(view)[source]

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.

maxCanvasSize()[source]

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.

showEditor()[source]

Start the editor.

closeEditor()[source]

Close the editor.

setcurproj(project='')[source]

Show the current project name.

setcurfile(appname)[source]

Set the current application or script.

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

setcurdir()[source]

Show the current workdir.

resetCursor()[source]

Clear the override cursor stack.

This will reset the application cursor to the initial default.

keyPressEvent(e)[source]

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.

XGeometry(border=True)[source]

Get the main window position and size.

Parameters

border (bool) – If True (default), the returned geometry includes the border frame. If set to False, the border is excluded.

Returns

tuple (x,y,w,h) – A tuple of int with the top left position and the size of the window geometry.

writeSettings()[source]

Store the GUI settings

processEvents()[source]

Process interactive GUI events.

findDialog(name)[source]

Find the Dialog with the specified name.

Returns the list with matching dialogs, possibly empty.

closeDialog(name)[source]

Close the Dialog with the specified name.

Closest all the Dialogs 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

startRun()[source]

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.

stopRun()[source]

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()[source]

Cleanup the GUI (restore default state).

onExit(func)[source]

Register a function for execution on exit of the GUI.

Parameters

func (callable) – A function to be called on exit of the GUI. There is no guaranteed order of execution of the exit functions.

closeEvent(event)[source]

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.

fullScreen(onoff=None)[source]

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.

enableToolbars(enable=True)[source]

En/disable the toolbars.

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

The interactive Qt application

It sets the default locale to ‘C’ and rejects thousands separators. This is the only sensible thing to do for processing numbers in a scientific international community.

49.2. Functions defined in module gui.guimain

gui.guimain.setAppStyle(style)[source]

Set the main application style.

gui.guimain.setAppFont(font)[source]

Set the main application font.

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

gui.guimain.setAppFontFamily(family)[source]

Set the main application font family to the given family.

gui.guimain.setAppFontSize(size)[source]

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

gui.guimain.setAppearance()[source]

Set all the GUI appearance elements.

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

gui.guimain.exitDialog()[source]

Show the exit dialog to the user.

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

Get information about an X window.

Returns the information about an X11 window as obtained from the xwininfo command, but parsed as a dict. The window can be specified by its id or by its name. If neither is provided, the user needs to interactively select a window by clicking the mouse in that window.

Parameters
  • windowid (str, optional) – A hex string with the window id.

  • name (str) – The window name, usually displayed in the top border decoration.

  • check_only (bool) – If True, only check whether the window exists, but do not return the info.

Returns

dict – Return all the information obtained from calling xwininfo for the specified or picked window. If a window id or name is specified that does not exist, an empty dict is returned.

Notes

The window id of the pyFormex main window can be obtained from pf.GUI.winId(). The name of the window is pf.Version().

gui.guimain.pidofxwin(windowid)[source]

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.

gui.guimain.findOldProcesses(max=16)[source]

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.

gui.guimain.killProcesses(pids)[source]

Kill the processes in the pids list.

gui.guimain.showSplash()[source]

Show the splash screen

gui.guimain.startGUI(args)[source]

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.

gui.guimain.createDatabases()[source]

Create unified database objects for all menus.

gui.guimain.runGUI()[source]

Go into interactive mode