From 8cf251753f176c7d7d19b4c718ea428c26f97fc4 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 4 Sep 2018 22:25:12 +0200 Subject: [PATCH 01/33] add remote settings --- config/settings/espeak.settings.conf | 14 ++++++++++++++ config/settings/settings.conf | 14 ++++++++++++++ config/settings/settings.conf.example | 14 ++++++++++++++ config/settings/settings.conf.storm | 14 ++++++++++++++ config/settings/speech-dispatcher.settings.conf | 14 ++++++++++++++ src/fenrirscreenreader/core/settingsData.py | 9 ++++++++- 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 665d8289..3fd09f86 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -187,6 +187,20 @@ shell= cursor=True highlight=False +[remote] +enable=True +# connection type +# unix = unix sockets +method=unix +# allow settings to overwrite +enableSettingsRemote=True +# permitted settings +allowSettings=barrier#enabled +# allow commands to be executed +enableCommandRemote=True +# permitted commands +allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight + [barrier] enabled=True leftBarriers=│└┌─ diff --git a/config/settings/settings.conf b/config/settings/settings.conf index 8105e537..a3afbdb4 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -197,6 +197,20 @@ cursor=True #follow highlighted text changes highlight=False +[remote] +enable=True +# connection type +# unix = unix sockets +method=unix +# allow settings to overwrite +enableSettingsRemote=True +# permitted settings +allowSettings=barrier#enabled +# allow commands to be executed +enableCommandRemote=True +# permitted commands +allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight + [barrier] enabled=True leftBarriers=│└┌─ diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index 9094763b..fd65bf79 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -198,6 +198,20 @@ cursor=True #follow highlighted text changes highlight=False +[remote] +enable=True +# connection type +# unix = unix sockets +method=unix +# allow settings to overwrite +enableSettingsRemote=True +# permitted settings +allowSettings=barrier#enabled +# allow commands to be executed +enableCommandRemote=True +# permitted commands +allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight + [barrier] enabled=True leftBarriers=│└┌─ diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 73fb9797..ebb18c49 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -143,6 +143,20 @@ cursor=True #follow highlighted text changes highlight=False +[remote] +enable=True +# connection type +# unix = unix sockets +method=unix +# allow settings to overwrite +enableSettingsRemote=True +# permitted settings +allowSettings=barrier#enabled +# allow commands to be executed +enableCommandRemote=True +# permitted commands +allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight + [barrier] enabled=True leftBarriers=│└┌─ diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index e936de42..e8c315da 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -197,6 +197,20 @@ cursor=True #follow highlighted text changes highlight=False +[remote] +enable=True +# connection type +# unix = unix sockets +method=unix +# allow settings to overwrite +enableSettingsRemote=True +# permitted settings +allowSettings=barrier#enabled +# allow commands to be executed +enableCommandRemote=True +# permitted commands +allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight + [barrier] enabled=True leftBarriers=│└┌─ diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 88ae1653..7cacaa36 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -80,7 +80,14 @@ settingsData = { 'focus':{ 'cursor': True, 'highlight': False, - +}, +'remote':{ + 'enable': True, + 'method': 'unix', + 'enableSettingsRemote': True, + 'allowSettings': 'barrier#enabled', + 'enableCommandRemote': True, + 'allowCommands': 'Say,defineWindow,resetSettings,resetWindow,toggleHighlight', }, 'barrier':{ 'enabled': True, From d142fa952c8c1488260d01b355884107cecadf79 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 4 Sep 2018 22:32:03 +0200 Subject: [PATCH 02/33] add remote manager --- src/fenrirscreenreader/core/remoteManager.py | 15 +++++++ .../core/settingsManager.py | 45 ++++++++++--------- 2 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 src/fenrirscreenreader/core/remoteManager.py diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py new file mode 100644 index 00000000..c9600d90 --- /dev/null +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -0,0 +1,15 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from fenrirscreenreader.core import debug + +class remoteManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 87e6c9e9..4821813c 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -26,6 +26,7 @@ from fenrirscreenreader.core import tableManager from fenrirscreenreader.core import byteManager from fenrirscreenreader.core import attributeManager from fenrirscreenreader.core import barrierManager +from fenrirscreenreader.core import remoteManager from fenrirscreenreader.core import environment from fenrirscreenreader.core.settingsData import settingsData from fenrirscreenreader.core import debug @@ -159,7 +160,7 @@ class settingsManager(): self.env['runtime'][driverType].shutdown() except Exception as e: pass - del self.env['runtime'][driverType] + del self.env['runtime'][driverType] def setFenrirKeys(self, keys): keys = keys.upper() @@ -180,7 +181,7 @@ class settingsManager(): e = self.settingArgDict[section] except KeyError: self.settingArgDict[section] = {} - self.settingArgDict[section][option] = str(value) + self.settingArgDict[section][option] = str(value) def parseSettingArgs(self, settingArgs): for optionElem in settingArgs.split(';'): @@ -190,7 +191,7 @@ class settingsManager(): continue section = str(optionElem.split('#',1)[0]).lower() option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower() - value = optionElem.split('#',1)[1].split('=',1)[1] + value = optionElem.split('#',1)[1].split('=',1)[1] self.setOptionArgDict(section, option, value) def initFenrirConfig(self, cliArgs, fenrirManager = None, environment = environment.environment): @@ -208,7 +209,7 @@ class settingsManager(): if os.path.exists(settingsRoot + '/settings/settings.conf'): settingsFile = settingsRoot + '/settings/settings.conf' else: - return None + return None # get sound themes root if not os.path.exists(soundRoot): if os.path.exists(fenrirPath + '/../../config/sound/'): @@ -234,12 +235,12 @@ class settingsManager(): #self.setOptionArgDict('keyboard', 'keyboardLayout', 'pty') self.setSetting('keyboard', 'keyboardLayout', 'pty') self.setOptionArgDict('general', 'debugFile', '/tmp/fenrir-pty.log') - if cliArgs.emulated_evdev: - self.setOptionArgDict('screen', 'driver', 'ptyDriver') - self.setOptionArgDict('keyboard', 'driver', 'evdevDriver') + if cliArgs.emulated_evdev: + self.setOptionArgDict('screen', 'driver', 'ptyDriver') + self.setOptionArgDict('keyboard', 'driver', 'evdevDriver') self.setFenrirKeys(self.getSetting('general','fenrirKeys')) - self.setScriptKeys(self.getSetting('general','scriptKeys')) + self.setScriptKeys(self.getSetting('general','scriptKeys')) environment['runtime']['debug'] = debugManager.debugManager(self.env['runtime']['settingsManager'].getSetting('general','debugFile')) environment['runtime']['debug'].initialize(environment) @@ -265,39 +266,43 @@ class settingsManager(): else: environment['runtime']['punctuationManager'].loadDicts(self.getSetting('general','punctuationProfile')) - + if fenrirManager: environment['runtime']['fenrirManager'] = fenrirManager environment['runtime']['memoryManager'] = memoryManager.memoryManager() environment['runtime']['memoryManager'].initialize(environment) - + environment['runtime']['attributeManager'] = attributeManager.attributeManager() environment['runtime']['attributeManager'].initialize(environment) - + environment['runtime']['eventManager'] = eventManager.eventManager() environment['runtime']['eventManager'].initialize(environment) - + environment['runtime']['processManager'] = processManager.processManager() environment['runtime']['processManager'].initialize(environment) environment['runtime']['outputManager'] = outputManager.outputManager() - environment['runtime']['outputManager'].initialize(environment) + environment['runtime']['outputManager'].initialize(environment) environment['runtime']['byteManager'] = byteManager.byteManager() - environment['runtime']['byteManager'].initialize(environment) - + environment['runtime']['byteManager'].initialize(environment) + environment['runtime']['inputManager'] = inputManager.inputManager() - environment['runtime']['inputManager'].initialize(environment) + environment['runtime']['inputManager'].initialize(environment) environment['runtime']['screenManager'] = screenManager.screenManager() - environment['runtime']['screenManager'].initialize(environment) + environment['runtime']['screenManager'].initialize(environment) - environment['runtime']['commandManager'] = commandManager.commandManager() + environment['runtime']['commandManager'] = commandManager.commandManager() environment['runtime']['commandManager'].initialize(environment) - + environment['runtime']['helpManager'] = helpManager.helpManager() - environment['runtime']['helpManager'].initialize(environment) + environment['runtime']['helpManager'].initialize(environment) + + environment['runtime']['remoteManager'] = remoteManager.remoteManager() + environment['runtime']['remoteManager'].initialize(environment) + if environment['runtime']['inputManager'].getShortcutType() == 'KEY': if not os.path.exists(self.getSetting('keyboard','keyboardLayout')): From 8d6c96a44d95df4faac155b368377169130e92b6 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 5 Sep 2018 19:03:24 +0200 Subject: [PATCH 03/33] add remote event --- src/fenrirscreenreader/core/eventData.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/eventData.py b/src/fenrirscreenreader/core/eventData.py index 81805574..81eabc37 100644 --- a/src/fenrirscreenreader/core/eventData.py +++ b/src/fenrirscreenreader/core/eventData.py @@ -18,7 +18,8 @@ class fenrirEventType(Enum): ScreenChanged = 7 HeartBeat = 8 # for time based scheduling ExecuteCommand = 9 - ByteInput = 10 + ByteInput = 10 + RemoteIncomming = 11 def __int__(self): return self.value def __str__(self): From d5fa50e8c318ca54c850912f598bb3f852e40fed Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 5 Sep 2018 19:13:20 +0200 Subject: [PATCH 04/33] add handler functio --- src/fenrirscreenreader/core/eventManager.py | 4 +++- src/fenrirscreenreader/core/fenrirManager.py | 4 ++++ src/fenrirscreenreader/core/remoteManager.py | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/eventManager.py b/src/fenrirscreenreader/core/eventManager.py index 10c7c698..82e55b7c 100644 --- a/src/fenrirscreenreader/core/eventManager.py +++ b/src/fenrirscreenreader/core/eventManager.py @@ -55,7 +55,9 @@ class eventManager(): elif event['Type'] == fenrirEventType.ExecuteCommand: self.env['runtime']['fenrirManager'].handleExecuteCommand(event) elif event['Type'] == fenrirEventType.ByteInput: - self.env['runtime']['fenrirManager'].handleByteInput(event) + self.env['runtime']['fenrirManager'].handleByteInput(event) + elif event['Type'] == fenrirEventType.RemoteIncomming: + self.env['runtime']['fenrirManager'].handleRemoteIncomming(event) def isMainEventLoopRunning(self): return self.running.value == 1 def startMainEventLoop(self): diff --git a/src/fenrirscreenreader/core/fenrirManager.py b/src/fenrirscreenreader/core/fenrirManager.py index e757da1a..b9dbe67b 100644 --- a/src/fenrirscreenreader/core/fenrirManager.py +++ b/src/fenrirscreenreader/core/fenrirManager.py @@ -105,6 +105,10 @@ class fenrirManager(): self.environment['runtime']['commandManager'].executeCommand( command, 'help') return self.environment['runtime']['commandManager'].executeCommand( command, 'commands') + def handleRemoteIncomming(self, event): + if not event['Data']: + return + self.environment['runtime']['remoteManager'].handleRemoteIncomming(event['Data']) def handleScreenChange(self, event): self.environment['runtime']['screenManager'].hanldeScreenChange(event['Data']) ''' diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index c9600d90..e6ef192f 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -5,6 +5,7 @@ # By Chrys, Storm Dragon, and contributers. from fenrirscreenreader.core import debug +from fenrirscreenreader.core.eventData import fenrirEventType class remoteManager(): def __init__(self): @@ -13,3 +14,8 @@ class remoteManager(): self.env = environment def shutdown(self): pass + def unixSocketWatchDog(): + pass + def handleRemoteIncomming(self, eventData): + if not eventData: + return From 1fe54c6d97507dc615ea20bb656140bbe9210e40 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 5 Sep 2018 22:27:56 +0200 Subject: [PATCH 05/33] add initial remote stuff --- config/settings/espeak.settings.conf | 2 +- config/settings/settings.conf.example | 2 +- config/settings/settings.conf.storm | 2 +- .../settings/speech-dispatcher.settings.conf | 2 +- src/fenrirscreenreader/core/byteManager.py | 14 +-- src/fenrirscreenreader/core/eventManager.py | 6 +- src/fenrirscreenreader/core/remoteManager.py | 94 ++++++++++++++++++- src/fenrirscreenreader/core/settingsData.py | 2 +- .../core/settingsManager.py | 2 + 9 files changed, 107 insertions(+), 19 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 3fd09f86..5b2b5250 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -188,7 +188,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index fd65bf79..8754aa14 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -199,7 +199,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index ebb18c49..e9bc09be 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -144,7 +144,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index e8c315da..b4fb40af 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -198,7 +198,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/src/fenrirscreenreader/core/byteManager.py b/src/fenrirscreenreader/core/byteManager.py index 777ebaba..ebf57fcb 100644 --- a/src/fenrirscreenreader/core/byteManager.py +++ b/src/fenrirscreenreader/core/byteManager.py @@ -35,17 +35,17 @@ class byteManager(): if eventData == b'': return - convertedEscapeSequence = self.unifyEscapeSeq(eventData) + convertedEscapeSequence = self.unifyEscapeSeq(eventData) if self.switchCtrlModeOnce > 0: - self.switchCtrlModeOnce -= 1 - + self.switchCtrlModeOnce -= 1 + isControlMode = False if self.controlMode and not self.switchCtrlModeOnce == 1 or\ not self.controlMode: isControlMode = self.handleControlMode(eventData) - isCommand = False + isCommand = False if self.controlMode and not self.switchCtrlModeOnce == 1 or\ not self.controlMode and self.switchCtrlModeOnce == 1: if self.lastByteKey == convertedEscapeSequence: @@ -53,16 +53,16 @@ class byteManager(): self.repeat += 1 shortcutData = b'' for i in range(self.repeat): - shortcutData = shortcutData + convertedEscapeSequence + shortcutData = shortcutData + convertedEscapeSequence isCommand = self.detectByteCommand(shortcutData) # fall back to single stroke - do we want this? if not isCommand: isCommand = self.detectByteCommand(convertedEscapeSequence) - self.repeat = 1 + self.repeat = 1 if not (isCommand or isControlMode): self.env['runtime']['screenManager'].injectTextToScreen(eventData) if not isCommand: - self.repeat = 1 + self.repeat = 1 self.lastByteKey = convertedEscapeSequence self.lastInputTime = time.time() def getLastByteKey(self): diff --git a/src/fenrirscreenreader/core/eventManager.py b/src/fenrirscreenreader/core/eventManager.py index 82e55b7c..49185474 100644 --- a/src/fenrirscreenreader/core/eventManager.py +++ b/src/fenrirscreenreader/core/eventManager.py @@ -29,7 +29,7 @@ class eventManager(): #print('NET loop ' + str(time.time() - st)) def eventDispatcher(self, event): self.env['runtime']['debug'].writeDebugOut('eventManager:eventDispatcher:start: event: ' + str(event['Type']),debug.debugLevel.INFO) - + if not event: return if not event['Type']: @@ -79,9 +79,9 @@ class eventManager(): except Empty: pass def getEventQueue(self): - return self._eventQueue + return self._eventQueue def getRunning(self): - return self.running + return self.running def putToEventQueue(self,event, data): if not isinstance(event, fenrirEventType): return False diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index e6ef192f..51613544 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -6,16 +6,102 @@ from fenrirscreenreader.core import debug from fenrirscreenreader.core.eventData import fenrirEventType +import time +import select class remoteManager(): def __init__(self): pass def initialize(self, environment): - self.env = environment + self.env = environment + self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) + return + if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): + if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': + self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) + elif self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'tcp': + self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) def shutdown(self): - pass - def unixSocketWatchDog(): - pass + if self.sock: + self.sock.close() + self.sock = None + def unixSocketWatchDog(self, active, eventQueue): + while active.value == 1: + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data":'#!#command##say##this is a test' + }) + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data":'#!#command##interrupt' + }) + def tcpWatchDog(self, active, eventQueue): + import socket + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.host = '0.0.0.0' + self.port = 22447 + self.sock.bind((self.host, self.port)) + self.sock.listen(1) + while active.value == 1: + client_sock, client_addr = self.sock.accept() + if client_sock: + # Check if the client is still connected and if data is available: + try: + r, w, e = select.select([client_sock,], [], []) + except select.error: + return + if len(r) > 0: + rawdata = client_sock.recv(8129) + try: + data = rawdata.decode("utf-8").rstrip() + if data.startswith('#!#'): + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data": data + }) + except: + pass + client_sock.close() + if self.sock: + self.sock.close() + self.sock = None + def handleSettingsChange(self, settingsText): + if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): + return + if settingsText.startswith('set##'): + parameterText = settingsText[len('set##'):] + self.setSettings(parameterText) + if settingsText.startswith('reset'): + self.resetSettings() + def handleCommandExecution(self, commandText): + if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): + return + if commandText.startswith('exec#say##'): + parameterText = commandText[len('exec#say##'):] + self.execSay(parameterText) + if commandText.startswith('cancel##say'): + self.execInterruptSpeech() + def execSay(self, text): + self.env['runtime']['outputManager'].speakText(text) + def execInterruptSpeech(self): + self.env['runtime']['outputManager'].interruptOutput() + def resetSettings(self): + self.env['runtime']['settingsManager'].resetSettingArgDict() + def setSettings(self, settingsArgs): + self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs) def handleRemoteIncomming(self, eventData): if not eventData: return + # settings: + # #!#settings##set##section#setting=value[,section#setting=value] + # #!#settings##set##speech#voice=de + # #!#settings##reset + # execute command: + # #!#command##exec#say##this is a test + # #!#command##cancel##say + if not eventData.startswith('#!#'): + return + if eventData.startswith('#!#settings##'): + settingsText = eventData[len('#!#settings##'):] + self.handleSettingsChange(settingsText) + elif eventData.startswith('#!#command##'): + commandText = eventData[len('#!#command##'):] + self.handleCommandExecution(commandText) diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 7cacaa36..12e206f0 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -82,7 +82,7 @@ settingsData = { 'highlight': False, }, 'remote':{ - 'enable': True, + 'enabled': True, 'method': 'unix', 'enableSettingsRemote': True, 'allowSettings': 'barrier#enabled', diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 4821813c..a7ddad2b 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -174,6 +174,8 @@ class settingsManager(): for key in keyList: if not key in self.env['input']['scriptKey']: self.env['input']['scriptKey'].append(key) + def resetSettingArgDict(self): + self.settingArgDict = {} def setOptionArgDict(self, section, option, value): section = section.lower() option = option.lower() From 76122a93ad9b70aa701aa4acbe4af6e091ce78db Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 5 Sep 2018 23:03:07 +0200 Subject: [PATCH 06/33] add unix socket method --- src/fenrirscreenreader/core/remoteManager.py | 62 +++++++++++++------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 51613544..316777d8 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -8,14 +8,15 @@ from fenrirscreenreader.core import debug from fenrirscreenreader.core.eventData import fenrirEventType import time import select +import socket +import os, os.path class remoteManager(): def __init__(self): pass def initialize(self, environment): self.env = environment - self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) - return + if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) @@ -26,15 +27,36 @@ class remoteManager(): self.sock.close() self.sock = None def unixSocketWatchDog(self, active, eventQueue): + # echo "#<=>#command##exec#say##this is a test" | socat - UNIX-CLIENT:/tmp/fenrir-deamon.sock + if os.path.exists("/tmp/fenrir-deamon.sock"): + os.remove("/tmp/fenrir-deamon.sock") + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.sock.bind("/tmp/fenrir-deamon.sock") + self.sock.listen(1) while active.value == 1: - eventQueue.put({"Type":fenrirEventType.RemoteIncomming, - "Data":'#!#command##say##this is a test' - }) - eventQueue.put({"Type":fenrirEventType.RemoteIncomming, - "Data":'#!#command##interrupt' - }) + client_sock, client_addr = self.sock.accept() + if client_sock: + # Check if the client is still connected and if data is available: + try: + r, w, e = select.select([client_sock,], [], []) + except select.error: + return + if len(r) > 0: + rawdata = client_sock.recv(8129) + try: + data = rawdata.decode("utf-8").rstrip() + if data.startswith('#<=>#'): + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data": data + }) + except: + pass + client_sock.close() + if self.sock: + self.sock.close() + self.sock = None def tcpWatchDog(self, active, eventQueue): - import socket + # echo "#<=>#command##exec#say##this is a test" | nc localhost 22447 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.host = '0.0.0.0' @@ -53,7 +75,7 @@ class remoteManager(): rawdata = client_sock.recv(8129) try: data = rawdata.decode("utf-8").rstrip() - if data.startswith('#!#'): + if data.startswith('#<=>#'): eventQueue.put({"Type":fenrirEventType.RemoteIncomming, "Data": data }) @@ -91,17 +113,17 @@ class remoteManager(): if not eventData: return # settings: - # #!#settings##set##section#setting=value[,section#setting=value] - # #!#settings##set##speech#voice=de - # #!#settings##reset + # #<=>#settings##set##section#setting=value[,section#setting=value] + # #<=>#settings##set##speech#voice=de + # #<=>#settings##reset # execute command: - # #!#command##exec#say##this is a test - # #!#command##cancel##say - if not eventData.startswith('#!#'): + # #<=>#command##exec#say##this is a test + # #<=>#command##cancel##say + if not eventData.startswith('#<=>#'): return - if eventData.startswith('#!#settings##'): - settingsText = eventData[len('#!#settings##'):] + if eventData.startswith('#<=>#settings##'): + settingsText = eventData[len('#<=>#settings##'):] self.handleSettingsChange(settingsText) - elif eventData.startswith('#!#command##'): - commandText = eventData[len('#!#command##'):] + elif eventData.startswith('#<=>#command##'): + commandText = eventData[len('#<=>#command##'):] self.handleCommandExecution(commandText) From 3bb54256191f51c5602910d889e69e2d88a67dd4 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 5 Sep 2018 23:11:42 +0200 Subject: [PATCH 07/33] add some docu, remove trailing spaces --- src/fenrirscreenreader/core/remoteManager.py | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 316777d8..5ac38cbb 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -4,6 +4,29 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +''' +Remote controll: +start delimiter = #<=># +category=settings,command +setting actions: +- set (Parameter = settings) +- reset +command actions: +- exec (Parameter1 = Command, Parameter2 = Command Parameters) +- cancel +structure: +#<=>#category##action[##Parameter1##Parameter2] + +settings: +#<=>#settings##set##section#setting=value[,section#setting=value] +#<=>#settings##set##speech#voice=de +#<=>#settings##reset +execute command: +#<=>#command##exec#say##this is a test +#<=>#command##cancel##say +''' + + from fenrirscreenreader.core import debug from fenrirscreenreader.core.eventData import fenrirEventType import time @@ -44,7 +67,7 @@ class remoteManager(): if len(r) > 0: rawdata = client_sock.recv(8129) try: - data = rawdata.decode("utf-8").rstrip() + data = rawdata.decode("utf-8").rstrip().lstrip() if data.startswith('#<=>#'): eventQueue.put({"Type":fenrirEventType.RemoteIncomming, "Data": data @@ -74,7 +97,7 @@ class remoteManager(): if len(r) > 0: rawdata = client_sock.recv(8129) try: - data = rawdata.decode("utf-8").rstrip() + data = rawdata.decode("utf-8").rstrip().lstrip() if data.startswith('#<=>#'): eventQueue.put({"Type":fenrirEventType.RemoteIncomming, "Data": data @@ -112,6 +135,7 @@ class remoteManager(): def handleRemoteIncomming(self, eventData): if not eventData: return + # examples # settings: # #<=>#settings##set##section#setting=value[,section#setting=value] # #<=>#settings##set##speech#voice=de From ea60f41fcc2e0b723aef6afecb67bfc16294e76c Mon Sep 17 00:00:00 2001 From: chrys Date: Thu, 6 Sep 2018 23:54:56 +0200 Subject: [PATCH 08/33] add comment --- src/fenrirscreenreader/core/remoteManager.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 5ac38cbb..ae1c00df 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -51,10 +51,15 @@ class remoteManager(): self.sock = None def unixSocketWatchDog(self, active, eventQueue): # echo "#<=>#command##exec#say##this is a test" | socat - UNIX-CLIENT:/tmp/fenrir-deamon.sock - if os.path.exists("/tmp/fenrir-deamon.sock"): - os.remove("/tmp/fenrir-deamon.sock") + # socket daemon + # /run/user//fenrirscreenreader/daemon + # socket pty + # /run/user//fenrirscreenreader/ptyX + socketpath = '/tmp/fenrir-deamon.sock' + if os.path.exists(socketpath): + os.remove(socketpath) self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - self.sock.bind("/tmp/fenrir-deamon.sock") + self.sock.bind(socketpath) self.sock.listen(1) while active.value == 1: client_sock, client_addr = self.sock.accept() @@ -80,6 +85,7 @@ class remoteManager(): self.sock = None def tcpWatchDog(self, active, eventQueue): # echo "#<=>#command##exec#say##this is a test" | nc localhost 22447 + # port should be configureable self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.host = '0.0.0.0' From 800e950a7e986f9eb747b2d95a417b8e98c31da0 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 00:31:00 +0200 Subject: [PATCH 09/33] change syntax --- src/fenrirscreenreader/core/remoteManager.py | 47 +++++++++----------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index ae1c00df..414b3eab 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -39,7 +39,8 @@ class remoteManager(): pass def initialize(self, environment): self.env = environment - + self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) + return if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) @@ -73,10 +74,9 @@ class remoteManager(): rawdata = client_sock.recv(8129) try: data = rawdata.decode("utf-8").rstrip().lstrip() - if data.startswith('#<=>#'): - eventQueue.put({"Type":fenrirEventType.RemoteIncomming, - "Data": data - }) + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data": data + }) except: pass client_sock.close() @@ -104,10 +104,9 @@ class remoteManager(): rawdata = client_sock.recv(8129) try: data = rawdata.decode("utf-8").rstrip().lstrip() - if data.startswith('#<=>#'): - eventQueue.put({"Type":fenrirEventType.RemoteIncomming, - "Data": data - }) + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data": data + }) except: pass client_sock.close() @@ -117,18 +116,18 @@ class remoteManager(): def handleSettingsChange(self, settingsText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): return - if settingsText.startswith('set##'): - parameterText = settingsText[len('set##'):] + if settingsText.startswith('set '): + parameterText = settingsText[len('set '):] self.setSettings(parameterText) if settingsText.startswith('reset'): self.resetSettings() def handleCommandExecution(self, commandText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): return - if commandText.startswith('exec#say##'): - parameterText = commandText[len('exec#say##'):] + if commandText.startswith('say '): + parameterText = commandText[len('say '):] self.execSay(parameterText) - if commandText.startswith('cancel##say'): + if commandText.startswith('interrupt'): self.execInterruptSpeech() def execSay(self, text): self.env['runtime']['outputManager'].speakText(text) @@ -143,17 +142,15 @@ class remoteManager(): return # examples # settings: - # #<=>#settings##set##section#setting=value[,section#setting=value] - # #<=>#settings##set##speech#voice=de - # #<=>#settings##reset + # settings set section#setting=value[,section#setting=value] + # setting set speech#voice=de + # setting reset # execute command: - # #<=>#command##exec#say##this is a test - # #<=>#command##cancel##say - if not eventData.startswith('#<=>#'): - return - if eventData.startswith('#<=>#settings##'): - settingsText = eventData[len('#<=>#settings##'):] + # command say this is a test + # command interrupt + if eventData.startswith('setting '): + settingsText = eventData[len('setting '):] self.handleSettingsChange(settingsText) - elif eventData.startswith('#<=>#command##'): - commandText = eventData[len('#<=>#command##'):] + elif eventData.startswith('command '): + commandText = eventData[len('command '):] self.handleCommandExecution(commandText) From 69ffffc7a4846b7327ef46ada11a79c4331151ef Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 00:56:29 +0200 Subject: [PATCH 10/33] fix some stuff --- src/fenrirscreenreader/core/remoteManager.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 414b3eab..c06aae69 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -39,8 +39,7 @@ class remoteManager(): pass def initialize(self, environment): self.env = environment - self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) - return + if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) @@ -51,7 +50,7 @@ class remoteManager(): self.sock.close() self.sock = None def unixSocketWatchDog(self, active, eventQueue): - # echo "#<=>#command##exec#say##this is a test" | socat - UNIX-CLIENT:/tmp/fenrir-deamon.sock + # echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrir-deamon.sock # socket daemon # /run/user//fenrirscreenreader/daemon # socket pty @@ -59,7 +58,7 @@ class remoteManager(): socketpath = '/tmp/fenrir-deamon.sock' if os.path.exists(socketpath): os.remove(socketpath) - self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.bind(socketpath) self.sock.listen(1) while active.value == 1: @@ -84,7 +83,7 @@ class remoteManager(): self.sock.close() self.sock = None def tcpWatchDog(self, active, eventQueue): - # echo "#<=>#command##exec#say##this is a test" | nc localhost 22447 + # echo "command say this is a test" | nc localhost 22447 # port should be configureable self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) From 50b6c0761c7cece81f7faa0dc24f6a550af9fbde Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 01:03:55 +0200 Subject: [PATCH 11/33] fix some stuff --- src/fenrirscreenreader/core/remoteManager.py | 39 +++++++------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index c06aae69..936322bb 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -6,24 +6,22 @@ ''' Remote controll: -start delimiter = #<=># -category=settings,command -setting actions: -- set (Parameter = settings) +sectioncommandparameters +sections:command,setting +setting commands: +- set section#setting=value[,section#setting=value] - reset -command actions: -- exec (Parameter1 = Command, Parameter2 = Command Parameters) -- cancel -structure: -#<=>#category##action[##Parameter1##Parameter2] - +command commands: +- say text to speech +- interrupt +examples settings: -#<=>#settings##set##section#setting=value[,section#setting=value] -#<=>#settings##set##speech#voice=de -#<=>#settings##reset -execute command: -#<=>#command##exec#say##this is a test -#<=>#command##cancel##say +settings set section#setting=value[,section#setting=value] +setting set speech#voice=de +setting reset +command: +command say this is a test +command interrupt ''' @@ -84,7 +82,6 @@ class remoteManager(): self.sock = None def tcpWatchDog(self, active, eventQueue): # echo "command say this is a test" | nc localhost 22447 - # port should be configureable self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.host = '0.0.0.0' @@ -139,14 +136,6 @@ class remoteManager(): def handleRemoteIncomming(self, eventData): if not eventData: return - # examples - # settings: - # settings set section#setting=value[,section#setting=value] - # setting set speech#voice=de - # setting reset - # execute command: - # command say this is a test - # command interrupt if eventData.startswith('setting '): settingsText = eventData[len('setting '):] self.handleSettingsChange(settingsText) From 59f68e39ff3373795e924728cfdcb679cc0735f1 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 16:25:15 +0200 Subject: [PATCH 12/33] store stuff in dict isnteed of real settings --- src/fenrirscreenreader/core/settingsManager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 594a1483..07faf7ad 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -80,7 +80,8 @@ class settingsManager(): return True def setSetting(self, section, setting, value): - self.env['settings'].set(section, setting, value) + self.setOptionArgDict(section, setting, value) + #self.env['settings'].set(section, setting, value) def getSetting(self, section, setting): value = '' From c1e09f0e58c1fce5e3332dfff441d0b4b5f60afb Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 17:09:11 +0200 Subject: [PATCH 13/33] add widow --- src/fenrirscreenreader/core/cursorManager.py | 37 +++++++--- src/fenrirscreenreader/core/remoteManager.py | 71 +++++++++++++++----- 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/src/fenrirscreenreader/core/cursorManager.py b/src/fenrirscreenreader/core/cursorManager.py index bfb4ef6c..9d31cb56 100644 --- a/src/fenrirscreenreader/core/cursorManager.py +++ b/src/fenrirscreenreader/core/cursorManager.py @@ -82,21 +82,36 @@ class cursorManager(): except: pass return False - def setWindowForApplication(self): - if not self.env['commandBuffer']['Marks']['1']: - return False - if not self.env['commandBuffer']['Marks']['2']: - return False + def setWindowForApplication(self, start = None, end = None): + if start == None: + if not self.env['commandBuffer']['Marks']['1']: + return False + else: + x1 = self.env['commandBuffer']['Marks']['1']['x'] + y1 = self.env['commandBuffer']['Marks']['1']['y'] + else: + x1 = start['x'] + y1 = start['y'] + if end == None: + if not self.env['commandBuffer']['Marks']['2']: + return False + else: + x1 = self.env['commandBuffer']['Marks']['2']['x'] + y1 = self.env['commandBuffer']['Marks']['2']['y'] + else: + x1 = start['x'] + y1 = start['y'] + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() self.env['commandBuffer']['windowArea'][currApp] = {} - if self.env['commandBuffer']['Marks']['1']['x'] * self.env['commandBuffer']['Marks']['1']['y'] <= \ - self.env['commandBuffer']['Marks']['2']['x'] * self.env['commandBuffer']['Marks']['2']['y']: - self.env['commandBuffer']['windowArea'][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() - self.env['commandBuffer']['windowArea'][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + if x1 * y1 <= \ + x2 * y2: + self.env['commandBuffer']['windowArea'][currApp]['1'] = {'x':x1, 'y':y1} + self.env['commandBuffer']['windowArea'][currApp]['2'] = {'x':x2, 'y':y2} else: - self.env['commandBuffer']['windowArea'][currApp]['1'] = self.env['commandBuffer']['Marks']['2'].copy() - self.env['commandBuffer']['windowArea'][currApp]['2'] = self.env['commandBuffer']['Marks']['1'].copy() + self.env['commandBuffer']['windowArea'][currApp]['1'] = {'x':x2, 'y':y2} + self.env['commandBuffer']['windowArea'][currApp]['2'] = {'x':x1, 'y':y1} return True def clearWindowForApplication(self): currApp = self.env['runtime']['applicationManager'].getCurrentApplication() diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 936322bb..80c43e95 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -34,7 +34,16 @@ import os, os.path class remoteManager(): def __init__(self): - pass + # command controll + self.commandConst = 'COMMAND ' + self.sayConst = 'SAY ' + self.interruptConst = 'INTERRUPT' + self.defineWindowConst = 'WINDOW ' + self.resetWindowConst = 'RESETWINDOW' + # setting controll + self.settingConst = 'SETTING ' + self.setSettingConst = 'SET ' + self.resetSettingConst = 'RESET' def initialize(self, environment): self.env = environment @@ -112,22 +121,53 @@ class remoteManager(): def handleSettingsChange(self, settingsText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): return - if settingsText.startswith('set '): - parameterText = settingsText[len('set '):] + upperSettingsText = settingsText.upper() + # set setting + if upperSettingsText.startswith(self.setSettingConst): + parameterText = settingsText[len(self.setSettingConst):] self.setSettings(parameterText) - if settingsText.startswith('reset'): + # reset setting + if upperSettingsText.startswith(self.resetSettingConst): self.resetSettings() def handleCommandExecution(self, commandText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): return - if commandText.startswith('say '): - parameterText = commandText[len('say '):] - self.execSay(parameterText) - if commandText.startswith('interrupt'): - self.execInterruptSpeech() - def execSay(self, text): + upperCommandText = commandText.upper() + # say + if upperCommandText.startswith(self.sayConst): + parameterText = commandText[len(self.sayConst):] + self.say(parameterText) + # interrupt + if upperCommandText.startswith(self.interruptConst): + self.interruptSpeech() + # define window + if upperCommandText.startswith(self.defineWindowConst): + parameterText = commandText[len(self.defineWindowConst):] + self.defineWindow(parameterText) + # reset window + if upperCommandText.startswith(self.resetWindowConst): + self.resetWindow() + def defineWindow(self, windowText): + start = {} + end = {} + try: + windowList = windowText.split(' ') + if len(windowList) < 4: + return + print(windowList) + start['x'] = int(windowList[0]) + start['y'] = int(windowList[1]) + end['x'] = int(windowList[2]) + end['y'] = int(windowList[3]) + + self.env['runtime']['cursorManager'].setWindowForApplication(start, end) + except: + pass + def resetWindow(self): + self.env['runtime']['cursorManager'].clearWindowForApplication() + def say(self, text): self.env['runtime']['outputManager'].speakText(text) - def execInterruptSpeech(self): + def interruptSpeech(self): self.env['runtime']['outputManager'].interruptOutput() def resetSettings(self): self.env['runtime']['settingsManager'].resetSettingArgDict() @@ -136,9 +176,10 @@ class remoteManager(): def handleRemoteIncomming(self, eventData): if not eventData: return - if eventData.startswith('setting '): - settingsText = eventData[len('setting '):] + upperEventData = eventData.upper() + if upperEventData.startswith(self.settingConst): + settingsText = eventData[len(self.settingConst):] self.handleSettingsChange(settingsText) - elif eventData.startswith('command '): - commandText = eventData[len('command '):] + elif upperEventData.startswith(self.commandConst): + commandText = eventData[len(self.commandConst):] self.handleCommandExecution(commandText) From 35cd391e6c840d098d04286ebdaab1820be3dd47 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 17:13:48 +0200 Subject: [PATCH 14/33] add widow --- src/fenrirscreenreader/core/cursorManager.py | 4 ++++ src/fenrirscreenreader/core/remoteManager.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fenrirscreenreader/core/cursorManager.py b/src/fenrirscreenreader/core/cursorManager.py index 9d31cb56..d6109328 100644 --- a/src/fenrirscreenreader/core/cursorManager.py +++ b/src/fenrirscreenreader/core/cursorManager.py @@ -83,6 +83,10 @@ class cursorManager(): pass return False def setWindowForApplication(self, start = None, end = None): + x1 = 0 + x2 = 0 + y1 = 0 + y2 = 0 if start == None: if not self.env['commandBuffer']['Marks']['1']: return False diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 80c43e95..a43f91dd 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -154,14 +154,13 @@ class remoteManager(): windowList = windowText.split(' ') if len(windowList) < 4: return - print(windowList) start['x'] = int(windowList[0]) start['y'] = int(windowList[1]) end['x'] = int(windowList[2]) end['y'] = int(windowList[3]) self.env['runtime']['cursorManager'].setWindowForApplication(start, end) - except: + except Exception as e: pass def resetWindow(self): self.env['runtime']['cursorManager'].clearWindowForApplication() From 7575c13d71feec2357e1b85c879488ae3581b6c2 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 19:36:25 +0200 Subject: [PATCH 15/33] make sock writeable --- src/fenrirscreenreader/core/remoteManager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index a43f91dd..a2118709 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -30,7 +30,7 @@ from fenrirscreenreader.core.eventData import fenrirEventType import time import select import socket -import os, os.path +import os, os.path, sys, stat class remoteManager(): def __init__(self): @@ -68,6 +68,7 @@ class remoteManager(): self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.bind(socketpath) self.sock.listen(1) + os.chmod(socketpath, 0o222) while active.value == 1: client_sock, client_addr = self.sock.accept() if client_sock: From 06e513a97677299c332072f609fb4b1bb1df1fe2 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 19:39:12 +0200 Subject: [PATCH 16/33] restrict ip to localhost --- src/fenrirscreenreader/core/remoteManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index a2118709..3ebefa64 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -94,7 +94,7 @@ class remoteManager(): # echo "command say this is a test" | nc localhost 22447 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.host = '0.0.0.0' + self.host = '127.0.0.1' self.port = 22447 self.sock.bind((self.host, self.port)) self.sock.listen(1) From 14aadf6eda678e6a2e53fb9aadf4f68ae26d7f07 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 19:50:10 +0200 Subject: [PATCH 17/33] make socket uniqe --- src/fenrirscreenreader/core/remoteManager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 3ebefa64..51f3e7dd 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -62,7 +62,10 @@ class remoteManager(): # /run/user//fenrirscreenreader/daemon # socket pty # /run/user//fenrirscreenreader/ptyX - socketpath = '/tmp/fenrir-deamon.sock' + if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver': + socketpath = '/tmp/fenrirscreenreader-deamon.sock' + else: + socketpath = '/tmp/fenrirscreenreader-' + str(os.getpid()) + '.sock' if os.path.exists(socketpath): os.remove(socketpath) self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -147,7 +150,7 @@ class remoteManager(): self.defineWindow(parameterText) # reset window if upperCommandText.startswith(self.resetWindowConst): - self.resetWindow() + self.resetWindow() def defineWindow(self, windowText): start = {} end = {} From a3cb2010ab18fbfeb2a33ba6453c0af08988c9d6 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 19:52:56 +0200 Subject: [PATCH 18/33] sync --- src/fenrirscreenreader/core/remoteManager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 51f3e7dd..c7dc6fb7 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -71,7 +71,8 @@ class remoteManager(): self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.bind(socketpath) self.sock.listen(1) - os.chmod(socketpath, 0o222) + if not self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver': + os.chmod(socketpath, 0o222) while active.value == 1: client_sock, client_addr = self.sock.accept() if client_sock: From 0d0985af9d7c6822fd64c169b6f39a34df62c521 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 20:45:42 +0200 Subject: [PATCH 19/33] remove sockets if fenrir stops --- src/fenrirscreenreader/core/remoteManager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index c7dc6fb7..72b71763 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -91,6 +91,9 @@ class remoteManager(): except: pass client_sock.close() + + if os.path.exists(socketpath): + os.remove(socketpath) if self.sock: self.sock.close() self.sock = None From 6b8c24831c29f7511a8972b24c2329fbbec4135c Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 21:19:21 +0200 Subject: [PATCH 20/33] fix make port and path configurable --- config/settings/espeak.settings.conf | 7 ++++++- config/settings/settings.conf | 5 +++++ config/settings/settings.conf.example | 7 ++++++- config/settings/settings.conf.storm | 7 ++++++- config/settings/speech-dispatcher.settings.conf | 7 ++++++- src/fenrirscreenreader/core/remoteManager.py | 17 +++++++---------- src/fenrirscreenreader/core/settingsData.py | 2 ++ 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 5b2b5250..3137a660 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -188,10 +188,15 @@ cursor=True highlight=False [remote] -enabled=True +enable=True # connection type # unix = unix sockets +# tcp = tcp (localhost only) method=unix +# tcp port +port=22447 +# socket filepath +socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True # permitted settings diff --git a/config/settings/settings.conf b/config/settings/settings.conf index a3afbdb4..ab2d8f90 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -201,7 +201,12 @@ highlight=False enable=True # connection type # unix = unix sockets +# tcp = tcp (localhost only) method=unix +# tcp port +port=22447 +# socket filepath +socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True # permitted settings diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index 8754aa14..a9e893e8 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -199,10 +199,15 @@ cursor=True highlight=False [remote] -enabled=True +enable=True # connection type # unix = unix sockets +# tcp = tcp (localhost only) method=unix +# tcp port +port=22447 +# socket filepath +socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True # permitted settings diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index e9bc09be..2969e76a 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -144,10 +144,15 @@ cursor=True highlight=False [remote] -enabled=True +enable=True # connection type # unix = unix sockets +# tcp = tcp (localhost only) method=unix +# tcp port +port=22447 +# socket filepath +socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True # permitted settings diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index b4fb40af..4bfe3c0c 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -198,10 +198,15 @@ cursor=True highlight=False [remote] -enabled=True +enable=True # connection type # unix = unix sockets +# tcp = tcp (localhost only) method=unix +# tcp port +port=22447 +# socket filepath +socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True # permitted settings diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 72b71763..89a7b77f 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -57,21 +57,18 @@ class remoteManager(): self.sock.close() self.sock = None def unixSocketWatchDog(self, active, eventQueue): - # echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrir-deamon.sock - # socket daemon - # /run/user//fenrirscreenreader/daemon - # socket pty - # /run/user//fenrirscreenreader/ptyX + # echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrirscreenreader-deamon.sock + if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver': - socketpath = '/tmp/fenrirscreenreader-deamon.sock' + socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-deamon.sock' else: - socketpath = '/tmp/fenrirscreenreader-' + str(os.getpid()) + '.sock' + socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-' + str(os.getpid()) + '.sock' if os.path.exists(socketpath): os.remove(socketpath) self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.bind(socketpath) self.sock.listen(1) - if not self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver': + if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver': os.chmod(socketpath, 0o222) while active.value == 1: client_sock, client_addr = self.sock.accept() @@ -91,7 +88,7 @@ class remoteManager(): except: pass client_sock.close() - + if os.path.exists(socketpath): os.remove(socketpath) if self.sock: @@ -102,7 +99,7 @@ class remoteManager(): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.host = '127.0.0.1' - self.port = 22447 + self.port = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'port') self.sock.bind((self.host, self.port)) self.sock.listen(1) while active.value == 1: diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 12e206f0..b0cb535f 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -84,6 +84,8 @@ settingsData = { 'remote':{ 'enabled': True, 'method': 'unix', + 'port': 22447, + 'socketpath':'/tmp/', 'enableSettingsRemote': True, 'allowSettings': 'barrier#enabled', 'enableCommandRemote': True, From ef091a427d85fd4ecc8b7359c78fd863414c29eb Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 21:55:40 +0200 Subject: [PATCH 21/33] add permission propertys --- config/settings/espeak.settings.conf | 2 +- config/settings/settings.conf | 2 +- config/settings/settings.conf.example | 2 +- config/settings/settings.conf.storm | 2 +- config/settings/speech-dispatcher.settings.conf | 2 +- src/fenrirscreenreader/core/remoteManager.py | 16 +++++++++++++--- src/fenrirscreenreader/core/settingsData.py | 2 +- src/fenrirscreenreader/core/settingsManager.py | 10 +++++++++- 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 3137a660..2ee038c1 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -204,7 +204,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf b/config/settings/settings.conf index ab2d8f90..54550c55 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -214,7 +214,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index a9e893e8..64d71a66 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -215,7 +215,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 2969e76a..7e808e86 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -160,7 +160,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index 4bfe3c0c..8dbbc242 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -214,7 +214,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 89a7b77f..0fa4947e 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -48,9 +48,9 @@ class remoteManager(): self.env = environment if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): - if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': + if self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'UNIX': self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) - elif self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'tcp': + elif self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'TCP': self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) def shutdown(self): if self.sock: @@ -126,6 +126,7 @@ class remoteManager(): def handleSettingsChange(self, settingsText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): return + upperSettingsText = settingsText.upper() # set setting if upperSettingsText.startswith(self.setSettingConst): @@ -137,7 +138,14 @@ class remoteManager(): def handleCommandExecution(self, commandText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): return + allowCommands = self.env['runtime']['settingsManager'].getSetting('remote', 'allowCommands').upper().split(',') upperCommandText = commandText.upper() + allowed = False + for a in allowCommands: + if upperCommandText.startswith(a): + allowed = True + if not allowed: + return # say if upperCommandText.startswith(self.sayConst): parameterText = commandText[len(self.sayConst):] @@ -176,7 +184,9 @@ class remoteManager(): def resetSettings(self): self.env['runtime']['settingsManager'].resetSettingArgDict() def setSettings(self, settingsArgs): - self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs) + allowSettings = self.env['runtime']['settingsManager'].getSetting('remote', 'allowSettings').upper().split(',') + + self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs, allowSettings) def handleRemoteIncomming(self, eventData): if not eventData: return diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index b0cb535f..60b34e50 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -89,7 +89,7 @@ settingsData = { 'enableSettingsRemote': True, 'allowSettings': 'barrier#enabled', 'enableCommandRemote': True, - 'allowCommands': 'Say,defineWindow,resetSettings,resetWindow,toggleHighlight', + 'allowCommands': 'say,interrupt,window,resetwindow', }, 'barrier':{ 'enabled': True, diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 07faf7ad..bd609070 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -186,12 +186,20 @@ class settingsManager(): self.settingArgDict[section] = {} self.settingArgDict[section][option] = str(value) - def parseSettingArgs(self, settingArgs): + def parseSettingArgs(self, settingArgs, allowSettings): for optionElem in settingArgs.split(';'): if len(optionElem.split('#',1)) != 2: continue if len(optionElem.split('#',1)[1].split('=',1)) != 2: continue + allowed = False + if allowSettings: + for a in allowSettings: + if a in optionElem: + allowed = True + if not allowed: + continue + section = str(optionElem.split('#',1)[0]).lower() option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower() value = optionElem.split('#',1)[1].split('=',1)[1] From c7502ab909e632cf649ba9317804cc467139b9a1 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 22:08:08 +0200 Subject: [PATCH 22/33] make parameter optional --- src/fenrirscreenreader/core/settingsManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index bd609070..a4b8d52e 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -186,7 +186,7 @@ class settingsManager(): self.settingArgDict[section] = {} self.settingArgDict[section][option] = str(value) - def parseSettingArgs(self, settingArgs, allowSettings): + def parseSettingArgs(self, settingArgs, allowSettings = None): for optionElem in settingArgs.split(';'): if len(optionElem.split('#',1)) != 2: continue From 28d12dad917ce4d0bcb40fceb198360d2629a190 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 23:09:02 +0200 Subject: [PATCH 23/33] not flood on vcsa error --- src/fenrirscreenreader/screenDriver/vcsaDriver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/screenDriver/vcsaDriver.py b/src/fenrirscreenreader/screenDriver/vcsaDriver.py index 0a3e2910..85a9f932 100644 --- a/src/fenrirscreenreader/screenDriver/vcsaDriver.py +++ b/src/fenrirscreenreader/screenDriver/vcsaDriver.py @@ -155,7 +155,8 @@ class driver(screenDriver): "Data":self.createScreenEventData(currScreen,screenContent) }) except Exception as e: - self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR) + time.sleep(0.2) def createScreenEventData(self, screen, content): From 5cd0a1dd67e97f4e20309fac9d20da22214d1159 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 23:16:30 +0200 Subject: [PATCH 24/33] dont endless loop on mapping issues in evdev --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 6e9439ef..c8a8b69f 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -92,10 +92,10 @@ class driver(inputDriver): event = None foundKeyInSequence = False foreward = False - eventFired = False - for fd in r: + eventFired = False + for fd in r: try: - event = self.iDevices[fd].read_one() + event = self.iDevices[fd].read_one() except: self.removeDevice(fd) while(event): @@ -106,8 +106,10 @@ class driver(inputDriver): if event.code != 0: currMapEvent = self.mapEvent(event) if not currMapEvent: + event = self.iDevices[fd].read_one() continue if not isinstance(currMapEvent['EventName'], str): + event = self.iDevices[fd].read_one() continue if currMapEvent['EventState'] in [0,1,2]: eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()}) @@ -116,7 +118,7 @@ class driver(inputDriver): if event.type in [2,3]: foreward = True - event = self.iDevices[fd].read_one() + event = self.iDevices[fd].read_one() if not foundKeyInSequence: if foreward and not eventFired: self.writeEventBuffer() From b0459fa7f9b62e1e9fbb578a112c549ad2d66d25 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 23:27:15 +0200 Subject: [PATCH 25/33] remove ignore file support --- 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/fenrirscreenreader/core/screenManager.py | 12 ++---------- src/fenrirscreenreader/core/settingsData.py | 1 - 7 files changed, 2 insertions(+), 16 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 2ee038c1..563feda4 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -122,7 +122,6 @@ 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 54550c55..c6213de0 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -124,7 +124,6 @@ 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 64d71a66..fe8a4f99 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -125,7 +125,6 @@ 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 7e808e86..758d12e2 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -79,7 +79,6 @@ 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 8dbbc242..ba3178a3 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -124,7 +124,6 @@ driver=vcsaDriver encoding=auto screenUpdateDelay=0.05 suspendingScreen= -suspendingScreenFile=/tmp/fenrirSuspend autodetectSuspendingScreen=True [keyboard] diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index b39608d9..e3bca0de 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -195,15 +195,7 @@ class screenManager(): if fixIgnoreScreens != '': ignoreScreens.extend(fixIgnoreScreens.split(',')) if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'): - ignoreScreens.extend(self.env['screen']['autoIgnoreScreens']) - 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 + ignoreScreens.extend(self.env['screen']['autoIgnoreScreens']) self.env['runtime']['debug'].writeDebugOut('screenManager:isSuspendingScreen ignore:' + str(ignoreScreens) + ' current:'+ str(screen ), debug.debugLevel.INFO) return (screen in ignoreScreens) @@ -214,7 +206,7 @@ class screenManager(): def isDelta(self, ignoreSpace=False): newDelta = self.env['screen']['newDelta'] if ignoreSpace: - newDelta = newDelta.strip() + newDelta = newDelta.strip() return newDelta != '' def isNegativeDelta(self): return self.env['screen']['newNegativeDelta'] != '' diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 60b34e50..021d1267 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -51,7 +51,6 @@ settingsData = { 'encoding': 'auto', 'screenUpdateDelay': 0.1, 'suspendingScreen': '', - 'suspendingScreenFile': '/tmp/fenrirSuspend', 'autodetectSuspendingScreen': False, }, 'general':{ From 45921a44878cee5649d8875cfa5749c09153f0b1 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 11:13:19 +0200 Subject: [PATCH 26/33] add release notes 1.9.3 --- realese nots/1.9.3 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 realese nots/1.9.3 diff --git a/realese nots/1.9.3 b/realese nots/1.9.3 new file mode 100644 index 00000000..8c69eb7f --- /dev/null +++ b/realese nots/1.9.3 @@ -0,0 +1,14 @@ +- fix hight CPU load in VCSA pressing mute key +- add remote manager +- remote manager: TCP connection +- remote manager: UNIX Socket connection(default) +- remote manager: set settings set a setting (-o syntax) +- remote manager: reset settings +- remote Manager: say command (say something) +- remote manager: interrupt command (interrupt current speech) +- remote manager: window command (to define window) +- remote manager: resetwindow command (to reset window) +- remote manager: settings filter (only allow things in list) +- remote manager: command filter (only allow things in list) +- settings: store settings more centralized +- variouse speedups and bugfixes From a0beb42e896a6c937b064a27e7e60607b1ab386a Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 20:05:59 +0200 Subject: [PATCH 27/33] remove remote filter lists --- config/settings/espeak.settings.conf | 4 --- config/settings/settings.conf | 4 --- config/settings/settings.conf.example | 4 --- config/settings/settings.conf.storm | 4 --- .../settings/speech-dispatcher.settings.conf | 4 --- src/fenrirscreenreader/core/remoteManager.py | 15 +++------ src/fenrirscreenreader/core/settingsData.py | 2 -- .../core/settingsManager.py | 31 +++++++------------ 8 files changed, 16 insertions(+), 52 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 563feda4..b5edcc26 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -198,12 +198,8 @@ port=22447 socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True -# permitted settings -allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True -# permitted commands -allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf b/config/settings/settings.conf index c6213de0..10d171af 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -208,12 +208,8 @@ port=22447 socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True -# permitted settings -allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True -# permitted commands -allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index fe8a4f99..80039a81 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -209,12 +209,8 @@ port=22447 socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True -# permitted settings -allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True -# permitted commands -allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 758d12e2..65f58552 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -154,12 +154,8 @@ port=22447 socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True -# permitted settings -allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True -# permitted commands -allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index ba3178a3..2467a9b3 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -208,12 +208,8 @@ port=22447 socketpath=/tmp/ # allow settings to overwrite enableSettingsRemote=True -# permitted settings -allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True -# permitted commands -allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 0fa4947e..9be43ea0 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -126,7 +126,7 @@ class remoteManager(): def handleSettingsChange(self, settingsText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): return - + upperSettingsText = settingsText.upper() # set setting if upperSettingsText.startswith(self.setSettingConst): @@ -138,14 +138,9 @@ class remoteManager(): def handleCommandExecution(self, commandText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): return - allowCommands = self.env['runtime']['settingsManager'].getSetting('remote', 'allowCommands').upper().split(',') + upperCommandText = commandText.upper() - allowed = False - for a in allowCommands: - if upperCommandText.startswith(a): - allowed = True - if not allowed: - return + # say if upperCommandText.startswith(self.sayConst): parameterText = commandText[len(self.sayConst):] @@ -184,9 +179,7 @@ class remoteManager(): def resetSettings(self): self.env['runtime']['settingsManager'].resetSettingArgDict() def setSettings(self, settingsArgs): - allowSettings = self.env['runtime']['settingsManager'].getSetting('remote', 'allowSettings').upper().split(',') - - self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs, allowSettings) + self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs) def handleRemoteIncomming(self, eventData): if not eventData: return diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 021d1267..e7ee9c66 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -86,9 +86,7 @@ settingsData = { 'port': 22447, 'socketpath':'/tmp/', 'enableSettingsRemote': True, - 'allowSettings': 'barrier#enabled', 'enableCommandRemote': True, - 'allowCommands': 'say,interrupt,window,resetwindow', }, 'barrier':{ 'enabled': True, diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index a4b8d52e..8df06a54 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -87,10 +87,10 @@ class settingsManager(): value = '' try: value = self.settingArgDict[section.lower()][setting.lower()] - return value + return value except: pass - try: + try: value = self.env['settings'].get(section, setting) except: value = str(self.settings[section][setting]) @@ -100,7 +100,7 @@ class settingsManager(): value = 0 try: value = int(self.settingArgDict[section.lower()][setting.lower()]) - return value + return value except Exception as e: pass try: @@ -113,9 +113,9 @@ class settingsManager(): value = 0.0 try: value = float(self.settingArgDict[section.lower()][setting.lower()]) - return value + return value except Exception as e: - pass + pass try: value = self.env['settings'].getfloat(section, setting) except: @@ -160,7 +160,7 @@ class settingsManager(): try: self.env['runtime'][driverType].shutdown() except Exception as e: - pass + pass del self.env['runtime'][driverType] def setFenrirKeys(self, keys): @@ -185,21 +185,14 @@ class settingsManager(): except KeyError: self.settingArgDict[section] = {} self.settingArgDict[section][option] = str(value) - - def parseSettingArgs(self, settingArgs, allowSettings = None): + + def parseSettingArgs(self, settingArgs): for optionElem in settingArgs.split(';'): if len(optionElem.split('#',1)) != 2: continue if len(optionElem.split('#',1)[1].split('=',1)) != 2: continue - allowed = False - if allowSettings: - for a in allowSettings: - if a in optionElem: - allowed = True - if not allowed: - continue - + section = str(optionElem.split('#',1)[0]).lower() option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower() value = optionElem.split('#',1)[1].split('=',1)[1] @@ -288,13 +281,13 @@ class settingsManager(): environment['runtime']['memoryManager'].initialize(environment) environment['runtime']['attributeManager'] = attributeManager.attributeManager() - environment['runtime']['attributeManager'].initialize(environment) + environment['runtime']['attributeManager'].initialize(environment) environment['runtime']['eventManager'] = eventManager.eventManager() - environment['runtime']['eventManager'].initialize(environment) + environment['runtime']['eventManager'].initialize(environment) environment['runtime']['processManager'] = processManager.processManager() - environment['runtime']['processManager'].initialize(environment) + environment['runtime']['processManager'].initialize(environment) environment['runtime']['outputManager'] = outputManager.outputManager() environment['runtime']['outputManager'].initialize(environment) From a97c31577a6439de593f7fe46b60e6744555ddc6 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 22:23:27 +0200 Subject: [PATCH 28/33] add setting save --- src/fenrirscreenreader/core/remoteManager.py | 15 +++++++++++++++ src/fenrirscreenreader/core/settingsManager.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 9be43ea0..0d9c8b47 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -43,6 +43,7 @@ class remoteManager(): # setting controll self.settingConst = 'SETTING ' self.setSettingConst = 'SET ' + self.saveSettingConst = 'SAVE ' self.resetSettingConst = 'RESET' def initialize(self, environment): self.env = environment @@ -132,6 +133,10 @@ class remoteManager(): if upperSettingsText.startswith(self.setSettingConst): parameterText = settingsText[len(self.setSettingConst):] self.setSettings(parameterText) + # save setting + if upperSettingsText.startswith(self.saveSettingConst): + parameterText = settingsText[len(self.saveSettingConst):] + self.saveSettings(parameterText) # reset setting if upperSettingsText.startswith(self.resetSettingConst): self.resetSettings() @@ -173,9 +178,19 @@ class remoteManager(): def resetWindow(self): self.env['runtime']['cursorManager'].clearWindowForApplication() def say(self, text): + if not text: + return + if text == '': + return self.env['runtime']['outputManager'].speakText(text) def interruptSpeech(self): self.env['runtime']['outputManager'].interruptOutput() + def saveSettings(self, settingConfigPath): + if not settingConfigPath: + return + if settingConfigPath == '': + return + self.env['runtime']['settingsManager'].saveSettings(settingConfigPath) def resetSettings(self): self.env['runtime']['settingsManager'].resetSettingArgDict() def setSettings(self, settingsArgs): diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 8df06a54..bf572eed 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -78,7 +78,21 @@ class settingsManager(): self.env['settings'] = ConfigParser() self.env['settings'].read(settingConfigPath) return True + def saveSettings(self, settingConfigPath): + # set opt dict here + # save file + try: + #print('file: ',settingConfigPath) + for section, settings in self.settingArgDict.items(): + for setting, value in settings.items(): + #print(section, setting, value) + self.env['settings'].set(section, setting, value) + #print('full',self.env['settings']) + configFile = open('/tmp/settings.conf', 'w') + self.env['settings'].write(configFile) + except Exception as e: + print(e) def setSetting(self, section, setting, value): self.setOptionArgDict(section, setting, value) #self.env['settings'].set(section, setting, value) From 450dc681fa476c80a7c900543bfb751a9d789948 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 22:25:40 +0200 Subject: [PATCH 29/33] add setting save --- src/fenrirscreenreader/core/settingsManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index bf572eed..d061a058 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -89,7 +89,7 @@ class settingsManager(): self.env['settings'].set(section, setting, value) #print('full',self.env['settings']) - configFile = open('/tmp/settings.conf', 'w') + configFile = open(settingConfigPath, 'w') self.env['settings'].write(configFile) except Exception as e: print(e) From 4482610c5bdd68f5b10d7ef185f0bded9825c7b2 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 22:29:20 +0200 Subject: [PATCH 30/33] add setting save --- src/fenrirscreenreader/core/settingsManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index d061a058..0e183e3d 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -92,7 +92,7 @@ class settingsManager(): configFile = open(settingConfigPath, 'w') self.env['settings'].write(configFile) except Exception as e: - print(e) + self.env['runtime']['debug'].writeDebugOut('saveSettings: save settingsfile:' + settingConfigPath + 'failed. Error:' + str(e), debug.debugLevel.ERROR) def setSetting(self, section, setting, value): self.setOptionArgDict(section, setting, value) #self.env['settings'].set(section, setting, value) From 4aea52a75ca55e1b2a1a95d27268ea220231de1d Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 22:33:15 +0200 Subject: [PATCH 31/33] add setting save --- src/fenrirscreenreader/core/remoteManager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 0d9c8b47..7258ba45 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -19,6 +19,7 @@ settings: settings set section#setting=value[,section#setting=value] setting set speech#voice=de setting reset +setting save /path/settings.conf command: command say this is a test command interrupt From 208e184026cb2b6fd78a1ec94d492e049801e3ed Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 22:35:57 +0200 Subject: [PATCH 32/33] add setting save --- realese nots/1.9.3 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/realese nots/1.9.3 b/realese nots/1.9.3 index 8c69eb7f..1c2e98e5 100644 --- a/realese nots/1.9.3 +++ b/realese nots/1.9.3 @@ -2,13 +2,12 @@ - add remote manager - remote manager: TCP connection - remote manager: UNIX Socket connection(default) -- remote manager: set settings set a setting (-o syntax) -- remote manager: reset settings -- remote Manager: say command (say something) -- remote manager: interrupt command (interrupt current speech) -- remote manager: window command (to define window) -- remote manager: resetwindow command (to reset window) -- remote manager: settings filter (only allow things in list) -- remote manager: command filter (only allow things in list) +- remote manager: set settings set a setting (-o syntax) "setting set sound#enabled=False" +- remote manager: reset settings "setting reset" +- remote manager: save settings "setting save /path/settings.conf" +- remote Manager: say command (say something) "command say this is a test" +- remote manager: interrupt command (interrupt current speech) "command interrupt" +- remote manager: window command (to define window) "command window startX startY endX endY" +- remote manager: resetwindow command (to reset window) "command resetwindow" - settings: store settings more centralized - variouse speedups and bugfixes From f83081fb060818e787bfda75cf940aa341838bfc Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 8 Sep 2018 23:15:18 +0200 Subject: [PATCH 33/33] change permission after write --- src/fenrirscreenreader/core/remoteManager.py | 2 +- src/fenrirscreenreader/core/settingsManager.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 7258ba45..18ba6207 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -31,7 +31,7 @@ from fenrirscreenreader.core.eventData import fenrirEventType import time import select import socket -import os, os.path, sys, stat +import os, os.path class remoteManager(): def __init__(self): diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 0e183e3d..a39c73ca 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -5,6 +5,7 @@ # By Chrys, Storm Dragon, and contributers. import os, inspect + currentdir = os.path.dirname(os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe())))) fenrirPath = os.path.dirname(currentdir) @@ -91,6 +92,8 @@ class settingsManager(): configFile = open(settingConfigPath, 'w') self.env['settings'].write(configFile) + configFile.close() + os.chmod(settingConfigPath, 0o666) except Exception as e: self.env['runtime']['debug'].writeDebugOut('saveSettings: save settingsfile:' + settingConfigPath + 'failed. Error:' + str(e), debug.debugLevel.ERROR) def setSetting(self, section, setting, value):