spinetoolbox.fetch_parent

The FetchParent and FlexibleFetchParent classes.

Module Contents

Classes

FetchParent

param index

an index to speedup looking up fetched items

ItemTypeFetchParent

param index

an index to speedup looking up fetched items

FlexibleFetchParent

param index

an index to speedup looking up fetched items

FetchIndex

dict() -> new empty dictionary

_ItemCallback

class spinetoolbox.fetch_parent.FetchParent(index=None, owner=None, chunk_size=1000)[source]

Bases: PySide6.QtCore.QObject

Parameters
  • index (FetchIndex, optional) – an index to speedup looking up fetched items

  • owner (object, optional) – somebody who owns this FetchParent. If it’s a QObject instance, then this FetchParent becomes obsolete whenever the owner is destroyed

  • chunk_size (int, optional) – the number of items this parent should be happy with fetching at a time. If None, then no limit is imposed and the parent should fetch the entire contents of the DB.

property index[source]
abstract property fetch_item_type[source]

Returns the DB item type to fetch, e.g., “entity_class”.

Returns

str

property is_obsolete[source]
property is_fetched[source]
property is_busy[source]
_changes_pending[source]
apply_changes_immediately()[source]
reset()[source]

Resets fetch parent as if nothing was ever fetched.

position(db_map)[source]
increment_position(db_map)[source]
_apply_pending_changes()[source]
bind_item(item, db_map)[source]
_make_restore_item_callback(db_map)[source]
_make_update_item_callback(db_map)[source]
_make_remove_item_callback(db_map)[source]
_is_valid(version)[source]
_change_item(handler, item, db_map, version)[source]
add_item(item, db_map, version=None)[source]
update_item(item, db_map, version=None)[source]
remove_item(item, db_map, version=None)[source]
key_for_index(db_map)[source]

Returns the key for this parent in the index.

Parameters

db_map (DatabaseMapping) –

Returns

Any

accepts_item(item, db_map)[source]

Called by the associated SpineDBWorker whenever items are fetched and also added/updated/removed. Returns whether this parent accepts that item as a children.

In case of modifications, the SpineDBWorker will call one or more of handle_items_added(), handle_items_updated(), or handle_items_removed() with all the items that pass this test.

Parameters
  • item (dict) – The item

  • db_map (DatabaseMapping) –

Returns

bool

shows_item(item, db_map)[source]

Called by the associated SpineDBWorker whenever items are fetched and accepted. Returns whether this parent will show this item to the user.

Parameters
  • item (dict) – The item

  • db_map (DatabaseMapping) –

Returns

bool

set_obsolete(obsolete)[source]

Sets the obsolete status.

Parameters

obsolete (bool) – whether parent has become obsolete

set_fetched(fetched)[source]

Sets the fetched status.

Parameters

fetched (bool) – whether parent has been fetched completely

set_busy(busy)[source]

Sets the busy status.

Parameters

busy (bool) – whether parent is busy fetching

abstract handle_items_added(db_map_data)[source]

Called by SpineDBWorker when items are added to the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

abstract handle_items_removed(db_map_data)[source]

Called by SpineDBWorker when items are removed from the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

abstract handle_items_updated(db_map_data)[source]

Called by SpineDBWorker when items are updated in the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

class spinetoolbox.fetch_parent.ItemTypeFetchParent(fetch_item_type, index=None, owner=None, chunk_size=1000)[source]

Bases: FetchParent

Parameters
  • index (FetchIndex, optional) – an index to speedup looking up fetched items

  • owner (object, optional) – somebody who owns this FetchParent. If it’s a QObject instance, then this FetchParent becomes obsolete whenever the owner is destroyed

  • chunk_size (int, optional) – the number of items this parent should be happy with fetching at a time. If None, then no limit is imposed and the parent should fetch the entire contents of the DB.

property fetch_item_type[source]

Returns the DB item type to fetch, e.g., “entity_class”.

Returns

str

abstract handle_items_added(db_map_data)[source]

Called by SpineDBWorker when items are added to the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

abstract handle_items_removed(db_map_data)[source]

Called by SpineDBWorker when items are removed from the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

abstract handle_items_updated(db_map_data)[source]

Called by SpineDBWorker when items are updated in the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

__str__()[source]
class spinetoolbox.fetch_parent.FlexibleFetchParent(fetch_item_type, handle_items_added=None, handle_items_removed=None, handle_items_updated=None, accepts_item=None, shows_item=None, key_for_index=None, index=None, owner=None, chunk_size=1000)[source]

Bases: ItemTypeFetchParent

Parameters
  • index (FetchIndex, optional) – an index to speedup looking up fetched items

  • owner (object, optional) – somebody who owns this FetchParent. If it’s a QObject instance, then this FetchParent becomes obsolete whenever the owner is destroyed

  • chunk_size (int, optional) – the number of items this parent should be happy with fetching at a time. If None, then no limit is imposed and the parent should fetch the entire contents of the DB.

key_for_index(db_map)[source]

Returns the key for this parent in the index.

Parameters

db_map (DatabaseMapping) –

Returns

Any

handle_items_added(db_map_data)[source]

Called by SpineDBWorker when items are added to the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

handle_items_removed(db_map_data)[source]

Called by SpineDBWorker when items are removed from the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

handle_items_updated(db_map_data)[source]

Called by SpineDBWorker when items are updated in the DB.

Parameters

db_map_data (dict) – Mapping DatabaseMapping instances to list of dict-items for which accepts_item() returns True.

accepts_item(item, db_map)[source]

Called by the associated SpineDBWorker whenever items are fetched and also added/updated/removed. Returns whether this parent accepts that item as a children.

In case of modifications, the SpineDBWorker will call one or more of handle_items_added(), handle_items_updated(), or handle_items_removed() with all the items that pass this test.

Parameters
  • item (dict) – The item

  • db_map (DatabaseMapping) –

Returns

bool

shows_item(item, db_map)[source]

Called by the associated SpineDBWorker whenever items are fetched and accepted. Returns whether this parent will show this item to the user.

Parameters
  • item (dict) – The item

  • db_map (DatabaseMapping) –

Returns

bool

class spinetoolbox.fetch_parent.FetchIndex[source]

Bases: dict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

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

reset()[source]
abstract process_item(item, db_map)[source]
position(db_map)[source]
increment_position(db_map)[source]
get_items(key, db_map)[source]
class spinetoolbox.fetch_parent._ItemCallback(fn, *args)[source]
__call__(item)[source]
__str__()[source]

Return str(self).