replaces namespace fenrir with fenrirscreenreader

This commit is contained in:
chrys
2018-03-21 11:10:28 +01:00
parent 40da178136
commit a8a0f7cc29
241 changed files with 11181 additions and 0 deletions

View File

View File

@ -0,0 +1,121 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
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
if x - 1 < 0:
if y - 1 >= 0:
y -= 1
x = len(wrappedLines[y]) - 1
lineBreak = True
else:
lineBreak = False
endOfScreen = True
else:
x -= 1
currChar = ''
if not endOfScreen:
currChar = wrappedLines[y][x]
return x, y, currChar, endOfScreen, lineBreak
def getCurrentChar(currX,currY, currText):
if currText == '':
return -1, -1, ''
wrappedLines = currText.split('\n')
currChar = wrappedLines[currY][currX]
return currX, currY, currChar
def getUpChar(currX,currY, currText):
endOfScreen = False
if currText == '':
return -1, -1, '', endOfScreen
wrappedLines = currText.split('\n')
currY -= 1
if currY < 0:
currY = 0
else:
endOfScreen = True
currChar = ''
if not endOfScreen:
currChar = wrappedLines[currY][currX]
return currX, currY, currChar, endOfScreen
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
else:
endOfScreen = True
currChar = ''
if not endOfScreen:
currChar = wrappedLines[currY][currX]
return currX, currY, currChar, endOfScreen
def getLastCharInLine(currY, currText):
endOfScreen = False
if currText == '':
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
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:
y += 1
x = 0
lineBreak = True
else:
lineBreak = False
endOfScreen = True
else:
x += 1
currChar = ''
if not endOfScreen:
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"
}
try:
phonChar = phoneticsDict[currChar.upper()]
if currChar.isupper():
phonChar = phonChar[0].upper() + phonChar[1:]
return phonChar
except:
return currChar

View File

@ -0,0 +1,23 @@
#!/usr/bin/python
import configparser
import os
import sys
from os import listdir
from os.path import isfile, join
from inspect import isfunction
from xdg import BaseDirectory
# Get configuration directory
if len(sys.argv) > 1:
configPath = sys.argv[1]
elif os.geteuid() == 0:
# Save settings system wide
configPath = "/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"

View File

@ -0,0 +1,52 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
from collections import Counter
def getPrevLine(currX,currY, currText):
endOfScreen = False
if currText == '':
return -1, -1, '', endOfScreen
wrappedLines = currText.split('\n')
x = currX
y = currY
if y - 1 >= 0:
y -= 1
else:
endOfScreen = True
x = 0
currLine = ''
if not endOfScreen:
currLine = wrappedLines[y]
return x, y, currLine, endOfScreen
def getCurrentLine(currX,currY, currText):
if currText == '':
return -1, -1, ''
wrappedLines = currText.split('\n')
x = currX
y = currY
x = 0
currLine = wrappedLines[y]
return x, y, currLine
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):
y += 1
else:
endOfScreen = True
x = 0
currLine = ''
if not endOfScreen:
currLine = wrappedLines[y]
return x, y, currLine, endOfScreen

View File

@ -0,0 +1,60 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
def getTextBetweenMarks(firstMark, secondMark, inText):
if inText == 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):
startMark = firstMark.copy()
endMark = secondMark.copy()
else:
endMark = firstMark.copy()
startMark = secondMark.copy()
textPart = ''
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']:
if currY == startMark['y']:
textPart += inText[currY][startMark['x']:]
else:
textPart += inText[currY]
if len(inText[currY].strip()) != 0:
if len(textPart) - len(textPart.rstrip()) > 0:
textPart = textPart[:len(textPart.rstrip())] + "\n"
else:
textPart += '\n'
else:
textPart += inText[currY][:endMark['x'] + 1]
currY += 1
return textPart
def getTextBeforeMark(mark, inText):
if inText == None:
return ''
if mark == None:
return ''
return getTextBetweenMarks({'x':0,'y':0}, mark, inText)
def getTextAfterMark(mark, inText):
if inText == None:
return ''
if mark == None:
return ''
inText = inText.split('\n')
return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText)

View File

@ -0,0 +1,19 @@
#!/bin/python
# -*- coding: utf-8 -*-
# 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"]:
from importlib.machinery import SourceFileLoader
else: # Python 3.5+, no support for python < 3.3.
import importlib.util
def importModule(moduleName, moduleLocation):
if version in ["3.3","3.4"]:
return SourceFileLoader(moduleName, moduleLocation).load_module()
else:
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

View File

@ -0,0 +1,8 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug

View File

@ -0,0 +1,117 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
from collections import Counter
import string
from select import select
from select import epoll
import select
import re
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)
# Use translate to remove all non-printable characters
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))
def splitEvery(toSplit, every=64):
return list(toSplit[i:i+every] for i in range(0, len(toSplit), every))
def hasMoreRead(fd):
r, w, e = select([fd], [], [], 0)
return (fd in r)
def hasMorePollPri(fd):
p = epoll()
p.register(fd, select.POLLPRI | select.POLLERR)
r = p.poll(0)
return (fd in r)
def trackHighlights(oldAttr, newAttr, text, lenght):
result = ''
currCursor = None
if oldAttr == newAttr:
return result, currCursor
if len(newAttr) == 0:
return result, currCursor
if len(oldAttr) != len(newAttr):
return result, currCursor
old = splitEvery(oldAttr,lenght)
new = splitEvery(newAttr,lenght)
textLines = text.split('\n')
background = []
if len(textLines) - 1 != len(new):
return result, currCursor
try:
bgStat = Counter(newAttr).most_common(3)
background.append(bgStat[0][0])
# if there is a third color add a secondary background (for dialogs for example)
if len(bgStat) > 2:
if bgStat[1][1] > 40:
background.append(bgStat[1][0])
except Exception as e:
background.append((7,7,0,0,0,0))
for line in range(len(new)):
if old[line] != new[line]:
for column in range(len(new[line])):
print(new[line][column])
if old[line][column] != new[line][column]:
if not new[line][column] in background:
if not currCursor:
currCursor = {}
currCursor['x'] = column
currCursor['y'] = line
result += textLines[line][column]
result += ' '
return result, currCursor
'''
t = 'hallo\nwelt!'
old = ((1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0))
new = ((0,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0),(1,1,0,0))
trackHighlights(old,new,t,5)
'''
class headLineManipulation:
def __init__(self):
self.regExSingle = re.compile(r'(([^\w\s])\2{5,})')
self.regExDouble = re.compile(r'([^\w\s]{2,}){5,}')
def replaceHeadLines(self, text):
result = ''
newText = ''
lastPos = 0
for match in self.regExDouble.finditer(text):
span = match.span()
newText += text[lastPos:span[0]]
numberOfChars = len(text[span[0]:span[1]])
name = text[span[0]:span[1]][:2]
if name.strip(name[0]) == '':
newText += ' ' + str(numberOfChars) + ' ' + name[0] + ' '
else:
newText += ' ' + str(int(numberOfChars / 2)) + ' ' + name + ' '
lastPos = span[1]
newText += ' ' + text[lastPos:]
lastPos = 0
for match in self.regExSingle.finditer(newText):
span = match.span()
result += text[lastPos:span[0]]
numberOfChars = len(newText[span[0]:span[1]])
name = newText[span[0]:span[1]][:2]
if name.strip(name[0]) == '':
result += ' ' + str(numberOfChars) + ' ' + name[0] + ' '
else:
result += ' ' + str(int(numberOfChars / 2)) + ' ' + name + ' '
lastPos = span[1]
result += ' ' + newText[lastPos:]
return result

View File

@ -0,0 +1,122 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
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:
if x == 0:
Found = True
else:
if currLine[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
else:
y -= 1
currLine = wrappedLines[y]
x = len( currLine) - 1
lineBreak = True
else:
x -= 1
if Found:
currWord = currLine[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
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]
if x - 1 < 0:
if y - 1 < 0:
lineBreak = False
endOfScreen = True
return currX, currY, '', endOfScreen, lineBreak
else:
y -= 1
currLine = wrappedLines[y]
x = len( currLine) - 1
lineBreak = 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
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
else:
y += 1
currLine = wrappedLines[y]
x = 0
lineBreak = True
else:
x += 1
if not currLine[x] in string.whitespace:
if x == 0:
Found = True
else:
if currLine[x - 1] in string.whitespace:
Found = True
if Found:
currWord = currLine[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