params_interfaces#

class ChannelUiParameter(tab: QWidget, channel_name: str, *, event_bus: EventBus, name_widget_name: str | None = None, get_view: Callable[[], Mapping[str, Any]] | None = None, apply_patch: Callable[[dict], None] | None = None)[source]#

Bases: UiParameter, ABC

Base class for channel parameters. Each channel parameter is associated with a channel name and a widget in the tab.

abstract property cfg_subtree: List[str]#
property name#
class ChannelsUiParameterCollection(tab: QWidget, *, pipeline_name: str, event_bus: EventBus, get_view: Callable[[], Mapping[str, Any]] | None = None, apply_patch: Callable[[dict], None] | None = None)[source]#

Bases: UiParameterCollection

get(channel, default_value=None)[source]#
items()[source]#
keys()[source]#
values()[source]#
property channel_params#
property channels#
publishes = <ClearMap.Utils.event_bus.Publishes object>#
property relevant_channels#
class EditingFinishedFilter(callback, parent=None)[source]#

Bases: QObject

Emits a callback when a QPlainTextEdit loses focus (≈ editingFinished).

eventFilter(self, a0: Optional[QObject], a1: Optional[QEvent]) bool[source]#

Bases: object

A class to link a widget to a config file. This is the object passed in the params_dict attribute of the UiParameter class. It is used in the __getattr__ and __setattr__ and __connect_widget methods to link the widget to the config file.

Warning

extra_connect needs to return the disconnector function if required.

keys#

The list of keys to access the value in the config file If None, the attribute is not present in the config file and will not be connected

Type:

list(str) (optional)

_widget#

The GUI widget to be connected to the config file

Type:

QWidget

object_name#
Type:

str

default#

The default value to be used if the value is not found in the config file

Type:

Any

connect#

A function to call to do the binding between the widget and the corresponding section of the config file or a boolean to indicate whether the widget should be connected to the config file. If set to True, the widget will be connected automatically by simply updating the value in the config file. For more complex widgets, a function can be passed to handle the connection. Set to False to not connect or connect manually.

Type:

function | bool

add_disconnector(fn: Callable[[], None])[source]#
disconnect_all()[source]#
has_connect_function()[source]#
is_relevant(view)[source]#
cast_from_ui: Callable[[Any], Any] | None#
cast_to_ui: Callable[[Any], Any] | None#
connect: bool#
default: Any | None#
keys: List[str]#
missing_ok: bool#
object_name: str | None#
present_if: Callable[[dict], bool] | None#
scope_root: QWidget | None#
property widget#
class UiParameter(tab: QWidget, *, event_bus: EventBus, get_view: Callable[[], Mapping[str, Any]] | None = None, apply_patch: Callable[[dict], None] | None = None)[source]#

Bases: BusSubscriberMixin

This is a class to link the GUI widgets to the config file. This is done automatically from parsing the params_dict attribute. The params_dict attribute is a dictionary of the form:

{'attr_name': ParamLink(keys, widget, attr_name=, default=, connect=)}
or
{'attr_name': keys,}

where:

  • attr_name is the name of the attribute in the class

  • keys is a list of keys (chain) to access the value in the config file.

If None, the attribute is not connected widget is the GUI widget connect is a boolean to indicate whether the widget should be connected to the config file. Set to False to not connect or connect manually. If the value is not a ParamLink, it is assumed that the keys point to the value and the widget connection is done through accessors and mutators.

tab#

The tab where the widget is located

Type:

QWidget

params_dict#

The dictionary of attributes and their corresponding ParamLink

Type:

Dict[str, ParamLink | List[str]

_cfg_subtree#

The list of keys to access the config file. This allows a relative path to be used from the whole config file.

Type:

List[str]

bind_apply_patch(fn: Callable[[dict], None]) None[source]#

Provide a sink to apply a patch (already scoped to the section).

bind_view_provider(fn: Callable[[], Mapping[str, Any]]) None[source]#

Provide a readonly view of the current section (fresh each call).

build_params_dict() dict[source]#
cfg_to_ui()[source]#
connect()[source]#

Connect GUI slots here

connect_simple_widgets()[source]#
extend_params_dict(extra_param_links: dict[str, ParamLink | list], *, connect_new: bool = True)[source]#

Extend the params_dict with new entries after creation (and potenitally after initaial connexion)

Parameters:
  • extra_param_links (dict[str, ParamLink | list]) – The new entries to add to the params_dict

  • connect_new

Returns

get(item, default_value=None)[source]#
handle_widget_changed(*_, attr_name='', **__)[source]#

Generic handler for simple widgets that binds them to the config file. Calls _emit_patch with the keys obtained from the ParamLink with attr_name and the current value of the attribute. Discards the values of the signal passed by Qt.

Parameters:

attr_name (str) – The name of the attribute in the class

is_simple_attr(key)[source]#
post_connect()[source]#
sanitize_neg_one(val)[source]#

In python, the maximum item (last item) in a list can be accessed with -1. In ClearMap, the maximum is often represented by None. This function is used to do the conversion.

Parameters:

val (int) – The value to be converted

Returns

int or None

The converted value

sanitize_nones(val)[source]#

In python, the maximum item (last item) in a list can be accessed with -1. In ClearMap, the maximum is often represented by None. This function is used to do the conversion.

Parameters:

val (int or None) – The value to be converted

Returns

int

The converted value

sanitize_path_read(val)[source]#
sanitize_path_write(val)[source]#
str_to_capitalize(val)[source]#
str_to_lower(val)[source]#
teardown()[source]#
advanced_controls: List[QWidget]#
property cfg_subtree: List[str]#
tab: QWidget#
property view#
class UiParameterCollection(tab: QWidget, *, pipeline_name: str, event_bus: EventBus, get_view: Callable[[], Mapping[str, Any]] | None = None, apply_patch: Callable[[dict], None] | None = None)[source]#

Bases: BusSubscriberMixin, ABC

For multi-section UiParameters that share the same config file. This ensures the file remains consistent. Although the attributes of contained UiParameters are accessible, it is recommended to first dereference them to avoid clashes.

bind_apply_patch(fn: Callable[[dict], None]) None[source]#

Provide a sink to apply a patch (already scoped to the section).

bind_view_provider(fn: Callable[[], Mapping[str, Any]]) None[source]#

Provide a readonly view of the current section (fresh each call).

cfg_to_ui()[source]#
handle_advanced_state_changed(state)[source]#
pop(channel_name)[source]#
set_painting(painting: bool)[source]#
advanced_controls: List[QWidget]#
cfg_subtree: List[str]#
abstract property params: list[UiParameter]#
property version#
property view#

Bases: ParamLink

cast_sentinel_from_ui(ui_val: Any)[source]#
cast_sentinel_to_ui(cfg_val: Any)[source]#
ensure_list(val)[source]#
equals_disabled_value(val)[source]#
property dtype#
property has_global_toggle#
property n_numbers#
class WidgetOps[source]#

Bases: object

Registry + cache for widget getters/setters/connectors.

connect(widget: QWidget, cb: Callable[[], None]) Callable[[], None] | None[source]#
get(widget: QWidget) Any[source]#
register(cls: Type[QWidget], *, getter: Callable[[QWidget], Any] | None = None, setter: Callable[[QWidget, Any], None] | None = None, connector: Callable[[QWidget, Callable[[], None]], None] | None = None) None[source]#

Register operations for a given widget class. If an operation is None, it will not be registered. This will clear the cache which will be rebuilt on demand.

Parameters:
  • cls (Type[QWidget]) – The widget class to register

  • getter (Getter) – The getter function for the widget class

  • setter (Setter) – The setter function for the widget class

  • connector (Connector) – The connector function for the widget class

resolve(widget: QWidget) Tuple[Callable[[QWidget], Any] | None, Callable[[QWidget, Any], None] | None, Callable[[QWidget, Callable[[], None]], None] | None][source]#

Resolve the operations for a given widget instance. Uses the class of the widget to lookup the operations. This will also use MRO to find the most specific registered operations. Caches the results for faster lookup next time.

Parameters:

widget (QWidget) – The widget instance to resolve the operations for

Returns

OpsTuple

A tuple of (getter, setter, connector) functions or None if not found

set(widget: QWidget, value: Any, *, silent: bool = False) None[source]#
combobox_getter(widget: QComboBox)[source]#
combobox_setter(widget: QComboBox, value)[source]#
connect_frame(widget, callback)[source]#
frame_getter(widget: QFrame)[source]#

For compound objects wrapped in a frame like singlets, doublets and triplets, with or without a checkbox or for text edits with an enable checkbox

frame_setter(widget: QFrame, value)[source]#

For compound objects wrapped in a frame like singlets, doublets and triplets, with or without a checkbox or for text edits with an enable checkbox

identity_op(x)[source]#
invert(x)[source]#
line_edit_getter(widget: QLineEdit)[source]#
list_widget_getter(widget: QListWidget)[source]#
list_widget_setter(widget: QListWidget, itm_list: List[str])[source]#
n_proc_connector(widget: NProcessesWidget, cb)[source]#
n_proc_getter(widget: NProcessesWidget)[source]#
n_proc_setter(widget: NProcessesWidget, value)[source]#

Create a ParamLink for an optional text field. This is a QFrame widgets that contain a text editable (QLineEdit or QPlainTextEdit) and an enable/disable checkbox.

Parameters:
  • keys (List[str]) – The keys for the config

  • widget (QFrame) – The QFrame widget containing the text edit and checkbox

  • disabled_value (Optional[Union[str, None]]) – The value to be used when the widget is disabled. If None, the config value will be None when disabled. If “auto”, the config value will be “auto” when disabled. Default is None.

Returns

ParamLink

The ParamLink object to be used in the params_dict

param_handler(func)[source]#

For handlers/slots that write back to config. If we’re painting, warn (in debug) and skip.

param_setter(func)[source]#

For UiParameter setters that touch widgets. Brackets the setter with self._painting = True/False.