|
@@ -7,6 +7,7 @@ import os
|
7
|
7
|
import sys
|
8
|
8
|
|
9
|
9
|
import qdarkstyle
|
|
10
|
+
|
10
|
11
|
# pylint: disable=E0611
|
11
|
12
|
from PySide2.QtWidgets import (
|
12
|
13
|
QAction,
|
|
@@ -32,7 +33,7 @@ except ImportError:
|
32
|
33
|
dbus = None
|
33
|
34
|
|
34
|
35
|
from piket_client.sound import PLOP_WAVE, UNDO_WAVE
|
35
|
|
-from piket_client.model import Person, ConsumptionType, Consumption
|
|
36
|
+from piket_client.model import Person, ConsumptionType, Consumption, ServerStatus
|
36
|
37
|
import piket_client.logger
|
37
|
38
|
|
38
|
39
|
LOG = logging.getLogger(__name__)
|
|
@@ -60,7 +61,6 @@ class NameButton(QPushButton):
|
60
|
61
|
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
61
|
62
|
self.customContextMenuRequested.connect(self.confirm_hide)
|
62
|
63
|
|
63
|
|
-
|
64
|
64
|
@Slot(str)
|
65
|
65
|
def new_active_id(self, new_id: str) -> None:
|
66
|
66
|
""" Change the active ConsumptionType id, update the label. """
|
|
@@ -97,14 +97,14 @@ class NameButton(QPushButton):
|
97
|
97
|
def confirm_hide(self) -> None:
|
98
|
98
|
ok = QMessageBox.warning(
|
99
|
99
|
self.window(),
|
100
|
|
- 'Persoon verbergen?',
|
101
|
|
- f'Wil je {self.person.name} verbergen?',
|
|
100
|
+ "Persoon verbergen?",
|
|
101
|
+ f"Wil je {self.person.name} verbergen?",
|
102
|
102
|
QMessageBox.Yes,
|
103
|
103
|
QMessageBox.Cancel,
|
104
|
104
|
)
|
105
|
105
|
|
106
|
106
|
if ok == QMessageBox.Yes:
|
107
|
|
- LOG.warning('Hiding person %s', self.person.name)
|
|
107
|
+ LOG.warning("Hiding person %s", self.person.name)
|
108
|
108
|
self.person.set_active(False)
|
109
|
109
|
self.parent().init_ui()
|
110
|
110
|
|
|
@@ -131,7 +131,6 @@ class NameButtons(QWidget):
|
131
|
131
|
self.active_consumption_type_id = new_id
|
132
|
132
|
self.new_id_set.emit(new_id)
|
133
|
133
|
|
134
|
|
-
|
135
|
134
|
def init_ui(self) -> None:
|
136
|
135
|
""" Initialize UI: build GridLayout, retrieve People and build a button
|
137
|
136
|
for each. """
|
|
@@ -183,9 +182,13 @@ class PiketMainWindow(QMainWindow):
|
183
|
182
|
self.osk = session_bus.get_object(
|
184
|
183
|
"org.onboard.Onboard", "/org/onboard/Onboard/Keyboard"
|
185
|
184
|
)
|
186
|
|
- except dbus.exceptions.DBusException:
|
|
185
|
+ except dbus.exceptions.DBusException as exception:
|
187
|
186
|
# Onboard not present or dbus broken
|
188
|
187
|
self.osk = None
|
|
188
|
+ LOG.error("Could not connect to Onboard:")
|
|
189
|
+ LOG.exception(exception)
|
|
190
|
+ else:
|
|
191
|
+ LOG.warning("Onboard disabled due to missing dbus.")
|
189
|
192
|
|
190
|
193
|
# Go full screen
|
191
|
194
|
self.setWindowState(Qt.WindowActive | Qt.WindowFullScreen)
|
|
@@ -215,8 +218,10 @@ class PiketMainWindow(QMainWindow):
|
215
|
218
|
|
216
|
219
|
# Right
|
217
|
220
|
self.toolbar.addAction(
|
218
|
|
- self.load_icon("add_consumption_type.svg"), "Nieuw",
|
219
|
|
- self.add_consumption_type)
|
|
221
|
+ self.load_icon("add_consumption_type.svg"),
|
|
222
|
+ "Nieuw",
|
|
223
|
+ self.add_consumption_type,
|
|
224
|
+ )
|
220
|
225
|
self.toolbar.setContextMenuPolicy(Qt.PreventContextMenu)
|
221
|
226
|
self.toolbar.setFloatable(False)
|
222
|
227
|
self.toolbar.setMovable(False)
|
|
@@ -257,8 +262,9 @@ class PiketMainWindow(QMainWindow):
|
257
|
262
|
sys.exit()
|
258
|
263
|
|
259
|
264
|
for ct in cts:
|
260
|
|
- action = QAction(self.load_icon(ct.icon or "beer_bottle.svg"),
|
261
|
|
- ct.name, self.ct_ag)
|
|
265
|
+ action = QAction(
|
|
266
|
+ self.load_icon(ct.icon or "beer_bottle.svg"), ct.name, self.ct_ag
|
|
267
|
+ )
|
262
|
268
|
action.setCheckable(True)
|
263
|
269
|
action.setData(str(ct.consumption_type_id))
|
264
|
270
|
|
|
@@ -319,10 +325,7 @@ class PiketMainWindow(QMainWindow):
|
319
|
325
|
def add_consumption_type(self) -> None:
|
320
|
326
|
self.show_keyboard()
|
321
|
327
|
name, ok = QInputDialog.getItem(
|
322
|
|
- self,
|
323
|
|
- "Lijst toevoegen",
|
324
|
|
- "Wat wil je strepen?",
|
325
|
|
- ["Wijn", "Radler"]
|
|
328
|
+ self, "Lijst toevoegen", "Wat wil je strepen?", ["Wijn", "Radler"]
|
326
|
329
|
)
|
327
|
330
|
self.hide_keyboard()
|
328
|
331
|
|
|
@@ -331,9 +334,7 @@ class PiketMainWindow(QMainWindow):
|
331
|
334
|
ct = ct.create()
|
332
|
335
|
|
333
|
336
|
action = QAction(
|
334
|
|
- self.load_icon(ct.icon or "beer_bottle.svg"),
|
335
|
|
- ct.name,
|
336
|
|
- self.ct_ag
|
|
337
|
+ self.load_icon(ct.icon or "beer_bottle.svg"), ct.name, self.ct_ag
|
337
|
338
|
)
|
338
|
339
|
action.setCheckable(True)
|
339
|
340
|
action.setData(str(ct.consumption_type_id))
|
|
@@ -379,7 +380,6 @@ class PiketMainWindow(QMainWindow):
|
379
|
380
|
self.undo_queue.append(consumption)
|
380
|
381
|
self.undo_action.setDisabled(False)
|
381
|
382
|
|
382
|
|
-
|
383
|
383
|
@staticmethod
|
384
|
384
|
def create_spacer() -> QWidget:
|
385
|
385
|
""" Return an empty QWidget that automatically expands. """
|
|
@@ -394,7 +394,7 @@ class PiketMainWindow(QMainWindow):
|
394
|
394
|
directory. """
|
395
|
395
|
|
396
|
396
|
if self.dark_theme:
|
397
|
|
- filename = 'white_' + filename
|
|
397
|
+ filename = "white_" + filename
|
398
|
398
|
|
399
|
399
|
icon = QIcon(os.path.join(self.icons_dir, filename))
|
400
|
400
|
return icon
|
|
@@ -402,16 +402,37 @@ class PiketMainWindow(QMainWindow):
|
402
|
402
|
|
403
|
403
|
def main() -> None:
|
404
|
404
|
""" Main entry point of GUI client. """
|
|
405
|
+ LOG.info("Loading piket_client")
|
405
|
406
|
app = QApplication(sys.argv)
|
|
407
|
+
|
|
408
|
+ # Set dark theme
|
406
|
409
|
app.setStyleSheet(qdarkstyle.load_stylesheet_pyside2())
|
|
410
|
+
|
|
411
|
+ # Enlarge font size
|
407
|
412
|
font = app.font()
|
408
|
413
|
size = font.pointSize()
|
409
|
414
|
font.setPointSize(size * 1.5)
|
410
|
415
|
app.setFont(font)
|
411
|
416
|
|
|
417
|
+ # Test connectivity
|
|
418
|
+ server_running, info = ServerStatus.is_server_running()
|
|
419
|
+
|
|
420
|
+ if not server_running:
|
|
421
|
+ LOG.critical("Could not connect to server", extra={"info": info})
|
|
422
|
+ QMessageBox.critical(
|
|
423
|
+ None,
|
|
424
|
+ "Help er is iets kapot",
|
|
425
|
+ "Kan niet starten omdat de server niet reageert, stuur een foto van "
|
|
426
|
+ "dit naar Maarten: " + repr(info),
|
|
427
|
+ )
|
|
428
|
+ return 1
|
|
429
|
+
|
|
430
|
+ # Load main window
|
412
|
431
|
main_window = PiketMainWindow()
|
413
|
432
|
main_window.show()
|
414
|
433
|
|
|
434
|
+ # Let's go
|
|
435
|
+ LOG.info("Starting QT event loop.")
|
415
|
436
|
app.exec_()
|
416
|
437
|
|
417
|
438
|
|