populse_mia.user_interface.data_viewer.anatomist.mia_anatomist

Mia data viewer implementation based on Anatomist

Contains:
Class:
  • MiaViewer

Classes

MiaViewer([init_global_handlers])

A data viewer for Mia (Multiparametric Image Analysis) using PyAnatomist.

class populse_mia.user_interface.data_viewer.anatomist.mia_anatomist.TableDataBrowser(project, data_browser, tags_to_display, update_values, activate_selection, link_viewer=True)[source]

Bases: QTableWidget

Table widget that displays the documents contained in the database and their associated tags.

__init__(project, data_browser, tags_to_display, update_values, activate_selection, link_viewer=True)[source]

Initialize the data table widget with project data and browser context.

Parameters:
  • (Project) (project) – The current project instance containing data and configuration.

  • (DataBrowser) (data_browser) – Parent DataBrowser widget that contains this table.

  • (list[str]) (tags_to_display) – List of metadata tags to show as table columns.

  • (bool) (activate_selection) – If True, enables cell editing; if False, table is read-only.

  • (bool) – True to enable the selection feature, False otherwise.

  • link_viewer(bool) – If True, links table selection to external viewer widget. Defaults to True.

Notes

  • Column sorting and reordering are enabled by default (except first column).

  • Extended selection mode is used unless activate_selection is falsy.

  • A custom context menu is available only when both activate_selection and link_viewer are True.

add_column(column, tag)[source]

Add a new column to the table with the specified tag.

Inserts a column at the given index, configures its header with metadata from the database, sets the appropriate delegate based on field type, and populates cells with current values from the database.

Parameters:
  • (int) (column) – Zero-based index where the column should be inserted.

  • (str) (tag) – Tag name identifying the field to add from the database.

Note

Temporarily disconnects item change signals during insertion to prevent unwanted event triggers, then reconnects them after completion.

add_columns()[source]

Add and update table columns based on database fields.

This method synchronizes the table’s columns with the current database schema by:

  • Adding columns for new database fields that don’t exist in the table

  • Populating new columns with values from the database

  • Removing columns that no longer exist in the database

  • Applying appropriate formatting delegates based on field types

  • Maintaining column visibility settings

The method temporarily disconnects item change signals during operation to prevent unwanted events, then reconnects them after completion.

Note:
  • The TAG_FILENAME column is always placed first

  • Columns are sorted alphabetically (except TAG_FILENAME)

  • System tags (TAG_CHECKSUM, TAG_HISTORY) are excluded

  • Undefined values are displayed in italic bold text

add_path()[source]

Open a dialog to add documents to the current project.

Creates and displays a PopUpAddPath dialog that allows users to select and add document paths to the project’s data browser.

add_rows(rows)[source]

Insert rows into the table if they don’t already exist.

This method adds new scans to the table, populating each column with data from the database. It displays a progress dialog during the operation and handles special cases like the TAG_BRICKS column with custom widgets.

Parameters:

rows – An iterable of scan identifiers to be added to the table.

Note

  • Duplicate scans (already present in the table) are automatically skipped

  • Sorting is temporarily disabled during the insertion process

  • The first column (name) is set as non-editable

  • TAG_BRICKS columns receive custom button widgets for interaction

batch_update(*, disable_sorting=True)[source]

Context manager for efficient batch updates.

This manager temporarily disables repainting, signal emission, and optionally sorting, allowing multiple modifications to the table without triggering unnecessary redraws or signal handling. All previous widget states are restored upon exit, even if an exception occurs.

Parameters:

(bool) (disable_sorting) – If True (default), temporarily disables sorting during the batch update to prevent rearrangements.

clear_cell()[source]

Clear values from selected cells in the table.

This method removes data from the currently selected cells in the database and updates the UI to reflect the cleared state. The operation is recorded in the project’s undo history for potential reversal.

The method performs the following actions for each selected cell:
  • Retrieves the current value from the database

  • Removes the value from the database

  • Updates the cell’s visual appearance (italic + bold)

  • Records the change for undo/redo functionality

Side Effects:
  • Modifies database values in COLLECTION_CURRENT

  • Updates table cell formatting

  • Appends operation to project.undos

  • Clears project.redos

context_menu_table(position)[source]

Create and display the context menu for the table, and perform the corresponding action based on the user’s selection.

Parameters:

(QPoint) (position) – The mouse cursor position relative to the widget.

delete_from_brick(brick_id)[source]

Delete a brick and its associated documents from the database.

This method cleans up the database when a pipeline (composed of multiple bricks) is initialized but not executed before another pipeline is started or the software is closed. It removes the brick and any orphaned output documents that are not used as inputs elsewhere.

Parameters:

(str) (brick_id) – The unique identifier of the brick to be deleted.

display_file()[source]

Open the selected file(s) in the user’s default application.

Iterates over all selected items in the view, resolves their absolute paths, and opens each file using the platform’s default application.

Supported platforms: Linux, macOS, and Windows.

display_unreset_values()[source]

Displays a warning dialog listing values that cannot be reset.

This method shows a QMessageBox warning when certain values (such as user tags, FileName, or undefined cells) cannot be reset because they lack a raw value. The dialog includes a descriptive message and an OK button for dismissal.

edit_table_data_values()[source]

Edit and update selected cell values in the DataBrowser table.

This method handles the selection of cells, validation of list lengths, and updating of values in both the table and the database. It supports list-type fields and ensures data consistency across selections.

Steps:
  1. Collects selected cells and their metadata (coordinates, types, lengths, etc.).

  2. Validates list lengths for compatibility.

  3. Opens a dialog for value modification if valid.

  4. Updates the table and database, and records changes for undo/redo history.

Note

  • Exits early if the selected tag is ‘TAG_BRICKS’ or if the field type is not a list.

  • Disconnects and reconnects the itemChanged signal to prevent recursive updates.

fill_cells_update_table()[source]

Initialize and populate table cells with scan data from the database.

This method performs the following operations:
  1. Creates a progress dialog to track cell population

  2. Retrieves scan documents matching scans_to_visualize from the database

  3. Populates each cell with appropriate data based on column type

  4. Handles special cases (name column, bricks column)

  5. Applies saved sorting preferences

  6. Resizes rows and columns to fit content

Special column handling:
  • Column 0 (name): Read-only, always displays as string

  • Bricks column: Displays clickable buttons for brick history

  • Other columns: Editable, type-specific formatting

Notes

  • Displays a modal progress dialog during population

  • Temporarily hides the table during updates for performance

  • Connects cell change signals after population completes

fill_headers(take_tags_to_update=False)[source]

Initialize and populate table headers with field metadata.

Sets up table columns based on database fields, configuring each with:
  • Appropriate tooltips showing description, unit, and type

  • Specialized delegates for numeric and temporal data types

  • Visibility based on display settings or field attributes

Parameters:

take_tags_to_update – If True, use tags_to_display for visibility. If False, use field visibility attributes. Defaults to False.

get_current_filter()[source]

Get the current data browser selection.

Returns the list of selected scan paths if a selection is active, otherwise returns all visible scan paths in the data browser.

Return (list):

List of scan paths from either the current selection or all visible scans in the data browser.

get_index_insertion(to_insert)[source]

Find the insertion index for a new column to maintain alphabetical order.

Uses binary search to efficiently locate the correct position for inserting a column header while preserving the existing alphabetical sort order.

Parameters:

(str) (to_insert) – The column header text to insert.

Return (int):

The column index where the new column should be inserted. Returns columnCount() if it should be appended at the end.

Note: Assumes that column 0 is reserved (TAG_FILENAME must always be

the first tag on the left) and start the search from column 1.

get_scan_row(scan)[source]

Find the row index for a given scan filename.

Parameters:

scan – The scan filename to search for.

Return(int):

The zero-based row index if the scan is found, None otherwise.

get_tag_column(tag)[source]

Find the column index for a given tag name.

Searches through the table’s horizontal headers to locate the column corresponding to the specified tag.

Parameters:

(str) (tag) – The name of the tag to search for.

Return (int):

The zero-based column index if the tag is found, None otherwise.

mouseReleaseEvent(event)[source]

Handle mouse release event and update table data.

This method is called when a mouse button is released over the widget. It delegates to the parent class handler and then updates the table data values.

Parameters:

(QMouseEvent) (event) – The mouse event containing information about the button released, position, and modifiers.

multiple_sort_infos(list_tags, order)[source]

Sort table rows by multiple tag values.

Sorts the visualized scans based on the values of specified tags, then reorganizes the table rows to reflect the new order. Handles both regular items and special brick widgets during the reordering.

Parameters:
  • list_tags(list) – List of tag names to sort by (primary to secondary).

  • (str) (order) – Sort direction, either “Ascending” or “Descending”.

Note

Temporarily disables item change signals during sorting to prevent triggering update handlers. The sort is stable and preserves the relative order of items with equal sort keys.

multiple_sort_pop_up()[source]

Display the multiple sort configuration dialog.

Creates and shows a modal dialog that allows users to configure multiple sorting criteria for the current project data.

Note

The dialog instance is stored in self.pop_up.

on_cell_changed(item_origin)[source]

Update cell values and appearance when edited by the user.

This method handles both single and multi-cell selection, validating type compatibility across all selected cells before applying changes. It performs the following operations:

  1. Validates that all selected cells have compatible types

  2. Verifies the new value matches the expected type(s)

  3. Updates the database with validated values

  4. Maintains undo/redo history for all modifications

  5. Refreshes cell colors and formatting

Special handling: - PatientName: Removes spaces (used for subfolder naming in

calculations)

  • TAG_BRICKS/TAG_FILENAME: Read-only fields, changes are rejected

  • List types: Prevents mixed type selections but allows homogeneous

    lists

Parameters:

item_origin – QTableWidgetItem from which the edit originated

Side effects:
  • Modifies database values for selected cells

  • Updates cell appearance (colors, fonts)

  • Adds entry to project undo history

  • Clears redo history

  • Resizes columns to fit content

remove_scan()[source]

Remove selected scans from the database and file system.

This method handles the removal of scan documents from both the current and initial collections in the project database. It performs the following:

  • Prompts user for confirmation if scans are in the active scan list

  • Preserves modification history for removed scan values

  • Deletes associated files (.nii and .json) from the file system

  • Updates the UI table to reflect removals

The removal process can be cancelled by the user when prompted. If multiple scans are selected, the user can choose to apply their decision to all remaining scans.

Side effects:
  • Modifies database by removing documents from COLLECTION_CURRENT and COLLECTION_INITIAL

  • Deletes scan files from the project folder

  • Updates UI table rows and marks project as having unsaved modifications

reset_cell()[source]

Reset selected cells to their original values from the initial collection.

This method restores the values of all selected cells to their original state by retrieving values from COLLECTION_INITIAL and updating COLLECTION_CURRENT. If any cells lack initial values (e.g., user-created tags), a warning is displayed. The operation is recorded in the project history for undo/redo functionality.

Side effects:
  • Updates database values in COLLECTION_CURRENT

  • Updates table cell display values

  • Appends operation to project.undos

  • Clears project.redos

  • May display a warning dialog for unreset values

  • Resizes table columns to fit content

reset_column()[source]

Reset selected columns to their original values.

Restores values in selected cells to their initial state from the database. If a cell’s initial value doesn’t exist (e.g., user-added tags), it cannot be reset and a warning will be displayed.

The operation is recorded in the project’s undo history. Any existing redo history is cleared after this operation.

Side effects:
  • Updates database values in COLLECTION_CURRENT

  • Updates table cell displays

  • Appends to project.undos

  • Clears project.redos

  • Resizes columns to fit content

  • May display warning dialog for unreset values

reset_row()[source]

Reset selected cells to their original values from the initial collection.

Restores the values of all cells in selected rows to their initial state by copying values from COLLECTION_INITIAL to COLLECTION_CURRENT. Only cells with available initial values are reset. User-defined tags without initial values are skipped and trigger a warning dialog.

The operation is recorded in the project’s undo/redo history, allowing users to revert the reset if needed. After resetting, columns are automatically resized to fit their contents.

