From 66be5935cfe7bcaa2a776af5ff7ee014125dd756 Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 12 Mar 2018 21:29:34 +0100 Subject: [PATCH 1/7] first transport of text using the eventloop --- src/fenrir/core/fenrirManager.py | 11 ++++---- src/fenrir/core/screenManager.py | 20 +++++++-------- src/fenrir/screenDriver/vcsaDriver.py | 37 +++++++++++++++------------ 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/fenrir/core/fenrirManager.py b/src/fenrir/core/fenrirManager.py index 31c2439e..92afa4f2 100644 --- a/src/fenrir/core/fenrirManager.py +++ b/src/fenrir/core/fenrirManager.py @@ -80,7 +80,6 @@ class fenrirManager(): self.singleKeyCommand = False if self.environment['input']['keyForeward'] > 0: self.environment['input']['keyForeward'] -=1 - self.environment['runtime']['screenManager'].update('onInput') self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput') #print('handleInput:',time.time() - startTime) def handleExecuteCommand(self, event): @@ -93,8 +92,8 @@ class fenrirManager(): self.environment['runtime']['commandManager'].executeCommand( command, 'help') return self.environment['runtime']['commandManager'].executeCommand( command, 'commands') - def handleScreenChange(self, event): - self.environment['runtime']['screenManager'].update('onScreenChange') + def handleScreenChange(self, event): + self.environment['runtime']['screenManager'].hanldeScreenChange(event['Data']) ''' if self.environment['runtime']['applicationManager'].isApplicationChange(): self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange') @@ -103,10 +102,10 @@ class fenrirManager(): self.environment['runtime']['applicationManager'].getCurrentApplication()) ''' self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged') - self.environment['runtime']['screenManager'].update('onScreenChange') + self.environment['runtime']['screenDriver'].getCurrScreen() def handleScreenUpdate(self, event): #startTime = time.time() - self.environment['runtime']['screenManager'].update('onUpdate') + self.environment['runtime']['screenManager'].handleScreenUpdate(event['Data']) ''' if self.environment['runtime']['applicationManager'].isApplicationChange(): self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange') @@ -120,7 +119,7 @@ class fenrirManager(): # has cursor changed? if self.environment['runtime']['cursorManager'].isCursorVerticalMove() or \ self.environment['runtime']['cursorManager'].isCursorHorizontalMove(): - self.environment['runtime']['commandManager'].executeDefaultTrigger('onCursorChange') + self.environment['runtime']['commandManager'].executeDefaultTrigger('onCursorChange') self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate') self.environment['runtime']['inputManager'].clearLastDeepInput() #print('handleScreenUpdate:',time.time() - startTime) diff --git a/src/fenrir/core/screenManager.py b/src/fenrir/core/screenManager.py index 29e45d67..e337d039 100644 --- a/src/fenrir/core/screenManager.py +++ b/src/fenrir/core/screenManager.py @@ -19,18 +19,18 @@ class screenManager(): def shutdown(self): self.env['runtime']['settingsManager'].shutdownDriver('screenDriver') - - def update(self, trigger='onUpdate'): - self.env['runtime']['screenDriver'].getCurrScreen() - - if trigger == 'onScreenChange': - self.env['runtime']['screenDriver'].getSessionInformation() - - self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] + def hanldeScreenChange(self, eventData): + self.env['runtime']['screenDriver'].getCurrScreen() + self.env['runtime']['screenDriver'].getSessionInformation() if self.isScreenChange(): - self.changeBrailleScreen() + self.changeBrailleScreen() if not self.isSuspendingScreen(self.env['screen']['newTTY']): - self.env['runtime']['screenDriver'].update(trigger) + self.env['runtime']['screenDriver'].update(eventData, 'onScreenChange') + self.env['screen']['lastScreenUpdate'] = time.time() + def handleScreenUpdate(self, eventData): + self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] + if not self.isSuspendingScreen(self.env['screen']['newTTY']): + self.env['runtime']['screenDriver'].update(eventData, 'onScreenUpdate') #if trigger == 'onUpdate' or self.isScreenChange() \ # or len(self.env['screen']['newDelta']) > 6: # self.env['runtime']['screenDriver'].getCurrApplication() diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index 93cad131..bf541b45 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -116,6 +116,21 @@ class driver(screenDriver): #self.env['runtime']['debug'].writeDebugOut('getSessionInformation:' + str(self.env['screen']['autoIgnoreScreens']) + ' ' + str(self.env['general']) ,debug.debugLevel.INFO) def updateWatchdog(self,active , eventQueue): + screenData = { + 'columns': 0, + 'lines': 0, + 'delta': '', + 'negativeDelta': '', + 'attribDelta': '', + 'cursorAttrib':None, + 'cursor':{'x':0,'y':0}, + 'Bytes': b'', + 'Text': '', + 'Attributes': None, + 'Scren':'0', + 'Application': '', + 'screenUpdateTime': time.time(), + } try: vcsa = {} vcsaDevices = glob.glob('/dev/vcsa*') @@ -148,12 +163,12 @@ class driver(screenDriver): except: pass oldScreen = currScreen - eventQueue.put({"Type":fenrirEventType.ScreenChanged,"Data":''}) try: vcsa[currScreen].seek(0) lastScreenContent = vcsa[currScreen].read() except: - pass + pass + eventQueue.put({"Type":fenrirEventType.ScreenChanged,"Data":lastScreenContent}) else: self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO) vcsa[currScreen].seek(0) @@ -167,7 +182,7 @@ class driver(screenDriver): time.sleep(0.008) vcsa[currScreen].seek(0) dirtyContent = vcsa[currScreen].read() - eventQueue.put({"Type":fenrirEventType.ScreenUpdate,"Data":None}) + eventQueue.put({"Type":fenrirEventType.ScreenUpdate,"Data":screenContent}) except Exception as e: self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR) @@ -272,20 +287,8 @@ class driver(screenDriver): return _('Default') def getFenrirFontSize(self, attribute): return _('Default') - def update(self, trigger='onUpdate'): - if trigger == 'onInput': # no need for an update on input for VCSA - return - newContentBytes = b'' - try: - # read screen - vcsa = open(self.vcsaDevicePath + self.env['screen']['newTTY'],'rb',0) - newContentBytes = vcsa.read() - vcsa.close() - if len(newContentBytes) < 5: - return - except Exception as e: - self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) - return + def update(self, text, trigger='onUpdate'): + newContentBytes = text # set new "old" values self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes'] self.env['screen']['oldContentText'] = self.env['screen']['newContentText'] From 60c4940a5dbecf628b10831af591e4788681310f Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 12 Mar 2018 21:54:57 +0100 Subject: [PATCH 2/7] Adjust wait --- src/fenrir/screenDriver/vcsaDriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index bf541b45..5330bd24 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -179,7 +179,7 @@ class driver(screenDriver): screenContent = dirtyContent if time.time() - timeout >= 0.4: break - time.sleep(0.008) + time.sleep(0.02) vcsa[currScreen].seek(0) dirtyContent = vcsa[currScreen].read() eventQueue.put({"Type":fenrirEventType.ScreenUpdate,"Data":screenContent}) From 2493761bc7d8230fe610c31d7b7a0fadc8fdc37e Mon Sep 17 00:00:00 2001 From: chrys87 Date: Tue, 13 Mar 2018 09:17:05 +0100 Subject: [PATCH 3/7] Update genericDriver.py --- src/fenrir/soundDriver/genericDriver.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/fenrir/soundDriver/genericDriver.py b/src/fenrir/soundDriver/genericDriver.py index 5a85d6f4..f982bfd1 100644 --- a/src/fenrir/soundDriver/genericDriver.py +++ b/src/fenrir/soundDriver/genericDriver.py @@ -6,6 +6,7 @@ from core import debug import subprocess +import shlex from core.soundDriver import soundDriver class driver(soundDriver): @@ -30,19 +31,25 @@ class driver(soundDriver): return if interrupt: self.cancel() - popenFrequenceCommand = self.frequenceCommand.replace('fenrirVolume', str(self.volume + adjustVolume )) - popenFrequenceCommand = popenFrequenceCommand.replace('fenrirFreqDuration', str(duration)) - popenFrequenceCommand = popenFrequenceCommand.replace('fenrirFrequence', str(frequence)) - self.proc = subprocess.Popen(popenFrequenceCommand, shell=True) + popenFrequenceCommand = shlex.split(self.frequenceCommand) + for idx, word in enumerate(popenFrequenceCommand): + word = word.replace('fenrirVolume', str(self.volume + adjustVolume )) + word = word.replace('fenrirFreqDuration', str(duration)) + word = word.replace('fenrirFrequence', str(frequence)) + popenFrequenceCommand[idx] = word + self.proc = subprocess.Popen(popenFrequenceCommand, shell=False) self.soundType = 'frequence' def playSoundFile(self, filePath, interrupt = True): if not self._initialized: return if interrupt: self.cancel() - popenSoundFileCommand = self.soundFileCommand.replace('fenrirVolume', str(self.volume )) - popenSoundFileCommand = popenSoundFileCommand.replace('fenrirSoundFile', filePath) - self.proc = subprocess.Popen(popenSoundFileCommand, shell=True) + popenSoundFileCommand = shlex.split(self.soundFileCommand) + for idx, word in enumerate(popenSoundFileCommand): + word = word.replace('fenrirVolume', str(self.volume )) + word = word.replace('fenrirSoundFile', str(filePath)) + popenSoundFileCommand[idx] = word + self.proc = subprocess.Popen(popenSoundFileCommand, shell=False) self.soundType = 'file' def cancel(self): if not self._initialized: From 9978f6dcee6f8844367efe3189fa62f2a6e0cc0e Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 13 Mar 2018 22:45:52 +0100 Subject: [PATCH 4/7] add ignoreFile for screens --- config/settings/espeak.settings.conf | 1 + config/settings/settings.conf | 1 + config/settings/settings.conf.example | 1 + config/settings/settings.conf.storm | 1 + config/settings/speech-dispatcher.settings.conf | 1 + src/fenrir/core/screenManager.py | 10 +++++++++- src/fenrir/core/settingsData.py | 1 + 7 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 98cb1e6c..e94a9d8b 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -122,6 +122,7 @@ driver=vcsaDriver encoding=auto screenUpdateDelay=0.05 suspendingScreen= +suspendingScreenFile=/tmp/fenrirSuspend autodetectSuspendingScreen=True [keyboard] diff --git a/config/settings/settings.conf b/config/settings/settings.conf index b535c58b..1e4d5a0d 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -124,6 +124,7 @@ driver=vcsaDriver encoding=auto screenUpdateDelay=0.05 suspendingScreen= +suspendingScreenFile=/tmp/fenrirSuspend autodetectSuspendingScreen=True [keyboard] diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index 01fb662c..1e4dd243 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -125,6 +125,7 @@ driver=vcsaDriver encoding=auto screenUpdateDelay=0.05 suspendingScreen= +suspendingScreenFile=/tmp/fenrirSuspend autodetectSuspendingScreen=True [keyboard] diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 04a9a3a0..ea2d68af 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -79,6 +79,7 @@ driver=vcsaDriver encoding=auto screenUpdateDelay=0.05 suspendingScreen= +suspendingScreenFile=/tmp/fenrirSuspend autodetectSuspendingScreen=True [keyboard] diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index 6fa5b96b..a6ead851 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -124,6 +124,7 @@ driver=vcsaDriver encoding=auto screenUpdateDelay=0.05 suspendingScreen= +suspendingScreenFile=/tmp/fenrirSuspend autodetectSuspendingScreen=True [keyboard] diff --git a/src/fenrir/core/screenManager.py b/src/fenrir/core/screenManager.py index e337d039..a7fbc7d1 100644 --- a/src/fenrir/core/screenManager.py +++ b/src/fenrir/core/screenManager.py @@ -5,7 +5,7 @@ # By Chrys, Storm Dragon, and contributers. from core import debug -import time +import time, os class screenManager(): def __init__(self): @@ -60,6 +60,14 @@ class screenManager(): if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'): ignoreScreens.extend(self.env['screen']['autoIgnoreScreens']) self.env['runtime']['debug'].writeDebugOut('screenManager:isSuspendingScreen ' + str(ignoreScreens) + ' '+ str(self.env['screen']['newTTY']),debug.debugLevel.INFO) + try: + ignoreFileName = self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreenFile') + if ignoreFileName != '': + if os.access(ignoreFileName, os.R_OK): + with open(ignoreFileName) as fp: + ignoreScreens.extend(fp.read().replace('\n','').split(',')) + except: + pass return (screen in ignoreScreens) def isScreenChange(self): diff --git a/src/fenrir/core/settingsData.py b/src/fenrir/core/settingsData.py index 1bc23b40..cb99ac10 100644 --- a/src/fenrir/core/settingsData.py +++ b/src/fenrir/core/settingsData.py @@ -51,6 +51,7 @@ settingsData = { 'encoding': 'auto', 'screenUpdateDelay': 0.1, 'suspendingScreen': '', + 'suspendingScreenFile': '/tmp/fenrirSuspend', 'autodetectSuspendingScreen': False, }, 'general':{ From 9b8b985052e4f9af2f24fde746b64b65879d307e Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 13 Mar 2018 22:55:04 +0100 Subject: [PATCH 5/7] add todo --- TODO v2.0 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/TODO v2.0 b/TODO v2.0 index b81b2a7c..f13abb64 100644 --- a/TODO v2.0 +++ b/TODO v2.0 @@ -117,16 +117,17 @@ Cleanups: [X] curr item [X] first item [X] last item -General: +General: +- [X] read ignorescreens from an file to be able to halt fenrir from outside - commands [X] place last spoken to clipboard (Easy for contribution) - Improvend Headline Seperator and Multible Char Support [X]read "13 #" insteed of ################### Braille Support: Driver: -[Done] make generic speech driver default -[Done] pyttsx3 speech driver +[X] make generic speech driver default +[X] pyttsx3 speech driver - get information already in watchdogs insteed of mainloop (use eventloop to transport) - [Done] InputDriver + [X] InputDriver Settings: Application Profiles: From 551c699a9f6a0c2757a50645a79b08c732ab2bb2 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 13 Mar 2018 23:43:22 +0100 Subject: [PATCH 6/7] add rudimentary tools to add/remove the current session to ignorefile --- tools/addScreenToIgnoreList.py | 26 ++++++++++++++++++++++++++ tools/removeScreenFromIgnoreList.py | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 tools/addScreenToIgnoreList.py create mode 100755 tools/removeScreenFromIgnoreList.py diff --git a/tools/addScreenToIgnoreList.py b/tools/addScreenToIgnoreList.py new file mode 100755 index 00000000..57aa9f37 --- /dev/null +++ b/tools/addScreenToIgnoreList.py @@ -0,0 +1,26 @@ +#!/bin/python +import os + +def addScreenToIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): + if useCurrentScreen: + tty = open('/sys/devices/virtual/tty/tty0/active','r') + screen = str(tty.read()[3:-1]) + ignoreScreens = [] + ignoreScreensStr = '' + if ignoreFileName != '': + if os.access(ignoreFileName, os.R_OK): + with open(ignoreFileName, 'r') as fp: + try: + ignoreScreens = fp.read().split(',')#.replace('\n','').split(',') + except Exception as e: + print(e) + + if not screen in ignoreScreens: + ignoreScreens.extend(screen) + ignoreScreensStr = ','.join(ignoreScreens) + + with open(ignoreFileName, 'w') as fp: + fp.write(ignoreScreensStr) + +if __name__ == "__main__": + addScreenToIgnoreList() diff --git a/tools/removeScreenFromIgnoreList.py b/tools/removeScreenFromIgnoreList.py new file mode 100755 index 00000000..163c5928 --- /dev/null +++ b/tools/removeScreenFromIgnoreList.py @@ -0,0 +1,26 @@ +#!/bin/python +import os + +def addScreenToIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): + if useCurrentScreen: + tty = open('/sys/devices/virtual/tty/tty0/active','r') + screen = str(tty.read()[3:-1]) + ignoreScreens = [] + ignoreScreensStr = '' + if ignoreFileName != '': + if os.access(ignoreFileName, os.R_OK): + with open(ignoreFileName, 'r') as fp: + try: + ignoreScreens = fp.read().split(',')#.replace('\n','').split(',') + except Exception as e: + print(e) + + if screen in ignoreScreens: + ignoreScreens.remove(screen) + ignoreScreensStr = ','.join(ignoreScreens) + + with open(ignoreFileName, 'w') as fp: + fp.write(ignoreScreensStr) + +if __name__ == "__main__": + addScreenToIgnoreList() From f2bf06d82ca8f88e8befc4dba1cb2975a5447a74 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 13 Mar 2018 23:44:52 +0100 Subject: [PATCH 7/7] fix function name --- tools/removeScreenFromIgnoreList.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/removeScreenFromIgnoreList.py b/tools/removeScreenFromIgnoreList.py index 163c5928..c755246d 100755 --- a/tools/removeScreenFromIgnoreList.py +++ b/tools/removeScreenFromIgnoreList.py @@ -1,7 +1,7 @@ #!/bin/python import os -def addScreenToIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): +def removeScreenFromIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): if useCurrentScreen: tty = open('/sys/devices/virtual/tty/tty0/active','r') screen = str(tty.read()[3:-1]) @@ -23,4 +23,4 @@ def addScreenToIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', u fp.write(ignoreScreensStr) if __name__ == "__main__": - addScreenToIgnoreList() + removeScreenFromIgnoreList()