Most of the pep8 changes finished. Be careful, things may be horribly broken.
This commit is contained in:
@@ -7,111 +7,111 @@
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
||||
def getPrevChar(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
def get_prev_char(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if x - 1 < 0:
|
||||
if y - 1 >= 0:
|
||||
y -= 1
|
||||
x = len(wrappedLines[y]) - 1
|
||||
lineBreak = True
|
||||
x = len(wrapped_lines[y]) - 1
|
||||
line_break = True
|
||||
else:
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
else:
|
||||
x -= 1
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[y][x]
|
||||
return x, y, currChar, endOfScreen, lineBreak
|
||||
curr_char = ''
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[y][x]
|
||||
return x, y, curr_char, end_of_screen, line_break
|
||||
|
||||
|
||||
def getCurrentChar(currX, currY, currText):
|
||||
if currText == '':
|
||||
def get_current_char(curr_x, curr_y, curr_text):
|
||||
if curr_text == '':
|
||||
return -1, -1, ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char
|
||||
|
||||
|
||||
def getUpChar(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
currY -= 1
|
||||
if currY < 0:
|
||||
currY = 0
|
||||
def get_up_char(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_y -= 1
|
||||
if curr_y < 0:
|
||||
curr_y = 0
|
||||
else:
|
||||
endOfScreen = True
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
end_of_screen = True
|
||||
curr_char = ''
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char, end_of_screen
|
||||
|
||||
|
||||
def getDownChar(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
currY += 1
|
||||
if currY >= len(wrappedLines):
|
||||
currY = len(wrappedLines) - 1
|
||||
def get_down_char(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_y += 1
|
||||
if curr_y >= len(wrapped_lines):
|
||||
curr_y = len(wrapped_lines) - 1
|
||||
else:
|
||||
endOfScreen = True
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
end_of_screen = True
|
||||
curr_char = ''
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char, end_of_screen
|
||||
|
||||
|
||||
def getLastCharInLine(currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
def get_last_char_in_line(curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currX = len(wrappedLines[currY].rstrip()) - 1
|
||||
if currX < 0:
|
||||
currX = 0
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_x = len(wrapped_lines[curr_y].rstrip()) - 1
|
||||
if curr_x < 0:
|
||||
curr_x = 0
|
||||
curr_char = wrapped_lines[curr_y][curr_x]
|
||||
return curr_x, curr_y, curr_char
|
||||
|
||||
|
||||
def getNextChar(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
if x + 1 == len(wrappedLines[y]):
|
||||
if y + 1 <= len(wrappedLines) - 1:
|
||||
def get_next_char(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if x + 1 == len(wrapped_lines[y]):
|
||||
if y + 1 <= len(wrapped_lines) - 1:
|
||||
y += 1
|
||||
x = 0
|
||||
lineBreak = True
|
||||
line_break = True
|
||||
else:
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
else:
|
||||
x += 1
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[y][x]
|
||||
curr_char = ''
|
||||
if not end_of_screen:
|
||||
curr_char = wrapped_lines[y][x]
|
||||
|
||||
return x, y, currChar, endOfScreen, lineBreak
|
||||
return x, y, curr_char, end_of_screen, line_break
|
||||
|
||||
|
||||
def getPhonetic(currChar):
|
||||
if len(currChar) != 1:
|
||||
return currChar
|
||||
phoneticsDict = {
|
||||
def get_phonetic(curr_char):
|
||||
if len(curr_char) != 1:
|
||||
return curr_char
|
||||
phonetics_dict = {
|
||||
"A": "alpha", "B": "bravo", "C": "charlie", "D": "delta", "E": "echo",
|
||||
"F": "foxtrot", "G": "golf", "H": "hotel", "I": "india", "J": "juliet",
|
||||
"K": "kilo", "L": "lima", "M": "mike", "N": "november", "O": "oscar",
|
||||
@@ -120,33 +120,33 @@ def getPhonetic(currChar):
|
||||
"Y": "yankee", "Z": "zulu"
|
||||
}
|
||||
try:
|
||||
phonChar = phoneticsDict[currChar.upper()]
|
||||
if currChar.isupper():
|
||||
phonChar = phonChar[0].upper() + phonChar[1:]
|
||||
return phonChar
|
||||
phon_char = phonetics_dict[curr_char.upper()]
|
||||
if curr_char.isupper():
|
||||
phon_char = phon_char[0].upper() + phon_char[1:]
|
||||
return phon_char
|
||||
except Exception as e:
|
||||
# Utility function, no env access - return fallback
|
||||
return currChar
|
||||
return curr_char
|
||||
|
||||
|
||||
def presentCharForReview(
|
||||
def present_char_for_review(
|
||||
env,
|
||||
char,
|
||||
interrupt=True,
|
||||
announceCapital=True,
|
||||
announce_capital=True,
|
||||
flush=False):
|
||||
"""Present a character for explicit review commands only"""
|
||||
if char == ' ':
|
||||
if ' ' in env['punctuation']['PUNCTDICT']:
|
||||
announceChar = env['punctuation']['PUNCTDICT'][' ']
|
||||
announce_char = env['punctuation']['PUNCTDICT'][' ']
|
||||
else:
|
||||
announceChar = 'space'
|
||||
env['runtime']['outputManager'].presentText(
|
||||
announceChar, interrupt=interrupt, flush=flush)
|
||||
announce_char = 'space'
|
||||
env['runtime']['OutputManager'].present_text(
|
||||
announce_char, interrupt=interrupt, flush=flush)
|
||||
else:
|
||||
env['runtime']['outputManager'].presentText(
|
||||
env['runtime']['OutputManager'].present_text(
|
||||
char,
|
||||
interrupt=interrupt,
|
||||
ignorePunctuation=True,
|
||||
announceCapital=announceCapital,
|
||||
ignore_punctuation=True,
|
||||
announce_capital=announce_capital,
|
||||
flush=flush)
|
||||
|
@@ -10,13 +10,13 @@ from xdg import BaseDirectory
|
||||
|
||||
# Get configuration directory
|
||||
if len(sys.argv) > 1:
|
||||
configPath = sys.argv[1]
|
||||
config_path = sys.argv[1]
|
||||
elif os.geteuid() == 0:
|
||||
# Save settings system wide
|
||||
configPath = "/etc/fenrir.conf"
|
||||
config_path = "/etc/fenrir.conf"
|
||||
else:
|
||||
# Use local settings
|
||||
configPath = BaseDirectory.xdg_data_home + "/fenrir"
|
||||
if not os.path.exists(configPath):
|
||||
os.makedirs(configPath)
|
||||
configPath = configPath + "/fenrir.conf"
|
||||
config_path = BaseDirectory.xdg_data_home + "/fenrir"
|
||||
if not os.path.exists(config_path):
|
||||
os.makedirs(config_path)
|
||||
config_path = config_path + "/fenrir.conf"
|
||||
|
@@ -7,48 +7,48 @@
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
||||
def getPrevLine(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
def get_prev_line(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if y - 1 >= 0:
|
||||
y -= 1
|
||||
else:
|
||||
endOfScreen = True
|
||||
x = currX
|
||||
currLine = ''
|
||||
if not endOfScreen:
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine, endOfScreen
|
||||
end_of_screen = True
|
||||
x = curr_x
|
||||
curr_line = ''
|
||||
if not end_of_screen:
|
||||
curr_line = wrapped_lines[y]
|
||||
return x, y, curr_line, end_of_screen
|
||||
|
||||
|
||||
def getCurrentLine(currX, currY, currText):
|
||||
if currText == '':
|
||||
def get_current_line(curr_x, curr_y, curr_text):
|
||||
if curr_text == '':
|
||||
return -1, -1, ''
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
x = 0
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine
|
||||
curr_line = wrapped_lines[y]
|
||||
return x, y, curr_line
|
||||
|
||||
|
||||
def getNextLine(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
if y + 1 < len(wrappedLines):
|
||||
def get_next_line(curr_x, curr_y, curr_text):
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
if y + 1 < len(wrapped_lines):
|
||||
y += 1
|
||||
else:
|
||||
endOfScreen = True
|
||||
x = currX
|
||||
currLine = ''
|
||||
if not endOfScreen:
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine, endOfScreen
|
||||
end_of_screen = True
|
||||
x = curr_x
|
||||
curr_line = ''
|
||||
if not end_of_screen:
|
||||
curr_line = wrapped_lines[y]
|
||||
return x, y, curr_line, end_of_screen
|
||||
|
@@ -7,12 +7,12 @@
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
||||
def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
if inText is None:
|
||||
def get_text_between_marks(firstMark, secondMark, in_text):
|
||||
if in_text is None:
|
||||
return ''
|
||||
if not isinstance(inText, list):
|
||||
inText = inText.split('\n')
|
||||
if len(inText) < 1:
|
||||
if not isinstance(in_text, list):
|
||||
in_text = in_text.split('\n')
|
||||
if len(in_text) < 1:
|
||||
return ''
|
||||
if firstMark is None:
|
||||
return ''
|
||||
@@ -20,48 +20,48 @@ def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
return ''
|
||||
if (firstMark['y'] + 1) * (firstMark['x'] +
|
||||
1) <= (secondMark['y'] + 1) * (secondMark['x'] + 1):
|
||||
startMark = firstMark.copy()
|
||||
endMark = secondMark.copy()
|
||||
start_mark = firstMark.copy()
|
||||
end_mark = secondMark.copy()
|
||||
else:
|
||||
endMark = firstMark.copy()
|
||||
startMark = secondMark.copy()
|
||||
textPart = ''
|
||||
if startMark['y'] == endMark['y']:
|
||||
textPart += inText[startMark['y']][startMark['x']:endMark['x'] + 1]
|
||||
end_mark = firstMark.copy()
|
||||
start_mark = secondMark.copy()
|
||||
text_part = ''
|
||||
if start_mark['y'] == end_mark['y']:
|
||||
text_part += in_text[start_mark['y']][start_mark['x']:end_mark['x'] + 1]
|
||||
else:
|
||||
currY = startMark['y']
|
||||
while currY <= endMark['y']:
|
||||
if currY < endMark['y']:
|
||||
if currY == startMark['y']:
|
||||
textPart += inText[currY][startMark['x']:]
|
||||
curr_y = start_mark['y']
|
||||
while curr_y <= end_mark['y']:
|
||||
if curr_y < end_mark['y']:
|
||||
if curr_y == start_mark['y']:
|
||||
text_part += in_text[curr_y][start_mark['x']:]
|
||||
else:
|
||||
textPart += inText[currY]
|
||||
if len(inText[currY].strip()) != 0:
|
||||
if len(textPart) - len(textPart.rstrip()) > 0:
|
||||
textPart = textPart[:len(textPart.rstrip())] + "\n"
|
||||
text_part += in_text[curr_y]
|
||||
if len(in_text[curr_y].strip()) != 0:
|
||||
if len(text_part) - len(text_part.rstrip()) > 0:
|
||||
text_part = text_part[:len(text_part.rstrip())] + "\n"
|
||||
else:
|
||||
textPart += '\n'
|
||||
text_part += '\n'
|
||||
else:
|
||||
textPart += inText[currY][:endMark['x'] + 1]
|
||||
currY += 1
|
||||
return textPart
|
||||
text_part += in_text[curr_y][:end_mark['x'] + 1]
|
||||
curr_y += 1
|
||||
return text_part
|
||||
|
||||
|
||||
def getTextBeforeMark(mark, inText):
|
||||
if inText is None:
|
||||
def get_text_before_mark(mark, in_text):
|
||||
if in_text is None:
|
||||
return ''
|
||||
if mark is None:
|
||||
return ''
|
||||
return getTextBetweenMarks({'x': 0, 'y': 0}, mark, inText)
|
||||
return get_text_between_marks({'x': 0, 'y': 0}, mark, in_text)
|
||||
|
||||
|
||||
def getTextAfterMark(mark, inText):
|
||||
if inText is None:
|
||||
def get_text_after_mark(mark, in_text):
|
||||
if in_text is None:
|
||||
return ''
|
||||
if mark is None:
|
||||
return ''
|
||||
inText = inText.split('\n')
|
||||
return getTextBetweenMarks(
|
||||
in_text = in_text.split('\n')
|
||||
return get_text_between_marks(
|
||||
mark, {
|
||||
'x': len(
|
||||
inText[0]) - 1, 'y': len(inText) - 1}, inText)
|
||||
in_text[0]) - 1, 'y': len(in_text) - 1}, in_text)
|
||||
|
@@ -10,7 +10,7 @@ else: # Python 3.5+, no support for python < 3.3.
|
||||
import importlib.util
|
||||
|
||||
|
||||
def importModule(moduleName, moduleLocation):
|
||||
def import_module(moduleName, moduleLocation):
|
||||
if version in ["3.3", "3.4"]:
|
||||
return SourceFileLoader(moduleName, moduleLocation).load_module()
|
||||
else:
|
||||
|
@@ -12,7 +12,7 @@ import os
|
||||
from select import select
|
||||
|
||||
|
||||
def removeNonprintable(text):
|
||||
def remove_nonprintable(text):
|
||||
# Get the difference of all ASCII characters from the set of printable
|
||||
# characters
|
||||
nonprintable = set([chr(i) for i in range(128)]
|
||||
@@ -21,16 +21,16 @@ def removeNonprintable(text):
|
||||
return text.translate({ord(character): None for character in nonprintable})
|
||||
|
||||
|
||||
def insertNewlines(string, every=64):
|
||||
def insert_newlines(string, every=64):
|
||||
return '\n'.join(string[i:i + every] for i in range(0, len(string), every))
|
||||
|
||||
|
||||
def splitEvery(toSplit, every=64):
|
||||
def split_every(toSplit, every=64):
|
||||
return list(toSplit[i:i + every] for i in range(0, len(toSplit), every))
|
||||
|
||||
|
||||
def createScreenEventData(content):
|
||||
eventData = {
|
||||
def create_screen_event_data(content):
|
||||
event_data = {
|
||||
'bytes': content,
|
||||
'lines': content['lines'],
|
||||
'columns': content['columns'],
|
||||
@@ -44,24 +44,24 @@ def createScreenEventData(content):
|
||||
'attributes': content['attributes'],
|
||||
'screenUpdateTime': time.time(),
|
||||
}
|
||||
return eventData.copy()
|
||||
return event_data.copy()
|
||||
|
||||
|
||||
def hasMore(fd, timetout=0.05):
|
||||
def has_more(fd, timetout=0.05):
|
||||
r, _, _ = select([fd], [], [], timetout)
|
||||
return (fd in r)
|
||||
|
||||
|
||||
def hasMoreWhat(fdList, timetout=0.05):
|
||||
if not isinstance(fdList, list):
|
||||
def has_more_what(fd_list, timetout=0.05):
|
||||
if not isinstance(fd_list, list):
|
||||
return []
|
||||
elif fdList == []:
|
||||
elif fd_list == []:
|
||||
return []
|
||||
r, _, _ = select(fdList, [], [], timetout)
|
||||
r, _, _ = select(fd_list, [], [], timetout)
|
||||
return r
|
||||
|
||||
|
||||
def isValidShell(shell=''):
|
||||
def is_valid_shell(shell=''):
|
||||
if not isinstance(shell, str):
|
||||
return False
|
||||
if shell == '':
|
||||
@@ -73,22 +73,22 @@ def isValidShell(shell=''):
|
||||
return False
|
||||
except Exception as e:
|
||||
# Utility function, no env access - use fallback logging
|
||||
print(f'screen_utils isValidShell: Error checking shell {shell}: {e}')
|
||||
print(f'screen_utils is_valid_shell: Error checking shell {shell}: {e}')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def getShell():
|
||||
def get_shell():
|
||||
try:
|
||||
shell = os.environ["FENRIRSHELL"]
|
||||
if isValidShell(shell):
|
||||
if is_valid_shell(shell):
|
||||
return shell
|
||||
except Exception as e:
|
||||
# Utility function, no env access - continue silently
|
||||
pass
|
||||
try:
|
||||
shell = os.environ["SHELL"]
|
||||
if isValidShell(shell):
|
||||
if is_valid_shell(shell):
|
||||
return shell
|
||||
except Exception as e:
|
||||
# Utility function, no env access - continue silently
|
||||
@@ -102,11 +102,11 @@ def getShell():
|
||||
homedir, shell) = user.split(':')
|
||||
shell = shell.replace('\n', '')
|
||||
if username == getpass.getuser():
|
||||
if isValidShell(shell):
|
||||
if is_valid_shell(shell):
|
||||
return shell
|
||||
except Exception as e:
|
||||
# Utility function, no env access - continue silently
|
||||
pass
|
||||
if isValidShell('/bin/bash'):
|
||||
if is_valid_shell('/bin/bash'):
|
||||
return '/bin/bash'
|
||||
return '/bin/sh'
|
||||
|
@@ -8,118 +8,118 @@ from fenrirscreenreader.core import debug
|
||||
import string
|
||||
|
||||
|
||||
def getCurrentWord(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
if currText.strip(string.whitespace) == '':
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
x = currX
|
||||
y = currY
|
||||
currWord = ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currLine = wrappedLines[y]
|
||||
Found = False
|
||||
while (not Found):
|
||||
if not currLine[x] in string.whitespace:
|
||||
def get_current_word(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == '':
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
curr_word = ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_line = wrapped_lines[y]
|
||||
found = False
|
||||
while (not found):
|
||||
if not curr_line[x] in string.whitespace:
|
||||
if x == 0:
|
||||
Found = True
|
||||
found = True
|
||||
else:
|
||||
if currLine[x - 1] in string.whitespace:
|
||||
Found = True
|
||||
if not Found:
|
||||
if curr_line[x - 1] in string.whitespace:
|
||||
found = True
|
||||
if not found:
|
||||
if x - 1 < 0:
|
||||
if y - 1 < 0:
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
else:
|
||||
y -= 1
|
||||
currLine = wrappedLines[y]
|
||||
x = len(currLine) - 1
|
||||
lineBreak = True
|
||||
curr_line = wrapped_lines[y]
|
||||
x = len(curr_line) - 1
|
||||
line_break = True
|
||||
else:
|
||||
x -= 1
|
||||
if Found:
|
||||
currWord = currLine[x:]
|
||||
if found:
|
||||
curr_word = curr_line[x:]
|
||||
for d in string.whitespace:
|
||||
delimiterPos = currWord.find(d)
|
||||
if delimiterPos != -1:
|
||||
currWord = currWord[:delimiterPos]
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
return currX, currY, '', False, False
|
||||
delimiter_pos = curr_word.find(d)
|
||||
if delimiter_pos != -1:
|
||||
curr_word = curr_word[:delimiter_pos]
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
return curr_x, curr_y, '', False, False
|
||||
|
||||
|
||||
def getPrevWord(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
if currText.strip(string.whitespace) == '':
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
x, y, currWord, endOfScreen, lineBreakCurrWord = getCurrentWord(
|
||||
currX, currY, currText)
|
||||
if endOfScreen:
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
wrappedLines = currText.split('\n')
|
||||
currLine = wrappedLines[y]
|
||||
def get_prev_word(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == '':
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
x, y, curr_word, end_of_screen, line_break_curr_word = get_current_word(
|
||||
curr_x, curr_y, curr_text)
|
||||
if end_of_screen:
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_line = wrapped_lines[y]
|
||||
if x - 1 < 0:
|
||||
if y - 1 < 0:
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
else:
|
||||
y -= 1
|
||||
currLine = wrappedLines[y]
|
||||
x = len(currLine) - 1
|
||||
lineBreak = True
|
||||
curr_line = wrapped_lines[y]
|
||||
x = len(curr_line) - 1
|
||||
line_break = True
|
||||
else:
|
||||
x -= 1
|
||||
lineBreakCurrWord = lineBreak or lineBreakCurrWord
|
||||
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x, y, currText)
|
||||
lineBreak = lineBreak or lineBreakCurrWord
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
line_break_curr_word = line_break or line_break_curr_word
|
||||
x, y, curr_word, end_of_screen, line_break = get_current_word(x, y, curr_text)
|
||||
line_break = line_break or line_break_curr_word
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
|
||||
|
||||
def getNextWord(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
if currText.strip(string.whitespace) == '':
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
x = currX
|
||||
y = currY
|
||||
currWord = ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currLine = wrappedLines[y]
|
||||
Found = False
|
||||
while (not Found):
|
||||
if not Found:
|
||||
if x + 1 > len(currLine) - 1:
|
||||
if y + 1 > len(wrappedLines) - 1:
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
def get_next_word(curr_x, curr_y, curr_text):
|
||||
line_break = False
|
||||
end_of_screen = False
|
||||
if curr_text == '':
|
||||
return -1, -1, '', end_of_screen, line_break
|
||||
if curr_text.strip(string.whitespace) == '':
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
x = curr_x
|
||||
y = curr_y
|
||||
curr_word = ''
|
||||
wrapped_lines = curr_text.split('\n')
|
||||
curr_line = wrapped_lines[y]
|
||||
found = False
|
||||
while (not found):
|
||||
if not found:
|
||||
if x + 1 > len(curr_line) - 1:
|
||||
if y + 1 > len(wrapped_lines) - 1:
|
||||
line_break = False
|
||||
end_of_screen = True
|
||||
return curr_x, curr_y, '', end_of_screen, line_break
|
||||
else:
|
||||
y += 1
|
||||
currLine = wrappedLines[y]
|
||||
curr_line = wrapped_lines[y]
|
||||
x = 0
|
||||
lineBreak = True
|
||||
line_break = True
|
||||
else:
|
||||
x += 1
|
||||
if not currLine[x] in string.whitespace:
|
||||
if not curr_line[x] in string.whitespace:
|
||||
if x == 0:
|
||||
Found = True
|
||||
found = True
|
||||
else:
|
||||
if currLine[x - 1] in string.whitespace:
|
||||
Found = True
|
||||
if Found:
|
||||
currWord = currLine[x:]
|
||||
if curr_line[x - 1] in string.whitespace:
|
||||
found = True
|
||||
if found:
|
||||
curr_word = curr_line[x:]
|
||||
for d in string.whitespace:
|
||||
delimiterPos = currWord.find(d)
|
||||
if delimiterPos != -1:
|
||||
currWord = currWord[:delimiterPos]
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
return currX, currY, '', False, False
|
||||
delimiter_pos = curr_word.find(d)
|
||||
if delimiter_pos != -1:
|
||||
curr_word = curr_word[:delimiter_pos]
|
||||
return x, y, curr_word, end_of_screen, line_break
|
||||
return curr_x, curr_y, '', False, False
|
||||
|
Reference in New Issue
Block a user