scoreboard_ui.py 3.57 KB
Newer Older
Tom Pillot's avatar
Tom Pillot committed
1
2
3
4
5
6
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg


class ScoreWindowUi(qtw.QMainWindow):
7
8
    RANK, NAME, POINTS = range(3)

Tom Pillot's avatar
Tom Pillot committed
9
10
11
12
13
14
15
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Scores")
        widget = qtw.QWidget(self)
        self.setCentralWidget(widget)

Tom Pillot's avatar
Tom Pillot committed
16
17
18
19
20
        # Change background color
        palette = qtg.QPalette()
        palette.setColor(qtg.QPalette.Background, qtg.QColor("#E0E1E0"))
        self.setPalette(palette)

21
22
23
24
        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))

Tom Pillot's avatar
Tom Pillot committed
25
26
27
        self.time_edit = qtw.QTimeEdit()
        self.time_edit.setDisplayFormat("mm:ss")
        self.time_edit.setAlignment(qtc.Qt.AlignCenter)
28
        self.time_edit.setFixedHeight(200)
29
        self.time_edit.setDisabled(True)  # The time can't be modified or selected
30

Tom Pillot's avatar
Tom Pillot committed
31
32
33
        # 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()
34
35
36
37
        hlayout1 = qtw.QHBoxLayout()
        hlayout1.addWidget(self.time_edit)
        hlayout1.addWidget(self.start_stop_button)
        self.time_widget.setLayout(hlayout1)
Tom Pillot's avatar
Tom Pillot committed
38

39
        with open("game/qss/time_widget.qss", "r") as f:
Tom Pillot's avatar
Tom Pillot committed
40
            self.time_widget.setStyleSheet(f.read())
41

42
43
44
        self.list_widget = qtw.QListWidget()
        self.list_widget.setDisabled(True)

45
        with open("game/qss/list_widget.qss", "r") as f:
46
47
            self.list_widget.setStyleSheet(f.read())

48
        self.webcam_label = qtw.QLabel()
49
        self.webcam_timer = qtc.QTimer()
50
51
52
53
54
55

        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"))

Tom Pillot's avatar
Tom Pillot committed
56
        # Hide vertical headers and set height for the rows
57
        self.table_widget.verticalHeader().setVisible(False)
Tom Pillot's avatar
Tom Pillot committed
58
59
60
61
62
        self.table_widget.verticalHeader().setSectionResizeMode(qtw.QHeaderView.Fixed)
        self.table_widget.verticalHeader().setDefaultSectionSize(75)

        # Prevent user from selecting and modifying the cells
        self.table_widget.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
Tom Pillot's avatar
Tom Pillot committed
63
64
        self.table_widget.setFocusPolicy(qtc.Qt.NoFocus)
        self.table_widget.setSelectionMode(qtw.QAbstractItemView.NoSelection)
65

66
        with open("game/qss/table_widget.qss", "r") as f:
67
            self.setStyleSheet(f.read())
Tom Pillot's avatar
Tom Pillot committed
68
69
70

        self.timer = qtc.QTimer(self)

71
        vlayout1 = qtw.QVBoxLayout()
72
        vlayout1.addWidget(self.list_widget)
73
74
        vlayout1.addWidget(self.webcam_label)

75
76
77
        hlayout2 = qtw.QHBoxLayout()
        hlayout2.addWidget(self.table_widget, stretch=True)
        hlayout2.addLayout(vlayout1)
78
79

        vlayout2 = qtw.QVBoxLayout()
Tom Pillot's avatar
Tom Pillot committed
80
        vlayout2.addWidget(self.time_widget, alignment=qtc.Qt.AlignCenter)
81
        vlayout2.addLayout(hlayout2)
82
83
84
        widget.setLayout(vlayout2)

    def resizeEvent(self, a0):
85
        super().resizeEvent(a0)
86
87
88
        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))
89
        self.time_edit.setFixedWidth(self.table_widget.width())