populse_mia.user_interface.pipeline_manager.pipeline_editor

Module that executes the actions in the pipeline manager menu and allows to graphically modify a pipeline.

Contains:

Class:
  • PipelineEditor

  • PipelineEditorTabs

Function:
  • find_filename

  • get_path

  • save_pipeline

Functions

find_filename(paths_list, packages_list, ...)

Locate a pipeline file within configured paths.

get_path(name, dictionary[, prev_paths, pckg])

Recursively search for a module name inside a nested dictionary structure and return its full path as a list of keys.

save_pipeline(pipeline, filename)

Save a pipeline to a file in the appropriate format.

Classes

PipelineEditor(project, main_window)

Graphical editor for creating, editing, and managing pipelines.

PipelineEditorTabs(project, scan_list, ...)

Tab widget for managing multiple pipeline editors.

class populse_mia.user_interface.pipeline_manager.pipeline_editor.Path(*args, **kwargs)[source]

Bases: PurePath

PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.

stat(*, follow_symlinks=True)[source]

Return the result of the stat() system call on this path, like os.stat() does.

lstat()[source]

Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.

exists(*, follow_symlinks=True)[source]

Whether this path exists.

This method normally follows symlinks; to check whether a symlink exists, add the argument follow_symlinks=False.

is_dir()[source]

Whether this path is a directory.

is_file()[source]

Whether this path is a regular file (also True for symlinks pointing to regular files).

is_mount()[source]

Check if this path is a mount point

Whether this path is a symbolic link.

is_junction()[source]

Whether this path is a junction.

is_block_device()[source]

Whether this path is a block device.

is_char_device()[source]

Whether this path is a character device.

is_fifo()[source]

Whether this path is a FIFO.

is_socket()[source]

Whether this path is a socket.

samefile(other_path)[source]

Return whether other_path is the same or not as this file (as returned by os.path.samefile()).

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]

Open the file pointed to by this path and return a file object, as the built-in open() function does.

read_bytes()[source]

Open the file in bytes mode, read it, and close the file.

read_text(encoding=None, errors=None)[source]

Open the file in text mode, read it, and close the file.

write_bytes(data)[source]

Open the file in bytes mode, write to it, and close the file.

write_text(data, encoding=None, errors=None, newline=None)[source]

Open the file in text mode, write to it, and close the file.

iterdir()[source]

Yield path objects of the directory contents.

The children are yielded in arbitrary order, and the special entries ‘.’ and ‘..’ are not included.

_scandir()[source]
_make_child_relpath(name)[source]
glob(pattern, *, case_sensitive=None)[source]

Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.

rglob(pattern, *, case_sensitive=None)[source]

Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.

walk(top_down=True, on_error=None, follow_symlinks=False)[source]

Walk the directory tree from this directory, similar to os.walk().

__init__(*args, **kwargs)[source]
classmethod cwd()[source]

Return a new path pointing to the current working directory.

classmethod home()[source]

Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

absolute()[source]

Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.

Use resolve() to get the canonical path to a file.

resolve(strict=False)[source]

Make the path absolute, resolving all symlinks on the way and also normalizing it.

owner()[source]

Return the login name of the file owner.

group()[source]

Return the group name of the file gid.

Return the path to which the symbolic link points.

touch(mode=438, exist_ok=True)[source]

Create this file with the given access mode, if it doesn’t exist.

mkdir(mode=511, parents=False, exist_ok=False)[source]

Create a new directory at this given path.

chmod(mode, *, follow_symlinks=True)[source]

Change the permissions of the path, like os.chmod().

lchmod(mode)[source]

Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.

Remove this file or link. If the path is a directory, use rmdir() instead.

rmdir()[source]

Remove this directory. The directory must be empty.

rename(target)[source]

Rename this path to the target path.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.

replace(target)[source]

Rename this path to the target path, overwriting if that path exists.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.

Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.

Make this path a hard link pointing to the same file as target.

Note the order of arguments (self, target) is the reverse of os.link’s.

expanduser()[source]

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

exception populse_mia.user_interface.pipeline_manager.pipeline_editor.TraitError(args=None, name=None, info=None, value=None)[source]

Bases: Exception

__init__(args=None, name=None, info=None, value=None)[source]
set_desc(desc, object=None)[source]
set_prefix(prefix)[source]
set_args()[source]
class populse_mia.user_interface.pipeline_manager.pipeline_editor.Node(pipeline, name, inputs, outputs)[source]

Bases: Controller

Basic Node structure of the pipeline that need to be tuned.

It is possible to define custom nodes inheriting Node. To be usable in all contexts (GUI construction, pipeline save / reload), custom nodes should define a few additional instance and class methods which will allow automatic systems (such as get_node_instance()) to reinstantiate and save them:

  • configure_controller(cls): classmethod

    return a Controller instance which specifies parameters needed to build the node instance. Typically it may contain a parameters (plugs) list and other specifications.

  • configured_controller(self): instance method:

    on an instance, returns a Controller instance in the same shape as configure_controller above, but with values filled from the instance. This controller will allow saving parameters needed to instantiate again the node with the same state.

  • build_node(cls, pipeline, name, conf_controller): class method

    returns an instance of the node class, built using appropriate parameters (using configure_controller() or configured_controller() from another instance)

name

the node name

Type:

str

full_name

a unique name among all nodes and sub-nodes of the top level pipeline

Type:

str

enabled

user parameter to control the node activation

Type:

bool

activated

parameter describing the node status

Type:

bool

connect()[source]
set_callback_on_plug()[source]
get_plug_value()[source]
set_plug_value()[source]
get_trait()[source]
__init__(pipeline, name, inputs, outputs)[source]

Generate a Node

Parameters:
  • pipeline (Pipeline (mandatory)) – the pipeline object where the node is added

  • name (str (mandatory)) – the node name

  • inputs (list of dict (mandatory)) – a list of input parameters containing a dictionary with default values (mandatory key: name)

  • outputs (dict (mandatory)) – a list of output parameters containing a dictionary with default values (mandatory key: name)

property process
property full_name
static _value_callback(self, source_plug_name, dest_node, dest_plug_name, value)[source]

Spread the source plug value to the destination plug.

_value_callback_with_logging(log_stream, prefix, source_plug_name, dest_node, dest_plug_name, value)[source]

Spread the source plug value to the destination plug, and log it in a stream for debugging.

connect(source_plug_name, dest_node, dest_plug_name)[source]

Connect linked plugs of two nodes

Parameters:
  • source_plug_name (str (mandatory)) – the source plug name

  • dest_node (Node (mandatory)) – the destination node

  • dest_plug_name (str (mandatory)) – the destination plug name

disconnect(source_plug_name, dest_node, dest_plug_name, silent=False)[source]

disconnect linked plugs of two nodes

Parameters:
  • source_plug_name (str (mandatory)) – the source plug name

  • dest_node (Node (mandatory)) – the destination node

  • dest_plug_name (str (mandatory)) – the destination plug name

  • silent (bool) – if False, do not fire an exception if the connection does not exust (perhaps already disconnected

_pipeline_deleted(pipeline)[source]
cleanup()[source]

cleanup before deletion

disconnects all plugs, remove internal and cyclic references

set_callback_on_plug(plug_name, callback)[source]

Add an event when a plug change

Parameters:
  • plug_name (str (mandatory)) – a plug name

  • callback (@f (mandatory)) – a callback function

remove_callback_from_plug(plug_name, callback)[source]

Remove an event when a plug change

Parameters:
  • plug_name (str (mandatory)) – a plug name

  • callback (@f (mandatory)) – a callback function

get_plug_value(plug_name)[source]

Return the plug value

Parameters:

plug_name (str (mandatory)) – a plug name

Returns:

output – the plug value

Return type:

object

set_plug_value(plug_name, value, protected=None)[source]

Set the plug value

Parameters:
  • plug_name (str (mandatory)) – a plug name

  • value (object (mandatory)) – the plug value we want to set

  • protected (None or bool (tristate)) – if True or False, force the “protected” status of the plug. If None, keep it as is.

get_trait(trait_name)[source]

Return the desired trait

Parameters:

trait_name (str (mandatory)) – a trait name

Returns:

output – the trait named trait_name

Return type:

trait

get_connections_through(plug_name, single=False)[source]

If the node has internal links (inside a pipeline, or in a switch or other custom connection node), return the “other side” of the internal connection to the selected plug. The returned plug may be in an internal node (in a pipeline), or in an external node connected to the node. When the node is “opaque” (no internal connections), it returns the input plug. When the node is inactive / disabled, it returns [].

Parameters:
  • plug_name (str) – plug to get connections with

  • single (bool) – if True, stop at the first connected plug. Otherwise return the list of all connected plugs.

Returns:

[(node, plug_name, plug), …] Returns [(self, plug_name, plug)] when the plug has no internal connection.

Return type:

connected_plug; list of tuples

is_job()[source]

if True, the node will be represented as a Job in Soma-Workflow. Otherwise the node is static and does not run.

requirements()[source]

Requirements needed to run the node. It is a dictionary which keys are config/settings modules and values are requests for them.

The default implementation returns an empty dict (no requirements), and should be overloaded by processes which actually have requirements.

Ex:

{'spm': 'version >= "12" and standalone == "True"')
check_requirements(environment='global', message_list=None)[source]

Checks the process requirements against configuration settings values in the attached CapsulEngine. This makes use of the requirements() method and checks that there is one matching config value for each required module.

Parameters:
  • environment (str) – config environment id. Normally corresponds to the computing resource name, and defaults to “global”.

  • message_list (list) – if not None, this list will be updated with messages for unsatisfied requirements, in order to present the user with an understandable error.

Returns:

config – if None is returned, requirements are not met: the process cannot run. If a dict is returned, it corresponds to the matching config values. When no requirements are needed, an empty dict is returned. A pipeline, if its requirements are met will return a list of configuration values, because different nodes may require different config values.

Return type:

dict, list, or None

get_missing_mandatory_parameters(exclude_links=False)[source]

Returns a list of parameters which are not optional, and which value is Undefined or None, or an empty string for a File or Directory parameter.

Parameters:

exclude_links (bool) – if True, an empty parameter which has a link to another node will not be reported missing, since the execution will assign it a temporary value which will not prevent the pipeline from running.

get_study_config()[source]

Get (or create) the StudyConfig this process belongs to

set_study_config(study_config)[source]

Set the StudyConfig this process belongs to

class populse_mia.user_interface.pipeline_manager.pipeline_editor.PipelineNode(pipeline, name, process, **kwargs)[source]

Bases: ProcessNode

A special node to store the pipeline user-parameters

get_connections_through(plug_name, single=False)[source]

If the node has internal links (inside a pipeline, or in a switch or other custom connection node), return the “other side” of the internal connection to the selected plug. The returned plug may be in an internal node (in a pipeline), or in an external node connected to the node. When the node is “opaque” (no internal connections), it returns the input plug. When the node is inactive / disabled, it returns [].

Parameters:
  • plug_name (str) – plug to get connections with

  • single (bool) – if True, stop at the first connected plug. Otherwise return the list of all connected plugs.

Returns:

[(node, plug_name, plug), …] Returns [(self, plug_name, plug)] when the plug has no internal connection.

Return type:

connected_plug; list of tuples

class populse_mia.user_interface.pipeline_manager.pipeline_editor.Process(**kwargs)[source]

Bases: Controller

A process is an atomic component that contains a processing.

A process is typically an object with typed parameters, and an execution function. Parameters are described using Enthought traits through Soma-Base Controller base class.

In addition to describing its parameters, a Process must implement its execution function, either through a python method, by overloading _run_process(), or through a commandline execution, by overloading get_commandline(). The second way allows to run on a remote processing machine which has not necessary capsul, nor python, installed.

Parameters are declared or queried using the traits API, and their values are in the process instance variables:

from __future__ import print_function
from capsul.api import Process
import traits.api as traits

class MyProcess(Process):

    # a class trait
    param1 = traits.Str('def_param1')

    def __init__(self):
        super(MyProcess, self).__init__()
        # declare an input param
        self.add_trait('param2', traits.Int())
        # declare an output param
        self.add_trait('out_param', traits.File(output=True))

    def _run_process(self):
        with open(self.out_param, 'w') as f:
            print('param1:', self.param1, file=f)
            print('param2:', self.param2, file=f)

# run it with parameters
MyProcess()(param2=12, out_param='/tmp/log.txt')

Note about the File and Directory traits

The File trait type represents a file parameter. A file is actually two things: a filename (string), and the file itself (on the filesystem). For an input it is OK not to distinguish them, but for an output, there are two different cases:

  • the file (on the filesystem) is an output, but the filename (string) is given as an input: this is the classical “commandline” behavior, when we tell the program where it should write its output file.

  • the file is an output, and the filename is also an output: this is rather a “function return value” behavior: the process determines internally where it should write the file, and tells as an output where it did.

To distinguish these two cases, in Capsul we normally add in the File or Directory trait a property input_filename which is True when the filename is an input, and False when the filename is an output:

self.add_trait('out_file',
               traits.File(output=True, input_filename=False))

However, as most of our processes are based on the “commandline behavior” (the filename is an input) and we often forget to specify the input_filename parameter, the default is the “filename is an input” behavior, when not specified.

Attributes

name

the class name.

Type:

str

id

the string description of the class location (ie., module.class).

Type:

str

log_file

if None, the log will be generated in the current directory otherwise it will be written in log_file path.

Type:

str (default None)

Note

  • Type ‘Process.help()’ for a full description of this process parameters.

  • Type ‘<Process>.get_input_spec()’ for a full description of this process input trait types.

  • Type ‘<Process>.get_output_spec()’ for a full description of this process output trait types.

__init__(**kwargs)[source]

Initialize the Process class.

add_trait(name, trait)[source]

Ensure that trait.output and trait.optional are set to a boolean value before calling parent class add_trait.

run(**kwargs)[source]

Obsolete: use self.__call__ instead

_run_process()[source]

Runs the processings when the instance is called.

Either this _run_process() or get_commandline() must be defined in derived classes.

Note that _run_process() is called as a python function, on a Process instance. When using remote processing (cluster for instance), this means that the commandline which will run needs to be able to re- instantiate the same process: the process thus has to be stored in a file or python module which can be accessed from the remote machine, and python / capsul correctly installed and available on it.

get_commandline() at the contrary, can implement commandlines which are completely independent from Capsul, and from python.

Note

If both methods are not defined in the derived class a NotImplementedError error is raised.

On the other side, if both methods are overloaded, the process behavior in local sequential computing mode and in Soma-Workflow modes may be different.

_before_run_process()[source]

This method is called by StudyConfig.run() before calling _run_process(). By default, it does nothing but can be overridden in derived classes.

_after_run_process(run_process_result)[source]

This method is called by StudyConfig.run() after calling _run_process(). It is expected to return the final result of the process. By default, it does nothing but can be overridden in derived classes.

_get_log(exec_info)[source]

Method that generate the logging structure from the execution information and class attributes.

Parameters:

exec_info (dict (mandatory)) – the execution information, the dictionary is supposed to contain a runtime attribute.

Returns:

log – the logging information.

Return type:

dict

_rst_table(data)[source]

Create a rst formatted table.

Parameters:

data (list of lists of str (mandatory)) – the table line-cell centent.

Returns:

rsttable – the rst formatted table containing the input data.

Return type:

list of str

save_log(returncode)[source]

Method to save process execution information in json format.

If the class attribute log_file is not set, a log.json output file is generated in the process call current working directory.

Parameters:

returncode (ProcessResult) – the process result return code.

classmethod help(returnhelp=False)[source]

Method to print the full help.

Parameters:
  • cls (process class (mandatory)) – a process class

  • returnhelp (bool (optional, default False)) – if True return the help string message, otherwise display it on the console.

get_commandline()[source]

Method to generate a commandline representation of the process.

If not implemented, it will generate a commandline running python, instantiating the current process, and calling its _run_process() method.

Returns:

commandline – Arguments are in separate elements of the list.

Return type:

list of strings

params_to_command()[source]

Generates a commandline representation of the process.

If not implemented, it will generate a commandline running python, instantiating the current process, and calling its _run_process() method.

This method is new in Capsul v3 and is a replacement for get_commandline().

It can be overwritten by custom Process subclasses. Actually each process should overwrite either params_to_command() or _run_process().

The returned commandline is a list, which first element is a “method”, and others are the actual commandline with arguments. There are several methods, the process is free to use either of the supported ones, depending on how the execution is implemented.

Methods:

capsul_job: Capsul process run in python

The command will run the _run_process() execution method of the process, after loading input parameters from a JSON dictionary file. The only second element in the commandline list is the process identifier (module/class as in get_process_instance()). The location of the JSON file will be passed to the job execution through an environment variable SOMAWF_INPUT_PARAMS:

return ['capsul_job', 'morphologist.capsul.morphologist']
format_string: free commandline with replacements for parameters

Command arguments can be, or contain, format strings in the shape ‘%(param)s’, where param is a parameter of the process. This way we can map values correctly, and call a foreign command:

return ['format_string', 'ls', '%(input_dir)s']
json_job: free commandline with JSON file for input parameters

A bit like capsul_job but without the automatic wrapper:

return ['json_job', 'python', '-m', 'my_module']
Returns:

commandline – Arguments are in separate elements of the list.

Return type:

list of strings

make_commandline_argument(*args)[source]

This helper function may be used to build non-trivial commandline arguments in get_commandline implementations. Basically it concatenates arguments, but it also takes care of keeping track of temporary file objects (if any), and converts non-string arguments to strings (using repr()).

Ex:

>>> process.make_commandline_argument('param=', self.param)

will return the same as:

>>> 'param=' + self.param

if self.param is a string (file name) or a temporary path.

static run_from_commandline(process_definition)[source]

Run a process from a commandline call. The process name (with module) are given in argument, input parameters should be passed through a JSON file which location is in the SOMAWF_INPUT_PARAMS environment variable.

If the process has outputs, the SOMAWF_OUTUT_PARAMS environment variable should contain the location of an output file which will be written with a dict containing output parameters values.

get_log()[source]

Load the logging file.

Returns:

log – the content of the log file.

Return type:

dict

get_input_spec()[source]

Method to access the process input specifications.

Returns:

outputs – a string representation of all the input trait specifications.

Return type:

str

get_output_spec()[source]

Method to access the process output specifications.

Returns:

outputs – a string representation of all the output trait specifications.

Return type:

str

get_inputs()[source]

Method to access the process inputs.

Returns:

outputs – a dictionary with all the input trait names and values.

Return type:

dict

get_outputs()[source]

Method to access the process outputs.

Returns:

outputs – a dictionary with all the output trait names and values.

Return type:

dict

get_help(returnhelp=False, use_labels=False)[source]

Generate description of a process parameters.

Parameters:
  • returnhelp (bool (optional, default False)) – if True return the help string message formatted in rst, otherwise display the raw help string message on the console.

  • use_labels (bool) – if True, input and output sections will get a RestructuredText label to avoid ambiguities.

get_input_help(rst_formating=False)[source]

Generate description for process input parameters.

Parameters:

rst_formating (bool (optional, default False)) – if True generate a rst table with the input descriptions.

Returns:

helpstr – the class input traits help

Return type:

str

get_output_help(rst_formating=False)[source]

Generate description for process output parameters.

Parameters:

rst_formating (bool (optional, default False)) – if True generate a rst table with the input descriptions.

Returns:

helpstr – the trait output help descriptions

Return type:

str

set_parameter(name, value, protected=None)[source]

Method to set a process instance trait value.

For File and Directory traits the None value is replaced by the special Undefined trait value.

Parameters:
  • name (str (mandatory)) – the trait name we want to modify

  • value (object (mandatory)) – the trait value we want to set

  • protected (None or bool (tristate)) – if True or False, force the “protected” status of the plug. If None, keep it as is.

get_parameter(name)[source]

Method to access the value of a process instance.

Parameters:

name (str (mandatory)) – the trait name we want to modify

Returns:

value – the trait value we want to access

Return type:

object

get_study_config()[source]

Get (or create) the StudyConfig this process belongs to

set_study_config(study_config)[source]

Set a StudyConfig for the process. Note that it can only be done once: once a non-null StudyConfig has been assigned to the process, it should not change.

get_missing_mandatory_parameters()[source]

Returns a list of parameters which are not optional, and which value is Undefined or None, or an empty string for a File or Directory parameter.

requirements()[source]

Requirements needed to run the process. It is a dictionary which keys are config/settings modules and values are requests for them.

The default implementation returns an empty dict (no requirements), and should be overloaded by processes which actually have requirements.

Ex:

{'spm': 'version >= "12" and standalone == "True"')
check_requirements(environment='global', message_list=None)[source]

Checks the process requirements against configuration settings values in the attached CapsulEngine. This makes use of the requirements() method and checks that there is one matching config value for each required module.

Parameters:
  • environment (str) – config environment id. Normally corresponds to the computing resource name, and defaults to “global”.

  • message_list (list) – if not None, this list will be updated with messages for unsatisfied requirements, in order to present the user with an understandable error.

Returns:

config – if None is returned, requirements are not met: the process cannot run. If a dict is returned, it corresponds to the matching config values. When no requirements are needed, an empty dict is returned. A pipeline, if its requirements are met will return a list of configuration values, because different nodes may require different config values.

Return type:

dict, list, or None

class populse_mia.user_interface.pipeline_manager.pipeline_editor.Switch(pipeline, name, inputs, outputs, make_optional=(), output_types=None)[source]

Bases: Node

Switch node to select a specific Process.

A switch commutes a group of inputs to its outputs, according to its “switch” trait value. Each group may be typically linked to a different process. Processes not “selected” by the switch are disabled, if possible. Values are also propagated through inputs/outputs of the switch (see below).

Inputs / outputs:

Say the switch “my_switch” has 2 outputs, “param1” and “param2”. It will be connected to the outputs of 2 processing nodes, “node1” and “node2”, both having 2 outputs: node1.out1, node1.out2, node2.out1, node2.out2. The switch will thus have 4 entries, in 2 groups, named for instance “node1” and “node2”. The switch will link the outputs of node1 or node2 to its outputs. The switch inputs will be named as follows:

  • 1st group: “node1_switch_param1”, “node1_switch_param2”

  • 2nd group: “node2_switch_param1”, “node2_switch_param2”

  • When my_switch.switch value is “node1”, my_switch.node1_switch_param1 is connected to my_switch.param1 and my_switch.node1_switch_param2 is connected to my_switch.param2. The processing node node2 is disabled (unselected).

  • When my_switch.switch value is “node2”, my_switch.node2_switch_param1 is connected to my_switch.param1 and my_switch.node2_switch_param2 is connected to my_switch.param2. The processing node node1 is disabled (unselected).

Values propagation:

  • When a switch is activated (its switch parameter is changed), the outputs will reflect the selected inputs, which means their values will be the same as the corresponding inputs.

  • But in many cases, parameters values will be given from the output (if the switch output is one of the pipeline outputs, this one will be visible from the “outside world, not the switch inputs). In this case, values set as a switch input propagate to its inputs.

  • An exception is when a switch input is linked to the parent pipeline inputs: its value is also visible from “outside” and should not be set via output values via the switch. In this specific case, output values are not propagated to such inputs.

Notes

Switch is normally not instantiated directly, but from a pipeline pipeline_definition method

_switch_values

the switch options

Type:

list

_outputs

the switch output parameters

Type:

list

See also

_switch_changed, _anytrait_changed, capsul.pipeline.pipeline.Pipeline.add_switch, capsul.pipeline.pipeline.Pipeline.pipeline_definition

_doc_path = 'api/pipeline.html#capsul.pipeline.pipeline_nodes.Switch'
__init__(pipeline, name, inputs, outputs, make_optional=(), output_types=None)[source]

Generate a Switch Node

Warning

The input plug names are built according to the following rule: <input_name>_switch_<output_name>

Parameters:
  • pipeline (Pipeline (mandatory)) – the pipeline object where the node is added

  • name (str (mandatory)) – the switch node name

  • inputs (list (mandatory)) – a list of options

  • outputs (list (mandatory)) – a list of output parameters

  • make_optional (sequence (optional)) – list of optional outputs. These outputs will be made optional in the switch output. By default they are mandatory.

  • output_types (sequence of traits (optional)) – If given, this sequence should have the same size as outputs. It will specify each switch output parameter type (as a standard trait). Input parameters for each input block will also have this type.

_switch_changed(old_selection, new_selection)[source]

Add an event to the switch trait that enables us to select the desired option.

Parameters:
  • old_selection (str (mandatory)) – the old option

  • new_selection (str (mandatory)) – the new option

connections()[source]

Returns the current internal connections between input and output plugs

Returns:

connections – list of internal connections [(input_plug_name, output_plug_name), …]

Return type:

list

_anytrait_changed(name, old, new)[source]

Add an event to the switch trait that enables us to select the desired option.

Propagates value through the switch, from in put to output if the switch state corresponds to this input, or from output to inputs.

Parameters:
  • name (str (mandatory)) – the trait name

  • old (str (mandatory)) – the old value

  • new (str (mandatory)) – the new value

get_connections_through(plug_name, single=False)[source]

If the node has internal links (inside a pipeline, or in a switch or other custom connection node), return the “other side” of the internal connection to the selected plug. The returned plug may be in an internal node (in a pipeline), or in an external node connected to the node. When the node is “opaque” (no internal connections), it returns the input plug. When the node is inactive / disabled, it returns [].

Parameters:
  • plug_name (str) – plug to get connections with

  • single (bool) – if True, stop at the first connected plug. Otherwise return the list of all connected plugs.

Returns:

[(node, plug_name, plug), …] Returns [(self, plug_name, plug)] when the plug has no internal connection.

Return type:

connected_plug; list of tuples

is_job()[source]

if True, the node will be represented as a Job in Soma-Workflow. Otherwise the node is static and does not run.

get_switch_inputs()[source]
classmethod configure_controller()[source]
configured_controller()[source]
classmethod build_node(pipeline, name, conf_controller)[source]
populse_mia.user_interface.pipeline_manager.pipeline_editor.get_process_instance(process_or_id, study_config=None, **kwargs)[source]

Return a Process instance given an identifier.

Note that it is convenient to create a process from a StudyConfig instance: StudyConfig.get_process_instance()

The identifier is either:

  • a derived Process class.

  • a derived Process class instance.

  • a Nipype Interface instance.

  • a Nipype Interface class.

  • a string description of the class <module>.<class>.

  • a string description of a function to warp <module>.<function>.

  • a string description of a module containing a single process <module>

  • a string description of a pipeline <module>.<fname>.xml.

  • an XML filename for a pipeline.

  • a JSON filename for a pipeline.

  • a Python (.py) filename with process name in it: /path/process_source.py#ProcessName.

  • a Python (.py) filename for a file containing a single process.

Default values of the process instance are passed as additional parameters.

Parameters:
  • process_or_id (instance or class description (mandatory)) – a process/nipype interface instance/class or a string description.

  • study_config (StudyConfig instance (optional)) – A Process instance belongs to a StudyConfig framework. If not specified the study_config can be set afterwards.

  • kwargs – default values of the process instance parameters.

Returns:

result – an initialized process instance.

Return type:

Process

class populse_mia.user_interface.pipeline_manager.pipeline_editor.ProcessCompletionEngine(process, name=None)[source]

Bases: HasTraits

Parameters completion from attributes for a process or pipeline node instance, in the context of a specific data organization.

ProcessCompletionEngine can be used directly for a pipeline, which merely delegates completion to its nodes, and has to be subclassed for a data organization framework on a node.

To get a completion engine, use:

completion_engine = ProcessCompletionEngine.get_completion_engine(
    node, name)

Note that this will assign permanently the ProcessCompletionEngine object to its associated node or process. To get and set the attributes set:

attributes = completion_engine.get_attribute_values()
print(attributes.user_traits().keys())
attributes.specific_process_attribute = 'a value'

Once attributes are set, to process with parameters completion:

completion_engine.complete_parameters()

It is possible to have complete_parameters() triggered automatically when attributes or switch nodes change. To set this up, use:

completion_engine.install_auto_completion()

ProcessCompletionEngine can (and should) be specialized, at least to provide the attributes set for a given process. A factory is used to create the correct type of ProcessCompletionEngine for a given process / name: ProcessCompletionEngineFactory

capsul.attributes.fom_completion_engine.FomProcessCompletionEngine is a specialization of ProcessCompletionEngine to manage File Organization Models (FOM).

get_completion_engine()[source]
get_attribute_values()[source]
complete_parameters()[source]
set_parameters()[source]
attributes_to_path()[source]
get_path_completion_engine()[source]
install_auto_completion()[source]
remove_auto_completion()[source]
__init__(process, name=None)[source]
_clear_node(wr)[source]

Called when the object behind the self.process proxy is about to be deleted

get_attribute_values()[source]

Get attributes Controller associated to a process or node

Returns:

  • attributes (ProcessAttributes instance)

  • The default implementation does nothing for a

  • single Process instance, and merges attributes from its children if

  • the process is a pipeline.

_get_linked_attributes()[source]
complete_parameters(process_inputs={}, complete_iterations=True)[source]

Completes file parameters from given inputs parameters, which may include both “regular” process parameters (file names) and attributes.

Parameters:
  • process_inputs (dict (optional)) – parameters to be set on the process. It may include “regular” process parameters, and attributes used for completion. Attributes should be in a sub-dictionary under the key “capsul_attributes”.

  • complete_iterations (bool (optional)) – if False, iteration nodes inside the pipeline will not run their own completion. Thus parameters for the iterations will not be correctly completed. However this has 2 advantages: 1. it prevents modification of the input pipeline, 2. it will not do iterations completion which will anyway be done (again) when building a workflow in ~capsul.pipeline.pipeline_workflow.workflow_from_pipeline.

attributes_to_path(parameter, attributes)[source]

Build a path from attributes for a given parameter in a process.

Parameters:
  • parameter (str)

  • attributes (ProcessAttributes instance (Controller))

set_parameters(process_inputs)[source]

Set the given parameters dict to the given process. process_inputs may include regular parameters of the underlying process, and attributes (capsul_attributes: dict).

attributes_changed(obj, name, old, new)[source]

Traits changed callback which triggers parameters update.

This method basically calls complete_parameters() (after some checks).

Users do not normally have to use it directly, it is used internally when install_auto_completion() has been called.

See install_auto_completion()

nodes_selection_changed(obj, name, old, new)[source]

Traits changed callback which triggers parameters update.

This method basically calls complete_parameters() (after some checks).

Users do not normally have to use it directly, it is used internally when install_auto_completion() has been called.

See install_auto_completion()

install_auto_completion()[source]

Monitor attributes changes and switches changes (which may influence attributes) and recompute parameters completion when needed.

remove_auto_completion()[source]

Remove attributes monitoring and auto-recomputing of parameters.

Reverts install_auto_completion()

get_path_completion_engine()[source]

Get a PathCompletionEngine object for the given process. The default implementation queries PathCompletionEngineFactory, but some specific ProcessCompletionEngine implementations may override it for path completion at the process level (FOMs for instance).

static get_completion_engine(process, name=None)[source]

Get a ProcessCompletionEngine instance for a given process/node within the framework of its StudyConfig factory function.

static _remove_completion_engine(process)[source]
static _del_process_callback(process)[source]
_get_schemas()[source]

Get schemas dictionary from process and its StudyConfig

_install_subprogress_moniotoring(subprocess_compl)[source]
_remove_subprogress_moniotoring(subprocess_compl)[source]
static _substep_completion_progress(self, substep_completion_engine, obj, name, old, new)[source]
remove_attributes()[source]

Clear attributes controller cache, to allow rebuilding it after a change. This is generally a callback attached to switches changes.

remove_switch_observers()[source]

Remove notification callbacks previously set to listen switches state changes.

class populse_mia.user_interface.pipeline_manager.pipeline_editor.ProcessNode(pipeline, name, process, **kwargs)[source]

Bases: Node

Process node.

process

the process instance stored in the pipeline node

Type:

process instance

set_callback_on_plug()[source]
get_plug_value()[source]
set_plug_value()[source]
get_trait()[source]
__init__(pipeline, name, process, **kwargs)[source]

Generate a ProcessNode

Parameters:
  • pipeline (Pipeline (mandatory)) – the pipeline object where the node is added.

  • name (str (mandatory)) – the node name.

  • process (instance) – a process/interface instance.

  • kwargs (dict) – process default values.

set_callback_on_plug(plug_name, callback)[source]

Add an event when a plug change

Parameters:
  • plug_name (str (mandatory)) – a plug name

  • callback (@f (mandatory)) – a callback function

remove_callback_from_plug(plug_name, callback)[source]

Remove an event when a plug change

Parameters:
  • plug_name (str (mandatory)) – a plug name

  • callback (@f (mandatory)) – a callback function

get_plug_value(plug_name)[source]

Return the plug value

Parameters:

plug_name (str (mandatory)) – a plug name

Returns:

output – the plug value

Return type:

object

set_plug_value(plug_name, value, protected=None)[source]

Set the plug value

Parameters:
  • plug_name (str (mandatory)) – a plug name

  • value (object (mandatory)) – the plug value we want to set

  • protected (None or bool (tristate)) – if True or False, force the “protected” status of the plug. If None, keep it as is.

is_parameter_protected(plug_name)[source]

Tells whether the given parameter is protected or not

protect_parameter(plug_name, state=True)[source]

Protect the named parameter.

Protecting is not a real lock, it just marks the parameter a list of “protected” parameters. This is typically used to mark values that have been set manually by the user (using the ControllerWidget for instance) and that should not be later modified by automatic parameters tweaking (such as completion systems).

Protected parameters are listed in an additional trait, “protected_parameters”.

If the “state” parameter is False, then we will unprotect it (calling unprotect_parameter())

get_trait(trait_name)[source]

Return the desired trait

Parameters:

trait_name (str (mandatory)) – a trait name

Returns:

output – the trait named trait_name

Return type:

trait

is_job()[source]

if True, the node will be represented as a Job in Soma-Workflow. Otherwise the node is static and does not run.

requirements()[source]

Requirements reimplementation for a process node. This node delegates to its underlying process. see capsul.process.process.requirements()

check_requirements(environment='global', message_list=None)[source]

Reimplementation of capsul.pipeline.pipeline_nodes.Node.requirements() for a ProcessNode. This one delegates to its underlying process (or pipeline).

get_study_config()[source]

Get (or create) the StudyConfig this process belongs to

set_study_config(study_config)[source]

Get (or create) the StudyConfig this process belongs to

_process_deleted(process)[source]
property study_config
property completion_engine
populse_mia.user_interface.pipeline_manager.pipeline_editor.save_py_pipeline(pipeline, py_file)[source]

Save a pipeline in an Python source file

Parameters:
  • pipeline (Pipeline instance) – pipeline to save

  • py_file (str or file-like object) – .py file to save the pipeline in

populse_mia.user_interface.pipeline_manager.pipeline_editor.save_xml_pipeline(pipeline, xml_file)[source]

Save a pipeline in an XML file

Parameters:
  • pipeline (Pipeline instance) – pipeline to save

  • xml_file (str or file-like object) – XML file to save the pipeline in

class populse_mia.user_interface.pipeline_manager.pipeline_editor.NodeGWidget(name, parameters, pipeline, parent=None, process=None, sub_pipeline=None, colored_parameters=True, logical_view=False, labels=[], show_opt_inputs=True, show_opt_outputs=True, userlevel=0)[source]

Bases: QGraphicsItem

__init__(name, parameters, pipeline, parent=None, process=None, sub_pipeline=None, colored_parameters=True, logical_view=False, labels=[], show_opt_inputs=True, show_opt_outputs=True, userlevel=0)[source]
property userlevel
_release()[source]
get_title()[source]
update_parameters()[source]
update_parameters_now()[source]
update_labels(labels)[source]

Update colored labels

_get_label(label, register=True)[source]
new_color(num)[source]
_repaint_parameter(param_name, new_value)[source]
_build()[source]
changeSize(w, h)[source]
updateSize(w, h)[source]
_colored_text_item(label, text=None, margin=2)[source]
_build_regular_view_plugs()[source]
change_input_view()[source]
change_output_view()[source]
_build_logical_view_plugs()[source]
_create_label_marks()[source]
clear_plugs()[source]
updateInfoActived(state)[source]
fonced_viewer(det)[source]
_set_brush()[source]
_color_disabled(color)[source]
_create_parameter(param_name, pipeline_plug)[source]
_shift_params()[source]
_remove_parameter(param_name)[source]
_parameter_text(param_name)[source]
update_node()[source]
contentsRect()[source]
boundingRect(self) QRectF[source]
paint(self, painter: QPainter | None, option: QStyleOptionGraphicsItem | None, widget: QWidget | None = None)[source]
postscript(file_name)[source]
resize_subpipeline_on_show()[source]
resize_subpipeline_on_hide()[source]
in_params_width()[source]
out_params_width()[source]
add_subpipeline_view(sub_pipeline, allow_open_controller=True, scale=None)[source]
mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent | None)[source]
mousePressEvent(self, event: QGraphicsSceneMouseEvent | None)[source]
keyPressEvent(self, event: QKeyEvent | None)[source]
class populse_mia.user_interface.pipeline_manager.pipeline_editor.PipelineDeveloperView(pipeline=None, parent=None, show_sub_pipelines=False, allow_open_controller=False, logical_view=False, enable_edition=False, userlevel=0)[source]

Bases: QGraphicsView

Pipeline representation as a graph, using boxes and arrows.

Based on Qt QGraphicsView, this can be used as a Qt QWidget.

Qt signals are emitted on a right click on a node box, and on a double click on a sub-pipeline box, to allow handling at a higher level. Default behaviors can be enabled using constructor parameters.

Ctrl + double click opens sub-pipelines in embedded views inside their parent box.

subpipeline_clicked
node_right_clicked
process_clicked
node_clicked
node_clicked_ctrl
plug_clicked
plug_right_clicked
colored_parameters
scene
__init__()[source]
set_pipeline()[source]
is_logical_view()[source]
set_logical_view()[source]
zoom_in()[source]
zoom_out()[source]
openProcessController()[source]
add_embedded_subpipeline()[source]
onLoadSubPipelineClicked()[source]
onOpenProcessController()[source]
enableNode()[source]
enable_step()[source]
disable_preceding_steps()[source]
disable_following_steps()[source]
enable_preceding_steps()[source]
enable_following_steps()[source]
set_switch_value()[source]
disable_done_steps()[source]
enable_all_steps()[source]
check_files()[source]
auto_dot_node_positions()[source]
save_dot_image_ui()[source]
reset_initial_nodes_positions()[source]
window()[source]
subpipeline_clicked

Signal emitted when a sub pipeline has to be open.

process_clicked

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

node_clicked

Signal emitted when a node box has to be open.

node_clicked_ctrl

Signal emitted when a node box has to be in the foreground.

switch_clicked

Signal emitted when a switch box has to be open.

node_right_clicked

Signal emitted when a node box is right-clicked

plug_clicked

Signal emitted when a plug is clicked

plug_right_clicked

Signal emitted when a plug is right-clicked

link_right_clicked

Signal emitted when a link is right-clicked

edit_sub_pipeline

Signal emitted when a sub-pipeline has to be edited

open_filter

Signal emitted when an Input Filter has to be opened

export_to_db_scans

Signal emitted when an Input Filter has to be linked to database_scans

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

node_keydelete_clicked

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

class ProcessNameEdit(parent=None, class_type_check=<function is_process>)[source]

Bases: QLineEdit

A specialized QLineEdit with completion for process name

__init__(parent=None, class_type_check=<function is_process>)[source]
static _execfile(filename)[source]
load_py(filename)[source]
get_processes_or_modules(filename)[source]
on_text_edited(text)[source]
__init__(pipeline=None, parent=None, show_sub_pipelines=False, allow_open_controller=False, logical_view=False, enable_edition=False, userlevel=0)[source]

PipelineDeveloperView

Parameters:
  • pipeline (Pipeline (optional)) – pipeline object to be displayed If omitted an empty pipeline will be used, and edition mode will be activated.

  • parent (QWidget (optional)) – parent widget

  • show_sub_pipelines (bool (optional)) – if set, sub-pipelines will appear as red/pink boxes and a double click on one of them will open another window with the sub-pipeline structure in it

  • allow_open_controller (bool (optional)) – if set, a right click on any box will open another window with the underlying node controller, allowing to see and edit parameters values, switches states, etc.

  • logical_view (bool (optional)) – if set, plugs and links between plugs are hidden, only links between nodes are displayed.

  • enable_edition (bool (optional)) – if set, pipeline edition features are available in GUI and menus: adding process boxes, drawing links etc. If pipeline is not specified, then edition will be activated anyway.

scene = None

PipelineScene

the main scene.

Type:

type

colored_parameters = True

If enabled (default), parameters in nodes boxes are displayed with color codes representing their state, and the state of their values: output parameters, empty values, existing files, non-existing files…

When colored_parameters is set, however, callbacks have to be installed to track changes in traits values, so this actually has an overhead. When colored_parameters is used, the color code is as follows:

  • black pamameter name: input

  • red parameter name: output

  • italics parameter name: Undefined, None, or empty string value

  • bold parameter name: existing file or directory name

  • regular font parameter name: non-existing file, or non-file parameter type

  • black plug: mandatory

  • green plug: optional

  • grey plug: mandatory, inactive

  • light green plug: optional, inactive

  • grey link: inactive

  • orange link: active

  • dotted line link: weak link

property userlevel
ensure_pipeline(pipeline)[source]

Check that we have a pipeline or a process

_set_pipeline(pipeline)[source]
set_pipeline(pipeline)[source]

Assigns a new pipeline to the view.

closeEvent(event)[source]

Ensure pipeline is released before the widget is closed.

release_pipeline(delete=False)[source]

Releases the pipeline currently viewed (and remove the callbacks)

If delete is set, this means the view is within deletion process and a new scene should not be built

is_logical_view()[source]

in logical view mode, plugs and links between plugs are hidden, only links between nodes are displayed.

set_logical_view(state)[source]

in logical view mode, plugs and links between plugs are hidden, only links between nodes are displayed.

Parameters:

state (bool (mandatory)) – to set/unset the logical view mode

_reset_pipeline()[source]
zoom_in()[source]

Zoom the view in, applying a 1.2 zoom factor

zoom_out()[source]

Zoom the view out, applying a 1/1.2 zool factor

edition_enabled()[source]

Get the editable state

set_enable_edition(state=True)[source]

Set the editable state. Edition allows to modify a pipeline: adding / removing process boxes and switches, drawing links, etc.

is_restricted_edition_mode()[source]

Get the restricted mode status

Returns:

enabled

Return type:

bool

set_restricted_edition_mode(enabled)[source]

Set the restricted edition mode. In restricted mode, some background menu actions (“add process”, “open node controller”…) are not available.

Parameters:

enabled (bool)

wheelEvent(self, event: QWheelEvent | None)[source]
mousePressEvent(self, event: QMouseEvent | None)[source]
mouseReleaseEvent(self, event: QMouseEvent | None)[source]
mouseMoveEvent(self, event: QMouseEvent | None)[source]
dragEnterEvent(event)[source]

Event handler when the mouse enters the widget.

Parameters:

event – event

dragMoveEvent(event)[source]

Event handler when the mouse moves in the widget.

Parameters:

event – event

dropEvent(event)[source]

Event handler when something is dropped in the widget.

Parameters:

event – event

drop_process(path)[source]

Find the dropped process in the system’s paths.

Parameters:

path – class’s path (e.g. “nipype.interfaces.spm.Smooth”) (str)

add_embedded_subpipeline(subpipeline_name, scale=None)[source]

Adds an embedded sub-pipeline inside its parent node.

onLoadSubPipelineClicked(node_name, sub_pipeline, modifiers)[source]

Event to load a open a sub-pipeline view. If ctrl is pressed the new view will be embedded in its parent node box.

window()[source]

window() is overloaded from QWidget.window() to handle embedded views cases. A PipelineDeveloperView may be displayed inside a NodeGWidget. In this case, we want to go up to the parent scene’s window to the “real” top window, where QWidget.window() will end in the current graphics scene.

onOpenProcessController(node_name, process)[source]

Event to open a sub-process/sub-pipeline controller

openProcessController()[source]
open_node_menu(node_name, process)[source]

right-click popup menu for nodes

emit_export_to_db_scans()[source]
emit_open_filter()[source]
emit_edit_sub_pipeline()[source]
show_optional_inputs()[source]

Added to choose to visualize optional inputs.

show_optional_outputs()[source]

Added to choose to visualize optional outputs.

open_background_menu()[source]

Open the right-click menu when triggered from the pipeline background.

enableNode(checked)[source]
enable_step(step_name, state)[source]
disable_preceding_steps(step_name, dummy)[source]
disable_following_steps(step_name, dummy)[source]
enable_preceding_steps(step_name, dummy)[source]
enable_following_steps(step_name, dummy)[source]
set_switch_value(switch, value, dummy)[source]
disable_done_steps()[source]
enable_all_steps()[source]
check_files()[source]
auto_dot_node_positions()[source]

Calculate pipeline nodes positions using graphviz/dot, and place the pipeline view nodes accordingly.

_read_dot_pos(filename)[source]

Read the nodes positions from a file generated by graphviz/dot, in “plain” text format.

Returns:

nodes_pos – keys are nodes IDs (names), and values are 2D positions

Return type:

dict

save_dot_image_ui()[source]

Ask for a filename using the file dialog, and save a graphviz/dot representation of the pipeline. The pipeline representation follows the current visualization mode (“regular” or “logical” with smaller boxes) with one link of a given type (active, weak) between two given boxes: all parameters are not represented.

reset_initial_nodes_positions()[source]

Set each pipeline node to its “saved” position, ie the one which may be found in the “node_position” variable of the pipeline.

switch_logical_view()[source]
print_node_positions()[source]
del_node(node_name=None)[source]
export_node_plugs(node_name, inputs=True, outputs=True, optional=False)[source]
export_plugs(inputs=True, outputs=True, optional=False)[source]
export_node_unconnected_mandatory_plugs()[source]
export_node_all_unconnected_plugs()[source]
export_node_unconnected_mandatory_inputs()[source]
export_node_all_unconnected_inputs()[source]
export_node_unconnected_mandatory_outputs()[source]
export_node_all_unconnected_outputs()[source]
export_unconnected_mandatory_plugs()[source]
export_all_unconnected_plugs()[source]
export_unconnected_mandatory_inputs()[source]
export_all_unconnected_inputs()[source]
export_unconnected_mandatory_outputs()[source]
export_all_unconnected_outputs()[source]
_change_step()[source]
class ProcessModuleInput(display_str='process module/name', class_type_check=<function is_process>)[source]

Bases: QDialog

__init__(display_str='process module/name', class_type_check=<function is_process>)[source]
add_process()[source]

Insert a process node in the pipeline. Asks for the process module/name, and the node name before inserting.

add_named_process(proc_module, node_name=None)[source]
add_node()[source]

Insert a custom node in the pipeline. Asks for the node module/name, and the node name before inserting.

add_named_node(node_name, node_module)[source]
class IterativeProcessInput(engine)[source]

Bases: ProcessModuleInput

__init__(engine)[source]
set_plugs(text)[source]
iterative_plugs()[source]
add_iterative_process()[source]

Insert an iterative process node in the pipeline. Asks for the process module/name, the node name, and iterative plugs before inserting.

add_switch()[source]

Insert a switch node in the pipeline. Asks for the switch inputs/outputs, and the node name before inserting.

add_optional_output_switch()[source]

Insert an optional output switch node in the pipeline. Asks for the switch inputs/outputs, and the node name before inserting.

_plug_clicked(name)[source]
_node_delete_clicked(name_node)[source]
get_doc_browser(create=False)[source]
_node_clicked(name, node)[source]
static get_node_html_doc(node)[source]
show_doc(node_name=None)[source]
show_node_doc(node)[source]
_node_clicked_ctrl(name, process)[source]
_plug_right_clicked(name)[source]
class _PlugEdit(show_weak=True, parent=None)[source]

Bases: QDialog

__init__(show_weak=True, parent=None)[source]
_export_plug()[source]
_change_iterative_plug(checked)[source]
_protect_plug(checked)[source]
_enable_plug_completion(checked)[source]
_remove_plug()[source]
_edit_plug()[source]
_prune_plugs()[source]
confirm_erase_pipeline()[source]
new_pipeline()[source]
load_pipeline(filename='', load_pipeline=True)[source]
save_pipeline()[source]

Ask for a filename using the file dialog, and save the pipeline as a XML, JSON or python file.

load_pipeline_parameters(root_path='')[source]

Loading and setting pipeline parameters (inputs and outputs) from a Json file. :return:

save_pipeline_parameters()[source]

Saving pipeline parameters (inputs and outputs) to a Json file. :return:

class populse_mia.user_interface.pipeline_manager.pipeline_editor.QInputDialog(parent: QWidget | None = None, flags: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags())

Bases: QDialog

DoubleInput = 2
class InputDialogOption

Bases: int

class InputDialogOptions
class InputDialogOptions(f: QInputDialog.InputDialogOptions | QInputDialog.InputDialogOption)
class InputDialogOptions(a0: QInputDialog.InputDialogOptions)

Bases: simplewrapper

class InputMode

Bases: int

IntInput = 1
NoButtons = 1
TextInput = 0
UseListViewForComboBoxItems = 2
UsePlainTextEditForTextInput = 4
cancelButtonText(self) str
comboBoxItems(self) List[str]
done(self, result: int)
doubleDecimals(self) int
doubleMaximum(self) float
doubleMinimum(self) float
doubleStep(self) float
doubleValue(self) float
doubleValueChanged

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

doubleValueSelected

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

getDouble(parent: QWidget | None, title: str | None, label: str | None, value: float = 0, min: float = -2147483647, max: float = 2147483647, decimals: int = 1, flags: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags())
getDouble(parent: QWidget | None, title: str | None, label: str | None, value: float, minValue: float, maxValue: float, decimals: int, flags: Qt.WindowFlags | Qt.WindowType, step: float) None
getInt(parent: QWidget | None, title: str | None, label: str | None, value: int = 0, min: int = -2147483647, max: int = 2147483647, step: int = 1, flags: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags())
getItem(parent: QWidget | None, title: str | None, label: str | None, items: Iterable[str | None], current: int = 0, editable: bool = True, flags: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags(), inputMethodHints: Qt.InputMethodHints | Qt.InputMethodHint = Qt.ImhNone)
getMultiLineText(parent: QWidget | None, title: str | None, label: str | None, text: str | None = '', flags: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags(), inputMethodHints: Qt.InputMethodHints | Qt.InputMethodHint = Qt.ImhNone)
getText(parent: QWidget | None, title: str | None, label: str | None, echo: QLineEdit.EchoMode = QLineEdit.Normal, text: str | None = '', flags: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags(), inputMethodHints: Qt.InputMethodHints | Qt.InputMethodHint = Qt.ImhNone)
inputMode(self) QInputDialog.InputMode
intMaximum(self) int
intMinimum(self) int
intStep(self) int
intValue(self) int
intValueChanged

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

intValueSelected

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

isComboBoxEditable(self) bool
labelText(self) str
minimumSizeHint(self) QSize
okButtonText(self) str
open(self)
open(self, slot: PYQT_SLOT) None
options(self) QInputDialog.InputDialogOptions
setCancelButtonText(self, text: str | None)
setComboBoxEditable(self, editable: bool)
setComboBoxItems(self, items: Iterable[str | None])
setDoubleDecimals(self, decimals: int)
setDoubleMaximum(self, max: float)
setDoubleMinimum(self, min: float)
setDoubleRange(self, min: float, max: float)
setDoubleStep(self, step: float)
setDoubleValue(self, value: float)
setInputMode(self, mode: QInputDialog.InputMode)
setIntMaximum(self, max: int)
setIntMinimum(self, min: int)
setIntRange(self, min: int, max: int)
setIntStep(self, step: int)
setIntValue(self, value: int)
setLabelText(self, text: str | None)
setOkButtonText(self, text: str | None)
setOption(self, option: QInputDialog.InputDialogOption, on: bool = True)
setOptions(self, options: QInputDialog.InputDialogOptions | QInputDialog.InputDialogOption)
setTextEchoMode(self, mode: QLineEdit.EchoMode)
setTextValue(self, text: str | None)
setVisible(self, visible: bool)
sizeHint(self) QSize
testOption(self, option: QInputDialog.InputDialogOption) bool
textEchoMode(self) QLineEdit.EchoMode
textValue(self) str
textValueChanged

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

textValueSelected

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

class populse_mia.user_interface.pipeline_manager.pipeline_editor.QMessageBox(parent: QWidget | None = None)
class populse_mia.user_interface.pipeline_manager.pipeline_editor.QMessageBox(icon: QMessageBox.Icon, title: str | None, text: str | None, buttons: QMessageBox.StandardButtons | QMessageBox.StandardButton = QMessageBox.NoButton, parent: QWidget | None = None, flags: Qt.WindowFlags | Qt.WindowType = Qt.Dialog | Qt.MSWindowsFixedSizeDialogHint)

Bases: QDialog

Abort = 262144
AcceptRole = 0
ActionRole = 3
Apply = 33554432
ApplyRole = 8
ButtonMask = -769
class ButtonRole

Bases: int

Cancel = 4194304
Close = 2097152
Critical = 3
Default = 256
DestructiveRole = 2
Discard = 8388608
Escape = 512
FirstButton = 1024
FlagMask = 768
Help = 16777216
HelpRole = 4
class Icon

Bases: int

Ignore = 1048576
Information = 1
InvalidRole = -1
LastButton = 134217728
No = 65536
NoAll = 131072
NoButton = 0
NoIcon = 0
NoRole = 6
NoToAll = 131072
Ok = 1024
Open = 8192
Question = 4
RejectRole = 1
Reset = 67108864
ResetRole = 7
RestoreDefaults = 134217728
Retry = 524288
Save = 2048
SaveAll = 4096
class StandardButton

Bases: int

class StandardButtons
class StandardButtons(f: QMessageBox.StandardButtons | QMessageBox.StandardButton)
class StandardButtons(a0: QMessageBox.StandardButtons)

Bases: simplewrapper

Warning = 2
Yes = 16384
YesAll = 32768
YesRole = 5
YesToAll = 32768
about(parent: QWidget | None, caption: str | None, text: str | None)
aboutQt(parent: QWidget | None, title: str | None = '')
addButton(self, button: QAbstractButton | None, role: QMessageBox.ButtonRole)
addButton(self, text: str | None, role: QMessageBox.ButtonRole) QPushButton | None
addButton(self, button: QMessageBox.StandardButton) QPushButton | None
button(self, which: QMessageBox.StandardButton) QAbstractButton | None
buttonClicked

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

buttonRole(self, button: QAbstractButton | None) QMessageBox.ButtonRole
buttons(self) List[QAbstractButton]
changeEvent(self, a0: QEvent | None)
checkBox(self) QCheckBox | None
clickedButton(self) QAbstractButton | None
closeEvent(self, a0: QCloseEvent | None)
critical(parent: QWidget | None, title: str | None, text: str | None, buttons: QMessageBox.StandardButtons | QMessageBox.StandardButton = QMessageBox.Ok, defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton) QMessageBox.StandardButton
defaultButton(self) QPushButton | None
detailedText(self) str
escapeButton(self) QAbstractButton | None
event(self, e: QEvent | None) bool
icon(self) QMessageBox.Icon
iconPixmap(self) QPixmap
information(parent: QWidget | None, title: str | None, text: str | None, buttons: QMessageBox.StandardButtons | QMessageBox.StandardButton = QMessageBox.Ok, defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton) QMessageBox.StandardButton
informativeText(self) str
keyPressEvent(self, a0: QKeyEvent | None)
open(self)
open(self, slot: PYQT_SLOT) None
question(parent: QWidget | None, title: str | None, text: str | None, buttons: QMessageBox.StandardButtons | QMessageBox.StandardButton = QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No), defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton) QMessageBox.StandardButton
removeButton(self, button: QAbstractButton | None)
resizeEvent(self, a0: QResizeEvent | None)
setCheckBox(self, cb: QCheckBox | None)
setDefaultButton(self, button: QPushButton | None)
setDefaultButton(self, button: QMessageBox.StandardButton) None
setDetailedText(self, text: str | None)
setEscapeButton(self, button: QAbstractButton | None)
setEscapeButton(self, button: QMessageBox.StandardButton) None
setIcon(self, a0: QMessageBox.Icon)
setIconPixmap(self, a0: QPixmap)
setInformativeText(self, text: str | None)
setStandardButtons(self, buttons: QMessageBox.StandardButtons | QMessageBox.StandardButton)
setText(self, a0: str | None)
setTextFormat(self, a0: Qt.TextFormat)
setTextInteractionFlags(self, flags: Qt.TextInteractionFlags | Qt.TextInteractionFlag)
setWindowModality(self, windowModality: Qt.WindowModality)
setWindowTitle(self, title: str | None)
showEvent(self, a0: QShowEvent | None)
standardButton(self, button: QAbstractButton | None) QMessageBox.StandardButton
standardButtons(self) QMessageBox.StandardButtons
standardIcon(icon: QMessageBox.Icon) QPixmap
text(self) str
textFormat(self) Qt.TextFormat
textInteractionFlags(self) Qt.TextInteractionFlags
warning(parent: QWidget | None, title: str | None, text: str | None, buttons: QMessageBox.StandardButtons | QMessageBox.StandardButton = QMessageBox.Ok, defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton) QMessageBox.StandardButton
populse_mia.user_interface.pipeline_manager.pipeline_editor.weak_proxy(obj, callback=None)[source]

Build a weak proxy (weakref.ProxyType) from an object, if it is not already one, and keep a reference to the original object (via a weakref.ReferenceType) in it.

callback is passed to weakref.proxy().

class populse_mia.user_interface.pipeline_manager.pipeline_editor.Config(properties_path=None)[source]

Bases: object

Object that handles the configuration of the software

Contains:

Methods:

  • _configure_matlab_only: Configures MATLAB without SPM

  • _configure_matlab_spm: Configures SPM and MATLAB

  • _configure_mcr_only: Configures MCR without SPM

  • _configure_standalone_spm: Configures standalone SPM and MCR

  • _disable_matlab_spm: Disables all MATLAB and SPM configurations

  • get_admin_hash: Get the value of the hash of the admin password

  • get_afni_path: Returns the path of AFNI

  • get_ants_path: Returns the path of ANTS

  • getBackgroundColor: Get background color

  • get_capsul_config: Get CAPSUL config dictionary

  • get_capsul_engine: Get a global CapsulEngine object used for all operations in MIA application

  • getChainCursors: Returns if the “chain cursors” checkbox of the mini-viewer is activated

  • get_freesurfer_setup: Get freesurfer path

  • get_fsl_config: Returns the path of the FSL config file

  • get_mainwindow_maximized: Get the maximized (full-screen) flag

  • get_mainwindow_size: Get the main window size

  • get_matlab_command: Returns Matlab command

  • get_matlab_path: Returns the path of Matlab’s executable

  • get_matlab_standalone_path: Returns the path of Matlab Compiler Runtime

  • get_max_projects: Returns the maximum number of projects displayed in the “Saved projects” menu

  • get_max_thumbnails: Get max thumbnails number at the data browser bottom

  • get_mri_conv_path: Returns the MRIManager.jar path

  • get_mrtrix_path: Returns mrtrix path

  • getNbAllSlicesMax: Returns the maximum number of slices to display in the mini viewer

  • get_opened_projects: Returns the opened projects

  • get_projects_save_path: Returns the folder where the projects are saved

  • get_properties_path: Returns the software’s properties path

  • get_referential: Returns boolean to indicate DataViewer referential

  • get_resources_path: Get the resources path

  • getShowAllSlices: Returns if the “show all slices” checkbox of the mini viewer is activated

  • getSourceImageDir: Get the source directory for project images

  • get_spm_path: Returns the path of SPM12 (license version)

  • get_spm_standalone_path: Returns the path of SPM12 (standalone version)

  • getTextColor: Return the text color

  • getThumbnailTag: Returns the tag that is displayed in the mini viewer

  • get_use_afni: Returns the value of “use afni” checkbox in the preferences

  • get_use_ants: Returns the value of “use ants” checkbox in the preferences

  • get_use_clinical: Returns the value of “clinical mode” checkbox in the preferences

  • get_use_freesurfer: Returns the value of “use freesurfer” checkbox in the preferences

  • get_use_fsl: Returns the value of “use fsl” checkbox in the preferences

  • get_use_matlab: Returns the value of “use matlab” checkbox in the preferences

  • get_use_matlab_standalone: Returns the value of “use matlab standalone” checkbox in the preferences

  • get_use_mrtrix: Returns the value of “use mrtrix” checkbox in the preferences

  • get_user_level: Get the user level in the Capsul config

  • get_user_mode: Returns the value of “user mode” checkbox in the preferences

  • get_use_spm: Returns the value of “use spm” checkbox in the preferences

  • get_use_spm_standalone: Returns the value of “use spm standalone” checkbox in the preferences

  • getViewerConfig: Returns the DataViewer configuration (neuro or radio), by default neuro

  • getViewerFramerate: Returns the DataViewer framerate for automatic time running images

  • isAutoSave: Checks if auto-save mode is activated

  • isControlV1: Checks if the selected display of the controller is of V1 type

  • isRadioView: Checks if miniviewer in radiological orientation (if not, then it is in neurological orientation)

  • loadConfig: Reads the config in the config.yml file

  • saveConfig: Saves the config to the config.yml file

  • set_admin_hash: Set the password hash

  • set_afni_path: Set the path of the AFNI

  • set_ants_path: Set the path of the ANTS

  • setAutoSave: Sets the auto-save mode

  • setBackgroundColor: Sets the background color

  • set_capsul_config: Set CAPSUL configuration dict into MIA config

  • setChainCursors: Set the “chain cursors” checkbox of the mini viewer

  • set_clinical_mode: Set the value of “clinical mode” in the preferences

  • setControlV1: Set controller display mode (True if V1)

  • set_freesurfer_setup: Set freesurfer path

  • set_fsl_config: Set the path of the FSL config file

  • set_mainwindow_maximized: Set the maximized (fullscreen) flag

  • set_mainwindow_size: Set main window size

  • set_matlab_path: Set the path of Matlab’s executable

  • set_matlab_standalone_path: Set the path of Matlab Compiler Runtime

  • set_max_projects: Set the maximum number of projects displayed in the “Saved projects” menu

  • set_max_thumbnails: Set max thumbnails number at the data browser bottom

  • set_mri_conv_path: Set the MRIManager.jar path

  • set_mrtrix_path: Set the path of mrtrix

  • setNbAllSlicesMax: Set the maximum number of slices to display in the mini viewer

  • set_opened_projects: Set the opened projects

  • set_projects_save_path: Set the folder where the projects are saved

  • set_radioView: Set the orientation in miniviewer (True for radiological, False for neurological orientation)

  • set_referential: Set the DataViewer referential

  • set_resources_path: Set the resources path

  • setShowAllSlices: Set the “show all slices” checkbox of the mini viewer

  • setSourceImageDir: Set the source directory for project images

  • set_spm_path: Set the path of SPM12 (license version)

  • set_spm_standalone_path: Set the path of SPM12 (standalone version)

  • setTextColor: Set the text color

  • setThumbnailTag: Set the tag that is displayed in the mini viewer

  • set_use_afni: Set the value of “use afni” checkbox in the preferences

  • set_use_ants: Set the value of “use ants” checkbox in the preferences

  • set_use_freesurfer: Set the value of “use freesurfer” checkbox in the preferences

  • set_use_fsl: Set the value of “use fsl” checkbox in the preferences

  • set_use_matlab: Set the value of “use matlab” checkbox in the preferences

  • set_use_matlab_standalone: Set the value of “use matlab standalone” checkbox in the preferences

  • set_use_mrtrix: Set the value of “use mrtrix” checkbox in the preferences

  • set_user_mode: Set the value of “user mode” checkbox in the preferences

  • set_use_spm: Set the value of “use spm” checkbox in the preferences

  • set_use_spm_standalone: Set the value of “use spm standalone” checkbox in the preferences

  • setViewerConfig: Set the Viewer configuration neuro or radio

  • setViewerFramerate: Set the Viewer frame rate for automatic running time images

  • update_capsul_config: Update a global CapsulEngine object used for all operations in MIA application

capsul_engine = None
__init__(properties_path=None)[source]

Initialization of the Config class

Parameters:

properties_path – (str) If provided, the configuration file will be loaded / saved from the given directory. Otherwise, the regular heuristics will be used to determine the config path. This option allows to use an alternative config directory (for tests for instance).

_configure_matlab_only(matlab_path: str) None[source]

Configures MATLAB without SPM, ensuring that only MATLAB is used.

Parameters:

matlab_path – (str) The directory path of the MATLAB installation.

_configure_matlab_spm(spm_dir, matlab_path)[source]

Configures SPM to use the specified SPM directory with a MATLAB installation.

Parameters:
  • spm_dir – (str) The directory path of the SPM installation.

  • matlab_path – (str) The directory path of the MATLAB installation.

_configure_mcr_only(mcr_dir: str) None[source]

Configures MATLAB Compiler Runtime (MCR) without SPM, ensuring that only MCR is used.

Parameters:

mcr_dir – (str) The directory path of the MATLAB Compiler Runtime (MCR).

_configure_standalone_spm(spm_dir, mcr_dir)[source]

Configures standalone SPM to use the specified SPM and MATLAB Compiler Runtime (MCR) directories.

Parameters:
  • spm_dir – (str) The directory path of the standalone SPM installation.

  • mcr_dir – (str) The directory path of the MATLAB Compiler Runtime (MCR).

_disable_matlab_spm() None[source]

Disables all MATLAB and SPM configurations, ensuring that neither MATLAB nor SPM is used.

get_admin_hash()[source]

Retrieves the hashed admin password from the configuration.

Returns:

The hashed admin password if found in config, False if not present in config.

get_afni_path()[source]

Get the AFNI path.

Returns:

(str) Path to AFNI, or “” if unknown.

get_ants_path()[source]

Get the ANTS path.

Returns:

(str) Path to ANTS, or “” if unknown.

getBackgroundColor()[source]

Get background color.

Returns:

(str) Background color, or “” if unknown.

get_capsul_config(sync_from_engine=True)[source]

Retrieve and construct the Capsul configuration dictionary.

This function builds a configuration dictionary for Capsul, incorporating settings for various neuroimaging tools and processing engines. It manages configurations for tools like SPM, FSL, FreeSurfer, MATLAB, AFNI, ANTs, and MRTrix.

The function first retrieves local settings for each tool from the Mia preferences, then constructs the appropriate configuration structure. If requested, it can synchronize the configuration with the current Capsul engine state.

Parameters:

sync_from_engine – (bool) If True, synchronizes the configuration with the current Capsul engine settings after building the base configuration.

Returns:

(dict) A nested dictionary containing the complete Capsul configuration, structured with the following main sections:

  • engine_modules: List of available processing modules

  • engine: Contains global and environment-specific settings, as well as configurations specific to certain tools (SPM, FSL, etc.)

Private functions:
  • _configure_spm: Configure SPM settings.

  • _configure_tool: Configure various neuroimaging settings (e.g. ‘fsl’, ‘afni’, etc.)

static get_capsul_engine()[source]

Get or create a global CapsulEngine singleton for Mia application operations.

The engine is created only once when first needed (lazy initialization). Subsequent calls return the same instance.

Returns:

(CapsulEngine) The global CapsulEngine instance.

getChainCursors()[source]

Get the value of the checkbox ‘chain cursor’ in miniviewer.

Returns:

(bool) Value of the checkbox.

get_freesurfer_setup()[source]

Get the freesurfer path.

Returns:

(str) Path to freesurfer, or “” if unknown.

get_fsl_config()[source]

Get the FSL config file path.

Returns:

(str) Path to the fsl/etc/fslconf/fsl.sh file.

get_mainwindow_maximized()[source]

Get the maximized (fullscreen) flag.

Returns:

(bool) Maximized (fullscreen) flag.

get_mainwindow_size()[source]

Get the main window size.

Returns:

(list) Main window size.

get_matlab_command()[source]

Retrieves the appropriate Matlab command based on the configuration.

Returns:

(str) The Matlab executable path or None if no path is specified.

get_matlab_path()[source]

Get the path to the matlab executable.

Returns:

(str) A path.

get_matlab_standalone_path()[source]

Get the path to matlab compiler runtime.

Returns:

(str) A path.

get_max_projects()[source]

Retrieves the maximum number of projects displayed in the “Saved projects” menu.

Returns:

(int) The maximum number of projects. Defaults to 5 if not specified.

get_max_thumbnails()[source]

Retrieves the maximum number of thumbnails displayed in the mini-viewer at the bottom of the data browser.

Returns:

(int) The maximum number of thumbnails. Defaults to 5 if not specified.

get_mri_conv_path()[source]

Get the MRIManager.jar path.

Returns:

(str) A path.

get_mrtrix_path()[source]

Get the mrtrix path.

Returns:

(str) A path.

getNbAllSlicesMax()[source]

Get number the maximum number of slices to display in the miniviewer.

Returns:

(int) Maximum number of slices to display in miniviewer.

get_opened_projects()[source]

Get opened projects.

Returns:

(list) Opened projects.

get_projects_save_path()[source]

Get the path where projects are saved.

Returns:

(str) A path.

get_properties_path()[source]

Retrieves the path to the folder containing the “processes” and “properties” directories of Mia.

The properties path is defined in the configuration_path.yml file, located in ~/.populse_mia.

  • In user mode, the path is retrieved from the properties_user_path parameter.

  • In developer mode, the path is retrieved from the properties_dev_path parameter.

If outdated parameters (mia_path, mia_user_path) are found, they are automatically updated in the configuration file.

Returns:

(str) The absolute path to the properties folder.

get_referential()[source]

Retrieves the chosen referential from the anatomist_2 data viewer.

Returns:

(str) “0” for World Coordinates, “1” for Image ref.

get_resources_path()[source]

Get the resources path.

Returns:

(str) A path.

getShowAllSlices()[source]

Get whether the show_all_slices parameters was enabled or not in the miniviewer.

Returns:

(bool) True if the show_all_slices parameters was enabled.

getSourceImageDir()[source]

Get the source directory for project images.

Returns:

(str) A path.

get_spm_path()[source]

Get the path of SPM.

Returns:

(str) A path.

get_spm_standalone_path()[source]

Get the path to the SPM12 standalone version.

Returns:

(str) A path.

getTextColor()[source]

Get the text color.

Returns:

(str) The text color.

getThumbnailTag()[source]

Get the tag of the thumbnail displayed in the miniviewer.

Returns:

(str) The tag of the thumbnail displayed in miniviewer.

get_use_afni()[source]

Get the value of “use afni” checkbox in the preferences.

Returns:

(bool) The value of “use afni” checkbox.

get_use_ants()[source]

Get the value of “use ants” checkbox in the preferences.

Returns:

(bool) The value of “use ants” checkbox.

get_use_clinical()[source]

Get the clinical mode in the preferences.

Returns:

(bool) The clinical mode.

get_use_freesurfer()[source]

Get the value of “use freesurfer” checkbox in the preferences.

Returns:

(bool) The value of “use freesurfer” checkbox.

get_use_fsl()[source]

Get the value of “use fsl” checkbox in the preferences.

Returns:

(bool) The value of “use fsl” checkbox.

get_use_matlab()[source]

Get the value of “use matlab” checkbox in the preferences.

Returns:

(bool) The value of “use matlab” checkbox.

get_use_matlab_standalone()[source]

Get the value of “use matlab standalone” checkbox in the preferences.

Returns:

(bool) The value of “use matlab standalone” checkbox.

get_use_mrtrix()[source]

Get the value of “use mrtrix” checkbox in the preferences.

Returns:

(bool) The value of “use mrtrix” checkbox.

get_user_level()[source]

Get the user level in the Capsul config.

Returns:

(int) The user level in the Capsul config.

get_user_mode()[source]

Get if user mode is disabled or enabled in the preferences.

Returns:

(bool) If True, the user mode is enabled.

get_use_spm()[source]

Get the value of “use spm” checkbox in the preferences.

Returns:

(bool) The value of “use spm” checkbox.

get_use_spm_standalone()[source]

Get the value of “use spm standalone” checkbox in the preferences.

Returns:

(bool) The value of “use spm standalone” checkbox.

getViewerConfig()[source]

Get the viewer config “neuro” or “radio”, “neuro” by default.

Returns:

(str) The viewer config (“neuro” or “radio”).

getViewerFramerate()[source]

Get the Viewer framerate.

Returns:

(str) The Viewer framerat (ex. “5”).

isAutoSave()[source]

Get if the auto-save mode is enabled or not.

Returns:

(bool) If True, auto-save mode is enabled.

isControlV1()[source]

Gets whether the controller display is of type V1.

Returns:

(bool) If True, V1 controller display.

isRadioView()[source]

Get if the display in miniviewer is in radiological orientation.

Returns:

(bool) If True, radiological orientation, otherwise neurological orientation.

loadConfig()[source]

Read the config from config.yml file.

Attempts to read an encrypted YAML configuration file from the properties directory, decrypt it using Fernet encryption, and parse it as YAML.

Returns:

(dict) Parsed configuration from the YAML file. Returns empty dict if parsing fails.

saveConfig()[source]

Save the current parameters in the config.yml file.

Encrypts and writes the current configuration (self.config) to config.yml using Fernet encryption. Creates the necessary directory structure if it doesn’t exist. After saving, updates the capsul configuration.

set_admin_hash(admin_hash)[source]

Set the password hash.

Parameters:

admin_hash – A string.

set_afni_path(path)[source]

Set the AFNI path.

Parameters:

path – (str) A path.

set_ants_path(path)[source]

Set the ANTS path

Parameters:

path – (str) A path.

setAutoSave(save)[source]

Set auto-save mode.

Parameters:

save – A boolean.

setBackgroundColor(color)[source]

Set background color and save configuration.

Parameters:

color – Color string (‘Black’, ‘Blue’, ‘Green’, ‘Grey’, ‘Orange’, ‘Red’, ‘Yellow’, ‘White’)

set_capsul_config(capsul_config_dict)[source]

Update Mia configuration with Capsul settings and synchronize tools configuration.

Called after editing Capsul config (via File > Mia preferences > Pipeline tab > Edit CAPSUL config) to synchronize Capsul settings with Mia preferences. Configures various neuroimaging tools (AFNI, ANTs, FSL, etc.) based on the Capsul engine configuration.

Parameters:

capsul_config_dict – Dictionary containing Capsul configuration.

Structure of capsul_config_dict:

{
    'engine': {
        'environment_name': {...configuration...}
    },
    'engine_modules': [...]
}
Private function:
  • _get_module_config: Extracts module configuration from the global Capsul configuration.

setChainCursors(chain_cursors)[source]

Set the value of the checkbox ‘chain cursor’ in the mini viewer.

Parameters:

chain_cursors – A boolean.

set_clinical_mode(clinical_mode)[source]

Enable or disable clinical mode.

Parameters:

clinical_mode – A boolean.

setControlV1(controlV1)[source]

Set controller display mode (True if V1).

Parameters:

controlV1 – A boolean.

set_freesurfer_setup(path)[source]

Set the freesurfer config file.

Parameters:

path – (str) Path to freesurfer/FreeSurferEnv.sh.

set_fsl_config(path)[source]

Set the FSL config file.

Parameters:

path – (str) Path to fsl/etc/fslconf/fsl.sh.

set_mainwindow_maximized(enabled)[source]

Set the maximized (full-screen) flag.

Parameters:

enabled – A boolean.

set_mainwindow_size(size)[source]

Set main window size.

Parameters:

size – A list of two integers.

set_matlab_path(path)[source]

Set the path of Matlab’s executable.

Parameters:

path – (str) A path.

set_matlab_standalone_path(path)[source]

Set the path of Matlab Compiler Runtime.

Parameters:

path – (str) A path.

set_max_projects(nb_max_projects)[source]

Set the maximum number of projects displayed in the “Saved projects” menu.

Parameters:

nb_max_projects – An integer.

set_max_thumbnails(nb_max_thumbnails)[source]

Set max thumbnails number at the data browser bottom.

Parameters:

nb_max_thumbnails – An integer.

set_mri_conv_path(path)[source]

Set the MRIManager.jar path.

Parameters:

path – (str) A path.

set_mrtrix_path(path)[source]

Set the mrtrix path.

Parameters:

path – (str) A path.

setNbAllSlicesMax(nb_slices_max)[source]

Set the number of slices to display in the mini-viewer.

Parameters:

nb_slices_max – (int) Maximum number of slices to display.

set_opened_projects(new_projects)[source]

Set the list of opened projects and saves the modification.

Parameters:

new_projects – (list[str]) A list of paths.

set_projects_save_path(path)[source]

Set the folder where the projects are saved.

Parameters:

path – (str) A path.

set_radioView(radio_view)[source]

Set the radiological / neurological orientation in mini viewer.

  • True for radiological

  • False for neurological

Parameters:

radio_view – A boolean.

set_referential(ref)[source]

Set the referential to “image Ref” or “World Coordinates” in anatomist_2 data viewer.

Parameters:

ref – (str) “0” for World Coordinates, “1” for Image Ref.

set_resources_path(path)[source]

Set the resources path.

Parameters:

path – (str) A path.

setShowAllSlices(show_all_slices)[source]

Set the show_all_slides setting in miniviewer.

Parameters:

show_all_slices – A boolean.

setSourceImageDir(source_image_dir)[source]

Set the source directory for project images.

Parameters:

source_image_dir – (str) A path.

set_spm_path(path)[source]

Set the path of SPM (license version).

Parameters:

path – (str) A path.

set_spm_standalone_path(path)[source]

Set the path of SPM (standalone version).

Parameters:

path – (str) A path.

setTextColor(color)[source]

Set text color and save configuration.

Parameters:

color – Color string (‘Black’, ‘Blue’, ‘Green’, ‘Grey’, ‘Orange’, ‘Red’, ‘Yellow’, ‘White’)

setThumbnailTag(thumbnail_tag)[source]

Set the tag that is displayed in the mini-viewer.

Parameters:

thumbnail_tag – A string.

set_use_afni(use_afni)[source]

Set the value of “use_afni” checkbox in the preferences.

Parameters:

use_afni – A boolean.

set_use_ants(use_ants)[source]

Set the value of “use_ants” checkbox in the preferences.

Parameters:

use_ants – A boolean.

set_use_freesurfer(use_freesurfer)[source]

Set the value of “use_freesurfer” checkbox in the preferences.

Parameters:

use_freesurfer – A boolean.

set_use_fsl(use_fsl)[source]

Set the value of “use_fsl” checkbox in the preferences.

Parameters:

use_fsl – A boolean.

set_use_matlab(use_matlab)[source]

Set the value of “use matlab” checkbox in the preferences.

Parameters:

use_matlab – A boolean.

set_use_matlab_standalone(use_matlab_standalone)[source]

Set the value of “use_matlab_standalone” checkbox in the preferences.

Parameters:

use_matlab – A boolean.

set_use_mrtrix(use_mrtrix)[source]

Set the value of “use_mrtrix” checkbox in the preferences.

Parameters:

use_mrtrix – A boolean.

set_user_mode(user_mode)[source]

Enable or disable user mode.

Parameters:

user_mode – A boolean.

set_use_spm(use_spm)[source]

Set the value of “use spm” checkbox in the preferences.

Parameters:

use_spm – A boolean.

set_use_spm_standalone(use_spm_standalone)[source]

Set the value of “use spm standalone” checkbox in the preferences.

Parameters:

use_spm_standalone – A boolean.

setViewerConfig(config_NeuRad)[source]

sets user’s configuration neuro or radio for data_viewer.

  • neuro: neurological

  • radio: radiological

Parameters:

config_NeuRad – A string.

setViewerFramerate(im_sec)[source]

sets user’s framerate for data_viewer.

Parameters:

im_sec – (int) Number of images per second.

update_capsul_config()[source]

Updates the global CapsulEngine object used for all operations in the Mia application.

The CapsulEngine is created once when needed and updated each time the configuration is saved. This method ensures that all necessary engine modules are loaded and configurations are properly imported from the saved settings.

Returns:

(capsul.engine.CapsulEngine) The updated CapsulEngine object, or None if the engine is not initialized.

class populse_mia.user_interface.pipeline_manager.pipeline_editor.FilterWidget(project, node_name, node, main_window)[source]

Bases: QWidget

A PyQt widget for filtering and selecting files in a pipeline’s Input_Filter process.

This widget provides a user-friendly interface for filtering database files using both rapid and advanced search functionalities. It allows users to:

  • Browse and select files from the project database.

  • Perform rapid searches using a text-based search bar.

  • Apply advanced filters using a customizable search interface.

  • Visualize and update tags associated with the files.

  • Save the configured filter to the process for further use in the pipeline.

The widget is designed to integrate seamlessly with the pipeline editor, providing real-time feedback and updates as filters are applied.

__init__(project, node_name, node, main_window)[source]

Initialize the Filter Widget for pipeline node filtering.

Parameters:
  • project – Current project instance containing database and configuration.

  • node_name – Display name of the filter node.

  • node – Input_Filter node instance containing the filter process.

  • main_window – Parent main window for UI hierarchy.

layout_view()[source]

Configure and initialize the main widget layout.

Sets up a vertical layout containing:
  • Search bar with reset button

  • Advanced search widget

  • Data table

  • Action buttons (visualize tags, filter, OK, Cancel)

The window is sized to 60% width and 80% height of the screen resolution.

normalize_scan_path(scan_path)[source]

Normalize a scan path to a logical project-relative path.

Converts any scan path (absolute, relative, or symlinked) into a consistent project-relative representation, preferably starting at the project’s data directory.

Resolution strategy (in order of preference):
  1. Path relative to project root (if path is under project)

  2. Path relative to ‘data/’ directory (semantic anchor fallback)

  3. Absolute path string (last resort)

Parameters:

scan_path – File path to normalize (absolute or relative)

Returns:

Normalized path string, relative to project root when possible

Examples

>>> normalize_scan_path('/abs/path/project/data/scans/001.tif')
'data/scans/001.tif'
>>> normalize_scan_path('../other/data/scans/002.tif')
'data/scans/002.tif'

Note

Handles symlinks, mount aliases, and varying working directories robustly. Does not require paths to exist on disk.

ok_clicked()[source]

Apply the configured filter to the process and close the dialog.

Collects filter parameters from the advanced search interface and rapid search text field, creates a Filter object, and applies it to the process if it’s a ProcessMIA instance. The dialog is then closed regardless of process type.

Reset search interface to default state.

Clears the rapid search text field, resets advanced search rows, and restores the table to display all available scans. The table is updated efficiently by tracking the previous visualization state.

Side effects:
  • Clears rapid_search text field

  • Resets advanced_search rows to empty list

  • Updates advanced_search display

  • Restores table_data to show all scans from scan_list

