pylablib.core.gui.qt package

Submodules

pylablib.core.gui.qt.utils module

pylablib.core.gui.qt.utils.delete_layout_item(layout, idx)[source]

Remove and item with the given index (completely delete it)

pylablib.core.gui.qt.utils.clean_layout(layout, delete_layout=False)[source]

Delete all items from the layout.

If delete_layout==True, delete the layout as well.

pylablib.core.gui.qt.utils.is_layout_row_empty(layout, row)[source]

Check if the given row in a grid layout is empty

pylablib.core.gui.qt.utils.get_last_filled_row(layout, start_row=0)[source]

Find the last non-empty row in a grid layout after start_row (inclusive).

If all rows after (and including) start_row are empty, return None .

pylablib.core.gui.qt.utils.get_first_empty_row(layout, start_row=0)[source]

Find the first completely empty row in a grid layout after start_row (inclusive)

pylablib.core.gui.qt.utils.insert_layout_row(layout, row)[source]

Insert row in a grid layout at a given tow index.

Any multi-column item spanning over the row (i.e., starting at least one row before row and ending at least on row after row) gets stretched. Anything else either stays in place (if it’s above row), or gets moved one row down.

pylablib.core.gui.qt.utils.compress_grid_layout(layout)[source]

Find all empty rows in a grid layout and shift them to the bottom

pylablib.core.gui.qt.values module

Uniform representation of values from different widgets: numerical and text edits and labels, combo and check boxes, buttons.

pylablib.core.gui.qt.values.build_children_tree(root, types_include, is_atomic=None, is_excluded=None, self_node='#')[source]
pylablib.core.gui.qt.values.has_methods(widget, methods_sets)[source]

Chick if the widget has methods from given set.

methods_sets is a list of method sets. The function returns True iff the widget has at least one method from each of the sets.

pylablib.core.gui.qt.values.get_method_kind(method, add_args=0)[source]

Determine whether the method takes name as its argument

add_args specifies number of additional required arguments. Return "named" is the method has at least add_args+1 arguments, and the first one is called "name". Otherwise, return "simple".

class pylablib.core.gui.qt.values.IValueHandler(widget)[source]

Bases: object

Generic handler of a widget value.

Has method to get and set the value (or all values, if the widget has internal value structure), representing values as strings, and value changed signal.

Parameters:widget – handled widget.
get_value(name=None)[source]

Get widget value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

get_all_values()[source]

Get all values of the widget.

Return widget value for simple widgets, or a dictionary of all internal values for complex widgets.

set_value(value, name=None)[source]

Set widget value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

set_all_values(value)[source]

Set all values of the widget.

value is a target value for simple widgets, or a dictionary of values for complex widgets.

repr_value(value, name=None)[source]

Return textual representation of the value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

class pylablib.core.gui.qt.values.VirtualValueHandler(value=None, complex_value=False)[source]

Bases: pylablib.core.gui.qt.values.IValueHandler

Virtual value handler (to simulate controls which are not present in the GUI).

Parameters:
  • value – initial value
  • complex_value (bool) – if True, the internal value is assumed to be complex, so it is forced to be a Dictionary.
get_value(name=None)[source]

Get widget value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

set_value(value, name=None)[source]

Set widget value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

class pylablib.core.gui.qt.values.IDefaultValueHandler(widget, default_name=None)[source]

Bases: pylablib.core.gui.qt.values.IValueHandler

Default value handler, typically used for custom widgets.

To implement getting and setting values, looks for get/set_value and get/set_all_values methods for the widget and uses them accordingly.

Parameters:
  • widget – handled widget
  • default_name (str) – default name to be supplied to get/set_value and get/set_all_values methods if they require a name argument.
get_value(name=None)[source]

Get widget value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

get_all_values()[source]

Get all values of the widget.

Return widget value for simple widgets, or a dictionary of all internal values for complex widgets.

set_value(value, name=None)[source]

Set widget value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

set_all_values(value)[source]

Set all values of the widget.

value is a target value for simple widgets, or a dictionary of values for complex widgets.

repr_value(value, name=None)[source]

Return textual representation of the value.

If name is not None, it specifies the name of the value parameter inside the widget (for complex widgets).

class pylablib.core.gui.qt.values.ISingleValueHandler(widget)[source]

Bases: pylablib.core.gui.qt.values.IValueHandler

Base class for single-value widget handler, typically used for built-in pyQt widgets.

Defines new functions get/set_single_value which don’t take a name argument; raises an error if the name is supplied to any of the standard functions.

Parameters:widget – handled widget
get_single_value()[source]

Get the widget value

get_value(name=None)[source]

Get widget value.

If name is not None raise an error.

set_single_value(value)[source]

Set the widget value

set_value(value, name=None)[source]

Set widget value.

If name is not None raise an error.

repr_single_value(value)[source]

Represent the widget value as a string

repr_value(value, name=None)[source]

Return textual representation of the value.

If name is not None raise an error.

class pylablib.core.gui.qt.values.LineEditValueHandler(widget)[source]

Bases: pylablib.core.gui.qt.values.ISingleValueHandler

Value handler for QLineEdit widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

class pylablib.core.gui.qt.values.LabelValueHandler(widget)[source]

Bases: pylablib.core.gui.qt.values.ISingleValueHandler

Value handler for QLabel widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

class pylablib.core.gui.qt.values.IBoolValueHandler(widget, labels=('Off', 'On'))[source]

Bases: pylablib.core.gui.qt.values.ISingleValueHandler

Generic value handler for widgets with boolean values

repr_single_value(value)[source]

Represent the widget value as a string

class pylablib.core.gui.qt.values.CheckboxValueHandler(widget, labels=('Off', 'On'))[source]

Bases: pylablib.core.gui.qt.values.IBoolValueHandler

Value handler for QCheckBox widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

class pylablib.core.gui.qt.values.PushButtonValueHandler(widget, labels=('Off', 'On'))[source]

Bases: pylablib.core.gui.qt.values.IBoolValueHandler

Value handler for QPushButton widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

repr_single_value(value)[source]

Represent the widget value as a string

class pylablib.core.gui.qt.values.ToolButtonValueHandler(widget, labels=('Off', 'On'))[source]

Bases: pylablib.core.gui.qt.values.IBoolValueHandler

Value handler for QToolButton widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

repr_single_value(value)[source]

Represent the widget value as a string

class pylablib.core.gui.qt.values.ComboBoxValueHandler(widget)[source]

Bases: pylablib.core.gui.qt.values.ISingleValueHandler

Value handler for QComboBox widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

value_changed_signal()[source]

Get the pyQt signal emitted when the value is changed.

repr_single_value(value)[source]

Represent the widget value as a string

class pylablib.core.gui.qt.values.ProgressBarValueHandler(widget)[source]

Bases: pylablib.core.gui.qt.values.ISingleValueHandler

Value handler for QProgressBar widget

get_single_value()[source]

Get the widget value

set_single_value(value)[source]

Set the widget value

pylablib.core.gui.qt.values.is_handled_widget(widget)[source]

Check if the widget can be handles by IDefaultValueHandler

pylablib.core.gui.qt.values.get_default_value_handler(widget)[source]

Autodetect value handler for the given widget

class pylablib.core.gui.qt.values.ValuesTable(gui_thread_safe=False)[source]

Bases: object

A table of values which can be used to manipulate many value handlers at once and represent them as a hierarchical structure.

Has two container-like accessor: .v for settings/getting values (i.e., self.get_value(name) is equivalent to self.v[name], and self.set_value(name, value) is equivalent to self.v[name]=value) and .w for getting the underlying widget (i.e., self.get_widget(name) is equivalent to self.w[name])

Parameters:gui_thread_safe (bool) – if True, all value-access calls (get/set_value, get/set_all_values) are automatically called in the GUI thread.
add_handler(name, handler)[source]

Add a value handler under a given name

remove_handler(name)[source]

Remove the value handler with a given name

get_handler(name)[source]

Get the value hander with the given name

add_widget(name, widget)[source]

Add a widget under a given name (value handler type is auto-detected)

get_widget(name)[source]

Get the widget corresponding to the handler under the given name

add_table(name, table)[source]

Add a nested ValuesTable under a given name

add_virtual_element(name, value=None)[source]

Add a virtual value element.

Doesn’t correspond to any actual widget, but behaves very similarly from the application point of view (its value can be set or read, it has on-change events, it can have indicator).

add_all_children(root, root_name=None, types_include=None, types_exclude=(), names_exclude=None)[source]

Add a widget and all its children to the table.

Parameters:
  • root – root widget
  • root_name – path to the sub-branch where the values will be placed
  • types_include – if not None, specifies list of widget classes to include in the table
  • types_include – specifies list of widget classes to exclude from the table
  • names_exclude – if not None, specifies list of widget names to exclude from the table
get_value(name)

Get value under a given name.

Automatically handles complex widgets and sub-names

get_all_values(root='', include=None)

Get all values in a subtree with the given root (all table values by default).

If supplied, include is a container specifies which specifies names (relative to the root) to include in the result; by default, include everything. Return a Dictionary object containing tree structure of the names.

set_value(name, value)

Set value under a given name.

Automatically handles complex widgets and sub-names

set_all_values(values, root='', include=None)

Set all values in a subtree with the given root (all table values by default).

values is a dictionary with values (can only contain some values out of the ones the table). If supplied, include is a container specifies which specifies names (relative to the root) to include in the result; by default, include everything.

repr_value(name, value)[source]

Get a textual representation of a value under a given name.

Automatically handles complex widgets and sub-names

changed_event(name)[source]

Get changed events for a value under a given name.

update_value(name)[source]

Send update signal for a handler with a given name (emit a changed signal with the current value)

class pylablib.core.gui.qt.values.IIndicatorHandler[source]

Bases: object

Generic handler of an indicator.

Has methods to get and set the indicator value.

get_value(name=None)[source]

Get indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

set_value(value, name=None)[source]

Set indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

pylablib.core.gui.qt.values.VirtualIndicatorHandler

