To make Fenrir easier to approach for new developer, start code migration to be pep8 compliant.

This commit is contained in:
Storm Dragon
2025-07-01 22:23:50 -04:00
parent 4bcf82178e
commit 7408951152
345 changed files with 8688 additions and 3852 deletions

View File

@ -9,22 +9,25 @@ import time
import os
import sys
from fenrirscreenreader.core import i18n
from fenrirscreenreader.core.i18n import _
from fenrirscreenreader.core import settingsManager
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.eventData import fenrirEventType
class fenrirManager():
def __init__(self, cliArgs):
self.isInitialized = False
try:
self.environment = settingsManager.settingsManager().initFenrirConfig(cliArgs, self)
if not self.environment:
raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable')
raise RuntimeError(
'Cannot Initialize. Maybe the configfile is not available or not parseable')
except RuntimeError:
raise
self.environment['runtime']['outputManager'].presentText(_("Start Fenrir"), soundIcon='ScreenReaderOn', interrupt=True)
self.environment['runtime']['outputManager'].presentText(
_("Start Fenrir"), soundIcon='ScreenReaderOn', interrupt=True)
signal.signal(signal.SIGINT, self.captureSignal)
signal.signal(signal.SIGTERM, self.captureSignal)
@ -41,26 +44,30 @@ class fenrirManager():
self.shutdown()
def handleInput(self, event):
self.environment['runtime']['debug'].writeDebugOut('DEBUG INPUT fenrirMan:' + str(event), debug.debugLevel.INFO)
self.environment['runtime']['debug'].writeDebugOut(
'DEBUG INPUT fenrirMan:' + str(event), debug.debugLevel.INFO)
if not event['Data']:
event['Data'] = self.environment['runtime']['inputManager'].getInputEvent()
if event['Data']:
event['Data']['EventName'] = self.environment['runtime']['inputManager'].convertEventName(event['Data']['EventName'])
self.environment['runtime']['inputManager'].handleInputEvent(event['Data'])
event['Data']['EventName'] = self.environment['runtime']['inputManager'].convertEventName(
event['Data']['EventName'])
self.environment['runtime']['inputManager'].handleInputEvent(
event['Data'])
else:
return
if self.environment['runtime']['inputManager'].noKeyPressed():
if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['inputManager'].clearLastDeepInput()
if self.environment['runtime']['screenManager'].isIgnoredScreen():
self.environment['runtime']['inputManager'].writeEventBuffer()
else:
else:
if self.environment['runtime']['helpManager'].isTutorialMode():
self.environment['runtime']['inputManager'].clearEventBuffer()
self.environment['runtime']['inputManager'].keyEcho(event['Data'])
self.environment['runtime']['inputManager'].keyEcho(
event['Data'])
if self.environment['runtime']['vmenuManager'].getActive():
self.environment['runtime']['inputManager'].clearEventBuffer()
@ -68,10 +75,10 @@ class fenrirManager():
self.detectShortcutCommand()
if self.modifierInput:
self.environment['runtime']['inputManager'].clearEventBuffer()
self.environment['runtime']['inputManager'].clearEventBuffer()
if self.singleKeyCommand:
if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['inputManager'].clearEventBuffer()
self.environment['runtime']['inputManager'].clearEventBuffer()
else:
self.environment['runtime']['inputManager'].writeEventBuffer()
@ -84,13 +91,16 @@ class fenrirManager():
if self.environment['input']['keyForeward'] > 0:
self.environment['input']['keyForeward'] -= 1
self.environment['runtime']['commandManager'].executeDefaultTrigger('onKeyInput')
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onKeyInput')
def handleByteInput(self, event):
if not event['Data'] or event['Data'] == b'':
return
self.environment['runtime']['byteManager'].handleByteInput(event['Data'])
self.environment['runtime']['commandManager'].executeDefaultTrigger('onByteInput')
self.environment['runtime']['byteManager'].handleByteInput(
event['Data'])
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onByteInput')
def handleExecuteCommand(self, event):
if not event['Data'] or event['Data'] == '':
@ -99,71 +109,96 @@ class fenrirManager():
# special modes
if self.environment['runtime']['helpManager'].isTutorialMode():
if self.environment['runtime']['commandManager'].commandExists(currentCommand, 'help'):
self.environment['runtime']['commandManager'].executeCommand(currentCommand, 'help')
if self.environment['runtime']['commandManager'].commandExists(
currentCommand, 'help'):
self.environment['runtime']['commandManager'].executeCommand(
currentCommand, 'help')
return
elif self.environment['runtime']['vmenuManager'].getActive():
if self.environment['runtime']['commandManager'].commandExists(currentCommand, 'vmenu-navigation'):
self.environment['runtime']['commandManager'].executeCommand(currentCommand, 'vmenu-navigation')
if self.environment['runtime']['commandManager'].commandExists(
currentCommand, 'vmenu-navigation'):
self.environment['runtime']['commandManager'].executeCommand(
currentCommand, 'vmenu-navigation')
return
# default
self.environment['runtime']['commandManager'].executeCommand(currentCommand, 'commands')
self.environment['runtime']['commandManager'].executeCommand(
currentCommand, 'commands')
def handleRemoteIncomming(self, event):
if not event['Data']:
return
self.environment['runtime']['remoteManager'].handleRemoteIncomming(event['Data'])
self.environment['runtime']['remoteManager'].handleRemoteIncomming(
event['Data'])
def handleScreenChange(self, event):
self.environment['runtime']['screenManager'].handleScreenChange(event['Data'])
self.environment['runtime']['screenManager'].handleScreenChange(
event['Data'])
if self.environment['runtime']['vmenuManager'].getActive():
return
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged')
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onScreenChanged')
self.environment['runtime']['screenDriver'].getCurrScreen()
def handleScreenUpdate(self, event):
self.environment['runtime']['screenManager'].handleScreenUpdate(event['Data'])
self.environment['runtime']['screenManager'].handleScreenUpdate(
event['Data'])
if time.time() - self.environment['runtime']['inputManager'].getLastInputTime() >= 0.3:
if time.time() - \
self.environment['runtime']['inputManager'].getLastInputTime() >= 0.3:
self.environment['runtime']['inputManager'].clearLastDeepInput()
if (self.environment['runtime']['cursorManager'].isCursorVerticalMove() or
self.environment['runtime']['cursorManager'].isCursorHorizontalMove()):
self.environment['runtime']['commandManager'].executeDefaultTrigger('onCursorChange')
if (self.environment['runtime']['cursorManager'].isCursorVerticalMove(
) or self.environment['runtime']['cursorManager'].isCursorHorizontalMove()):
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onCursorChange')
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onScreenUpdate')
self.environment['runtime']['inputManager'].clearLastDeepInput()
def handlePlugInputDevice(self, event):
try:
self.environment['runtime']['inputManager'].setLastDetectedDevices(event['Data'])
self.environment['runtime']['inputManager'].setLastDetectedDevices(
event['Data'])
except Exception as e:
self.environment['runtime']['debug'].writeDebugOut('handlePlugInputDevice: Error setting last detected devices: ' + str(e), debug.debugLevel.ERROR)
self.environment['runtime']['inputManager'].handlePlugInputDevice(event['Data'])
self.environment['runtime']['commandManager'].executeDefaultTrigger('onPlugInputDevice', force=True)
self.environment['runtime']['inputManager'].setLastDetectedDevices(None)
self.environment['runtime']['debug'].writeDebugOut(
'handlePlugInputDevice: Error setting last detected devices: ' + str(e),
debug.debugLevel.ERROR)
self.environment['runtime']['inputManager'].handlePlugInputDevice(
event['Data'])
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onPlugInputDevice', force=True)
self.environment['runtime']['inputManager'].setLastDetectedDevices(
None)
def handleHeartBeat(self, event):
self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat', force=True)
self.environment['runtime']['commandManager'].executeDefaultTrigger(
'onHeartBeat', force=True)
def detectShortcutCommand(self):
if self.environment['input']['keyForeward'] > 0:
return
if len(self.environment['input']['prevInput']) > len(self.environment['input']['currInput']):
if len(self.environment['input']['prevInput']) > len(
self.environment['input']['currInput']):
return
if self.environment['runtime']['inputManager'].isKeyPress():
self.modifierInput = self.environment['runtime']['inputManager'].currKeyIsModifier()
self.modifierInput = self.environment['runtime']['inputManager'].currKeyIsModifier(
)
else:
if not self.environment['runtime']['inputManager'].noKeyPressed():
if self.singleKeyCommand:
self.singleKeyCommand = len(self.environment['input']['currInput']) == 1
self.singleKeyCommand = len(
self.environment['input']['currInput']) == 1
if not(self.singleKeyCommand and self.environment['runtime']['inputManager'].noKeyPressed()):
currentShortcut = self.environment['runtime']['inputManager'].getCurrShortcut()
self.command = self.environment['runtime']['inputManager'].getCommandForShortcut(currentShortcut)
if not (
self.singleKeyCommand and self.environment['runtime']['inputManager'].noKeyPressed()):
currentShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(
)
self.command = self.environment['runtime']['inputManager'].getCommandForShortcut(
currentShortcut)
if not self.modifierInput:
if self.environment['runtime']['inputManager'].isKeyPress():
@ -176,11 +211,13 @@ class fenrirManager():
# fire event
if self.command != '':
if self.modifierInput:
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
self.environment['runtime']['eventManager'].putToEventQueue(
fenrirEventType.ExecuteCommand, self.command)
self.command = ''
else:
if self.singleKeyCommand:
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
self.environment['runtime']['eventManager'].putToEventQueue(
fenrirEventType.ExecuteCommand, self.command)
self.command = ''
def setProcessName(self, name='fenrir'):
@ -201,7 +238,8 @@ class fenrirManager():
libc.prctl(15, byref(stringBuffer), 0, 0, 0)
return True
except Exception as e:
self.environment['runtime']['debug'].writeDebugOut('setProcName: Error setting process name: ' + str(e), debug.debugLevel.ERROR)
self.environment['runtime']['debug'].writeDebugOut(
'setProcName: Error setting process name: ' + str(e), debug.debugLevel.ERROR)
return False
@ -209,7 +247,9 @@ class fenrirManager():
try:
self.environment['runtime']['eventManager'].stopMainEventLoop()
except Exception as e:
self.environment['runtime']['debug'].writeDebugOut('shutdownRequest: Error stopping main event loop: ' + str(e), debug.debugLevel.ERROR)
self.environment['runtime']['debug'].writeDebugOut(
'shutdownRequest: Error stopping main event loop: ' + str(e),
debug.debugLevel.ERROR)
def captureSignal(self, sigInit, frame):
self.shutdownRequest()
@ -217,7 +257,8 @@ class fenrirManager():
def shutdown(self):
self.environment['runtime']['inputManager'].ungrabAllDevices()
self.environment['runtime']['eventManager'].stopMainEventLoop()
self.environment['runtime']['outputManager'].presentText(_("Quit Fenrir"), soundIcon='ScreenReaderOff', interrupt=True)
self.environment['runtime']['outputManager'].presentText(
_("Quit Fenrir"), soundIcon='ScreenReaderOff', interrupt=True)
self.environment['runtime']['eventManager'].cleanEventQueue()
time.sleep(0.6)