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

class AxisParams(min, max, bin)

Bases: tuple

bin
max
min
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 is None, 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.

get_value()[source]

Get ROI value.

Return tuple (xparams, yparams) of two axes parameters (each is a 3-tuple (min, max, bin)).

set_value(roi, notify_value_change=True)[source]

Set ROI value.

roi is a tuple (xparams, yparams) of two axes parameters (each is a 3-tuple (min, max, bin)). If notify_value_change==True, emit the value_changed signal; otherwise, change value silently.

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)
set_limit(lim)[source]

Set range values limit (2-tuple)

value_changed

Used by autodoc_mock_imports.

get_value()[source]

Get current range value (2-tuple (left, right))

set_value(rng, notify_value_change=True)[source]

Get current range value

rng is a 2-tuple (left, right) If notify_value_change==True, emit the value_changed signal; otherwise, change value silently.

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

get_all_values()[source]

Get all control values

set_all_values(params)[source]

Set all control values

get_all_indicators()[source]

Get all GUI indicators as a dictionary

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
class Rectangle(rect, center=None, size=None)[source]

Bases: object

update_params(center=None, size=None)[source]
setupUi(name, img_size=(1024, 1024), min_size=(512, 512))[source]

Setup the image view.

Parameters:
  • name (str) – widget name
  • img_size (tuple) – default image size (used only until actual image is supplied)
  • min_size (tuple) – minimal widget size
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 a pyqtgraph.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

arm_single()[source]

Arm the single-image trigger

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).

update_rectangles()[source]

Update rectangle coordinates

del_rectangle(name)[source]

Delete a rectangle with a given name

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). If do_redraw==True, force update regardless of the "update_image" button state; otherwise, update only if it is enabled. If only_new_image==True and the image hasn’t changed since the last call to update_image, skip redraw (however, if do_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 underlying pyqtgraph.PlotWidget.plot() method.

delete_trace(name)[source]

Delete trace plot

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. If hide_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).

update_traces(only_new_data=True)[source]

Update displayed traces.

If only_new_data==True and the data hasn’t changed since the last call to update_traces, skip replotting.

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 to self.v[name], and self.set_value(name, value) is equivalent to self.v[name]=value), .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), and .w for getting the underlying widget (i.e., self.get_widget(name) is equivalent to self.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, and update_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 to setupUi()
  • 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_button(name, caption, checkable=False, value=False, label=None, add_indicator=None, location=(None, 0))[source]

Add a button to the table.

Parameters:
  • name (str) – widget name (used to reference its value in the values table)
  • caption (str) – text on the button
  • checkable (bool) – determines whether the button is checkable (has on/off state) or simple press button
  • value (bool) – if checkable, specifies initial value

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:
  • name (str) – widget name (used to reference its value in the values table)
  • caption (str) – text on the checkbox
  • value (bool) – specifies initial value

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:
  • name (str) – widget name (used to reference its value in the values table)
  • value (bool) – specifies initial value

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; see limit.as_limiter() for details
  • formatter (tuple) – either "int" (for integer values), or tuple specifying floating value format; see format.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:
  • name (str) – widget name (used to reference its value in the values table)
  • value (bool) – specifies initial value

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; see limit.as_limiter() for details
  • formatter (tuple) – either "int" (for integer values), or tuple specifying floating value format; see format.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:
  • name (str) – widget name (used to reference its value in the values table)
  • value (bool) – specifies initial value

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:
  • name (str) – widget name (used to reference its value in the values table)
  • value (bool) – specifies initial value
  • options (list) – list of string specifying box options

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

add_padding(prop=1)[source]

Add a padding (expandable spacer) with the given proportion

insert_row(row)[source]

Insert a new table row at the given location

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_handler(name)[source]

Get value handler of a widget with the given name

get_widget(name)[source]

Get a widget with the given name

changed_event(name)[source]

Get a value-changed signal for a widget with the given name

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

clear(disconnect=False)[source]

Clear the table (remove all widgets)

If disconnect==True, also disconnect all slots connected to the value_changed signal.

pylablib.aux_libs.gui.widgets.param_table.TFixedParamTable

alias of pylablib.aux_libs.gui.widgets.param_table.FixedParamTable

pylablib.aux_libs.gui.widgets.param_table.FixedParamTable(v=None, i=None)[source]
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.
get_all_values()[source]

Get all control values

set_all_values(params)[source]

Set all control values

get_all_indicators()[source]

Get all GUI indicators as a dictionary

setup_channels()[source]

Update channels from the associated plotter.

Sets up GUI appearance (dropdown menu items and checkbox rows) to correspond to the trace plotter settings. Called automatically on creation or channels update, doesn’t need to be called explicitly.

get_enabled_channels()[source]

Get a list of enabled channels

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 or TableAccumulatorThread as data sources.

Parameters:parent – parent widget
setupUi(name, add_end_marker=False, update_only_on_visible=True)[source]

Setup the image view.

Parameters:
  • name (str) – widget name
  • add_end_marker (bool) – if True, point markers are added at the position of the last point (makes easier to track plotting progress).
  • update_only_on_visible (bool) – ig True, only update plot if the widget is visible.
setup_channels(channels, channel_indices=None)[source]

Setup and complete plot channels settings (name, color, legend name)

channels is a dictionary {name: params}, where params 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 global end_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 when Reset controller button is pressed.

get_enabled_channels()[source]

Get list of enabled channels and update plot lines if necessary

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 or TableAccumulatorThread 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 to update_plot().

get_data_from_source()[source]

Get data from the default source.

Return dictionary {name: column}.

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.

Module contents