UI

lantz.ui.widgets

Implements UI widgets based on Qt widgets. To achieve functionality, instances of QtWidgets are patched.

copyright:2015 by Lantz Authors, see AUTHORS for more details.
license:BSD, see LICENSE for more details.
class lantz.ui.widgets.ChildrenWidgets(parent)[source]

Convenience class to iterate children.

Parameters:parent – parent widget.
class lantz.ui.widgets.FeatWidget[source]

Widget to show a Feat.

class lantz.ui.widgets.WidgetMixin[source]

Mixin class to provide extra functionality to QWidget derived controls.

Derived class must override _WRAPPED to indicate with which classes it can be mixed.

To wrap an existing widget object use:

>>> widget = QComboBox()
>>> WidgetMixin.wrap(widget)

If you want lantz to provide an appropriate wrapped widget for a given feat:

>>> widget = WidgetMixin.from_feat(feat)

In any case, after wrapping a widget you need to bind it to a feat:

>>> feat = driver.feats[feat_name]
>>> widget.bind_feat(feat)

Finally, you need to

>>> widget.lantz_target = driver
classmethod from_feat(feat, parent=None)[source]

Return a widget appropriate to represent a lantz feature.

Parameters:
  • feat – a lantz feature proxy, the result of inst.feats[feat_name].
  • parent – parent widget.
keyPressEvent(event)[source]

When ‘u’ is pressed, request new units. When ‘r’ is pressed, get new value from the driver.

on_feat_value_changed(value, old_value=MISSING, other=MISSING)[source]

When the driver value is changed, update the widget if necessary.

on_widget_value_changed(value, old_value=MISSING, other=MISSING)[source]

When the widget is changed by the user, update the driver with the new value.

setReadOnly(value)[source]

Set read only s

setValue(value)[source]

Set widget value.

value()[source]

Get widget value.

value_from_feat()[source]

Update the widget value with the current Feat value of the driver.

value_to_feat()[source]

Update the Feat value of the driver with the widget value.

feat_key

Key associated with the DictFeat.

lantz_target

Driver connected to the widget.

readable

If the Feat associated with the widget can be read (get).

writable

If the Feat associated with the widget can be written (set).

lantz.ui.widgets.connect_driver(parent, target, *, prefix='', sep='__')[source]

Connect all children widgets to their corresponding lantz feature matching by name. Non-matching names are ignored.

Parameters:
  • parent – parent widget.
  • target – the driver.
  • prefix – prefix to be prepended to the lantz feature (default = ‘’)
  • sep – separator between prefix, name and suffix
lantz.ui.widgets.connect_feat(widget, target, feat_name=None, feat_key=MISSING)[source]

Connect a feature from a given driver to a widget. Calling this function also patches the widget is necessary.

If applied two times with the same widget, it will connect to the target provided in the second call. This behaviour can be useful to change the connection target without rebuilding the whole UI. Alternative, after connect has been called the first time, widget will have a property lantz_target that can be used to achieve the same thing.

Parameters:
  • widget – widget instance.
  • target – driver instance.
  • feat_name – feature name. If None, connect using widget name.
  • feat_key – For a DictFeat, this defines which key to show.
lantz.ui.widgets.connect_setup(parent, targets, *, prefix=None, sep='__')[source]

Connect all children widget to their corresponding

Parameters:
  • parent – parent widget.
  • targets – iterable of drivers.
  • prefix – prefix to be prepended to the lantz feature name if None, the driver name will be used (default) if it is a dict, the driver name will be used to obtain he prefix.
lantz.ui.widgets.initialize_and_report(widget, drivers, register_finalizer=True, initializing_msg='Initializing ...', initialized_msg='Initialized', concurrent=True, dependencies=None)[source]

Initialize drivers while reporting the status in a QtWidget.

Parameters:
  • widget – Qt Widget where the status information is going to be shown.
  • drivers – iterable of drivers to initialize.
  • register_finalizer – register driver.finalize method to be called at python exit.
  • initializing_msg – message to be displayed while initializing.
  • initialized_msg – message to be displayed after successful initialization.
  • concurrent – indicates that drivers with satisfied dependencies should be initialized concurrently.
  • dependencies – indicates which drivers depend on others to be initialized. each key is a driver name, and the corresponding value is an iterable with its dependencies.
Returns:

the QThread doing the initialization.

lantz.ui.widgets.register_wrapper(cls)[source]

Register a class as lantz wrapper for QWidget subclasses.

The class must contain a field (_WRAPPERS) with a tuple of the QWidget subclasses that it wraps.

lantz.ui.widgets.request_new_units(current_units)[source]

Ask for new units using a dialog box and return them.

Parameters:current_units (Quantity) – current units or magnitude.