spinetoolbox.project_item

ProjectItem and ProjectItemResource classes.

authors:
  1. Savolainen (VTT)
date:

4.10.2018

Module Contents

class spinetoolbox.project_item.ProjectItem(name, description, x, y, project, logger)[source]

Bases: spinetoolbox.metaobject.MetaObject

Class for project items that are not category nor root. These items can be executed, refreshed, and so on.

x

horizontal position in the screen

Type:float
y

vertical position in the screen

Type:float
Parameters:
  • name (str) – item name
  • description (str) – item description
  • x (float) – horizontal position on the scene
  • y (float) – vertical position on the scene
  • project (SpineToolboxProject) – project item’s project
  • logger (LoggerInterface) – a logger instance
item_changed[source]
create_data_dir(self)[source]
static item_type()[source]

Item’s type identifier string.

static category()[source]

Item’s category identifier string.

make_signal_handler_dict(self)[source]

Returns a dictionary of all shared signals and their handlers. This is to enable simpler connecting and disconnecting. Must be implemented in subclasses.

activate(self)[source]

Restore selections and connect signals.

deactivate(self)[source]

Save selections and disconnect signals.

restore_selections(self)[source]

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

save_selections(self)[source]

Save selections in shared widgets for this project item into instance variables.

_connect_signals(self)[source]

Connect signals to handlers.

_disconnect_signals(self)[source]

Disconnect signals from handlers and check for errors.

set_properties_ui(self, properties_ui)[source]
set_icon(self, icon)[source]
get_icon(self)[source]

Returns the graphics item representing this item in the scene.

clear_notifications(self)[source]

Clear all notifications from the exclamation icon.

add_notification(self, text)[source]

Add a notification to the exclamation icon.

set_rank(self, rank)[source]

Set rank of this item for displaying in the design view.

stop_execution(self)[source]

Stops executing this View.

execute(self, resources, direction)[source]

Executes this item in the given direction using the given resources and returns a boolean indicating the outcome.

Subclasses need to implement execute_forward and execute_backward to do the appropriate work in each direction.

Parameters:
  • resources (list) – a list of ProjectItemResources available for execution
  • direction (str) – either “forward” or “backward”
Returns:

True if execution succeeded, False otherwise

Return type:

bool

run_leave_animation(self)[source]

Runs the animation that represents execution leaving this item. Blocks until the animation is finished.

execute_forward(self, resources)[source]

Executes this item in the forward direction.

The default implementation just returns True.

Parameters:resources (list) – a list of ProjectItemResources available for execution
Returns:True if execution succeeded, False otherwise
Return type:bool
execute_backward(self, resources)[source]

Executes this item in the backward direction.

The default implementation just returns True.

Parameters:resources (list) – a list of ProjectItemResources available for execution
Returns:True if execution succeeded, False otherwise
Return type:bool
output_resources(self, direction)[source]

Returns output resources for execution in the given direction.

Subclasses need to implement output_resources_backward and/or output_resources_forward if they want to provide resources in any direction.

Parameters:direction (str) – Direction where output resources are passed
Returns:a list of ProjectItemResources
output_resources_forward(self)[source]

Returns output resources for forward execution.

The default implementation returns an empty list.

Returns:a list of ProjectItemResources
output_resources_backward(self)[source]

Returns output resources for backward execution.

The default implementation returns an empty list.

Returns:a list of ProjectItemResources
handle_dag_changed(self, rank, resources)[source]

Handles changes in the DAG.

Subclasses should reimplement the _do_handle_dag_changed() method.

Parameters:
  • rank (int) – item’s execution order
  • resources (list) – resources available from input items
_do_handle_dag_changed(self, resources)[source]

Handles changes in the DAG.

Usually this entails validating the input resources and populating file references etc. The default implementation does nothing.

Parameters:resources (list) – resources available from input items
make_execution_leave_animation(self)[source]

Returns animation to play when execution leaves this item.

Returns:QParallelAnimationGroup
invalidate_workflow(self, edges)[source]

Notifies that this item’s workflow is not acyclic.

Parameters:edges (list) – A list of edges that make the graph acyclic after removing them.
item_dict(self)[source]

Returns a dictionary corresponding to this item.

static default_name_prefix()[source]

prefix for default item name

rename(self, new_name)[source]

Renames this item.

If the project item needs any additional steps in renaming, override this method in subclass. See e.g. rename() method in DataStore class.

Parameters:new_name (str) – New name
Returns:True if renaming succeeded, False otherwise
Return type:bool
open_directory(self)[source]

Open this item’s data directory in file explorer.

tear_down(self)[source]

Tears down this item. Called both before closing the app and when removing the item from the project. Implement in subclasses to eg close all QMainWindows opened by this item.

set_up(self)[source]

Sets up this item. Called when adding the item to the project. Implement in subclasses to eg recreate attributes destroyed by tear_down.

update_name_label(self)[source]

Updates the name label on the properties widget when renaming an item.

Must be reimplemented by subclasses.

notify_destination(self, source_item)[source]

Informs an item that it has become the destination of a connection between two items.

The default implementation logs a warning message. Subclasses should reimplement this if they need more specific behavior.

Parameters:source_item (ProjectItem) – connection source item
available_resources_downstream(self, upstream_resources)[source]

Returns resources available to downstream items.

Should be reimplemented by subclasses if they want to offer resources to downstream items. The default implementation returns an empty list.

Parameters:upstream_resources (list) – a list of resources available from upstream items
Returns:a list of ProjectItemResources
available_resources_upstream(self)[source]

Returns resources available to upstream items.

Should be reimplemented by subclasses if they want to offer resources to upstream items. The default implementation returns an empty list.

Returns:a list of ProjectItemResources
static upgrade_from_no_version_to_version_1(item_name, old_item_dict, old_project_dir)[source]

Upgrades item’s dictionary from no version to version 1.

Subclasses should reimplement this method if their JSON format changed between no version and version 1 .proj files.

Parameters:
  • item_name (str) – item’s name
  • old_item_dict (str) – no version item dictionary
  • old_project_dir (str) – path to the previous project dir. We use old project directory here since the new project directory may be empty at this point and the directories for the new project items have not been created yet.
Returns:

version 1 item dictionary

class spinetoolbox.project_item.ProjectItemResource(provider, type_, url='', metadata=None)[source]

Class to hold a resource made available by a project item and that may be consumed by another project item.

Init class.

Parameters:
  • provider (ProjectItem) – The item that provides the resource
  • type (str) – The resource type, either “file” or “database” (for now)
  • url (str) – The url of the resource
  • metadata (dict) – Some metadata providing extra information about the resource. For now it has one key: - future (bool): whether the resource is from the future, e.g. Tool output files advertised beforehand
path[source]

Returns the resource path in the local syntax, as obtained from parsing the url.

scheme[source]

Returns the resource scheme, as obtained from parsing the url.

__eq__(self, other)[source]
__repr__(self)[source]