From ce4da1834fed382b484f2bd6b598c95b0b653e3b Mon Sep 17 00:00:00 2001 From: Chrys Date: Fri, 4 Oct 2019 17:33:48 +0200 Subject: [PATCH] improve error handling --- src/fenrirscreenreader/core/inputManager.py | 4 ++- .../inputDriver/evdevDriver.py | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index 0cd654d9..c70a57fa 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -62,9 +62,11 @@ class inputManager(): if self.env['runtime']['screenManager'].getCurrScreenIgnored(): if self.ungrabAllDevices(): self.executeDeviceGrab = False + print('ungrabbed') else: if self.grabAllDevices(): self.executeDeviceGrab = False + print('grabbed') def sendKeys(self, keyMacro): for e in keyMacro: key = '' @@ -183,7 +185,7 @@ class inputManager(): return '' eventName = eventName.upper() if eventName == 'KEY_LEFTCTRL': - eventName = 'KEY_CTRL' + eventName = 'KEY_CTRL' elif eventName == 'KEY_RIGHTCTRL': eventName = 'KEY_CTRL' elif eventName == 'KEY_LEFTSHIFT': diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index e095a59f..11c5cb43 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -230,7 +230,7 @@ class driver(inputDriver): self.iDevicesFD.append(fd) for fd in self.iDevicesFD: if not fd in self.iDevices: - self.iDevicesFD.remove(fd) + self.iDevicesFD.remove(fd) except: pass def mapEvent(self, event): @@ -321,9 +321,24 @@ class driver(inputDriver): return def addDevice(self, newDevice): self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: device added: ' + str(newDevice.fd) + ' ' +str(newDevice),debug.debugLevel.INFO) - self.iDevices[newDevice.fd] = newDevice - self.gDevices[newDevice.fd] = False - self.createUInputDev(newDevice.fd) + try: + self.iDevices[newDevice.fd] = newDevice + self.createUInputDev(newDevice.fd) + self.gDevices[newDevice.fd] = False + except: + # if it doesnt work clean up + try: + del(self.iDevices[newDevice.fd]) + except: + pass + try: + del(self.uDevices[newDevice.fd]) + except: + pass + try: + del(self.gDevices[newDevice.fd]) + except: + pass def grabDevice(self, fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): return True @@ -333,7 +348,7 @@ class driver(inputDriver): self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO) except IOError: self.gDevices[fd] = True - self.removeDevice(fd) + #self.removeDevice(fd) except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR) return False @@ -347,7 +362,7 @@ class driver(inputDriver): self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: ungrab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO) except IOError: self.gDevices[fd] = False - self.removeDevice(fd) + #self.removeDevice(fd) except Exception as e: return False return True