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


Tom Pillot's avatar
Tom Pillot committed
7
class ScoreWindow(ScoreWindowUi):
Tom Pillot's avatar
Tom Pillot committed
8
    def __init__(self, teams):
Tom Pillot's avatar
Tom Pillot committed
9
10
        super().__init__()

Tom Pillot's avatar
Tom Pillot committed
11
12
        self.teams = teams
        self.time_is_red = False
Tom Pillot's avatar
Tom Pillot committed
13

Tom Pillot's avatar
Tom Pillot committed
14
15
    def timer_start(self, time):
        self.time_edit.setTime(time)
Tom Pillot's avatar
Tom Pillot committed
16
17
18
19
20
        self.timer.timeout.connect(self.timer_timeout)
        self.timer.start(1000)
        self.update_gui()

    def timer_timeout(self):
Tom Pillot's avatar
Tom Pillot committed
21
22
23
24
25
26
27
28
29
30
        self.timer.start(1000)
        if self.time_edit.time() == qtc.QTime(0, 0, 0, 0):
            if self.time_is_red:
                self.time_edit.setStyleSheet("color: black")
                self.time_is_red = False
            else:
                self.time_edit.setStyleSheet("color: red")
                self.time_is_red = True
        else:
            self.update_gui()
Tom Pillot's avatar
Tom Pillot committed
31
32

    def update_gui(self):
Tom Pillot's avatar
Tom Pillot committed
33
34
        self.time_edit.setTime(self.time_edit.time().addSecs(-1))

35
36
37
    def add_teams(self):
        self.table_widget.setRowCount(len(self.teams))
        i = 0
Tom Pillot's avatar
Tom Pillot committed
38
        for team in self.teams.values():
39
40
41
42
43
44
45
46
47
48
            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()