Skip to content

Commit 6800570

Browse files
committed
add on-screen keyboard for X11 and wayland
1 parent 6f36b9d commit 6800570

File tree

7 files changed

+81
-17
lines changed

7 files changed

+81
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ debian/*debhelper*
44
debian/files
55
debian/*.substvars
66
.pybuild/
7-
*/__pycache__/
7+
*/__pycache__/
8+
build/

bin/toggle-wvkbd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#This script toggle the virtual keyboard
3+
4+
PID="$(pidof wvkbd-mobintl)"
5+
if [ "$PID" != "" ]; then
6+
killall wvkbd-mobintl
7+
else
8+
wvkbd-mobintl
9+
# use wvkbd-mobintl --help for options
10+
#
11+
# -L 300 = landscape, 300 pixels tall
12+
# -fg ffffff = foreground color white
13+
# -fg-sp ffffff = special keys foreground white
14+
# -text 000000 = text color black
15+
# -text-sp 000000 = special keys text color black
16+
# -fn 40 = font size 40
17+
18+
fi

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ X-Python3-Version: >= 3.2
1010
Package: openplotter-settings
1111
Architecture: all
1212
Multi-Arch: foreign
13-
Depends: ${misc:Depends}, ${python3:Depends}, python3-wxgtk4.0, python3-ujson, python3-pyudev, vlc, matchbox-keyboard
13+
Depends: ${misc:Depends}, ${python3:Depends}, python3-wxgtk4.0, python3-ujson, python3-pyudev, vlc, matchbox-keyboard, wvkbd
1414
Description: Main OpenPlotter app
1515
Main OpenPlotter app

openplotterSettings/openplotterSettings.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ def pageGeneral(self):
218218
self.toolbar3.ToggleTool(303,True)
219219
self.Maximize()
220220

221+
out = subprocess.check_output('echo $XDG_SESSION_TYPE', shell=True).decode(sys.stdin.encoding)
222+
if 'wayland' in out: self.toolbar10.EnableTool(1001,False)
223+
221224
delay = self.conf.get('GENERAL', 'delay')
222225
if delay:
223226
self.delay.SetValue(delay)
@@ -242,7 +245,9 @@ def OnToolFile(self,e):
242245

243246
def OnToolMatchbox(self,e=0):
244247
subprocess.call(['pkill', '-f', 'matchbox-keyboard'])
245-
subprocess.Popen('matchbox-keyboard')
248+
out = subprocess.check_output('echo $XDG_SESSION_TYPE', shell=True).decode(sys.stdin.encoding)
249+
if 'wayland' in out: subprocess.Popen('toggle-wvkbd')
250+
else: subprocess.Popen('matchbox-keyboard')
246251

247252
def OnToolKeyboards(self,e=0):
248253
if self.keyboardsList.GetSelection() == -1: return
@@ -797,7 +802,7 @@ def OnToolWayland(self,e):
797802
msg += _('OpenPlotter will reboot. Are you sure?')
798803
dlg = wx.MessageDialog(None, msg, _('Question'), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_EXCLAMATION)
799804
if dlg.ShowModal() == wx.ID_YES:
800-
subprocess.call([self.platform.admin, 'raspi-config', 'nonint', 'do_wayland', 'W2'])
805+
subprocess.call([self.platform.admin, 'python3', self.currentdir+'/wayland.py', 'W2'])
801806
out = subprocess.check_output('raspi-config nonint get_vnc', shell=True).decode(sys.stdin.encoding)
802807
if '0' in out: self.conf.set('GENERAL', 'forceVNC', '1')
803808
os.system('shutdown -r now')
@@ -810,7 +815,7 @@ def OnToolWayland(self,e):
810815
msg += _('OpenPlotter will reboot. Are you sure?')
811816
dlg = wx.MessageDialog(None, msg, _('Question'), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_EXCLAMATION)
812817
if dlg.ShowModal() == wx.ID_YES:
813-
subprocess.call([self.platform.admin, 'raspi-config', 'nonint', 'do_wayland', 'W1'])
818+
subprocess.call([self.platform.admin, 'python3', self.currentdir+'/wayland.py', 'W1'])
814819
out = subprocess.check_output('raspi-config nonint get_vnc', shell=True).decode(sys.stdin.encoding)
815820
if '0' in out: self.conf.set('GENERAL', 'forceVNC', '1')
816821
os.system('shutdown -r now')

openplotterSettings/startup.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,20 @@ def starting(self):
249249
self.add_logger_data({'green':'','black':_('disabled'),'red':''})
250250
except Exception as e: self.add_logger_data({'green':'','black':'','red':str(e)})
251251

252-
self.add_logger_data(_('Checking virtual keyboard...'))
253-
currentKeyboard = self.conf.get('GENERAL', 'keyboard')
254-
if currentKeyboard: self.add_logger_data({'green':'','black':currentKeyboard,'red':''})
255-
else:
256-
try:
257-
folder = self.conf.home+'/.matchbox'
258-
if not os.path.exists(folder): os.mkdir(folder)
259-
os.system('cp -f '+self.currentdir+'/data/keyboards/keyboard-EN.xml '+folder+'/keyboard.xml')
260-
self.conf.set('GENERAL', 'keyboard', 'keyboard-EN.xml')
261-
self.add_logger_data({'green':'','black':'keyboard-EN.xml','red':''})
262-
except Exception as e:
263-
self.add_logger_data({'green':'','black':'','red':str(e)})
252+
out = subprocess.check_output('echo $XDG_SESSION_TYPE', shell=True).decode(sys.stdin.encoding)
253+
if not 'wayland' in out:
254+
self.add_logger_data(_('Checking virtual keyboard...'))
255+
currentKeyboard = self.conf.get('GENERAL', 'keyboard')
256+
if currentKeyboard: self.add_logger_data({'green':'','black':currentKeyboard,'red':''})
257+
else:
258+
try:
259+
folder = self.conf.home+'/.matchbox'
260+
if not os.path.exists(folder): os.mkdir(folder)
261+
os.system('cp -f '+self.currentdir+'/data/keyboards/keyboard-EN.xml '+folder+'/keyboard.xml')
262+
self.conf.set('GENERAL', 'keyboard', 'keyboard-EN.xml')
263+
self.add_logger_data({'green':'','black':'keyboard-EN.xml','red':''})
264+
except Exception as e:
265+
self.add_logger_data({'green':'','black':'','red':str(e)})
264266

265267
if self.isRPI:
266268
self.add_logger_data(_('Checking backlight...'))

openplotterSettings/wayland.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
# This file is part of OpenPlotter.
4+
# Copyright (C) 2023 by Sailoog <https://github.com/openplotter/openplotter-settings>
5+
#
6+
# Openplotter is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 2 of the License, or
9+
# any later version.
10+
# Openplotter is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
17+
18+
import subprocess, os, sys
19+
20+
subprocess.call(['raspi-config', 'nonint', 'do_wayland', sys.argv[1]])
21+
22+
if sys.argv[1] == 'W2': command = 'toggle-wvkbd'
23+
if sys.argv[1] == 'W1': command = 'matchbox-keyboard'
24+
25+
shortcut = '/usr/share/applications/inputmethods/matchbox-keyboard.desktop'
26+
if os.path.exists(shortcut):
27+
file = open(shortcut, 'r')
28+
file2 = ''
29+
while True:
30+
line = file.readline()
31+
if not line: break
32+
if 'Exec=' in line: file2 += 'Exec='+command+'\n'
33+
else: file2 += line
34+
file.close()
35+
file1 = open(shortcut, 'w')
36+
file1.write(file2)
37+
file1.close()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'Programming Language :: Python :: 3'],
3434
include_package_data=True,
3535
entry_points={'console_scripts': ['openplotter-settings=openplotterSettings.openplotterSettings:main','openplotter-startup=openplotterSettings.startup:main','openplotterPostInstall=openplotterSettings.postInstall:main','settingsPreUninstall=openplotterSettings.settingsPreUninstall:main','settingsSourcesInstall=openplotterSettings.installSources:main']},
36+
scripts=['bin/toggle-wvkbd'],
3637
data_files=[('share/applications', ['openplotterSettings/data/openplotter-settings.desktop','openplotterSettings/data/openplotter-check.desktop']),('share/pixmaps', ['openplotterSettings/data/openplotter-settings.png', 'openplotterSettings/data/openplotter-48.png', 'openplotterSettings/data/openplotter-check.png', 'openplotterSettings/data/brightness-48.png']),
3738
('share/sounds/openplotter', ['openplotterSettings/data/sounds/Bleep.mp3',
3839
'openplotterSettings/data/sounds/House_Fire_Alarm.mp3',

0 commit comments

Comments
 (0)