mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
udpates DataServiceList (constructor and attributes)
This commit is contained in:
parent
f6eef7085e
commit
28410a97f5
@ -119,7 +119,9 @@ class CallbackManager:
|
|||||||
else:
|
else:
|
||||||
# convert the builtin list into a DataServiceList and add the
|
# convert the builtin list into a DataServiceList and add the
|
||||||
# callback
|
# callback
|
||||||
notifying_list = DataServiceList(attr_value, callback=[callback])
|
notifying_list = DataServiceList(
|
||||||
|
attr_value, callback_list=[callback]
|
||||||
|
)
|
||||||
self._list_mapping[id(attr_value)] = notifying_list
|
self._list_mapping[id(attr_value)] = notifying_list
|
||||||
|
|
||||||
setattr(obj, attr_name, notifying_list)
|
setattr(obj, attr_name, notifying_list)
|
||||||
|
@ -23,21 +23,17 @@ class DataServiceList(list):
|
|||||||
|
|
||||||
Additional callbacks can be added after initialization using the `add_callback`
|
Additional callbacks can be added after initialization using the `add_callback`
|
||||||
method.
|
method.
|
||||||
|
|
||||||
Attributes:
|
|
||||||
callbacks (list):
|
|
||||||
List of callback functions to be executed on item set.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*args: list[Any],
|
*args: list[Any],
|
||||||
callback: list[Callable[[int, Any], None]] | None = None,
|
callback_list: list[Callable[[int, Any], None]] | None = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.callbacks: list[Callable[[int, Any], None]] = []
|
self._callbacks: list[Callable[[int, Any], None]] = []
|
||||||
if isinstance(callback, list):
|
if isinstance(callback_list, list):
|
||||||
self.callbacks = callback
|
self._callbacks = callback_list
|
||||||
|
|
||||||
for item in args[0]:
|
for item in args[0]:
|
||||||
warn_if_instance_class_does_not_inherit_from_DataService(item)
|
warn_if_instance_class_does_not_inherit_from_DataService(item)
|
||||||
@ -58,7 +54,7 @@ class DataServiceList(list):
|
|||||||
value = u.convert_to_quantity(value, str(current_value.u))
|
value = u.convert_to_quantity(value, str(current_value.u))
|
||||||
super().__setitem__(key, value) # type: ignore
|
super().__setitem__(key, value) # type: ignore
|
||||||
|
|
||||||
for callback in self.callbacks:
|
for callback in self._callbacks:
|
||||||
callback(key, value)
|
callback(key, value)
|
||||||
|
|
||||||
def add_callback(self, callback: Callable[[int, Any], None]) -> None:
|
def add_callback(self, callback: Callable[[int, Any], None]) -> None:
|
||||||
@ -69,4 +65,4 @@ class DataServiceList(list):
|
|||||||
callback (Callable[[int, Any], None]): Callback function that takes two
|
callback (Callable[[int, Any], None]): Callback function that takes two
|
||||||
arguments - index of the changed item and its new value.
|
arguments - index of the changed item and its new value.
|
||||||
"""
|
"""
|
||||||
self.callbacks.append(callback)
|
self._callbacks.append(callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user