populse_mia.user_interface.pipeline_manager.process_library¶
Module that contains class and methods to process the different libraries of the project.
Functions
|
Import a Python module from a file without registering it in |
|
Construct a hierarchical node structure from a dictionary. |
Classes
|
Data model providing a tree structure for an arbitrary dictionary. |
|
Dialog for installing Python packages from a folder or zip file. |
|
A tree-like structure to manage hierarchical data with parent-child relationships. |
|
A tree widget that displays user-added packages and their modules. |
|
Dialog for managing package library configurations. |
|
A tree view to display available Capsul's processes. |
|
Widget that manages the available Capsul's processes in the software. |
- class populse_mia.user_interface.pipeline_manager.process_library.DictionaryTreeModel(root, parent=None)[source]¶
Bases:
QAbstractItemModelData model providing a tree structure for an arbitrary dictionary.
This model is designed to represent a dictionary as a tree structure, enabling interaction with the data through a tree view.
- Contains:
- Methods:
columnCount: Return always 1.
data: Return the data requested by the view.
flags: Everything is enabled and selectable, only the leaves can be dragged.
getNode: Return a Node() from given index.
headerData: Return the name of the requested column.
index: Return an index from given row, column and parent.
insertRows: Insert rows from starting position and number given by rows.
mimeData: Used when the widget is dragged by the user.
mimeTypes: Return a constant.
parent: return the parent from given index.
removeRows: Remove the rows from position to position+rows.
rowCount: The number of rows is the number of children.
setData: Method called when the user changes data.
to_dict: return the root node as a dictionary.
- __init__(root, parent=None)[source]¶
Initializes the DictionaryTreeModel with a root node.
- Parameters:
root (populse_mia.user_interface.pipeline_manager.process_library.Node) – The root node of the tree.
parent (Qt.QObject) – The parent object.
- columnCount(parent=None)[source]¶
Returns the number of columns, which is always 1.
- Parameters:
parent (QModelIndex) – The parent index (unused in this implementation).
- Returns:
The number of columns.
- Return type:
- data(index, role)[source]¶
Returns the data associated with the item at the given index and role.
This method is called by Qt’s model/view framework to retrieve data for a model item. The
rolespecifies how the data will be used, for example,Qt.DisplayRolefor displaying the item orQt.EditRolewhen editing it.- Parameters:
index (QModelIndex) – The model index of the item for which data is requested.
role (int) – The Qt item-data role specifying the type or purpose of the requested data, such as
Qt.DisplayRoleorQt.EditRole.
- Returns:
The item’s name for
Qt.DisplayRoleandQt.EditRole, orNoneif the index is invalid or the role is not handled.- Return type:
str | None
- flags(index)[source]¶
Get the item flags for the specified index.
- Parameters:
index (QModelIndex) – The model index to retrieve flags for.
- Returns:
The corresponding item flags.
- Return type:
- getNode(index)[source]¶
Retrieves the Node object from the given index.
- Parameters:
index (QModelIndex) – The index of the node.
- Returns:
The Node object.
- Return type:
populse_mia.user_interface.pipeline_manager.process_library.Node
- headerData(section, orientation, role)[source]¶
Returns the header label for the given section.
- Parameters:
section (int) – The section number for which to retrieve the header label.
orientation (Orientation) – The orientation of the header, either horizontal or vertical. This parameter is unused in this implementation.
role (int) – The role for which to retrieve the header data. Only
Qt.DisplayRoleis handled by this implementation.
- Returns:
The header label for the requested section, or None if the section or role is not handled.
- Return type:
str | None
- index(row, column, parent)[source]¶
Creates an index for the given row, column, and parent.
- Parameters:
row (int) – The row number.
column (int) – The column number.
parent (QModelIndex) – The parent index.
- Returns:
The created index, or an invalid index if not available.
- Return type:
- insertRows(position, rows, parent=<PyQt5.QtCore.QModelIndex object>)[source]¶
Inserts rows starting from the specified position.
- Parameters:
position (int) – The starting position to insert rows.
rows (int) – The number of rows to insert.
parent (QModelIndex) – The parent index.
- Returns:
True if the rows were successfully inserted, False otherwise.
- Return type:
- mimeData(indexes)[source]¶
Return MIME data for the specified model indexes.
The data associated with each valid index is encoded as bytes and concatenated into a single
QByteArray, which is stored under the"component/name"MIME type.- Parameters:
indexes (list[QModelIndex]) – The model indexes to include in the MIME data.
- Returns:
MIME data containing the encoded data associated with the specified indexes.
- Return type:
- parent(index)[source]¶
Returns the parent index for the given index.
- Parameters:
index (QModelIndex) – The index of the item.
- Returns:
The parent index, or an invalid index if not available.
- Return type:
- removeRows(position, rows, parent=<PyQt5.QtCore.QModelIndex object>)[source]¶
Removes rows starting from the specified position to position+rows.
- Parameters:
position (int) – The starting position to remove rows.
rows (int) – The number of rows to remove.
parent (QModelIndex) – The parent index.
- Returns:
True if all rows were successfully removed, False otherwise.
- Return type:
- rowCount(parent)[source]¶
Returns the number of rows, which corresponds to the number of children.
- Parameters:
parent (QModelIndex) – The parent index.
- Returns:
The number of rows.
- Return type:
- setData(index, value, role=2)[source]¶
Updates the data when the user makes changes.
- Parameters:
index (QModelIndex) – The index of the item.
value (str) – The new value to set.
role (ItemDataRole) – The role of the data to set.
- Returns:
True if the data was successfully set, False otherwise.
- Return type:
- class populse_mia.user_interface.pipeline_manager.process_library.InstallProcesses(main_window, folder)[source]¶
Bases:
QDialogDialog for installing Python packages from a folder or zip file.
This widget allows users to browse and select a Python package or zip file containing packages, then install them into Mia.
- Contains:
- Methods:
_add_package: Add a package and its modules to the process tree.
_change_pattern_in_folder: Replace pattern in all Python files within a folder.
_install_new_package: Install a new package.
_load_process_config: Load the process configuration from YAML.
_rollback_changes: Roll back changes in case of installation failure.
_show_qmessagebox: Display an error message box.
_show_status_message: Update status message in the main window.
_update_existing_package: Update an existing package.
_validate_input: Validate the input file or directory.
get_filename: Opens a file dialog to get the folder or zip file to install.
install: Installs the selected file/folder on Populse_mia.
- Signals:
process_installed: Signal emitted when a process is successfully installed.
- __init__(main_window, folder)[source]¶
Initialize the installation dialog.
- Parameters:
main_window (populse_mia.user_interface.main_window.MainWindow) – The main application window.
folder (bool) – If True, install from folder; if False, install from zip file.
- _change_pattern_in_folder(path, old_pattern, new_pattern)[source]¶
Replace pattern in all Python files within a folder.
- _rollback_changes(config_path, original_config, processes_path, package_names, mia_processes_not_found, tmp_folder4MIA)[source]¶
Roll back changes in case of installation failure.
- Parameters:
config_path (str) – Path to configuration file.
original_config (dict) – Original configuration to restore.
processes_path (str) – Path to processes directory.
package_names (list) – Names of packages that were being installed.
mia_processes_not_found (bool) – Flag indicating if Mia processes backup was made.
tmp_folder4MIA (str) – Path to Mia processes backup.
- _show_status_message(message)[source]¶
Update status message in the main window.
- Parameters:
message (str) – Status message to display.
- _update_existing_package(filename, package_name, processes_path)[source]¶
Update an existing package.
- get_filename(folder)[source]¶
Open a file dialog to select the package source.
- Parameters:
folder (bool) – If True, opens a directory selection dialog; If False, opens a zip file selection dialog.
- install()[source]¶
Install a package from a zip file or a folder.
- This method handles the complete installation process:
Extracts or copies the package to the processes directory.
Updates the process dictionary.
Registers the new package in the configuration.
Any exceptions during installation are caught and reported to the user, with automatic rollback of any changes made.
- class populse_mia.user_interface.pipeline_manager.process_library.Node(name, parent=None)[source]¶
Bases:
objectA tree-like structure to manage hierarchical data with parent-child relationships.
This class provides functionality to create and manipulate tree nodes, where each node can have a name, value, parent, and multiple children.
- Contains:
- Methods:
__repr__: Define what should be printed by the class.
_recurse_dict: Recursively build a dictionary representation of the node hierarchy.
addChild: Add a child to the children list.
attrs: Get attributes of this node as a dictionary.
child: Return a child from its index in the list.
childCount: return the number of children.
data: Return the name or the value of the object.
insertChild: Insert a child to a specific position.
log: Generate a formatted string representation of the node hierarchy.
name: Gets or sets the name of the node.
parent: Return the parent of the node.
removeChild: Remove a child node at the specified position.
resource: Placeholder that always returns None.
row: Return the index of the object in its parent list of children.
setData: Update the name or the value of the object.
to_dict: Convert the node hierarchy to a dictionary.
to_list: Convert the node hierarchy to a list.
value: Gets or sets the value of the node.
- __init__(name, parent=None)[source]¶
Initialize a new Node instance.
- Parameters:
name (str) – The name of the node.
parent (populse_mia.user_interface.pipeline_manager.process_library.Node | None) – The parent node. If provided, this node is automatically added to the parent’s list of children. Defaults to None.
- _recurse_dict(d)[source]¶
Recursively build a dictionary representation of the node hierarchy.
- Parameters:
d (dict) – The dictionary to populate with the node hierarchy.
- addChild(child)[source]¶
Add a child node to this node.
- Parameters:
child (populse_mia.user_interface.pipeline_manager.process_library.Node) – The child node to add.
- attrs()[source]¶
Get attributes of this node as a dictionary.
- Returns:
A dictionary of property names and their values.
- Return type:
- child(row)[source]¶
Get a child node by its index.
- Parameters:
row (int) – The index of the child node in the children list.
- Returns:
The child node at the specified index.
- Return type:
populse_mia.user_interface.pipeline_manager.process_library.Node
- childCount()[source]¶
Get the number of children of this node.
- Returns:
The number of child nodes.
- Return type:
- insertChild(position, child)[source]¶
Insert a child node at a specific position.
- Parameters:
position (int) – The position at which to insert the child.
child (populse_mia.user_interface.pipeline_manager.process_library.Node) – The child node to insert.
- Returns:
True if insertion was successful, False otherwise.
- Return type:
- parent()[source]¶
Get the parent of this node.
- Returns:
The parent node or None if this is a root node.
- Return type:
populse_mia.user_interface.pipeline_manager.process_library.Node | None
- removeChild(position, child)[source]¶
Remove a child node at the specified position.
- Parameters:
position (int) – The position of the child to remove.
child (populse_mia.user_interface.pipeline_manager.process_library.Node) – The child node to remove.
- Returns:
True if removal was successful, False otherwise.
- Return type:
- resource()[source]¶
Get resource information for this node.
This method is a placeholder that always returns None.
- Returns:
None.
- Return type:
None
- row()[source]¶
Get the index of this node in its parent’s children list.
- Returns:
The index of this node in its parent’s children list, or None if this node has no parent.
- Return type:
int | None
- class populse_mia.user_interface.pipeline_manager.process_library.PackageLibrary(package_tree, paths)[source]¶
Bases:
QTreeWidgetA tree widget that displays user-added packages and their modules.
This widget allows users to enable or disable packages and modules by checking or unchecking them in the tree view. The tree structure reflects the hierarchical organization of packages and their modules.
- Contains:
- Methods:
fill_item: fills the items of the tree recursively.
generate_tree: generates the package tree.
recursive_checks: checks/unchecks all child items.
recursive_checks_from_child: checks/unchecks all parent items.
set_module_view: sets if a module has to be enabled or disabled in the process library.
update_checks: updates the checks of the tree from an item.
- fill_item(item, value)[source]¶
Recursively populate the tree items.
Traverses the package tree and creates corresponding QTreeWidgetItems with appropriate check states.
- Parameters:
item (QTreeWidgetItem) – Current tree item to populate.
value (dict | list | str) – Value to populate the item with.
- generate_tree()[source]¶
Generate the package tree structure.
Clears the current tree and populates it with items from package_tree. Temporarily disconnects the itemChanged signal to prevent unwanted updates.
- recursive_checks(parent)[source]¶
Propagate check state down to all child items.
When a parent item is checked/unchecked, all its children inherit the same check state.
- Parameters:
parent (QTreeWidgetItem) – Parent item whose check state is propagated.
- recursive_checks_from_child(child)[source]¶
Propagate check state up to parent items.
When a child item is checked, its parents are also checked. When a child item is unchecked, its parent is unchecked only if all siblings are also unchecked.
- Parameters:
child (QTreeWidgetItem) – Child item whose check state affects parents.
- set_module_view(item, state)[source]¶
Update the enabled/disabled state of a module in the package tree.
Updates the underlying
package_treedata structure according to the check state of the module’s tree item.Qt.Checkedhas a value of 2, whileQt.Uncheckedhas a value of 0.- Parameters:
item (QTreeWidgetItem) – Tree item corresponding to a module.
state (CheckState) – New check state of the module, either
Qt.Checked(2) orQt.Unchecked(0).
- update_checks(item, column)[source]¶
Handle check state changes and propagate them.
When an item’s check state changes, this method ensures the change is properly propagated to children and parent items.
- Parameters:
item (QTreeWidgetItem) – Item whose check state changed.
column (int) – Column index of the change (should be 0).
- class populse_mia.user_interface.pipeline_manager.process_library.PackageLibraryDialog(mia_main_window=None, parent=None)[source]¶
Bases:
QDialogDialog for managing package library configurations.
This dialog allows users to add, remove, and delete packages from the process library. It provides interfaces for installing packages, updating the package tree, and saving configurations.
- Contains:
- Methods:
_create_button: Create a standardized button.
_create_install_buttons: Create buttons for installing processes.
_create_line_edit: Create and configure the line edit.
_create_list_group: Create a group box for a list with reset functionality.
_create_list_widget: Create a list widget with extended selection mode.
_create_main_layout: Create the main layout for the dialog.
_create_package_management_buttons: Create buttons for package management.
_create_save_cancel_layout: Create layout for save and cancel buttons.
_create_status_label: Create and configure the status label.
_load_initial_configuration: Load initial package configuration.
_setup_ui: Set up the user interface components
add_package: Add a package and its modules to the package tree.
add_package_with_text: Add a package from the line edit text.
browse_package: Open a browser to select a package (commented).
delete_package: Delete a package (admin-only functionality).
delete_package_with_text: Delete a package from the line edit text.
install_processes_pop_up: Open popup for installing processes.
load_config: Load package configuration from YAML file.
load_packages: Update the process library tree.
ok_clicked: Handle applying changes to packages.
remove_package: Remove a package from the package tree.
remove_package_with_text: Remove a package from the line edit text.
reset_action: Reset previous package addition or removal actions.
save: Save package configuration to process_config.yml.
save_config: save the current config to process_config.yml (commented).
update_config: Update package configuration and library attributes.
- Signals:
signal_save: Signal emitted when configuration is saved.
- __init__(mia_main_window=None, parent=None)[source]¶
Initialize the PackageLibraryDialog.
- Parameters:
mia_main_window (populse_mia.user_interface.main_window.MainWindow) – Reference to the main application window.
parent (populse_mia.user_interface.main_window.MainWindow | None) – Parent widget for the dialog.
- _create_button(text, callback)[source]¶
Create and configure a push button.
The button is configured not to be the dialog’s default button and not to become the default button automatically.
- Parameters:
text (str) – Text displayed on the button.
callback (callable) – Callback invoked when the button is clicked.
- Returns:
Configured push button.
- Return type:
- _create_install_buttons()[source]¶
Create buttons for installing processes.
- Returns:
Layout with install process buttons.
- Return type:
- _create_line_edit()[source]¶
Create and configure the line edit.
- Returns:
Configured line edit for package input.
- Return type:
- _create_list_group(title, list_widget, reset_callback)[source]¶
Create a group box for a list with reset functionality.
- Parameters:
title (str) – Group box title.
list_widget (QListWidget) – List widget to add to group.
reset_callback (callable) – Callback for reset button.
- Returns:
Configured group box with list and reset button.
- Return type:
- _create_list_widget()[source]¶
Create a list widget with extended selection mode.
- Returns:
Configured list widget.
- Return type:
- _create_main_layout(install_layout, management_layout, user_mode)[source]¶
Create the main layout for the dialog.
- Parameters:
install_layout (QHBoxLayout) – Layout for install buttons.
management_layout (QHBoxLayout) – Layout for package management buttons.
user_mode (bool) – Whether the application is in user mode.
- Returns:
Main layout of the dialog.
- Return type:
- _create_package_management_buttons(user_mode)[source]¶
Create buttons for package management.
- Parameters:
user_mode (bool) – Whether the application is in user mode.
- Returns:
Layout with package management buttons.
- Return type:
- _create_save_cancel_layout()[source]¶
Create layout for save and cancel buttons.
- Returns:
Layout with save and cancel buttons.
- Return type:
- _create_status_label()[source]¶
Create and configure the status label.
- Returns:
Configured status label.
- Return type:
- add_package(module_name, class_name=None, show_error=False, init_package_tree=False)[source]¶
Add a package and its modules to the package tree with comprehensive module and class discovery.
This method recursively discovers and adds packages, subpackages, and their classes to the package tree. It provides flexible options for package initialization and error handling.
- Parameters:
module_name (str) – Fully qualified name of the module to add. Example: ‘myproject.processors’
class_name (str | None) – Specific class name to focus on during package addition. If provided, only this class or its parent packages will be processed.
show_error (bool) – Controls error reporting behavior. If True, displays error messages in a QMessageBox. If False, collects errors silently. Defaults to False.
init_package_tree (bool) – If True, reinitializes the entire package tree before adding the module. Defaults to False.
- Returns:
A list of error messages encountered during package addition, or “No package selected!” if no module name is provided.
- Return type:
- add_package_with_text(package_name=False, update_view=True)[source]¶
Add a package to the Package Library.
This method attempts to add a package or module to the library based on the provided package name. It supports adding packages with or without file extensions, and handles various import scenarios.
- delete_package(index=1, to_delete=None, remove=True, loop=False, from_pipeline_manager=False)[source]¶
Delete a package from the library (admin-only functionality).
This method removes the package from the package library tree, updates the __init__.py file, and deletes the package directory and files if they are empty.
- Parameters:
index (int) – Recursive index for navigating modules. Defaults to 1.
to_delete (str | None) – The package / brick to delete (e.g., ‘test.Test’). Defaults to None.
remove (bool) – Whether to remove the brick from the package tree. Defaults to True.
loop (bool) – Whether to delete silently without confirmation. Defaults to False.
from_pipeline_manager (bool) – Whether deletion is initiated from pipeline manager. Defaults to False.
- Returns:
A list of deleted packages/bricks (classes).
- Return type:
- delete_package_with_text(package_name='', update_view=True)[source]¶
Delete a package from the line edit’s text.
- install_processes_pop_up(from_folder=False)[source]¶
Display the install processes pop-up.
- Parameters:
from_folder (bool) – Whether the installation is from a folder. Defaults to False.
- static load_config()[source]¶
Load the process configuration from
process_config.yml.The configuration file is searched for in the
propertiesdirectory of the configured properties path. If the file cannot be read or parsed, an empty dictionary is returned and a warning is logged.- Returns:
The loaded configuration dictionary, or an empty dictionary if the configuration cannot be loaded.
- Return type:
- remove_package(package)[source]¶
Removes a package from the package tree.
This method attempts to remove the specified package from the package library. If the package is not found, a warning message is displayed. The package tree is updated after a successful removal.
- remove_package_with_text(package_name='', update_view=True, tree_remove=True)[source]¶
Removes the specified package from the package tree and updates the view accordingly.
- Parameters:
- reset_action(itemlist, add)[source]¶
Resets a previous package addition or removal action.
- Parameters:
itemlist (QListWidget) – The list widget containing items to reset.
add (bool) – If True, resets an addition by removing the package if it exists in the configuration. If False, re-adds the package.
- save(close=True)[source]¶
Saves the package library configuration to process_config.yml.
This method updates the package information from the package library tree and writes it to the configuration file. Optionally, it can close the dialog after saving.
- Parameters:
close (bool) – If True, closes the dialog after saving. Defaults to True.
- class populse_mia.user_interface.pipeline_manager.process_library.ProcessLibrary(d, pkg_lib)[source]¶
Bases:
QTreeViewA tree view to display available Capsul’s processes.
- Contains:
- Methods:
keyPressEvent: Event when the delete key is pressed.
load_dictionary: Loads a dictionary to the tree.
mousePressEvent: Event when the mouse is pressed.
to_dict: Returns a dictionary from the current tree.
- Signals:
item_library_clicked: Signal emitted when an item in the library is clicked.
- __init__(d, pkg_lib)[source]¶
Initialize the ProcessLibrary class.
- Parameters:
d (dict) – Dictionary corresponding to the tree.
pkg_lib (PackageLibraryDialog) – Package library dialog associated with this process library.
- keyPressEvent(event)[source]¶
Handles key press events, specifically the Delete key.
If the Delete key is pressed and the user is not in user mode, the selected package(s) will be deleted from the package library.
- Parameters:
event (QKeyEvent) – The key event triggering this handler.
- load_dictionary(d)[source]¶
Load a dictionary into the tree.
- Parameters:
d (dict) – Dictionary to load. See the packages attribute in the ProcessLibraryWidget class.
- mousePressEvent(event)[source]¶
Handles mouse press events on the tree view.
If a valid item is clicked, it sets the current index and emits a signal with the selected item’s text. If the right mouse button is pressed, a context menu is displayed, allowing the user to remove or delete a package.
- Parameters:
event (QMouseEvent) – The mouse event triggering this handler.
- class populse_mia.user_interface.pipeline_manager.process_library.ProcessLibraryWidget(main_window=None)[source]¶
Bases:
QWidgetWidget that manages the available Capsul’s processes in the software.
- Contains:
- Methods:
_configure_process_library: Configure the process library settings.
_setup_layout: Setup the layout for the widget.
load_config: Read the config in process_config.yml and return it as a dictionary.
load_packages: Set packages and paths to the widget and to the system paths.
open_pkg_lib: Open the package library.
save_config: Save the current config to process_config.yml. (commented)
update_config: Update the config and loads the corresponding packages.
update_process_library: Update the tree of the process library.
- __init__(main_window=None)[source]¶
Initialize the ProcessLibraryWidget.
- Parameters:
main_window (populse_mia.user_interface.main_window.MainWindow) – The current main window.
- populse_mia.user_interface.pipeline_manager.process_library.import_file(full_name, path)[source]¶
Import a Python module from a file without registering it in
sys.modules.Creates a module specification from the specified file, creates the corresponding module object, and executes the module using its loader.
- Parameters:
- Returns:
The imported module.
- Return type:
- populse_mia.user_interface.pipeline_manager.process_library.node_structure_from_dict(datadict, parent=None, root_node=None)[source]¶
Construct a hierarchical node structure from a dictionary.
This function converts a nested dictionary into a tree structure suitable for a TreeModel. It processes nodes based on specific conditions and recursively builds the tree.
- Parameters:
datadict (dict) – The dictionary to convert into a node structure.
parent (populse_mia.user_interface.pipeline_manager.process_library.Node | None) – The parent node of the current node. Defaults to None.
root_node (populse_mia.user_interface.pipeline_manager.process_library.Node | None) – The root node of the tree. Defaults to None.
- Returns:
The root node of the constructed tree.
- Return type:
populse_mia.user_interface.pipeline_manager.process_library.Node | None