RQList

class pyreaqtive.models.rqlist.RQList(initial_items=None)

Bases: pyreaqtive.models.rqmodel.RQModel

Reactive List Model.

Represents a list of model instances

This model is quite different from the others and doesn’t use data_changed signal. Instead it uses insert and remove signals that indicate the index of the list where this event is happening. This can greatly improve the efficiency of widgets that use this model.

Parameters

initial_items (List[Any]) –

rq_list_insert

List insert signal.

Indicates that there’s been an insertion to the position indicated by the int

rq_list_remove

List remove signal.

Indicates that there’s been an deletion in the position indicated by the int

__init__(initial_items=None)

Constructor.

Parameters

initial_items (Optional[List[Any]]) – List of items

_list: List[Any]

Model store variable

Stores list of instances

_reactive_indexes: Dict[object, pyreaqtive.models.rqint.RQInt]

Weak reference dictionary of reactive indexes requested and that have to be updated when list changes

Key is model Value is reactive index

set(value)

Method to set the value of the underlying object.

Must be overridden by model

Parameters

value (List[Any]) – New value of the model

Return type

None

get()

Get value of the model.

Returns

value of the model

Return type

list

insert(index, item)

Insert a item to the specified index on the list.

Parameters
  • index (int) – positional index on the list

  • item (Any) – item to be inserted

Return type

None

append(item)

Append an item to the end of the list.

Parameters

item (Any) – Item to be appended

Return type

None

__delitem__(key)

Delete the item in the list in the specified index.

Parameters

key (Union[int, slice]) – positional index on the list or slice

Return type

None

pop()

Delete last instance of the list.

Return type

None

remove(item)

Remove first occurrence of value.

Parameters

item (Any) – item

Return type

None

remove_all(item)

Remove all instances in the list.

Parameters

item (Any) – item

Return type

None

clear()

Clear all items of the list.

Return type

None

__getitem__(index)

Returns the indicated item of the list.

Parameters

index (int) – element of the list

Returns

item in the list indicated by index

Return type

Any

index(item)

Returns the index where a item is located.

Raises an ValueError if is not in the list

Parameters

item (Any) – instance that should be in the list

Returns

index of the item in the list

Return type

int

update_reactive_indexes()
Return type

None

reactive_index(model)

Returns a reactive index model that indicates where the item is located.

Parameters

model (object) – instance that should be in the list

Returns

reactive index of the item in the list

Return type

RQListIndex

__iter__()

Iterator of the elements of the list.

Returns

Iterator of RQModels

Return type

Iterator[Any]

__len__()

Length of the list.

Return type

int

count(value)

Same as python list method.

Parameters

value (Any) –

Return type

int

extend(iterable)

Same as python list method.

Parameters

iterable (List[Any]) –

Return type

None

__contains__(item)

Same as python list method.

Parameters

item (Any) –

Return type

bool

class pyreaqtive.models.rqlist.RQComputedList(function, **kwargs)

Bases: pyreaqtive.models.rqmodel.RQComputedModel, pyreaqtive.models.rqlist.RQList

Reactive Computed List Model.

Parameters
_list: List[Any]

Model store variable

Stores list of instances

_reactive_indexes: Dict[object, pyreaqtive.models.rqint.RQInt]

Weak reference dictionary of reactive indexes requested and that have to be updated when list changes

Key is model Value is reactive index

__init__(function, **kwargs)

Constructor.

Parameters
  • function (Callable) – function to calculate the model value from input values

  • **kwargs – reactive models in the function by variable name as keyword Changes in these models will trigger recalculation of the function

  • kwargs (pyreaqtive.models.rqmodel.RQModel) –

_variable_changed()

Variable changed slot.

Called when some of the models have emitted rq_data_changed.

Recalculates the list with the function and calculates differences with the current list, inserting and deleting the differences.

Return type

None

get()

See overridden method.

ComputedLists are recalculated on change, not on request, so this just redirects to the actual list.

Return type

list