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
0a8784e2
Commit
0a8784e2
authored
Jun 30, 2020
by
Tom Pillot
Browse files
Improved scoreboard design
parent
d5e9d9e4
Changes
8
Hide whitespace changes
Inline
Side-by-side
game/detector.py
View file @
0a8784e2
...
...
@@ -43,8 +43,6 @@ class Detector(apriltag.Detector):
greys
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2GRAY
)
dets
=
super
().
detect
(
greys
)
for
det
in
dets
:
print
(
dir
(
det
))
print
(
type
(
det
))
if
det
.
decision_margin
>=
self
.
DECISION_MARGIN
:
rect
=
det
.
corners
.
astype
(
int
).
reshape
((
-
1
,
1
,
2
))
cv2
.
polylines
(
img
,
[
rect
],
True
,
(
0
,
0
,
255
),
2
)
...
...
game/scoreboard.py
View file @
0a8784e2
...
...
@@ -37,6 +37,8 @@ class ScoreWindow(ScoreWindowUi):
self
.
time_is_red
=
True
else
:
self
.
update_gui
()
# Sort the table
self
.
sort_by_points
()
def
update_gui
(
self
):
self
.
time_edit
.
setTime
(
self
.
time_edit
.
time
().
addSecs
(
-
1
))
...
...
@@ -49,10 +51,18 @@ class ScoreWindow(ScoreWindowUi):
i
+=
1
def
set_table_item
(
self
,
row
,
team
):
self
.
table_widget
.
setItem
(
row
,
self
.
RANK
,
qtw
.
QTableWidgetItem
(
str
(
team
.
rank
)))
self
.
table_widget
.
item
(
row
,
self
.
RANK
).
setBackground
(
qtg
.
QColor
(
team
.
color
))
self
.
table_widget
.
setItem
(
row
,
self
.
NAME
,
qtw
.
QTableWidgetItem
(
team
.
name
))
self
.
table_widget
.
setItem
(
row
,
self
.
POINTS
,
qtw
.
QTableWidgetItem
(
str
(
team
.
points
)))
rank_item
=
qtw
.
QTableWidgetItem
(
"#"
+
str
(
team
.
rank
))
rank_item
.
setBackground
(
qtg
.
QColor
(
team
.
color
))
rank_item
.
setTextAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
table_widget
.
setItem
(
row
,
self
.
RANK
,
rank_item
)
self
.
table_widget
.
setItem
(
row
,
self
.
NAME
,
qtw
.
QTableWidgetItem
(
" "
+
team
.
name
))
points_item
=
qtw
.
QTableWidgetItem
()
points_item
.
setData
(
qtc
.
Qt
.
EditRole
,
team
.
points
)
points_item
.
setTextAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
table_widget
.
setItem
(
row
,
self
.
POINTS
,
points_item
)
self
.
table_widget
.
resizeRowsToContents
()
self
.
table_widget
.
resizeColumnsToContents
()
...
...
@@ -70,3 +80,10 @@ class ScoreWindow(ScoreWindowUi):
else
:
print
(
"Failed to grab frame."
)
self
.
webcam_timer
.
start
(
self
.
WEBCAM_REFRESH_TIME
)
def
sort_by_points
(
self
):
self
.
table_widget
.
sortByColumn
(
self
.
POINTS
,
qtc
.
Qt
.
DescendingOrder
)
# Update ranks
for
row
in
range
(
self
.
table_widget
.
rowCount
()):
item
=
self
.
table_widget
.
item
(
row
,
self
.
RANK
)
item
.
setText
(
"#"
+
str
(
row
+
1
))
game/scoreboard_ui.py
View file @
0a8784e2
...
...
@@ -17,8 +17,8 @@ class ScoreWindowUi(qtw.QMainWindow):
self
.
time_edit
.
setFont
(
qtg
.
QFont
(
"Arial"
,
100
,
qtg
.
QFont
.
Bold
))
self
.
time_edit
.
setDisplayFormat
(
"mm:ss"
)
self
.
time_edit
.
setAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
time_edit
.
setReadOnly
(
True
)
self
.
time_edit
.
setFixedHeight
(
200
)
self
.
time_edit
.
setDisabled
(
True
)
with
open
(
"game/time_edit.qss"
,
"r"
)
as
f
:
self
.
time_edit
.
setStyleSheet
(
f
.
read
())
...
...
@@ -35,6 +35,8 @@ class ScoreWindowUi(qtw.QMainWindow):
self
.
table_widget
.
setFont
(
qtg
.
QFont
(
"Arial"
,
40
,
qtg
.
QFont
.
Bold
))
self
.
table_widget
.
setEditTriggers
(
qtw
.
QAbstractItemView
.
NoEditTriggers
)
self
.
table_widget
.
verticalHeader
().
setVisible
(
False
)
self
.
table_widget
.
setFocusPolicy
(
qtc
.
Qt
.
NoFocus
)
self
.
table_widget
.
setSelectionMode
(
qtw
.
QAbstractItemView
.
NoSelection
)
# self.table_widget.setShowGrid(False)
with
open
(
"game/table_widget.qss"
,
"r"
)
as
f
:
...
...
game/table_widget.qss
View file @
0a8784e2
QHeaderView::section {
background-color: #646464;
color: rgba(255, 255, 255, 222);
background-color: rgb(63, 81, 181);
padding: 4px;
font-size: 14pt;
border-style: none;
...
...
@@ -16,6 +17,7 @@ QHeaderView::section:vertical {
}
QTableWidget {
color: #FFFFFF;
color: rgba(0, 0, 0, 222);
background-color: rgb(245, 245, 246);
border-radius: 10px;
}
\ No newline at end of file
game/team.py
View file @
0a8784e2
class
Team
:
def
__init__
(
self
,
name
,
tag_id
,
color
):
def
__init__
(
self
,
name
,
tag_id
,
color
,
points
):
self
.
name
=
name
self
.
tag_id
=
tag_id
self
.
color
=
color
self
.
points
=
0
self
.
points
=
points
self
.
rank
=
0
self
.
can_win_points
=
True
def
add_points
(
self
,
points_added
):
self
.
points
+=
points_added
if
self
.
can_win_points
:
self
.
points
+=
points_added
self
.
can_win_points
=
False
game/team_chooser.py
View file @
0a8784e2
...
...
@@ -19,6 +19,8 @@ class TeamWindow(TeamWindowUi):
def
__init__
(
self
):
super
().
__init__
()
self
.
random_gen
=
qtc
.
QRandomGenerator
()
# For testing
self
.
detector
=
Detector
()
self
.
teams
=
{}
# The keys are the tag ids and the values are the teams
...
...
@@ -59,7 +61,7 @@ class TeamWindow(TeamWindowUi):
self
.
tag_label
.
setText
(
""
)
self
.
tag_label
.
setStyleSheet
(
""
)
self
.
name_input
.
setText
(
""
)
self
.
teams
[
tag_id
]
=
Team
(
name
,
tag_id
,
self
.
team_colors
[
tag_id
])
self
.
teams
[
tag_id
]
=
Team
(
name
,
tag_id
,
self
.
team_colors
[
tag_id
]
,
int
(
self
.
random_gen
.
generate
()
/
10000000
)
)
def
edit_team
(
self
):
"""
...
...
game/time_edit.qss
View file @
0a8784e2
QTimeEdit {
color: white;
selection-color: white;
selection-background-color: black;
background-color: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 cyan, stop:1 blue);
border-style: solid;
border-width: 4px;
border-color: rgb(100,100,100);
color: #EEF4FF;
background-color: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #028BC3, stop:1 #7B4FB7);
border-radius: 10px;
}
QTimeEdit::up-button {width: 0}
...
...
main.py
View file @
0a8784e2
...
...
@@ -30,7 +30,7 @@ if __name__ == '__main__':
app
=
qtw
.
QApplication
(
sys
.
argv
)
w
=
MainWindow
()
# A
jout automatique d'équipe pour tester l'
application
# A
dd teams to test the
application
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
"test"
:
for
tag_id
in
w
.
team_window
.
team_colors
.
keys
():
tag_str
=
str
(
tag_id
)
...
...
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