pylablib.aux_libs.gui.widgets package¶
Submodules¶
pylablib.aux_libs.gui.widgets.custom_controls module¶
-
class
pylablib.aux_libs.gui.widgets.custom_controls.
BinROICtl
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Class for ROI control.
Has 2 rows (for X and Y coordinates), each with 3 numerical edits: min, max (or width, depending on
setupUi()
parameters), and bin.Like most widgets, requires calling
setupUi()
to set up before usage.Parameters: parent – parent widget -
value_changed
¶ signal emitted when the ROIvalue is changed
-
validateROI
(xparams, yparams)[source]¶ Restrict current ROI values according to the class constraints
-
setupUi
(name, xlim=(0, None), ylim=None, maxbin=None, minsize=0, maxsize=None, kind='minmax', validate=None)[source]¶ Setup the ROI control.
Parameters: - name (str) – widget name
- xlim (tuple) – limit for x-axis min and max values
- ylim (tuple) – limit for y-axis min and max values
- maxbin (int or tuple) – maximal allowed binning (int imples same for both axes)
- minsize (int or tuple) – minimal allowed size (int imples same for both axes)
- maxsize (int or tuple) – maximal allowed size (int imples same for both axes)
- kind (str) – can be either
"minmax"
(each axis control are min, max, and bin) or"minsize"
(each axis control are min, size and bin) - validate – if not
None
, a function which takes tuple(xparams, yparams)
of two axes parameters (each is a 3-tuple(min, max, bin)
) and return their constrained versions.
-
set_limits
(xlim='keep', ylim='keep', maxbin='keep', minsize='keep', maxsize='keep')[source]¶ Set limits for various parameters.
If value is
"keep"
, keep the current value; if value isNone
, impose no constraints. maxbin, minsize and maxsize can be integers or 2-tuples depending on whether the limits are the same or different for two axes.
-
value_changed
Used by autodoc_mock_imports.
-
-
class
pylablib.aux_libs.gui.widgets.custom_controls.
RangeCtl
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Class for range control.
Can have any subset of 3 rows: specifying min-max, specifying center-span (connected to min-max), and specifying step.
Like most widgets, requires calling
setupUi()
to set up before usage.Parameters: parent – parent widget - Signals:
- value_changed: emitted when the ROIvalue is changed
-
setupUi
(name, lim=(None, None), order=True, formatter='float', labels=('Min', 'Max', 'Center', 'Span', 'Step'), elements=('minmax', 'cspan', 'step'))[source]¶ Setup the range control.
Parameters: - name (str) – widget name
- lim (tuple) – limit containing min and max values
- order (bool) – if
True
, first value is always smaller than the second one (values are swapped otherwise) - formatter (str) – formatter for all edit boxes; see
format.as_formatter()
for details - labels (tuple) – tuple of 5 labels for 5 controls: min, max, center, span, and step (need to always specify 5, even if no all elements are included)
- elements (tuple) – tuple specifying elements which are displayed for the control;
can contain
"minmax"
(min-max row),"cspan"
(center-span row), and"step"
(step row)
-
value_changed
¶ Used by autodoc_mock_imports.
pylablib.aux_libs.gui.widgets.image_plotter module¶
PyQtGraph-based image plotter.
Has 2 parts: ImageView
which displays the image,
and ImageViewController
which controls the image display (value ranges, flipping or transposing, etc.)
ImageView
can also operate alone without a controller.
When both are used, ImageView
is created and set up first, and then supplied to ImageViewController.setupUi()
method.
-
class
pylablib.aux_libs.gui.widgets.image_plotter.
ImageViewController
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Class for controlling an image inside
ImageView
.Like most widgets, requires calling
setupUi()
to set up before usage.Parameters: parent – parent widget -
setupUi
(name, view, display_table=None, display_table_root=None)[source]¶ Setup the image view controller.
Parameters: - name (str) – widget name
- view (ImageView) – controlled image view
- display_table (bool) – as
IndicatorValuesTable
object used to access table values; by default, create one internally - display_table_root (str) – if not
None
, specify root (i.e., path prefix) for values inside the table.
-
set_img_lim
(*args)[source]¶ Set up image limits
Can specify either only upper limit (lower stays the same), or both limits. Value of
None
implies no limit.
-
setup_gui_state
()¶ Enable or disable controls based on which actions are enabled
-
-
class
pylablib.aux_libs.gui.widgets.image_plotter.
ImageView
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Image view object.
Built on top of
pyqtgraph.ImageView
class.Parameters: parent – parent widget -
setupUi
(name, img_size=(1024, 1024), min_size=(512, 512))[source]¶ Setup the image view.
Parameters:
-
set_colormap
(cmap)[source]¶ Setup colormap.
Can be name of one built-in colormaps (
"gray"
,"gray_sat"
,"hot"
,"hot_sat"
), a list specifying PyQtGraph colormap or apyqtgraph.ColorMap
instance.
-
set_binning
(xbin=1, ybin=1, mode='mean', update_image=True)[source]¶ Set image binning (useful for showing large images).
-
set_image
(img)[source]¶ Set the current image.
The image display won’t be updated until
update_image()
is called. This function is thread-safe (i.e., the application state remains consistent if it’s called from another thread, although race conditions on simultaneous calls from multiple threads still might happen).
-
center_lines
()¶ Center coordinate lines
-
set_rectangle
(name, center=None, size=None)[source]¶ Add or change parameters of a rectangle with a given name.
Rectangle coordinates are specified in the original image coordinate system (i.e., rectangles are automatically flipped/transposed/scaled with the image).
-
show_rectangles
(show=True, names=None)[source]¶ Toggle showing rectangles on or off
If names is given, it specifies names of rectangles to show or hide (by default, all rectangles).
-
update_image_controls
()¶ Update image controls in the connected
ImageViewController
object
-
update_image
(update_controls=False, do_redraw=False, only_new_image=True)¶ Update displayed image.
If
update_controls==True
, update control values (such as image min/max values and line positions). Ifdo_redraw==True
, force update regardless of the"update_image"
button state; otherwise, update only if it is enabled. Ifonly_new_image==True
and the image hasn’t changed since the last call toupdate_image
, skip redraw (however, ifdo_redraw==True
, force redrawing regardless).
-
pylablib.aux_libs.gui.widgets.line_plotter module¶
Simple PyQtGraph-based line plotter.
A small expansion on top of pyqtgraph.PlotWidget
which allows for thread-safe plot updating.
-
class
pylablib.aux_libs.gui.widgets.line_plotter.
LinePlotter
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Line plotter object.
Built on top of
pyqtgraph.PlotWidget
class.Parameters: parent – parent widget -
add_trace
(name, caption=None, *args, **kwargs)[source]¶ Add a trace plot.
If caption is not
None
, the trace is also added into the legend under the given caption. All other arguments are passed to the underlyingpyqtgraph.PlotWidget.plot()
method.
-
set_traces
(data, hide_missing=True)[source]¶ Set data to be plotted.
data is a list or a dictionary of 2-column numpy arrays containing x- and y-coordinates of the plots. If it is a list, the columns are assumed to be in the order of their creation (also available as
trace_names
attribute). If it is a dictionary, the keys are the column names. Ifhide_missing==True
and some traces are missing from the data, hide them (although they still appear in the legend); otherwise, the missing traces are left unchanged.This function is thread-safe (i.e., the application state remains consistent if it’s called from another thread, although race conditions on simultaneous calls from multiple threads still might happen).
-
pylablib.aux_libs.gui.widgets.param_table module¶
-
class
pylablib.aux_libs.gui.widgets.param_table.
ParamTable
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
GUI parameter table.
Simplifies creating code-generated controls and displays table layouts.
Has methods for adding various kinds of controls (labels, edit boxes, combo boxes, check boxes), automatically creates values table for easy settings/getting. By default supports 2-column (label-control) and 3-column (label-control-indicator) layout, depending on the parameters given to
setupUi()
.Similar to
IndicatorValuesTable
, has three container-like accessor:.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
), and.w
for getting the underlying widget (i.e.,self.get_widget(name)
is equivalent toself.w[name]
)Like most widgets, requires calling
setupUi()
to set up before usage.Parameters: parent – parent widget -
setupUi
(name, add_indicator=False, display_table=None, display_table_root=None, gui_thread_safe=False)[source]¶ Setup the table.
Parameters: - name (str) – table widget name
- add_indicator (bool) – if
True
, add indicators for all added widgets by default. - display_table (bool) – as
IndicatorValuesTable
object used to access table values; by default, create one internally - display_table_root (str) – if not
None
, specify root (i.e., path prefix) for values inside the table; if not specified, then there’s no additional root for internal table (display_table is None
), or it is equal to name if there is an external table (display_table is not None
) - gui_thread_safe (bool) – if
True
, all value-access and indicator-access calls (get/set_value
,get/set_all_values
,get/set_indicator
, andupdate_indicators
) are automatically called in the GUI thread.
-
value_changed
¶ Used by autodoc_mock_imports.
-
class
ParamRow
(widget, label, value_handler, indicator_handler)¶ Bases:
tuple
-
indicator_handler
¶
-
label
¶
-
value_handler
¶
-
widget
¶
-
-
add_simple_widget
(name, widget, label=None, value_handler=None, add_indicator=None, location=(None, 0))[source]¶ Add a ‘simple’ (single-spaced, single-valued) widget to the table.
Parameters: - name (str) – widget name (used to reference its value in the values table)
- widget – widget to add
- label (str) – if not
None
, specifies label to put in front of the widget in the layout - value_handler – value handler of the widget; by default, use auto-detected value handler (works for many simple built-in or custom widgets)
- add_indicator – if
True
, add an indicator label in the third column and a corresponding indicator handler in the built-in values table; by default, use the default value supplied tosetupUi()
- location (tuple) – tuple
(row, column)
specifying location of the widget (or widget label, if it is specified); by default, add to a new row in the end and into the first column
Return the widget’s value handler
-
add_custom_widget
(name, widget, value_handler=None, indicator_handler=None, location=(None, 0, 1, None))[source]¶ Add a ‘custom’ (multi-spaced, possibly complex-valued) widget to the table.
Parameters: - name (str) – widget name (used to reference its value in the values table)
- widget – widget to add
- value_handler – value handler of the widget; by default, use auto-detected value handler (works for many simple built-in or custom widgets)
- indicator_handler – indicator handler of the widget; by default, use auto-detected indciator handler
(use
set/get_indicator
methods if present, or no indicator otherwises) - location (tuple) – tuple
(row, column, rowspan, colspan)
specifying location of the widget; by default, add to a new row in the end and into the first column, span one row and all table columns
Return the widget’s value handler
-
add_virtual_element
(name, value=None, add_indicator=None)[source]¶ Add a virtual table 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 a button to the table.
Parameters: Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_check_box
(name, caption, value=False, label=None, add_indicator=None, location=(None, 0))[source]¶ Add a checkbox to the table.
Parameters: Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_text_label
(name, value=None, label=None, location=(None, 0))[source]¶ Add a text label to the table.
Parameters: Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_num_label
(name, value=0, limiter=None, formatter=None, label=None, location=(None, 0))[source]¶ Add a numerical label to the table.
Parameters: - name (str) – widget name (used to reference its value in the values table)
- value (float) – specifies initial value
- limiter (tuple) – tuple
(upper_limit, lower_limit, action, value_type)
specifying value limits; seelimit.as_limiter()
for details - formatter (tuple) – either
"int"
(for integer values), or tuple specifying floating value format; seeformat.as_formatter()
for details
Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_text_edit
(name, value=None, label=None, add_indicator=None, location=(None, 0))[source]¶ Add a text edit to the table.
Parameters: Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_num_edit
(name, value=None, limiter=None, formatter=None, label=None, add_indicator=None, location=(None, 0))[source]¶ Add a numerical edit to the table.
Parameters: - name (str) – widget name (used to reference its value in the values table)
- value (bool) – specifies initial value
- limiter (tuple) – tuple
(upper_limit, lower_limit, action, value_type)
specifying value limits; seelimit.as_limiter()
for details - formatter (tuple) – either
"int"
(for integer values), or tuple specifying floating value format; seeformat.as_formatter()
for details
Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_progress_bar
(name, value=None, label=None)[source]¶ Add a progress bar to the table.
Parameters: Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_combo_box
(name, value=None, options=None, label=None, add_indicator=None)[source]¶ Add a combo box to the table.
Parameters: Rest of the arguments and the return value are the same as
add_simple_widget()
.
-
add_spacer
(height, width=1, location=(None, 0))[source]¶ Add a spacer with the given width and height
-
add_label
(text, location=(None, 0))[source]¶ Add a text label (only for decoration) with the given text
-
lock
(names=None, locked=True)[source]¶ Lock (disable) or unlock (enable) widgets with the given names (by default, all widgets)
-
get_value
(name)¶ Get value of a widget with the given name
-
set_value
(name, value)¶ Set value of a widget with the given name
-
get_all_values
()¶ Get values of all widgets in the table
-
set_all_values
(values)¶ Set values of all widgets in the table
-
get_indicator
(name)¶ Get indicator value for a widget with the given name
-
set_indicator
(name, value)¶ Set indicator value for a widget with the given name
-
get_all_indicators
()¶ Get all indicator values
-
update_indicators
()¶ Update all indicators (set their value
-
-
pylablib.aux_libs.gui.widgets.param_table.
TFixedParamTable
¶ alias of
pylablib.aux_libs.gui.widgets.param_table.FixedParamTable
-
class
pylablib.aux_libs.gui.widgets.param_table.
StatusTable
(parent=None)[source]¶ Bases:
pylablib.aux_libs.gui.widgets.param_table.ParamTable
Expansion of
ParamTable
which adds status lines, which automatically subscribe to signals and update values.-
add_status_line
(name, label=None, srcs=None, tags=None, filt=None, make_status=None)[source]¶ Add a status line to the table:
Parameters: - name (str) – widget name (used to reference its value in the values table)
- label (str) – if not
None
, specifies label to put in front of the status line - srcs (list) – status signal sources
- tags (list) – status signal tags
- filt (list) – filter function for the signals
- make_status – if not
None
, specifies a function which takes 3 arguments (signal source, tag, and value) and generates a status line text.
-
pylablib.aux_libs.gui.widgets.trace_plotter module¶
PyQtGraph-based trace plotter.
Has 2 parts: TracePlotter
which displays the plots,
and TracePlotterController
which controls the channels (X-axis, enabled channels) and the plotting (buffer size, updating, etc.)
TracePlotter
can also operate alone without a controller.
When both are used, TracePlotter
is created and set up first, and then supplied to TracePlotterController.setupUi()
method.
-
class
pylablib.aux_libs.gui.widgets.trace_plotter.
TracePlotterController
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Class for controlling traces inside
TracePlotter
.Like most widgets, requires calling
setupUi()
to set up before usage.Parameters: parent – parent widget -
setupUi
(name, plotter, display_table=None, display_table_root=None)[source]¶ Setup the trace plotter controller.
Parameters: - name (str) – widget name
- plotter (TracePlotter) – controlled image plotter
- display_table (bool) – as
IndicatorValuesTable
object used to access table values; by default, create one internally - display_table_root (str) – if not
None
, specify root (i.e., path prefix) for values inside the table.
-
-
class
pylablib.aux_libs.gui.widgets.trace_plotter.
TracePlotter
(parent=None)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Trace plotter object.
Built on top of
pyqtgraph.PlotWidget
class.Intended for plotting of gradually-accumulated data; designed to work tightly with
TableAccumulator
orTableAccumulatorThread
as data sources.Parameters: parent – parent widget -
setupUi
(name, add_end_marker=False, update_only_on_visible=True)[source]¶ Setup the image view.
Parameters:
-
setup_channels
(channels, channel_indices=None)[source]¶ Setup and complete plot channels settings (name, color, legend name)
channels is a dictionary
{name: params}
, whereparams
is a parameter dictionary with the following possible keys:"name"
- channel name used in the controller GUI;"legend_name"
- channel name used in the plotting window (legend and x-axis label);"color"
- channel plot color;"end_marker"
- overrides globalend_marker
property of the plotter;"factor"
- rescaling factor applied before plotting.
-
on_reset
¶ Used by autodoc_mock_imports.
-
reset_history
()¶ Reset plot history.
Reset source (if specified) and emits
on_reset
signal. Automatically called whenReset
controller button is pressed.
-
get_required_channels
()[source]¶ Get list of channels required for plotting: all enabled channels plus ‘X axis’ and ‘Order by’ channels
-
get_data_from_accum
(table_accum)[source]¶ Get data from the table accumulator, taking selected channels into account
Return dictionary
{name: column}
.
-
get_data_from_accum_thread
(table_accum_thread)[source]¶ Get data from the table accumulator thread, taking selected channels into account
Return dictionary
{name: column}
.
-
setup_data_source
(src=None)[source]¶ Setup data source.
Add a data source (
TableAccumulator
orTableAccumulatorThread
instance used as a source of data for channels). The source is used to automatically grab channel data and receive reset commands. Not necessary, if the data is provided explicitly toupdate_plot()
.
-
update_plot
(data=None, idx_column=None)[source]¶ Update plot data.
Parameters: - data – dictionary
{name: column}
with the data. Should contain all selected channel and channels used for x-axis and order. if not supplied, can be grabbed automatically from the default data source (if supplied). - idx_column – name of the default index column; if the “order by” column name is the same as idx_column, no data re-ordering is performed. doesn’t need to be supplied, but can improve plotting speed somewhat.
- data – dictionary
-