To make Fenrir easier to approach for new developer, start code migration to be pep8 compliant.
This commit is contained in:
@@ -27,8 +27,11 @@ command interrupt
|
||||
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
from fenrirscreenreader.core.i18n import _
|
||||
from fenrirscreenreader.core.eventData import fenrirEventType
|
||||
import time, os
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
class remoteManager():
|
||||
def __init__(self):
|
||||
@@ -50,16 +53,22 @@ class remoteManager():
|
||||
self.saveAsSettingConst = 'SAVEAS '
|
||||
self.saveSettingConst = 'SAVE'
|
||||
self.resetSettingConst = 'RESET'
|
||||
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
self.env['runtime']['settingsManager'].loadDriver(\
|
||||
self.env['runtime']['settingsManager'].getSetting('remote', 'driver'), 'remoteDriver')
|
||||
self.env['runtime']['settingsManager'].loadDriver(
|
||||
self.env['runtime']['settingsManager'].getSetting(
|
||||
'remote', 'driver'), 'remoteDriver')
|
||||
|
||||
def shutdown(self):
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('remoteDriver')
|
||||
|
||||
def handleSettingsChangeWithResponse(self, settingsText):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'):
|
||||
return {"success": False, "message": "Settings remote control is disabled"}
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool(
|
||||
'remote', 'enableSettingsRemote'):
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Settings remote control is disabled"}
|
||||
|
||||
upperSettingsText = settingsText.upper()
|
||||
try:
|
||||
@@ -67,12 +76,16 @@ class remoteManager():
|
||||
if upperSettingsText.startswith(self.setSettingConst):
|
||||
parameterText = settingsText[len(self.setSettingConst):]
|
||||
self.setSettings(parameterText)
|
||||
return {"success": True, "message": f"Setting applied: {parameterText}"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Setting applied: {parameterText}"}
|
||||
# save as setting
|
||||
elif upperSettingsText.startswith(self.saveAsSettingConst):
|
||||
parameterText = settingsText[len(self.saveAsSettingConst):]
|
||||
self.saveSettings(parameterText)
|
||||
return {"success": True, "message": f"Settings saved to: {parameterText}"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Settings saved to: {parameterText}"}
|
||||
# save setting
|
||||
elif upperSettingsText == self.saveSettingConst:
|
||||
self.saveSettings()
|
||||
@@ -80,14 +93,19 @@ class remoteManager():
|
||||
# reset setting
|
||||
elif upperSettingsText == self.resetSettingConst:
|
||||
self.resetSettings()
|
||||
return {"success": True, "message": "Settings reset to defaults"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Settings reset to defaults"}
|
||||
else:
|
||||
return {"success": False, "message": f"Unknown settings command: {settingsText}"}
|
||||
return {
|
||||
"success": False,
|
||||
"message": f"Unknown settings command: {settingsText}"}
|
||||
except Exception as e:
|
||||
return {"success": False, "message": f"Settings error: {str(e)}"}
|
||||
|
||||
def handleSettingsChange(self, settingsText):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool(
|
||||
'remote', 'enableSettingsRemote'):
|
||||
return
|
||||
|
||||
upperSettingsText = settingsText.upper()
|
||||
@@ -107,8 +125,11 @@ class remoteManager():
|
||||
self.resetSettings()
|
||||
|
||||
def handleCommandExecutionWithResponse(self, commandText):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'):
|
||||
return {"success": False, "message": "Command remote control is disabled"}
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool(
|
||||
'remote', 'enableCommandRemote'):
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Command remote control is disabled"}
|
||||
|
||||
upperCommandText = commandText.upper()
|
||||
|
||||
@@ -117,7 +138,8 @@ class remoteManager():
|
||||
if upperCommandText.startswith(self.sayConst):
|
||||
parameterText = commandText[len(self.sayConst):]
|
||||
self.say(parameterText)
|
||||
return {"success": True, "message": f"Speaking: {parameterText[:50]}{'...' if len(parameterText) > 50 else ''}"}
|
||||
return {"success": True,
|
||||
"message": f"Speaking: {parameterText[:50]}{'...' if len(parameterText) > 50 else ''}"}
|
||||
# interrupt
|
||||
elif upperCommandText == self.interruptConst:
|
||||
self.interruptSpeech()
|
||||
@@ -125,12 +147,16 @@ class remoteManager():
|
||||
# temp disable speech
|
||||
elif upperCommandText == self.tempDisableSpeechConst:
|
||||
self.tempDisableSpeech()
|
||||
return {"success": True, "message": "Speech temporarily disabled"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Speech temporarily disabled"}
|
||||
# set vmenu
|
||||
elif upperCommandText.startswith(self.vmenuConst):
|
||||
parameterText = commandText[len(self.vmenuConst):]
|
||||
self.setVMenu(parameterText)
|
||||
return {"success": True, "message": f"VMenu set to: {parameterText}"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"VMenu set to: {parameterText}"}
|
||||
# reset vmenu
|
||||
elif upperCommandText == self.resetVmenuConst:
|
||||
self.resetVMenu()
|
||||
@@ -143,7 +169,9 @@ class remoteManager():
|
||||
elif upperCommandText.startswith(self.defineWindowConst):
|
||||
parameterText = commandText[len(self.defineWindowConst):]
|
||||
self.defineWindow(parameterText)
|
||||
return {"success": True, "message": f"Window defined: {parameterText}"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Window defined: {parameterText}"}
|
||||
# reset window
|
||||
elif upperCommandText == self.resetWindowConst:
|
||||
self.resetWindow()
|
||||
@@ -152,17 +180,23 @@ class remoteManager():
|
||||
elif upperCommandText.startswith(self.setClipboardConst):
|
||||
parameterText = commandText[len(self.setClipboardConst):]
|
||||
self.setClipboard(parameterText)
|
||||
return {"success": True, "message": f"Clipboard set: {parameterText[:50]}{'...' if len(parameterText) > 50 else ''}"}
|
||||
return {"success": True,
|
||||
"message": f"Clipboard set: {parameterText[:50]}{'...' if len(parameterText) > 50 else ''}"}
|
||||
elif upperCommandText.startswith(self.exportClipboardConst):
|
||||
self.exportClipboard()
|
||||
return {"success": True, "message": "Clipboard exported to file"}
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Clipboard exported to file"}
|
||||
else:
|
||||
return {"success": False, "message": f"Unknown command: {commandText}"}
|
||||
return {
|
||||
"success": False,
|
||||
"message": f"Unknown command: {commandText}"}
|
||||
except Exception as e:
|
||||
return {"success": False, "message": f"Command error: {str(e)}"}
|
||||
|
||||
def handleCommandExecution(self, commandText):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool(
|
||||
'remote', 'enableCommandRemote'):
|
||||
return
|
||||
|
||||
upperCommandText = commandText.upper()
|
||||
@@ -200,16 +234,23 @@ class remoteManager():
|
||||
self.setClipboard(parameterText)
|
||||
elif upperCommandText.startswith(self.exportClipboardConst):
|
||||
self.exportClipboard()
|
||||
|
||||
def tempDisableSpeech(self):
|
||||
self.env['runtime']['outputManager'].tempDisableSpeech()
|
||||
def setVMenu(self, vmenu = ''):
|
||||
|
||||
def setVMenu(self, vmenu=''):
|
||||
self.env['runtime']['vmenuManager'].setCurrMenu(vmenu)
|
||||
|
||||
def resetVMenu(self):
|
||||
self.env['runtime']['vmenuManager'].setCurrMenu()
|
||||
def setClipboard(self, text = ''):
|
||||
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', text)
|
||||
|
||||
def setClipboard(self, text=''):
|
||||
self.env['runtime']['memoryManager'].addValueToFirstIndex(
|
||||
'clipboardHistory', text)
|
||||
|
||||
def quitFenrir(self):
|
||||
self.env['runtime']['eventManager'].stopMainEventLoop()
|
||||
|
||||
def defineWindow(self, windowText):
|
||||
start = {}
|
||||
end = {}
|
||||
@@ -222,30 +263,42 @@ class remoteManager():
|
||||
end['x'] = int(windowList[2])
|
||||
end['y'] = int(windowList[3])
|
||||
|
||||
self.env['runtime']['cursorManager'].setWindowForApplication(start, end)
|
||||
self.env['runtime']['cursorManager'].setWindowForApplication(
|
||||
start, end)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def resetWindow(self):
|
||||
self.env['runtime']['cursorManager'].clearWindowForApplication()
|
||||
|
||||
def say(self, text):
|
||||
if not text:
|
||||
return
|
||||
if text == '':
|
||||
return
|
||||
self.env['runtime']['outputManager'].speakText(text)
|
||||
|
||||
def interruptSpeech(self):
|
||||
self.env['runtime']['outputManager'].interruptOutput()
|
||||
|
||||
def exportClipboard(self):
|
||||
clipboardFilePath = self.env['runtime']['settingsManager'].getSetting('general', 'clipboardExportPath')
|
||||
clipboardFilePath = clipboardFilePath.replace('$user',self.env['general']['currUser'])
|
||||
clipboardFilePath = clipboardFilePath.replace('$USER',self.env['general']['currUser'])
|
||||
clipboardFilePath = clipboardFilePath.replace('$User',self.env['general']['currUser'])
|
||||
clipboardFile = open(clipboardFilePath,'w')
|
||||
clipboardFilePath = self.env['runtime']['settingsManager'].getSetting(
|
||||
'general', 'clipboardExportPath')
|
||||
clipboardFilePath = clipboardFilePath.replace(
|
||||
'$user', self.env['general']['currUser'])
|
||||
clipboardFilePath = clipboardFilePath.replace(
|
||||
'$USER', self.env['general']['currUser'])
|
||||
clipboardFilePath = clipboardFilePath.replace(
|
||||
'$User', self.env['general']['currUser'])
|
||||
clipboardFile = open(clipboardFilePath, 'w')
|
||||
try:
|
||||
if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'):
|
||||
self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True)
|
||||
return
|
||||
clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory')
|
||||
if self.env['runtime']['memoryManager'].isIndexListEmpty(
|
||||
'clipboardHistory'):
|
||||
self.env['runtime']['outputManager'].presentText(
|
||||
_('clipboard empty'), interrupt=True)
|
||||
return
|
||||
clipboard = self.env['runtime']['memoryManager'].getIndexListElement(
|
||||
'clipboardHistory')
|
||||
# Fenrir will crash if the clipboard variable is type None
|
||||
if clipboard is not None:
|
||||
clipboardFile.write(clipboard)
|
||||
@@ -253,28 +306,41 @@ class remoteManager():
|
||||
clipboardFile.write('')
|
||||
clipboardFile.close()
|
||||
os.chmod(clipboardFilePath, 0o644)
|
||||
self.env['runtime']['outputManager'].presentText(_('clipboard exported to file'), interrupt=True)
|
||||
self.env['runtime']['outputManager'].presentText(
|
||||
_('clipboard exported to file'), interrupt=True)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut('export_clipboard_to_file:run: Filepath:'+ clipboardFile +' trace:' + str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'export_clipboard_to_file:run: Filepath:' +
|
||||
clipboardFile +
|
||||
' trace:' +
|
||||
str(e),
|
||||
debug.debugLevel.ERROR)
|
||||
|
||||
def saveSettings(self, settingConfigPath = None):
|
||||
def saveSettings(self, settingConfigPath=None):
|
||||
if not settingConfigPath:
|
||||
settingConfigPath = self.env['runtime']['settingsManager'].getSettingsFile()
|
||||
settingConfigPath = self.env['runtime']['settingsManager'].getSettingsFile(
|
||||
)
|
||||
if settingConfigPath == '':
|
||||
return
|
||||
self.env['runtime']['settingsManager'].saveSettings(settingConfigPath)
|
||||
|
||||
def resetSettings(self):
|
||||
self.env['runtime']['settingsManager'].resetSettingArgDict()
|
||||
|
||||
def setSettings(self, settingsArgs):
|
||||
self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs)
|
||||
self.env['runtime']['screenManager'].updateScreenIgnored()
|
||||
self.env['runtime']['inputManager'].handleDeviceGrab(force = True)
|
||||
self.env['runtime']['inputManager'].handleDeviceGrab(force=True)
|
||||
|
||||
def handleRemoteIncommingWithResponse(self, eventData):
|
||||
if not eventData:
|
||||
return {"success": False, "message": "No data received"}
|
||||
|
||||
|
||||
upperEventData = eventData.upper()
|
||||
self.env['runtime']['debug'].writeDebugOut('remoteManager:handleRemoteIncommingWithResponse: event: ' + str(eventData),debug.debugLevel.INFO)
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'remoteManager:handleRemoteIncommingWithResponse: event: ' +
|
||||
str(eventData),
|
||||
debug.debugLevel.INFO)
|
||||
|
||||
try:
|
||||
if upperEventData.startswith(self.settingConst):
|
||||
@@ -284,15 +350,20 @@ class remoteManager():
|
||||
commandText = eventData[len(self.commandConst):]
|
||||
return self.handleCommandExecutionWithResponse(commandText)
|
||||
else:
|
||||
return {"success": False, "message": "Unknown command format. Use 'COMMAND ...' or 'SETTING ...'"}
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Unknown command format. Use 'COMMAND ...' or 'SETTING ...'"}
|
||||
except Exception as e:
|
||||
return {"success": False, "message": f"Exception: {str(e)}"}
|
||||
|
||||
|
||||
def handleRemoteIncomming(self, eventData):
|
||||
if not eventData:
|
||||
return
|
||||
upperEventData = eventData.upper()
|
||||
self.env['runtime']['debug'].writeDebugOut('remoteManager:handleRemoteIncomming: event: ' + str(eventData),debug.debugLevel.INFO)
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'remoteManager:handleRemoteIncomming: event: ' +
|
||||
str(eventData),
|
||||
debug.debugLevel.INFO)
|
||||
|
||||
if upperEventData.startswith(self.settingConst):
|
||||
settingsText = eventData[len(self.settingConst):]
|
||||
|
||||
Reference in New Issue
Block a user