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
c1829a63
Commit
c1829a63
authored
Jun 30, 2020
by
Tom Pillot
Browse files
Added a table for the scoreboard and custom style
parent
7229d008
Changes
7
Hide whitespace changes
Inline
Side-by-side
game/scoreboard.py
View file @
c1829a63
...
...
@@ -32,6 +32,17 @@ class ScoreWindow(ScoreWindowUi):
def
update_gui
(
self
):
self
.
time_edit
.
setTime
(
self
.
time_edit
.
time
().
addSecs
(
-
1
))
def
show_teams
(
self
):
def
add_teams
(
self
):
self
.
table_widget
.
setRowCount
(
len
(
self
.
teams
))
i
=
0
for
team
in
self
.
teams
.
values
():
self
.
list_widget
.
addItem
(
team
.
name
)
self
.
set_table_item
(
i
,
team
)
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
)))
self
.
table_widget
.
resizeRowsToContents
()
self
.
table_widget
.
resizeColumnsToContents
()
game/scoreboard_ui.py
View file @
c1829a63
...
...
@@ -4,6 +4,8 @@ from PyQt5 import QtGui as qtg
class
ScoreWindowUi
(
qtw
.
QMainWindow
):
RANK
,
NAME
,
POINTS
=
range
(
3
)
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -11,29 +13,49 @@ class ScoreWindowUi(qtw.QMainWindow):
widget
=
qtw
.
QWidget
(
self
)
self
.
setCentralWidget
(
widget
)
self
.
list_widget
=
qtw
.
QListWidget
()
self
.
time_edit
=
qtw
.
QTimeEdit
()
self
.
time_edit
.
setFont
(
qtg
.
QFont
(
"Arial"
,
80
,
qtg
.
QFont
.
Bold
))
self
.
time_edit
.
setDisplayFormat
(
"mm:ss"
)
self
.
time_edit
.
setAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
time_edit
.
setReadOnly
(
True
)
self
.
time_edit
.
setStyleSheet
(
"""
QTimeEdit {
color: white;
selection-color: white;
selection-background-color: black;
background-color: black;
border-style: solid;
border-width: 4px;
border-color: rgb(100,100,100);
}
QTimeEdit::up-button {width: 0}
QTimeEdit::down-button {width: 0}
"""
)
with
open
(
"game/time_edit.qss"
,
"r"
)
as
f
:
self
.
time_edit
.
setStyleSheet
(
f
.
read
())
self
.
list_view
=
qtw
.
QListView
()
self
.
webcam_pixmap
=
qtg
.
QPixmap
(
"/home/ozon/Pictures/icone.png"
)
self
.
webcam_label
=
qtw
.
QLabel
()
self
.
webcam_label
.
setPixmap
(
self
.
webcam_pixmap
)
self
.
table_widget
=
qtw
.
QTableWidget
(
0
,
3
,
self
)
self
.
table_widget
.
setHorizontalHeaderItem
(
self
.
RANK
,
qtw
.
QTableWidgetItem
(
"Classement"
))
self
.
table_widget
.
setHorizontalHeaderItem
(
self
.
NAME
,
qtw
.
QTableWidgetItem
(
"Nom"
))
self
.
table_widget
.
setHorizontalHeaderItem
(
self
.
POINTS
,
qtw
.
QTableWidgetItem
(
"Points"
))
# self.table_widget.horizontalHeader().setSectionResizeMode(qtw.QHeaderView.Stretch)
self
.
table_widget
.
setEditTriggers
(
qtw
.
QAbstractItemView
.
NoEditTriggers
)
self
.
table_widget
.
verticalHeader
().
setVisible
(
False
)
# self.table_widget.setShowGrid(False)
with
open
(
"game/table_widget.qss"
,
"r"
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
self
.
timer
=
qtc
.
QTimer
(
self
)
vlayout
=
qtw
.
QVBoxLayout
()
vlayout
.
addWidget
(
self
.
time_edit
,
alignment
=
qtc
.
Qt
.
AlignCenter
)
vlayout
.
addWidget
(
self
.
list_widget
)
widget
.
setLayout
(
vlayout
)
vlayout1
=
qtw
.
QVBoxLayout
()
vlayout1
.
addWidget
(
self
.
list_view
)
vlayout1
.
addWidget
(
self
.
webcam_label
)
hlayout
=
qtw
.
QHBoxLayout
()
hlayout
.
addWidget
(
self
.
table_widget
)
hlayout
.
addLayout
(
vlayout1
)
vlayout2
=
qtw
.
QVBoxLayout
()
vlayout2
.
addWidget
(
self
.
time_edit
,
alignment
=
qtc
.
Qt
.
AlignCenter
)
vlayout2
.
addLayout
(
hlayout
)
widget
.
setLayout
(
vlayout2
)
def
resizeEvent
(
self
,
a0
):
self
.
table_widget
.
setColumnWidth
(
self
.
RANK
,
int
(
self
.
table_widget
.
width
()
/
6
))
self
.
table_widget
.
setColumnWidth
(
self
.
NAME
,
int
(
self
.
table_widget
.
width
()
/
2
))
self
.
table_widget
.
setColumnWidth
(
self
.
POINTS
,
int
(
self
.
table_widget
.
width
()
/
3
))
game/table_widget.qss
0 → 100644
View file @
c1829a63
QHeaderView::section {
background-color: #646464;
padding: 4px;
font-size: 14pt;
border-style: none;
border-bottom: 1px solid #fffff8;
border-right: 1px solid #fffff8;
}
QHeaderView::section:horizontal {
border-top: 1px solid #fffff8;
}
QHeaderView::section:vertical {
border-left: 1px solid #fffff8;
}
QTableWidget {
color: #FFFFFF;
font-size: 20pt;
border-radius: 10px;
}
\ No newline at end of file
game/team.py
View file @
c1829a63
class
Team
:
def
__init__
(
self
,
name
,
tag_id
):
def
__init__
(
self
,
name
,
tag_id
,
color
):
self
.
name
=
name
self
.
tag_id
=
tag_id
self
.
color
=
color
self
.
points
=
0
self
.
rank
=
0
def
add_points
(
self
,
points_added
):
self
.
points
+=
points_added
game/team_chooser.py
View file @
c1829a63
...
...
@@ -10,7 +10,7 @@ class TeamWindow(TeamWindowUi):
STATUS_TIME
=
5000
team_colors
=
{
1
:
"#FE3200"
,
2
:
"#FE6500"
,
3
:
"#FE9800"
,
4
:
"#FECB00"
,
5
:
"#FEFE00"
,
6
:
"#CBFE00"
,
24
:
"#98FE00"
,
25
:
"#65FE00"
,
26
:
"#32FE00"
,
27
:
"#00FE00"
,
28
:
"00FE32"
,
29
:
"#00FE65"
,
30
:
"#00FE98"
,
24
:
"#98FE00"
,
25
:
"#65FE00"
,
26
:
"#32FE00"
,
27
:
"#00FE00"
,
28
:
"
#
00FE32"
,
29
:
"#00FE65"
,
30
:
"#00FE98"
,
48
:
"#00FECB"
,
49
:
"#00FEFE"
,
50
:
"#00CBFE"
,
51
:
"#0098FE"
,
52
:
"#0065FE"
,
53
:
"#0032FE"
,
54
:
"#0000FE"
,
72
:
"#3200FE"
,
73
:
"#6500FE"
,
74
:
"#A100FE"
,
75
:
"#D400FE"
,
76
:
"#FE00F6"
,
77
:
"#FF00C3"
,
78
:
"#FE008F"
,
96
:
"#FE005D"
,
97
:
"#FE002A"
,
98
:
"#474747"
,
99
:
"#8C8C8C"
,
100
:
"#643030"
,
101
:
"#9A6565"
,
102
:
"#BC9F9F"
...
...
@@ -59,7 +59,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
.
teams
[
tag_id
]
=
Team
(
name
,
tag_id
,
self
.
team_colors
[
tag_id
]
)
def
edit_team
(
self
):
"""
...
...
game/time_edit.qss
0 → 100644
View file @
c1829a63
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);
}
QTimeEdit::up-button {width: 0}
QTimeEdit::down-button {width: 0}
\ No newline at end of file
main.py
View file @
c1829a63
...
...
@@ -19,13 +19,27 @@ class MainWindow(qtw.QWidget):
def
start_activity
(
self
):
if
self
.
team_window
.
can_start_activity
():
self
.
scoreboard_window
.
show
_teams
()
self
.
scoreboard_window
.
add
_teams
()
time
=
self
.
team_window
.
time_edit
.
time
()
self
.
scoreboard_window
.
timer_start
(
time
)
self
.
stacked_layout
.
setCurrentIndex
(
1
)
self
.
scoreboard_window
.
showMaximized
()
if
__name__
==
'__main__'
:
app
=
qtw
.
QApplication
(
sys
.
argv
)
w
=
MainWindow
()
# Ajout automatique d'équipe pour tester l'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
)
name
=
"test"
+
str
(
tag_id
)
w
.
team_window
.
name_input
.
setText
(
name
)
w
.
team_window
.
tag_label
.
setText
(
tag_str
)
w
.
team_window
.
add_button
.
click
()
table_name
=
w
.
team_window
.
table_model
.
data
(
w
.
team_window
.
table_model
.
index
(
0
,
w
.
team_window
.
NAME
))
table_tag_id
=
w
.
team_window
.
table_model
.
data
(
w
.
team_window
.
table_model
.
index
(
0
,
w
.
team_window
.
TAG
))
sys
.
exit
(
app
.
exec_
())
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