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

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

52.1. Classes defined in module gui.guimain

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

Watch for changes in files and then execute an 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_like) – The path of the file to be watched.

  • func (callable) – The function to be called when the file changes. The path is passed as an argument.

removeWatch(path)[source]

Remove the watch for a file path

Parameters:

path (path_like) – The path of the file to be watched.

onFileChanged(path)[source]

Call installed function when file changed

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

Implements the pyFormex GUI.

The GUI has a main window with a menubar on top and a statusbar at the bottom. One or more toolbars may be located at the top, bottom, left or right side of the main window. The central part is split up over a display canvas at the top and a Python console at the bottom. The split size of these two parts can be adjusted. The canvas may contain one or more OpenGL widgets for 3D rendering. The console displays messages from the applications and can be used to access any internal part of pyFormex and interactively execute pyFormex instructions.

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.

insertModuleMenu(name)[source]

Insert the menu from module name in the top menu

If the module defines an attribute MenuData, it is inserted in the MenuBar. If it defines a function menu_enabler, it is called afterwards.

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

Install a group of buttons in the statusbar

saveConsoleHistory()[source]

Save the console history

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.

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

This includes the GUI size and position

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.

run()[source]

Go into interactive mode until the user exits

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=['/usr/bin/sphinx-build'])[source]

The interactive Qt application

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

Overrides some QApplication methods for convenience (usually to allow simple strings as input).

maxSize()[source]

Return the maximum available screensize

currentStyle()[source]

Return the application style in use

getStyles()[source]

Return the available styles, removing the faulty ones.

setStyle(style)[source]

Set the application style.

style is a string, one of those returned by getStyles()

setFont(font)[source]

Set the main application font.

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

setFontFamily(family)[source]

Set the main application font family to the given family.

setFontSize(size)[source]

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

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

52.2. Functions defined in module gui.guimain

gui.guimain.splitXgeometry(geometry)[source]

Split an X11 window geometry string in its components.

Parameters:

geometry (str) – A string in X11 window geometry format: WxH+X+Y, where W, H are the width and height of the window, and X,Y are the position of the top left corner. The +Y or +X+Y parts may be missing and will thendefault to 0.

Returns:

(W, H, X, Y) – A tuple of four ints.

Examples

>>> splitXgeometry('1000x800+20')
(1000, 800, 20, 0)
gui.guimain.Xgeometry(w, h, x=0, y=0)[source]

Return an X11 window geometry string.

Parameters:
  • (w (tuple of int) – The width, height, xpos and ypos to pack into an X11 geometry string.

  • h (tuple of int) – The width, height, xpos and ypos to pack into an X11 geometry string.

  • x (tuple of int) – The width, height, xpos and ypos to pack into an X11 geometry string.

  • y) (tuple of int) – The width, height, xpos and ypos to pack into an X11 geometry string.

Returns:

str – A string of the format WxH+X+Y.

Examples

>>> Xgeometry(1000, 800, 20, 0)
'1000x800+20+0'
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 this 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.createGUI()[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.