win_magnification._object_utils
Aug 11, 2023
Internal module
- class PropertiesObserver[source]
Bases:
object
Usage example:>>> class MyPropertiesObserver(PropertiesObserver): ... def __init__(self): ... self.property1 = 10 ... self.property2 = 10 ... super().__init__() ... >>> property_observer = MyPropertiesObserver() >>> property_observer.subscribe(lambda *_: print('update')) >>> with property_observer.batch() as value: ... value.property1 += 1 # or property_observer.property1 += 1 ... value.property2 -= 1 # or property_observer.property2 -= 1 update >>> property_observer.property1 += 1; property_observer.property2 -= 1 update update
- class DataSource[source]
Bases:
Generic
[T
]Wraps interaction with outer world data sources
- property data: T
- classmethod dynamic(source: Callable[[], T], setter: Callable[[T], None]) WrappedFieldType [source]
Creates
DataSource
with source/setter specified- Parameters
source – New method of getting fresh data
setter – New method of updating data
- Returns
New DataSource
- classmethod const(value: T) WrappedFieldType [source]
Creates
DataSource
which constantly returns the same value, that can’t be changed- Parameters
value – Const to retrieve
- Returns
New DataSource
- WrappedFieldType
Any child of
WrappedField
alias of TypeVar(‘WrappedFieldType’, bound=
WrappedField
)
- class WrappedField(datasource: Optional[DataSource[T]] = None)[source]
Bases:
PropertiesObserver
,Generic
[T
]Allows to get/set/get default/reset value of field wrappedMostly used to allow selective changes of complex fields- property default: WrappedFieldType
- property raw: T