search_str(str_search)[source]

Filter and update the displayed scans based on a search string.

Performs a rapid search to filter scans in the browser view. An empty search string displays all available scans. Special handling is provided for undefined values and custom search filters.

Parameters:

str_search – Search query string. Use empty string to show all scans, or NOT_DEFINED_VALUE constant to filter scans with undefined fields.

Side Effects:
  • Updates self.table_data.scans_to_visualize with filtered results

  • Updates self.advanced_search.scans_list with filtered results

  • Triggers table row update via self.table_data.update_visualized_rows()

update_tag_to_filter()[source]

Display a tag selection dialog and update the filter button text.

Opens a popup dialog allowing the user to select from visible project tags. If a tag is selected (dialog accepted), updates the filter button’s text to reflect the chosen tag.

update_tags()[source]

Update the list of visualized tags through a user dialog.

Opens a modal dialog that allows users to select which tags should be displayed in the table view. Upon confirmation, the method:

  • Updates table columns to show only selected tags

  • Refreshes advanced search field options

  • Ensures TAG_FILENAME is always included in visible tags

The dialog is automatically cleaned up after use, whether the user confirms or cancels the operation.

class populse_mia.user_interface.pipeline_manager.pipeline_editor.PopUpClosePipeline(pipeline_name)[source]

Bases: QDialog

Dialog displayed when closing a modified pipeline editor.

This dialog asks the user whether they want to save changes before closing the pipeline editor. It provides three options: save, don’t save, or cancel.

Signals:

save_as_signal: Emitted when the user chooses to save the pipeline. do_not_save_signal: Emitted when the user chooses not to save

the pipeline.

cancel_signal: Emitted when the user cancels the closing action.

bool_save_as

Indicates if the pipeline should be saved under a new name.

Type:

bool

bool_exit

Indicates if the editor can be closed.

Type:

bool

pipeline_name

Name of the pipeline being edited.

Type:

str

save_as_signal

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

do_not_save_signal

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

cancel_signal

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

__init__(pipeline_name)[source]

Initialize the dialog with the pipeline name.

Parameters:

(str) (pipeline_name) – Name of the pipeline (basename).

_connect_signals()[source]

Connect button signals to their respective slots.

_setup_ui()[source]

Set up the dialog’s user interface.

can_exit()[source]

Check if the editor can be closed.

Return (bool): True if the editor can be closed, False otherwise.

cancel_clicked()[source]

Handle the cancel button click.

Sets bool_exit to False, emits cancel_signal, and closes the dialog.

do_not_save_clicked()[source]

Handle the ‘Do not save’ button click.

Sets bool_exit to True, emits do_not_save_signal, and closes the dialog.

save_as_clicked()[source]

Handle the ‘Save’ button click.

Sets bool_save_as and bool_exit to True, emits save_as_signal, and closes the dialog.

populse_mia.user_interface.pipeline_manager.pipeline_editor.verCmp(first_ver, sec_ver, comp)[source]

Version comparator.

Compares two versions according to the specified comparator:
  • ‘eq’: Returns True if the first version is equal to the second.

  • ‘sup’: Returns True if the first version is greater than or equal

    to the second.

  • ‘inf’: Returns True if the first version is less than or equal to

    the second.

Parameters:
  • (str) (comp) – The first version to compare (e.g., ‘0.13.0’).

  • (str) – The second version to compare (e.g., ‘0.13.0’).

  • (str) – The comparator to use (‘sup’, ‘inf’, ‘eq’).

Returns:

True if the comparison condition is satisfied, False otherwise.

Contains:
Private function:
  • normalise: transform a version of a package to a corresponding list of integer

class populse_mia.user_interface.pipeline_manager.pipeline_editor.PipelineEditor(project, main_window)[source]

Bases: PipelineDeveloperView

Graphical editor for creating, editing, and managing pipelines.

This view provides interactive tools to build pipeline graphs, connect nodes and plugs, edit node properties, and track modifications. It also handles persistence (save/export) and undo/redo history management.

pipeline_saved

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

pipeline_modified

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

__init__(project, main_window)[source]

Initialize the PipelineEditor for visual pipeline development.

Sets up the pipeline editor with project context and initializes undo/redo functionality.

Parameters:

project – The current project instance containing pipeline data and configuration.

Parm main_window:

The main application window instance for UI integration.

Delete a link between two pipeline nodes.

Removes a connection between a source node’s output plug and a destination node’s input plug, updates the pipeline state, and records the action in history.

Parameters:
  • link – Link specification string in the format “source_node.output_plug->dest_node.input_plug”.If None, uses the current link stored in self._current_link.

  • from_undo – Whether this deletion is being performed as part of an undo operation. Affects history recording.

  • from_redo – Whether this deletion is being performed as part of a redo operation. Affects history recording.

Side Effects:
  • Updates self._current_link to the deleted link

  • Modifies self._current_link_def with link component references

  • Calls parent class’s _del_link() to perform actual deletion

  • Records action in history unless from undo/redo

_export_plug(pipeline_parameter=None, optional=None, weak_link=None, from_undo=False, from_redo=False, temp_plug_name=None, multi_export=False)[source]

Export a plug to a pipeline global input or output.

This method exports a node plug to the pipeline level, making it accessible as a pipeline parameter. It handles name conflicts, creates appropriate links, and maintains operation history for undo/redo functionality.

Parameters:
  • (str) (pipeline_parameter) – Name for the exported pipeline parameter. If None, prompts user for a name via dialog. Defaults to None.

  • (bool) (multi_export) – Whether the exported plug is optional. If None, derived from dialog checkbox or plug configuration. Defaults to None.

  • (bool) – Whether to create a weak link (doesn’t enforce execution order). If None, derived from dialog or defaults to False.

  • (bool) – True when called during an undo operation. Used to prevent circular history updates. Defaults to False.

  • (bool) – True when called during a redo operation. Used to prevent circular history updates. Defaults to False.

  • (tuple) (temp_plug_name) – A (node_name, plug_name) tuple specifying the plug to export. If None, uses self._temp_plug_name. Defaults to None.

  • (bool) – True when exporting multiple plugs simultaneously. Changes return behavior and error handling. Defaults to False.

Return (str):

When multi_export is True, returns the plug name on success or None on failure. When multi_export is False, returns None after updating the UI and history.

Raises:
  • TraitError – Logged as warning when plug export fails due to trait issues.

  • ValueError – Logged as warning when export fails due to invalid values.

Side Effects:
  • May display dialog boxes for user input

  • Updates pipeline structure and UI

  • Adds entry to operation history (unless from_undo/from_redo)

  • Shows status message in main window

Handle link release event and update pipeline history.

Called when a user releases a link in the pipeline editor. This method extends the parent class behavior by recording the link addition in the history and displaying a status message.

Parameters:

event – Mouse event corresponding to the link release.

_remove_plug(plug_names=None, from_undo=False, from_redo=False, from_export_plugs=False)[source]

Remove one or more plugs from the pipeline.

This method removes plugs from the pipeline, tracks their connections for potential undo/redo operations, and updates the application history unless called from an export operation.

Parameters:
  • plug_names – A tuple (node_name, plug_name) or list of such tuples specifying the plug(s) to remove. If None, uses self._temp_plug_name.

  • from_undo – Whether this method is being called from an undo operation.

  • from_redo – Whether this method is being called from a redo operation.

  • from_export_plugs – Whether this method is being called from an export plugs undo/redo operation. When True, history is not updated.

Note:

For each removed plug, stores [plug_info, connected_plugs, optional_flag] in the history for potential restoration.

Add a link between two nodes in the pipeline.

Creates a connection between a source node’s output plug and a destination node’s input plug. The link is represented as “node.plug->node.plug” format and added to the pipeline scene.

Parameters:
  • source – A tuple of (node_name, plug_name) for the source connection.

  • dest – A tuple of (node_name, plug_name) for the destination connection.

  • active – Whether the link is currently active/enabled.

  • weak – Whether the link is a weak reference that doesn’t enforce strict execution dependencies.

  • from_undo – Whether this action originates from an undo operation. Defaults to False.

  • from_redo – Whether this action originates from a redo operation. Defaults to False.

  • allow_export – Whether to allow this link in exported pipelines. Defaults to False.

Side Effects:
  • Adds the link to the pipeline scene

  • Updates the pipeline visualization

  • Records the action in history (unless from undo/redo)

  • Displays a status message in the main window

add_named_process(class_process, node_name=None, from_undo=False, from_redo=False, links=None)[source]

Add a process to the pipeline with optional link restoration.

This method adds a named process to the pipeline and configures it according to project settings. It also handles link restoration when the action is part of an undo/redo operation.

Parameters:
  • (str) (node_name) – The name of the process class to instantiate.

  • (str) – Custom name for the node. If None, the name is derived from the process’s context_name or name attribute. Defaults to None.

  • (bool) (from_redo) – Whether this action is part of an undo operation. Defaults to False.

  • (bool) – Whether this action is part of a redo operation. Defaults to False.

  • (list) (links) – List of link tuples to restore, where each tuple contains (source, dest, active, weak). Used during undo/redo operations. Defaults to None.

Side Effects:
  • Adds process to the pipeline

  • Configures project settings if applicable

  • Restores links if provided

  • Updates history for undo/redo

  • Updates UI status bar and buttons

check_modifications()[source]

Check and update pipeline nodes that have been modified.

This method iterates through all pipeline nodes and detects if the underlying process definition has changed (added/removed inputs/outputs).

When changes are detected, it:
  • Recreates the node with the updated process definition

  • Preserves the node’s position in the scene

  • Attempts to restore compatible links

  • Removes incompatible links and notifies the user

Side Effects:

Modifies self.scene.gnodes, self.scene.glinks, and pipeline.nodes. Displays a warning dialog if any links are removed.

del_node(node_name=None, from_undo=False, from_redo=False)[source]

Deletes a node from the pipeline and updates the GUI and history accordingly.

Parameters:
  • (str) (node_name) – The name of the node to delete. If not provided, the currently selected node is used.

  • (bool) (from_redo) – True if the deletion was triggered by an undo operation.

  • (bool) – True if the deletion was triggered by a redo operation.

export_node_plugs(node_name, inputs=True, outputs=True, optional=False, from_undo=False, from_redo=False)[source]

Export plugs (parameters) from a pipeline node to make them available externally.

This method identifies and exports node plugs that meet the specified criteria (input/output type, optional status, unlinked status) and are not in the pipeline’s exclusion list.

Parameters:
  • node_name – Name of the node whose plugs should be exported.

  • inputs – Whether to export input plugs. Defaults to True.

  • outputs – Whether to export output plugs. Defaults to True.

  • optional – Whether to include optional plugs in the export. Defaults to False.

  • from_undo – Whether this call originates from an undo operation. Defaults to False.

  • from_redo – Whether this call originates from a redo operation. Defaults to False.

Note:
  • Only unlinked plugs are exported (outputs without links_to, inputs without links_from)

  • Certain system plugs are automatically excluded (nodes_activation, selection_changed, etc.)

  • The operation is recorded in the history for undo/redo support

get_current_filename()[source]

Return the relative path to the last saved pipeline file.

Returns the relative path from the current working directory to the file where this pipeline was most recently saved. If the pipeline has never been saved, returns an empty string.

Return (str):

Relative path to the pipeline file, or empty string if never saved.

save_pipeline(filename=None)[source]

Save the pipeline to a Python file.

This method saves the current pipeline configuration to a file. If no filename is provided, it prompts the user with a file dialog. The method performs validation to ensure the filename is valid (doesn’t start with a digit, has .py extension) and checks user permissions.

Parameters:

(str) (filename) – Path where the pipeline should be saved. If None, a file dialog will be shown. Defaults to None.

Return (str):
The absolute path of the saved pipeline file,

or None if:

  • The pipeline is empty (fewer than 2 nodes)

  • The user cancelled the save dialog

  • The filename is invalid

  • The user lacks permission to overwrite an existing file

Note:
  • pipeline_saved: Signal emitted with the filename when save is

    successful.

update_history(history_maker, from_undo, from_redo)[source]

Update the undo/redo history after a pipeline action.

Manages the undo and redo stacks based on the action performed. When an action is undone, it’s moved to the redo stack. When a new action is performed (not from undo/redo), it’s added to the undo stack and complementary redo entries are cleaned up to maintain consistency.

Parameters:
  • history_maker – A list describing the action, where history_maker[0] is the action type (e.g., ‘add_process’, ‘delete_process’, ‘update_node_name’) and history_maker[1] is typically the affected node identifier.

  • (bool) (from_redo) – Whether this update stems from an undo operation. Defaults to False.

  • (bool) – Whether this update stems from a redo operation. Defaults to False.

Note:
  • ‘update_node_name’ actions are not added to the undo stack

  • Complementary actions (add/delete for the same process) are removed from the redo stack when a new action occurs

  • pipeline_modified: Signal emitted indicating the pipeline has been modified.

update_node_name(old_node, old_node_name, new_node_name, from_undo=False, from_redo=False)[source]

Update a node’s name in the pipeline, preserving all connections.

This method renames a node by: 1. Temporarily removing all links connected to the node 2. Renaming the node in the pipeline 3. Restoring all links with the updated node name 4. Recording the action in the history for undo/redo support

Parameters:
  • old_node – The node object to rename.

  • old_node_name – The current name of the node.

  • new_node_name – The desired new name for the node.

  • from_undo – Whether this action is being performed as part of an undo operation. Defaults to False.

  • from_redo – Whether this action is being performed as part of a redo operation. Defaults to False.

Side Effects:
  • Updates the pipeline’s node registry

  • Removes and recreates all links connected to the node

  • Updates pipeline activation states

  • Records action in history

  • Displays status message to user

update_plug_value(node_name, new_value, plug_name, value_type, from_undo=False, from_redo=False)[source]

Update a node’s plug value and record the change in history.

Updates the specified plug on the given node with a new value. The update is recorded in the history for undo/redo operations unless it’s already part of an undo/redo action.

