move some commands to onScreenUpdate (WIP)

This commit is contained in:
chrys 2017-06-30 19:37:50 +02:00
parent 16f4e3e981
commit 98ce582b15
13 changed files with 9 additions and 589 deletions

View File

@ -23,52 +23,7 @@ class command():
return 'No Description found'
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('time', 'enabled'):
return
onMinutes = self.env['runtime']['settingsManager'].getSetting('time', 'onMinutes')
delaySec = self.env['runtime']['settingsManager'].getSettingAsInt('time', 'delaySec')
# no need
if onMinutes == '' and delaySec <= 0:
return
onMinutes = onMinutes.split(',')
now = datetime.datetime.now()
# ignore onMinutes if there is a delaySec
if delaySec > 0:
if int((now-self.lastTime).total_seconds()) < delaySec:
return
else:
# shoul announce?
if not str(now.minute) in onMinutes:
return
# already announced?
if now.hour == self.lastTime.hour:
if now.minute == self.lastTime.minute:
return
dateFormat = self.env['runtime']['settingsManager'].getSetting('general', 'dateFormat')
dateString = datetime.datetime.strftime(now, dateFormat)
presentDate = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentDate') and \
self.lastDateString != dateString
presentTime = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentTime')
# no changed value to announce
if not (presentDate or presentTime):
return
timeFormat = self.env['runtime']['settingsManager'].getSetting('general', 'timeFormat')
timeString = datetime.datetime.strftime(now, timeFormat)
if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'interrupt'):
self.env['runtime']['outputManager'].interruptOutput()
if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'announce'):
self.env['runtime']['outputManager'].playSoundIcon('announce')
if presentTime:
# present the time
self.env['runtime']['outputManager'].presentText(_('Autotime: {0}').format(timeString), soundIcon='', interrupt=False)
# and date if changes
if presentDate:
self.env['runtime']['outputManager'].presentText(dateString , soundIcon='', interrupt=False)
self.lastDateString = dateString
self.lastTime = datetime.datetime.now()
self.lastTimeString = timeString
self.env['runtime']['screenDriver'].getSessionInformation()
def setCallback(self, callback):
pass

View File

