pylablib.core.gui package¶
Subpackages¶
- pylablib.core.gui.widgets package
- Submodules
- pylablib.core.gui.widgets.button module
- pylablib.core.gui.widgets.combo_box module
- pylablib.core.gui.widgets.container module
- pylablib.core.gui.widgets.edit module
- pylablib.core.gui.widgets.label module
- pylablib.core.gui.widgets.layout_manager module
- pylablib.core.gui.widgets.param_table module
- Module contents
Submodules¶
pylablib.core.gui.formatter module¶
-
pylablib.core.gui.formatter.
parse_float
(s)[source]¶ Parse string as a float, with metric prefixes recognition.
Return tuple
(sign, integer, dot, fractional, exponent, prefix)
, where each entry has structure(begin, end, text)
. ReturnNone
if string is unrecognizable.
-
pylablib.core.gui.formatter.
pos_to_order
(s, pos)[source]¶ For a given string representation of a float and position in the string, get the decimal order for this position.
Return
None
if string is un-parsable or position is out of range (not in mantissa section of the number).
-
pylablib.core.gui.formatter.
order_to_pos
(s, order)[source]¶ For a given string representation of float and decimal order, get the position in the string corresponding to this order.
If order is out of range for a given representation, truncates to most/least significant digit position. Return
None
if string is un-parsable.
-
pylablib.core.gui.formatter.
str_to_float
(s)[source]¶ Return float value of a string, with metric prefixes recognition.
Raise
ValueError
if string is unrecognizable.
-
pylablib.core.gui.formatter.
is_integer
(n, tolerance=0.0)[source]¶ Check if n is less than tolerance away from the nearest integer.
-
pylablib.core.gui.formatter.
float_to_str_SI
(n, digits=3, trailing_zeros=False)[source]¶ Represent float using SI metric prefixes.
For orders
>=27
and<-24
use usual scientific notation with order being multiple of 3. Iftrailing_zeros==True
, then digits define precision, rather than number significant digits
-
class
pylablib.core.gui.formatter.
FloatFormatter
(output_format='auto', digits=3, add_trailing_zeros=True, leading_zeros=0, explicit_sign=False)[source]¶ Bases:
object
Floating point number formatter.
Callable object with takes a number as an argument and returns is string representation.
Parameters: - output_format (str) – can be
"auto"
(use standard Python conversion),"SI"
(use SI prefixes if possible), or"sci"
(scientific “E” notation). - digits (int) – if
add_trailing_zeros==False
, determines the number of significant digits; otherwise, determines precision (number of digits after decimal point). - add_trailing_zeros (bool) – if
True
, always show fixed number of digits after the decimal point, with zero padding if necessary. - leading_zeros (bool) – determines the minimal size of the integer part (before the decimal point) of the number; pads with zeros if necessary.
- explicit_sign (bool) – if
True
, always add explicit plus sign.
- output_format (str) – can be
-
class
pylablib.core.gui.formatter.
IntegerFormatter
[source]¶ Bases:
object
Simple integer number formatter.
Callable object with takes a number as an argument and returns is string representation.
For more flexibility (e.g., adding leading zeros) it is possible to use
FloatFormatter
withdigits=0
andadd_trailing_zeros=True
.
-
class
pylablib.core.gui.formatter.
FmtStringFormatter
(fmt)[source]¶ Bases:
object
Formatter based on format string.
Callable object with takes a number as an argument and returns is string representation.
-
pylablib.core.gui.formatter.
as_formatter
(formatter)[source]¶ Turn an object into a formatter.
Can be a callable object turning value into a string, a string (
"float"
,"int"
, or a format string, e.g.,".5f"
), or a tuple starting with"float"
which contains arguments to theFloatFormatter
.
pylablib.core.gui.limiter module¶
-
exception
pylablib.core.gui.limiter.
LimitError
(value, lower_limit=None, upper_limit=None)[source]¶ Bases:
ArithmeticError
Error raised when the value is out of limits and can’t be coerced
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
pylablib.core.gui.limiter.
NumberLimit
(lower_limit=None, upper_limit=None, action='coerce', value_type=None)[source]¶ Bases:
object
Number limiter, which checks validity of user inputs.
Callable object with takes a number as an argument and either returns its coerced version (or the number itself, if it is within limits), or raises
LimitError
if it should be ignored.Parameters: - lower_limit – lower limit (inclusive), or
None
if there is no limit. - upper_limit – upper limit (inclusive), or
None
if there is no limit. - action (str) – action taken if the number is out of limits; either
"coerce"
(return the closest valid value), or"ignore"
(raiseLimitError
). - value_type (str) – determines value type coercion; can be
None
(do nothing, only check limits),"float"
(cast to float), or"int"
(cast to integer).
- lower_limit – lower limit (inclusive), or
-
pylablib.core.gui.limiter.
filter_limiter
(pred)[source]¶ Turn a predicate into a limiter.
Returns a function that raises
LimitError
if the predicate is false.
-
pylablib.core.gui.limiter.
as_limiter
(limiter)[source]¶ Turn an object into a limiter.
Limiter can be a callable object which takes a single value and either returns a limited value, or raises
LimitError
if it should be ignored; or it can be a tuple(lower, upper, action, value_type)
, wherelower
andupper
are the limits (None
means no limits),action
defines out-of-limit action (either"ignore"
to ignore entered value, or"coerce"
to truncate to the nearest limit), andvalue_type
can beNone
(keep value as is),"float"
(cast value to float),"int"
(cast value to int). If the tuple is shorter, the missing parts are filled by default values(None, None, "ignore", None)
.
pylablib.core.gui.utils module¶
-
pylablib.core.gui.utils.
get_top_parent
(widget)[source]¶ Find the top-level parent (parent which does not have further parents)
-
pylablib.core.gui.utils.
find_layout_element
(layout, element)[source]¶ Find a layout element.
Can be a widget, a sublayout, or a layout element Return item index within the layout. If layout is empty or item is not present, return
None
-
pylablib.core.gui.utils.
delete_layout_item
(layout, idx)[source]¶ Remove and item with the given index (completely delete it)
-
pylablib.core.gui.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.utils.
get_layout_container
(widget, top=None, kind='widget')[source]¶ Find a container widget or layout which contains the given widget.
Note that the container widget does not necessarily correspond to the element parent. If no container could be found, return
None
. If kind can be either"widget"
(return the containing widget), or"layout"
(return the containing layout, which is a layout or sublayout of the containing widget).This method works by traversing the whole layout tree, so it can be relatively slow. top can specify the top container (widget or layout) which definitely contains the given widget; if not specified, use the top-level parent found by
get_top_parent()
.
-
pylablib.core.gui.utils.
get_all_layout_containers
(widget, top=None, kind='widget')[source]¶ Get a list of all widgets or layouts containing the current widget.
The list is arranged from the bottom of the hierarchy (starting from widget) to the top. Note that the container widget does not necessarily correspond to the element parent. If no containers could be found, return
None
. If kind can be either"widget"
(return the containing widgets), or"layout"
(return the containing layouts, which are layouts or sublayouts of the containing widgets.This method works by traversing the whole layout tree, so it can be relatively slow. top can specify the top container (widget or layout) which definitely contains the given widget; if not specified, use the top-level parent found by
get_top_parent()
.
-
pylablib.core.gui.utils.
delete_widget
(widget)[source]¶ Remove widget from its layout container and delete it
-
class
pylablib.core.gui.utils.
TWidgetLocation
(layout, position)¶ Bases:
tuple
-
count
()¶ Return number of occurrences of value.
-
index
()¶ Return first index of value.
Raises ValueError if the value is not present.
-
layout
¶
-
position
¶
-
-
pylablib.core.gui.utils.
get_widget_location
(widget, layout=None)[source]¶ Get location of a widget within the given layout.
Return tuple
(layout, position)
, wherelayout
is the layout object, andposition
is either a single position number (for box layouts), or a tuple(row, col, rowspan, colspan)
for a grid layout. If layout is not specified, autodetect it.
-
pylablib.core.gui.utils.
place_widget_at_location
(widget, location)[source]¶ Insert a widget within the given layout location.
location is a tuple tuple
(layout, position)
, wherelayout
is the layout object, andposition
is either a single position number (for box layouts), or a tuple(row, col, rowspan, colspan)
for a grid layout. The tuple has the same format as returned byget_widget_location()
.
-
pylablib.core.gui.utils.
is_layout_row_empty
(layout, row)[source]¶ Check if the given row in a grid layout is empty
-
pylablib.core.gui.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.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.utils.
insert_layout_row
(layout, row, stretch=0, compress=False)[source]¶ Insert row in a grid layout at a given index.
Any multi-column item spanning over the row (i.e., starting at least one row before row and ending at least one row after row) gets stretched. Anything else either stays in place (if it’s above row), or gets moved one row down. stretch determines the stretch factor of the new row. If
compress==True
, try to find an empty row below the inserted position and shit it to the new row’s place; otherwise, add a completely new row.
-
pylablib.core.gui.utils.
is_layout_column_empty
(layout, col)[source]¶ Check if the given column in a grid layout is empty
-
pylablib.core.gui.utils.
get_last_filled_column
(layout, start_col=0)[source]¶ Find the last non-empty column in a grid layout after start_col (inclusive).
If all rows after (and including) start_col are empty, return
None
.
-
pylablib.core.gui.utils.
get_first_empty_column
(layout, start_col=0)[source]¶ Find the first completely empty column in a grid layout after start_col (inclusive)
-
pylablib.core.gui.utils.
insert_layout_column
(layout, col, stretch=0, compress=False)[source]¶ Insert column in a grid layout at a given index.
Any multi-row item spanning over the column (i.e., starting at least one column before col and ending at least one column after col) gets stretched. Anything else either stays in place (if it’s above col), or gets moved one column to the right. stretch determines the stretch factor of the new column. If
compress==True
, try to find an empty column below the inserted position and shit it to the new column’s place; otherwise, add a completely new column.
-
pylablib.core.gui.utils.
compress_grid_layout
(layout)[source]¶ Find all empty rows in a grid layout and shift them to the bottom
-
pylablib.core.gui.utils.
get_relative_position
(widget, origin=None)[source]¶ Get widget’s position relative to the origin (top-level parent if
None
)
-
pylablib.core.gui.utils.
get_relative_rectangle
(widget, origin=None, border=0, trim_border=True)[source]¶ Get widget rectangle area relative to the origin (top-level parent if
None
).If border is non-zero, it specifies a border (integer or 2-tuple) around the widget to add to the rectangle. If
trim_border==True
, the resulting rectangle is trimmed to lie withing the origin area. ReturnQRect
object.
-
pylablib.core.gui.utils.
get_screenshot
(window=None, rect=None, widget=None, border=0, include_titlebar=True)[source]¶ Take a screenshot of a given window or a given widget.
Either window or widget must be defined. If rect (type
QRect
) or widget are defined, they specify the area to include into screenshot; in this case, border can define an additional border to add to the rectangle. If rectangle is not defined, then include_titlebar specifies whether the window titlebar is included.
pylablib.core.gui.value_handling module¶
Uniform representation of values from different widgets: numerical and text edits and labels, combo and check boxes, buttons.
-
pylablib.core.gui.value_handling.
build_children_tree
(root, types_include, is_atomic=None, is_excluded=None, self_node='#')[source]¶
-
pylablib.core.gui.value_handling.
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
if the widget has at least one method from each of the sets.
-
pylablib.core.gui.value_handling.
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 leastadd_args+1
arguments, and the first one is called"name"
. Otherwise, return"simple"
.
-
exception
pylablib.core.gui.value_handling.
NoParameterError
[source]¶ Bases:
KeyError
Error raised by some handlers to indicate that the parameter is missing
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
pylablib.core.gui.value_handling.
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 notNone
, 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 notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
repr_value
(value, name=None)[source]¶ Return textual representation of the value.
If
name
is notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
connect_value_changed_handler
(handler, only_signal=True)[source]¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
-
class
pylablib.core.gui.value_handling.
VirtualValueHandler
(value=None, multivalued=False)[source]¶ Bases:
pylablib.core.gui.value_handling.IValueHandler
Virtual value handler (to simulate controls which are not present in the GUI).
Parameters: - value – initial value
- multivalued (bool) – if
True
, the internal value is assumed to be complex, so it is forced to be aDictionary
every time it is set.
-
get_value
(name=None)[source]¶ Get widget value.
If
name
is notNone
, 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 notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
class
pylablib.core.gui.value_handling.
PropertyValueHandler
(getter=None, setter=None, default_name=None)[source]¶ Bases:
pylablib.core.gui.value_handling.IValueHandler
Virtual value handler which uses custom getter/setter methods to simulate a value.
If getter or setter are not supplied but are called, they raise
NoParameterError
; this means that they are ignored inGUIValues.get_all_values()
andGUIValues.set_all_values()
methods, but raise an error when access directly (e.g., usingGUIValues.get_value()
).Parameters: - getter – value getter method; takes 0 or 1 (name) arguments and returns the value
- setter – value setter method; takes 1 (value) or 2 (name and value) arguments and sets the value
- default_name (str) – default name to be supplied to
getter
andsetter
methods if they require a name argument
-
get_value
(name=None)[source]¶ Get widget value.
If
name
is notNone
, 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 notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
class
pylablib.core.gui.value_handling.
StandardValueHandler
(widget, default_name=None)[source]¶ Bases:
pylablib.core.gui.value_handling.IValueHandler
Standard value handler, typically used for custom widgets.
To implement getting and setting values, looks for
get/set_value
andget/set_all_values
methods for the widget and uses them accordingly. To implement value representing, looks forrepr_value
method (if not defined, use simple string conversion). To implement value change signal, looks forvalue_changed
widget signal.Parameters: - widget – handled widget
- default_name (str) – default name to be supplied to
get/set_value
andget/set_all_values
methods if they require a name argument.
-
get_value
(name=None)[source]¶ Get widget value.
If
name
is notNone
, 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 notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
repr_value
(value, name=None)[source]¶ Return textual representation of the value.
If
name
is notNone
, it specifies the name of the value parameter inside the widget (for complex widgets).
-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
class
pylablib.core.gui.value_handling.
ISingleValueHandler
(widget)[source]¶ Bases:
pylablib.core.gui.value_handling.IValueHandler
Base class for single-value widget handler, typically used for built-in Qt 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 -
repr_value
(value, name=None)[source]¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
-
class
pylablib.core.gui.value_handling.
LineEditValueHandler
(widget)[source]¶ Bases:
pylablib.core.gui.value_handling.ISingleValueHandler
Value handler for
QLineEdit
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
repr_single_value
(value)¶ Represent the widget value as a string
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
LabelValueHandler
(widget)[source]¶ Bases:
pylablib.core.gui.value_handling.ISingleValueHandler
Value handler for
QLabel
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
repr_single_value
(value)¶ Represent the widget value as a string
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
IBoolValueHandler
(widget, labels=('Off', 'On'))[source]¶ Bases:
pylablib.core.gui.value_handling.ISingleValueHandler
Generic value handler for widgets with boolean values
-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_single_value
()¶ Get the widget value
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_single_value
(value)¶ Set the widget value
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
CheckboxValueHandler
(widget, labels=('Off', 'On'))[source]¶ Bases:
pylablib.core.gui.value_handling.IBoolValueHandler
Value handler for
QCheckBox
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
PushButtonValueHandler
(widget, labels=('Off', 'On'))[source]¶ Bases:
pylablib.core.gui.value_handling.IBoolValueHandler
Value handler for
QPushButton
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
ToolButtonValueHandler
(widget, labels=('Off', 'On'))[source]¶ Bases:
pylablib.core.gui.value_handling.IBoolValueHandler
Value handler for
QToolButton
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
ComboBoxValueHandler
(widget)[source]¶ Bases:
pylablib.core.gui.value_handling.ISingleValueHandler
Value handler for
QComboBox
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
class
pylablib.core.gui.value_handling.
ProgressBarValueHandler
(widget)[source]¶ Bases:
pylablib.core.gui.value_handling.ISingleValueHandler
Value handler for
QProgressBar
widget-
can_set_value
(allow_focus=True)¶ Check if setting value from the code is allowed.
Parameters: focus – if False
, indicates that settings of focused widgets isn’t allowed, with some exceptions (buttons, check boxes, combo boxes)
-
connect_value_changed_handler
(handler, only_signal=True)¶ Connect value changed signal.
If
only_signal==True
, equivalent to connecting a handler function toget_value_changed_signal()
signal; however, ifonly_signal==False
, it also works for some objects (e.g.,QLabel
) don’t have built-in on-changed signals by calling the handler explicitly every time the value is changed.Note that the connection is always direct (i.e., it doesn’t deal with message queues and different threads, but rather directly calls the handler function). If you need to connect a handler to a signal using some other connection method, you can use
get_value_changed_signal()
directly.
-
get_handler
(name=None)¶ Get handler of a contained widget (or same widget, if
name==None
)
-
get_value
(name=None)¶ Get widget value.
If
name
is notNone
raise an error.
-
get_value_changed_signal
()¶ Get the Qt signal emitted when the value is changed
-
repr_single_value
(value)¶ Represent the widget value as a string
-
repr_value
(value, name=None)¶ Return textual representation of the value.
If
name
is notNone
raise an error.
-
set_value
(value, name=None)¶ Set widget value.
If
name
is notNone
raise an error.
-
-
pylablib.core.gui.value_handling.
is_handled_widget
(widget)[source]¶ Check if the widget can be handles by
StandardValueHandler
-
pylablib.core.gui.value_handling.
create_value_handler
(widget)[source]¶ Autodetect value handler for the given widget
-
class
pylablib.core.gui.value_handling.
IIndicatorHandler
[source]¶ Bases:
object
Generic handler of an indicator.
Has methods to get and set the indicator value.
-
pylablib.core.gui.value_handling.
VirtualIndicatorHandler
¶ alias of
pylablib.core.gui.value_handling.VirtualValueHandler
-
class
pylablib.core.gui.value_handling.
StandardIndicatorHandler
(widget, default_name=None)[source]¶ Bases:
pylablib.core.gui.value_handling.IIndicatorHandler
Default indicator handler, typically used for custom widgets.
To implement getting and setting values, looks for
get/set_indicator
andget/set_all_indicators
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.
-
class
pylablib.core.gui.value_handling.
LabelIndicatorHandler
(label, formatter=None, repr_value_name=None)[source]¶ Bases:
pylablib.core.gui.value_handling.IIndicatorHandler
Indicator handler which uses a label to show the value.
Can 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 handler used to represent the value (takes string values)
- formatter – specifies a way to turn values into string representation;
can be a widget handler or a widget (its
repr_func
method is used to represent its value), a function (it takes either a single value argument or two argumentsname
andvalue
and returns string value), orNone
(use simple string conversion) - repr_value_name (str) – default name to be supplied to repr_value if it requires a name argument and name is not supplied
-
pylablib.core.gui.value_handling.
create_indicator_handler
(widget, label=None, require_setter=False)[source]¶ Autodetect indicator handler for the given widget and optional indicator label
-
exception
pylablib.core.gui.value_handling.
MissingGUIHandlerError
[source]¶ Bases:
KeyError
Missing GUI handler
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
pylablib.core.gui.value_handling.
GUIValues
(gui_thread_safe=True)[source]¶ Bases:
object
A collection of values which can be used to manipulate many value handlers at once and represent them as a hierarchical structure.
Has four container-like accessor:
.h
for getting/adding/removing the value handler (i.e.,self.get_handler(name)
is equivalent toself.h[name]
, andself.add_handler(name, handler)
is equivalent toself.h[name]=handler
, andself.remove_handler(name)
is equivalent todel self.h[name]
),.w
for getting the underlying widget (i.e.,self.get_widget(name)
is equivalent toself.w[name]
),.v
for settings/getting values (i.e.,self.get_value(name)
is equivalent toself.v[name]
, andself.set_value(name, value)
is equivalent toself.v[name]=value
),.i
for settings/getting indicator values (i.e.,self.get_indicator(name)
is equivalent toself.i[name]
, andself.set_indicator(name, value)
is equivalent toself.i[name]=value
).vs
for getting the value changed Qt signal (i.e.,self.get_value_changed_signal(name)
is equivalent toself.s[name]
),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
, andupdate_indicators
) are automatically called in the GUI thread.-
remove_handler
(name, remove_indicator=True, disconnect=False)[source]¶ Remove the value handler with a given name.
If
remove_indicator==True
, also try to remove the indicator widget. Ifdisconnect==True
, also disconnect all slots connected to thevalue_changed
signal. Unlike most methods (e.g.,get_value()
orget_handler()
), does not recursively query the children, so it only works if the handler is contained in this table.
-
add_widget
(name, widget, add_indicator=True)[source]¶ Add a widget under a given name (value handler type is auto-detected)
-
add_virtual_element
(name, value=None, multivalued=False, add_indicator=True)[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). The element value is simply stored on set and retrieved on get. If
multivalued==True
, the internal value is assumed to be complex, so it is forced to be aDictionary
every time it is set. Ifadd_indicator==True
, add default indicator handler as well.
-
add_property_element
(name, getter=None, setter=None, add_indicator=True)[source]¶ Add a property value element.
Doesn’t correspond to any actual widget, but behaves very similarly from the application point of view; each time the value is set or get, the corresponding setter and getter methods are called. If
add_indicator==True
, add default (stored value) indicator handler as well.
-
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 values set.
The result is organized as a tree using parent-child relations (note that it implies that only children widgets correspond to tree nodes, i.e., only their values can be get/set).
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 (e.g.,QCheckBox
) to include - types_include – specifies list of widget classes to exclude
- names_exclude – if not
None
, specifies list of widget names to exclude
-
class
IndicatorsSet
(ind)¶ Bases:
tuple
-
count
()¶ Return number of occurrences of value.
-
ind
¶
-
index
()¶ Return first index of value.
Raises ValueError if the value is not present.
-
-
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
isNone
, use widget’sget/set_indicator
orget/set_all_indicators
functions to indicate the value. Otherwise, use the given label to indicate the value (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, formatter=None, ind_name='__default__')[source]¶ Add label-based indicator with a given name.
formatter specifies a way to turn values into string representation; can be a widget handler or a widget (its
repr_func
method is used to represent its value), a function (it takes either a single value argument or two argumentsname
andvalue
and returns string value), orNone
(use simple string conversion) ind_name can distinguish different sub-indicators with the same name, if the same value has multiple indicators.
-
get_value
(name=None)¶ Get a value or a set of values in a subtree under a given name (all values by default).
Automatically handles complex widgets and sub-names. If name refers to a branch, return a
Dictionary
object containing tree structure of the names. If supplied, include and exclude are containers specifying included and excluded names (relative to the root); by default, include everything and exclude nothing.
-
get_all_values
(root=None)[source]¶ Get all values in the given sub-branch.
Same as
get_value()
, but returns an empty dictionary if the name is missing.
-
set_value
(name, value)¶ Set value under a given name.
Automatically handles complex widgets and sub-names
-
get_indicator
(name=None, 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. If supplied, include and exclude are containers specifying included and excluded names (relative to the root); by default, include everything and exclude nothing.
-
get_all_indicators
(root=None, ind_name='__default__')[source]¶ Get all indicator values in the given sub-branch.
Same as
get_indicator()
, but returns an empty dictionary if the root is missing.
-
set_indicator
(name, value, ind_name=None, ignore_missing=False)¶ 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. If supplied, include and exclude are containers specifying included and excluded names (relative to the root); by default, include everything and exclude nothing. If
ignore_missing==True
and the given indicator and sub-indicator names are missing, raise an error; otherwise, do nothing.
-
update_indicators
(root='')¶ Update all indicators in a subtree with the given root (all values by default) to represent current values.
If supplied, include and exclude are containers specifying included and excluded names (relative to the root); by default, include everything and exclude nothing.
-
-
pylablib.core.gui.value_handling.
get_gui_values
(gui_values=None, gui_values_path='')[source]¶ Get new or existing
GUIValues
object and the sub-branch path inside it based on the supplied arguments.If gui_values is
None
or"new"
, create a new object and set empty root path. If gui_values itself hasgui_values
attribute, get this attribute, and prepend object’sgui_values_path
attribute to the given path. Otherwise, assume that gui_values isGUIValues
object, and use the supplied root.