To make Fenrir easier to approach for new developer, start code migration to be pep8 compliant.
This commit is contained in:
@ -6,14 +6,15 @@
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
def getPrevChar(currX,currY, currText):
|
||||
lineBreak = False
|
||||
|
||||
def getPrevChar(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
wrappedLines = currText.split('\n')
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
y = currY
|
||||
if x - 1 < 0:
|
||||
if y - 1 >= 0:
|
||||
y -= 1
|
||||
@ -26,63 +27,68 @@ def getPrevChar(currX,currY, currText):
|
||||
x -= 1
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[y][x]
|
||||
currChar = wrappedLines[y][x]
|
||||
return x, y, currChar, endOfScreen, lineBreak
|
||||
|
||||
def getCurrentChar(currX,currY, currText):
|
||||
|
||||
def getCurrentChar(currX, currY, currText):
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
wrappedLines = currText.split('\n')
|
||||
wrappedLines = currText.split('\n')
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar
|
||||
|
||||
def getUpChar(currX,currY, currText):
|
||||
|
||||
def getUpChar(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
wrappedLines = currText.split('\n')
|
||||
currY -= 1
|
||||
if currY < 0:
|
||||
currY = 0
|
||||
currY = 0
|
||||
else:
|
||||
endOfScreen = True
|
||||
endOfScreen = True
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
|
||||
def getDownChar(currX,currY, currText):
|
||||
|
||||
def getDownChar(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
wrappedLines = currText.split('\n')
|
||||
currY += 1
|
||||
if currY >= len(wrappedLines):
|
||||
currY = len(wrappedLines) -1
|
||||
currY = len(wrappedLines) - 1
|
||||
else:
|
||||
endOfScreen = True
|
||||
endOfScreen = True
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[currY][currX]
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
|
||||
|
||||
def getLastCharInLine(currY, currText):
|
||||
endOfScreen = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currX = len(wrappedLines[currY].rstrip())-1
|
||||
wrappedLines = currText.split('\n')
|
||||
currX = len(wrappedLines[currY].rstrip()) - 1
|
||||
if currX < 0:
|
||||
currX = 0
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar
|
||||
|
||||
def getNextChar(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
|
||||
def getNextChar(currX, currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen, lineBreak
|
||||
wrappedLines = currText.split('\n')
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
if x + 1 == len(wrappedLines[y]):
|
||||
@ -91,26 +97,27 @@ def getNextChar(currX,currY, currText):
|
||||
x = 0
|
||||
lineBreak = True
|
||||
else:
|
||||
lineBreak = False
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
else:
|
||||
x += 1
|
||||
x += 1
|
||||
currChar = ''
|
||||
if not endOfScreen:
|
||||
currChar = wrappedLines[y][x]
|
||||
currChar = wrappedLines[y][x]
|
||||
|
||||
return x, y, currChar, endOfScreen, lineBreak
|
||||
|
||||
|
||||
def getPhonetic(currChar):
|
||||
if len(currChar) != 1:
|
||||
return currChar
|
||||
phoneticsDict = {
|
||||
"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",
|
||||
"P":"papa", "Q":"quebec", "R":"romeo", "S":"sierra", "T":"tango",
|
||||
"U":"uniform", "V":"victor", "W":"whisky", "X":"x ray",
|
||||
"Y":"yankee", "Z":"zulu"
|
||||
"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",
|
||||
"P": "papa", "Q": "quebec", "R": "romeo", "S": "sierra", "T": "tango",
|
||||
"U": "uniform", "V": "victor", "W": "whisky", "X": "x ray",
|
||||
"Y": "yankee", "Z": "zulu"
|
||||
}
|
||||
try:
|
||||
phonChar = phoneticsDict[currChar.upper()]
|
||||
@ -121,14 +128,25 @@ def getPhonetic(currChar):
|
||||
# Utility function, no env access - return fallback
|
||||
return currChar
|
||||
|
||||
def presentCharForReview(env, char, interrupt=True, announceCapital=True, flush=False):
|
||||
|
||||
def presentCharForReview(
|
||||
env,
|
||||
char,
|
||||
interrupt=True,
|
||||
announceCapital=True,
|
||||
flush=False):
|
||||
"""Present a character for explicit review commands only"""
|
||||
if char == ' ':
|
||||
if ' ' in env['punctuation']['PUNCTDICT']:
|
||||
announceChar = env['punctuation']['PUNCTDICT'][' ']
|
||||
else:
|
||||
announceChar = 'space'
|
||||
env['runtime']['outputManager'].presentText(announceChar, interrupt=interrupt, flush=flush)
|
||||
env['runtime']['outputManager'].presentText(
|
||||
announceChar, interrupt=interrupt, flush=flush)
|
||||
else:
|
||||
env['runtime']['outputManager'].presentText(char, interrupt=interrupt, ignorePunctuation=True, announceCapital=announceCapital, flush=flush)
|
||||
|
||||
env['runtime']['outputManager'].presentText(
|
||||
char,
|
||||
interrupt=interrupt,
|
||||
ignorePunctuation=True,
|
||||
announceCapital=announceCapital,
|
||||
flush=flush)
|
||||
|
@ -17,7 +17,6 @@ elif os.geteuid() == 0:
|
||||
else:
|
||||
# Use local settings
|
||||
configPath = BaseDirectory.xdg_data_home + "/fenrir"
|
||||
if not os.path.exists(configPath): os.makedirs(configPath)
|
||||
if not os.path.exists(configPath):
|
||||
os.makedirs(configPath)
|
||||
configPath = configPath + "/fenrir.conf"
|
||||
|
||||
|
||||
|
@ -6,13 +6,14 @@
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
def getPrevLine(currX,currY, currText):
|
||||
|
||||
def getPrevLine(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
x = currX
|
||||
y = currY
|
||||
y = currY
|
||||
if y - 1 >= 0:
|
||||
y -= 1
|
||||
else:
|
||||
@ -23,7 +24,8 @@ def getPrevLine(currX,currY, currText):
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine, endOfScreen
|
||||
|
||||
def getCurrentLine(currX,currY, currText):
|
||||
|
||||
def getCurrentLine(currX, currY, currText):
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
wrappedLines = currText.split('\n')
|
||||
@ -33,7 +35,8 @@ def getCurrentLine(currX,currY, currText):
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine
|
||||
|
||||
def getNextLine(currX,currY, currText):
|
||||
|
||||
def getNextLine(currX, currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
@ -47,5 +50,5 @@ def getNextLine(currX,currY, currText):
|
||||
x = currX
|
||||
currLine = ''
|
||||
if not endOfScreen:
|
||||
currLine = wrappedLines[y]
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine, endOfScreen
|
||||
|
@ -6,28 +6,30 @@
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
||||
def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
if inText == None:
|
||||
if inText is None:
|
||||
return ''
|
||||
if not isinstance(inText, list):
|
||||
inText = inText.split('\n')
|
||||
if len(inText) < 1:
|
||||
return ''
|
||||
if firstMark == None:
|
||||
return ''
|
||||
if secondMark == None:
|
||||
return ''
|
||||
if (firstMark['y'] + 1) * (firstMark['x'] + 1) <= (secondMark['y'] + 1) * (secondMark['x'] + 1):
|
||||
if firstMark is None:
|
||||
return ''
|
||||
if secondMark is None:
|
||||
return ''
|
||||
if (firstMark['y'] + 1) * (firstMark['x'] +
|
||||
1) <= (secondMark['y'] + 1) * (secondMark['x'] + 1):
|
||||
startMark = firstMark.copy()
|
||||
endMark = secondMark.copy()
|
||||
else:
|
||||
endMark = firstMark.copy()
|
||||
startMark = secondMark.copy()
|
||||
startMark = secondMark.copy()
|
||||
textPart = ''
|
||||
if startMark['y'] == endMark['y']:
|
||||
textPart += inText[startMark['y']][startMark['x']:endMark['x'] + 1]
|
||||
else:
|
||||
currY = startMark['y']
|
||||
currY = startMark['y']
|
||||
while currY <= endMark['y']:
|
||||
if currY < endMark['y']:
|
||||
if currY == startMark['y']:
|
||||
@ -35,7 +37,7 @@ def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
else:
|
||||
textPart += inText[currY]
|
||||
if len(inText[currY].strip()) != 0:
|
||||
if len(textPart) - len(textPart.rstrip()) > 0:
|
||||
if len(textPart) - len(textPart.rstrip()) > 0:
|
||||
textPart = textPart[:len(textPart.rstrip())] + "\n"
|
||||
else:
|
||||
textPart += '\n'
|
||||
@ -44,17 +46,22 @@ def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
currY += 1
|
||||
return textPart
|
||||
|
||||
|
||||
def getTextBeforeMark(mark, inText):
|
||||
if inText == None:
|
||||
if inText is None:
|
||||
return ''
|
||||
if mark == None:
|
||||
if mark is None:
|
||||
return ''
|
||||
return getTextBetweenMarks({'x':0,'y':0}, mark, inText)
|
||||
return getTextBetweenMarks({'x': 0, 'y': 0}, mark, inText)
|
||||
|
||||
|
||||
def getTextAfterMark(mark, inText):
|
||||
if inText == None:
|
||||
if inText is None:
|
||||
return ''
|
||||
if mark == None:
|
||||
if mark is None:
|
||||
return ''
|
||||
inText = inText.split('\n')
|
||||
return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText)
|
||||
return getTextBetweenMarks(
|
||||
mark, {
|
||||
'x': len(
|
||||
inText[0]) - 1, 'y': len(inText) - 1}, inText)
|
||||
|
@ -3,17 +3,19 @@
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
import sys
|
||||
version = sys.version[:3] # we only need major.minor version.
|
||||
if version in ["3.3","3.4"]:
|
||||
version = sys.version[:3] # we only need major.minor version.
|
||||
if version in ["3.3", "3.4"]:
|
||||
from importlib.machinery import SourceFileLoader
|
||||
else: # Python 3.5+, no support for python < 3.3.
|
||||
else: # Python 3.5+, no support for python < 3.3.
|
||||
import importlib.util
|
||||
|
||||
|
||||
def importModule(moduleName, moduleLocation):
|
||||
if version in ["3.3","3.4"]:
|
||||
if version in ["3.3", "3.4"]:
|
||||
return SourceFileLoader(moduleName, moduleLocation).load_module()
|
||||
else:
|
||||
spec = importlib.util.spec_from_file_location(moduleName, moduleLocation)
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
moduleName, moduleLocation)
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
return driver_mod
|
||||
|
@ -5,4 +5,3 @@
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
|
||||
|
@ -5,50 +5,63 @@
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
import getpass, time, string, os
|
||||
import getpass
|
||||
import time
|
||||
import string
|
||||
import os
|
||||
from select import select
|
||||
|
||||
|
||||
def removeNonprintable(text):
|
||||
# Get the difference of all ASCII characters from the set of printable characters
|
||||
nonprintable = set([chr(i) for i in range(128)]).difference(string.printable)
|
||||
# Get the difference of all ASCII characters from the set of printable
|
||||
# characters
|
||||
nonprintable = set([chr(i) for i in range(128)]
|
||||
).difference(string.printable)
|
||||
# Use translate to remove all non-printable characters
|
||||
return text.translate({ord(character):None for character in nonprintable})
|
||||
return text.translate({ord(character): None for character in nonprintable})
|
||||
|
||||
|
||||
def insertNewlines(string, every=64):
|
||||
return '\n'.join(string[i:i+every] for i in range(0, len(string), every))
|
||||
return '\n'.join(string[i:i + every] for i in range(0, len(string), every))
|
||||
|
||||
|
||||
def splitEvery(toSplit, every=64):
|
||||
return list(toSplit[i:i+every] for i in range(0, len(toSplit), every))
|
||||
return list(toSplit[i:i + every] for i in range(0, len(toSplit), every))
|
||||
|
||||
|
||||
def createScreenEventData(content):
|
||||
eventData = {
|
||||
'bytes': content,
|
||||
'lines': content['lines'],
|
||||
'columns': content['columns'],
|
||||
'textCursor':
|
||||
'textCursor':
|
||||
{
|
||||
'x': int( content['cursor'][0]),
|
||||
'y': int( content['cursor'][1])
|
||||
},
|
||||
'x': int(content['cursor'][0]),
|
||||
'y': int(content['cursor'][1])
|
||||
},
|
||||
'screen': content['screen'],
|
||||
'text': content['text'],
|
||||
'attributes': content['attributes'],
|
||||
'screenUpdateTime': time.time(),
|
||||
}
|
||||
return eventData.copy()
|
||||
return eventData.copy()
|
||||
|
||||
|
||||
def hasMore(fd, timetout=0.05):
|
||||
r, _, _ = select([fd], [], [], timetout)
|
||||
return (fd in r)
|
||||
|
||||
|
||||
def hasMoreWhat(fdList, timetout=0.05):
|
||||
if not isinstance(fdList, list):
|
||||
return []
|
||||
return []
|
||||
elif fdList == []:
|
||||
return []
|
||||
r, _, _ = select(fdList, [], [], timetout)
|
||||
return r
|
||||
|
||||
def isValidShell(shell = ''):
|
||||
|
||||
def isValidShell(shell=''):
|
||||
if not isinstance(shell, str):
|
||||
return False
|
||||
if shell == '':
|
||||
@ -56,7 +69,7 @@ def isValidShell(shell = ''):
|
||||
try:
|
||||
if not os.path.isfile(shell):
|
||||
return False
|
||||
if not os.access(shell,os.X_OK):
|
||||
if not os.access(shell, os.X_OK):
|
||||
return False
|
||||
except Exception as e:
|
||||
# Utility function, no env access - use fallback logging
|
||||
@ -64,6 +77,7 @@ def isValidShell(shell = ''):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def getShell():
|
||||
try:
|
||||
shell = os.environ["FENRIRSHELL"]
|
||||
@ -71,7 +85,7 @@ def getShell():
|
||||
return shell
|
||||
except Exception as e:
|
||||
# Utility function, no env access - continue silently
|
||||
pass
|
||||
pass
|
||||
try:
|
||||
shell = os.environ["SHELL"]
|
||||
if isValidShell(shell):
|
||||
@ -84,8 +98,9 @@ def getShell():
|
||||
with open('/etc/passwd') as f:
|
||||
users = f.readlines()
|
||||
for user in users:
|
||||
(username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':')
|
||||
shell = shell.replace('\n','')
|
||||
(username, encrypwd, uid, gid, gecos,
|
||||
homedir, shell) = user.split(':')
|
||||
shell = shell.replace('\n', '')
|
||||
if username == getpass.getuser():
|
||||
if isValidShell(shell):
|
||||
return shell
|
||||
|
@ -7,20 +7,21 @@
|
||||
from fenrirscreenreader.core import debug
|
||||
import string
|
||||
|
||||
def getCurrentWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
|
||||
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
|
||||
if currText.strip(string.whitespace) == '':
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
x = currX
|
||||
y = currY
|
||||
currWord = ''
|
||||
currWord = ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currLine = wrappedLines[y]
|
||||
Found = False
|
||||
while(not Found):
|
||||
while (not Found):
|
||||
if not currLine[x] in string.whitespace:
|
||||
if x == 0:
|
||||
Found = True
|
||||
@ -36,7 +37,7 @@ def getCurrentWord(currX,currY, currText):
|
||||
else:
|
||||
y -= 1
|
||||
currLine = wrappedLines[y]
|
||||
x = len( currLine) - 1
|
||||
x = len(currLine) - 1
|
||||
lineBreak = True
|
||||
else:
|
||||
x -= 1
|
||||
@ -45,18 +46,20 @@ def getCurrentWord(currX,currY, currText):
|
||||
for d in string.whitespace:
|
||||
delimiterPos = currWord.find(d)
|
||||
if delimiterPos != -1:
|
||||
currWord = currWord[:delimiterPos]
|
||||
currWord = currWord[:delimiterPos]
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
return currX, currY, '', False, False
|
||||
|
||||
def getPrevWord(currX,currY, currText):
|
||||
lineBreak = 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 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')
|
||||
@ -69,32 +72,33 @@ def getPrevWord(currX,currY, currText):
|
||||
else:
|
||||
y -= 1
|
||||
currLine = wrappedLines[y]
|
||||
x = len( currLine) - 1
|
||||
x = len(currLine) - 1
|
||||
lineBreak = True
|
||||
else:
|
||||
x -= 1
|
||||
lineBreakCurrWord = lineBreak or lineBreakCurrWord
|
||||
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,currText)
|
||||
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x, y, currText)
|
||||
lineBreak = lineBreak or lineBreakCurrWord
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
||||
def getNextWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
|
||||
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
|
||||
if currText.strip(string.whitespace) == '':
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
x = currX
|
||||
y = currY
|
||||
currWord = ''
|
||||
currWord = ''
|
||||
wrappedLines = currText.split('\n')
|
||||
currLine = wrappedLines[y]
|
||||
Found = False
|
||||
while(not Found):
|
||||
while (not Found):
|
||||
if not Found:
|
||||
if x + 1 > len( currLine ) - 1:
|
||||
if y + 1 > len( wrappedLines ) - 1:
|
||||
if x + 1 > len(currLine) - 1:
|
||||
if y + 1 > len(wrappedLines) - 1:
|
||||
lineBreak = False
|
||||
endOfScreen = True
|
||||
return currX, currY, '', endOfScreen, lineBreak
|
||||
@ -110,7 +114,7 @@ def getNextWord(currX,currY, currText):
|
||||
Found = True
|
||||
else:
|
||||
if currLine[x - 1] in string.whitespace:
|
||||
Found = True
|
||||
Found = True
|
||||
if Found:
|
||||
currWord = currLine[x:]
|
||||
for d in string.whitespace:
|
||||
@ -119,4 +123,3 @@ def getNextWord(currX,currY, currText):
|
||||
currWord = currWord[:delimiterPos]
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
return currX, currY, '', False, False
|
||||
|
||||
|
Reference in New Issue
Block a user