populse_mia.install.mia_install_widget

The module used for mia’s installation and configuration.

Basically, this module is dedicated to the GUI used at the installation time

Classes

MIAInstallWidget()

The main class for Mia's installation and configuration.

class populse_mia.install.mia_install_widget.MIAInstallWidget[source]

Bases: QWidget

The main class for Mia’s installation and configuration.

Contains:
Methods:
  • _create_info_button: Return a circular information button with the given tooltip.

  • browse_matlab: Opens a file dialog for the user to select a MATLAB executable file.

  • browse_matlab_standalone: Opens a directory dialog for the user to select the MATLAB Compile Runtime (MCR) directory.

  • browse_mia_config_path: Opens a directory dialog for the user to select a folder for installing the MiA configuration.

  • browse_projects_path: Opens a directory dialog for the user to select a folder to store Mia’s projects.

  • browse_spm: Opens a directory dialog for the user to select the SPM directory.

  • browse_spm_standalone: Opens a directory dialog for the user to select the SPM standalone directory.

  • btnstate: Toggles the state of two related buttons based on the text of the clicked button.

  • clone_mia_resources: Clones the mia_resources repository from GitLab to the specified directory.

  • find_matlab_path: Attempts to find the installation path of MATLAB on the system.

  • install: Manages the installation and configuration of Mia and associated software components.

  • install_matlab_api: Installs the MATLAB Engine API for Python.

  • install_package: Installs or upgrades a Python package using pip.

  • last_layout: Sets the final layout for the application window after Mia installation.

  • make_mrifilemanager_folder: Clones the MRI conversion repository into the specified directory.

  • ok_or_abort: Handles the action when the user clicks a button in a message box.

  • set_new_layout: Changes the layout to show the installation progress.

  • uninstall_package: Uninstalls a Python package using pip.

  • upgrade_soma_capsul: Upgrades the soma-base, soma-workflow, and capsul packages by cloning their latest versions from GitHub.

  • use_matlab_changed: Toggles the state of MATLAB-related options based on the ‘use_matlab’ checkbox.

  • use_spm_changed: Updates the state of SPM-related options based on the ‘use_spm’ checkbox.

  • use_spm_standalone_changed: Updates the state of standalone SPM-related options based on the ‘use_spm_standalone’ checkbox.

__init__()[source]

Initialize the installation dialog.

Build the user interface, initialize installation parameters and default paths, detect the execution environment, and configure the Matlab and SPM options according to the software available on the system.

_create_info_button(tooltip: str) QPushButton[source]

Return a circular information button with the given tooltip.

Parameters:

tooltip (str) – The tooltip text to display when hovering over the button.

Returns:

A QPushButton configured as an information button.

Type:

QPushButton

browse_matlab()[source]

Opens a file dialog for the user to select a MATLAB executable file.

This method presents a file selection dialog to the user, allowing them to choose the MATLAB executable file from their file system. If a file is selected, the file path is displayed in the matlab_choice widget.

Note

  • Opens a QFileDialog for file selection with the title ‘Choose Matlab executable file’.

  • The dialog starts in the user’s home directory.

  • If the user selects a file, sets the matlab_choice widget text to the selected file path.

browse_matlab_standalone()[source]

Opens a directory dialog for the user to select the MATLAB Compile Runtime (MCR) directory.

This method opens a directory selection dialog, allowing the user to choose the folder where the MATLAB Compiler Runtime (MCR) is installed. If a directory is selected, the path is displayed in the matlab_standalone_choice widget.

Note

  • Opens a QFileDialog for directory selection with the title ‘Choose MCR directory’.

  • The dialog starts in the user’s home directory.

  • If the user selects a directory, sets the matlab_standalone_choice widget text to the selected directory path.

browse_mia_config_path()[source]

Opens a directory dialog for the user to select a folder for installing the Mia configuration.

This method displays a dialog that allows the user to choose a directory in which the Mia configuration files will be installed. If a directory is selected, its path is displayed in the mia_config_path_choice widget.

Note

  • Opens a QFileDialog for directory selection with the title ‘Select a folder where to install Mia configuration’.

  • Starts the dialog in the user’s home directory.

  • If a directory is selected, updates the mia_config_path_choice widget text with the selected directory path.

browse_projects_path()[source]

Opens a directory dialog for the user to select a folder to store Mia’s projects.

This method opens a directory selection dialog, allowing the user to choose a folder where Mia’s projects will be stored. If a folder is selected, its path is displayed in the projects_path_choice widget.

Note

  • Opens a QFileDialog for directory selection with the title “Select a folder where to store Mia’s projects”.

  • Starts the dialog in the user’s home directory.

  • If a directory is selected, updates the projects_path_choice widget text with the selected folder path.

browse_spm()[source]

Opens a directory dialog for the user to select the SPM (Statistical Parametric Mapping) directory.

This method displays a directory selection dialog, allowing the user to choose the folder where the SPM software is installed. If a directory is selected, its path is displayed in the spm_choice widget.

Note

  • Opens a QFileDialog for directory selection with the title ‘Choose SPM directory’.

  • Starts the dialog in the user’s home directory.

  • If a directory is selected, updates the spm_choice widget text with the selected directory path.

browse_spm_standalone()[source]

Opens a directory dialog for the user to select the SPM (Statistical Parametric Mapping) standalone directory.

This method opens a directory selection dialog, allowing the user to choose the folder where the standalone version of SPM is installed. If a directory is selected, its path is displayed in the spm_standalone_choice widget.

Note

  • Opens a QFileDialog for directory selection with the title ‘Choose SPM standalone directory’.

  • Starts the dialog in the user’s home directory.

  • If a directory is selected, updates the spm_standalone_choice widget text with the selected directory path.

btnstate(button)[source]

Toggles the state of two related buttons based on the text of the clicked button.

This method manages the state of two buttons (host_target_push_button and casa_target_push_button) based on the text of the button that is clicked. If the button text is ‘Casa_Distro’, it ensures that the host_target_push_button is unchecked when the button is checked and vice versa. If the button text is ‘Host’, it ensures that the casa_target_push_button isunchecked when the button is checked and vice versa.

Parameters:

button (QPushButton) – The button that was clicked to trigger the state change.

Note

  • If the clicked button’s text is “Casa_Distro”, toggles the state of the host_target_push_button.

  • If the clicked button’s text is “Host”, toggles the state of the casa_target_push_button.

  • Ensures that when one button is checked, the other is unchecked.

clone_mia_resources(mia_resources_dir)[source]

Clones the mia_resources repository from GitLab to the specified directory.

This method uses git clone to download the mia_resources repository from the specified GitLab URL to the given local directory.

Parameters:

mia_resources_dir (str) – The directory where the mia_resources repository will be cloned.

Returns:

True if cloning succeeds, False otherwise.

Return type:

bool

find_matlab_path()[source]

Attempts to find the installation path of MATLAB on the system.

This method tries to locate the MATLAB installation by running the matlab command with specific options to retrieve the root directory of MATLAB. It checks if the path is valid and whether the MATLAB executable (matlab or matlab.exe) exists in the ‘bin’ directory under the root directory. If the executable is found, it returns the full path to the MATLAB executable.

If MATLAB cannot be found or an error occurs during the process, an empty string is returned.

Returns:

The path to the MATLAB executable if found, otherwise an empty string.

Return type:

str

Note

  • Runs the MATLAB command matlab -nodisplay -nosplash -nodesktop -r ‘disp(matlabroot); exit’ to obtain the root installation directory.

  • Checks for the existence of the MATLAB executable (matlab or matlab.exe) under the bin folder.

  • Returns the full path to the executable if found, or an empty string if not.

  • In case of an exception (e.g., MATLAB is not installed), prints a message and returns an empty string.

install()[source]

Manages the installation and configuration of Mia and associated software components.

This method performs the following steps:

  1. Installs populse_mia and mia_processes from PyPi.

  2. Checks the selected installation target (Host or Casa_Distro).

  3. Configures the operating mode (clinical or research).

  4. Optionally integrates with MATLAB and SPM based on user selections.

  5. Manages the creation and initialization of necessary directories and configuration files:

    • Creates the directory ~/.populse_mia if it does not exist and ensures the presence of configuration files.

    • Initializes user-specific directories for properties, processes, and projects.

    • Manages MRI conversion directories and resources.

  6. Prompts the user with warnings and asks for confirmation before overwriting existing directories if necessary.

  7. Clones required repositories (MRI conversion tools and mia_resources).

  8. Updates the configuration file with new paths and settings.

  9. Optionally upgrades packages (soma-base, soma-workflow, capsul) if the Host installation target is selected.

  10. Finalizes the installation and updates the GUI with the installation status.

The method requires user input via checkboxes and buttons to configure various aspects of the installation.

Note

  • host_target_push_button: Defines whether the host target installation is selected.

  • clinical_mode_push_button: Defines whether the clinical mode is selected.

  • use_matlab_checkbox: Defines whether MATLAB integration is enabled.

  • use_spm_checkbox: Defines whether SPM integration is enabled.

  • use_spm_standalone_checkbox: Defines whether standalone SPM integration is enabled.

  • mia_config_path_choice: Path for the configuration directory.

  • projects_path_choice: Path for the projects directory.

  • check_box_mia, check_box_mri_conv, check_box_config, check_box_pkgs: GUI elements for status display.

