|
@@ -17,11 +17,16 @@ from PySide2.QtWidgets import (
|
17
|
17
|
QWidget,
|
18
|
18
|
)
|
19
|
19
|
from PySide2.QtGui import QIcon
|
20
|
|
-from PySide2.QtCore import QSize
|
|
20
|
+from PySide2.QtCore import QSize, Qt
|
21
|
21
|
|
22
|
22
|
# pylint: enable=E0611
|
23
|
23
|
import requests
|
24
|
24
|
|
|
25
|
+try:
|
|
26
|
+ import dbus
|
|
27
|
+except ImportError:
|
|
28
|
+ dbus = None
|
|
29
|
+
|
25
|
30
|
from piket_client.sound import PLOP_WAVE
|
26
|
31
|
|
27
|
32
|
|
|
@@ -103,25 +108,42 @@ class PiketMainWindow(QMainWindow):
|
103
|
108
|
|
104
|
109
|
self.main_widget = None
|
105
|
110
|
self.toolbar = None
|
|
111
|
+ self.osk = None
|
106
|
112
|
self.init_ui()
|
107
|
113
|
|
108
|
114
|
def init_ui(self) -> None:
|
109
|
115
|
""" Initialize the UI: construct main widget and toolbar. """
|
|
116
|
+
|
|
117
|
+ # Connect to dbus, get handle to virtual keyboard
|
|
118
|
+ if dbus:
|
|
119
|
+ try:
|
|
120
|
+ session_bus = dbus.SessionBus()
|
|
121
|
+ self.osk = session_bus.get_object('org.onboard.Onboard',
|
|
122
|
+ '/org/onboard/Onboard/Keyboard')
|
|
123
|
+ except dbus.exceptions.DBusException:
|
|
124
|
+ # Onboard not present or dbus broken
|
|
125
|
+ self.osk = None
|
|
126
|
+
|
|
127
|
+ # Go full screen
|
|
128
|
+ self.setWindowState(Qt.WindowActive | Qt.WindowFullScreen)
|
|
129
|
+
|
|
130
|
+ # Initialize main widget
|
110
|
131
|
self.main_widget = NameButtons()
|
111
|
132
|
self.setCentralWidget(self.main_widget)
|
112
|
133
|
|
113
|
134
|
font_metrics = self.fontMetrics()
|
114
|
|
- icon_size = font_metrics.height() * 2.5
|
|
135
|
+ icon_size = font_metrics.height() * 2
|
115
|
136
|
|
116
|
137
|
# Initialize toolbar
|
117
|
138
|
self.toolbar = QToolBar()
|
|
139
|
+ self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
|
118
|
140
|
self.toolbar.setIconSize(QSize(icon_size, icon_size))
|
119
|
141
|
|
120
|
142
|
# Left
|
121
|
143
|
self.toolbar.addAction(
|
122
|
144
|
self.load_icon("add_person.svg"), "Nieuw persoon", self.add_person
|
123
|
145
|
)
|
124
|
|
- self.toolbar.addAction(self.load_icon("undo.svg"), "Heydrich")
|
|
146
|
+ self.toolbar.addAction(self.load_icon("undo.svg"), "Oeps")
|
125
|
147
|
|
126
|
148
|
self.toolbar.addWidget(self.create_spacer())
|
127
|
149
|
|
|
@@ -129,9 +151,20 @@ class PiketMainWindow(QMainWindow):
|
129
|
151
|
self.toolbar.addAction(self.load_icon("beer_bottle.svg"), "Bierrr")
|
130
|
152
|
self.addToolBar(self.toolbar)
|
131
|
153
|
|
|
154
|
+ def show_keyboard(self) -> None:
|
|
155
|
+ ''' Show the virtual keyboard, if possible. '''
|
|
156
|
+ if self.osk:
|
|
157
|
+ self.osk.Show()
|
|
158
|
+
|
|
159
|
+ def hide_keyboard(self) -> None:
|
|
160
|
+ ''' Hide the virtual keyboard, if possible. '''
|
|
161
|
+ if self.osk:
|
|
162
|
+ self.osk.Hide()
|
|
163
|
+
|
132
|
164
|
def add_person(self) -> None:
|
133
|
165
|
""" Ask for a new Person and register it, then rebuild the central
|
134
|
166
|
widget. """
|
|
167
|
+ self.show_keyboard()
|
135
|
168
|
name, ok = QInputDialog.getItem(
|
136
|
169
|
self,
|
137
|
170
|
"Persoon toevoegen",
|
|
@@ -140,6 +173,7 @@ class PiketMainWindow(QMainWindow):
|
140
|
173
|
0,
|
141
|
174
|
True,
|
142
|
175
|
)
|
|
176
|
+ self.hide_keyboard()
|
143
|
177
|
if ok and name:
|
144
|
178
|
req = requests.post(
|
145
|
179
|
urljoin(SERVER_URL, "people"), json={"person": {"name": name}}
|