|
@@ -6,6 +6,8 @@ import sys
|
6
|
6
|
|
7
|
7
|
# pylint: disable=E0611
|
8
|
8
|
from PySide2.QtWidgets import (
|
|
9
|
+ QAction,
|
|
10
|
+ QActionGroup,
|
9
|
11
|
QApplication,
|
10
|
12
|
QGridLayout,
|
11
|
13
|
QInputDialog,
|
|
@@ -16,7 +18,7 @@ from PySide2.QtWidgets import (
|
16
|
18
|
QWidget,
|
17
|
19
|
)
|
18
|
20
|
from PySide2.QtGui import QIcon
|
19
|
|
-from PySide2.QtCore import QSize, Qt
|
|
21
|
+from PySide2.QtCore import QSize, Qt, QObject, Signal, Slot
|
20
|
22
|
|
21
|
23
|
# pylint: enable=E0611
|
22
|
24
|
|
|
@@ -26,7 +28,7 @@ except ImportError:
|
26
|
28
|
dbus = None
|
27
|
29
|
|
28
|
30
|
from piket_client.sound import PLOP_WAVE
|
29
|
|
-from piket_client.model import Person
|
|
31
|
+from piket_client.model import Person, ConsumptionType
|
30
|
32
|
|
31
|
33
|
|
32
|
34
|
def plop() -> None:
|
|
@@ -37,24 +39,36 @@ def plop() -> None:
|
37
|
39
|
class NameButton(QPushButton):
|
38
|
40
|
""" Wraps a QPushButton to provide a counter. """
|
39
|
41
|
|
40
|
|
- def __init__(self, person: Person, *args, **kwargs) -> None:
|
|
42
|
+ def __init__(self, person: Person, active_id: str, *args, **kwargs) -> None:
|
41
|
43
|
self.person = person
|
42
|
|
- self.count = person.consumptions["1"]
|
|
44
|
+ self.active_id = active_id
|
43
|
45
|
|
44
|
46
|
super().__init__(self.current_label, *args, **kwargs)
|
45
|
47
|
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
46
|
48
|
|
47
|
49
|
self.clicked.connect(self.process_click)
|
48
|
50
|
|
|
51
|
+ @Slot(str)
|
|
52
|
+ def new_active_id(self, new_id: str):
|
|
53
|
+ self.active_id = new_id
|
|
54
|
+ self.setText(self.current_label)
|
|
55
|
+
|
|
56
|
+ @property
|
|
57
|
+ def active_consumption_type_id(self) -> str:
|
|
58
|
+ return self.parent().active_consumption_type_id
|
|
59
|
+
|
|
60
|
+ @property
|
|
61
|
+ def current_count(self) -> int:
|
|
62
|
+ return self.person.consumptions.get(self.active_id, 0)
|
|
63
|
+
|
49
|
64
|
@property
|
50
|
65
|
def current_label(self) -> str:
|
51
|
66
|
""" Return the label to show on the button. """
|
52
|
|
- return f"{self.person.name} ({self.count})"
|
|
67
|
+ return f"{self.person.name} ({self.current_count})"
|
53
|
68
|
|
54
|
69
|
def process_click(self) -> None:
|
55
|
70
|
""" Process a click on this button. """
|
56
|
|
- if self.person.add_consumption():
|
57
|
|
- self.count = self.person.consumptions["1"]
|
|
71
|
+ if self.person.add_consumption(self.active_id):
|
58
|
72
|
self.setText(self.current_label)
|
59
|
73
|
plop()
|
60
|
74
|
else:
|
|
@@ -65,19 +79,28 @@ class NameButtons(QWidget):
|
65
|
79
|
""" Main widget responsible for capturing presses and registering them.
|
66
|
80
|
"""
|
67
|
81
|
|
68
|
|
- def __init__(self) -> None:
|
|
82
|
+ new_id_set = Signal(str)
|
|
83
|
+
|
|
84
|
+ def __init__(self, consumption_type_id) -> None:
|
69
|
85
|
super().__init__()
|
70
|
86
|
|
71
|
87
|
self.layout = None
|
|
88
|
+ self.active_consumption_type_id = consumption_type_id
|
72
|
89
|
self.init_ui()
|
73
|
90
|
|
|
91
|
+ @Slot(str)
|
|
92
|
+ def consumption_type_changed(self, new_id: str):
|
|
93
|
+ self.active_consumption_type_id = new_id
|
|
94
|
+ self.new_id_set.emit(new_id)
|
|
95
|
+
|
74
|
96
|
def init_ui(self) -> None:
|
75
|
97
|
""" Initialize UI: build GridLayout, retrieve People and build a button
|
76
|
98
|
for each. """
|
77
|
99
|
self.layout = QGridLayout()
|
78
|
100
|
|
79
|
101
|
for index, person in enumerate(Person.get_all()):
|
80
|
|
- button = NameButton(person)
|
|
102
|
+ button = NameButton(person, self.active_consumption_type_id, self)
|
|
103
|
+ self.new_id_set.connect(button.new_active_id)
|
81
|
104
|
self.layout.addWidget(button, index // 2, index % 2)
|
82
|
105
|
|
83
|
106
|
self.setLayout(self.layout)
|
|
@@ -87,6 +110,8 @@ class PiketMainWindow(QMainWindow):
|
87
|
110
|
""" QMainWindow subclass responsible for showing the main application
|
88
|
111
|
window. """
|
89
|
112
|
|
|
113
|
+ consumption_type_changed = Signal(str)
|
|
114
|
+
|
90
|
115
|
def __init__(self) -> None:
|
91
|
116
|
super().__init__()
|
92
|
117
|
|
|
@@ -111,10 +136,6 @@ class PiketMainWindow(QMainWindow):
|
111
|
136
|
# Go full screen
|
112
|
137
|
self.setWindowState(Qt.WindowActive | Qt.WindowFullScreen)
|
113
|
138
|
|
114
|
|
- # Initialize main widget
|
115
|
|
- self.main_widget = NameButtons()
|
116
|
|
- self.setCentralWidget(self.main_widget)
|
117
|
|
-
|
118
|
139
|
font_metrics = self.fontMetrics()
|
119
|
140
|
icon_size = font_metrics.height() * 2
|
120
|
141
|
|
|
@@ -132,9 +153,34 @@ class PiketMainWindow(QMainWindow):
|
132
|
153
|
self.toolbar.addWidget(self.create_spacer())
|
133
|
154
|
|
134
|
155
|
# Right
|
135
|
|
- self.toolbar.addAction(self.load_icon("beer_bottle.svg"), "Bierrr")
|
|
156
|
+ ag = QActionGroup(self.toolbar)
|
|
157
|
+ ag.setExclusive(True)
|
|
158
|
+
|
|
159
|
+ for ct in ConsumptionType.get_all():
|
|
160
|
+ action = QAction(
|
|
161
|
+ self.load_icon(ct.icon or 'beer_bottle.svg'),
|
|
162
|
+ ct.name,
|
|
163
|
+ ag
|
|
164
|
+ )
|
|
165
|
+ action.setCheckable(True)
|
|
166
|
+ action.setData(str(ct.consumption_type_id))
|
|
167
|
+
|
|
168
|
+ ag.actions()[0].setChecked(True)
|
|
169
|
+ [self.toolbar.addAction(a) for a in ag.actions()]
|
|
170
|
+ ag.triggered.connect(self.consumption_type_change)
|
|
171
|
+
|
136
|
172
|
self.addToolBar(self.toolbar)
|
137
|
173
|
|
|
174
|
+ # Initialize main widget
|
|
175
|
+ self.main_widget = NameButtons(ag.actions()[0].data())
|
|
176
|
+ self.consumption_type_changed.connect(self.main_widget.consumption_type_changed)
|
|
177
|
+ self.setCentralWidget(self.main_widget)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+ @Slot(QAction)
|
|
181
|
+ def consumption_type_change(self, action: QAction):
|
|
182
|
+ self.consumption_type_changed.emit(action.data())
|
|
183
|
+
|
138
|
184
|
def show_keyboard(self) -> None:
|
139
|
185
|
''' Show the virtual keyboard, if possible. '''
|
140
|
186
|
if self.osk:
|