Most of the pep8 changes finished. Be careful, things may be horribly broken.

This commit is contained in:
Storm Dragon
2025-07-03 13:22:00 -04:00
parent 7408951152
commit 21bb9c6083
344 changed files with 6374 additions and 6083 deletions

View File

@ -12,171 +12,171 @@ import sys
from fenrirscreenreader.core.i18n import _
from fenrirscreenreader.core import settingsManager
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.eventData import fenrirEventType
from fenrirscreenreader.core.eventData import FenrirEventType
class fenrirManager():
class FenrirManager():
def __init__(self, cliArgs):
self.isInitialized = False
self.is_initialized = False
try:
self.environment = settingsManager.settingsManager().initFenrirConfig(cliArgs, self)
self.environment = settingsManager.SettingsManager().init_fenrir_config(cliArgs, self)
if not self.environment:
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)
signal.signal(signal.SIGINT, self.captureSignal)
signal.signal(signal.SIGTERM, self.captureSignal)
self.environment['runtime']['OutputManager'].present_text(
_("Start Fenrir"), sound_icon ='ScreenReaderOn', interrupt=True)
signal.signal(signal.SIGINT, self.capture_signal)
signal.signal(signal.SIGTERM, self.capture_signal)
self.isInitialized = True
self.is_initialized = True
self.modifierInput = False
self.singleKeyCommand = False
self.command = ''
self.setProcessName()
self.set_process_name()
def proceed(self):
if not self.isInitialized:
if not self.is_initialized:
return
self.environment['runtime']['eventManager'].startMainEventLoop()
self.environment['runtime']['EventManager'].start_main_event_loop()
self.shutdown()
def handleInput(self, event):
self.environment['runtime']['debug'].writeDebugOut(
'DEBUG INPUT fenrirMan:' + str(event), debug.debugLevel.INFO)
def handle_input(self, event):
self.environment['runtime']['DebugManager'].write_debug_out(
'DEBUG INPUT fenrirMan:' + str(event), debug.DebugLevel.INFO)
if not event['Data']:
event['Data'] = self.environment['runtime']['inputManager'].getInputEvent()
if not event['data']:
event['data'] = self.environment['runtime']['InputManager'].get_input_event()
if event['Data']:
event['Data']['EventName'] = self.environment['runtime']['inputManager'].convertEventName(
event['Data']['EventName'])
self.environment['runtime']['inputManager'].handleInputEvent(
event['Data'])
if event['data']:
event['data']['EventName'] = self.environment['runtime']['InputManager'].convert_event_name(
event['data']['EventName'])
self.environment['runtime']['InputManager'].handle_input_event(
event['data'])
else:
return
if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['inputManager'].clearLastDeepInput()
if self.environment['runtime']['InputManager'].no_key_pressed():
self.environment['runtime']['InputManager'].clear_last_deep_input()
if self.environment['runtime']['screenManager'].isIgnoredScreen():
self.environment['runtime']['inputManager'].writeEventBuffer()
if self.environment['runtime']['ScreenManager'].is_ignored_screen():
self.environment['runtime']['InputManager'].write_event_buffer()
else:
if self.environment['runtime']['helpManager'].isTutorialMode():
self.environment['runtime']['inputManager'].clearEventBuffer()
self.environment['runtime']['inputManager'].keyEcho(
event['Data'])
if self.environment['runtime']['HelpManager'].is_tutorial_mode():
self.environment['runtime']['InputManager'].clear_event_buffer()
self.environment['runtime']['InputManager'].key_echo(
event['data'])
if self.environment['runtime']['vmenuManager'].getActive():
self.environment['runtime']['inputManager'].clearEventBuffer()
if self.environment['runtime']['VmenuManager'].get_active():
self.environment['runtime']['InputManager'].clear_event_buffer()
self.detectShortcutCommand()
self.detect_shortcut_command()
if self.modifierInput:
self.environment['runtime']['inputManager'].clearEventBuffer()
self.environment['runtime']['InputManager'].clear_event_buffer()
if self.singleKeyCommand:
if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['inputManager'].clearEventBuffer()
if self.environment['runtime']['InputManager'].no_key_pressed():
self.environment['runtime']['InputManager'].clear_event_buffer()
else:
self.environment['runtime']['inputManager'].writeEventBuffer()
self.environment['runtime']['InputManager'].write_event_buffer()
if self.environment['runtime']['inputManager'].noKeyPressed():
if self.environment['runtime']['InputManager'].no_key_pressed():
self.modifierInput = False
self.singleKeyCommand = False
self.environment['runtime']['inputManager'].writeEventBuffer()
self.environment['runtime']['inputManager'].handleDeviceGrab()
self.environment['runtime']['InputManager'].write_event_buffer()
self.environment['runtime']['InputManager'].handle_device_grab()
if self.environment['input']['keyForeward'] > 0:
self.environment['input']['keyForeward'] -= 1
self.environment['runtime']['commandManager'].executeDefaultTrigger(
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onKeyInput')
def handleByteInput(self, event):
if not event['Data'] or event['Data'] == b'':
def handle_byte_input(self, event):
if not event['data'] or event['data'] == b'':
return
self.environment['runtime']['byteManager'].handleByteInput(
event['Data'])
self.environment['runtime']['commandManager'].executeDefaultTrigger(
self.environment['runtime']['ByteManager'].handle_byte_input(
event['data'])
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onByteInput')
def handleExecuteCommand(self, event):
if not event['Data'] or event['Data'] == '':
def handle_execute_command(self, event):
if not event['data'] or event['data'] == '':
return
currentCommand = event['Data']
current_command = event['data']
# 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']['HelpManager'].is_tutorial_mode():
if self.environment['runtime']['CommandManager'].command_exists(
current_command, 'help'):
self.environment['runtime']['CommandManager'].execute_command(
current_command, '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')
elif self.environment['runtime']['VmenuManager'].get_active():
if self.environment['runtime']['CommandManager'].command_exists(
current_command, 'vmenu-navigation'):
self.environment['runtime']['CommandManager'].execute_command(
current_command, 'vmenu-navigation')
return
# default
self.environment['runtime']['commandManager'].executeCommand(
currentCommand, 'commands')
self.environment['runtime']['CommandManager'].execute_command(
current_command, 'commands')
def handleRemoteIncomming(self, event):
if not event['Data']:
def handle_remote_incomming(self, event):
if not event['data']:
return
self.environment['runtime']['remoteManager'].handleRemoteIncomming(
event['Data'])
self.environment['runtime']['remoteManager'].handle_remote_incomming(
event['data'])
def handleScreenChange(self, event):
self.environment['runtime']['screenManager'].handleScreenChange(
event['Data'])
if self.environment['runtime']['vmenuManager'].getActive():
def handle_screen_change(self, event):
self.environment['runtime']['ScreenManager'].handle_screen_change(
event['data'])
if self.environment['runtime']['VmenuManager'].get_active():
return
self.environment['runtime']['commandManager'].executeDefaultTrigger(
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onScreenChanged')
self.environment['runtime']['screenDriver'].getCurrScreen()
self.environment['runtime']['ScreenDriver'].get_curr_screen()
def handleScreenUpdate(self, event):
self.environment['runtime']['screenManager'].handleScreenUpdate(
event['Data'])
def handle_screen_update(self, event):
self.environment['runtime']['ScreenManager'].handle_screen_update(
event['data'])
if time.time() - \
self.environment['runtime']['inputManager'].getLastInputTime() >= 0.3:
self.environment['runtime']['inputManager'].clearLastDeepInput()
self.environment['runtime']['InputManager'].get_last_input_time() >= 0.3:
self.environment['runtime']['InputManager'].clear_last_deep_input()
if (self.environment['runtime']['cursorManager'].isCursorVerticalMove(
) or self.environment['runtime']['cursorManager'].isCursorHorizontalMove()):
self.environment['runtime']['commandManager'].executeDefaultTrigger(
if (self.environment['runtime']['CursorManager'].is_cursor_vertical_move(
) or self.environment['runtime']['CursorManager'].is_cursor_horizontal_move()):
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onCursorChange')
self.environment['runtime']['commandManager'].executeDefaultTrigger(
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onScreenUpdate')
self.environment['runtime']['inputManager'].clearLastDeepInput()
self.environment['runtime']['InputManager'].clear_last_deep_input()
def handlePlugInputDevice(self, event):
def handle_plug_input_device(self, event):
try:
self.environment['runtime']['inputManager'].setLastDetectedDevices(
event['Data'])
self.environment['runtime']['InputManager'].set_last_detected_devices(
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(
self.environment['runtime']['DebugManager'].write_debug_out(
'handle_plug_input_device: Error setting last detected devices: ' + str(e),
debug.DebugLevel.ERROR)
self.environment['runtime']['InputManager'].handle_plug_input_device(
event['data'])
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onPlugInputDevice', force=True)
self.environment['runtime']['inputManager'].setLastDetectedDevices(
self.environment['runtime']['InputManager'].set_last_detected_devices(
None)
def handleHeartBeat(self, event):
self.environment['runtime']['commandManager'].executeDefaultTrigger(
def handle_heart_beat(self, event):
self.environment['runtime']['CommandManager'].execute_default_trigger(
'onHeartBeat', force=True)
def detectShortcutCommand(self):
def detect_shortcut_command(self):
if self.environment['input']['keyForeward'] > 0:
return
@ -184,24 +184,24 @@ class fenrirManager():
self.environment['input']['currInput']):
return
if self.environment['runtime']['inputManager'].isKeyPress():
self.modifierInput = self.environment['runtime']['inputManager'].currKeyIsModifier(
if self.environment['runtime']['InputManager'].is_key_press():
self.modifierInput = self.environment['runtime']['InputManager'].curr_key_is_modifier(
)
else:
if not self.environment['runtime']['inputManager'].noKeyPressed():
if not self.environment['runtime']['InputManager'].no_key_pressed():
if self.singleKeyCommand:
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.singleKeyCommand and self.environment['runtime']['InputManager'].no_key_pressed()):
current_shortcut = self.environment['runtime']['InputManager'].get_curr_shortcut(
)
self.command = self.environment['runtime']['inputManager'].getCommandForShortcut(
currentShortcut)
self.command = self.environment['runtime']['InputManager'].get_command_for_shortcut(
current_shortcut)
if not self.modifierInput:
if self.environment['runtime']['inputManager'].isKeyPress():
if self.environment['runtime']['InputManager'].is_key_press():
if self.command != '':
self.singleKeyCommand = True
@ -211,16 +211,16 @@ class fenrirManager():
# fire event
if self.command != '':
if self.modifierInput:
self.environment['runtime']['eventManager'].putToEventQueue(
fenrirEventType.ExecuteCommand, self.command)
self.environment['runtime']['EventManager'].put_to_event_queue(
FenrirEventType.execute_command, self.command)
self.command = ''
else:
if self.singleKeyCommand:
self.environment['runtime']['eventManager'].putToEventQueue(
fenrirEventType.ExecuteCommand, self.command)
self.environment['runtime']['EventManager'].put_to_event_queue(
FenrirEventType.execute_command, self.command)
self.command = ''
def setProcessName(self, name='fenrir'):
def set_process_name(self, name='fenrir'):
"""Attempts to set the process name to 'fenrir'."""
try:
from setproctitle import setproctitle
@ -233,33 +233,33 @@ class fenrirManager():
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)
string_buffer = create_string_buffer(len(name) + 1)
string_buffer.value = bytes(name, 'UTF-8')
libc.prctl(15, byref(string_buffer), 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']['DebugManager'].write_debug_out(
'setProcName: Error setting process name: ' + str(e), debug.DebugLevel.ERROR)
return False
def shutdownRequest(self):
def shutdown_request(self):
try:
self.environment['runtime']['eventManager'].stopMainEventLoop()
self.environment['runtime']['EventManager'].stop_main_event_loop()
except Exception as e:
self.environment['runtime']['debug'].writeDebugOut(
'shutdownRequest: Error stopping main event loop: ' + str(e),
debug.debugLevel.ERROR)
self.environment['runtime']['DebugManager'].write_debug_out(
'shutdown_request: Error stopping main event loop: ' + str(e),
debug.DebugLevel.ERROR)
def captureSignal(self, sigInit, frame):
self.shutdownRequest()
def capture_signal(self, sigInit, frame):
self.shutdown_request()
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']['eventManager'].cleanEventQueue()
self.environment['runtime']['InputManager'].ungrab_all_devices()
self.environment['runtime']['EventManager'].stop_main_event_loop()
self.environment['runtime']['OutputManager'].present_text(
_("Quit Fenrir"), sound_icon ='ScreenReaderOff', interrupt=True)
self.environment['runtime']['EventManager'].clean_event_queue()
time.sleep(0.6)
for currentManager in self.environment['general']['managerList']: