diff --git a/src/fenrir-package/commands/onInput/10000-shut_up.py b/src/fenrir-package/commands/onInput/10000-shut_up.py index 6444e454..26d2420f 100644 --- a/src/fenrir-package/commands/onInput/10000-shut_up.py +++ b/src/fenrir-package/commands/onInput/10000-shut_up.py @@ -4,8 +4,11 @@ class command(): def __init__(self): pass def run(self, environment): - if environment['screenData']['newDelta'] != environment['screenData']['oldDelta']: - environment['runtime']['outputManager'].interruptOutput(environment) + if environment['screenData']['newCursor'] == environment['screenData']['oldCursor'] and\ + environment['screenData']['newDelta'] == environment['screenData']['oldDelta']: + return environment + environment['runtime']['outputManager'].interruptOutput(environment) + print('10000-shut_up.py') return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/onInput/50000-speak_incomming.py b/src/fenrir-package/commands/onInput/50000-speak_incomming.py deleted file mode 100644 index 2fd954c4..00000000 --- a/src/fenrir-package/commands/onInput/50000-speak_incomming.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/python - -class command(): - def __init__(self): - pass - def run(self, environment): - return environment - if environment['screenData']['newCursor'] != environment['screenData']['oldCursor']: - print(environment['screenData']['newCursor'] != environment['screenData']['oldCursor']) - return environment - if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \ - environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: - environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], Interrupt=False) - return environment - def setCallback(self, callback): - pass - def shutdown(self): - pass diff --git a/src/fenrir-package/commands/onInput/54000-read_line_if_cursor_change_horizontal.py b/src/fenrir-package/commands/onInput/54000-read_line_if_cursor_change_horizontal.py deleted file mode 100644 index 8dbbf565..00000000 --- a/src/fenrir-package/commands/onInput/54000-read_line_if_cursor_change_horizontal.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/python - -class command(): - def __init__(self): - pass - def run(self, environment): - if environment['screenData']['newCursor']['x'] == environment['screenData']['oldCursor']['x'] or\ - environment['screenData']['newCursor']['y'] != environment['screenData']['oldCursor']['y']: - return environment - if environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']][environment['screenData']['newCursor']['x']].replace(" ","").replace("\n","").replace("\t","") == '': - environment['runtime']['outputManager'].speakText(environment, "blank") - else: - environment['runtime']['outputManager'].speakText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']][environment['screenData']['newCursor']['x']]) - return environment - def setCallback(self, callback): - pass - def shutdown(self): - pass diff --git a/src/fenrir-package/commands/onInput/57000-read_line_if_cursor_change_vertical.py b/src/fenrir-package/commands/onInput/57000-read_line_if_cursor_change_vertical.py deleted file mode 100644 index f9f3f202..00000000 --- a/src/fenrir-package/commands/onInput/57000-read_line_if_cursor_change_vertical.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/python - -class command(): - def __init__(self): - pass - def run(self, environment): - if environment['screenData']['newCursor']['y'] == environment['screenData']['oldCursor']['y']: - return environment - if environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']].replace(" ","").replace("\n","").replace("\t","") == '': - environment['runtime']['outputManager'].speakText(environment, "blank") - else: - environment['runtime']['outputManager'].speakText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']]) - return environment - def setCallback(self, callback): - pass - def shutdown(self): - pass diff --git a/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py b/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py index 444162fa..1518e038 100644 --- a/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py +++ b/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py @@ -4,9 +4,10 @@ class command(): def __init__(self): pass def run(self, environment): - if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \ - environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: - environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta']) + if environment['screenData']['newDelta'] == environment['screenData']['oldDelta'] and \ + environment['screenData']['newTTY'] == environment['screenData']['oldTTY']: + return environment + environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'],len(environment['screenData']['newDelta']) == 1) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 5cde1347..45e24688 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -11,10 +11,12 @@ class inputManager(): #for dev in self.devices.values(): print(dev) def getKeyPressed(self, environment): + timeout = True try: - r, w, x = select(self.devices, [], []) + r, w, x = select(self.devices, [], [],0.5) environment['runtime']['globalLock'].acquire(True) if r != []: + timeout = False for fd in r: for event in self.devices[fd].read(): if event.type == evdev.ecodes.EV_KEY: @@ -28,7 +30,7 @@ class inputManager(): except: pass environment['input']['currShortcutString'] = self.getShortcutString(environment) - return environment + return environment, timeout def getShortcutString(self, environment): if environment['input']['currShortcut'] == {}: diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 39fc02c5..2e5d5bb7 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -15,24 +15,25 @@ from core import settingsManager class fenrir(): def __init__(self): - self.threadHandleInput = None + self.threadonInput = Thread(target=self.onInput, args=()) self.environment = settingsManager.settingsManager().initFenrirConfig() signal.signal(signal.SIGINT, self.captureSignal) def proceed(self): - self.threadHandleInput = Thread(target=self.handleInput, args=()) - self.threadHandleInput.start() + self.threadonInput.start() while(self.environment['generalInformation']['running']): self.updateScreen() self.shutdown() - def handleInput(self): + def onInput(self): while(self.environment['generalInformation']['running']): - self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment) + self.environment, timeout = self.environment['runtime']['inputManager'].getKeyPressed(self.environment) self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment, 'onInput') - self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') + if not timeout: + self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') + self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') if self.environment['commandInfo']['currCommand'] != '': self.environment['input']['currShortcut'] = {} self.environment['input']['currShortcutString'] = '' @@ -40,6 +41,7 @@ class fenrir(): self.environment['runtime']['globalLock'].release() def updateScreen(self): + return self.environment['runtime']['globalLock'].acquire(True) self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment,'updateScreen') self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') @@ -48,7 +50,7 @@ class fenrir(): def handleCommands(self): if (self.environment['commandInfo']['currCommand'] != '') and \ - (time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.02): + (time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.01): self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands') def shutdown(self): diff --git a/src/fenrir-package/screen/linux.py b/src/fenrir-package/screen/linux.py index e6a811e1..16917d4b 100644 --- a/src/fenrir-package/screen/linux.py +++ b/src/fenrir-package/screen/linux.py @@ -13,15 +13,6 @@ class screen(): self.textWrapper = textwrap.TextWrapper() self.textWrapper.drop_whitespace = False def analyzeScreen(self, environment, trigger='updateScreen'): - # set new "old" values - environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes'] - environment['screenData']['oldContentText'] = environment['screenData']['newContentText'] - environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib'] - environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x'] - environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y'] - environment['screenData']['oldTTY'] = environment['screenData']['newTTY'] - environment['screenData']['oldDelta'] = environment['screenData']['newDelta'] - newTTY = environment['screenData']['newTTY'] # read screen currTTY = open('/sys/devices/virtual/tty/tty0/active','r') newTTY = currTTY.read()[3:-1] @@ -35,11 +26,20 @@ class screen(): return environment except: return environment - if trigger != 'onInput': # so we already moved the cursor and is not input -> screenchanges was faster + if trigger != 'onInput' and False: # so we already moved the cursor and is not input -> screenUpdate was faster if ((newContentBytes[2] != environment['screenData']['oldCursor']['x']) or\ (newContentBytes[3] != environment['screenData']['oldCursor']['y'])) and\ (newTTY == environment['screenData']['oldTTY']): return environment + # set new "old" values + environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes'] + environment['screenData']['oldContentText'] = environment['screenData']['newContentText'] + environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib'] + environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x'] + environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y'] + environment['screenData']['oldTTY'] = environment['screenData']['newTTY'] + environment['screenData']['oldDelta'] = environment['screenData']['newDelta'] + environment['screenData']['newTTY'] = newTTY environment['screenData']['newContentBytes'] = newContentBytes # get metadata like cursor or screensize @@ -47,12 +47,9 @@ class screen(): environment['screenData']['columns'] = int( environment['screenData']['newContentBytes'][1]) environment['screenData']['newCursor']['x'] = int( environment['screenData']['newContentBytes'][2]) environment['screenData']['newCursor']['y'] = int( environment['screenData']['newContentBytes'][3]) - # analyze content - environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('WINDOWS-1250')) + environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode("ascii", "replace")) environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2] - if environment['screenData']['newContentText'].count('\n') != 0: - environment['screenData']['newContentText'] = environment['screenData']['newContentText'].replace('\n',"") environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2] if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: