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
43f0078a
Commit
43f0078a
authored
Jul 01, 2020
by
Tom Pillot
Browse files
Add start stop button on the scoreboard
parent
0fcfa328
Changes
9
Show whitespace changes
Inline
Side-by-side
game/icons/start.png
0 → 100644
View file @
43f0078a
5.92 KB
game/icons/stop.png
0 → 100644
View file @
43f0078a
4.35 KB
game/list_widget.qss
→
game/
qss/
list_widget.qss
View file @
43f0078a
File moved
game/table_widget.qss
→
game/
qss/
table_widget.qss
View file @
43f0078a
File moved
game/time_widget.qss
→
game/
qss/
time_widget.qss
View file @
43f0078a
File moved
game/scoreboard.py
View file @
43f0078a
...
...
@@ -15,18 +15,19 @@ class ScoreWindow(ScoreWindowUi):
self
.
teams
=
teams
self
.
initial_time
=
0
self
.
time_is_red
=
False
self
.
is_started
=
False
self
.
detector
=
Detector
()
self
.
start_stop_button
.
clicked
.
connect
(
self
.
start_stop_activity
)
def
start_scoreboard
(
self
,
time
):
# Start and display the clock
self
.
time_edit
.
setTime
(
time
)
self
.
initial_time
=
-
time
.
secsTo
(
qtc
.
QTime
(
0
,
0
,
0
,
0
))
# Time set initially in seconds
self
.
timer
.
timeout
.
connect
(
self
.
timer_timeout
)
self
.
timer
.
start
(
1000
)
self
.
update_gui
()
# Show the webcam
self
.
webcam_timer
.
timeout
.
connect
(
self
.
refresh_webcam
)
self
.
webcam_timer
.
start
(
self
.
WEBCAM_REFRESH_TIME
)
self
.
refresh_webcam
(
detect_tags
=
False
)
def
timer_timeout
(
self
):
self
.
timer
.
start
(
1000
)
...
...
@@ -74,7 +75,7 @@ class ScoreWindow(ScoreWindowUi):
# Keep the points item so the points can be modified later easily
team
.
points_item
=
points_item
def
refresh_webcam
(
self
):
def
refresh_webcam
(
self
,
detect_tags
=
True
):
# Read an image from the webcam and detect the tags it contains
ret
,
frame
=
self
.
detector
.
cam
.
read
()
dets
=
self
.
detector
.
show_tags_on_image
(
frame
)
...
...
@@ -90,6 +91,7 @@ class ScoreWindow(ScoreWindowUi):
print
(
"Failed to grab frame."
)
# Update scores
if
detect_tags
:
# Prevent teams from winning points when the game has not started
for
det
in
dets
:
if
det
.
decision_margin
>
self
.
detector
.
DECISION_MARGIN
:
self
.
add_points
(
det
.
tag_id
)
...
...
@@ -126,3 +128,18 @@ class ScoreWindow(ScoreWindowUi):
def
show_event
(
self
,
team
,
points_added
):
message
=
team
.
name
+
" a gagné "
+
str
(
points_added
)
+
" points."
self
.
list_widget
.
insertItem
(
0
,
message
)
def
start_stop_activity
(
self
):
"""
Start or stop the activity depending on the last button state
"""
if
self
.
is_started
:
self
.
timer
.
stop
()
self
.
webcam_timer
.
stop
()
self
.
start_stop_button
.
setIcon
(
qtg
.
QIcon
(
'game/icons/start.png'
))
self
.
is_started
=
False
else
:
self
.
timer
.
start
(
1000
)
self
.
webcam_timer
.
start
(
self
.
WEBCAM_REFRESH_TIME
)
self
.
start_stop_button
.
setIcon
(
qtg
.
QIcon
(
'game/icons/stop.png'
))
self
.
is_started
=
True
game/scoreboard_ui.py
View file @
43f0078a
...
...
@@ -18,6 +18,10 @@ class ScoreWindowUi(qtw.QMainWindow):
palette
.
setColor
(
qtg
.
QPalette
.
Background
,
qtg
.
QColor
(
"#E0E1E0"
))
self
.
setPalette
(
palette
)
self
.
start_stop_button
=
qtw
.
QPushButton
()
self
.
start_stop_button
.
setIcon
(
qtg
.
QIcon
(
'game/icons/start.png'
))
self
.
start_stop_button
.
setIconSize
(
qtc
.
QSize
(
50
,
50
))
self
.
time_edit
=
qtw
.
QTimeEdit
()
self
.
time_edit
.
setDisplayFormat
(
"mm:ss"
)
self
.
time_edit
.
setAlignment
(
qtc
.
Qt
.
AlignCenter
)
...
...
@@ -27,16 +31,18 @@ class ScoreWindowUi(qtw.QMainWindow):
# The time edit needs to be inside a widget so that we can set the style of the widget and
# later when the font color of the time edit is changed, the widget style remains the same
self
.
time_widget
=
qtw
.
QWidget
()
self
.
time_widget
.
setLayout
(
qtw
.
QVBoxLayout
())
self
.
time_widget
.
layout
().
addWidget
(
self
.
time_edit
)
hlayout1
=
qtw
.
QHBoxLayout
()
hlayout1
.
addWidget
(
self
.
time_edit
)
hlayout1
.
addWidget
(
self
.
start_stop_button
)
self
.
time_widget
.
setLayout
(
hlayout1
)
with
open
(
"game/time_widget.qss"
,
"r"
)
as
f
:
with
open
(
"game/
qss/
time_widget.qss"
,
"r"
)
as
f
:
self
.
time_widget
.
setStyleSheet
(
f
.
read
())
self
.
list_widget
=
qtw
.
QListWidget
()
self
.
list_widget
.
setDisabled
(
True
)
with
open
(
"game/list_widget.qss"
,
"r"
)
as
f
:
with
open
(
"game/
qss/
list_widget.qss"
,
"r"
)
as
f
:
self
.
list_widget
.
setStyleSheet
(
f
.
read
())
self
.
webcam_label
=
qtw
.
QLabel
()
...
...
@@ -57,7 +63,7 @@ class ScoreWindowUi(qtw.QMainWindow):
self
.
table_widget
.
setFocusPolicy
(
qtc
.
Qt
.
NoFocus
)
self
.
table_widget
.
setSelectionMode
(
qtw
.
QAbstractItemView
.
NoSelection
)
with
open
(
"game/table_widget.qss"
,
"r"
)
as
f
:
with
open
(
"game/
qss/
table_widget.qss"
,
"r"
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
self
.
timer
=
qtc
.
QTimer
(
self
)
...
...
@@ -66,13 +72,13 @@ class ScoreWindowUi(qtw.QMainWindow):
vlayout1
.
addWidget
(
self
.
list_widget
)
vlayout1
.
addWidget
(
self
.
webcam_label
)
hlayout
=
qtw
.
QHBoxLayout
()
hlayout
.
addWidget
(
self
.
table_widget
,
stretch
=
True
)
hlayout
.
addLayout
(
vlayout1
)
hlayout
2
=
qtw
.
QHBoxLayout
()
hlayout
2
.
addWidget
(
self
.
table_widget
,
stretch
=
True
)
hlayout
2
.
addLayout
(
vlayout1
)
vlayout2
=
qtw
.
QVBoxLayout
()
vlayout2
.
addWidget
(
self
.
time_widget
,
alignment
=
qtc
.
Qt
.
AlignCenter
)
vlayout2
.
addLayout
(
hlayout
)
vlayout2
.
addLayout
(
hlayout
2
)
widget
.
setLayout
(
vlayout2
)
def
resizeEvent
(
self
,
a0
):
...
...
game/team_chooser.py
View file @
43f0078a
...
...
@@ -22,10 +22,13 @@ class TeamWindow(TeamWindowUi):
self
.
detector
=
Detector
()
self
.
teams
=
{}
# The keys are the tag ids and the values are the teams
self
.
add_activities
()
self
.
scan_button
.
clicked
.
connect
(
self
.
detect_tag
)
self
.
add_button
.
clicked
.
connect
(
self
.
add_team
)
self
.
edit_button
.
clicked
.
connect
(
self
.
edit_team
)
self
.
delete_button
.
clicked
.
connect
(
self
.
delete_team
)
self
.
activity_box
.
currentIndexChanged
.
connect
(
self
.
show_activity_description
)
def
set_label_color
(
self
,
tag_id
):
try
:
...
...
@@ -120,3 +123,17 @@ class TeamWindow(TeamWindowUi):
self
.
status_bar
.
showMessage
(
"Veuillez choisir le temps de l'activité."
,
self
.
STATUS_TIME
)
return
False
return
True
def
add_activities
(
self
):
"""
Add activities with their descriptions
"""
name
=
"Course Thymio"
description
=
"Les équipes doivent programmer leur Thymio pour qu'il arrive le plus vite possible à la fin du"
\
" parcourt. Une webcam qui filme l'arrivée permet de détecter automatiquement les équipes qui "
\
"réussissent à finir la course dans les temps. "
self
.
activity_box
.
addItem
(
name
,
description
)
self
.
show_activity_description
()
def
show_activity_description
(
self
):
self
.
activity_description
.
setText
(
self
.
activity_box
.
currentData
())
game/team_chooser_ui.py
View file @
43f0078a
...
...
@@ -20,7 +20,12 @@ class TeamWindowUi(qtw.QMainWindow):
self
.
setStatusBar
(
self
.
status_bar
)
self
.
table_view
=
qtw
.
QTableView
()
# Prevent user from selecting and modifying the cells
self
.
table_view
.
setEditTriggers
(
qtw
.
QAbstractItemView
.
NoEditTriggers
)
self
.
table_view
.
setFocusPolicy
(
qtc
.
Qt
.
NoFocus
)
self
.
table_view
.
setSelectionMode
(
qtw
.
QAbstractItemView
.
NoSelection
)
self
.
table_view
.
horizontalHeader
().
setSectionResizeMode
(
qtw
.
QHeaderView
.
Stretch
)
self
.
table_view
.
verticalHeader
().
setVisible
(
False
)
...
...
@@ -38,7 +43,11 @@ class TeamWindowUi(qtw.QMainWindow):
self
.
edit_button
=
qtw
.
QPushButton
(
"Modifier"
)
self
.
delete_button
=
qtw
.
QPushButton
(
"Supprimer"
)
self
.
scan_button
=
qtw
.
QPushButton
(
"Scanner le tag"
)
self
.
activity_box
=
qtw
.
QComboBox
()
self
.
activity_description
=
qtw
.
QLabel
()
self
.
activity_description
.
setWordWrap
(
True
)
self
.
activity_description
.
setFixedWidth
(
300
)
self
.
start_button
=
qtw
.
QPushButton
(
"Démarrer l'activité"
)
self
.
tag_label
=
qtw
.
QLabel
(
""
)
...
...
@@ -75,12 +84,13 @@ class TeamWindowUi(qtw.QMainWindow):
vlayout2
=
qtw
.
QVBoxLayout
()
vlayout2
.
addWidget
(
qtw
.
QLabel
(
"Choix de l'activité :"
))
vlayout2
.
addWidget
(
self
.
activity_box
)
vlayout2
.
addWidget
(
self
.
activity_description
)
vlayout2
.
addItem
(
vertical_spacer
)
vlayout2
.
addWidget
(
qtw
.
QLabel
(
"Choix du temps :"
))
vlayout2
.
addWidget
(
self
.
time_edit
)
vlayout2
.
addItem
(
vertical_spacer
)
vlayout2
.
addWidget
(
self
.
start_button
)
vlayout2
.
addStretch
()
#
vlayout2.addStretch()
hlayout5
=
qtw
.
QHBoxLayout
()
hlayout5
.
addLayout
(
vlayout1
)
...
...
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