Commit c1829a63 authored by Tom Pillot's avatar Tom Pillot
Browse files

Added a table for the scoreboard and custom style

parent 7229d008
...@@ -32,6 +32,17 @@ class ScoreWindow(ScoreWindowUi): ...@@ -32,6 +32,17 @@ class ScoreWindow(ScoreWindowUi):
def update_gui(self): def update_gui(self):
self.time_edit.setTime(self.time_edit.time().addSecs(-1)) 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(): 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()
...@@ -4,6 +4,8 @@ from PyQt5 import QtGui as qtg ...@@ -4,6 +4,8 @@ from PyQt5 import QtGui as qtg
class ScoreWindowUi(qtw.QMainWindow): class ScoreWindowUi(qtw.QMainWindow):
RANK, NAME, POINTS = range(3)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
...@@ -11,29 +13,49 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -11,29 +13,49 @@ class ScoreWindowUi(qtw.QMainWindow):
widget = qtw.QWidget(self) widget = qtw.QWidget(self)
self.setCentralWidget(widget) self.setCentralWidget(widget)
self.list_widget = qtw.QListWidget()
self.time_edit = qtw.QTimeEdit() self.time_edit = qtw.QTimeEdit()
self.time_edit.setFont(qtg.QFont("Arial", 80, qtg.QFont.Bold)) self.time_edit.setFont(qtg.QFont("Arial", 80, qtg.QFont.Bold))
self.time_edit.setDisplayFormat("mm:ss") self.time_edit.setDisplayFormat("mm:ss")
self.time_edit.setAlignment(qtc.Qt.AlignCenter) self.time_edit.setAlignment(qtc.Qt.AlignCenter)
self.time_edit.setReadOnly(True) self.time_edit.setReadOnly(True)
self.time_edit.setStyleSheet("""
QTimeEdit { with open("game/time_edit.qss", "r") as f:
color: white; self.time_edit.setStyleSheet(f.read())
selection-color: white;
selection-background-color: black; self.list_view = qtw.QListView()
background-color: black; self.webcam_pixmap = qtg.QPixmap("/home/ozon/Pictures/icone.png")
border-style: solid; self.webcam_label = qtw.QLabel()
border-width: 4px; self.webcam_label.setPixmap(self.webcam_pixmap)
border-color: rgb(100,100,100);
} self.table_widget = qtw.QTableWidget(0, 3, self)
QTimeEdit::up-button {width: 0} self.table_widget.setHorizontalHeaderItem(self.RANK, qtw.QTableWidgetItem("Classement"))
QTimeEdit::down-button {width: 0} 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) self.timer = qtc.QTimer(self)
vlayout = qtw.QVBoxLayout() vlayout1 = qtw.QVBoxLayout()
vlayout.addWidget(self.time_edit, alignment=qtc.Qt.AlignCenter) vlayout1.addWidget(self.list_view)
vlayout.addWidget(self.list_widget) vlayout1.addWidget(self.webcam_label)
widget.setLayout(vlayout)
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))
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
class Team: class Team:
def __init__(self, name, tag_id): def __init__(self, name, tag_id, color):
self.name = name self.name = name
self.tag_id = tag_id self.tag_id = tag_id
self.color = color
self.points = 0 self.points = 0
self.rank = 0
def add_points(self, points_added): def add_points(self, points_added):
self.points += points_added self.points += points_added
...@@ -10,7 +10,7 @@ class TeamWindow(TeamWindowUi): ...@@ -10,7 +10,7 @@ class TeamWindow(TeamWindowUi):
STATUS_TIME = 5000 STATUS_TIME = 5000
team_colors = { team_colors = {
1: "#FE3200", 2: "#FE6500", 3: "#FE9800", 4: "#FECB00", 5: "#FEFE00", 6: "#CBFE00", 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", 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", 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" 96: "#FE005D", 97: "#FE002A", 98: "#474747", 99: "#8C8C8C", 100: "#643030", 101: "#9A6565", 102: "#BC9F9F"
...@@ -59,7 +59,7 @@ class TeamWindow(TeamWindowUi): ...@@ -59,7 +59,7 @@ class TeamWindow(TeamWindowUi):
self.tag_label.setText("") self.tag_label.setText("")
self.tag_label.setStyleSheet("") self.tag_label.setStyleSheet("")
self.name_input.setText("") 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): def edit_team(self):
""" """
......
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
...@@ -19,13 +19,27 @@ class MainWindow(qtw.QWidget): ...@@ -19,13 +19,27 @@ class MainWindow(qtw.QWidget):
def start_activity(self): def start_activity(self):
if self.team_window.can_start_activity(): if self.team_window.can_start_activity():
self.scoreboard_window.show_teams() self.scoreboard_window.add_teams()
time = self.team_window.time_edit.time() time = self.team_window.time_edit.time()
self.scoreboard_window.timer_start(time) self.scoreboard_window.timer_start(time)
self.stacked_layout.setCurrentIndex(1) self.stacked_layout.setCurrentIndex(1)
self.scoreboard_window.showMaximized()
if __name__ == '__main__': if __name__ == '__main__':
app = qtw.QApplication(sys.argv) app = qtw.QApplication(sys.argv)
w = MainWindow() 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_()) sys.exit(app.exec_())
Markdown is supported
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