63. gui.widgets — Widgets and dialogs for the pyFormex GUI

This module provides widgets and dialogs to easily extend the pyFormex GUI with user defined interaction. It allows to build quite complex dialogs with a minimal effort. Like the rest of the pyFormex GUI, it is based on the Qt toolkit. Using this module however makes creating user dialogs very simple, even without any knowledge of Qt.

63.1. Classes defined in module gui.widgets

class gui.widgets.ValidationError[source]

Raised in input fields that do not have an acceptable value.

class gui.widgets.InputItem(name, **kargs)[source]

A single input item in a Dialog.

This is the base class for all input items in an Dialog. An InputItem in the dialog is treated as a unit and refered to by a single unique name.

The InputItem class is rarely used directly. Most of the components of an Dialog are subclasses of it, each specialized in some form of input data or representation. There is e.g. an InputInt class to input an integer number and an InputString for the input of a string. The base class groups the functionality that is common to the different input widgets. Even the subclasses are seldomly used directly by the normal user. Most of the time an Dialog is created by just specifying the proper data using the helper function _I, _G, _T, _C defined in draw. See Input Dialogs for more guidelines.

The InputItem widget holds a horizontal layout box (QHBoxLayout) to group its components. In most cases there are just two components: a label with the name of the field, and the actual input field. Other components, such as buttons or sliders, may be added. This is often done in subclasses.

The constructor has one required argument: name. The remaining are keyword parameters. Some of them are used by all subclasses, others are only for some subclass(es). Some of the parameters are handled by this base class, others are handled by the individual subclass. All InputItem classes use the **kargs syntax, so accept all option. They just act on the useful ones.

For reference, we add here the full list of keyword options in use.

Parameters:
  • name (str) – The name used to identify the item. It should be unique for all InputItems in the same Dialog. It is used as a key in the dictionary that returns all the input values in the dialog. It is also the default label displayed in front of the input field if no text is specified.

  • value (data) – The initial value of the field. The data type is dependent on the itemtype. In simple cases the data type will determine the itemtype if it is not specified: int, float, str. Required in most cases, though some itemtypes have a default value (see choices).

  • itemtype (str) – The type of input field. This will determine the type of data to be specified as value, the type of data returned, and the subclass of InputItem used to accept the data. For a string ‘abc’ the subclass used is InputAbc.

  • text (str | QPixmap) – A text string or icon that is displayed next to the input area, instead of the default name. Use this field to display a more descriptive text for the user, while using a short name for handling the return value. Set it to an empty string to suppress the creation of a label. This is useful if the input field widget itself already provides a label (see InputBool).

  • tooltip (str) – A string that will be shown when the user hovers the mouse over the InputItem widget. It can be used to give more comprehensive explanation to first time users.

  • choices (list) – A list of strings which are options to choose from. If specified and no itemtype is given, the options are presented as a combo box. Alternatively, one can use itemtype ‘hradio’, ‘vradio’, or ‘push’. If choices are given and no value is specified, the default value is set to the first item in the choices list. If a value is given that does not appear in choices, the value will be added as the first option in choices.

  • min (data) – The minimum value for the data to be entered. Useful with ‘int’ and ‘float’ types. If specified, you will not be able to return a lower value.

  • max (data) – The maximum value for the data to be entered. Useful with ‘int’ and ‘float’ types. If specified, you will not be able to return a higher value.

  • func (callable) – A callable taking an InputItem as parameter. If specified, it is called whenever the value of the item is changed. Many InputItems support this feature. Some even require it. From the passed InputItem, all information about the item and even the whole dialog (through its parent attribute) can be accessed.

  • data (data) – Any extra data that you want to be stored into the widget. These data are not displayed, but can be useful in the functioning of the widget (for example as extra information for func).

  • enabled (bool) – If False, the InputItem will not be enabled, meaning that the user can not enter or change any values there. Disabled fields are usually displayed in a greyed-out fashion. Default is True.

  • readonly (bool) – If True, the data are read-only and can not be changed by the user. Unlike disabled items, they are displayed in a normal fashion. Default is False.

  • spacer (str) – Only the characters ‘l’, ‘r’ and ‘c’ are relevant. If the string contains an ‘l’, a spacer is inserted before the label. If the string contains an ‘r’, a spacer in inserted after the input field. If the string contains a ‘c’, a spacer in inserted between the label and the input filed.

  • width (int) – The minimum width in pixels of the input field

  • buttons (a list of (label,function) tuples. For each tuple a button) – will be added after the input field. The button displays the text and when pressed, the specified function will be executed. The function takes no arguments.

Notes

Subclasses should have an __init__() method which first constructs a proper widget for the input field, and stores it in the attribute self.input. Then the baseclass should be properly initialized, passing it the name and any optional parameters:

self.input = SomeInputWidget()
super().__init__(name, **kargs)

Subclasses should also override the following default methods of the InputItem base class:

  • text(): if the subclass calls the superclass __init__() method with a value text=''. This method should return the value of the displayed text.

  • value(): if the value of the input field is not given by self.input.text(), i.e. in most cases. This method should return the value of the input field. In many cases this is different from the string displayed in the input field. Thus an InputInt should return an int. If the currenttly displayed input can not be validated, a ValidationError should be raised.

  • setValue(val): always, unless the field is readonly. This method should change the value of the input widget to the specified value.

Subclasses are allowed to NOT have a self.input attribute, IFF they redefine both the value() and the setValue() methods.

Subclasses can set validators on the input, like:

self.input.setValidator(QtGui.QIntValidator(self.input))

Subclasses can define a show() method e.g. to select the data in the input field on display of the dialog.

dialog()[source]

Return the Dialog to which this InputItem belongs

Returns:

Dialog – The Dialog this item is part of, or None if the InputItem was not constructed as part of a Dialog.

name()[source]

Return the name of the InputItem.

text()[source]

Return the displayed text of the InputItem.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

on_value_change(**kargs)[source]

Call the installed func with self as parameter

class gui.widgets.InputLabel(name, value, format='', **kargs)[source]

An unchangeable information field.

Unlike the other InputItem subclasses, this is actually not an input widget and also does not return a value. It is mostly used to present information to the user.

Parameters:
  • name (str) – The name of the field.

  • value (str) – The contents to be displayed. This may be plain text, html or reStructuredText. The latter is detected if it starts with a line containing two dots, followed with an empty line. It is converted to html before being displayed.

value()[source]

Return the widget’s value.

class gui.widgets.InputInfo(name, value, **kargs)[source]

An unchangeable input field.

It is just like an InputString, but the text can not be edited. The value should be a simple string without newlines.

Parameters:
  • name (str) – The name of the field.

  • value (str) – The string to be displayed and returned as a value.

class gui.widgets.InputString(name, value, max=None, **kargs)[source]

An editable string input field.

Parameters:
  • name (str) – The name of the field.

  • value (str | object) – The initial value of the InputItem. This is normally a string type. If not, it is converted to a string before displaying, and the displayed string will be eval’ed before returning its value. This allows e.g for editing compound objects like tuples and lists.

  • max (int, optional) – If specified, the displayed string can not be made longer than this number of characters.

show(self)[source]
value()[source]

Return the widget’s value.

class gui.widgets.InputText(name, value, format='', ret_format='plain', **kargs)[source]

A scrollable text input field.

Shows a multiline text in the input field. Rich text formats (html, rst) can be displayed in nice rendering mode.

Parameters:
  • name (str) – The name of the field.

  • value (str) – The text to be displayed. Rich text formats (html, rst) can be displayed in nice rendering mode (at the expense of not being editable).

  • format (str, optional) – The format of the text: ‘plain’, ‘html’ or ‘rst’. The default is to use autodetection. ReStructuredText is detected if text start with ‘..’. Specify format=’plain’ to force display in plain text and make rich text formats editable.

  • ret_format (str, optional) – The format of the return value: ‘plain’ or ‘html’. The default is ‘plain’. ‘rst’ can not yet be returned.

sizeHint(self) QSize[source]
show(self)[source]
value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputBool(name, value, **kargs)[source]

A boolean input item.

Creates a checkbox for the input of a boolean value.

Parameters:
  • name (str) – The name of the field.

  • value (bool) – The initial value. If True, the checkbox is checked upon display.

  • func (callable) – Called with then InputBool as parameter whenever the value is changed.

text()[source]

Return the displayed text.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputSelect(name, value=[], choices=[], sort=False, single=False, check=False, fast_sel=False, maxh=-1, **kargs)[source]

An InputItem to select from a list of choices.

InputSelect allows the selection of zero, one or more items from a list of choices.

Parameters:
  • name (str) – The name of the field.

  • value (list of str) – The initially selected choices. Values that are not in the choices list are ignored. Default is an empty list.

  • choices (list of str) – The list of possible choices.

  • single (bool) – If True, only a single item can be selected. Default False.

  • maxh (int) – If -1, the widget has a fixed height that holds all the items in the list. This is the default and works well for small lists. If 0, the widget will try to show all the items, but gets scrollbars if the space is not sufficient. With maxh>0, the widget will show exactly this number of items, and provide scrollbars to show the rest.

  • check (bool, optional) – Default False. If True, all items have a checkbox and only the checked items are returned. This option forces single==False.

  • fast_sel (bool, optional) – Default False. If True, two extra buttons are added to the InputItem, to select or deseledt all options at once.

See also

InputCombo

select exactly one value from a list of choices

setSelected(selected, flag=True)[source]

Mark the specified items as selected or not.

setChecked(selected, flag=True)[source]

Mark the specified items as checked or not.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

setAll()[source]

Mark all items as selected/checked.

setNone()[source]

Mark all items as not selected/checked.

class gui.widgets.InputCombo(name, value, choices=[], func=None, **kargs)[source]

A combobox InputItem.

A combobox allows the selection of a single item from a drop down list.

choices is a list/tuple of possible values. If value is not in the choices list, it is prepended.

The choices are presented to the user as a combobox, which will initially be set to the default value.

Parameters:
  • name (str) – Name of the field.

  • value (bool) – The initially selected value. In not specified, the first item of choices is used.

  • choices (list) – A list of strings which are the options to choose from. If value is not in the list, it is prepended.

  • func (callable, optional) – A callable taking a single argument. If specified, the function will be called with the InputItem as parameter whenever the current selection changes.

Notes

For compatibility, ‘onselect’ is still accepted as alias for ‘func’, but is deprecated.

See also

InputRadio

alternate single selection widget using radio buttons

InputPush

alternate single selection widget using push buttons

InputSelect

selection widget allowing zero, one or more selected items

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s current value.

setChoices(choices)[source]

Change the widget’s choices.

This also sets the current value to the first in the list.

class gui.widgets.InputRadio(name, value, choices=[], direction='h', **kargs)[source]

A radiobuttons InputItem.

Radio buttons are a set of buttons used to select a value from a list.

Parameters:
  • name (str) – Name of the field.

  • value (bool) – The initially selected value. In not specified, the first item of choices is used.

  • choices (list) – A list of strings which are the options to choose from. If value is not in the list, it is prepended.

  • direction ('h' | 'v') – The default ‘h’ displays the radio buttons in a horizontal box. Specifying ‘v’ puts them in a vertical box.

See also

InputCombo

alternate selection widget using a combo box

InputPush

alternate selection widget using push buttons

InputSelect

selection widget allowing zero, one or more selected items

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputPush(name, value=None, choices=[], func=None, icons=None, iconsonly=False, direction='h', count=0, small=False, **kargs)[source]

A push buttons InputItem.

Use push buttons to select of a value from a list of choices. The choices are presented to the user as a box with mutually exclusive push buttons. The buttons can display a text, an icon or both.

Parameters:
  • name (str) – Name of the item.

  • value (str, optional) – The initially selected value. If not specified, it is set to the first item of choices.

  • choices (list, optional) – The list of possible values. If value is specified and not contained in choices, it is prepended to it. If not specified, it is set to a list containing only the specified value.

  • func (callable) – A function that will be called whenever the currently selected value is changed.

  • icons (list, optional) – List of icon names to display on the buttons. The list should have the same length as choices. A None may be used for buttons that do not need an icon.

  • iconsonly (bool, optional) – If True, only the icons are displayed on the buttons. The default False will display both text and icon.

  • direction ('h' | 'v', optional) – By default the buttons are grouped in a horizontal box. Specifying ‘v’ will order the buttons vertically.

  • count (int, optional) – The maximum number of buttons to display in the main ordering direction.

  • small (bool, optional) – If True, small buttons are used instead of the normal ones. This may be a good option if you have a lot of choices.

  • func – The function to call when the button is clicked. The function receives the input field as argument. From this argument, the field’s attributes like name, value(), text, can be retrieved. The function should return the value to be set, or None if it is to be unchanged. If no function is specified, the value can not be changed.

Raises:

ValueError – If neither value nor choices are specified.:

See also

InputCombo

alternate selection widget using a combo box

InputRadio

alternate selection widget using radio buttons

InputSelect

selection widget allowing zero, one or more selected items

setText(text, index=0)[source]

Change the text on button index.

setIcon(icon, index=0)[source]

Change the icon on button index.

checkedId()[source]

Return the number of the checked button

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputInt(name, value, **kargs)[source]

An integer input item.

A text edit widget allowing to enter an integer number.

Parameters:
  • name (str) – Name of the item.

  • value (int) – The initially value.

  • min (int, optional) – If specified, this is the lowest acceptable value.

  • max (int, optional) – If specified, this is the highest acceptable value.

show(self)[source]
value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputFloat(name, value, **kargs)[source]

A float input item.

A text edit widget allowing to enter an integer number.

Parameters:
  • name (str) – Name of the item.

  • value (float) – The initially value.

  • min (float, optional) – If specified, this is the lowest acceptable value.

  • max (float, optional) – If specifieid, this is the highest acceptable value.

  • dec (int, optional) – If specified, the maximum number of decimal digits.

show(self)[source]
value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputSlider(name, value, **kargs)[source]

An integer input item with a slider.

An InputInt with an added slider to change the value.

Parameters:
  • name (str) – Name of the item.

  • value (int) – The initial value.

  • min (int, optional) – The lowest acceptable value. Default 0.

  • max (int, optional) – The highest acceptable value. Default 100.

  • ticks (int, optional) – The step length between ticks on the slider. Default is (max-min)//10.

  • func (callable, optional) – Function called whenever the value is changed.

  • tracking (bool, optional) – If True (default), func is called repeatedly while the slider is being dragged. If False, func is only called when the user releases the slider.

class gui.widgets.InputFSlider(name, value, **kargs)[source]

A float input item with a slider.

An InputFloat with an added slider to change the value.

Parameters:
  • name (str) – Name of the item.

  • value (int) – The initial value.

  • min (int, optional) – The lowest acceptable value for the slider. Default 0.

  • max (int, optional) – The highest acceptable value for the slider. Default 100.

  • scale (float, optional) – The scale factor to compute the float value from the integer slider value. Default is 1.0.

  • ticks (int, optional) – The step length between ticks on the slider. Default is (max-min)//10.

  • func (callable, optional) – Function called whenever the value is changed.

  • tracking (bool, optional) – If True (default), func is called repeatedly while the slider is being dragged. If False, func is only called when the user releases the slider.

class gui.widgets.InputTable(name, value, chead=None, rhead=None, celltype=None, rowtype=None, coltype=None, edit=True, resize=None, autowidth=True, **kargs)[source]

An input item for tabular data.

Parameters:
  • name (str) – Name of the item.

  • value (array_like) –

    A 2-D array of items, with nrow rows and ncol columns.

    If it is an NumPy array, InputTable will use the ArrayModel: editing the data will directly change the input data array; all items are of the same type; the size of the table can not be changed.

    Else a TableModel is used. Rows and columns can be added to or removed from the table. Item type can be set per row or per column or for the whole table.

  • chead (list, optional) – List of column headers

  • rhead (list, optional) – List of row headers

  • celltype

  • rowtype

  • coltype

  • edit (bool) –

  • resize

  • autowidth

  • **kargs – Aditionally, all keyword parameters of the TableModel or ArrayModel may be passed

value()[source]

Return the widget’s value.

class gui.widgets.InputPoint(name, value, **kargs)[source]

A 2D or 3D point or vector input item.

An input field holding a CoordsBox widget. The default gives fields x, y and z. With ndim=2, only x and y.

Parameters:
  • name (str) – Name of the item.

  • value (list of float) – A list of two or three floats that are the initial values of the vector components. The dimension of the vector is determined from the length.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputIVector(name, value, **kargs)[source]

A vector of int values.

Parameters:
  • name (str) – Name of the item.

  • value (list of int) – The initial values of the integers in the list. The values can be changed, but no values can be added or deleted.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputButton(name, value, **kargs)[source]

A button input item.

The button input field is a button displaying the current value. Clicking on the button executes a function responsible for changing the value.

Parameters:
  • name (str) – Name of the item.

  • value (str) – Text to display on the button

  • func (callable) – A function to be called when the button is clicked. The function receives the InputItem as argument. From this argument, the fields attributes like name, value, text, can be retrieved.

class gui.widgets.InputColor(name, value, **kargs)[source]

A color input item.

An InputItem specialized in selecting a color. The input field is a button displaying the current color. Clicking on the button opens a color dialog, and the returned color value is set in the button.

Parameters:
  • name (str) – Name of the item.

  • value (color_like) – The initial color.

setValue(value)[source]

Change the widget’s value.

class gui.widgets.InputFont(name, value, **kargs)[source]

An input item to select a font.

An InpuItem specialized in selecting a font. The input field is a button displaying the current text font. Clicking on the button opens a font dialog, and the returned font name is displayed in the button.

Parameters:
  • name (str) – Name of the item.

  • value (str) – The initial font name.

setFont(self, a0: QFont)[source]
class gui.widgets.InputFilename(name, value, filter='*', mode='file', preview=None, **kargs)[source]

A filename input item.

An InpuItem specialized in selecting a file. The input field is a button displaying the file name. Clicking on the button opens a file selection dialog, and the returned file name is displayed in the button.

Parameters:
  • name (str) – Name of the item.

  • value (str) – The initial file name.

  • filter (str) – The filter for the accepted filenames. See also InputFile. Default is ‘*’.

  • mode (str) – If True, the file selection mode. One of ‘file’, ‘exist’, ‘dir’, ‘any’ or ‘multi’. Default is False. See InputFile for details.

  • preview (ImageView, optional) – A widget having a showImage method. This can be used with image files to show a preview of the selected file. In most cases the preview widget is inserted in a dialog directly below the InputFilename field.

See also

InputFile

a file selection dialog integrated in the InputItem

changeFilename()[source]

Pop up a FileDialog to change the filename

value()[source]

Return the widget’s value.

class gui.widgets.InputFile(name, value, filter='*', mode='file', compr=False, auto_suffix=True, sidebar=[], **kargs)[source]

An input item to select a file.

A filename input field with an integrated file selection widget that allows to interactively select one (or more) file(s) or a directory from the file system, even create new directories.

The returned value is a single Path except for the ‘multi’ mode, which returns a (possibly empty) list of Paths.

Parameters:
  • name (str) – Name of the item.

  • value (path_like) – The path of the initially shown directory. It should be an existing path on the file system. If a filename is specified, that file will be marked as the initial selection.

  • filter (str | list of str) –

    One or more filter(s) to restrict the selectable files in the dialog. If multiple filters are given, the user can select which one to use. Each string can be one of the following:

    • a string in the format ‘DESCRIPTION (PATTERNS)’ where DESCRIPTION is a text describing the file type and PATTERNS is one or more filename matching patterns, separated by blanks. Example: ‘Image files (*.png *.jpg)’

    • a key that can be passed to utils.fileDescriptions() to generate such a string. The function contains ready made filters for most common file types used in pyFormex.

  • mode (str) –

    Determines what can be selected. One of:

    • ’file’: select a file (existing or not). This is the default.

    • ’exist’: select an existing file

    • ’dir’: select an existing directory (widget allows to create a new)

    • ’any’: select a file (existing or not) or a directory

    • ’multi’: select multiple existing paths from the same directory

  • compr (bool) – If True, the specified filters will be expanded to also include compressed files of the specified patterns. Compression algorithms include ‘gz’ and ‘bz2’. For example, a filter ‘Python files (*.py)’ would be changed to ‘Python files (*.py *.py.gz *.py.bz2)’.

  • auto_suffix (bool) – If True (default), new file names will automatically be changed to have an extension matching the current filter. If False, any name is accepted as a new file name.

  • sidebar (list) – A list of path_like strings to add to the sidebar of the filedialog. This is typically used to provide shortcuts to some often used directories.

See also

InputFilename

a filename input field with popup file selection dialog

done(value)[source]

Close the dialog when the selector is closed, e.g. on double click

value()[source]

Return the widget’s value.

setValue(value)[source]

Change the widget’s value.

class gui.widgets.InputWidget(name, value, **kargs)[source]

An input item containing another widget.

Parameters:
  • name (str) – Name of the item.

  • value (widget) –

    Another widget, often an InputItem. The widget should have at least the following methods:

    • value(): returns the value of the accepted data in the widget.

    • setValue(dict): updates the value(s) in the widget with those in the passed dict.

text()[source]

Return the displayed text.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputGroup(name, **kargs)[source]

A boxed group of InputItems.

An InputGroup groups multiple InputItems in a box with label. It contains it’s own InputForm in which the items can be layed out instead of in the Dialog’s main form. The InputGroup is normally created by using the _G() function in the Dialog items argument.

Parameters:
  • name (str) – Name of the group.

  • check (bool, optional) – If True, the group label has a check widget to enable/disable all items in the group at once.

  • enabled (bool, optional) – If True (default), the group is enabled initially.

value()[source]

Return the widget’s value.

setValue(val)[source]

Change the widget’s value.

class gui.widgets.InputHBox(name, hbox, **kargs)[source]

A column of items in a hbox input form.

Usually, all InputItems in a Dialog are put vertically in the form. Using the _C() function in the Dialog input, a horizontal box is created in the form, which each can be filled with multiple columns of InputItems.

Parameters:

name (str) – Name of the hbox.

class gui.widgets.InputTab(name, tab, **kargs)[source]

A tab page in an input form.

An InputTab groups multiple InputItems in a tab page with a label. It contains it’s own InputForm in which items can be layed out instead of in the Dialog’s main form. The label has a check box to enable/disable the whole set of items as a group. The InputTab is normally created by using the _T() function in the Dialog items argument.

Parameters:

name (str) – Name of the tab.

class gui.widgets.InputForm[source]

An input form.

The input form is a layout box in which the InputItems are normally layed out vertically. The form can contain hboxes, which create multiple columns of vertically layed out items. Furthermore, the form can consist of multiple tabs which each can be filled with (columns of ) input items.

class gui.widgets.Dialog(items, *, enablers=[], actions=None, default=None, message=None, caption=None, parent=None, modal=None, flags=None, store=None, save=None, prefix='', autoprefix=False, flat=None, scroll=False, buttonsattop=True, size=None)[source]

A popup window to edit, accept or reject input values.

The Dialog class presents a unified system for quick and easy creation of common dialog types. The provided dialog can become quite sophisticated with tabbed pages, groupboxes and custom widgets. Both modal and modeless (non-modal) dialogs can be created.