Raises:

Exception – If any unexpected issues arise during the directory creation or software installation steps.

install_matlab_api()[source]

Installs the MATLAB Engine API for Python.

This method attempts to install the MATLAB Engine API by calling pip install . in the MATLAB extern/engines/python directory. It temporarily changes the working directory to execute the installation command and then restores the directory.

Returns:

True if the installation succeeds, False otherwise.

Return type:

bool

Raises:

Note

  • self.matlab_path must be set to the MATLAB installation path.

  • This method uses subprocess.check_call() to run pip install . for compatibility with virtual environments.

install_package(package)[source]

Installs or upgrades a Python package using pip.

This method constructs a pip command to install or upgrade a specified package. It checks if the current environment is a virtual environment and, if not, adds the –user flag to the command to install the package for the current user.

The method executes the command using subprocess.check_call() to ensure that the package is installed or upgraded successfully.

Parameters:

package (str) – The name of the package to be installed or upgraded.

Raises:

subprocess.CalledProcessError – If the pip installation command fails.

last_layout()[source]

Sets the final layout for the application window after Mia installation.

This method constructs and sets the final user interface layout after the successful installation of Mia. It displays information about the installation paths and operating mode, along with a command to launch the application. Additionally, it provides a “Quit” button for the user to exit the window.

The layout includes the following elements:
  • A label confirming that Mia has been installed.

  • Paths for the Mia configuration, project storage MRI conversion, and Mia resources.

  • The operating mode used for the installation.

  • Command lines to launch Mia depending on the Python setup.

  • A “Quit” button to close the application.

It ensures that all widgets and layouts are properly added to the window, and that the layout is set as the main layout of the window.

make_mrifilemanager_folder(mri_conv_dir)[source]

Clones the MRI conversion repository into the specified directory.

Parameters:

mri_conv_dir (str) – The directory where the repository will be cloned.

Returns:

True if cloning succeeds, False otherwise.

Return type:

bool

ok_or_abort(button)[source]

Handles the action when the user clicks a button in a message box.

This method checks the role of the clicked button. If the “OK” button is clicked, it sets the folder_exists_flag to False. If any other button is clicked, it sets the folder_exists_flag to True.

Parameters:

button (QPushButton) – The button that was clicked in the message box.

Note

Modifies the folder_exists_flag (bool): A flag that indicates whether the folder exists based on the user’s response to the message box.

set_new_layout()[source]

Changes the layout to show the installation progress.

This method sets up a temporary layout to display the progress of the installation. It includes a label indicating the installation is ongoing, and checkboxes for tracking the status of various installation steps, such as installing Mia, MRIFileManager, writing the config file, and installing Python packages. The layout is then set as the current layout for the widget.

Note

Modifies the layout of the widget to reflect the installation status, with labels and checkboxes to indicate progress.

static uninstall_package(package)[source]

Uninstalls a Python package using pip.

This method attempts to uninstall a specified package using pip. It first tries to use the current Python interpreter (sys.executable) to uninstall the package. If an exception occurs (e.g., if pip is not available for the current interpreter), it falls back to using the pip3 command to uninstall the package.

Parameters:

package (str) – The name of the Python package to uninstall.

Raises:

subprocess.CalledProcessError – If the package uninstall command fails.

upgrade_soma_capsul()[source]

Upgrades the soma-base, soma-workflow, and capsul packages by cloning their latest versions from GitHub and reinstalling them.

This method performs the following steps:
  1. Creates a temporary directory to store the cloned repositories.

  2. Uninstalls the current versions of soma-base, soma-workflow, and capsul.

  3. Clones each package’s repository (soma-base, soma-workflow, and capsul) from GitHub.

  4. Installs the cloned package using the current Python interpreter with setup.py install.

If any step fails, an error message is printed, and the process continues to the next package. After the upgrades, the method returns to the original working directory and deletes the temporary directory.

Raises:

subprocess.CalledProcessError – If any command execution fails.

use_matlab_changed()[source]

Toggles the state of MATLAB-related options based on the ‘use_matlab’ checkbox.

When unchecked, all MATLAB and SPM options are disabled. Called when the use_matlab checkbox is changed.

use_spm_changed()[source]

Updates the state of SPM-related options based on the ‘use_spm’ checkbox.

When unchecked, disables all SPM options, and when checked, enables the regular SPM options while disabling the standalone SPM options.

Called when the use_spm checkbox is changed

use_spm_standalone_changed()[source]

Updates the state of standalone SPM-related options based on the ‘use_spm_standalone’ checkbox.

When checked, enables the standalone SPM options while disabling the regular SPM options, and vice versa. Called when the use_spm_standalone checkbox is changed