widgets#

Custom widgets for the ClearMap GUI.

This module provides reusable Qt widgets and compound controls used throughout the ClearMap graphical interface, including:

class BlockProcessingWidget(parent=None, title: str = 'Block processing', with_overlap: bool = True, default_min: int = 1000000, default_max: int = 10000000)[source]#

Bases: QGroupBox

Reusable UI for block_processing parameters:
  • size_min

  • size_max

  • overlap

  • n_processes

The internal controls are spinboxes. We expose properties with value()/setValue() style methods to play nice with ParamLink.

property n_processes: int#
property overlap: int | None#
property size_max: int#
property size_min: int#
class CheckableListWidget(parent=None)[source]#

Bases: QWidget

A list widget where each item has a checkbox.

add_item(item)[source]#
check_item_at(index)[source]#
check_items(items_list)[source]#
clear()[source]#
delete_item(index)[source]#
get_checked_items()[source]#
get_item(item_name)[source]#
on_item_changed(item)[source]#
set_item_checked(item_name, state)[source]#
set_items(items)[source]#
check_state_changed#

(index, checked, item_text).

Type:

Emitted when an item’s check state changes. Arguments

class ClickableFrame[source]#

Bases: QFrame

A QFrame that emits a clicked signal on mouse press.

mousePressEvent(self, a0: Optional[QMouseEvent])[source]#
clicked#

Emitted on mouse press.

class ComparisonsModel(group_names: List[str] = <factory>, selected: List[Tuple[str, str]]=<factory>, sep: str = ' vs ')[source]#

Bases: object

all_pairs() List[Tuple[str, str]][source]#
parse_label(label: str) Tuple[str, str][source]#
serialize_label(pair: Tuple[str, str]) str[source]#
group_names: List[str]#
selected: List[Tuple[str, str]]#
sep: str = ' vs '#
class ComparisonsWidgetAdapter(layout, groups_sep: str = ' vs ')[source]#

Bases: object

Owns and (re)builds the comparisons area. Exposes only high-level ops so GroupAnalysisParams doesn’t touch low-level widgetry.

rebuild(model: ComparisonsModel, *, on_plot_group: Callable[[str], None], channels: List[str], on_channel_changed: Callable[[str], None], suffixes: List[str] = None, preselected_comparisons: List[Tuple[str, str]] | None = None) None[source]#
selected_pairs(model: ComparisonsModel) List[Tuple[str, str]][source]#
class DataFrameWidget(df, n_digits=2, parent=None)[source]#

Bases: QWidget

A simple widget to display a pandas DataFrame

class ExtendableTabWidget(parent=None, with_add_tab=True)[source]#

Bases: QTabWidget

add_channel_widget(widget, name='')[source]#
current_channel()[source]#
get_channel_widget(name=None, return_idx=False)[source]#
get_channels_names()[source]#
handle_tab_bar_click(index)[source]#
remove_channel_widget(name)[source]#
set_current_channel_name(name)[source]#
addTabClicked#

Emitted when the (+) tab is clicked.

channelChanged#

channel name.

Type:

Emitted when a channel tab is clicked. Argument

channelRenamed#

(old_name, new_name).

Type:

Emitted when a channel tab is renamed. Arguments

property last_real_tab_idx#
class FileDropListWidget(parent=None, plus_btn=None, minus_btn=None)[source]#

Bases: QListWidget

addItem(self, aitem: Optional[QListWidgetItem])[source]#
addItem(self, label: str)
addItems(self, labels: Iterable[str])[source]#
add_files(file_paths=None)[source]#
dragEnterEvent(self, e: Optional[QDragEnterEvent])[source]#
dragMoveEvent(self, e: Optional[QDragMoveEvent])[source]#
dropEvent(self, event: Optional[QDropEvent])[source]#
get_items_text()[source]#
remove_selected()[source]#
itemsChanged#

Emitted when items are added or removed.

class GraphFilterList(layout: QVBoxLayout, parent: QWidget | None = None)[source]#

Bases: QWidget

A vertical list of graph-filter rows with AND/OR combiners between them.

Compatibility guarantees for GraphFilterParams:

  • The container layout is a QVBoxLayout named 'filterParamsVerticalLayout'.

  • Each filter row widget is named 'filter_{idx}'.

  • Between row i and i+1 a QFrame is inserted that contains two QRadioButton instances named 'filter_{i}_and_btn' (checked by default) and 'filter_{i}_or_btn'.

add_filter_row(*, title: str | None = None) QWidget[source]#

Add a new filter row. Returns the filter QWidget to pass to GraphFilterParams.

row_count() int[source]#
filtersChanged#

Emitted when filters are added or modified.

class GroupPage(*, ui_name: str = 'sample_group_controls.ui', start_folder_getter=<function GroupPage.<lambda>>)[source]#

Bases: object

Wrapper around one sample_group_controls.ui page.

connect(on_changed: Callable[[], None]) None[source]#

Wire config-writing callbacks. Idempotent.

connect_group_name_changed(on_name_changed: Callable[[str], None]) None[source]#
property name: str#
property paths: List[str]#
property widget: QWidget#
class GroupsWidgetAdapter(*, toolbox: QToolBox, container_layout: QLayout, add_btn: QPushButton, remove_btn: QPushButton, start_folder_getter=<function GroupsWidgetAdapter.<lambda>>, groups_ui_file='sample_group_controls.ui')[source]#

Bases: QWidget

ParamLink-compatible adapter:
  • owns a list[GroupPage] kept in the same order as the toolbox pages.

  • add/remove uses the provided buttons and QToolBox currentIndex.

  • set_value/get_value talk only dict[str, list[str]].

add_group(name: str | None = None, paths: List[str] | None = None) int[source]#

Add a new (possibly empty) group and return its index.

connect(on_changed: Callable[[], None]) None[source]#
get_all_paths() list[str][source]#
get_paths(idx: int) list[str][source]#
get_value() Dict[str, List[str]][source]#
group_count() int[source]#
remove_current_page() Tuple[int, str][source]#
set_paths(idx: int, paths: list[str]) None[source]#
set_value(groups: Dict[str, List[str]]) None[source]#
property group_names: list[str]#
class Landmark(idx, dialog, color)[source]#

Bases: object

activate()[source]#
formatted_coords(img_type)[source]#
isChecked()[source]#
is_set()[source]#

Coords of both fixed and moving images are set

Returns

bool

property color#
class LandmarksSelectorDialog(fixed_image_path, moving_image_path, fixed_image_landmarks_path, moving_image_landmarks_path, app=None)[source]#

Bases: WizardWidget

A dialog to select landmarks in 3D space for registration The dialog allows to select landmarks in two views (fixed and moving) The landmarks are displayed in two 3D viewers with matching colors The dialog saves the landmarks to files for the fixed and moving images

add_marker()[source]#

Add a new marker to the dialog

clear_landmarks()[source]#

Clear all the markers and the landmarks file paths and reset the dialog

connect_buttons()[source]#

Connect the buttons to their slots. This method is called automatically in the constructor

get_coords(img_type)[source]#

Get the coordinates of all the markers for the specified image type.

Parameters:

img_type (str) – The type of the image (‘fixed_image’ or ‘moving_image’).

Returns

np.ndarray

The array of marker coordinates.

get_new_color()[source]#

Get a new color for a marker (not already used) .. rubric:: Returns

str

The new color name

plot(lut=None, parent=None)[source]#

Plot the 3D landmarks onto the fixed and moving images using data viewers.

Parameters:
  • lut (str) – Lookup table for coloring the 3D plot.

  • parent (QWidget) – The parent widget for the plot.

remove_marker()[source]#

Remove the last marker

set_current_coords(x, y, z, img_type)[source]#

Set the coordinates for the specified image type.

Parameters:
  • img_type (str) – The type of the image (‘fixed_image’ or ‘moving_image’).

  • x (float) – The x-coordinate.

  • y (float) – The y-coordinate.

  • z (float) – The z-coordinate.

setup()[source]#

Setup the dialog after creation from the ui file. This method is called automatically in the constructor

write_coords()[source]#

Write the coordinates of the markers to the respective landmarks files

property colors#

Get the ordered list of colors of the markers

Returns

list(str)

The markers colors

property current_color#

Get the color of the currently selected marker

Returns

str

The color of the currently selected marker

property current_marker#

Get the index of the currently selected marker .. rubric:: Returns

int : the index of the currently selected marker

class LandmarksWeightsPanel(parent: QWidget = None, value_to_model=None, model_to_value=None)[source]#

Bases: QFrame

Compact panel that renders one row per landmark-params file.

Each row contains a label, a 0–100 slider, and a value display.

Public API:

Optional transforms can be supplied to map between slider value (0–100) and model value (float). Defaults are identity; keep scaling (e.g. exp) in the controller.

getValue()[source]#
get_params_and_weights() dict[str, int][source]#

Return current mapping of param file name to raw slider value (0..100).

get_weights() list[int][source]#

Return current raw slider values (0..100).

setValue(weights)[source]#
set_items(names: list[str], weights: list[int] | None = None) None[source]#

Rebuild rows for the given names; optionally seed slider positions.

set_weights(weights: list[int]) None[source]#

Set weights without rebuilding rows (length must match).

valueChangedConnect(cb)[source]#

Qt-like connector used by our generic binder.

weightAtChanged#

(index, value).

Type:

Emitted when a single slider changes. Arguments

weightsChanged#

full list of weights (0–100).

Type:

Emitted when any slider changes. Argument

class ManageAssetsWidget(src_folder, params, sample_manager, app=None)[source]#

Bases: WizardWidget

action(action_name)[source]#

Perform the specified action on the selected assets. This will broadcast the action to the appropriate method of the sample manager

Parameters:

action_name (str) – The name of the action to perform

assert_all_images()[source]#
asset_types_to_assets(asset_names)[source]#
connect_buttons()[source]#

Connect the buttons to their slots. This method is called automatically in the constructor but should be implemented in the subclass

crop_dialog()[source]#
handle_selection_changed(itm_text)[source]#

Handle the selection change in the list_selection widget. This will update the asset info text browser with the information of the selected asset

Parameters:

itm_text (str) – The text of the selected item in the list_selection widget. This is a string representation of the asset type and channel, e.g. “(channel, asset_type)”

prompt_params(action_name)[source]#

Create a new dialog to prompt the user for the additional parameters of the specified action

Parameters:

action_name (str) – The name of the action to perform

Returns

dict

The parameters to use for the action

resample_assets()[source]#
resample_dialog()[source]#
setup()[source]#

Setup the dialog after creation from the ui file. This method is called automatically in the constructor but should be implemented in the subclass

update_resample_params(param_name, value)[source]#
property channel#
property selected_asset_types#
property selected_assets#
class NProcessesWidget(parent: QWidget | None = None, label: str = 'n_processes')[source]#

Bases: QWidget

Simple n_processes widget: label + spinbox.

Exposes value() / setValue() and a valueChanged signal so it can be used transparently by ParamLink.

setMaximum(maximum: int)[source]#
setMinimum(minimum: int)[source]#
setRange(minimum: int, maximum: int)[source]#
setValue(v: int)[source]#
value() int[source]#
valueChanged#

new value.

Type:

Emitted when the spin box value changes. Argument

class OrthoViewer(img=None, parent=None)[source]#

Bases: object

Orthogonal viewer for 3D images.

This is a class that allows to visualize 3D images in 3 orthogonal views.

add_regions()[source]#

Add the interactive linear-region overlays to each orthogonal view.

plot_orthogonal_views(img=None, parent=None)[source]#

Plot the orthogonal views of the image.

Parameters:
  • img (np.ndarray) – The image to plot. If None, the image set at initialization will be used.

  • parent (QWidget) – The parent widget to plot into. If None, the parent set at initialization will be used.

Returns

list of DataViewer

setup(img, params, parent=None, no_scale=False)[source]#

Initialize the viewer after the object has been created.

Parameters:
  • img (np.ndarray) – The 3D image to visualize.

  • params (UiParameter) – The parameters object.

  • parent (QWidget) – The parent widget.

  • no_scale (bool) – If True, disable coordinate scaling.

update_ranges(ranges)[source]#

Update the ranges (min, max) for each axis of the viewer.

Parameters:

ranges (list of tuple of float)

property depth#

Get the depth of the image.

Returns

int

property height#

Get the height of the image.

Returns

int

property shape#

Get the shape of the image.

Returns

tuple of int

property width#

Get the width of the image.

Returns

int

class PatternDialog(src_folder, params, app=None, min_file_number=10, tile_extension='.ome.tif')[source]#

Bases: WizardWidget

A wizard dialog to help the user define file patterns for a set of image file paths The dialog scans the source folder to find patterns in the file names and suggests them to the user there must be at least min_file_number files in the folder with the extension tile_extension to trigger the pattern search

add_group()[source]#

Add a new group of widgets to the dialog This is a group of widgets to define a pattern for a set of image files (typically a channel)

all_channels_defined()[source]#
connect_buttons()[source]#

Connect the buttons to their slots. This method is called automatically in the constructor

get_channel_names()[source]#
get_patterns() List[PatternFinder][source]#

Scan the current source folder to get the pattern finders for the image files

Non blocking to keep the UI responsive

Returns

list(PatternFinder)

The pattern finders for the source folder

get_results() List[ChannelPatternSpec][source]#
get_widgets(image_group_id, axis)[source]#

Get the widgets (label, pattern and combo) for a given image group and axis

Parameters:
  • image_group_id (int) – The index of the image group

  • axis (int) – The index of the axis

Returns

tuple(QLabel, QLabel, QComboBox)

The label of the axis, pattern for the axis pattern and combobox containing the axis name (as a letter)

save_results()[source]#
setup()[source]#

Setup the dialog after creation from the ui file. This method is called automatically in the constructor

validate_pattern()[source]#

Validate the pattern defined by the user and update the result widget The result is saved in the pattern_strings attribute for the current channel name

min_file_number: int#
n_image_groups: int#
patterns_finders: List[PatternFinder]#
tile_extension: str#
class PerfMonitor(parent, fast_period, slow_period, *args, **kwargs)[source]#

Bases: QWidget

get_cpu_percent()[source]#
get_ram_percent()[source]#
get_thread_percent()[source]#
handle_gpu_vals_updated()[source]#
handle_proc_changed(file_path)[source]#
start()[source]#
stop()[source]#
update_cpu_values()[source]#
update_gpu_values()[source]#
cpu_vals_changed#

(cpu_percent, thread_percent, ram_percent).

Type:

Emitted when CPU values update. Arguments

gpu_vals_changed#

(gpu_percent, vram_percent).

Type:

Emitted when GPU values update. Arguments

percent_thread#

The percentage of the CPU used by the most active process of ClearMap

class ProgressWatcher(max_progress=100, main_max_progress=1, timer_interval_ms=250, parent=None)[source]#

Bases: QWidget

A QWidget that watches the progress of a process.

It uses signals to update the progress bar and the text. The main setup methods are setup() and prepare_for_substep(). It is meant to be used in conjunction with a progress dialog to which it is connected through its signals.

count_dones()[source]#

Parse the logs to extract the number of completed operations (based on self.pattern). For each match, the progress is incremented by 1. For efficiency, the logs are read from the last read position.

Returns

int

The cumulative number of matched operations.

finish()[source]#

Trigger the finished signal.

get_progress()[source]#

Get the current progress.

Returns

int

increment(increment)[source]#

Increment the progress value of the current main or sub step.

Parameters:

increment (int or float) – The increment value. If float, it is considered as a fraction of the maximum progress value.

increment_main_progress(increment=1)[source]#

Integer increment of the main progress.

Parameters:

increment (int) – The increment value (default is 1).

prepare_for_substep(step_length, pattern, step_name)[source]#

Setup the watcher for a new substep.

Parameters:
  • step_length (int) – The number of steps in the operation.

  • pattern (str or re.Pattern or tuple or None) – The text to look for in the logs to check for progress.

  • step_name (str) – Name (title) of the substep.

reset()[source]#

Reset all the values to their initial state.

reset_log_length()[source]#

Reset the done counter and seek to the end of the log file.

set_main_progress(value)[source]#

Set the progress value for the main step.

Parameters:

value (int) – The progress value.

set_poll_interval(ms: int)[source]#

Set the log-polling interval in milliseconds.

set_progress(value)[source]#

Set the progress value of the current main or sub step.

Parameters:

value (int) – The progress value.

setup(main_step_name, main_step_length, sub_step_length=0, pattern=None)[source]#

Post-initialisation setup.

Parameters:
  • main_step_name (str) – Title of the main processing step.

  • main_step_length (int) – Total number of main steps.

  • sub_step_length (int) – Total number of sub-steps within the current main step.

  • pattern (str or re.Pattern or tuple or None) – Text pattern to search for in logs to detect progress increments.

start_polling()[source]#

Start polling the log file for progress pattern matches.

stop_polling()[source]#

Stop log-file polling.

aborted#

whether abort was confirmed.

Type:

