spinetoolbox.project_item.project_item

Contains base classes for project items and item factories.

authors
  1. Savolainen (VTT)

date

4.10.2018

Module Contents

Classes

ProjectItem

Class for project items that are not category nor root.

class spinetoolbox.project_item.project_item.ProjectItem(name, description, x, y, project)[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

create_data_dir(self)[source]
abstract static item_type()[source]

Item’s type identifier string.

Returns

type string

Return type

str

abstract static item_category()[source]

Item’s category.

Returns

category name

Return type

str

property logger(self)[source]
property log_document(self)[source]
property filter_log_documents(self)[source]
property filter_consoles(self)[source]
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]

Sets the properties tab widget for the item.

Note that this method expects the widget that is generated from the .ui files and initialized with the setupUi() method rather than the entire properties tab widget.

Parameters

properties_ui (QWidget) – item’s properties UI

specification(self)[source]

Returns the specification for this item.

set_specification(self, specification)[source]

Pushes a new SetItemSpecificationCommand to the toolbox’ undo stack.

do_set_specification(self, specification)[source]

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

Parameters

specification (ProjectItemSpecification) – specification of this item. None removes the specification.

undo_set_specification(self)[source]
set_icon(self, icon)[source]

Sets the icon for the item.

Parameters

icon (ProjectItemIcon) – item’s icon

get_icon(self)[source]

Returns the graphics item representing this item in the scene.

_check_notifications(self)[source]

Checks if exclamation icon notifications need to be set or cleared.

clear_notifications(self)[source]

Clear all notifications from the exclamation icon.

add_notification(self, text)[source]

Add a notification to the exclamation icon.

remove_notification(self, text)[source]
set_rank(self, rank)[source]

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

property executable_class(self)[source]
handle_execution_successful(self, execution_direction, engine_state)[source]

Performs item dependent actions after the execution item has finished successfully.

Parameters
  • execution_direction (str) – “FORWARD” or “BACKWARD”

  • engine_state – engine state after item’s execution

resources_for_direct_successors(self)[source]

Returns resources for direct successors.

These resources can include transient files that don’t exist yet, or filename patterns. The default implementation returns an empty list.

Returns

a list of ProjectItemResources

Return type

list

resources_for_direct_predecessors(self)[source]

Returns resources for direct predecessors.

These resources can include transient files that don’t exist yet, or filename patterns. The default implementation returns an empty list.

Returns

a list of ProjectItemResources

Return type

list

_resources_to_predecessors_changed(self)[source]

Notifies direct predecessors that item’s resources have changed.

_resource_to_predecessors_replaced(self, old, new)[source]

Notifies direct predecessors that one of item’s resources has been replaced.

Parameters
  • old (ProjectItemResource) – old resource

  • new (ProjectItemResource) – new resource

upstream_resources_updated(self, resources)[source]

Notifies item that resources from direct predecessors have changed.

Parameters

resources (list of ProjectItemResource) – new resources from upstream

replace_resource_from_upstream(self, old, new)[source]

Replaces an existing resource from direct predecessor by a new one.

Parameters
  • old (ProjectItemResource) – old resource

  • new (ProjectItemResource) – new resource

_resources_to_successors_changed(self)[source]

Notifies direct successors that item’s resources have changed.

_resource_to_successors_replaced(self, old, new)[source]

Notifies direct successors that one of item’s resources has been replaced.

Parameters
  • old (ProjectItemResource) – old resource

  • new (ProjectItemResource) – new resource

downstream_resources_updated(self, resources)[source]

Notifies item that resources from direct successors have changed.

Parameters

resources (list of ProjectItemResource) – new resources from downstream

replace_resource_from_downstream(self, old, new)[source]

Replaces an existing resource from direct successor by a new one.

Parameters
  • old (ProjectItemResource) – old resource

  • new (ProjectItemResource) – new resource

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.

revalidate_workflow(self)[source]
item_dict(self)[source]

Returns a dictionary corresponding to this item.

static parse_item_dict(item_dict)[source]

Reads the information needed to construct the base ProjectItem class from an item dict.

Parameters

item_dict (dict) – an item dict

Returns

item’s name, description as well as x and y coordinates

Return type

tuple

copy_local_data(self, original_data_dir, original_url, duplicate_items)[source]

Copies local data linked to a duplicated project item.

Parameters
  • original_data_dir (str) – original dir of duplicated ProjectItem

  • original_url (dict) – original url of the duplicated ProjectItem

  • duplicate_items (bool) – Flag indicating if linked files should be copied

abstract static from_dict(name, item_dict, toolbox, project)[source]

Deserialized an item from item dict.

Parameters
  • name (str) – item’s name

  • item_dict (dict) – serialized item

  • toolbox (ToolboxUI) – the main window

  • project (SpineToolboxProject) – a project

Returns

deserialized item

Return type

ProjectItem

actions(self)[source]

Item specific actions.

Returns

item’s actions

Return type

list of QAction

rename(self, new_name, rename_data_dir_message)[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

  • rename_data_dir_message (str) – Message to show when renaming item’s data directory

Returns

True if item was renamed successfully, False otherwise

Return type

bool

open_directory(self, checked=False)[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.

abstract 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

_create_filter_log_document(self, filter_id)[source]

Creates log document for a filter execution if none yet, and returns it

Parameters

filter_id (str) – filter identifier

Returns

SignedTextDocument

_create_log_document(self)[source]

Creates log document if none yet, and returns it

Parameters

filter_id (str) – filter identifier

Returns

SignedTextDocument

add_log_message(self, filter_id, message)[source]

Adds a message to the log document.

Parameters
  • filter_id (str) – filter identifier

  • message (str) – formatted message

add_event_message(self, filter_id, msg_type, msg_text)[source]

Adds a message to the log document.

Parameters
  • filter_id (str) – filter identifier

  • msg_type (str) – message type

  • msg_text (str) – message text

add_process_message(self, filter_id, msg_type, msg_text)[source]

Adds a message to the log document.

Parameters
  • filter_id (str) – filter identifier

  • msg_type (str) – message type

  • msg_text (str) – message text

static upgrade_v1_to_v2(item_name, item_dict)[source]

Upgrades item’s dictionary from v1 to v2.

Subclasses should reimplement this method if there are changes between version 1 and version 2.

Parameters
  • item_name (str) – item’s name

  • item_dict (dict) – Version 1 item dictionary

Returns

Version 2 item dictionary

Return type

dict

static upgrade_v2_to_v3(item_name, item_dict, project_upgrader)[source]

Upgrades item’s dictionary from v2 to v3.

Subclasses should reimplement this method if there are changes between version 2 and version 3.

Parameters
  • item_name (str) – item’s name

  • item_dict (dict) – Version 2 item dictionary

  • project_upgrader (ProjectUpgrader) – Project upgrader class instance

Returns

Version 3 item dictionary

Return type

dict