Browse Source

Add Onboard support, fullscreen, text with buttons

- Add dbus-python dependency in 'osk' extra
- If dbus is present, attempt to connect to Onboard
- If Onboard is present, show it before asking for a new person's name,
    and hide after entering it.
- Go fullscreen when the client starts
- Show text under the toolbar buttons, make icons smaller.
Maarten van den Berg 6 years ago
parent
commit
d8aa04e5e4
2 changed files with 40 additions and 3 deletions
  1. 37 3
      piket_client/gui.py
  2. 3 0
      setup.py

+ 37 - 3
piket_client/gui.py

17
     QWidget,
17
     QWidget,
18
 )
18
 )
19
 from PySide2.QtGui import QIcon
19
 from PySide2.QtGui import QIcon
20
-from PySide2.QtCore import QSize
20
+from PySide2.QtCore import QSize, Qt
21
 
21
 
22
 # pylint: enable=E0611
22
 # pylint: enable=E0611
23
 import requests
23
 import requests
24
 
24
 
25
+try:
26
+    import dbus
27
+except ImportError:
28
+    dbus = None
29
+
25
 from piket_client.sound import PLOP_WAVE
30
 from piket_client.sound import PLOP_WAVE
26
 
31
 
27
 
32
 
103
 
108
 
104
         self.main_widget = None
109
         self.main_widget = None
105
         self.toolbar = None
110
         self.toolbar = None
111
+        self.osk = None
106
         self.init_ui()
112
         self.init_ui()
107
 
113
 
108
     def init_ui(self) -> None:
114
     def init_ui(self) -> None:
109
         """ Initialize the UI: construct main widget and toolbar. """
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
         self.main_widget = NameButtons()
131
         self.main_widget = NameButtons()
111
         self.setCentralWidget(self.main_widget)
132
         self.setCentralWidget(self.main_widget)
112
 
133
 
113
         font_metrics = self.fontMetrics()
134
         font_metrics = self.fontMetrics()
114
-        icon_size = font_metrics.height() * 2.5
135
+        icon_size = font_metrics.height() * 2
115
 
136
 
116
         # Initialize toolbar
137
         # Initialize toolbar
117
         self.toolbar = QToolBar()
138
         self.toolbar = QToolBar()
139
+        self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
118
         self.toolbar.setIconSize(QSize(icon_size, icon_size))
140
         self.toolbar.setIconSize(QSize(icon_size, icon_size))
119
 
141
 
120
         # Left
142
         # Left
121
         self.toolbar.addAction(
143
         self.toolbar.addAction(
122
             self.load_icon("add_person.svg"), "Nieuw persoon", self.add_person
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
         self.toolbar.addWidget(self.create_spacer())
148
         self.toolbar.addWidget(self.create_spacer())
127
 
149
 
129
         self.toolbar.addAction(self.load_icon("beer_bottle.svg"), "Bierrr")
151
         self.toolbar.addAction(self.load_icon("beer_bottle.svg"), "Bierrr")
130
         self.addToolBar(self.toolbar)
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
     def add_person(self) -> None:
164
     def add_person(self) -> None:
133
         """ Ask for a new Person and register it, then rebuild the central
165
         """ Ask for a new Person and register it, then rebuild the central
134
         widget. """
166
         widget. """
167
+        self.show_keyboard()
135
         name, ok = QInputDialog.getItem(
168
         name, ok = QInputDialog.getItem(
136
             self,
169
             self,
137
             "Persoon toevoegen",
170
             "Persoon toevoegen",
140
             0,
173
             0,
141
             True,
174
             True,
142
         )
175
         )
176
+        self.hide_keyboard()
143
         if ok and name:
177
         if ok and name:
144
             req = requests.post(
178
             req = requests.post(
145
                 urljoin(SERVER_URL, "people"), json={"person": {"name": name}}
179
                 urljoin(SERVER_URL, "people"), json={"person": {"name": name}}

+ 3 - 0
setup.py

37
                 'simpleaudio',
37
                 'simpleaudio',
38
                 'requests',
38
                 'requests',
39
             ],
39
             ],
40
+            'osk': [
41
+                'dbus-python',
42
+            ],
40
         },
43
         },
41
 
44
 
42
         include_package_data=True,
45
         include_package_data=True,