port onInput to new parameters and modolarize some stuff

This commit is contained in:
chrys 2016-10-20 21:52:36 +02:00
parent 74aee822a3
commit 6668832eda
9 changed files with 61 additions and 42 deletions

View File

@ -5,6 +5,7 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
from core import debug from core import debug
from utils import char_utils
class command(): class command():
def __init__(self): def __init__(self):
@ -17,20 +18,22 @@ class command():
return '' return ''
def run(self): def run(self):
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: if self.environment['runtime']['screenManager'].isScreenChange():
return return
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
# detect an change on the screen, we just want to cursor arround, so no change should appear # detect an change on the screen, we just want to cursor arround, so no change should appear
if self.env['screenData']['newDelta'] != '': if self.environment['runtime']['screenManager'].isDelta():
return return
if self.env['screenData']['newNegativeDelta'] != '': if self.environment['runtime']['screenManager'].isNegativeDelta():
return
# is a vertical change?
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
return return
# is it a horizontal change? # is it a horizontal change?
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y'] or\ if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']:
return return
currChar = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']][self.env['screenData']['newCursor']['x']] x, y, currChar, endOfScreen = char_utils.getCurrentChar(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText'])
if not currChar.isspace(): if not currChar.isspace():
self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True) self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True)
def setCallback(self, callback): def setCallback(self, callback):

View File

@ -25,7 +25,7 @@ class command():
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
# is there any change? # is there any change?
if self.env['screenData']['newDelta'] == '': if not self.environment['runtime']['screenManager'].isDelta():
return 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) # 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['screenData']['newDelta']) > 3: if len(self.env['screenData']['newDelta']) > 3:

View File

@ -5,6 +5,7 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
from core import debug from core import debug
from utils import line_utils
class command(): class command():
def __init__(self): def __init__(self):
@ -19,15 +20,16 @@ class command():
def run(self): def run(self):
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: if self.environment['runtime']['screenManager'].isScreenChange():
return return
if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']: if self.environment['runtime']['screenManager'].isDelta():
return return
if self.env['screenData']['newCursor']['y'] == self.env['screenData']['oldCursor']['y']: # is a vertical change?
if not self.environment['runtime']['cursorManager'].isCursorVerticalMove():
return return
if self.env['runtime']['inputManager'].noKeyPressed():
return x, y, currLine, endOfScreen = line_utils.getCurrentLine(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText'])
currLine = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
if currLine.isspace(): if currLine.isspace():
self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True)
else: else:

View File

@ -18,27 +18,29 @@ class command():
return 'No Description found' return 'No Description found'
def run(self): def run(self):
# first place could not be the end of a word
if self.env['screenData']['newCursor']['x'] == 0:
return
# is it enabled?
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'):
return return
# just when cursor move worddetection is needed # just when cursor move worddetection is needed
if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
return return
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
# for now no new line # for now no new line
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
return return
# is there a delta bigger than keyecho?
if len(self.env['screenData']['newDelta']) > 1: if len(self.env['screenData']['newDelta']) > 1:
return return
# first place could not be the end of a word
if self.env['screenData']['newCursor']['x'] == 0:
return
# get the word # get the word
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']] newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent) x, y, currWord, endOfScreen = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
# was this a typed word? # was this a typed word?
if self.env['screenData']['newDelta'] != '': if self.env['screenData']['newDelta'] != '':
if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['oldCursor']['x']): if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['oldCursor']['x']):

View File

@ -45,23 +45,25 @@ class command():
return return
# just when cursor move worddetection is needed # just when cursor move worddetection is needed
if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
return return
# for now no new line # for now no new line
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
return return
# more than a keyecho?
if len(self.env['screenData']['newDelta']) > 1: if len(self.env['screenData']['newDelta']) > 1:
return return
if self.env['screenData']['newNegativeDelta'] != '': # deletion
if self.environment['runtime']['screenManager'].isNegativeDelta():
return return
# first place could not be the end of a word # first place could not be the end of a word
if self.env['screenData']['newCursor']['x'] == 0: if self.env['screenData']['newCursor']['x'] == 0:
return return
# get the word # get the word (just for speedup only look at current line
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']] newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent) x, y, currWord, endOfScreen = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
# was this a typed word? # was this a typed word?
if self.env['screenData']['newDelta'] != '': if self.env['screenData']['newDelta'] != '':
if not(newContent[self.env['screenData']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screenData']['oldCursor']['x']): if not(newContent[self.env['screenData']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screenData']['oldCursor']['x']):

View File

@ -25,13 +25,12 @@ class command():
return return
# More than just a deletion happend # More than just a deletion happend
if self.env['screenData']['newDelta'].strip() != '': if self.environment['runtime']['screenManager'].isDelta():
if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']:
return
if self.env['runtime']['inputManager'].noKeyPressed():
return return
# No deletion # no deletion
if self.env['screenData']['newNegativeDelta'] == '': if not self.environment['runtime']['screenManager'].isNegativeDelta():
return
if self.env['runtime']['inputManager'].noKeyPressed():
return return
# too much for a single backspace... # too much for a single backspace...
if len(self.env['screenData']['newNegativeDelta']) >= 2: if len(self.env['screenData']['newNegativeDelta']) >= 2:

View File

@ -47,6 +47,12 @@ class cursorManager():
return return
self.env['screenData']['oldCursorReview'] = None self.env['screenData']['oldCursorReview'] = None
self.env['screenData']['newCursorReview'] = None self.env['screenData']['newCursorReview'] = None
def isCursorHorizontalMove(self):
return self.env['screenData']['newCursor']['x'] != self.env['screenData']['oldCursor']['x']
def isCursorVerticalMove(self):
return self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']
def isReviewMode(self): def isReviewMode(self):
return self.env['screenData']['newCursorReview'] != None return self.env['screenData']['newCursorReview'] != None

View File

@ -44,7 +44,10 @@ class screenManager():
if not self.env['screenData']['oldTTY']: if not self.env['screenData']['oldTTY']:
return False return False
return self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY'] return self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']
def isDelta(self):
return self.env['screenData']['newDelta'] != ''
def isNegativeDelta(self):
return self.env['screenData']['newNegativeDelta'] != ''
def getWindowAreaInText(self, text): def getWindowAreaInText(self, text):
if not self.env['runtime']['cursorManager'].isApplicationWindowSet(): if not self.env['runtime']['cursorManager'].isApplicationWindowSet():
return text return text

View File

@ -27,7 +27,7 @@ def getPrevChar(currX,currY, currText):
def getCurrentChar(currX,currY, currText): def getCurrentChar(currX,currY, currText):
endOfScreen = False endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '' return -1, -1, '', endOfScreen
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
currChar = wrappedLines[currY][currX] currChar = wrappedLines[currY][currX]
return currX, currY, currChar, endOfScreen return currX, currY, currChar, endOfScreen
@ -40,6 +40,8 @@ def getUpChar(currX,currY, currText):
currY -= 1 currY -= 1
if currY < 0: if currY < 0:
currY = 0 currY = 0
else:
endOfScreen = True
currChar = wrappedLines[currY][currX] currChar = wrappedLines[currY][currX]
return currX, currY, currChar, endOfScreen return currX, currY, currChar, endOfScreen