Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tom Pillot
Thymio Game
Commits
571723c8
Commit
571723c8
authored
Jul 03, 2020
by
Tom Pillot
Browse files
Disconnect timers before reconnecting them so they don't have multiple handlers
parent
9898d72b
Changes
1
Hide whitespace changes
Inline
Side-by-side
game/scoreboard.py
View file @
571723c8
...
@@ -146,7 +146,7 @@ class ScoreWindow(ScoreWindowUi):
...
@@ -146,7 +146,7 @@ class ScoreWindow(ScoreWindowUi):
""" Start or stop the activity depending on the last button state """
""" Start or stop the activity depending on the last button state """
if
self
.
join_started
:
if
self
.
join_started
:
# Start scoreboard and tag detection
# 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
.
scoreboard_timer
.
start
(
1000
)
self
.
webcam_timer
.
start
(
self
.
WEBCAM_REFRESH_TIME
)
self
.
webcam_timer
.
start
(
self
.
WEBCAM_REFRESH_TIME
)
...
@@ -154,7 +154,7 @@ class ScoreWindow(ScoreWindowUi):
...
@@ -154,7 +154,7 @@ class ScoreWindow(ScoreWindowUi):
self
.
join_started
=
False
self
.
join_started
=
False
# Run all Thymios at the same time
# 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
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
else
:
else
:
...
@@ -162,15 +162,30 @@ class ScoreWindow(ScoreWindowUi):
...
@@ -162,15 +162,30 @@ class ScoreWindow(ScoreWindowUi):
self
.
join_started
=
True
self
.
join_started
=
True
# Send a message to all Thymios so they can join the activity
# 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
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
def
send_join_broadcast
(
self
):
def
send_join_broadcast
(
self
):
""" Send a message to all Thymios so they can join the activity """
""" Send a message to all Thymios so they can join the activity """
self
.
socket
.
sendto
(
"join"
.
encode
(),
self
.
socket_dest
)
self
.
socket
.
sendto
(
"join"
.
encode
(),
self
.
socket_dest
)
print
(
"join"
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
def
send_start_broadcast
(
self
):
def
send_start_broadcast
(
self
):
""" Send a message to all Thymios to run at the same time """
""" Send a message to all Thymios to run at the same time """
self
.
socket
.
sendto
(
"start"
.
encode
(),
self
.
socket_dest
)
self
.
socket
.
sendto
(
"start"
.
encode
(),
self
.
socket_dest
)
print
(
"start"
)
self
.
send_timer
.
start
(
self
.
SEND_TIME
)
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment