-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathboard_view.py
75 lines (71 loc) · 3.01 KB
/
board_view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# category_view.py
#
# Category view for the stack window
from functools import partial
from PyQt6.QtWidgets import (
QWidget,
QLabel,
QPushButton,
QGridLayout,
QSizePolicy
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QFont
class BoardView(QWidget):
def __init__(self, parent, state):
super().__init__()
self.parent = parent
self.game_state = state
self.initUI()
def initUI(self):
self.layout = QGridLayout()
font = self.game_state.get_font("swiss911", 54)
round = self.game_state.get_round_data()
self.category_labels = [None] * len(round.categories)
for i, category in enumerate(round.categories):
p = (0, i)
cat_label = QLabel(category.title)
cat_label.setSizePolicy(QSizePolicy.Policy.Expanding,
QSizePolicy.Policy.Expanding)
cat_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
cat_label.setWordWrap(True)
cat_label.setFont(font)
cat_label.setStyleSheet("color: white;")
self.layout.addWidget(cat_label, *p)
self.category_labels[i] = cat_label
font.setLetterSpacing(QFont.SpacingType.AbsoluteSpacing, 4)
font.setPointSize(72)
font.setBold(True)
self.button_widgets = [[None
for j in range(len(round.categories[i].clues))]
for i in range(len(round.categories))]
for i, category in enumerate(round.categories):
for j, clue in enumerate(category.clues):
p = (j+1, i)
button = QPushButton(f"${clue.value}")
button.setFont(font)
button.setStyleSheet("color: #FFCC00;")
button.clicked.connect(
partial(self.parent.show_clue, i, j))
button.setSizePolicy(QSizePolicy.Policy.Expanding,
QSizePolicy.Policy.Expanding)
self.layout.addWidget(button, *p)
self.button_widgets[i][j] = button
self.setStyleSheet("background-color:#060CE9;")
self.setLayout(self.layout)
self.show()
def update(self):
round = self.game_state.get_round_data()
for i, category in enumerate(round.categories):
self.category_labels[i].setText(category.title)
for i, category in enumerate(round.categories):
for j, clue in enumerate(category.clues):
if clue.answered:
self.button_widgets[i][j].setEnabled(False)
self.button_widgets[i][j].setStyleSheet(
"background-color: #808080;")
else:
self.button_widgets[i][j].setText(f"${clue.value}")
self.button_widgets[i][j].setEnabled(True)
self.button_widgets[i][j].setStyleSheet(
"background-color: #060CE9; color: #FFCC00")