Plugins

pydetecdiv.plugins

Generic classes to discover and handle plugins

class pydetecdiv.plugins.Plugin

Bases: object

Generic class defining common Plugin attributes and methods

update_parameters(groups: list[str] | str = None) None

Update the parameters in the provided list of group names

Parameters:

groups – the list of group names or single group name

register() None

Abstract method to register the plugin. This method should be implemented by all plugins for them to work.

addActions(menu: QMenu) None

Method to add an action to a menu. This action triggers the launch method. If a submenu needs to be implemented or if arguments need to be passed to the launch method, this method may be overriden

Parameters:

menu – the menu to add actions to

launch() None

Abstract method that needs to be implemented in each concrete Plugin implementation to launch the plugin (with or without a GUI)

property parent_plugin: Self

return the parent plugin of the current plugin. This may be used to add functionalities to plugins without having to modify the original code

Returns:

None or the parent plugin

save_run(project: Project, method: str, parameters: dict[str, object]) Run

Save the current Run

Parameters:
  • project – the current project

  • method – the plugin method that was executed for the current run

  • parameters – the parameters that were passed to the method

Returns:

the saved Run instance

class pydetecdiv.plugins.PluginList

Bases: object

Class to create and handle list of discovered plugins

property plugins: ValuesView[Plugin]

return the list of available plugins

Returns:

the list of available plugins

load() None

Discover plugins and load them in plugin list

load_plugin(finder, name: str) Plugin | None

Load a plugin given a finder and its module name

Parameters:
  • finder – the module finder

  • name – the module name

Returns:

the plugin module

register_all() None

Register plugins

property len: int

The number of discovered plugins

Returns:

how many plugins have been discovered

pydetecdiv.plugins.gui

Module defining widgets and other utilities for creating windows/forms with a minimum of code

class pydetecdiv.plugins.gui.StyleSheets

Bases: object

Style sheets for the widgets

class pydetecdiv.plugins.gui.GroupBox(parent: QWidget, title: str = None)

Bases: QGroupBox

an extension of QGroupBox class

property plugin: Plugin | None

Property returning the plugin from the top parent of the current widget

Returns:

the plugin module or None if it was not found

addSubBox(widget: Type[Self], **kwargs: dict[str, Any]) Self

Adds a sub-box to the current GroupBox

Parameters:
  • widget – the class of the GroupBox to add as a sub box

  • kwargs – keywords arguments to pass to the sub box

Returns:

the sub box object

addOption(label: str = None, widget: Type[QWidget] = None, parameter: Parameter = None, enabled: bool = True, **kwargs: dict[str, Any]) QWidget

add an option to the current Form

Parameters:
  • enabled – whether this option is enabled

  • parameter – the Parameter attached to the widget

  • label – the label for the option

  • widget – the widget to specify the option value, etc

  • kwargs – extra args passed to the widget

Returns:

the option widget

class pydetecdiv.plugins.gui.ParametersFormGroupBox(parent: QWidget, title: str = None, show: bool = True)

Bases: GroupBox

an extension of GroupBox class to handle Forms

addSubBox(widget: Type[GroupBox], **kwargs: dict[str, Any]) GroupBox

Adds a sub-box to the current ParametersFormGroupBox

Parameters:
  • widget – the class of the GroupBox to add as a sub box

  • kwargs – keywords arguments to pass to the sub box

Returns:

the sub box object

addOption(label: str = None, widget: Type[QWidget] = None, parameter: Parameter = None, enabled: bool = True, **kwargs: dict[str, Any]) QWidget

add an option to the current Form

Parameters:
  • enabled – whether this option is enabled

  • parameter – the Parameter attached to the widget

  • label – the label for the option

  • widget – the widget to specify the option value, etc

  • kwargs – extra args passed to the widget

Returns:

the option widget

setRowVisible(index: int, on: bool = True) None

set the row defined by index or widget visible or invisible in the form layout

Parameters:
  • index – the row index or the widget in that row

  • on – whether the row should be visible or not

class pydetecdiv.plugins.gui.ComboBox(parent: QWidget, model: GenericModel = None, editable: bool = False, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QComboBox

an extension of the QComboBox class with a custom model/view architecture

setCurrentIndex(index: int) None

sets the currently selected index

Parameters:

index – the index to select

addItemDict(options: dict[str, Any]) None

add items to the ComboBox as a dictionary

Parameters:

options – dictionary of options specifying labels and corresponding user data {label: userData, …}

setItemsDict(options: dict[str, Any]) None

Defines items from a dictionary

Parameters:

options – the dictionary representing the options

setText(text: str) None

sets the current text if text is already an option, otherwise, it adds a new item

Parameters:

text – the text to select or add

text() str

returns the currently selected text

Returns:

the currently selected text

property selected: Signal

return property telling whether the current index of this ComboBox has changed

Returns:

Signal emitted when the current index has changed (i.e. new selection)

property changed: Signal

return property telling whether the current text of this ComboBox has changed. This overwrites the Pyside equivalent method in order to have the same method name for all widgets

Returns:

Signal emitted when the current text has changed (i.e. new selection)

value() str | Any

method to standardize the way widget values from a form are returned

Returns:

the current data if it can be json serialized or the current text of the selected item if it can’t

setValue(value: str) None

Defines the currently selected option of the ComboBox

Parameters:

value – the currently selected text

class pydetecdiv.plugins.gui.ListView(parent: QWidget, model: StringList = None, height: int = None, multiselection: bool = False, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QListView

an extension of the QComboBox class

addItemDict(options: dict[str, Any]) None

add items to the ComboBox as a dictionary

Parameters:

options – dictionary of options specifying labels and corresponding user data {label: userData, …}

property changed: Signal

return property telling whether the current text of this ComboBox has changed. This overwrites the Pyside equivalent method in order to have the same method name for all widgets

Returns:

PySide6.QtCore.QModelIndex the new selection model

selection() list[Any]

method to standardize the way widget values from a form are returned

Returns:

the current data (if it is defined) or the current text of the selected item

setValue()
contextMenuEvent(e: QContextMenuEvent) None

Definition of a context menu to clear or toggle selection of sources in list model, remove selected sources from the list model, clear the source list model

Parameters:

e (PySide6.QtGui.QContextMenuEvent) – mouse event providing the position of the context menu

unselect() None

Clear selection model

toggle() None

Toggle selection model, selected sources are deselected and unselected ones are selected

remove_items() None

Delete selected sources

clear_list() None

Clear the source list

class pydetecdiv.plugins.gui.ListWidget(parent: QWidget, model: DictItemModel = None, height: int = None, editable: bool = False, multiselection: bool = False, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QListView

An extension of the QListView providing consistency with other custom widgets.

setCurrentIndex(index: QModelIndex) None

Sets the current index (current selection)

Parameters:

index – the index for the current selection

addItemDict(options: dict[str, Any]) Any

add items to the ListWidget as a dictionary

Parameters:

options – dictionary of options specifying labels and corresponding user data {label: userData, …}

addItem(text: str, userData: Any = None) None

Adds an item to the list

Parameters:
  • text – the text to display in the List view

  • userData – the associated data (can be any type of object)

class pydetecdiv.plugins.gui.LineEdit(parent: QWidget, model: ItemModel = None, editable: bool = True, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QLineEdit

an extension of QLineEdit class

property changed
Returns:

property edited: Signal

returns the Signal that editing is finished

Returns:

the self.editingFinished signal

setEditable(editable: bool = True) None

Sets the property editable for the LineEdit widget

Parameters:

editable – True if the LineEdit can be edited, False otherwise

setModel(model: ItemModel) None

Sets the model for the LineEdit widget

Parameters:

model – the item model containing a str value

class pydetecdiv.plugins.gui.Label(parent: QWidget, model: ItemModel = None, **kwargs: dict[str, Any])

Bases: QLabel

an extension of QLabel class

setModel(model: ItemModel) None

Sets the model for the Label

Parameters:

model – the item model containing a str value

class pydetecdiv.plugins.gui.PushButton(parent: QWidget, text: str, icon: QIcon = None, flat: bool = False, enabled: bool = True)

Bases: QPushButton

an extension of QPushButton class

class pydetecdiv.plugins.gui.AdvancedButton(parent: QWidget, text: str = 'Advanced options')

Bases: PushButton

an extension of PushButton class to control collapsible group boxes for advanced options

hide()

hide the linked group box

linkGroupBox(group_box: GroupBox) None

link this advanced button to a group box whose expansion or collapse should be controlled by this button

Parameters:

group_box – the group box to link to this button

toggle()

toggle the advanced button to and from show/hide form

class pydetecdiv.plugins.gui.RadioButton(parent: QWidget, model: ItemModel = None, exclusive: bool = True, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QRadioButton

an extension of the QRadioButton class

setModel(model: ItemModel) None

Sets the model for the radio button

Parameters:

model – the item model containing a bool value

property changed: Signal
return property telling whether the RadioButton value has changed. This overwrites the Pyside equivalent method

in order to have the same method name for all widgets

Returns:

boolean indication whether the value has changed

on_toggled(checked: bool) None

Slot setting the value of the bool model when the RadioButton is toggled

Parameters:

checked – bool value indicating whether the button has been checked or unchecked

class pydetecdiv.plugins.gui.SpinBox(parent: QWidget, model: ItemModel = None, minimum: int = 1, maximum: int = 4096, single_step: int = 1, adaptive: bool = False, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QSpinBox

an extension of the QSpinBox class

setModel(model: ItemModel)

Sets the model for the spin box

Parameters:

model – the item model containing an int value

property changed: Signal
return property telling whether the spinbox value has changed. This overwrites the Pyside equivalent method in

order to have the same method name for all widgets

Returns:

boolean indication whether the value has changed

class pydetecdiv.plugins.gui.DoubleSpinBox(parent: QWidget, model: ItemModel = None, minimum: float = 0.1, maximum: float = 1.0, decimals: int = 2, single_step: float = 0.1, adaptive: bool = False, enabled: bool = True, **kwargs: dict[str, Any])

Bases: QDoubleSpinBox

an extension of the QDoubleSpinBox class

setModel(model: ItemModel) None

Sets the model for the spin box

Parameters:

model – the item model containing a float value

property changed

method returning whether the spinbox value has been changed

Returns:

boolean, True if the value was changed, False otherwise

class pydetecdiv.plugins.gui.TableView(parent, model=None, enabled=True, **kwargs)

Bases: QTableView

an extension of the QTableView widget

class pydetecdiv.plugins.gui.DialogButtonBox(parent: ~PySide6.QtWidgets.QWidget, buttons: ~PySide6.QtWidgets.QDialogButtonBox.StandardButton | ... = (<StandardButton.Ok: 1024>, <StandardButton.Close: 2097152>))

Bases: QDialogButtonBox

A extension of QDialogButtonBox to add a button box

connect_to(connections: dict[Signal, Callable] = None) None

Specify the connections between the signal from this button box and slots specified in a directory

Parameters:

connections – the dictionary linking signals to slots

class pydetecdiv.plugins.gui.Dialog(plugin: Plugin = None, title: str = None, **kwargs: dict[str, Any])

Bases: QDialog

An extension of QDialog to define forms that may be used to specify plugin options

fit_to_contents() None

Adjust the size of the window to fit its contents

addGroupBox(title: str = None, widget: ~typing.Type[~pydetecdiv.plugins.gui.GroupBox] = <class 'pydetecdiv.plugins.gui.ParametersFormGroupBox'>) GenericGroupBox

Add a group box to the Dialog window

Parameters:
  • title – the title of the group box to add

  • widget – the class of group box

Returns:

the group box

addButtonBox(buttons: ~PySide6.QtWidgets.QDialogButtonBox.StandardButton | ... = <StandardButton.Ok|Close: 2098176>, centered: bool = True) DialogButtonBox

Add a button box to the Dialog window

Parameters:
  • buttons – the buttons to add to the button box

  • centered – should the buttons be centred

Returns:

the button box

addButton(widget: Type[QPushButton], text: str = None, icon: QIcon = None, flat: bool = False) QPushButton

Add a button to the Dialog window

Parameters:
  • widget – the type of button to add

  • text – the text

  • icon – the icon

  • flat – should the button be flat

Returns:

the added button

arrangeWidgets(widget_list: list[QWidget]) None

Arrange the widgets in the Dialog window vertical layout

Parameters:

widget_list – the list of widgets to add to the vertical layout

pydetecdiv.plugins.gui.set_connections(connections: dict[Signal, Callable]) None

connect a signal to a slot or a list of slots, as defined in a dictionary

Parameters:

connections – the dictionary {signal: slot,…} or {signal: [slot1, slot2,…],…} containing the connections to create

pydetecdiv.plugins.parameters

Module defining the different types of parameters that may be needed to store information about a process and that may be specified using GUI widgets which are synchronized thanks to a shared model

class pydetecdiv.plugins.parameters.Parameter(name: str, label: str = None, default: Any = None, validator: Callable[[Any], bool] = None, groups: set[str] = None, updater: Callable = None, **kwargs: dict[str, Any])

Bases: object

Generic class defining the general behaviour of parameters

kwargs() dict[str, Any]

Returns keywords arguments that should be passed to any widget used to manage the parameter. This method should be overridden for specific Parameter implementations that may need more control over widgets

Returns:

a dictionary containing the keywords arguments

property default: Any

Returns the default value. If self._default is a callable, it is called to determine which value should be returned

Returns:

the default value

clear() None

Clears the parameter of it’s content

set_value(value: Any) None

Sets the current value for the parameter. The model’s value setter is called only if the new value is different to avoid emit the changed signal without any reason

Parameters:

value – the new parameter value

property value: Any

Returns the current value of the parameter

Returns:

the current value

property json: Any

Returns the current value in a json-compatible format. This method should be overridden for types that cannot be dumped with json.dumps.

Returns:

the parameter value

reset() None

Reset the value to the specified default

update() None

Runs the specify updater callable if it was set, to update the parameter’s value or choice

validate(value: Any) None

Validates the value using the specified validator callable or always returning True if validator is None. This method should be overridden for more specific needs of particular Parameter types

class pydetecdiv.plugins.parameters.ItemParameter(name: str, label: str = None, default: Any = None, validator: Callable[[...], bool] = None, groups: set[str] = None, updater: Callable = None, **kwargs: dict[str, Any])

Bases: Parameter

Class representing a parameter holding any kind of single value parameter (item).

class pydetecdiv.plugins.parameters.NumParameter(name: str, label: str = None, default: int | float = None, minimum: int | float = None, maximum: int | float = None, validator: Callable[[int | float], bool] = None, groups: set[str] = None, updater: Callable = None, **kwargs: dict[str, Any])

Bases: ItemParameter

Class representing a parameter holding a number.

kwargs() dict[str, Any]

Returns keywords arguments that should be passed to any widget used to manage the parameter

Returns:

a dictionary containing the keywords arguments

reset() None

Resets the current value to its default it is specified

set_minimum(value: int | float) None

Sets the minimum accepted value

Parameters:

value – the minimum value

set_maximum(value: int | float) None

Sets the maximum accepted value

Parameters:

value – the maximum value

set_range(minimum: int | float, maximum: int | float) None

Sets the range of accepted values for the numerical parameter

Parameters:
  • minimum – the minimum accepted value

  • maximum – the maximum accepted value

validate(value: int | float) bool

Validates a numerical value, returning True if value is numerical and lies within the specified range, False otherwise

Parameters:

value – the value to be tested

Returns:

the result of the validation process

class pydetecdiv.plugins.parameters.IntParameter(name: str, label: str = None, default: int = 1, validator: Callable[[int], bool] = None, minimum: int = 1, maximum: int = 4096, groups: set[str] = None, updater: Callable = None, **kwargs: dict[str, Any])

Bases: NumParameter

Class representing a parameter holding a integer number.

validate(value: int) bool

Validates the value for a integer parameter, making sure it lies within the specified range

Parameters:

value – the value to be validated

Returns:

the result of the validation test: True if the value is validated, False otherwise

class pydetecdiv.plugins.parameters.FloatParameter(name: str, label: str = None, default: float = 0.0, validator: Callable[[float], bool] = None, minimum: float = 0.0, maximum: float = 1.0, groups: set[str] = None, updater: Callable = None, **kwargs: dict[str, Any])

Bases: NumParameter

Class representing a parameter holding a float number.

validate(value: float) bool

Validates the value for a float parameter, making sure it lies within the specified range

Parameters:

value – the value to be validated

Returns:

the result of the validation test: True if the value is validated, False otherwise

class pydetecdiv.plugins.parameters.StringParameter(name: str, label: str = None, default: str = '', validator: Callable[[str], bool] = None, groups: set[str] = None, updater: Callable = None, **kwargs: dict[str, Any])

Bases: ItemParameter

Class representing a parameter holding text.

class pydetecdiv.plugins.parameters.CheckParameter(name: str, label: str = None, exclusive: bool = True, default: str | int | float | bool | Callable = None, validator: Callable[[bool], bool] = None, groups: set[str] = None, updater: Callable[[...], None] = None, **kwargs: dict[str, Any])

Bases: ItemParameter

Class representing a parameter whose value is either True (checked) or False (unchecked). Such parameters can be linked to CheckBox arranged in the same GroupBox and set to be mutually exclusive.

kwargs() dict[str, Any]

Returns keywords arguments that should be passed to any widget used to manage the parameter

Returns:

a dictionary containing the keyword arguments

class pydetecdiv.plugins.parameters.ChoiceParameter(name: str, items: dict[str, object] = None, label: str = None, default: str | int | float | bool | Callable = None, validator: Callable[[Any], bool] = None, groups: set[str] = None, updater: Callable[[...], None] = None, **kwargs: dict[str, Any])

Bases: Parameter

Class representing a parameter whose value is a selection among several options (items)

property json: str | list | dict

Returns the selected key in a way that is compatible with json.dumps. This is important to maintain consistency in the way keys strings representing lists or dictionaries are stored in json format (in SQLite, etc).

Returns:

the json-compatible representation of selected key

property key: str

Returns the key of the selected choice

Returns:

the selected key

property value: Any

Returns the value object of the selected choice

Returns:

the selected value object

property keys: list[str]

Returns all the keys for the ChoiceParameter corresponding to the actual choice values

Returns:

the list of all possible choices

property values: list[object]

Returns all the choice values for the ChoiceParameter

Returns:

the list of all possible values

property items: dict[str, object]

Returns all choice items for this parameter as a dictionary with key = name/representation of the corresponding option, value = the actual object

Returns:

all choice items

property item: object

Return the object represented by the ChoiceParameter option

Returns:

the object represented by this option

set_value(value: Any) None

Sets the current value for the parameter. The model’s value setter is called only if the new value is different to avoid emit the changed signal without any reason

Parameters:

value – the new parameter selected key, pointing to the new value

set_items(items: dict[str, object]) None

Sets the choice items of the ChoiceParameter object. It the object contained items before, these are cleared and replaced with the new set.

Parameters:

items – a dictionary containing the items to add to the ChoiceParameter. Key is the name/representation of the corresponding option, value is the actual object

add_item(item: dict[str, object]) None

Add an item to the ChoiceParameter object

Parameters:

item – the dictionary containing the choice item to add to the ChoiceParameter. Key is the name/representation of the corresponding option, value is the actual object.

add_items(items: dict[str, object]) None

Add items to the ChoiceParameter object

Parameters:

items – a dictionary containing the choice items to add to the ChoiceParameter. Key is the name/representation of the corresponding option, value is the actual object.

class pydetecdiv.plugins.parameters.Parameters(parameters: list[Parameter] | Parameter = None)

Bases: object

A class to handle a list of parameters

reset(groups: list[str] | str = None) None

Reset all parameters in groups

Parameters:

groups – the groups to reset

update(groups: list[str] | str = None) None

Updates all parameters in groups

Parameters:

groups – the groups to update

values(param_list: list[Parameter] = None, groups: list[str] | str = None) dict[str, Parameter]

Returns a dictionary of parameters with name as key and value as value

Parameters:
  • param_list – the list of parameters, if None, all parameters are returned

  • groups – the parameters groups, if None, all parameters are returned

Returns:

a dictionary of all parameters

get_groups(groups: list[str] | str, union: bool = False) list[Parameter]

Get parameters from groups. If multiple groups are given, either intersection (default) or union of the parameters sets is returned

Parameters:
  • groups – the groups

  • union – a boolean, if True, a parameter is returned if it belongs to at least one group, if False, it is returned only if it belongs to all groups

Returns:

a list of parameters

to_dict() dict[str, Parameter]

Return the parameters as a dictionary

Returns:

a dictionary of all parameters, values are Parameter objects

json(param_list: list[Parameter] = None, groups: list[str] | str = None) dict[str, object]

Return dictionary of parameters representing each of them as a json-compatible object

Parameters:
  • param_list – the list of parameters, if None, all parameters are returned

  • groups – the parameters groups, if None, all parameters are returned

Returns:

a dictionary of all parameters in a json-compatible format