Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 37c45366 authored by PEDERSEN Ny Aina's avatar PEDERSEN Ny Aina
Browse files

Update event call to give the var name.

Add the variable name to value_change events so we can use
a single handler to handle a set of variables.
parent 9ebedd19
No related branches found
No related tags found
No related merge requests found
......@@ -32,18 +32,20 @@ class EventList:
self.events = defaultdict(set)
self.variables = variables
def connect(self, event: str, function: Callable[[Any], None]) -> None:
def connect(self, event: str, function: Callable[[str, Any], None]) -> None:
"""
Connect a function to an event.
:param event: The name of the event to listen.
:param function: The function to call with the updated value.
:param function: The function to call on update. Receives two arguments
that are the variable that has been updated
and the updated value.
"""
self.events[event].add(function)
def disconnect(
self,
function: Callable[[Any], None],
function: Callable[[str, Any], None],
event: Optional[str] = None
) -> None:
"""
......@@ -67,7 +69,7 @@ class EventList:
"""
for variable in variable_list:
for function in self.events[f"value_change:{variable}"]:
function(self.variables[variable])
function(variable, self.variables[variable])
def trigger(self, event: str, *args: Optional[list[Any]]) -> None:
"""
......
......@@ -9,8 +9,7 @@ from level.level import level
# List that stores and the values of the variable that we watch
VALUES = []
def event_callback(new_value: int) -> None:
def event_callback(var: str, new_value: int) -> None:
"""
Append the new value to the global list
when a value_change event is received.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment