items.models#

Defines the base model used to display bookmark, asset and files items.

The model loads and reset data via the ItemModel.init_data() and ItemModel.reset_data() methods.

The model itself does not store data, but all retrieved data is cached independently to bookmarks.common.item_data. The interface for getting and setting data can be found in the bookmarks.common.data. However, the model is responsible for populating the data cache. See ItemModel.item_generator().

The model exposes different datasets to the view using the ItemModel.task() and ItemModel.data_type() switches. This is because file items are stored as sequence and individual items simultaneously and because the file model also keeps separate data for each task folder it encounters.

The currently exposed data can be retrieved by ItemModel.model_data(). To change/set the data set emit the ItemModel.taskFolderChanged and ItemModel.dataTypeChanged signals with their appropriate arguments.

Worth keeping in mind that Bookmarks loads data in two passes. The model is responsible for discovering items, but will not populate all item the data, and instead uses helper threads to offload work. The model’s associated threads are defined by overriding ItemModel.queues.

Each base model is nested inside a QSortFilterProxy used for filtering only. Sorting is implemented separately to run directly over the source data.

Classes:

FilterProxyModel([parent])

Proxy model responsible for data filtering.

ItemModel([parent])

The base model used for interacting with all bookmark, asset and file items.

Functions:

filter_includes_row(filter_text, searchable)

Checks if the filter string contains any double dashes (--) and if the filter text is found in the searchable string.

initdata(func)

The decorator is responsible validating the current active paths, and emitting the beginResetModel, endResetModel and ItemModel.coreDataLoaded signals.

Data:

DEFAULT_SORT_BY_NAME_ROLE

A default container used to sort items by name

class bookmarks.items.models.FilterProxyModel(parent=None)[source]#

Bases: QSortFilterProxyModel

Proxy model responsible for data filtering.

We filter items using item flags defined in bookmarks.common.core and their display and description roles. Sorting is not implemented by this model, and instead is we’re sorting the underlying data directly using common.data.sort_data()

filterFlagChanged#

Emitted when the user changes the current filter flags.

Type:

QtCore.Signal -> int, bool

filterTextChanged#

Emitted when the user changes the current filter text.

Type:

QtCore.Signal -> str

invalidated#

Emitted after the model has been reset or invalidated.

Type:

QtCore.Signal

Methods:

delayed_invalidate(*args, **kwargs)

Slot called by the queued invalidate timer's timeout signal.

filterAcceptsColumn(source_column[, parent])

Checks if the filter accepts the column.

filterAcceptsRow(idx[, parent])

Filters rows of the proxy model based on the current flags and filter string.

filter_flag(flag)

Returns the current flag-filter.

filter_text()

Filters the list of items containing this path segment.

init_filter_values(*args, **kwargs)

Load the saved widget filters from user_settings.

invalidate(*args, **kwargs)

Invalidates the filter.

invalidateFilter(*args, **kwargs)

Instead of calling invalidate directly, we'll pool consequent calls together.

reset(*args, **kwargs)

Resets and invalidates the proxy model.

save_history(v)

Saves the filter text history.

set_filter_flag(flag, v)

Save a filter value to user settings.

set_filter_text(v)

Slot called when a filter text has been set by the filter text editor widget.

sort(column[, order])

Disables sorting.

verify()

Verify the filter model contents to make sure archived items remain hidden when they're not meant to be visible.

delayed_invalidate(*args, **kwargs)[source]#

Slot called by the queued invalidate timer’s timeout signal.

filterAcceptsColumn(source_column, parent=QtCore.QModelIndex())[source]#

Checks if the filter accepts the column.

filterAcceptsRow(idx, parent=None)[source]#

Filters rows of the proxy model based on the current flags and filter string.

filter_flag(flag)[source]#

Returns the current flag-filter.

filter_text()[source]#

Filters the list of items containing this path segment.

init_filter_values(*args, **kwargs)[source]#

Load the saved widget filters from user_settings.

This determines if e.g. archived items are visible in the view.

invalidate(*args, **kwargs)[source]#

Invalidates the filter.

invalidateFilter(*args, **kwargs)[source]#

Instead of calling invalidate directly, we’ll pool consequent calls together.

reset(*args, **kwargs)[source]#

Resets and invalidates the proxy model.

save_history(v)[source]#

Saves the filter text history.

set_filter_flag(flag, v)[source]#

Save a filter value to user settings.

Parameters:
  • flag (int) – The flag to set.

  • v (bool) – The value to set.

set_filter_text(v)[source]#

Slot called when a filter text has been set by the filter text editor widget.

sort(column, order=QtCore.Qt.AscendingOrder)[source]#

Disables sorting.

verify()[source]#

Verify the filter model contents to make sure archived items remain hidden when they’re not meant to be visible.

class bookmarks.items.models.ItemModel(parent=None)[source]#

Bases: QAbstractTableModel

The base model used for interacting with all bookmark, asset and file items.

Data is stored in the datacache module that can be fetched using the model’s source_path, task and data_type.

coreDataLoaded#

Signals that the bare model data finished loading and that threads can start loading missing data.

Type:

QtCore.Signal -> weakref.ref, weakref.ref

coreDataReset#

Signals that the underlying model data has been reset. Used by the thread workers to empty their queues.

Type:

QtCore.Signal

dataTypeSorted#

Signals that the underlying model data was sorted.

Type:

QtCore.Signal -> int

sortingChanged#

Emitted when the sorting order or sorting role was changed by the user.

Type:

QtCore.Signal -> int, bool

activeChanged#

Signals ItemModel.active_index() change.

Type:

QtCore.Signal

dataTypeChanged#

Emitted when the exposed data type changes, e.g. from FileItem to SequenceItem.

Type:

QtCore.Signal -> int

updateIndex#

Emitted when an index repaint is requested.

Type:

QtCore.Signal -> QtCore.QModelIndex

queues#

A list of threads associated with the model.

Type:

tuple

Methods:

active_index()

The model's active_index.

canDropMimeData(mime, action, row, column[, ...])

Checks drop support for the given mime data.

columnCount([parent])

Number of columns the model has.

data(index[, role])

Returns and item data associated with the given index.

data_type()

Current key to the data dictionary.

default_row_size()

Returns the default item size.

dropMimeData(mime, action, row, column, parent)

Handles drop actions.

emit_reset_model(data_type)

Slot used to emit the reset model signals.

filter_setting_dict_key()

The custom dictionary key used to save filter settings to the user settings file.

flags(index)

Returns the item's flags.

get_filter_setting(key)

Get a filter value stored in the user settings file.

headerData(self, section, orientation[, role])

init_data()

The main method used by the model to fetch and store item information from the file system.

init_row_size(*args, **kwargs)

Load the current row size from the user settings file.

init_sort_values(*args, **kwargs)

Load the current sort role from the local preferences.

is_data_type_loaded()

Checks whether the current data type is fully loaded.

item_generator()

A generator method used by init_data() to yield the items the model should load.

mimeData(indexes)

Returns the drag mime data for the given indexes.

model_data()

The pointer to the model's internal data.

parent(child)

The parent of an item.

reset_data(*args[, force, emit_active])

Resets the model's internal data.

rowCount([parent])

The model's row count.

save_active()

Saves the model's active item to the user preferences.

setData(index, v[, role])

set_active(index)

Set the given index as the model's active_index().

set_filter_setting(key, v)

Set a filter value in the user settings file.

set_interrupt_requested()

Load interrupt requested by user.

set_sort_by(val)

Sets and saves the sort by value.

set_sort_order(val)

Sets and saves the sort order.

set_sorting(role, order)

Slot responsible for setting the sort role, order and sorting the model data.

sort_by()

Current sort role.

sort_data(**kwargs)

Function wrapper.

sort_order()

The currently set order of the items e.g.

source_path()

Source path of the model data as a tuple of path segments.

supportedDragActions(self)

supportedDropActions(self)

task()

The model's associated task.

unset_active()

Remove the model's active_index().

active_index()[source]#

The model’s active_index.

canDropMimeData(mime, action, row, column, parent=QtCore.QModelIndex())[source]#

Checks drop support for the given mime data.

columnCount(parent=QtCore.QModelIndex())[source]#

Number of columns the model has.

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

Returns and item data associated with the given index.

data_type()[source]#

Current key to the data dictionary.

default_row_size()[source]#

Returns the default item size.

dropMimeData(mime, action, row, column, parent)[source]#

Handles drop actions.

emit_reset_model(data_type)[source]#

Slot used to emit the reset model signals.

filter_setting_dict_key()[source]#

The custom dictionary key used to save filter settings to the user settings file.

See get_filter_setting() and set_filter_setting().

Returns:

The dictionary key.

Return type:

str

flags(index)[source]#

Returns the item’s flags.

get_filter_setting(key)[source]#

Get a filter value stored in the user settings file.

Each filter setting is associated with filter_setting_dict_key() and stored in a dictionary object inside the user settings file.

Parameters:

key (str) – Settings key type.

Returns:

The value saved in user settings, or None if not found.

headerData(self, section: int, orientation: PySide2.QtCore.Qt.Orientation, role: int = PySide2.QtCore.Qt.ItemDataRole.DisplayRole) Any[source]#
init_data()[source]#

The main method used by the model to fetch and store item information from the file system.

The model itself does not store any data, instead, we’re using the bookmarks.common.data module to store item data.

The individual items are returned by item_generator().

init_row_size(*args, **kwargs)[source]#

Load the current row size from the user settings file.

init_sort_values(*args, **kwargs)[source]#

Load the current sort role from the local preferences.

is_data_type_loaded()[source]#

Checks whether the current data type is fully loaded.

item_generator()[source]#

A generator method used by init_data() to yield the items the model should load.

Yields:

DirEntry – os.scandir DirEntry objects.

mimeData(indexes)[source]#

Returns the drag mime data for the given indexes.

model_data()[source]#

The pointer to the model’s internal data.

parent(child)[source]#

The parent of an item.

reset_data(*args, force=False, emit_active=True)[source]#

Resets the model’s internal data.

The underlying data is cached in the datacache module, so here we’ll make sure the data is available for the model to use. When the optional force flag is set, we’ll use init_data to load the item data from disk.

Otherwise, the method will check if our cached data is available and if not, uses init_data to fetch it.

rowCount(parent=QtCore.QModelIndex())[source]#

The model’s row count.

save_active()[source]#

Saves the model’s active item to the user preferences.

setData(index, v, role=QtCore.Qt.DisplayRole)[source]#
set_active(index)[source]#

Set the given index as the model’s active_index().

set_filter_setting(key, v)[source]#

Set a filter value in the user settings file.

Parameters:
  • key (str) – A filter key.

  • v (object) – A filter value to store.

set_interrupt_requested()[source]#

Load interrupt requested by user.

set_sort_by(val)[source]#

Sets and saves the sort by value.

set_sort_order(val)[source]#

Sets and saves the sort order.

Parameters:

val (int) – The new sort order.

set_sorting(role, order)[source]#

Slot responsible for setting the sort role, order and sorting the model data. Sorting is only possible when the model data is fully loaded.

sort_by()[source]#

Current sort role.

sort_data(**kwargs)#

Function wrapper.

sort_order()[source]#

The currently set order of the items e.g. ‘descending’.

source_path()[source]#

Source path of the model data as a tuple of path segments.

Returns:

A tuple of path segments.

Return type:

tuple

supportedDragActions(self) PySide2.QtCore.Qt.DropActions[source]#
supportedDropActions(self) PySide2.QtCore.Qt.DropActions[source]#
task()[source]#

The model’s associated task.

unset_active()[source]#

Remove the model’s active_index().

bookmarks.items.models.filter_includes_row(filter_text, searchable)[source]#

Checks if the filter string contains any double dashes (–) and if the filter text is found in the searchable string.

If both true, the row will be hidden.

bookmarks.items.models.initdata(func)[source]#

The decorator is responsible validating the current active paths, and emitting the beginResetModel, endResetModel and ItemModel.coreDataLoaded signals.

bookmarks.items.models.DEFAULT_SORT_BY_NAME_ROLE = ['', '', '', '', '', '', '', '']#

A default container used to sort items by name