spinetoolbox.project_item.project_item
Contains base classes for project items and item factories.
Module Contents
Classes
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.log_mixin.LogMixin
,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
- abstract static item_type()[source]
Item’s type identifier string.
- Returns:
type string
- Return type:
str
- make_signal_handler_dict()[source]
Returns a dictionary of all shared signals and their handlers. This is to enable simpler connecting and disconnecting. Must be implemented in subclasses.
- restore_selections()[source]
Restore selections into shared widgets when this project item is selected.
- save_selections()[source]
Save selections in shared widgets for this project item into instance variables.
- set_properties_ui(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
- set_specification(specification)[source]
Pushes a new SetItemSpecificationCommand to the toolbox’ undo stack.
- do_set_specification(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.
- set_icon(icon)[source]
Sets the icon for the item.
- Parameters:
icon (ProjectItemIcon) – item’s icon
- handle_execution_successful(execution_direction, engine_state)[source]
Performs item dependent actions after the execution item has finished successfully.
- Parameters:
execution_direction (ExecutionDirection) – ExecutionDirection.FORWARD or ExecutionDirection.BACKWARD
engine_state – engine state after item’s execution
- resources_for_direct_successors()[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()[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()[source]
Notifies direct predecessors that item’s resources have changed.
- _resources_to_predecessors_replaced(old, new)[source]
Notifies direct predecessors that item’s resources have been replaced.
- Parameters:
old (list of ProjectItemResource) – old resources
new (list of ProjectItemResource) – new resources
- upstream_resources_updated(resources)[source]
Notifies item that resources from direct predecessors have changed.
- Parameters:
resources (list of ProjectItemResource) – new resources from upstream
- replace_resources_from_upstream(old, new)[source]
Replaces existing resources from direct predecessor by a new ones.
- Parameters:
old (list of ProjectItemResource) – old resources
new (list of ProjectItemResource) – new resources
- _resources_to_successors_changed()[source]
Notifies direct successors that item’s resources have changed.
- _resources_to_successors_replaced(old, new)[source]
Notifies direct successors that one of item’s resources has been replaced.
- Parameters:
old (list of ProjectItemResource) – old resources
new (list of ProjectItemResource) – new resources
- downstream_resources_updated(resources)[source]
Notifies item that resources from direct successors have changed.
- Parameters:
resources (list of ProjectItemResource) – new resources from downstream
- replace_resources_from_downstream(old, new)[source]
Replaces existing resources from direct successor by a new ones.
- Parameters:
old (list of ProjectItemResource) – old resources
new (list of ProjectItemResource) – new resources
- item_dict()[source]
Returns a dictionary corresponding to this item.
- Returns:
serialized project item
- Return type:
dict
- static item_dict_local_entries()[source]
Returns entries or ‘paths’ in item dict that should be stored in project’s local data directory.
- Returns:
local data item dict entries
- Return type:
list of tuple of str
- 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(item_dict)[source]
Copies local data linked to a duplicated project item.
- Parameters:
item_dict (dict) – serialized item
- 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:
- rename(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
- tear_down()[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()[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()[source]
Updates the name label on the properties widget, used when selecting an item and renaming the selected one.
- notify_destination(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
- 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