populse_mia.user_interface.main_window

Module to define main window appearance, functions and settings.

Initialize the software appearance and defines interactions with the user.

Classes

MainWindow(project[, test, deleted_projects])

Initialize software appearance and define interactions with the user.

class populse_mia.user_interface.main_window.MainWindow(project, test=False, deleted_projects=None)[source]

Bases: QMainWindow

Initialize software appearance and define interactions with the user.

Contains:

Methods:

  • add_clinical_tags: Add the clinical tags to the database and the data browser.

  • check_database: Check if files in database have been modified or removed since they have been converted for the first time.

  • check_unsaved_modifications: Check if there are differences between the current project and the database.

  • closeEvent: Override the closing event to check if there are unsaved modifications.

  • create_project_pop_up: Create a new project.

  • create_view_actions: Create the actions in each menu.

  • create_view_menus: Create the menu-bar.

  • create_view_window: Create the main window view.

  • create_tabs: Create the tabs.

  • credits: Open the credits in a web browser.

  • del_clinical_tags: Remove the clinical tags to the database and the data browser.

  • delete_project: Open a project and updates the recent projects list.

  • documentation: Open the documentation in a web browser.

  • get_controller_version: Returns controller_version_changed attribute.

  • import_data: Call the import software (MRI File Manager).

  • install_processes_pop_up: Open the install processes pop-up.

  • last_window_closed: Force exit the event loop after ipython console is closed.

  • open_project_pop_up: Open a pop-up to open a project and updates the recent projects.

  • open_recent_project: Open a recent project.

  • open_shell: Open a Qt console shell with an IPython kernel seeing the program internals.

  • package_library_pop_up: Open the package library pop-up.

  • project_properties_pop_up: Open the project properties pop-up.

  • redo: Redo the last action made by the user.

  • remove_raw_files_useless: Remove the useless raw files of the current project.

  • save: Save either the current project or the current pipeline.

  • save_as: Save either the current project or the current pipeline under a new name.

  • save_project_as: Open a pop-up to save the current project as.

  • saveChoice: Checks if the project needs to be saved as or just saved.

  • see_all_projects: Open a pop-up to show the recent projects.

  • set_controller_version: Reverses controller_version_changed attribute.

  • setup_menu_actions: Initialize menu actions.

  • setup_window_size: Set the window size and maximize if needed.

  • software_preferences_pop_up: Open the Mia preferences pop-up.

  • switch_project: Switches project if it’s possible.

  • tab_changed: Method called when the tab is changed.

  • undo: Undoes the last action made by the user.

  • update_project: Update the project once the database has been updated.

  • update_recent_projects_actions: Update the list of recent projects.

__init__(project, test=False, deleted_projects=None)[source]

Main window class, initializes the software appearance and defines interactions with the user.

Parameters:
  • project – Current project in the software.

  • test – Boolean indicating if the widget is launched from unit tests or not.

  • deleted_projects – Projects that have been deleted.

add_clinical_tags()[source]

Add the clinical tags to the database and the data browser.

check_database()[source]

Check if files in database have been modified since first import.

check_unsaved_modifications()[source]

Check if there are differences between the current project and the database.

:Returns (bool) True if there are unsaved modifications,

False otherwise

closeEvent(event)[source]

Override the QWidget closing event to check if there are unsaved modifications.

Parameters:

event – Closing event.

create_project_pop_up()[source]

Create a new project.

create_view_actions()[source]

Create the actions and their shortcuts in each menu.

create_view_menus()[source]

Create the menu-bar view.

create_view_window()[source]

Create the main window view.

create_tabs()[source]

Create the tabs and initializes the DataBrowser and PipelineManager classes.

credits()[source]

Open the credits in a web browser

del_clinical_tags()[source]

Remove the clinical tags to the database and the data browser.

delete_project()[source]

Open a pop-up to open a project and updates the recent projects list.

static documentation()[source]

Open the documentation in a web browser.

get_controller_version()[source]

Gives the value of the controller_version_changed attribute.

Returns:

A boolean.

import_data()[source]

Import MRI data using the MRI File Manager and load it into the database.

This method performs the following steps:
  1. Launches the MRI conversion software to convert MRI files to Nifti/JSON format.

  2. Attempts import with maximum heap size of 4096M, falls back to 1024M if needed.

  3. Updates the database with newly imported scans.

  4. Refreshes the data browser UI with new scan information.

install_processes_pop_up(folder=False)[source]

Open the install processes pop-up.

Parameters:

folder – (boolean) True if installing from a folder.

static last_window_closed()[source]

Force exit the event loop after ipython console is closed.

Note

If the ipython console has been run, something prevents Qt from quitting after the window is closed. The cause is not known yet. So: force exit the event loop.

open_project_pop_up()[source]

Open a dialog to select and open a project, updating recent projects list.

This method handles:
  1. Checking for unsaved modifications in current project.

  2. Opening project selection dialog.

  3. Validating project path.

  4. Switching to new project.

  5. Updating clinical mode based on database fields.

  6. Updating database paths if project is external.

open_recent_project()[source]

Open a recent project.

open_shell()[source]

Open an in-process Qt console (QtConsole) connected to this application.

This method creates a QtConsole widget that runs inside the current application process, allowing interactive inspection and manipulation of program internals such as the main window, project, and the QApplication instance. This console does not spawn a subprocess and fully integrates with the existing Qt event loop.

Features:

  • Provides access to key objects:
    • main_window: this MainWindow instance.

    • project: if available, the current project object.

    • app: the current QApplication instance.

  • Interactive Python prompt.

  • Stdout/stderr from the application will appear in the console.

Dependencies:
  • qtconsole for the console widget.

  • ipykernel for the in-process IPython kernel.

  • IPython for interactive shell support.

If any of these are missing, the console will not open, and a warning is logged.

Raises:

RuntimeError – If QApplication instance does not exist when calling this method.

Returns:

(RichJupyterWidget) the created QtConsole widget instance.

Contains:

Inner functions:

  • cleanup_console: Safely clean up an in-process Jupyter kernel and its communication channels.

Inner classes:

  • SafeRichJupyterWidget: A safer QtConsole widget for in-process IPython shells.

package_library_pop_up()[source]

Open the package library pop-up

project_properties_pop_up()[source]

Open the project properties pop-up

redo()[source]

Redo the last action made by the user.

remove_raw_files_useless()[source]

Remove the useless raw files of the current project.

Close the database connection. The project is not valid any longer after this call.

save()[source]

Save either the current project or the current pipeline.

save_as()[source]

Save either the current project or the current pipeline under a new name.

save_project_as()[source]

Open a pop-up to save the current project as.

saveChoice()[source]

Check if the project needs to be ‘saved as’ or just ‘saved’.

see_all_projects()[source]

Open a pop-up to show the recent projects.

set_controller_version()[source]

Reverses the value of the controller_version_changed attribute.

From False to True and vice versa

setup_menu_actions(sources_images_dir)[source]

Initialize menu actions with icons and descriptions.

Parameters:

sources_images_dir – Directory containing source images for icons.

setup_window_size()[source]

Set the window size and maximize if needed.

software_preferences_pop_up()[source]

Open the Mia preferences pop-up.

switch_project(file_path, name)[source]

Check if it’s possible to open the selected project and quit the current one.

Parameters:
  • file_path – Raw file_path.

  • name – Project name.

Returns:

A boolean.

tab_changed()[source]

Update the window when switching between application tab.

Updates the UI state and data when switching between Data Browser, Data Viewer, and Pipeline Manager tabs. Handles data synchronization, search state preservation, and unsaved changes warnings.

The method performs the following operations based on the selected tab:
  • Data Browser: Refreshes table data, preserves search state and visualization settings.

  • Data Viewer: Loads current viewer and updates document list.

  • Pipeline Manager: Updates scan lists and handles unsaved modifications.

undo()[source]

Reverts the last action performed by the user, depending on the active tab.

If the “Data Browser” tab is active, the undo operation is applied to the project’s database. If the “Pipeline Manager” tab is active, the pipeline manager’s undo function is invoked.

update_project(file_path, call_update_table=True)[source]

Updates the project after a database change.

This method updates the database, the window title, and the recent and saved projects menus.

Parameters:
  • file_path – (str) The file path of the new project.

  • call_update_table – (bool) Whether to update the table data, Defaults to True.

update_recent_projects_actions()[source]

Updates the list of recent projects in the UI.

Hides all recent project actions first, then updates and displays the most recent ones based on the configured maximum.