spinetoolbox.project_items.tool

Tool plugin.

author:
  1. Marin (KTH)
date:

12.9.2019

Package Contents

class spinetoolbox.project_items.tool.item_maker(name, description, x, y, toolbox, project, logger, tool='', execute_in_work=True, cmd_line_args=None)

Bases: spinetoolbox.project_item.ProjectItem

Tool class.

Parameters:
  • name (str) – Object name
  • description (str) – Object description
  • x (float) – Initial X coordinate of item icon
  • y (float) – Initial Y coordinate of item icon
  • toolbox (ToolboxUI) – QMainWindow instance
  • project (SpineToolboxProject) – the project this item belongs to
  • logger (LoggerInterface) – a logger instance
  • tool (str) – Name of this Tool’s Tool specification
  • execute_in_work (bool) – Execute associated Tool specification in work (True) or source directory (False)
  • cmd_line_args (list) – Tool command line arguments
static item_type()

See base class.

static category()

See base class.

make_signal_handler_dict(self)

Returns a dictionary of all shared signals and their handlers. This is to enable simpler connecting and disconnecting.

restore_selections(self)

Restore selections into shared widgets when this project item is selected.

update_execution_mode(self, checked)

Pushed a new UpdateToolExecuteInWorkCommand to the toolbox stack.

do_update_execution_mode(self, execute_in_work)

Updates execute_in_work setting.

update_execute_in_work_button(self)
update_tool_specification(self, row)

Update Tool specification according to selection in the specification comboBox.

Parameters:row (int) – Selected row in the comboBox
update_tool_cmd_line_args(self)

Updates tool cmd line args list as line edit text is changed.

do_update_tool_cmd_line_args(self, cmd_line_args)
set_tool_specification(self, tool_specification)

Pushes a new SetToolSpecificationCommand to the toolbox’ undo stack.

do_set_tool_specification(self, tool_specification)

Sets Tool specification for this Tool. Removes Tool specification if None given as argument.

Parameters:tool_specification (ToolSpecification) – Tool specification of this Tool. None removes the specification.
update_tool_ui(self)

Updates Tool UI to show Tool specification details. Used when Tool specification is changed. Overrides execution mode (work or source) with the specification default.

update_tool_models(self)

Update Tool models with Tool specification details. Used when Tool specification is changed. Overrides execution mode (work or source) with the specification default.

open_results(self, checked=False)

Open output directory in file browser.

edit_tool_specification(self)

Open Tool specification editor for the Tool specification attached to this Tool.

open_tool_specification_file(self)

Open Tool specification file.

open_tool_main_program_file(self)

Open Tool specification main program file in an external text edit application.

open_tool_main_directory(self)

Open directory where the Tool specification main program is located in file explorer.

tool_specification(self)

Returns Tool specification.

populate_source_file_model(self, items)

Add required source files (includes) into a model. If items is None or an empty list, model is cleared.

populate_input_file_model(self, items)

Add required Tool input files into a model. If items is None or an empty list, model is cleared.

populate_opt_input_file_model(self, items)

Add optional Tool specification files into a model. If items is None or an empty list, model is cleared.

populate_output_file_model(self, items)

Add Tool output files into a model. If items is None or an empty list, model is cleared.

populate_specification_model(self, populate)

Add all tool specifications to a single QTreeView.

Parameters:populate (bool) – False to clear model, True to populate.
update_name_label(self)

Update Tool tab name label. Used only when renaming project items.

_update_base_directory(self)

Updates the path to the base directory, depending on execute_in_work.

output_resources_forward(self)

See base class.

_find_last_output_files(self)

Returns a list of most recent output files from the results directory.

Returns:list
execute_backward(self, resources)

See base class.

execute_forward(self, resources)

See base class.

count_files_and_dirs(self)

Count the number of files and directories in required input files model.

Returns:Tuple containing the number of required files and directories.
_optional_output_destination_paths(self, paths)

Returns a dictionary telling where optional output files should be copied to before execution.

Parameters:paths (dict) – key is the optional file name pattern, value is a list of paths to source files
Returns:a map from source path to destination path
Return type:dict
create_input_dirs(self)

Iterate items in required input files and check if there are any directories to create. Create found directories directly to work or source directory.

Returns:Boolean variable depending on success
copy_input_files(self, paths)

Copy input files from given paths to work or source directory, depending on where the Tool specification requires them to be.

Parameters:paths (dict) – Key is path to destination file, value is path to source file.
Returns:Boolean variable depending on operation success
_copy_optional_input_files(self, paths)

Copy optional input files from given paths to work or source directory, depending on where the Tool specification requires them to be.

Parameters:paths (dict) – key is the source path, value is the destination path
copy_program_files(self)

Copies Tool specification source files to base directory.

_find_input_files(self, resources)

Iterates files in required input files model and looks for them in the given resources.

Parameters:resources (list) – resources available
Returns:Dictionary mapping required files to path where they are found, or to None if not found
_find_optional_input_files(self, resources)

Tries to find optional input files from previous project items in the DAG. Returns found paths.

Parameters:resources (list) – resources available
Returns:Dictionary of optional input file paths or an empty dictionary if no files found. Key is the optional input item and value is a list of paths that matches the item.
static _filepaths_from_resources(resources)

Returns file paths from given resources.