Side Effects:
  • Updates database values in COLLECTION_CURRENT

  • Updates table cell display values

  • Appends operation to project.undos

  • Clears project.redos

  • Shows warning dialog if any values couldn’t be reset

  • Resizes table columns

section_moved(logical_index, old_index, new_index)[source]

Handle section movement to keep the FileName column fixed at position 0.

This slot is triggered when a user attempts to reorder table columns. It ensures the FileName column (logical index 0) always remains at the leftmost visual position, regardless of user drag-and-drop actions.

Parameters:
  • logical_index – The logical index of the moved column (unused).

  • old_index – The previous visual position of the column (unused).

  • new_index – The new visual position of the column (unused).

Note

Parameters are required by the Qt signal signature but not used in the implementation. Uses a guard flag to prevent recursive calls when programmatically repositioning the FileName column.

select_all_column(col)[source]

Select all cells in a column when its header is double-clicked.

This method clears any existing selection before selecting the entire column, ensuring only the specified column is highlighted.

Parameters:

(int) (col) – The zero-based index of the column to select.

select_all_columns()[source]

Select all columns containing currently selected cells.

Expands the current cell selection to include entire columns. If cells from multiple columns are selected, all corresponding columns will be selected. This method is typically invoked from the context menu.

Note

Temporarily switches selection mode to MultiSelection during operation, then restores ExtendedSelection mode.

selection_changed()[source]

Update the tab view when the table selection changes.

Rebuilds the internal scans list based on currently selected items, grouping tag names by scan name. If link_viewer is enabled, updates the connected mini viewer display.

Side effects:
  • Clears and repopulates self.scans with [scan_name, [tag_names]] pairs

  • Calls data_browser.connect_mini_viewer() if self.link_viewer is True

show_brick_history(scan)[source]

Display a popup window showing the history of a brick.

This method retrieves the brick UUID associated with the triggering sender, creates a history popup dialog, and displays it to the user.

Parameters:

scan – The scan data to display in the history popup.

Note

The sender (typically a UI widget) must be registered in self.bricks to retrieve the corresponding brick UUID.

sort_column(order)[source]

Sort the currently selected column.

Parameters:

int) (order (Qt.SortOrder or) – Sort order to apply. - Qt.AscendingOrder (0): Sort from lowest to highest - Qt.DescendingOrder (1): Sort from highest to lowest

Note

Temporarily disconnects signals during sorting to prevent unwanted side effects, then reconnects them afterward.

sort_updated(column, order)[source]

Update project state and apply sorting to the table.

Temporarily disconnects signals, updates the project’s sort configuration, applies the sort to table items, refreshes visual elements, and reconnects signals.

Parameters:
  • column – The column index to sort by. Use -1 to indicate no sorting.

  • order – The sort order (Qt.AscendingOrder or Qt.DescendingOrder).

Note

This method is a no-op when column is -1, allowing safe calls with invalid column indices.

update_colors()[source]

Update cell background colors based on data state and visibility.

Colors indicate:
  • White/Grey: Unmodified builtin tags (alternating for visible

    rows)

  • Cyan/Blue: Modified builtin tags (alternating for visible rows)

  • Pink/Red: User-defined tags or null values (alternating for

    visible rows)

Note: This method assumes the itemChanged signal is disconnected. Automatically saves modifications if auto-save is enabled.

update_selection()[source]

Update table selection based on current scan results.

Clears existing selection and selects cells corresponding to tags found in the current scan results. For each scan, selects the cells at the intersection of the scan’s row and its associated tag columns.

update_table(take_tags_to_update=False)[source]

Refresh the table with current project data.

Completely resets and repopulates the table when switching projects. This involves clearing selections, fetching current scan documents, refilling headers and cells, resizing columns/rows, and updating the visual appearance.

Parameters:

take_tags_to_update – If True, updates tags during the header fill operation. Defaults to False.

Side Effects:
  • Clears current table selection

  • Resets scans_to_visualize and scans_to_search attributes

  • Clears selected scans list if selection is active

  • Disconnects and reconnects table signals

  • Modifies table dimensions and visual styling

update_visualized_columns(old_tags, showed)[source]

Update column visibility based on tag selection changes.

Synchronizes the table’s visible columns with the provided tag list by:

  • Hiding columns for tags that are no longer displayed

  • Showing columns for newly displayed tags

  • Updating advanced search dropdowns if the search panel is open

  • Refreshing column sizing and colors

Parameters:
  • (list) (showed) – Previously visualized tags.

  • (list) – Tags to currently display in the table.

update_visualized_rows(old_scans)[source]

Update table row visibility based on current scan visualization state.

Temporarily disconnects selection signals, hides rows for scans no longer in the visualization list, shows rows for newly visualized scans, and updates the table appearance.

Parameters:

old_scans – Collection of scans from the previous state, used to determine which rows need to be hidden.

visualized_tags_pop_up()[source]

Display a modal dialog for configuring visualized tag columns.

Opens a properties popup showing currently visible tags and allowing the user to modify which tags are displayed in the data browser. The popup is sized to 50% of screen width and 80% of screen height.

class populse_mia.user_interface.data_viewer.anatomist.mia_anatomist.DataViewer[source]

Bases: ABC, QWidget

An abstract base class for data viewers with a minimal, extensible API.

This class defines a standard interface for data viewers, allowing subclasses to implement custom visualization strategies. The base methods provide a simple contract for managing and displaying documents across different viewer implementations.

The API is intentionally kept simple to provide flexibility for specific use cases while ensuring a consistent basic functionality.

clear()[source]

Remove all currently displayed files.

This method provides a default implementation that removes all files currently being displayed by calling remove_files().

close()[source]

Close the viewer by clearing all displayed files.

This method provides a standard way to clean up and close the viewer, ensuring all resources are released.

abstract display_files(files)[source]

Display the specified document files.

This method must be implemented by subclasses to define how files are visually presented or loaded.

Parameters:

(List) (files) – A list of files to be displayed.

Raises:

NotImplementedError – If not overridden by a subclass.

abstract displayed_files()[source]

Retrieve the list of currently displayed files.

Return (list):

A list of files currently being displayed.

Raises:

NotImplementedError – If not overridden by a subclass.

abstract remove_files(files)[source]

Remove specified files from the display.

Parameters:

(list) (files) – A list of files to be removed from display.

Raises:

NotImplementedError – If not overridden by a subclass.

abstract set_documents(project, documents)[source]

Set the project context and available documents.

Parameters:
  • project – The project associated with the documents.

  • (list) (documents) – The list of available documents.

Raises:

NotImplementedError – If not overridden by a subclass.

_abc_impl = <_abc._abc_data object>
class populse_mia.user_interface.data_viewer.anatomist.mia_anatomist.MiaViewer(init_global_handlers=None)[source]

Bases: DataViewer

A data viewer for Mia (Multiparametric Image Analysis) using PyAnatomist.

This class provides a specialized viewer for displaying and managing medical imaging files with additional filtering and visualization capabilities.

Mia data viewer # noqa: E501 implementation based on PyAnatomist # noqa: E501

_mia_viewers_count = 0
__init__(init_global_handlers=None)[source]

Initialize the MiaViewer.

Parameters:

init_global_handlers – Initial global handlers for Anatomist viewer.

static _find_child(parent, name)[source]

Find a child widget by name.

Parameters:
  • (Qt.QObject) (parent) – Parent widget to search in.

  • (str) (name) – Name of the child widget to find.

Return (Qt.QObject):

The found child widget.

_setup_ui()[source]

Set up the user interface components for the viewer.

close()[source]

Close the viewer and manage Anatomist viewer resources.

display_files(files)[source]

Display the given files in the Anatomist viewer.

Parameters:

(list) (files) – List of file paths to display.

displayed_files()[source]

Get the list of currently displayed files.

Return (List):

List of displayed file paths.

filter_documents()[source]

Open a dialog to filter and select documents for visualization.

remove_files(files)[source]

Remove specified files from the viewer.

Parameters:

(list) (files) – List of file paths to remove.

set_documents(project, documents)[source]

Set the current project and documents for the viewer.

Parameters:
  • project – The project to set.

  • (List) (documents) – List of documents in the project.

_abc_impl = <_abc._abc_data object>