madgui.util.collections module

Observable collection classes.

Classes

Boxed(value)

A box that holds a single object and can be observed for changes (assigning a different object).

Bool(value)

List([items])

A list-like class that can be observed for changes.

Selection()

Set of items with the additional notion of a cursor to the least recently active element.

class madgui.util.collections.Bool(value)[source]

Bases: madgui.util.collections.Boxed

class madgui.util.collections.Boxed(value)[source]

Bases: object

A box that holds a single object and can be observed for changes (assigning a different object).

Storing an object inside another one is the only way to pass around variable references in python (which doesn’t have native pointer or references variables otherwise and therefore only supports passing the objects themselves).

This class also provides a signal that notifies about changes in value.

This has some similarities to what is called a BehaviourSubject in RX.

Attributes

changed

Signal<[<class ‘object’>]>

changed2

Signal<[<class ‘object’>, <class ‘object’>]>

Methods

changed_singleshot(callback)

set(value[, force])

changed

Signal<[<class ‘object’>]>

changed2

Signal<[<class ‘object’>, <class ‘object’>]>

changed_singleshot(callback)[source]
set(value, force=False)[source]
class madgui.util.collections.List(items=None)[source]

Bases: object

A list-like class that can be observed for changes.

Methods

append(value)

S.append(value) – append value to the end of the sequence

clear()

count(value)

emit_changed_if(old, new)

Decide when self.changed should be emitted upon assigning a new value into an existing index.

extend(values)

index(value)

insert(index, value)

pop([index])

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) – remove first occurrence of value.

reverse()

S.reverse() – reverse IN PLACE

touch()

update_notify(slice, new_values)

Emit update signals, only when .

Attributes

changed

Signal<[<class ‘int’>, <class ‘object’>]>

inserted

Signal<[<class ‘int’>, <class ‘object’>]>

removed

Signal<[<class ‘int’>]>

update_finished

Signal<[<class ‘object’>, <class ‘object’>, <class ‘object’>]>

update_started

Signal<[<class ‘object’>, <class ‘object’>, <class ‘object’>]>

append(value)

S.append(value) – append value to the end of the sequence

changed

Signal<[<class ‘int’>, <class ‘object’>]>

clear()[source]
count(value)[source]
emit_changed_if(old, new)[source]

Decide when self.changed should be emitted upon assigning a new value into an existing index. Can be overridden by the user to change our behaviour.

extend(values)[source]
index(value)[source]
insert(index, value)[source]
inserted

Signal<[<class ‘int’>, <class ‘object’>]>

pop([index]) → item – remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

removed

Signal<[<class ‘int’>]>

reverse()

S.reverse() – reverse IN PLACE

touch()[source]
update_finished

Signal<[<class ‘object’>, <class ‘object’>, <class ‘object’>]>

update_notify(slice, new_values)[source]

Emit update signals, only when .

update_started

Signal<[<class ‘object’>, <class ‘object’>, <class ‘object’>]>

class madgui.util.collections.Selection[source]

Bases: madgui.util.collections.List

Set of items with the additional notion of a cursor to the least recently active element. Each item can occur only once in the set.

Note that the inherited List methods and signals can be used to listen for selection changes, and to query or delete items. However, for inserting or modifying elements, only use the methods defined in the Selection class can be used to ensure that items stay unique.

Methods

add(item[, replace])

Add the item to the set if not already present.

cursor_item()

Return the currently active item.

add(item, replace=False)[source]

Add the item to the set if not already present. If replace is true, the currently active item will be replaced by the new item. In each case, set the active element to item.

cursor_item()[source]

Return the currently active item.