add headLineManager
This commit is contained in:
parent
c7b2484cb2
commit
e5a69c7a30
45
src/fenrir/core/headLineManager.py
Normal file
45
src/fenrir/core/headLineManager.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Fenrir TTY screen reader
|
||||||
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
|
from core import debug
|
||||||
|
import re
|
||||||
|
|
||||||
|
class headLineManager():
|
||||||
|
def __init__(self):
|
||||||
|
self.regExSingle = re.compile(r'(([^\w\s])\2{5,})')
|
||||||
|
self.regExDouble = re.compile(r'([^\w\s]{2,}){5,}')
|
||||||
|
def initialize(self, environment):
|
||||||
|
self.env = environment
|
||||||
|
def shutdown(self):
|
||||||
|
pass
|
||||||
|
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
|
@ -92,9 +92,11 @@ class outputManager():
|
|||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
s = time.time()
|
||||||
|
text = self.env['runtime']['headLineManager'].replaceHeadLines(text)
|
||||||
text = self.env['runtime']['punctuationManager'].proceedPunctuation(text,ignorePunctuation)
|
text = self.env['runtime']['punctuationManager'].proceedPunctuation(text,ignorePunctuation)
|
||||||
text = text.replace('\n',' , ')
|
text = text.replace('\n',' , ')
|
||||||
|
print(time.time() -s)
|
||||||
self.env['runtime']['speechDriver'].speak(text)
|
self.env['runtime']['speechDriver'].speak(text)
|
||||||
self.env['runtime']['debug'].writeDebugOut("Speak: "+ text,debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut("Speak: "+ text,debug.debugLevel.INFO)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -21,6 +21,7 @@ from core import punctuationManager
|
|||||||
from core import cursorManager
|
from core import cursorManager
|
||||||
from core import applicationManager
|
from core import applicationManager
|
||||||
from core import helpManager
|
from core import helpManager
|
||||||
|
from core import headLineManager
|
||||||
from core import environment
|
from core import environment
|
||||||
from core import inputData
|
from core import inputData
|
||||||
from core.settingsData import settingsData
|
from core.settingsData import settingsData
|
||||||
@ -344,6 +345,8 @@ class settingsManager():
|
|||||||
environment['runtime']['applicationManager'].initialize(environment)
|
environment['runtime']['applicationManager'].initialize(environment)
|
||||||
environment['runtime']['helpManager'] = helpManager.helpManager()
|
environment['runtime']['helpManager'] = helpManager.helpManager()
|
||||||
environment['runtime']['helpManager'].initialize(environment)
|
environment['runtime']['helpManager'].initialize(environment)
|
||||||
|
environment['runtime']['headLineManager'] = headLineManager.headLineManager()
|
||||||
|
environment['runtime']['headLineManager'].initialize(environment)
|
||||||
if environment['runtime']['screenManager'] == None:
|
if environment['runtime']['screenManager'] == None:
|
||||||
environment['runtime']['screenManager'] = screenManager.screenManager()
|
environment['runtime']['screenManager'] = screenManager.screenManager()
|
||||||
environment['runtime']['screenManager'].initialize(environment)
|
environment['runtime']['screenManager'].initialize(environment)
|
||||||
|
@ -10,6 +10,7 @@ import string
|
|||||||
from select import select
|
from select import select
|
||||||
from select import epoll
|
from select import epoll
|
||||||
import select
|
import select
|
||||||
|
import re
|
||||||
|
|
||||||
def removeNonprintable(text):
|
def removeNonprintable(text):
|
||||||
# Get the difference of all ASCII characters from the set of printable characters
|
# Get the difference of all ASCII characters from the set of printable characters
|
||||||
@ -80,3 +81,37 @@ 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,
|
|||||||
|
|
||||||
trackHighlights(old,new,t,5)
|
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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user