2016-09-02 15:37:36 -04:00
|
|
|
#!/bin/python
|
2016-09-19 16:15:58 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Fenrir TTY screen reader
|
|
|
|
# By Chrys, Storm Dragon, and contributers.
|
|
|
|
|
2018-03-21 06:10:28 -04:00
|
|
|
from fenrirscreenreader.core import debug
|
2018-03-13 17:45:52 -04:00
|
|
|
import time, os
|
2016-09-02 15:37:36 -04:00
|
|
|
|
|
|
|
class screenManager():
|
|
|
|
def __init__(self):
|
2017-02-22 17:48:37 -05:00
|
|
|
pass
|
2016-09-14 17:27:19 -04:00
|
|
|
def initialize(self, environment):
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env = environment
|
|
|
|
self.env['runtime']['settingsManager'].loadDriver(\
|
|
|
|
self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver')
|
2017-02-22 17:48:37 -05:00
|
|
|
self.env['runtime']['screenDriver'].getCurrScreen()
|
2018-03-21 19:26:17 -04:00
|
|
|
self.env['runtime']['screenDriver'].getCurrScreen()
|
2017-02-22 17:48:37 -05:00
|
|
|
self.env['runtime']['screenDriver'].getSessionInformation()
|
2016-09-14 17:27:19 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def shutdown(self):
|
|
|
|
self.env['runtime']['settingsManager'].shutdownDriver('screenDriver')
|
2018-03-12 16:29:34 -04:00
|
|
|
def hanldeScreenChange(self, eventData):
|
|
|
|
self.env['runtime']['screenDriver'].getCurrScreen()
|
|
|
|
self.env['runtime']['screenDriver'].getSessionInformation()
|
2017-02-22 17:48:37 -05:00
|
|
|
if self.isScreenChange():
|
2018-03-12 16:29:34 -04:00
|
|
|
self.changeBrailleScreen()
|
|
|
|
if not self.isSuspendingScreen(self.env['screen']['newTTY']):
|
|
|
|
self.env['runtime']['screenDriver'].update(eventData, 'onScreenChange')
|
|
|
|
self.env['screen']['lastScreenUpdate'] = time.time()
|
|
|
|
def handleScreenUpdate(self, eventData):
|
|
|
|
self.env['screen']['oldApplication'] = self.env['screen']['newApplication']
|
2017-04-24 16:40:18 -04:00
|
|
|
if not self.isSuspendingScreen(self.env['screen']['newTTY']):
|
2018-03-12 16:29:34 -04:00
|
|
|
self.env['runtime']['screenDriver'].update(eventData, 'onScreenUpdate')
|
2017-06-26 19:35:12 -04:00
|
|
|
#if trigger == 'onUpdate' or self.isScreenChange() \
|
|
|
|
# or len(self.env['screen']['newDelta']) > 6:
|
|
|
|
# self.env['runtime']['screenDriver'].getCurrApplication()
|
2017-04-24 16:40:18 -04:00
|
|
|
self.env['screen']['lastScreenUpdate'] = time.time()
|
2017-08-13 17:13:05 -04:00
|
|
|
def formatAttributes(self, attribute, attributeFormatString = None):
|
2017-08-13 17:06:45 -04:00
|
|
|
if not attributeFormatString:
|
|
|
|
attributeFormatString = self.env['runtime']['settingsManager'].getSetting('general', 'attributeFormatString')
|
|
|
|
if not attributeFormatString:
|
|
|
|
return ''
|
|
|
|
if attributeFormatString == '':
|
|
|
|
return ''
|
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirBGColor', self.env['runtime']['screenDriver'].getFenrirBGColor(attribute))
|
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirFGColor', self.env['runtime']['screenDriver'].getFenrirFGColor(attribute))
|
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirUnderline', self.env['runtime']['screenDriver'].getFenrirUnderline(attribute))
|
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirBold', self.env['runtime']['screenDriver'].getFenrirBold(attribute))
|
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirBlink', self.env['runtime']['screenDriver'].getFenrirBlink(attribute))
|
2017-08-13 18:50:29 -04:00
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirFontSize', self.env['runtime']['screenDriver'].getFenrirFontSize(attribute))
|
2017-08-13 17:06:45 -04:00
|
|
|
attributeFormatString = attributeFormatString.replace('fenrirFont', self.env['runtime']['screenDriver'].getFenrirFont(attribute))
|
|
|
|
return attributeFormatString
|
2016-10-08 06:15:38 -04:00
|
|
|
def isSuspendingScreen(self, screen = None):
|
|
|
|
if screen == None:
|
2017-04-24 16:40:18 -04:00
|
|
|
screen = self.env['screen']['newTTY']
|
2017-02-22 17:48:37 -05:00
|
|
|
ignoreScreens = []
|
|
|
|
fixIgnoreScreens = self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreen')
|
|
|
|
if fixIgnoreScreens != '':
|
2017-02-27 17:30:43 -05:00
|
|
|
ignoreScreens.extend(fixIgnoreScreens.split(','))
|
2017-01-16 17:12:27 -05:00
|
|
|
if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'):
|
2017-04-24 16:40:18 -04:00
|
|
|
ignoreScreens.extend(self.env['screen']['autoIgnoreScreens'])
|
2017-06-30 17:04:03 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut('screenManager:isSuspendingScreen ' + str(ignoreScreens) + ' '+ str(self.env['screen']['newTTY']),debug.debugLevel.INFO)
|
2018-03-13 17:45:52 -04:00
|
|
|
try:
|
|
|
|
ignoreFileName = self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreenFile')
|
|
|
|
if ignoreFileName != '':
|
|
|
|
if os.access(ignoreFileName, os.R_OK):
|
|
|
|
with open(ignoreFileName) as fp:
|
|
|
|
ignoreScreens.extend(fp.read().replace('\n','').split(','))
|
|
|
|
except:
|
|
|
|
pass
|
2017-02-22 17:48:37 -05:00
|
|
|
return (screen in ignoreScreens)
|
|
|
|
|
2016-09-23 03:51:47 -04:00
|
|
|
def isScreenChange(self):
|
2017-04-24 16:40:18 -04:00
|
|
|
if not self.env['screen']['oldTTY']:
|
2016-10-08 09:08:53 -04:00
|
|
|
return False
|
2017-04-24 16:40:18 -04:00
|
|
|
return self.env['screen']['newTTY'] != self.env['screen']['oldTTY']
|
2017-11-10 14:08:58 -05:00
|
|
|
def isDelta(self, ignoreSpace=False):
|
|
|
|
newDelta = self.env['screen']['newDelta']
|
|
|
|
if ignoreSpace:
|
|
|
|
newDelta = newDelta.strip()
|
|
|
|
return newDelta != ''
|
2016-10-20 15:52:36 -04:00
|
|
|
def isNegativeDelta(self):
|
2017-04-24 16:40:18 -04:00
|
|
|
return self.env['screen']['newNegativeDelta'] != ''
|
2016-09-24 16:56:18 -04:00
|
|
|
def getWindowAreaInText(self, text):
|
|
|
|
if not self.env['runtime']['cursorManager'].isApplicationWindowSet():
|
|
|
|
return text
|
|
|
|
windowText = ''
|
|
|
|
windowList = text.split('\n')
|
2016-10-02 19:34:46 -04:00
|
|
|
currApp = self.env['runtime']['applicationManager'].getCurrentApplication()
|
|
|
|
windowList = windowList[self.env['commandBuffer']['windowArea'][currApp]['1']['y']:self.env['commandBuffer']['windowArea'][currApp]['2']['y'] + 1]
|
2016-09-24 16:56:18 -04:00
|
|
|
for line in windowList:
|
2016-10-02 19:34:46 -04:00
|
|
|
windowText += line[self.env['commandBuffer']['windowArea'][currApp]['1']['x']:self.env['commandBuffer']['windowArea'][currApp]['2']['x'] + 1] + '\n'
|
2016-09-24 16:56:18 -04:00
|
|
|
return windowText
|
2016-12-15 04:23:29 -05:00
|
|
|
|
2016-12-15 04:33:52 -05:00
|
|
|
def injectTextToScreen(self, text, screen = None):
|
2016-12-15 04:23:29 -05:00
|
|
|
try:
|
2016-12-15 04:33:52 -05:00
|
|
|
self.env['runtime']['screenDriver'].injectTextToScreen(text, screen)
|
2016-12-15 04:23:29 -05:00
|
|
|
except Exception as e:
|
2016-12-15 04:37:31 -05:00
|
|
|
self.env['runtime']['debug'].writeDebugOut('screenManager:injectTextToScreen ' + str(e),debug.debugLevel.ERROR)
|
2016-12-15 04:23:29 -05:00
|
|
|
|
2016-10-08 06:15:38 -04:00
|
|
|
def changeBrailleScreen(self):
|
2017-02-27 16:13:39 -05:00
|
|
|
if not self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'):
|
|
|
|
return
|
2016-10-08 06:15:38 -04:00
|
|
|
if not self.env['runtime']['brailleDriver']:
|
|
|
|
return
|
2017-04-24 16:40:18 -04:00
|
|
|
if self.env['screen']['oldTTY']:
|
|
|
|
if not self.isSuspendingScreen(self.env['screen']['oldTTY']):
|
2016-10-08 09:08:53 -04:00
|
|
|
try:
|
|
|
|
self.env['runtime']['brailleDriver'].leveScreen()
|
|
|
|
except Exception as e:
|
2016-12-17 06:49:54 -05:00
|
|
|
self.env['runtime']['debug'].writeDebugOut('screenManager:changeBrailleScreen:leveScreen ' + str(e),debug.debugLevel.ERROR)
|
2016-10-08 06:15:38 -04:00
|
|
|
if not self.isSuspendingScreen():
|
2016-10-08 08:58:48 -04:00
|
|
|
try:
|
2017-04-24 16:40:18 -04:00
|
|
|
self.env['runtime']['brailleDriver'].enterScreen(self.env['screen']['newTTY'])
|
2016-10-08 08:58:48 -04:00
|
|
|
except Exception as e:
|
2016-12-15 04:39:33 -05:00
|
|
|
self.env['runtime']['debug'].writeDebugOut('screenManager:changeBrailleScreen:enterScreen ' + str(e),debug.debugLevel.ERROR)
|