Commit 571723c8 authored by Tom Pillot's avatar Tom Pillot
Browse files

Disconnect timers before reconnecting them so they don't have multiple handlers

parent 9898d72b
......@@ -146,7 +146,7 @@ class ScoreWindow(ScoreWindowUi):
""" Start or stop the activity depending on the last button state """
if self.join_started:
# Start scoreboard and tag detection
self.webcam_timer.timeout.connect(self.refresh_webcam)
reconnect(self.webcam_timer.timeout, self.refresh_webcam)
self.scoreboard_timer.start(1000)
self.webcam_timer.start(self.WEBCAM_REFRESH_TIME)
......@@ -154,7 +154,7 @@ class ScoreWindow(ScoreWindowUi):
self.join_started = False
# Run all Thymios at the same time
self.send_timer.timeout.connect(self.send_start_broadcast)
reconnect(self.send_timer.timeout, self.send_start_broadcast)
self.send_timer.start(self.SEND_TIME)
else:
......@@ -162,15 +162,30 @@ class ScoreWindow(ScoreWindowUi):
self.join_started = True
# Send a message to all Thymios so they can join the activity
self.send_timer.timeout.connect(self.send_join_broadcast)
reconnect(self.send_timer.timeout, self.send_join_broadcast)
self.send_timer.start(self.SEND_TIME)
def send_join_broadcast(self):
""" Send a message to all Thymios so they can join the activity """
self.socket.sendto("join".encode(), self.socket_dest)
print("join")
self.send_timer.start(self.SEND_TIME)
def send_start_broadcast(self):
""" Send a message to all Thymios to run at the same time """
self.socket.sendto("start".encode(), self.socket_dest)
print("start")
self.send_timer.start(self.SEND_TIME)
def reconnect(signal, new_handler=None, old_handler=None):
while True:
try:
if old_handler is not None:
signal.disconnect(old_handler)
else:
signal.disconnect()
except TypeError:
break
if new_handler is not None:
signal.connect(new_handler)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment