visiannot.tools.pyqt_overlayer¶
Summary¶
Module with sub-classes and functions for GUI creation with PyQt5
See https://pypi.org/project/PyQt5 and https://doc.qt.io/qt-5/reference-overview.html
Data¶
Built-in mutable sequence. |
|
sys.flags |
Classes¶
Subclass of QtWidgets.QComboBox so that key press events are ignored |
|
Subclass of QtWidgets.QPushButton so that key press events are ignored |
|
Subclass of QtWidgets so that wheel events are ignored |
Functions¶
Adds a check box to a grid layout |
|
Creates a group box with a combo box and adds it to a grid layout |
|
Adds a group box to a grid layout |
|
Adds a list of line edits to a layout |
|
Adds a push button to a grid layout |
|
Adds a radio button to a grid layout |
|
Adds a scroll area to a grid layout |
|
Adds a table of spin boxes to an instance of QtWidgets.QGridLayout |
|
Creates a group box with a group of buttons and adds it to a parent layout |
|
Adds a widget to a layout |
|
Creates a window |
|
|
Deletes a specified number of widgets in a grid layout |
Opens a dialog window in order to select a directory |
|
Creates an event loop for a given GUI application, so that the windows do not disappear right after being created |
|
|
Creates a specific event loop for a given window while an event loop is already running, the specific event loop is stopped when the window is closed |
Creates a GUI application for display |
|
Sets the values of a list of lines edits from an input list or returns the values of a table of lines edits |
|
Sets the values of a table of spin boxes from an input list of lists or returns the values of a table of spin boxes |
|
Sets the style sheet for a list of Qt classes in a QApplication |
API¶
Data¶
-
visiannot.tools.pyqt_overlayer.argv= ['/home/docs/checkouts/readthedocs.org/user_builds/visiannot/envs/latest/lib/python3.8/site-packages/sphinx/__main__.py', '-T', '-E', '-b', 'html', '-d', '_build/doctrees', '-D', 'language=en', '.', '_build/html']¶ Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
-
visiannot.tools.pyqt_overlayer.flags= sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0)¶ sys.flags
Flags provided through command line arguments or environment vars.
Class ComboBox¶
-
class
visiannot.tools.pyqt_overlayer.ComboBox[source]¶ Bases:
PyQt5.QtWidgets.QComboBoxSubclass of QtWidgets.QComboBox so that key press events are ignored
Methods:
keyPressEvent(ev)Re-implemented so that key press events are ignored
Class PushButton¶
-
class
visiannot.tools.pyqt_overlayer.PushButton[source]¶ Bases:
PyQt5.QtWidgets.QPushButtonSubclass of QtWidgets.QPushButton so that key press events are ignored
Methods:
keyPressEvent(ev)Re-implemented so that key press events are ignored
Class ScrollArea¶
-
class
visiannot.tools.pyqt_overlayer.ScrollArea[source]¶ Bases:
PyQt5.QtWidgets.QScrollAreaSubclass of QtWidgets so that wheel events are ignored
Methods:
wheelEvent(ev)Re-implemented so that wheel events are ignored
Functions¶
-
visiannot.tools.pyqt_overlayer.add_check_box(layout, position, text, flag_checked=False, color=None)[source]¶ Adds a check box to a grid layout
The method raises an error if the length of position is not 2 or 4.
- Parameters
layout (QtWidgets.QGridLayout) – parent layout where the check box is added
position (tuple of integers) – position of the check box in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)text (str) – text displayed next to the check box
flag_checked (bool) – specify if check box is initially checked
color (tuple) – color in RGB format
- Returns
check box item
- Return type
QtWidgets.QCheckBox
-
visiannot.tools.pyqt_overlayer.add_combo_box(lay, widget_position, item_list, box_title=None, flag_enable_key_interaction=True)[source]¶ Creates a group box with a combo box and adds it to a grid layout
- Parameters
lay (QtWidgets.QGridLayout) – parent layout where the group box is added
widget_position (tuple of integers) – position of the group box in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)item_list (list) – items of the combo box, each element is a string
box_title (str) – title of the group box containing the combo box
flag_enable_key_interaction (bool) – specify if key press interaction is enabled
- Returns
grid (QtWidgets.QGridLayout) – layout filling the group box
group_box (QtWidgets.QGroupBox) – widget added to the parent layout
combo_box (
ComboBoxor QtWidgets.QComboBox) - combo box item
-
visiannot.tools.pyqt_overlayer.add_group_box(layout, position, title='')[source]¶ Adds a group box to a grid layout
Another grid layout is created to fill the group box.
The function raises an error if the length of
positionis not 2 or 4.- Parameters
layout (QtWidgets.QGridLayout) – parent layout where the group box is added
position (tuple of integers) – position of the group box in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)title (str) – group box title
- Returns
grid (QtWidgets.QGridLayout) – layout filling the group box
group_box (QtWidgets.QGroupBox)
-
visiannot.tools.pyqt_overlayer.add_line_edit_list(grid, pos, nb_rows, name='')[source]¶ Adds a list of line edits to a layout
The line edits are contained in an instance of QtWidgets.QGroupBox filled by an instance of QtWidgets.QGridLayout, see
add_group_box().- Parameters
grid (QtWidgets.QGridLayout) – parent layout where the line edits are added
pos (tuple of integers) – position of the group box containing the spin boxes in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)nb_rows (int) – number of rows in the list of line edits
name (str) – name of the group box containing the spin boxes
- Returns
grid_sub – instance of QtWidgets.QGridLayout containing the instances of QLineEdit
goup_box – instance of QtWidgets.QGroupBox containing the instances of QLineEdit
Adds a push button to a grid layout
The function raises an error if the length of
positionis not 2 or 4.- Parameters
layout (QtWidgets.QGridLayout) – parent layout where the push button is added
position (tuple of integers) – position of the button in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)text (str) – text displayed in the push button
width (int) – width of the push button in pixels, set to
0for automaticflag_enable_key_interaction (bool) – specify if key press interaction is enabled
color (tuple) – color in RGB format
- Returns
push button item (instance of QtWidgets.QPushButton or
PushButton)
Adds a radio button to a grid layout
The function raises an error if the length of
positionis not 2 or 4.- Parameters
layout (QtWidgets.QGridLayout) – parent layout where the radio button is added
position (tuple of integers) – position of the button in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)text (str) – text displayed next to the radio button
flag_checked (bool) – specify if button is initially checked
color (tuple) – color in RGB format
- Returns
radio button item
- Return type
QtWidgets.QRadioButton
-
visiannot.tools.pyqt_overlayer.add_scroll_area(layout, position, width=0, height=0, flag_ignore_wheel_event=False)[source]¶ Adds a scroll area to a grid layout
The scroll area is added to the parent layout. A specific layout (instance of QtWidgets.QGridLayout) is created for the scroll area.
- Parameters
layout (QtWidgets.QGridLayout) – parent layout where the scroll area is added
position (tuple of integers) – position of the items in the parent layout to be included in the scroll area, length 2
(row, col)or 4(row, col, rowspan, colspan)width (int or float) – width of the scroll area in pixels, set to
0if automaticheight (int or float) – height of the scroll area in pixels, set to
0if automaticflag_ignore_wheel_event (bool) – specify if wheel event is ignored
- Returns
scroll_lay (QtWidgets.QGridLayout) – layout filling the scroll area
scroll_area (QtWidgets.QScrollArea) – scroll area item
To add a widget to the scroll area, use
scroll_lay.addWidget(widget).
-
visiannot.tools.pyqt_overlayer.add_spin_box_table(grid, pos, nb_rows, nb_cols, name='', params={})[source]¶ Adds a table of spin boxes to an instance of QtWidgets.QGridLayout
The spin boxes are contained in an instance of QtWidgets.QGroupBox filled by an instance of QtWidgets.QGridLayout, see func:.add_group_box.
- Parameters
grid (QtWidgets.QGridLayout) – parent layout where the spin boxes are added
pos (tuple of integers) – position of the group box containing the spin boxes in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)nb_rows (int) – number of rows in the table of spin boxes
nb_cols (int) – number of columns in the table of spin boxes
name (str) – name of the group box containing the spin boxes
params (dict or list) – keyword arguments of the constructor of QtWidgets.QSpinBox (e.g. {“minimum”: 0, “maximum”: 255}), it might be a nested list of length
nb_rowsxnb_colsif the parameters differ from on spin box to another
- Returns
grid_sub – instance of QtWidgets.QGridLayout containing the table of spin boxes
goup_box – instance of QtWidgets.QGroupBox containing the table of spin boxes
Creates a group box with a group of buttons and adds it to a parent layout
The buttons are added in the order of the input label list. It may be eihter a row or a column of buttons (
nb_table == 0), or a table of buttons (nb_table != 0).- Parameters
lay (QtWidgets.QGridLayout) – parent layout where the group box is added
widget_position (tuple of integers) – position of the group box in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)label_list (list) – string labels of the buttons
button_type (str) – type of the buttons (
"radio","push"or"check_box"), in case of"radio"first button is checked, in case of"check_box"exclusivity is set to False and no button is checkedcolor_list (list) – RGB color for each button
box_title (str) – title of the group box containing the radio buttons
flag_horizontal (bool) – specify if buttons are displayed horizontally
nb_table (int) – number of buttons on a single row, set to
0if all buttons on 1 row, if the length oflabel_listis greater thannb_table, then the buttons are added on several rowskwargs – keyword arguments of the funtion that adds the button to the layout filling the group box (
add_radio_button(),add_push_button()oradd_check_box())
- Returns
grid (QtWidgets.QGridLayout) – layout filling the group box
group_box (QtWidgets.QGroupBox) – widget added to the parent layout
group_button (QtWidgets.QButtonGroup) – item containing the buttons
-
visiannot.tools.pyqt_overlayer.add_widget_to_layout(lay, wid, wid_pos)[source]¶ Adds a widget to a layout
an instance of QtWidgets.QGridLayout (or any )
It raises an error if the widget position is not a tuple/list of length 2 or 4.
- Parameters
lay (QtWidgets.QGridLayout) – parent layout where the widget is added (may be any other layout class with a method
addWidget)wid – widget to be added, it must be an instance of a sub-class of QtWidgets.QWidget
wid_pos (tuple of integers) – position of the widget in the parent layout, length 2
(row, col)or 4(row, col, rowspan, colspan)
-
visiannot.tools.pyqt_overlayer.create_window(size=(0, 0), title=None, bg_color=(240, 240, 240), flag_show=True)[source]¶ Creates a window
The geometry of the window can be updated afterward, see http://doc.qt.io/qt-4.8/application-windows.html#window-geometry for details.
If pyqtgraph items are to be added in the window, the background color won’t apply to them. To get the same background color for pyqtgraph items, the following line must be added:
pyqtgraph.setConfigOption('background',color).- Parameters
size (tuple) – size of the window in pixels, length 2
(width, height), set one value to 0 in order to have the window maximized in the corresponding directiontitle (str) – window title
bg_color (tuple or list) – background color of the window, either (RGB) or (RGBA)
flag_show (bool) – specify if the window must be displayed
- Returns
win (QtWidgets.QWidget) – window container
layout (QtWidgets.QGridLayout) – layout filling the window
-
visiannot.tools.pyqt_overlayer.delete_widgets_from_layout(grid, nb_items_to_delete=None)[source]¶ Deletes a specified number of widgets in a grid layout
The widgets are deleted in the inverse order of creation in the layout.
- Parameters
grid (QtWidgets.QGridLayout) – layout where widgets must be deleted
nb_items_to_delete (int) – number of widgets to delete, by default all widgets
-
visiannot.tools.pyqt_overlayer.get_directory_dialog(desc_text='Select directory', dir_root=None)[source]¶ Opens a dialog window in order to select a directory
- Parameters
desc_text (str) – short description text to be displayed as the dialog window title
dir_root (str) – initial directory where to go when launching the dialog window, default current working directory
-
visiannot.tools.pyqt_overlayer.infinite_loop_gui(app)[source]¶ Creates an event loop for a given GUI application, so that the windows do not disappear right after being created
- Parameters
app (QtCore.QCoreApplication or QtWidgets.QApplication) – GUI application
-
visiannot.tools.pyqt_overlayer.infinite_loop_gui_parallel(app, win)[source]¶ Creates a specific event loop for a given window while an event loop is already running, the specific event loop is stopped when the window is closed
- Parameters
app (QtCore.QCoreApplication or QtWidgets.QApplication) – GUI application
win (QtWidgets.QWidget) – window on which the parallel event loop is applied
-
visiannot.tools.pyqt_overlayer.initialize_gui()[source]¶ Creates a GUI application for display
- Returns
instance of QtCore.QCoreApplication or QtWidgets.QApplication
-
visiannot.tools.pyqt_overlayer.set_line_edit_list(grid, value_list, flag_display)[source]¶ Sets the values of a list of lines edits from an input list or returns the values of a table of lines edits
- Parameters
grid (QtWidgets.QGridLayout) – layout containing only the list of lines edits, see
add_line_edit_list()for creating onevalue_list (list) – in case of
flag_displayset toTrue, each element is a string for setting the list of lines edits – otherwise, let it be an empty listflag_display (bool) – specify if displaying values in the list of lines edits
- Returns
list of values contained in the list of lines edits (same as input argument
value_listin case offlag_displayset toTrue)- Return type
list
-
visiannot.tools.pyqt_overlayer.set_spin_box_table(grid, value_list_list, flag_display)[source]¶ Sets the values of a table of spin boxes from an input list of lists or returns the values of a table of spin boxes
- Parameters
grid (QtWidgets.QGridLayout) – layout containing only the table of spin boxes, see
add_spin_box_table()for creating onevalue_list_list (list) – in case of
flag_displayset toTrue, each element is a list of values for setting the table of spin boxes – otherwise, let it be an empty listflag_display (bool) – specify if displaying values in the table of spin boxes
- Returns
each element is a list containing the values in the table of spin boxes (same as input argument
value_list_listin case offlag_displayset toTrue)- Return type
list
-
visiannot.tools.pyqt_overlayer.set_style_sheet(app, font_name, font_size, font_color, qobj_list)[source]¶ Sets the style sheet for a list of Qt classes in a QApplication
- Parameters
app (QtCore.QCoreApplication or QtWidgets.QApplication) – GUI application in which the style sheet must be set
font_name (str) – font name
font_size (int or float) – size of the font in pt
font_color (tuple or list) – color (RGB) of the font
qobj_list (list) – each element is a string of the Qt class on which the style sheet is applied