madgui.util.collections module¶
Observable collection classes.
Classes
|
A box that holds a single object and can be observed for changes (assigning a different object). |
|
|
|
A list-like class that can be observed for changes. |
Set of items with the additional notion of a cursor to the least recently active element. |
-
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
Signal<[<class ‘object’>]>
Signal<[<class ‘object’>, <class ‘object’>]>
Methods
changed_singleshot
(callback)set
(value[, force])-
changed
¶ Signal<[<class ‘object’>]>
-
changed2
¶ Signal<[<class ‘object’>, <class ‘object’>]>
-
-
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
Signal<[<class ‘int’>, <class ‘object’>]>
Signal<[<class ‘int’>, <class ‘object’>]>
Signal<[<class ‘int’>]>
Signal<[<class ‘object’>, <class ‘object’>, <class ‘object’>]>
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’>]>
-
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.
-
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
-
update_finished
¶ Signal<[<class ‘object’>, <class ‘object’>, <class ‘object’>]>
-
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 theSelection
class can be used to ensure that items stay unique.Methods
add
(item[, replace])Add the item to the set if not already present.
Return the currently active item.