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

@ -5,47 +5,65 @@
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.i18n import _
class helpManager():
def __init__(self):
self.helpDict = {}
self.tutorialListIndex = None
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
pass
def toggleTutorialMode(self):
self.setTutorialMode(not self.env['general']['tutorialMode'])
def setTutorialMode(self, newTutorialMode):
if self.env['runtime']['vmenuManager'].getActive():
return
self.env['general']['tutorialMode'] = newTutorialMode
if newTutorialMode:
self.createHelpDict()
self.env['bindings'][str([1, ['KEY_ESC']])] = 'TOGGLE_TUTORIAL_MODE'
self.env['bindings'][str([1, ['KEY_ESC']])
] = 'TOGGLE_TUTORIAL_MODE'
self.env['bindings'][str([1, ['KEY_UP']])] = 'PREV_HELP'
self.env['bindings'][str([1, ['KEY_DOWN']])] = 'NEXT_HELP'
self.env['bindings'][str([1, ['KEY_SPACE']])] = 'CURR_HELP'
else:
try:
self.env['bindings'] = self.env['runtime']['settingsManager'].getBindingBackup()
self.env['bindings'] = self.env['runtime']['settingsManager'].getBindingBackup(
)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('helpManager setTutorialMode: Error restoring binding backup: ' + str(e), debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(
'helpManager setTutorialMode: Error restoring binding backup: ' + str(e),
debug.debugLevel.ERROR)
def isTutorialMode(self):
return self.env['general']['tutorialMode']
def getFormattedShortcutForCommand(self, command):
shortcut = []
rawShortcut = []
try:
rawShortcut = list(self.env['bindings'].keys())[list(self.env['bindings'].values()).index(command)]
rawShortcut = list(self.env['bindings'].keys())[
list(self.env['bindings'].values()).index(command)]
rawShortcut = self.env['rawBindings'][rawShortcut]
# prefer numbers for multitap
if rawShortcut[0] in range(2, 9):
formattedKey = str(rawShortcut[0]) +' times '
formattedKey = str(rawShortcut[0]) + ' times '
shortcut.append(formattedKey)
# prefer metha keys
for k in ['KEY_FENRIR', 'KEY_SCRIPT', 'KEY_CTRL', 'KEY_SHIFT', 'KEY_ALT', 'KEY_META']:
for k in [
'KEY_FENRIR',
'KEY_SCRIPT',
'KEY_CTRL',
'KEY_SHIFT',
'KEY_ALT',
'KEY_META']:
if k in rawShortcut[1]:
formattedKey = k
formattedKey = formattedKey.lower()
@ -63,48 +81,55 @@ class helpManager():
except Exception as e:
return ''
shortcut = str(shortcut)
shortcut = shortcut.replace('[','')
shortcut = shortcut.replace(']','')
shortcut = shortcut.replace("'",'')
shortcut = shortcut.replace('[', '')
shortcut = shortcut.replace(']', '')
shortcut = shortcut.replace("'", '')
return shortcut
def getCommandHelpText(self, command, section = 'commands'):
def getCommandHelpText(self, command, section='commands'):
commandName = command.lower()
commandName = commandName.split('__-__')[0]
commandName = commandName.replace('_',' ')
commandName = commandName.replace('_',' ')
commandName = commandName.replace('_', ' ')
commandName = commandName.replace('_', ' ')
if command == 'TOGGLE_TUTORIAL_MODE':
commandDescription = _('toggles the tutorial mode')
else:
commandDescription = self.env['runtime']['commandManager'].getCommandDescription(command, section = 'commands')
commandDescription = self.env['runtime']['commandManager'].getCommandDescription(
command, section='commands')
if commandDescription == '':
commandDescription = 'no Description available'
commandShortcut = self.getFormattedShortcutForCommand(command)
if commandShortcut == '':
commandShortcut = 'unbound'
helptext = commandName + ', Shortcut ' + commandShortcut + ', Description ' + commandDescription
helptext = commandName + ', Shortcut ' + \
commandShortcut + ', Description ' + commandDescription
return helptext
def createHelpDict(self, section = 'commands'):
def createHelpDict(self, section='commands'):
self.helpDict = {}
for command in sorted(self.env['commands'][section].keys()):
self.helpDict[len(self.helpDict)] = self.getCommandHelpText(command, section)
self.helpDict[len(self.helpDict)] = self.getCommandHelpText(
command, section)
if len(self.helpDict) > 0:
self.tutorialListIndex = 0
else:
self.tutorialListIndex = None
def getHelpForCurrentIndex(self):
if self.tutorialListIndex == None:
return ''
if self.tutorialListIndex is None:
return ''
return self.helpDict[self.tutorialListIndex]
def nextIndex(self):
if self.tutorialListIndex == None:
return
if self.tutorialListIndex is None:
return
self.tutorialListIndex += 1
if self.tutorialListIndex >= len(self.helpDict):
self.tutorialListIndex = 0
self.tutorialListIndex = 0
def prevIndex(self):
if self.tutorialListIndex == None:
return
if self.tutorialListIndex is None:
return
self.tutorialListIndex -= 1
if self.tutorialListIndex < 0:
self.tutorialListIndex = len(self.helpDict) - 1
self.tutorialListIndex = len(self.helpDict) - 1