alias of pylablib.core.gui.qt.values.VirtualValueHandler

class pylablib.core.gui.qt.values.IDefaultIndicatorHandler(widget, default_name=None)[source]

Bases: pylablib.core.gui.qt.values.IIndicatorHandler

Default indicator handler, typically used for custom widgets.

To implement getting and setting values, looks for get/set_indicator methods for the widget and uses them accordingly.

Parameters:
  • widget – handled widget
  • default_name (str) – default name to be supplied to get/set_indicator methods if they require a name argument.
get_value(name=None)[source]

Get indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

set_value(value, name=None)[source]

Set indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

class pylablib.core.gui.qt.values.FuncLabelIndicatorHandler(label, repr_func=None, repr_value_name=None)[source]

Bases: pylablib.core.gui.qt.values.IIndicatorHandler

Indicator handler which uses a label to show the value.

To takes optional function which converts values into strings (by default, use the standard string conversion).

Parameters:
  • label – widget or value hander used to represent the value (takes string values)
  • repr_func – if not None, specifies function used to convert values into strings
  • repr_value_name (str) – default name to be supplied to repr_func if it requires a name argument and name is not supplied.
get_value(name=None)[source]

Get indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

repr_value(value, name=None)[source]

Represent a value with a given name

set_value(value, name=None)[source]

Set indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

class pylablib.core.gui.qt.values.WidgetLabelIndicatorHandler(label, widget=None, repr_value_name=None)[source]

Bases: pylablib.core.gui.qt.values.IIndicatorHandler

Indicator handler which uses a label to show the value.

To takes optional widget or widget handler which converts values into strings using its repr_value method (by default, use the standard string conversion).

Parameters:
  • label – widget or value hander used to represent the value (takes string values)
  • widget – if not None, specifies widget used to convert values into strings
  • repr_value_name (str) – default name to be supplied to repr_value if it requires a name argument and name is not supplied.
get_value(name=None)[source]

Get indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

repr_value(value, name=None)[source]

Represent a value with a given name

set_value(value, name=None)[source]

Set indicator value.

If name is not None, it specifies the name of the indicator parameter inside the widget (for complex widgets).

pylablib.core.gui.qt.values.get_default_indicator_handler(widget, label=None, require_setter=False)[source]

Autodetect indicator handler for the given widget and label

class pylablib.core.gui.qt.values.IndicatorValuesTable(gui_thread_safe=False)[source]

Bases: pylablib.core.gui.qt.values.ValuesTable

A table of values which can also handle indicators. Inherits ValuesTable

Has an additional container-like accessor .i for settings/getting indicator values (i.e., self.get_indicator(name) is equivalent to self.i[name], and self.set_indicator(name, value) is equivalent to self.i[name]=value)

Parameters:gui_thread_safe (bool) – if True, all value-access and indicator-access calls (get/set_value, get/set_all_values, get/set_indicator, get/set_all_indicators, and update_indicators) are automatically called in the GUI thread.
add_indicator_handler(name, handler, ind_name='__default__')[source]

Add indicator handler with a given name.

ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators.

remove_indicator_handler(name, ind_name=None)[source]

Remove indicator handler with a given name.

ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators. By default, remove all indicators with this name

add_widget_indicator(name, widget, label=None, ind_name='__default__')[source]

Add widget-based indicator with a given name.

If label is None, use widget’s set_indicator and get_indicator functions to indicate the value. Otherwise, use WidgetLabelIndicatorHandler with the given label (label is used to show the value, widget is used to represent it). ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators.

add_label_indicator(name, label, repr_func=None, ind_name='__default__')[source]

Add label-based indicator with a given name.

repr_func can specify representation function which turns values into text. ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators.

add_widget(name, widget)[source]

Add a widget under a given name (value handler type is auto-detected)

add_virtual_element(name, value=None)[source]

Add a virtual value element.

Doesn’t correspond to any actual widget, but behaves very similarly from the application point of view (its value can be set or read, it has on-change events, it can have indicator).

add_table(name, table)[source]

Add a nested ValuesTable under a given name

get_indicator(name, ind_name='__default__')

Get indicator value with a given name.

ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators.

get_all_indicators(root='', ind_name='__default__', include=None)

Get all indicator values in a subtree with the given root (all table values by default).

ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators. If supplied, include is a container specifies which specifies names (relative to the root) to include in the result; by default, include everything. Return a Dictionary object containing tree structure of the names.

set_indicator(name, value, ind_name=None)

Set indicator value with a given name.

ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators. By default, set all sub-indicators to the given value.

set_all_indicators(values, root='', include=None)

Set all indicator values in a subtree with the given root (all table values by default).

values is a dictionary with indicated values (can only contain some values out of the ones the table). If supplied, include is a container specifies which specifies names (relative to the root) to include in the result; by default, include everything.

update_indicators(root='', include=None)

Update all indicators in a subtree with the given root (all table values by default) to represent current values. If supplied, include is a container specifies which specifies names (relative to the root) to include in the result; by default, include everything.

Module contents