Emitted when processing is aborted. Argument

finished#

main step name.

Type:

Emitted when all processing has finished. Argument

main_max_changed#

new maximum.

Type:

Emitted when the main progress maximum changes. Argument

property main_max_progress#

Current main-step maximum.

main_progress_changed#

current value.

Type:

Emitted when the main progress value changes. Argument

property main_step_name#

Current main step name.

main_step_name_changed#

step name.

Type:

Emitted when the main step name changes. Argument

max_changed#

new maximum.

Type:

Emitted when the sub-step progress maximum changes. Argument

property max_progress#

Current sub-step maximum.

progress_changed#

current value.

Type:

Emitted when the sub-step progress value changes. Argument

property sub_step_name#

Current sub-step name.

sub_step_name_changed#

step name.

Type:

Emitted when the sub-step name changes. Argument

class SamplePickerDialog(src_folder, params, app=None)[source]#

Bases: WizardWidget

A dialog to help the user pick the sample folders from a source folder. The dialog scans the source folder to find the sample folders based on the presence of a sample_params.cfg file The results are displayed in two lists. The user can move the sample folders from the left (available items) list to the right (selected items) list. The samples can be split into groups to allow for different processing of the groups.

connect_buttons()[source]#

Connect the buttons to their slots. This method is called automatically in the constructor

parse_sample_folders()[source]#

Scan the source folder to find experiment folders based on the presence of a sample config file (any supported name/extension).

Returns

list(str)

The list of sample folders, naturally sorted.

setup()[source]#

Setup the dialog after creation from the ui file. This method is called automatically in the constructor

class StructurePickerWidget(parent=None, json_base_name='ABA json 2022')[source]#

Bases: QTreeWidget

static build_tree(tree=None, parent=None)[source]#
static parse_json(base_name='ABA json 2022')[source]#
print_id(itm, col)[source]#
DARK_COLOR = '#2E3436'#
LIGHT_COLOR = 'white'#
class StructureSelector(app=None)[source]#

Bases: WizardWidget

close()[source]#
connect_buttons()[source]#

Connect the buttons to their slots. This method is called automatically in the constructor but should be implemented in the subclass

setup()[source]#

Setup the dialog after creation from the ui file. This method is called automatically in the constructor but should be implemented in the subclass

show()[source]#
class TwoListSelection(parent=None, input_title=None, output_title=None)[source]#

Bases: QWidget

A widget that allows to select items from a list and move them to another list.

This is useful for selecting items from a list of available items and moving them to a list of selected items.

addAvailableItems(items)[source]#

Add the list of available items to the left list.

Parameters:

items (list) – The list of items to add. Each element can be a string or a (text, user_data) tuple.

clear()[source]#

Clear both lists.

get_left_elements(with_data=False)[source]#

Get the list of items in the left list (available items).

Returns

list of str

get_right_elements(with_data=False)[source]#

Get the list of items in the right list (selected items).

Returns

list of str

on_selection_changed(list_widget)[source]#
setSelectedItems(items)[source]#

Add the list of selected items to the right list.

Parameters:

items (list) – The list of items to add.

update_buttons_status()[source]#
itemSelectionChanged#

item text.

Type:

Emitted when a single item is selected in either list. Argument

class WizardWidget(ui_name, ui_title, src_folder='', params=None, app=None, size=None, patch_parent_class='QDialog')[source]#

Bases: object

A base class for a complex dialogs designed with QT creator and exported as ui files. It is meant to be subclassed. The subclass should implement the setup and connect_buttons methods This class needs a src_folder, a ui_name, a ui_title. The ui names and titles are used to build a dialog from the ui file of the same name and parametrise the dialog

static enable_widgets(widgets)[source]#

Helper method to enable a list of widgets

Parameters:

widgets (list(QWidget)) – The list of widgets to enable

static hide_widgets(widgets)[source]#

Helper method to hide a list of widgets

Parameters:

widgets (list(QWidget)) – The list of widgets to hide

connect_buttons()[source]#

Connect the buttons to their slots. This method is called automatically in the constructor but should be implemented in the subclass

exec()[source]#

Execute the dialog

setup()[source]#

Setup the dialog after creation from the ui file. This method is called automatically in the constructor but should be implemented in the subclass

ensure_inline_histogram(histogram: PlotWidget | QWidget, hist_idx: int, layout: QLayout)[source]#