Merge branch 'master' into bleed

This commit is contained in:
chrys
2018-05-14 21:26:33 +02:00
9 changed files with 151 additions and 60 deletions

View File

@ -4,7 +4,7 @@
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
import signal, time, argparse
import signal, time, argparse, sys
from fenrirscreenreader.core import i18n
from fenrirscreenreader.core import settingsManager
@ -32,6 +32,7 @@ class fenrirManager():
self.command = ''
self.controlMode = True
self.switchCtrlModeOnce = 0
self.setProcessName()
def handleArgs(self):
args = None
parser = argparse.ArgumentParser(description="Fenrir Help")
@ -212,7 +213,32 @@ class fenrirManager():
if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
self.command = ''
def setProcessName(self, name = 'fenrir'):
"""Attempts to set the process name to 'fenrir'."""
#sys.argv[0] = name
# Disabling the import error of setproctitle.
# pylint: disable-msg=F0401
try:
from setproctitle import setproctitle
except ImportError:
pass
else:
setproctitle(name)
return True
try:
from ctypes import cdll, byref, create_string_buffer
libc = cdll.LoadLibrary('libc.so.6')
stringBuffer = create_string_buffer(len(name) + 1)
stringBuffer.value = bytes(name, 'UTF-8')
libc.prctl(15, byref(stringBuffer), 0, 0, 0)
return True
except:
pass
return False
def shutdownRequest(self):
try:
self.environment['runtime']['eventManager'].stopMainEventLoop()

View File

@ -40,14 +40,17 @@ class inputDriver():
return False
def toggleLedState(self, led = 0):
if not self._initialized:
return None
def grabDevices(self):
return
def grabAllDevices(self):
if not self._initialized:
return None
def releaseDevices(self):
return
def ungrabAllDevices(self):
if not self._initialized:
return None
return
def removeAllDevices(self):
if not self._initialized:
return
def __del__(self):
if not self._initialized:
return None
self.releaseDevices()
return
self.removeAllDevices()

View File

@ -109,10 +109,16 @@ class inputManager():
def grabAllDevices(self):
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
self.env['runtime']['inputDriver'].grabAllDevices()
try:
self.env['runtime']['inputDriver'].grabAllDevices()
except Exception as e:
pass
def ungrabAllDevices(self):
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
self.env['runtime']['inputDriver'].ungrabAllDevices()
try:
self.env['runtime']['inputDriver'].ungrabAllDevices()
except Exception as e:
pass
def updateInputDevices(self):
try:
@ -155,7 +161,10 @@ class inputManager():
return eventName
def clearEventBuffer(self):
self.env['runtime']['inputDriver'].clearEventBuffer()
try:
self.env['runtime']['inputDriver'].clearEventBuffer()
except Exception as e:
pass
def setLastDeepestInput(self, currentDeepestInput):
self.lastDeepestInput = currentDeepestInput
def clearLastDeepInput(self):

View File

@ -12,6 +12,7 @@ class screenManager():
def __init__(self):
self.currScreenIgnored = False
self.prevScreenIgnored = False
self.toggleDeviceGrab = False
def initialize(self, environment):
self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\
@ -40,15 +41,24 @@ class screenManager():
if not self.isSuspendingScreen(self.env['screen']['newTTY']):
self.update(eventData, 'onScreenChange')
self.env['screen']['lastScreenUpdate'] = time.time()
def handleDeviceGrab(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
return
if self.getCurrScreenIgnored() != self.getPrevScreenIgnored():
self.toggleDeviceGrab = True
if self.toggleDeviceGrab:
if self.env['runtime']['inputManager'].noKeyPressed():
if self.getCurrScreenIgnored():
self.env['runtime']['inputManager'].ungrabAllDevices()
self.env['runtime']['outputManager'].interruptOutput()
else:
self.env['runtime']['inputManager'].grabAllDevices()
self.toggleDeviceGrab = False
def handleScreenUpdate(self, eventData):
self.env['screen']['oldApplication'] = self.env['screen']['newApplication']
self.updateScreenIgnored()
if self.getCurrScreenIgnored() != self.getPrevScreenIgnored():
if self.getCurrScreenIgnored():
self.env['runtime']['inputManager'].ungrabAllDevices()
self.env['runtime']['outputManager'].interruptOutput()
else:
self.env['runtime']['inputManager'].grabAllDevices()
self.handleDeviceGrab()
if not self.getCurrScreenIgnored():
self.update(eventData, 'onScreenUpdate')
#if trigger == 'onUpdate' or self.isScreenChange() \
@ -158,13 +168,34 @@ class screenManager():
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))
attributeFormatString = attributeFormatString.replace('fenrirFontSize', self.env['runtime']['screenDriver'].getFenrirFontSize(attribute))
attributeFormatString = attributeFormatString.replace('fenrirFont', self.env['runtime']['screenDriver'].getFenrirFont(attribute))
try:
attributeFormatString = attributeFormatString.replace('fenrirBGColor', self.env['runtime']['screenDriver'].getFenrirBGColor(attribute))
except Exception as e:
pass
try:
attributeFormatString = attributeFormatString.replace('fenrirFGColor', self.env['runtime']['screenDriver'].getFenrirFGColor(attribute))
except Exception as e:
pass
try:
attributeFormatString = attributeFormatString.replace('fenrirUnderline', self.env['runtime']['screenDriver'].getFenrirUnderline(attribute))
except Exception as e:
pass
try:
attributeFormatString = attributeFormatString.replace('fenrirBold', self.env['runtime']['screenDriver'].getFenrirBold(attribute))
except Exception as e:
pass
try:
attributeFormatString = attributeFormatString.replace('fenrirBlink', self.env['runtime']['screenDriver'].getFenrirBlink(attribute))
except Exception as e:
pass
try:
attributeFormatString = attributeFormatString.replace('fenrirFontSize', self.env['runtime']['screenDriver'].getFenrirFontSize(attribute))
except Exception as e:
pass
try:
attributeFormatString = attributeFormatString.replace('fenrirFont', self.env['runtime']['screenDriver'].getFenrirFont(attribute))
except Exception as e:
pass
return attributeFormatString
def isSuspendingScreen(self, screen = None):
if screen == None:
@ -212,7 +243,6 @@ class screenManager():
try:
self.env['runtime']['screenDriver'].injectTextToScreen(text, screen)
except Exception as e:
print(e)
self.env['runtime']['debug'].writeDebugOut('screenManager:injectTextToScreen ' + str(e),debug.debugLevel.ERROR)
def changeBrailleScreen(self):

View File

@ -153,7 +153,10 @@ class settingsManager():
def shutdownDriver(self, driverType):
if self.env['runtime'][driverType] == None:
return
self.env['runtime'][driverType].shutdown()
try:
self.env['runtime'][driverType].shutdown()
except Exception as e:
pass
del self.env['runtime'][driverType]
def setFenrirKeys(self, keys):