From acd10812c68f48863c2fe2a5c6df0f1dd0ae7fbd Mon Sep 17 00:00:00 2001 From: chrys Date: Thu, 25 Aug 2016 01:42:46 +0200 Subject: [PATCH] polish clipboard handling, clean ups, more mark functions --- .../commands/copy_marked_to_clipboard.py | 17 +++++--- .../commands/commands/curr_char.py | 2 +- .../commands/commands/curr_line.py | 2 +- .../commands/commands/curr_word.py | 2 +- .../commands/commands/last_incomming.py | 5 +-- .../commands/linux_paste_clipboard.py | 2 +- .../commands/commands/marked_text.py | 4 +- .../commands/commands/next_char.py | 2 +- .../commands/commands/next_line.py | 2 +- .../commands/commands/next_word.py | 2 +- .../commands/commands/prev_char.py | 2 +- .../commands/commands/prev_line.py | 2 +- .../commands/commands/prev_word.py | 2 +- src/fenrir-package/utils/mark_utils.py | 40 ++++++++----------- 14 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/fenrir-package/commands/commands/copy_marked_to_clipboard.py b/src/fenrir-package/commands/commands/copy_marked_to_clipboard.py index 6619e8fc..c6154c39 100644 --- a/src/fenrir-package/commands/commands/copy_marked_to_clipboard.py +++ b/src/fenrir-package/commands/commands/copy_marked_to_clipboard.py @@ -1,11 +1,13 @@ #!/bin/python -from utils import mark_utils - +try: + from utils import mark_utils +except Exception as e: + print(e) class command(): def __init__(self): pass def run(self, environment): - print('run') + if (environment['commandBuffer']['Marks']['1'] == None) or \ (environment['commandBuffer']['Marks']['2'] == None): environment['runtime']['outputManager'].presentText(environment, "two marks needed", interrupt=True) @@ -17,12 +19,15 @@ class command(): if environment['commandBuffer']['Marks']['3'] != None: endMark = environment['commandBuffer']['Marks']['3'].copy() - marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'].split('\n')) + marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText']) environment['commandBuffer']['clipboard'] = [marked] + environment['commandBuffer']['clipboard'][:9] environment['commandBuffer']['currClipboard'] = 0 - - if marked.strip(" \t\n") == '': + environment['commandBuffer']['Marks']['1'] = None + environment['commandBuffer']['Marks']['2'] = None + environment['commandBuffer']['Marks']['3'] = None + + if marked.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True) diff --git a/src/fenrir-package/commands/commands/curr_char.py b/src/fenrir-package/commands/commands/curr_char.py index de845e9b..522452fa 100644 --- a/src/fenrir-package/commands/commands/curr_char.py +++ b/src/fenrir-package/commands/commands/curr_char.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ char_utils.getCurrentChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currChar.strip(" \t\n") == '': + if currChar.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank" ,interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currChar ,interrupt=True) diff --git a/src/fenrir-package/commands/commands/curr_line.py b/src/fenrir-package/commands/commands/curr_line.py index 538a0fb4..41aeef24 100644 --- a/src/fenrir-package/commands/commands/curr_line.py +++ b/src/fenrir-package/commands/commands/curr_line.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ line_utils.getCurrentLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currLine.strip(" \t\n") == '': + if currLine.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True) diff --git a/src/fenrir-package/commands/commands/curr_word.py b/src/fenrir-package/commands/commands/curr_word.py index 94f88798..8387a9a0 100644 --- a/src/fenrir-package/commands/commands/curr_word.py +++ b/src/fenrir-package/commands/commands/curr_word.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ word_utils.getCurrentWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currWord.strip(" \t\n") == '': + if currWord.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) diff --git a/src/fenrir-package/commands/commands/last_incomming.py b/src/fenrir-package/commands/commands/last_incomming.py index 3fe17d2d..a8d9801c 100644 --- a/src/fenrir-package/commands/commands/last_incomming.py +++ b/src/fenrir-package/commands/commands/last_incomming.py @@ -4,10 +4,7 @@ class command(): def __init__(self): pass def run(self, environment): - if environment['screenData']['newDelta'].strip(" \t\n") == '': - environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) - else: - environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True) + environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/linux_paste_clipboard.py b/src/fenrir-package/commands/commands/linux_paste_clipboard.py index 6ddb0cbc..03f99ea9 100644 --- a/src/fenrir-package/commands/commands/linux_paste_clipboard.py +++ b/src/fenrir-package/commands/commands/linux_paste_clipboard.py @@ -15,7 +15,7 @@ class command(): with open("/dev/tty" + environment['screenData']['newTTY'], 'w') as fd: for c in environment['commandBuffer']['clipboard'][currClipboard]: fcntl.ioctl(fd, termios.TIOCSTI, c) - time.sleep(0.01) + time.sleep(0.02) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/marked_text.py b/src/fenrir-package/commands/commands/marked_text.py index 22245acc..f753bfba 100644 --- a/src/fenrir-package/commands/commands/marked_text.py +++ b/src/fenrir-package/commands/commands/marked_text.py @@ -16,9 +16,9 @@ class command(): if environment['commandBuffer']['Marks']['3'] != None: endMark = environment['commandBuffer']['Marks']['3'].copy() - marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'].split('\n')) + marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText']) - if marked.strip(" \t\n") == '': + if marked.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True) diff --git a/src/fenrir-package/commands/commands/next_char.py b/src/fenrir-package/commands/commands/next_char.py index a1269dec..8d56b49c 100644 --- a/src/fenrir-package/commands/commands/next_char.py +++ b/src/fenrir-package/commands/commands/next_char.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ char_utils.getNextChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currChar.strip(" \t\n") == '': + if currChar.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True) diff --git a/src/fenrir-package/commands/commands/next_line.py b/src/fenrir-package/commands/commands/next_line.py index 4d1d0405..3a9d2f9c 100644 --- a/src/fenrir-package/commands/commands/next_line.py +++ b/src/fenrir-package/commands/commands/next_line.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ line_utils.getNextLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currLine.strip(" \t\n") == '': + if currLine.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True) diff --git a/src/fenrir-package/commands/commands/next_word.py b/src/fenrir-package/commands/commands/next_word.py index ca7e5038..fed0bb63 100644 --- a/src/fenrir-package/commands/commands/next_word.py +++ b/src/fenrir-package/commands/commands/next_word.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ word_utils.getNextWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currWord.strip(" \t\n") == '': + if currWord.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) diff --git a/src/fenrir-package/commands/commands/prev_char.py b/src/fenrir-package/commands/commands/prev_char.py index 0312e56a..73cecad9 100644 --- a/src/fenrir-package/commands/commands/prev_char.py +++ b/src/fenrir-package/commands/commands/prev_char.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ char_utils.getPrevChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currChar.strip(" \t\n") == '': + if currChar.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True) diff --git a/src/fenrir-package/commands/commands/prev_line.py b/src/fenrir-package/commands/commands/prev_line.py index 4b3cbc97..8cc223ff 100644 --- a/src/fenrir-package/commands/commands/prev_line.py +++ b/src/fenrir-package/commands/commands/prev_line.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ line_utils.getPrevLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currLine.strip(" \t\n") == '': + if currLine.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True) diff --git a/src/fenrir-package/commands/commands/prev_word.py b/src/fenrir-package/commands/commands/prev_word.py index 8cb453ab..4cc7db43 100644 --- a/src/fenrir-package/commands/commands/prev_word.py +++ b/src/fenrir-package/commands/commands/prev_word.py @@ -12,7 +12,7 @@ class command(): environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ word_utils.getPrevWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) - if currWord.strip(" \t\n") == '': + if currWord.strip() == '': environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) diff --git a/src/fenrir-package/utils/mark_utils.py b/src/fenrir-package/utils/mark_utils.py index 4235da1c..d82eda19 100644 --- a/src/fenrir-package/utils/mark_utils.py +++ b/src/fenrir-package/utils/mark_utils.py @@ -3,12 +3,10 @@ def getTextBetweenMarks(firstMark, secondMark, inText): if inText == None: return '' - if isinstance(inText, list): + if not isinstance(inText, list): inText = inText.split('\n') if len(inText) < 1: return '' - if inText == '': - return '' if firstMark == None: return '' if secondMark == None: @@ -19,30 +17,30 @@ def getTextBetweenMarks(firstMark, secondMark, inText): else: endMark = firstMark.copy() startMark = secondMark.copy() - currX = startMark['x'] - currY = startMark['y'] textPart = '' - while currY <= endMark['y'] and currY <= len(inText): - if startMark['y'] == endMark['y']: - textPart += inText[currY][currX:endMark['x'] + 1] - else: + if startMark['y'] == endMark['y']: + textPart += inText[startMark['y']][startMark['x']:endMark['x'] + 1] + else: + currY = startMark['y'] + while currY <= endMark['y']: if currY < endMark['y']: - textPart += inText[currY][currX:] - if len(textPart) - len(textPart[::-1].strip()) > 0: - textPart = textPart[:len(textPart[::-1].strip())] + "\n" + if currY == startMark['y']: + textPart += inText[currY][startMark['x']:] + else: + textPart += inText[currY] + if len(inText[currY].strip()) != 0: + if len(textPart) - len(textPart[::-1].strip()) > 0: + textPart = textPart[:len(textPart[::-1].strip())] + "\n" + else: + textPart += '\n' else: - textPart += inText[currY][:currX + 1] - currX = 0 - currY += 1 + textPart += inText[currY][:endMark['x'] + 1] + currY += 1 return textPart def getTextBeforeMark(mark, inText): if inText == None: return '' - if isinstance(inText, list): - inText = inText.split('\n') - if len(inText) < 1: - return '' if mark == None: return '' return getTextBetweenMarks({'x':0,'y':0}, mark, inText) @@ -50,10 +48,6 @@ def getTextBeforeMark(mark, inText): def getTextAfterMark(mark, inText): if inText == None: return '' - if isinstance(inText, list): - inText = inText.split('\n') - if len(inText) < 1: - return '' if mark == None: return '' return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText)