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(items)

Method to set the value of the underlying object.

Must be overridden by model

Parameters
  • value – New value of the model

  • items (List[Any]) –

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

Returns:

append(item)

Append a 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 – positional index on the list

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()
reactive_index(model)

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

Parameters
  • item – instance that should be in the list

  • model (object) –

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

Return type

int

extend(iterable)

Same as python list method

Parameters

iterable (List[Any]) –

__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