spinetoolbox.project_items.shared.models

Contains a generic File list model and an Item for that model. Used by the Importer project item but this may be handy for other project items as well.

authors:
  1. Savolainen (VTT), P. Vennström (VTT), A. Soininen (VTT)
date:

5.6.2020

Module Contents

Classes

FileListItem An item for FileListModel.
FileListModel A model for files to be shown in a file list view.

Functions

_file_label(resource) Picks a label for given file resource.
spinetoolbox.project_items.shared.models._file_label(resource)[source]

Picks a label for given file resource.

class spinetoolbox.project_items.shared.models.FileListItem(label, path, provider_name, is_pattern=False)[source]

An item for FileListModel.

Parameters:
  • label (str) – File label; a full path for ‘permanent’ files or just the basename for ‘transient’ files like Tool’s output.
  • path (str) – Absolute path to the file, empty if not known
  • provider_name (str) – Name of the project item providing the file
  • is_pattern (bool) – True if the file is actually a file name pattern

Initialize self. See help(type(self)) for accurate signature.

classmethod from_resource(cls, resource)[source]

Constructs a FileListItem from ProjectItemResource.

Parameters:resource (ProjectItemResource) – Resource
Returns:An item based on given resource
Return type:FileListItem
Raises:RuntimeError – If given resource has an unknown type
exists(self)[source]

Returns True if the file exists, False otherwise.

update(self, resource)[source]

Updates item information.

Parameters:resource (ProjectItemResource) – A fresh file resource
class spinetoolbox.project_items.shared.models.FileListModel[source]

Bases: PySide2.QtCore.QAbstractListModel

A model for files to be shown in a file list view. Used by Importer.

selected_state_changed[source]

Emitted when a file check box state changes.

files[source]

All model’s file items.

data(self, index, role=Qt.DisplayRole)[source]

Returns data associated with given role at given index.

flags(self, index)[source]

Returns item’s flags.

headerData(self, section, orientation, role=Qt.DisplayRole)[source]

Returns header information.

find_file(self, label)[source]

Returns a file item with given label.

labels(self)[source]

Returns a list of file labels.

mark_as_nonexistent(self, index)[source]

Marks item at given index as non-existing.

update(self, resources)[source]

Updates the model according to given list of resources.

rowCount(self, parent=QModelIndex())[source]

Returns the number of rows in the model.

set_selected(self, label, selected)[source]

Changes the given item’s selection status.

Parameters:
  • label (str) – item’s label
  • selected (bool) – True to select the item, False to deselect
setData(self, index, value, role=Qt.EditRole)[source]

Sets data in the model.

set_initial_state(self, selected_items)[source]

Fills model with incomplete data; needs a call to update() to make the model usable.