Browse Source

Update set_active to new client model

Maarten van den Berg 5 years ago
parent
commit
170e9698f9
1 changed files with 13 additions and 14 deletions
  1. 13 14
      piket_client/set_active.py

+ 13 - 14
piket_client/set_active.py

2
 Provides a helper tool to (de-)activate multiple people at once.
2
 Provides a helper tool to (de-)activate multiple people at once.
3
 """
3
 """
4
 
4
 
5
+import math
5
 import sys
6
 import sys
6
 
7
 
7
 # pylint: disable=E0611
8
 # pylint: disable=E0611
9
+import qdarkstyle
10
+from PySide2.QtCore import QObject, QSize, Qt, Signal, Slot
11
+from PySide2.QtGui import QIcon
8
 from PySide2.QtWidgets import (
12
 from PySide2.QtWidgets import (
9
     QAction,
13
     QAction,
10
     QActionGroup,
14
     QActionGroup,
19
     QToolBar,
23
     QToolBar,
20
     QWidget,
24
     QWidget,
21
 )
25
 )
22
-from PySide2.QtGui import QIcon
23
-from PySide2.QtCore import QObject, QSize, Qt, Signal, Slot
24
 
26
 
25
-# pylint: enable=E0611
27
+from piket_client.model import NetworkError, Person, ServerStatus
26
 
28
 
27
-import qdarkstyle
28
-
29
-from piket_client.model import Person, ServerStatus
29
+# pylint: enable=E0611
30
 
30
 
31
 
31
 
32
 class ActivationButton(QPushButton):
32
 class ActivationButton(QPushButton):
55
 
55
 
56
     def init_ui(self) -> None:
56
     def init_ui(self) -> None:
57
         ps = Person.get_all()
57
         ps = Person.get_all()
58
-        num_columns = round(len(ps) / 10) + 1
58
+        assert not isinstance(ps, NetworkError)
59
+        num_columns = math.ceil(math.sqrt(len(ps)))
59
 
60
 
60
         for index, person in enumerate(ps):
61
         for index, person in enumerate(ps):
61
             button = ActivationButton(person, self)
62
             button = ActivationButton(person, self)
66
     def __init__(self) -> None:
67
     def __init__(self) -> None:
67
         super().__init__()
68
         super().__init__()
68
 
69
 
69
-        self.toolbar = None
70
+        self.toolbar = QToolBar()
70
 
71
 
71
         self.init_ui()
72
         self.init_ui()
72
 
73
 
79
         icon_size = font_metrics.height() * 1.45
80
         icon_size = font_metrics.height() * 1.45
80
 
81
 
81
         # Toolbar
82
         # Toolbar
82
-        self.toolbar = QToolBar()
83
         self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
83
         self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
84
         self.toolbar.setIconSize(QSize(icon_size, icon_size))
84
         self.toolbar.setIconSize(QSize(icon_size, icon_size))
85
 
85
 
112
     app.setFont(font)
112
     app.setFont(font)
113
 
113
 
114
     # Test connectivity
114
     # Test connectivity
115
-    server_running, info = ServerStatus.is_server_running()
115
+    server_running = ServerStatus.is_server_running()
116
 
116
 
117
-    if not server_running:
118
-        LOG.critical("Could not connect to server", extra={"info": info})
117
+    if not isinstance(server_running, bool):
119
         QMessageBox.critical(
118
         QMessageBox.critical(
120
             None,
119
             None,
121
             "Help er is iets kapot",
120
             "Help er is iets kapot",
122
             "Kan niet starten omdat de server niet reageert, stuur een foto van "
121
             "Kan niet starten omdat de server niet reageert, stuur een foto van "
123
-            "dit naar Maarten: " + repr(info),
122
+            "dit naar Maarten: " + repr(server_running.value),
124
         )
123
         )
125
-        return 1
124
+        return
126
 
125
 
127
     # Load main window
126
     # Load main window
128
     main_window = ActiveStateMainWindow()
127
     main_window = ActiveStateMainWindow()