@ -1,43 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
from utils import char_utils
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return ''
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'cursor'):
return
if self.env['runtime']['screenManager'].isScreenChange():
return
if self.env['runtime']['inputManager'].noKeyPressed():
return
# detect an change on the screen, we just want to cursor arround, so no change should appear
if self.env['runtime']['screenManager'].isDelta():
return
if self.env['runtime']['screenManager'].isNegativeDelta():
return
# is a vertical change?
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return
# is it a horizontal change?
if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
return
x, y, currChar = char_utils.getCurrentChar(self.env['screen']['newCursor']['x'], self.env['screen']['newCursor']['y'], self.env['screen']['newContentText'])
if not currChar.isspace():
self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,40 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'No Description found'
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'charEcho'):
return
# detect deletion or chilling
if self.env['screen']['newCursor']['x'] <= self.env['screen']['oldCursor']['x']:
return
# is there any change?
if not self.env['runtime']['screenManager'].isDelta():
return
# big changes are no char (but the value is bigger than one maybe the differ needs longer than you can type, so a little strange random buffer for now)
if len(self.env['screen']['newDelta']) > 3:
return
# filter unneded space on word begin
currDelta = self.env['screen']['newDelta']
if len(currDelta.strip()) != len(currDelta) and \
currDelta.strip() != '':
currDelta = currDelta.strip()
self.env['runtime']['outputManager'].presentText(currDelta, interrupt=True, ignorePunctuation=True, announceCapital=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,45 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
from utils import line_utils
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return ''
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'cursor'):
return
if self.env['runtime']['inputManager'].noKeyPressed():
return
if self.env['runtime']['screenManager'].isScreenChange():
return
# this leads to problems in vim -> status line change -> no announcement, so we do check the lengh as hack
if self.env['runtime']['screenManager'].isDelta():
if len(self.env['screen']['newDelta']) > 4:
return
# is a vertical change?
if not self.env['runtime']['cursorManager'].isCursorVerticalMove():
return
x, y, currLine = line_utils.getCurrentLine(self.env['screen']['newCursor']['x'], self.env['screen']['newCursor']['y'], self.env['screen']['newContentText'])
if currLine.isspace():
self.env['runtime']['outputManager'].presentText(_("blank"), soundIcon='EmptyLine', interrupt=True, flush=False)
else:
self.env['runtime']['outputManager'].presentText(currLine, interrupt=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,24 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return _('enables or disables tracking of highlighted')
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'):
return
self.env['runtime']['outputManager'].presentText(self.env['screen']['newAttribDelta'], soundIcon='', interrupt=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,57 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
from utils import word_utils
import string
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'No Description found'
def run(self):
# first place could not be the end of a word
if self.env['screen']['newCursor']['x'] == 0:
return
# is it enabled?
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'):
return
# just when cursor move worddetection is needed
if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
return
if self.env['runtime']['inputManager'].noKeyPressed():
return
# for now no new line
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return
# get the word
newContent = self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']]
x, y, currWord, endOfScreen, lineBreak = \
word_utils.getCurrentWord(self.env['screen']['newCursor']['x'], 0, newContent)
# currently writing
if self.env['runtime']['screenManager'].isDelta():
return
else:
# at the end of a word
if not newContent[self.env['screen']['newCursor']['x']].isspace():
return
if (x + len(currWord) != self.env['screen']['newCursor']['x']) and \
(x + len(currWord) != self.env['screen']['newCursor']['x']-1):
return
if currWord != '':
self.env['runtime']['outputManager'].presentText(currWord, interrupt=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,136 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
from utils import word_utils
import os, string
initialized = False
try:
import enchant
initialized = True
except:
pass
class command():
def __init__(self):
self.language = ''
self.spellChecker = ''
def initialize(self, environment):
self.env = environment
self.updateSpellLanguage()
def shutdown(self):
pass
def getDescription(self):
return 'No Description found'
def updateSpellLanguage(self):
if not initialized:
self.env['runtime']['outputManager'].presentText('pychant is not installed', interrupt=True)
return
self.spellChecker = enchant.Dict(self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage'))
self.language = self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage')
def run(self):
if not initialized:
return
if not self.env['runtime']['settingsManager'].getSettingAsBool('general', 'autoSpellCheck'):
return
if self.env['runtime']['inputManager'].noKeyPressed():
return
if self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') != self.language:
try:
self.updateSpellLanguage()
except:
return
# just when horizontal cursor move worddetection is needed
if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
return
# for now no new line
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return
# more than a keyecho?
if len(self.env['screen']['newDelta']) > 1:
return
# deletion
if self.env['runtime']['screenManager'].isNegativeDelta():
return
# first place could not be the end of a word
if self.env['screen']['newCursor']['x'] == 0:
return
# get the word (just for speedup only look at current line
newContent = self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']]
x, y, currWord, endOfScreen, lineBreak = word_utils.getCurrentWord(self.env['screen']['newCursor']['x'], 0, newContent)
# was this a typed word?
if self.env['runtime']['screenManager'].isDelta():
if not(newContent[self.env['screen']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screen']['oldCursor']['x']):
return
else:
currWord = currWord.strip(string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~')
else:
# or just arrow arround?
if not newContent[self.env['screen']['newCursor']['x']].isspace():
return
if (x + len(currWord) != self.env['screen']['newCursor']['x']) and \
(x + len(currWord) != self.env['screen']['newCursor']['x']-1):
return
# just on end of word
if self.env['screen']['newCursor']['x'] > 0:
if not newContent[self.env['screen']['oldCursor']['x'] - 1].lower() in string.ascii_lowercase:
return
# ignore bash buildins
if currWord in ['cd','fg','bg','alias','bind','dir','caller','buildin','command','declare','echo','enable','help','let','local','logout',\
'mapfile','printf','read','readarray','source','type','typeset','ulimit','unalias']:
return
# ignore the application name
if currWord.upper() == 'FENRIR':
return
if currWord[0] =='-':
return
if currWord[0] == '/':
return
if currWord[0] == '#':
return
if currWord.startswith('./'):
return
if '@' in currWord and '.' in currWord:
return
if currWord[0] == '@':
return
if currWord.isnumeric():
return
if currWord.isdecimal():
return
if currWord.isspace():
return
try:
if os.path.exists("/bin/"+currWord):
return
except:
pass
try:
if os.path.exists("/usr/bin/"+currWord):
return
except:
pass
try:
if os.path.exists("/sbin/"+currWord):
return
except:
pass
if not self.spellChecker.check(currWord):
self.env['runtime']['outputManager'].presentText(_('misspelled'), soundIcon='mispell', interrupt=False, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,49 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'No Description found'
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'charDeleteEcho'):
return
# detect typing or chilling
if self.env['screen']['newCursor']['x'] >= self.env['screen']['oldCursor']['x']:
return
# More than just a deletion happend
if self.env['runtime']['screenManager'].isDelta():
return
# no deletion
if not self.env['runtime']['screenManager'].isNegativeDelta():
return
if self.env['runtime']['inputManager'].noKeyPressed():
return
# too much for a single backspace...
# word begin produce a diff wiht len == 2 |a | others with 1 |a|
if len(self.env['screen']['newNegativeDelta']) > 2:
return
currNegativeDelta = self.env['screen']['newNegativeDelta']
if len(currNegativeDelta.strip()) != len(currNegativeDelta) and \
currNegativeDelta.strip() != '':
currNegativeDelta = currNegativeDelta.strip()
self.env['runtime']['outputManager'].presentText(currNegativeDelta, interrupt=True, ignorePunctuation=True, announceCapital=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,58 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return ''
def run(self):
if self.env['runtime']['inputManager'].noKeyPressed():
return
if self.env['screen']['newAttribDelta'] != '':
return
if self.env['runtime']['screenManager'].isScreenChange():
return
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return
if len(self.env['input']['currInput']) != 1:
return
if not self.env['input']['currInput'][0] in ['KEY_UP','KEY_DOWN']:
return
prevLine = self.env['screen']['oldContentText'].split('\n')[self.env['screen']['newCursor']['y']]
currLine = self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']]
if not currLine.isspace():
currPrompt = currLine.find('$')
rootPrompt = currLine.find('#')
if currPrompt <= 0:
if rootPrompt > 0:
currPrompt = rootPrompt
else:
announce = currLine
if currPrompt > 0:
remove_digits = str.maketrans('0123456789', ' ')
if prevLine[:currPrompt].translate(remove_digits) == currLine[:currPrompt].translate(remove_digits):
announce = currLine[currPrompt+1:]
else:
announce = currLine
if currLine.isspace():
self.env['runtime']['outputManager'].presentText(_("blank"), soundIcon='EmptyLine', interrupt=True, flush=False)
else:
self.env['runtime']['outputManager'].presentText(announce, interrupt=True, flush=False)
self.env['commandsIgnore']['onScreenUpdate']['CHAR_DELETE_ECHO'] = True
self.env['commandsIgnore']['onScreenUpdate']['CHAR_ECHO'] = True
self.env['commandsIgnore']['onScreenUpdate']['INCOMING_IGNORE'] = True
def setCallback(self, callback):
pass

View File

@ -1,41 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'No Description found'
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'autoReadIncoming'):
return
# is there something to read?
if not self.env['runtime']['screenManager'].isDelta():
return
# its a cursor movement (experimental) - maybe also check current shortcut string?
#if not '$' in self.env['screen']['newDelta'] and
# not '#' in self.env['screen']['newDelta']:
if abs(self.env['screen']['newCursor']['x'] - self.env['screen']['oldCursor']['x']) >= 1:
if len(self.env['screen']['newDelta'].strip(' \n\t0123456789')) <= 2:
return
if abs(self.env['screen']['newCursor']['y'] - self.env['screen']['oldCursor']['y']) == 1:
if len(self.env['screen']['newDelta'].strip(' \n\t0123456789')) <= 2:
return
self.env['runtime']['outputManager'].presentText(self.env['screen']['newDelta'], interrupt=False, flush=False)
def setCallback(self, callback):
pass

View File

@ -1,39 +0,0 @@
#!/bin/python
import time
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'No Description found'
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('promote', 'enabled'):
return
if self.env['runtime']['settingsManager'].getSetting('promote', 'list').strip(" \t\n") == '':
return
if self.env['screen']['newDelta'] == '':
return
if int(time.time() - self.env['input']['lastInputTime']) < self.env['runtime']['settingsManager'].getSettingAsInt('promote', 'inactiveTimeoutSec'):
return
if len(self.env['runtime']['settingsManager'].getSetting('promote', 'list')) == 0:
return
for promote in self.env['runtime']['settingsManager'].getSetting('promote', 'list').split(','):
if promote in self.env['screen']['newDelta']:
self.env['runtime']['outputManager'].playSoundIcon('PromotedText')
self.env['input']['lastInputTime'] = time.time()
return
def setCallback(self, callback):
pass

View File

@ -63,33 +63,31 @@ class fenrirManager():
self.environment['runtime']['inputManager'].clearEventBuffer()
if self.environment['input']['keyForeward'] > 0:
self.environment['input']['keyForeward'] -=1
self.environment['runtime']['screenManager'].update('onInput')
#self.environment['runtime']['screenManager'].update('onInput')
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
self.handleCommands()
def handleScreenChange(self):
self.environment['runtime']['screenManager'].update('onScreenChange')
'''
if self.environment['runtime']['applicationManager'].isApplicationChange():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \
self.environment['runtime']['applicationManager'].getPrevApplication(), \
self.environment['runtime']['applicationManager'].getCurrentApplication())
if not self.environment['runtime']['screenManager'].isScreenChange():
'''
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged')
def handleScreenUpdate(self):
s = time.time()
self.environment['runtime']['screenManager'].update('onUpdate')
'''
if self.environment['runtime']['applicationManager'].isApplicationChange():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \
self.environment['runtime']['applicationManager'].getPrevApplication(), \
self.environment['runtime']['applicationManager'].getCurrentApplication())
#if not self.environment['runtime']['screenManager'].isScreenChange():
'''
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
#print(time.time() -s)
def handlePlugInputDevice(self):

View File

@ -21,9 +21,8 @@ class screenManager():
self.env['runtime']['settingsManager'].shutdownDriver('screenDriver')
def update(self, trigger='onUpdate'):
if trigger == 'onScreenChange':
self.env['runtime']['screenDriver'].getCurrScreen()
if trigger == 'onScreenChange':
self.env['runtime']['screenDriver'].getSessionInformation()
self.env['screen']['oldApplication'] = self.env['screen']['newApplication']
if self.isScreenChange():