Parameters:
  • items (list) – A list of items to be put in the dialog form. Each item is either an input item, meaning it can return a value to the program, or a plain QWidget, which can be used in an auxiliary role, but does not return a value. Input items are specified as a dict, containing all the required keyword arguments to construct one of the InputItem subclasses. Because these dicts can become quite verbal, the gui.draw module contains some shortcut functions that help in reducting the required input. Each InputItem at least has an attribute ‘name’ and a method ‘value()’. The dialog returns its results as a dict where the value() of each input item is stored with its name as key. The name can also be used as an index in the Dialog to get the corresponding InputItem.

  • enablers (list of tuples, optional) – Each item is a tuple of the form (key,value,key1,…) defining a field whose value will enable other fields. If the input itemm named key has the specified value, the the fields key1,… are enabled. Currently, key should be a field of type boolean, [radio], combo or group. Also, any input field should only have one enabler, or incorrect operation may result. Note: this feature is currently scheduled for revision.

  • actions (list | dict, optional) –

    Parameters to define a ButtonBox with actions. If a list, it must be like the actions parameter of ButtonBox. If a dict, it must contain the choices, funcs and optionally icons parameters of ButtonBox. The generated buttons are added to the dialog window above (default) or below the normal input form. They are generally used to perform some overall action on the input dialog, like accepting the values or rejecting them, and closing the dialog window, but they can be used for anything. Overall actions could also be triggered from buttons in the normal dialog form, but it is convenient for the user to make them stand off from the normal input form. The following default actions will be generated if the button text is supplied without a function:

    • ’Cancel’: reject (and close) the dialog

    • ’OK’: accept the data in the dialog and close it

    • ’Close’: close the dialog (possible containing non-validated entries).

    If no actions are specified, a default ButtonBox is created two buttons: Cancel and OK, to either reject or accept the input values. This is most valuable in modal dialogs, where some button is needed to end the modal dialog.

  • default (str, optional) – The text of the default action. This should be one of the actions defined in the actions parameter. If not specified, it is set to the first of the actions. If no actions were defined either, it is set to ‘OK’.

  • message (str, optional) – A text to be displayed in front of the action buttons. It is most functional when the action buttons are on top, to show information about the input form below.

  • caption (str, optional) – The title to be shown in the window decoration. Default is ‘pyFormex-dialog’. Dialog windows remember their position based on this caption.

  • parent (QWidget, optional) – The parent widget. Setting this will destroy the dialog when the parent is destroyed. The default is the pyFormex main window.

  • modal (bool, optional) – If True, the dialog is a modal one, meaning all other windows of the application are blocked until the user finishes the dialog by either accepting or rejecting the data, which will close the window. If False, the dialog is modeless and the user can continue working with other windows while the dialog stays open. The default is to not set any option and expect it to be specified when the dialog is shown (see show()).

  • store (dict | str, optional) –

    A dict or dict-like object storing the initial and/or the accepted values of the input items. The keys in the dict are the item names. The behavior of the store is different depending on the value of the save parameter.

    The default behavior of the store is to provide the initial values as well as store back the validated results. The values in the store will override the values specified in the items. Items do not need to have a value specified, if their value is in the store. On input validation the data in the store are updated. Missing items are added. This behavior will easily create persistence of the input data over different invocations of the Dialog. By using a store in the project dict (pf.PF), there will even be persistence over different executions of the script/app, and if the project is saved to a file even over different pyFormex sessions. As an extra convenience, if a string is specified instead of a dict, an empty dict will be created in pf.PF with that string as key, and that dict will be used as store. All items should specify an initial value in that case.

    If you do not want the validated results to be written back to your store, add the save=False parameter. In that case the store is read only and values specified in the items will override the values in the store.

  • save (bool, optional) – If False, makes the store read-only and gives the values in the items precedence over those in the store. If not provided or True, the store is read-write and will get updated with the validated results. The values in the store have preecence over those in the items.

  • prefix (str, optional) – If specified, the names of the input items will be prefixed with this string in the returned dialog results.

  • autoprefix (bool, optional) – If True, the names of items inside tabs and group boxes will get prefixed with the tab and group names, separated with a ‘/’. The default (False) will just use the specified item name.

  • flat (bool, optional) – If True, the results are returned in a single (flat) dictionary, with keys being the specified or autoprefixed ones. If False, the results will be structured: the value of a tab or a group is a dictionary with the results of its fields. If not provided, its value is set equal to that of autoprefix.

  • scroll (bool, optional) – If True, the input form will be put inside a scroll area, making the form scrollable in case it has so many fields that theyt are not all visible at once on the screen. The default is to no use a scroll area. Some parts of the input form may than fall off the screen and the user has to shift the window to make them accessible. It is better to limit the form size by putting items in multiple columns using hboxes, or in separate pages using tabs.

  • buttonsattop (bool, optional) – If True, the action buttons are put above the input form. If False, they are at the bottom. The default is configured in the user settings.

  • size (tuple (int, int)) – Initial size of the window (width, height) in pixels. The default is automatically defined by the size policies.

returncode

A code depending on how the Dialog was closed. It is generally one of

  • Dialog.ACCEPTED: if the Dialog was accepted.

  • Dialog.REJECTED: if the Dialog was rejected.

  • Dialog.TIMEOUT: if the Dialog timed out.

However, action buttons may finish the Dialog with another return value by calling self.done(returncode).

Type:

int

results

Contains the resulting values of all input fields. With a returncode REJECTED, it is an empty dict. With ACCEPTED, all values will be validated. With TIMEOUT, it contains None values for those fields that were invalid at the time of the timeout. Since the default operation modus is to not use a timeout, the user can just test the results dict, and if it contains anything, it are valid results.

Type:

dict

Examples

See the Input Dialogs.

add_items(form, prefix, items)[source]

Add input items to a form in the Dialog.

Parameters:
  • form (InputForm) – The form to which the items will be added.

  • prefix (str) – A string to be prepended to all item names.

  • items (list of input items) – The items to be put in the form. Each item is normally a dict with the keyword parameters to construct an instance of one of the InputItem subclasses, InputGroup, InputHbox, InputTab. It can however also be a QWidget, allowing highly customizable Dialogs.

add_group(form, prefix, name, items, **kargs)[source]

Add a group of input items.

Parameters:
  • form (InputForm) – The form in which to add the items.

  • prefix (str) – A string to be prepended to all item names.

  • name (str) – Name of the group.

  • items (list of dict) – A list a keyword parameters for constructing InputItems to be put in the group.

  • **kargs (keyword arguments) – Extra arguments passed to the InputGroup initialization.

add_hbox(form, prefix, name, items, newline=False, **kargs)[source]

Add a column with input items.

Parameters:
  • form (InputForm) – The form in which to add the items.

  • prefix (str) – A string to be prepended to all item names.

  • name (str) – Name of the hbox.

  • items (list of dict) – A list a keyword parameters for constructing InputItems to be put in the hbox.

  • **kargs (keyword arguments) – Extra arguments passed to the InputHbox initialization.

add_tab(form, prefix, name, items, **kargs)[source]

Add a Tab page with input items.

Parameters:
  • form (InputForm) – The form in which to add the items.

  • prefix (str) – A string to be prepended to all item names.

  • name (str) – Name of the tab.

  • items (list of dict) – A list a keyword parameters for constructing InputItems to be put in the tab.

  • **kargs (keyword arguments) – Extra arguments passed to the InputTab initialization.

add_input(form, prefix, **item)[source]

Add a single input item to the form.

Parameters:
  • form (InputForm) – The form in which to add the items.

  • prefix (str) – A string to be prepended to all item names.

  • **item – Keyword arguments for the initialization of the InputItem.

static sanitize_value_choices(value=None, choices=[])[source]

Sanitize the value and choices parameters

Make sure that value is one of the choices.

Parameters:
  • value (str, optional) – The initial selection from the choices. If not provided, the first option from choices becomes the value.

  • choices (list | tuple) – An iterable with the valid choices. If value is not in choices, it will be added at the beginning.

Returns:

  • value (str) – The default selected value

  • choices (list) – The list of choices, which is guaranteed to contain value.

Raises:
  • TypeError, if choices is not an iterable,

  • ValueError, if choices is empty and no value is given.

Examples

>>> Dialog.sanitize_value_choices('abc', [])
('abc', ['abc'])
>>> Dialog.sanitize_value_choices('abc', ['def'])
('abc', ['abc', 'def'])
>>> Dialog.sanitize_value_choices('abc', ['def', 'abc'])
('abc', ['def', 'abc'])
>>> Dialog.sanitize_value_choices(choices=['def', 'abc'])
('def', ['def', 'abc'])
updateData(d)[source]

Update a dialog from the data in given dictionary.

This can be used to programmatorically change the data in an already open dialog.

Parameters:

d (dict) – A dictionary where the keys are field names in the dialog. The values will be set in the corresponding input items. The dict does not need to contain all the dialog fields. Keys that are not anmes of input items are silently ignored.

show(*, modal=False, timeout=None, timeoutfunc=None)[source]

Show the dialog.

Parameters:
  • modal (bool) – If True, the Dialog is shown as a modal one, meaning that the user will have to complete (accept or reject) this Dialog before he can continue with other windows. The default is to show a modeless dialog.

  • timeout (int) – Timeout in seconds for the Dialog. If specified and larger that zero, the current data will be accepted automatically (if they can be validated) after the given period. A value 0 will timeout immediately, a negative value will never timeout. There will also be no timeout if the current data contain some invalid item.

validate()[source]

Update the dialog’s return value from the field values.

This function is connected to the ‘accepted()’ signal. Modal dialogs should normally not need to call it. In non-modal dialogs however, you can call it to update the results without having to raise the accepted() signal (which would close the dialog).

Returns:

bool – True if all fields got validated. As a side effect, self.results will then contain the validated results. If some field failed validation, the corresponding result is set to None, and the return value is False.

accept()[source]

Accept the dialog if the results are valid.

This calls validate() to check the current input field values. If all values are valid, they are stored in the results, and the dialog is closed. If there are invalid values, they are flagged in the dialog, and the dialog remains open to let the user fix the problems.

close()[source]

Close the Dialog.

Unregisters the Dialog from the GUI and then closes the Dialog window. If smart_placement is configured, the relative geometry of the window is stored in the user’s settings with the caption as key.

timeout()[source]

Called when the dialog times out.

This validates and stores the results, and then closes the dialog. Unlike accept(), the dialog is always closed, even if some input fields are not valid. In that case the results will contain a value None for the invalid fields.

waitResults()[source]

Wait for the results from an input dialog.

Processes the user interaction with the dialog until the user either rejects the dialog, or accepts the dialog with valid results.

The user can accept the dialog by pressing the OK button or the ENTER key, and reject the dialog with the CANCEL button or the ESC key. On accept, the current input data are validated and if some data is invalid, the accept is refused and a marker is displayed on the invalid field(s).

The result() method can be used to find out how the dialog was ended. Its value will be one of ACCEPTED, REJECTED or TIMEOUT.

getResults(**kargs)[source]

Show the dialog and wait for the results.

Parameters: same as for show(). This is a convenience function calling show() with the provided parameters, and the calls waitResults() and returns the results.

gui.widgets.InputDialog

alias of Dialog

class gui.widgets.ButtonBox(name='', actions=None, parent=None, value=None, choices=[], func=None, icons=None, iconsonly=False, spacing=2, spacer='l', **kargs)[source]

A horizontal box with action buttons.

This creates a horizontal box of push buttons, which each execute some functionality when pushed. The ButtonBox can be created in two ways: using the actions parameter with a list of tuples (text, func, icon), or using three parameters choices, func, icons, where choices and icons are lists, and func is a single function. Thus the following are equivalent:

ButtonBox(actions=[(text1, func1, icon1), (text2, func2, icon2)])
ButtonBox(choices=[text1, text2], func=func, icon=[icon1, icon2])

if the equivalent func would be defined as follows:

def func(id):
    if id == 0:
        func1()
    elif id == 1:
        func2()
Parameters:
  • actions (list of tuples, optional) – Each action is a tuple (text, func, icon) or (text, func) or (text,), where text is the string to be displayed on the button, func is a callable with zero or one positional argument, and icon is an icon name to be displayed on the button. If icon is omitted, the button only shows text. If func is omitted and text is a recognized standard value, a default func is installed (see parent parameter below). If func takes a parameter, it is passed the corresponding QPushButton, from where all details of the ButtonBox can be retrieved. See the func parameter. If the actions parameter is used, the choices, func and icons parameters must not be specified.

  • parent (Dialog or QtWidget.QDialog, optional) – The parent dialog to which the ButtonBox is added. If specified, some default actions are defined for often used button texts:

  • value (str, optional) – The text of the default button. The default button is the button that will be pressed when the user presses ENTER on the keyboard. If not specified, there is no default action.

  • choices (list of str, optional) – The list of strings to appear on the buttons.

  • func (callable, optional) – A function that will be called whenever any of the button is pushed. The function receives the triggering button as parameter. This allows the function to operate depending on the button text and to have access to the button’s parent ButtonBox. See Notes for an example.

  • icons (list of icon names, optional) – A list of strings that specify the icons to be placed on the buttons. A None by be used for buttons not needing an icon.

  • iconsonly (bool, optional) – If True, only icons will be shown on the button, without text. The default False shows both text and icon.

Notes

The following shows a ButtonBox with three buttons. The function prints the button text, but if the ‘close’ button is pressed, it also closes the ButtonBox:

def func(b):
    print(b.text())
    if b.text() == 'close':
         b.parent().close()

box = ButtonBox(choices=('option1', 'option2', 'close), func=func)
box.show()

The equivalent with using the actions parameter would be:

box = ButtonBox(actions=[
    ('option1', func), ('option2', func), ('close', func)])

Note that

Since both ButtonBox and InputPush are implemented as a QButtonGroup with QPushButton elements, it is tempting to merge the two classes. We have not (yet?) done it because in the InputPush the buttons are exclusive, and we use that feature to store and return the value of the set of buttons. Furthermore, the exclusive button group has other focus behavior, unwanted for action buttons (keyboard focus can not be cycled through the different buttons). The ButtonBox therefore has non-exclusive buttons and can not store a value. We could implement this ourselves (remember which button was pushed last) but it is not considered urgent.

setText(text, index=0)[source]

Change the text on button index.

setIcon(icon, index=0)[source]

Change the icon on button index.

checkedId()[source]

Return the number of the checked button

class gui.widgets.ListWidget(maxh=0)[source]

A customized QListWidget with ability to compute its required size.

sizeHint(self) QSize[source]
class gui.widgets.TableModel(data, chead=None, rhead=None, celltype=None, rowtype=None, coltype=None, edit=True, resize=None)[source]

A model representing a two-dimensional array of items.

Parameters:
  • data (array_like) – Any tabular data organized in a fixed number of rows and colums. This means that an item at row i and column j can be addressed as data[i][j]. Thus it can be a list of lists, or a list of tuples or a 2D numpy array. The data will always be returned as a list of lists though. Unless otherwise specified by the use of a celltype, coltype or rowtype argument, all items are converted to strings and will be returned as strings. Item storage order is row by row.

  • chead (list of str, optional) – A list of ncols column headers.

  • rhead (list of str, optional) – A list of nrows row headers.

  • celltype (callable, optional) – A function to tranform the editable string of a cell to the cell data. If specified, and no rowtype nor coltype are specified, each edited item will be translated this function before storing it in the output table. If data is a numpy array, the default is the datatype of the array. Else the default is str.

  • rowtype (list of nrows callables, optional) – If specified, the items of each row are mapped by the corresponding callable. This overrides celltype and is only used if coltype is not specified.

  • coltype (list of ncols callables, optional) – If specified, the items of each column are mapped by the corresponding callable. This overrides celltype and rowtype.

  • edit (bool, optional) – If True (default), the table is editable. Set to False to make the data readonly.

  • resize (bool, optional) – If True, the table can be resized: rows and columns can be added or removed. If False, the size of the table can not be changed. The default value is equal to the value of edit. If coltype is specified, the number of columns can not be changed. If rowtype is specified, the number of rows can not be changed.

See also

ArrayModel

a more efficient but not resizeable model for numpy arrays

makeEditable(edit=True, resize=None)[source]

Make the table editable or not.

  • edit: bool: makes the items in the table editable or not.

  • resize: bool: makes the table resizable or not. If unspecified, it is set equal to the edit.

rowCount(parent=None)[source]

Return number of rows in the table

columnCount(parent=None)[source]

Return number of columns in the table

data(index, role)[source]

Return the data at the specified index

cellType(r, c)[source]

Return the type of the item at the specified position

setCellData(r, c, value)[source]

Set the value of an individual table element.

This changes the stored data, not the interface.

setData(index, value, role=2)[source]

Set the value of an individual table element.

headerData(col, orientation, role)[source]

Return the header data for the sepcified row or column

insertRows(row=None, count=None)[source]

Insert row(s) in table

removeRows(row=None, count=None)[source]

Remove row(s) from table

flags(index)[source]

Return the TableModel flags.

class gui.widgets.ArrayModel(data, chead=None, rhead=None, edit=True)[source]

A model representing a two-dimensional numpy array.

Parameters:
  • data (2D numpy array) – The input data: a 2D int or float numpy array of shape (nrows, ncols).

  • chead (list of str, optional) – A list of ncol column headers. Default will show the column number.

  • rhead (list of str, optional) – A list of nrow row headers. Default will show the row number.

  • edit (bool, optional) – If True (default), the table is editable. Set to False to make the data readonly.

See also

TableModel

a more general (resizable) 2D table model

makeEditable(edit=True)[source]

Make the table editable or not.

  • edit: bool: makes the items in the table editable or not.

rowCount(parent=None)[source]

Return number of rows in the table

columnCount(parent=None)[source]

Return number of columns in the table

data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole) Any[source]
cellType(r, c)[source]

Return the type of the item at the specified position

setData(index, value, role=2)[source]

Set the value of an individual table element.

headerData(col, orientation, role)[source]

Return the header data for the sepcified row or column

flags(index)[source]

Return the TableModel flags.

class gui.widgets.Table(data, *, chead=None, rhead=None, label=None, celltype=None, rowtype=None, coltype=None, edit=True, resize=None, parent=None, autowidth=True)[source]

A widget to show/edit a two-dimensional array of items.

Parameters:
  • data (array_like) –

    A 2-D array of items, with nrow rows and ncol columns.

    If data is a numpy array, the Table will use the ArrayModel: editing the data will directly change the input data array; all items are of the same type; the size of the table can not be changed.

    Else a TableModel is used. Rows and columns can be added to or removed from the table. Item type can be set per row or per column or for the whole table.

  • label (currently unused (intended to display an optional label) – in the upper left corner if both chead and rhead are specified.

  • parent (widget) – The parent widget

  • autowidth (bool) – If True (default), columns are resized to the content width.

  • chead (optional) – Parameters passed to the ArrayModel or TableModel.

  • rhead (optional) – Parameters passed to the ArrayModel or TableModel.

  • delltype (optional) – Parameters passed to the ArrayModel or TableModel.

  • rowtype (optional) – Parameters passed to the ArrayModel or TableModel.

  • edit (optional) – Parameters passed to the ArrayModel or TableModel.

  • resize (optional) – Parameters passed to the ArrayModel or TableModel.

colWidths()[source]

Return the width of the columns in the table

rowHeights()[source]

Return the height of the rows in the table

minimumSizeHint(self) QSize[source]
sizeHint(self) QSize
dataChanged(self, topLeft: QModelIndex, bottomRight: QModelIndex, roles: Iterable[int] = [])[source]
update()[source]

Update the table.

This method should be called to update the widget when the data of the table have changed. If autowidth is True, this will also adjust the column widths.

value()[source]

Return the Table’s value.

class gui.widgets.MessageBox(text, format='', level='info', actions=['OK'], default=None, timeout=None, modal=None, caption=None, parent=None, check=None)[source]

A message box is a widget displaying a short text for the user.

The message box displays a text, an optional icon depending on the level and a number of action buttons.

Parameters:
  • text (str) – the text to be shown. This can be either plain text or html or reStructuredText.

  • format (str) – The text format: either ‘plain’, ‘html’ or ‘rest’. Any other value will trigger automatic recognition. Recognition of plain text and html is automatic. A text is autorecognized to be reStructuredText if its first line starts with ‘..’ (usually followed by a blank line).

  • level (str) – Defines the icon that will be shown together with the text. If one of ‘question’, ‘info’, ‘warning’ or ‘error’, a matching icon will be shown to hint the user about the type of message. Any other value will suppress the icon.

  • actions (list of str) – For each string a pushbutton will be created which can be used to exit the dialog and remove the message. By default there is a single button labeled ‘OK’.

Notes

When the MessageBox is displayed with the getResults() method, a modal dialog is created, i.e. the user will have to click a button or hit the ESC key before he can continue.

If you want a modeless dialog, allowing the user to continue while the message stays open, use the show() method to display it.

addCheck(text)[source]

Add a check field at the bottom of the layout.

show(self)[source]
getResults()[source]

Display the message box and wait for user to click a button.

This will show the message box as a modal dialog, so that the user has to click a button (or hit the ESC key) before he can continue. Returns the text of the button that was clicked or an empty string if ESC was hit.

class gui.widgets.TextBox(text, format=None, actions=[('OK',)], modal=None, parent=None, caption=None, mono=False, timeout=None, flags=None)[source]

Display a text and wait for user response.

Possible choices are ‘OK’ and ‘CANCEL’. The function returns True if the OK button was clicked or ‘ENTER’ was pressed, False if the ‘CANCEL’ button was pressed or ESC was pressed.

class gui.widgets.DropDownToolButton(toolbar, title, items, default)[source]

A toolbar button that drops down a menu

class gui.widgets.ToggleToolButton(toolbar, icons, func, status, checked=False, tooltip='')[source]

A toolbar button that toggles a state.

icons: tuple of two icon names (off, on) func: function that toggles the external state status: function that reports the external state checked: initial state tooltip: toolbar: the toolbar where the button is added

class gui.widgets.CoordsBox(ndim=3, readonly=False, *args)[source]

A widget displaying the coordinates of a point.

getValues()[source]

Return the current x,y,z values as a list of floats.

setValues(values)[source]

Set the three values of the widget.

class gui.widgets.ImageView(image=None, maxheight=None, parent=None)[source]

A widget displaying an image.

showImage(image, maxheight=None)[source]

Show an image in the viewer.

Parameters:

image – Either a filename or an existing QImage instance. If a filename, it should be an image file that can be read by the QImage constructor. Most image formats are understood by QImage. The list of supported formats can be obtained with gui.image.imageFormats() with parameters (‘qt’, ‘r’).

63.2. Functions defined in module gui.widgets

gui.widgets.standardIcon(label)[source]

Load a standard Qt icon.

Parameters:

icon (str) – One of ‘noicon’, ‘info’, ‘warning’, ‘error’, ‘question’. These are the standard icon strings accpted by QtWidgets.QMessageBox.standardIcon.

Returns:

QIcon – A QIcon as used by QtWidgets.QMessageBox, or the input string itself if it is not accepted.

gui.widgets.pyformexIcon(icon)[source]

Load a pyFormex icon.

Parameters:

icon (str) – The basename without extension of one of the image files in the pyformex icons directory. Only .xpm and .png image files are accepted.

Returns:

QIcon – A QIcon with an image loaded from the pyFormex icons directory.

gui.widgets.objSize(object)[source]

Return the width and height of an object.

Parameters:

object – Any object that has width and height methods, for example QWidget instances.

Returns:

  • w (int) – The width of the object

  • h (int) – The height of the object

gui.widgets.maxWinSize()[source]

Return the maximum window size.

The returned size is the maximum size for a window on the screen. This may be smaller than the physical screen size: for example, it may exclude the space for docking panels.

Returns:

  • w (int) – Maximum window width

  • h (int) – Maximum window height

gui.widgets.addTimeOut(widget, timeout=None, timeoutfunc=None)[source]

Add a timeout to a widget.

This enables calling a function or a widget method after a specified time has elapsed.

Parameters:
  • widget (QWidget) – The widget to set the timeout function for.

  • timeout (float, optional) – The time in seconds to wait before calling the timeout function. If None, it will be set to to the global widgets.input_timeout.

  • timeoutfunc (callable, optional) – Function to be called after the widget times out. If None, and the widget has a timeout method, that will be used.

Notes

If timeout is positive, a timer is installed into the widget which will call the timeoutfunc after timeout seconds have elapsed. The timeoutfunc can be any callable, but usually will emit a signal to make the widget accept or reject the input. The timeoutfunc will not be called if the widget is destructed before the timer has finished.

gui.widgets.fileUrls(files)[source]

Transform a list of local file names to urls

gui.widgets.defaultItemType(item)[source]

Guess the InputItem type from the value/choices

gui.widgets.simpleInputItem(name=None, value=None, itemtype=None, **kargs)[source]

A convenience function to create an InputItem dictionary

gui.widgets.groupInputItem(name, items=[], **kargs)[source]

A convenience function to create an InputItem dictionary

gui.widgets.columnInputItem(name, items=[], **kargs)[source]

A convenience function to create an InputItem dictionary

gui.widgets.tabInputItem(name, items=[], **kargs)[source]

A convenience function to create an InputItem dictionary

gui.widgets.selectFont()[source]

Ask the user to select a font.

Shows the QFontDialog widget, offering the user to select a font.

Returns:

QFont | None – A font if the user exited the dialog with the OK button or None if the user clicked CANCEL.

gui.widgets.getColor(col='black', caption='pyFormex Color Selector')[source]

Create a color selection dialog and return the selected color.

col is the initial selection. If a valid color is selected, its string name is returned, usually as a hex #RRGGBB string. If the dialog is canceled, None is returned.

gui.widgets.setCustomColors(col)[source]

Set QColorDialog Custom colors.

col is a list of max. 16 color values (any values accepted by colors.RGBcolor