Interfaces
observant.interfaces.observable.IObservable
Bases: Generic[T]
Source code in observant\interfaces\observable.py
disable()
enable()
get()
on_change(callback)
Register a callback function to be called when the value changes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback
|
Callable[[T], None]
|
A function that takes the new value as its argument. |
required |
set(value, notify=True)
Set a new value for the observable and notify all registered callbacks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
T
|
The new value to set. |
required |
notify
|
bool
|
Whether to notify the callbacks after setting the value. |
True
|
Source code in observant\interfaces\observable.py
observant.interfaces.list.IObservableList
Bases: Generic[T]
, ABC
Interface for observable lists with specific event types.
Source code in observant\interfaces\list.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
__contains__(item)
abstractmethod
__delitem__(index)
abstractmethod
__getitem__(index)
abstractmethod
__iter__()
abstractmethod
__len__()
abstractmethod
__setitem__(index, value)
abstractmethod
append(item)
abstractmethod
clear()
abstractmethod
copy()
abstractmethod
count(item)
abstractmethod
extend(items)
abstractmethod
index(item, start=0, end=None)
abstractmethod
insert(index, item)
abstractmethod
on_add(callback)
abstractmethod
on_change(callback)
abstractmethod
on_clear(callback)
abstractmethod
on_remove(callback)
abstractmethod
pop(index=-1)
abstractmethod
remove(item)
abstractmethod
observant.interfaces.dict.IObservableDict
Bases: Generic[TKey, TValue]
, ABC
Interface for observable dictionaries with specific event types.
Source code in observant\interfaces\dict.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
__contains__(key)
abstractmethod
__delitem__(key)
abstractmethod
__getitem__(key)
abstractmethod
__iter__()
abstractmethod
__len__()
abstractmethod
__setitem__(key, value)
abstractmethod
clear()
abstractmethod
copy()
abstractmethod
get(key, default=None)
abstractmethod
Return the value for a key if it exists, otherwise return a default value.
items()
abstractmethod
keys()
abstractmethod
on_add(callback)
abstractmethod
on_change(callback)
abstractmethod
on_clear(callback)
abstractmethod
on_remove(callback)
abstractmethod
on_update(callback)
abstractmethod
pop(key, default=None)
abstractmethod
Remove and return the value for a key if it exists, otherwise return a default value.
popitem()
abstractmethod
setdefault(key, default=None)
abstractmethod
Return the value for a key if it exists, otherwise set and return the default value.
update(other)
abstractmethod
observant.interfaces.proxy.IObservableProxy
Bases: Generic[T]
, ABC
Proxy for a data object that exposes its fields as Observable, ObservableList, or ObservableDict. Provides optional sync behavior to automatically write back to the source model.
Source code in observant\interfaces\proxy.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
add_validator(attr, validator)
abstractmethod
Add a validator function for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to validate. |
required |
validator
|
Callable[[Any], str | None]
|
A function that takes the field value and returns an error message if invalid, or None if valid. |
required |
Source code in observant\interfaces\proxy.py
can_redo(attr)
abstractmethod
Check if there are changes that can be redone for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if there are changes that can be redone, False otherwise. |
Source code in observant\interfaces\proxy.py
can_undo(attr)
abstractmethod
Check if there are changes that can be undone for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if there are changes that can be undone, False otherwise. |
Source code in observant\interfaces\proxy.py
computed(typ, name)
abstractmethod
Get a computed property by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
typ
|
type[T]
|
The type of the computed property. |
required |
name
|
str
|
The name of the computed property. |
required |
Returns:
Type | Description |
---|---|
IObservable[T]
|
An observable containing the computed value. |
Source code in observant\interfaces\proxy.py
dirty_fields()
abstractmethod
Get the set of field names that have been modified.
Returns:
Type | Description |
---|---|
set[str]
|
A set of field names that have been modified. |
get()
abstractmethod
is_dirty()
abstractmethod
Check if any fields have been modified since initialization or last reset.
Returns:
Type | Description |
---|---|
bool
|
True if any fields have been modified, False otherwise. |
is_valid()
abstractmethod
Get an observable that indicates whether all fields are valid.
Returns:
Type | Description |
---|---|
IObservable[bool]
|
An observable that emits True if all fields are valid, False otherwise. |
load_dict(values)
abstractmethod
observable(typ, attr, *, sync=None)
abstractmethod
Get or create an Observable[T] for a scalar field.
observable_dict(typ, attr, *, sync=None)
abstractmethod
Get or create an ObservableDict for a dict field.
observable_list(typ, attr, *, sync=None)
abstractmethod
Get or create an ObservableList[T] for a list field.
redo(attr)
abstractmethod
Redo the most recently undone change to a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to redo changes for. |
required |
register_computed(name, compute, dependencies)
abstractmethod
Register a computed property that depends on other observables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the computed property. |
required |
compute
|
Callable[[], T]
|
A function that returns the computed value. |
required |
dependencies
|
list[str]
|
List of field names that this computed property depends on. |
required |
Source code in observant\interfaces\proxy.py
reset_dirty()
abstractmethod
reset_validation(attr=None, *, revalidate=False)
abstractmethod
Reset validation errors for a specific field or all fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str | None
|
The field name to reset validation for. If None, reset all fields. |
None
|
revalidate
|
bool
|
Whether to re-run validators after clearing errors. |
False
|
Source code in observant\interfaces\proxy.py
save_to(obj)
abstractmethod
set_undo_config(attr, *, undo_max=None, undo_debounce_ms=None)
abstractmethod
Set the undo configuration for a specific field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to configure. |
required |
undo_max
|
int | None
|
Maximum number of undo steps to store. None means unlimited. |
None
|
undo_debounce_ms
|
int | None
|
Time window in milliseconds to group changes. None means no debouncing. |
None
|
Source code in observant\interfaces\proxy.py
track_scalar_change(attr, old_value, new_value)
abstractmethod
Track a scalar change for undo/redo functionality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name that changed. |
required |
old_value
|
Any
|
The old value before the change. |
required |
new_value
|
Any
|
The new value after the change. |
required |
Source code in observant\interfaces\proxy.py
undo(attr)
abstractmethod
Undo the most recent change to a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to undo changes for. |
required |
update(**kwargs)
abstractmethod
validation_errors()
abstractmethod
Get an observable dictionary of validation errors.
Returns:
Type | Description |
---|---|
IObservableDict[str, list[str]]
|
An observable dictionary mapping field names to lists of error messages. |
Source code in observant\interfaces\proxy.py
validation_for(attr)
abstractmethod
Get an observable list of validation errors for a specific field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The field name to get validation errors for. |
required |
Returns:
Type | Description |
---|---|
IObservable[list[str]]
|
An observable that emits a list of error messages for the field. |
IObservable[list[str]]
|
An empty list means the field is valid. |