Parameters:resources (list) – resources available
Returns:a list of file paths, possibly including patterns
_find_file(self, filename, resources)

Returns all occurrences of full paths to given file name in resources available.

Parameters:
  • filename (str) – Searched file name (no path)
  • resources (list) – list of resources available from upstream items
Returns:

Full paths to file if found, None if not found

Return type:

list

static _find_optional_files(pattern, available_file_paths)

Returns a list of found paths to files that match the given pattern in files available from the execution instance.

Parameters:
  • pattern (str) – file pattern
  • available_file_paths (list) – list of available file paths from upstream items
Returns:

List of (full) paths

Return type:

list

handle_execution_finished(self, return_code)

Handles Tool specification execution finished.

Parameters:return_code (int) – Process exit code
handle_output_files(self, ret)

Copies Tool specification output files from work directory to result directory.

Parameters:ret (int) – Tool specification process return value
create_output_dirs(self)

Makes sure that work directory has the necessary output directories for Tool output files. Checks only “outputfiles” list. Alternatively you can add directories to “inputfiles” list in the tool definition file.

Returns:True for success, False otherwise.
Return type:bool
Raises:OSError – If creating an output directory to work fails.
copy_output_files(self, target_dir)

Copies Tool specification output files from work directory to given target directory.

Parameters:target_dir (str) – Destination directory for Tool specification output files
Returns:Contains two lists. The first list contains paths to successfully copied files. The second list contains paths (or patterns) of Tool specification output files that were not found.
Return type:tuple
Raises:OSError – If creating a directory fails.
stop_execution(self)

Stops executing this Tool.

_do_handle_dag_changed(self, resources)

See base class.

item_dict(self)

Returns a dictionary corresponding to this item.

custom_context_menu(self, parent, pos)

Returns the context menu for this item.

Parameters:
  • parent (QWidget) – The widget that is controlling the menu
  • pos (QPoint) – Position on screen
apply_context_menu_action(self, parent, action)

Applies given action from context menu. Implement in subclasses as needed.

Parameters:
  • parent (QWidget) – The widget that is controlling the menu
  • action (str) – The selected action
rename(self, new_name)

Rename this item.

Parameters:new_name (str) – New name
Returns:Boolean value depending on success
Return type:bool
notify_destination(self, source_item)

See base class.

static default_name_prefix()

see base class

static _file_path_duplicates(file_paths)

Returns a list of lists of duplicate items in file_paths.

_notify_if_duplicate_file_paths(self, duplicates)

Adds a notification if duplicates contains items.

_flatten_file_path_duplicates(self, file_paths, log_duplicates=False)

Flattens the extra duplicate dimension in file_paths.

static _database_urls(resources)

Pries database URLs and their providers’ names from resources.

Parameters:resources (list) – a list of ProjectItemResource objects
Returns:a mapping from resource provider’s name to a database URL.
Return type:dict
class spinetoolbox.project_items.tool.ToolIcon(toolbox, x, y, w, h, name)[source]

Bases: spinetoolbox.graphics_items.ProjectItemIcon

Tool icon for the Design View.

Parameters:
  • toolbox (ToolBoxUI) – QMainWindow instance
  • x (float) – Icon x coordinate
  • y (float) – Icon y coordinate
  • w (float) – Width of master icon
  • h (float) – Height of master icon
  • name (str) – Item name
static _value_for_time(msecs)
start_animation(self)

Start the animation that plays when the Tool associated to this GraphicsItem is running.

stop_animation(self)

Stop animation

class spinetoolbox.project_items.tool.ToolPropertiesWidget(toolbox)[source]

Bases: PySide2.QtWidgets.QWidget

Widget for the Tool Item Properties.

Parameters:toolbox (ToolboxUI) – The toolbox instance where this widget should be embeded

Init class.

connect_signals(self)

Connect signals to slots.

show_tool_properties_context_menu(self, pos)

Create and show a context-menu in Tool properties if selected Tool has a Tool specification.

Parameters:pos (QPoint) – Mouse position
class spinetoolbox.project_items.tool.AddToolWidget(toolbox, x, y)[source]

Bases: PySide2.QtWidgets.QWidget

A widget that queries user’s preferences for a new item.

toolbox

Parent widget

Type:ToolboxUI
x

X coordinate of new item

Type:int
y

Y coordinate of new item

Type:int

Initialize class.

connect_signals(self)

Connect signals to slots.

update_args(self, row)

Show Tool specification command line arguments in text input.

Parameters:row (int) – Selected row number
name_changed(self)

Update label to show upcoming folder name.

ok_clicked(self)

Check that given item name is valid and add it to project.

call_add_item(self)

Creates new Item according to user’s selections.

keyPressEvent(self, e)

Close Setup form when escape key is pressed.

Parameters:e (QKeyEvent) – Received key press event.
closeEvent(self, event=None)

Handle close window.

Parameters:event (QEvent) – Closing event if ‘X’ is clicked.
spinetoolbox.project_items.tool.item_rank = 2[source]
spinetoolbox.project_items.tool.item_category[source]
spinetoolbox.project_items.tool.item_type[source]
spinetoolbox.project_items.tool.item_icon = :/icons/project_item_icons/hammer.svg[source]
spinetoolbox.project_items.tool.icon_maker[source]
spinetoolbox.project_items.tool.properties_widget_maker[source]
spinetoolbox.project_items.tool.add_form_maker[source]