spinetoolbox.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.
ProjectItemFactory Class for project item factories.
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]

Request DAG update. Emitted when a change affects other items in the DAG.

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

Item’s type identifier string.

static item_category()[source]

Item’s category.

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 SetToolSpecificationCommand to the toolbox’ undo stack.

do_set_specification(self, specification)[source]

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

Parameters:specification (ToolSpecification) – Tool specification of this Tool. 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.

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.

execution_item(self)[source]

Creates project item’s execution counterpart.

handle_execution_successful(self, execution_direction, engine_state)[source]

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

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
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
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
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 (dict) – 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

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

class spinetoolbox.project_item.ProjectItemFactory(toolbox)[source]

Class for project item factories.

Parameters:toolbox (ToolboxUI) –
item_maker[source]

Returns a ProjectItem subclass.

Returns:class
icon_maker[source]

Returns a ProjectItemIcon subclass.

Returns:class
add_form_maker[source]

Returns an AddProjectItem subclass.

Returns:class
specification_form_maker[source]

Returns a QWidget subclass to create and edit specifications.

Returns:class
specification_menu_maker[source]

Returns an ItemSpecificationMenu subclass.

Returns:class
static icon()[source]

Returns the icon resource path.

Returns:str
static supports_specifications()[source]

Returns whether or not this factory supports specs.

If the subclass implementation returns True, then it must also implement specification_form_maker, and specification_menu_maker.

Returns:bool
make_icon(self, toolbox, x, y, project_item)[source]

Returns a ProjectItemIcon to use with given toolbox, for given project item.

Parameters:
  • toolbox (ToolboxUI) –
  • x (int) – Icon X coordinate
  • y (int) – Icon Y coordinate
  • project_item (ProjectItem) – Project item
Returns:

ProjectItemIcon

make_item(self, *args, **kwargs)[source]

Returns a project item while setting its factory attribute.

Returns:ProjectItem
activate_project_item(self, toolbox, project_item)[source]

Activates the given project item so it works with the given toolbox. This is mainly intended to facilitate adding items back with redo.

Parameters:
static _make_properties_widget(toolbox)[source]

Creates the item’s properties tab widget.

Returns:QWidget