From 21e7f68235da66e072bc58e8ac92603dbf258d20 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 26 Feb 2017 14:45:14 +0100 Subject: [PATCH] clean up code/ dont crash if keyboard unplugs --- src/fenrir/core/generalInformation.py | 2 ++ src/fenrir/fenrir.py | 34 ++++----------------------- src/fenrir/inputDriver/evdevDriver.py | 7 +++++- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/fenrir/core/generalInformation.py b/src/fenrir/core/generalInformation.py index ab90a0bd..c3e5ce86 100644 --- a/src/fenrir/core/generalInformation.py +++ b/src/fenrir/core/generalInformation.py @@ -11,4 +11,6 @@ generalInformation = { 'tutorialMode': False, 'currUser':'', 'prevUser':'', +'managerList':['inputManager','screenManager','commandManager','outputManager' + ,'punctuationManager','cursorManager','applicationManager','debug'], } diff --git a/src/fenrir/fenrir.py b/src/fenrir/fenrir.py index 3ffd8d2f..ea248a8f 100644 --- a/src/fenrir/fenrir.py +++ b/src/fenrir/fenrir.py @@ -97,35 +97,11 @@ class fenrir(): self.shutdownRequest() def shutdown(self): - if self.environment['runtime']['inputManager']: - self.environment['runtime']['inputManager'].shutdown() - del self.environment['runtime']['inputManager'] - self.environment['runtime']['outputManager'].presentText("Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True) - time.sleep(0.9) # wait a little for sound - - if self.environment['runtime']['screenManager']: - self.environment['runtime']['screenManager'].shutdown() - del self.environment['runtime']['screenManager'] - if self.environment['runtime']['commandManager']: - self.environment['runtime']['commandManager'].shutdown() - del self.environment['runtime']['commandManager'] - if self.environment['runtime']['outputManager']: - self.environment['runtime']['outputManager'].shutdown() - del self.environment['runtime']['outputManager'] - if self.environment['runtime']['punctuationManager']: - self.environment['runtime']['punctuationManager'].shutdown() - del self.environment['runtime']['punctuationManager'] - if self.environment['runtime']['cursorManager']: - self.environment['runtime']['cursorManager'].shutdown() - del self.environment['runtime']['cursorManager'] - if self.environment['runtime']['applicationManager']: - self.environment['runtime']['applicationManager'].shutdown() - del self.environment['runtime']['applicationManager'] - - if self.environment['runtime']['debug']: - self.environment['runtime']['debug'].shutdown() - del self.environment['runtime']['debug'] - time.sleep(0.2) # wait a little before splatter it :) + self.environment['runtime']['outputManager'].presentText("Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True) + for currManager in self.environment['generalInformation']['managerList']: + if self.environment['runtime'][currManager]: + self.environment['runtime'][currManager].shutdown() + del self.environment['runtime'][currManager] self.environment = None def main(): diff --git a/src/fenrir/inputDriver/evdevDriver.py b/src/fenrir/inputDriver/evdevDriver.py index c185b6de..f7579e22 100644 --- a/src/fenrir/inputDriver/evdevDriver.py +++ b/src/fenrir/inputDriver/evdevDriver.py @@ -50,7 +50,12 @@ class driver(): r, w, x = select(self.iDevices, [], [], self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')) if r != []: for fd in r: - event = self.iDevices[fd].read_one() + try: + event = self.iDevices[fd].read_one() + except: + #print('jow') + del(self.iDevices[fd]) + return None foreward = False while(event): self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])