|
@@ -0,0 +1,77 @@
|
|
1
|
+"""
|
|
2
|
+Provides the graphical front-end for Piket.
|
|
3
|
+"""
|
|
4
|
+import sys
|
|
5
|
+
|
|
6
|
+from PySide2.QtWidgets import QApplication, QPushButton, QGridLayout, QWidget
|
|
7
|
+from PySide2.QtGui import QFont
|
|
8
|
+import requests
|
|
9
|
+
|
|
10
|
+from piket_client.sound import PLOP_WAVE
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+def plop() -> None:
|
|
14
|
+ """ Asynchronously play the plop sound. """
|
|
15
|
+ PLOP_WAVE.play()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+from piket_server import PEOPLE
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+FONT = QFont("Helvetica", 15)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+def get_names() -> {int: (str, int)}:
|
|
25
|
+ return PEOPLE
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+class NameButton(QPushButton):
|
|
29
|
+ """ Wraps a QPushButton to provide a counter. """
|
|
30
|
+
|
|
31
|
+ def __init__(self, name: str, count: int, *args, **kwargs) -> None:
|
|
32
|
+ self.name = name
|
|
33
|
+ self.count = count
|
|
34
|
+
|
|
35
|
+ super().__init__(self.current_label, *args, **kwargs)
|
|
36
|
+
|
|
37
|
+ self.clicked.connect(self.plop)
|
|
38
|
+
|
|
39
|
+ @property
|
|
40
|
+ def current_label(self) -> str:
|
|
41
|
+ return f"{self.name} ({self.count})"
|
|
42
|
+
|
|
43
|
+ def plop(self) -> None:
|
|
44
|
+ self.count += 1
|
|
45
|
+ plop()
|
|
46
|
+ self.setText(self.current_label)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+class NameButtons(QWidget):
|
|
50
|
+ def __init__(self) -> None:
|
|
51
|
+ super().__init__()
|
|
52
|
+
|
|
53
|
+ self.layout = None
|
|
54
|
+ self.init_ui()
|
|
55
|
+
|
|
56
|
+ def init_ui(self) -> None:
|
|
57
|
+ self.layout = QGridLayout()
|
|
58
|
+
|
|
59
|
+ for index, id in enumerate(PEOPLE):
|
|
60
|
+ person = PEOPLE[id]
|
|
61
|
+ button = NameButton(person["name"], person["count"])
|
|
62
|
+ self.layout.addWidget(button, index // 2, index % 2)
|
|
63
|
+
|
|
64
|
+ self.setLayout(self.layout)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+if __name__ == "__main__":
|
|
68
|
+ app = QApplication(sys.argv)
|
|
69
|
+ font = app.font()
|
|
70
|
+ size = font.pointSize()
|
|
71
|
+ font.setPointSize(size * 1.75)
|
|
72
|
+ app.setFont(font)
|
|
73
|
+
|
|
74
|
+ name_buttons = NameButtons()
|
|
75
|
+ name_buttons.show()
|
|
76
|
+
|
|
77
|
+ app.exec_()
|