Parameters:
  • node_name – The name of the node containing the plug.

  • new_value – The new value to assign to the plug. Will be cast to value_type unless from_undo or from_redo is True.

  • plug_name – The name of the plug to update.

  • value_type – The type constructor to apply to new_value (e.g., int, float, str). Ignored when from_undo or from_redo is True.

  • from_undo – If True, indicates this update is from an undo operation. Defaults to False.

  • from_redo – If True, indicates this update is from a redo operation. Defaults to False.

Side Effects:
  • Updates the plug value in the pipeline

  • Records the change in history (unless from undo/redo)

  • Displays a status message in the main window

  • Pops from the undo stack if from undo/redo

class populse_mia.user_interface.pipeline_manager.pipeline_editor.PipelineEditorTabs(project, scan_list, main_window)[source]

Bases: QTabWidget

Tab widget for managing multiple pipeline editors.

This widget provides a tabbed interface for creating, editing, and managing multiple pipeline configurations. Each tab contains a PipelineEditor instance with its own undo/redo history.

pipeline_saved

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

node_clicked

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

process_clicked

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

switch_clicked

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

__init__(project, scan_list, main_window)[source]

Initialize the pipeline editor tabs.

Parameters:
  • project – Current project instance in the software.

  • scan_list – List of selected database files.

  • main_window – Main application window reference.

check_modifications(current_index)[source]

Check if nodes in the current pipeline have been modified.

Validates modifications when switching between pipeline tabs. Skips validation for the special “add new pipeline” tab (last position).

Parameters:

current_index – The index of the tab being switched to.

Note:

The last tab (‘+’ button) may not have a widget, which is handled gracefully by catching AttributeError.

close_tab(idx)[source]

Close a tab and its associated editor, prompting to save if modified.

Removes the specified tab and cleans up its undo/redo history. If the tab contains unsaved changes (indicated by “ *” suffix), prompts the user to save before closing. If all tabs are closed, creates a new default pipeline.

Parameters:

idx – index of the tab to close

emit_node_clicked(node_name, process)[source]

Emit the appropriate signal when a node is clicked.

Emits either process_clicked or node_clicked signal depending on whether the process parameter is a Process instance.

Parameters:
  • node_name – The name of the clicked node.

  • process – The process associated with the node. If this is a Process instance, emits process_clicked; otherwise emits node_clicked.

emit_pipeline_saved(filename)[source]

Update the current tab title and emit the pipeline_saved signal.

Parameters:

filename – Path to the saved pipeline file.

emit_switch_clicked(node_name, switch)[source]

Emit a signal when a switch is toggled.

Parameters:
  • node_name – The name of the node whose switch was clicked.

  • switch – The Switch associated with the node.

Emits:

switch_clicked: Signal containing the node name and the Switch.

export_to_db_scans(node_name)[source]

Export the input of a filter to “database_scans” plug.

If database_scans already exists as a pipeline parameter, creates a link from database_scans to the node’s input. Otherwise, exports the node’s input parameter as database_scans at the pipeline level.

Parameters:

node_name – Name of the node whose input should be exported.

Note:

This method automatically updates the editor scene after modification.

get_capsul_engine()[source]

Configure and return a CapsulEngine for the current pipeline.

Retrieves a CapsulEngine instance from the MIA configuration and sets up the study configuration with project-specific directories. If the current pipeline has completion attributes, they are preserved during the engine setup process.

Returns (CapsulEngine):

Configured engine instance with study directories set to the project’s raw_data and derived_data folders.

Note:

This method temporarily saves and restores completion engine attributes to prevent loss of configuration when switching between pipelines.

get_current_editor()[source]

Return the editor corresponding to the currently selected tab.

Returns:

Editor instance for the active tab.

get_current_filename()[source]

Return the relative path of the file last saved in the current editor.

If the pipeline has never been saved, the current tab title is returned.

Returns:

The filename for the current editor.

get_current_pipeline()[source]

Return the pipeline associated with the current editor.

Returns None if no editor or scene is available.

Returns:

The pipeline for the current editor

get_current_tab_name()[source]

Return the name of the currently selected tab.

Trailing “*” and “&” characters are stripped.

Returns:

The current tab name.

get_editor_by_file_name(file_name)[source]

Return the editor associated with the given pipeline filename.

The filename corresponds to the last saved location of the pipeline.

Parameters:

file_name – Name of the file the pipeline was last saved to.

Returns:

The editor corresponding to the file name.

get_editor_by_index(idx)[source]

Retrieve an editor widget by its tab index.

Parameters:

idx – Zero-based index of the editor tab, or None if not found.

Returns:

The editor widget at the specified index, or None if idx is None or if the index corresponds to the “add tab” button (last tab) or if index out of range.

Note:

The last tab position is reserved for the “add tab” button and does not contain an editor widget.

get_editor_by_tab_name(tab_name)[source]

Retrieve the editor instance associated with a specific tab name.

Parameters:

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

Returns:

The editor instance corresponding to the specified tab name, or None if the tab is not found.

Raises:
  • ValueError: If tab_name is empty or None.

  • KeyError: If no tab exists with the given name.

get_filename_by_index(idx)[source]

Get the filename for the pipeline at the specified editor index.

Returns the relative path to the file where the pipeline was last saved. If the pipeline has never been saved, returns the tab title instead.

Parameters:

idx – The zero-based index of the editor tab.

Returns:

str or None. The filename or tab title if the editor exists, None if no editor exists at the given index.

get_index_by_editor(editor)[source]

Find the tab index for a given editor widget.

Parameters:

editor – The pipeline editor widget to locate.

Returns:

The zero-based index of the editor’s tab, or None if not found.

Note:

Searches all tabs except the last one (count() - 1).

get_index_by_filename(filename)[source]

Get the index of the first tab with the specified filename.

Parameters:

(str) (filename) – The pipeline filename to search for. Can be an absolute or relative path; will be normalized to relative.

Return (int):

The zero-based index of the matching tab, or None if no match is found.

Note:

Filenames are internally stored as relative paths for consistency. Only searches up to count() - 1 to exclude special tabs if any.

get_index_by_tab_name(tab_name)[source]

Find the index of a tab by its name.

Searches through all tabs (excluding the last one) to find a tab matching the given name.

Parameters:

(str) (tab_name) – The name of the tab to locate.

Return (int):

The zero-based index of the matching tab, or None if no match is found.

get_tab_name_by_index(idx)[source]

Get the clean tab name at the specified index.

Retrieves the tab text at the given index and removes formatting characters:

  • Qt keyboard shortcut indicators (ampersands)

  • Unsaved file indicators (trailing “ *”)

Parameters:

idx – Zero-based index of the tab.

Return (str):

The cleaned tab name, or None if the index is invalid or corresponds to the “add tab” button (last position).

has_pipeline_nodes()[source]

Check if any pipeline in the editor tabs contains nodes.

Iterates through all tab widgets and checks if any pipeline editor contains nodes by examining the presence of plugs in the pipeline’s root node.

Return (bool):

True if at least one pipeline contains nodes, False otherwise.

load_pipeline(filename=None)[source]

Load a pipeline into the editor.

Opens a pipeline file in a new or existing tab. If the pipeline is already open, switches to that tab. If the current tab is not empty, creates a new tab for the pipeline.

Parameters:

(str) (filename) – Path to the pipeline file to load. If None, prompts the user to select a file. Defaults to None.

Return (None):

Returns early on success, or cleans up and returns on failure.

Note:

This method is also called from open_sub_pipeline with a filename.

load_pipeline_parameters()[source]

Load pipeline parameters for the current editor.

Opens a file dialog in the user’s home directory to select a JSON file containing pipeline configuration parameters, then loads those parameters into the currently active editor’s pipeline.

new_tab()[source]

Create and initialize a new pipeline editor tab.

Creates a new PipelineEditor instance, connects all necessary signals, initializes its state, generates a unique tab name, and makes it the current tab. The new tab is inserted at the last tab position.

The tab name follows the pattern “New Pipeline {n}” where n is the first available index from 1 to 49.

open_filter(node_name)[source]

Open a filter widget for the specified pipeline node.

Creates and displays a FilterWidget instance for filtering data associated with the given node in the current pipeline.

Parameters:

node_name – The name of the node to apply filters to.

open_sub_pipeline(sub_pipeline)[source]

Open a sub-pipeline in a new tab.

This method locates and loads a sub-pipeline by:
  1. Reading the process configuration to find package paths

  2. Determining the pipeline’s source package (mia_processes or custom)

  3. Resolving the full filesystem path to the pipeline file

  4. Loading the pipeline in a new tab

Parameters:

sub_pipeline – The pipeline object to open. Must have a ‘name’ attribute and ‘__module__’ attribute for package resolution.

reset_pipeline()[source]

Reset and refresh the currently active editor’s pipeline display.

This triggers an asynchronous update of the pipeline view after a short delay (20ms). The update strategy depends on the editor’s view mode:

  • Logical view: Displays logical representations of nodes, plugs,

    and links

  • Normal view: Displays standard representations of nodes, plugs,

    and links

Note:

The update is performed asynchronously via a single-shot timer to allow the UI thread to remain responsive.

save_pipeline(new_file_name=None)[source]

Save the current pipeline to a file.

Performs either a “Save” or “Save As” operation depending on whether a filename is provided. Updates the tab text and emits a signal upon successful save.

Parameters:

(str) (new_file_name) – Target filename for the pipeline. If None, triggers a “Save As” dialog. Defaults to None.

Return (str or None):

The basename of the saved file if successful, None otherwise.

Side Effects:
  • Updates the current tab text with the new filename

  • Emits pipeline_saved signal (only for explicit saves)

  • Modifies the editor’s _pipeline_filename attribute

save_pipeline_parameters()[source]

Save pipeline parameters from the currently active editor.

Delegates the save operation to the current editor’s save method.

set_current_editor_by_editor(editor)[source]

Set the specified editor as the currently active editor.

Activates the tab containing the given editor by switching to its index.

Parameters:

editor – The editor instance to make active. Must be an editor that exists within one of the managed tabs.

set_current_editor_by_file_name(file_name)[source]

Activate the editor tab containing the specified file.

Sets the active editor tab to the one associated with the given file name, typically used when reopening a previously saved pipeline.

Parame file_name:

The name of the file whose editor tab should be activated.

set_current_editor_by_tab_name(tab_name)[source]

Activate the editor tab with the specified name.

Parameters:

tab_name – The display name of the tab to activate.

set_tab_index(index)[source]

Activate the tab at the specified index and update the current node.

Sets the active tab, stores it as the previous index for navigation history, and updates the current node state for the newly active editor.

Parameters:

index – The zero-based index of the tab to activate.

update_iteration_checkbox()[source]

Update the iteration checkbox state based on pipeline node names.

Sets the iteration checkbox to checked if any pipeline node has ‘iterated_’ in its key name, otherwise sets it to unchecked. If no valid pipeline exists or the pipeline lacks nodes, the checkbox is unchecked.

update_current_node()[source]

Update the node parameters display for the current pipeline.

Refreshes the UI to display parameters for all nodes in the current pipeline, updates user button states, iteration checkbox, and iterated tag display.

update_history(editor)[source]

Update the undo/redo history for the specified editor.

Saves the editor’s current undo and redo stacks and marks the active tab as modified by appending an asterisk to its title if not already present.

Parameters:

editor – The editor instance whose history should be saved.

Note:

This method assumes the editor is in the currently active tab.

update_pipeline_editors(editor)[source]

Update the pipeline editors after changes to the specified editor.

Synchronizes the editor’s undo/redo history and refreshes the scans list to reflect any modifications made in the pipeline editor.

Parameters:

editor – The editor instance that was modified.

update_scans_list()[source]

Update the list of database scans in every pipeline editor.

Iterates through all editor tabs (excluding the last tab, reserved for the “add tab” button) and updates the database_scans attribute for each pipeline that supports it. Also refreshes the iteration checkbox state after updating.

Note:

Silently continues if updating a pipeline fails, logging the error without interrupting the update process for remaining pipelines.

populse_mia.user_interface.pipeline_manager.pipeline_editor.find_filename(paths_list, packages_list, file_name)[source]

Locate a pipeline file within configured paths.

Searches for a file with the given name (with .py or .xml extension) by traversing through base paths combined with package subdirectories. Performs case-insensitive matching to handle filesystem sensitivity issues.

Parameters:
  • paths_list – Base directory paths from process_config.yml

  • packages_list – Ordered list of package subdirectories to traverse

  • file_name – Base name of the sub-pipeline file (without extension)

Returns:

Absolute path to the matched file, or None if not found

populse_mia.user_interface.pipeline_manager.pipeline_editor.get_path(name, dictionary, prev_paths=None, pckg=None)[source]

Recursively search for a module name inside a nested dictionary structure and return its full path as a list of keys.

The tree is assumed to be a mapping where:
  • Intermediate nodes are dictionaries (packages),

  • Leaf nodes are strings (module names).

Parameters:
  • (str) (pckg) – Name of the module to locate in the tree.

  • (dict) (dictionary) – The nested dictionary representing the tree structure.

  • (list[str]) (prev_paths) – The accumulated path leading to the current dictionary. If None, a new path list is created.

  • (str) – If provided, navigation starts inside that package name.

Return (list[str]):

A list of keys representing the path to the module, or None if the module is not found.

populse_mia.user_interface.pipeline_manager.pipeline_editor.save_pipeline(pipeline, filename)[source]

Save a pipeline to a file in the appropriate format.

Automatically detects the output format based on the file extension. Supported formats are Python source (.py) and XML (.xml). If no recognized extension is provided, defaults to Python format.

Parameters:
  • pipeline – The pipeline object to serialize and save.

  • filename – Path to the output file. The extension determines the output format (.py or .xml).

Note:

Unrecognized extensions will default to Python source format (.py)

Examples

>>> save_pipeline(my_pipeline, "model.py")
>>> save_pipeline(my_pipeline, "config.xml")
>>> save_pipeline(my_pipeline, "output")  # Defaults to .py format