This commit is contained in:
chrys 2019-01-22 00:37:07 +01:00
parent 4f22cb6fd3
commit 39684dea75
3 changed files with 32 additions and 46 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ fenrir.egg-info/
fenrir_screenreader.egg-info/ fenrir_screenreader.egg-info/
dist/ dist/
build/ build/
*.kate-swp
.directory

View File

@ -9,17 +9,22 @@ from fenrirscreenreader.core import debug
class vmenuManager(): class vmenuManager():
def __init__(self): def __init__(self):
self.helpDict = {} self.menuDict = {}
self.tutorialListIndex = None self.currMenu = {}
self.currIndex = None
self.currLevel = None
self.active = False
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
def shutdown(self): def shutdown(self):
pass pass
def toggleTutorialMode(self): def getActive(self):
self.setTutorialMode(not self.env['general']['tutorialMode']) return self.active
def setTutorialMode(self, newTutorialMode): def togglelMode(self):
self.env['general']['tutorialMode'] = newTutorialMode self.setActive(not self.getActive())
if newTutorialMode: def setActive(self, active):
self.active = active
if active:
self.createHelpDict() 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_UP']])] = 'PREV_HELP'
@ -33,49 +38,28 @@ class vmenuManager():
del(self.env['bindings'][str([1, ['KEY_SPACE']])]) del(self.env['bindings'][str([1, ['KEY_SPACE']])])
except: except:
pass pass
def isTutorialMode(self):
return self.env['general']['tutorialMode']
def getCommandHelpText(self, command, section = 'commands'):
commandName = command.lower()
commandName = commandName.split('__-__')[0]
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')
if commandDescription == '':
commandDescription = 'no Description available'
commandShortcut = self.env['runtime']['commandManager'].getShortcutForCommand( command)
commandShortcut = commandShortcut.replace('KEY_',' ')
commandShortcut = commandShortcut.replace('[','')
commandShortcut = commandShortcut.replace(']','')
commandShortcut = commandShortcut.replace("'",'')
if commandShortcut == '':
commandShortcut = 'unbound'
helptext = commandName + ', Shortcut ' + commandShortcut + ', Description ' + commandDescription
return helptext
def createHelpDict(self, section = 'commands'): def createHelpDict(self, section = 'commands'):
self.helpDict = {} self.menuDict = {}
for command in sorted(self.env['commands'][section].keys()): #for command in sorted(self.env['commands'][section].keys()):
self.helpDict[len(self.helpDict)] = self.getCommandHelpText(command, section) # self.menuDict[len(self.menuDict)] = self.getCommandHelpText(command, section)
if len(self.helpDict) > 0: if len(self.menuDict) > 0:
self.tutorialListIndex = 0 self.currIndex = 0
else: else:
self.tutorialListIndex = None self.currIndex = None
def getHelpForCurrentIndex(self): def getHelpForCurrentIndex(self):
if self.tutorialListIndex == None: if self.currIndex == None:
return '' return ''
return self.helpDict[self.tutorialListIndex] return self.menuDict[self.currIndex]
def nextIndex(self): def nextIndex(self):
if self.tutorialListIndex == None: if self.currIndex == None:
return return
self.tutorialListIndex += 1 self.currIndex += 1
if self.tutorialListIndex >= len(self.helpDict): if self.currIndex >= len(self.menuDict):
self.tutorialListIndex = 0 self.currIndex = 0
def prevIndex(self): def prevIndex(self):
if self.tutorialListIndex == None: if self.currIndex == None:
return return
self.tutorialListIndex -= 1 self.currIndex -= 1
if self.tutorialListIndex < 0: if self.currIndex < 0:
self.tutorialListIndex = len(self.helpDict) - 1 self.currIndex = len(self.menuDict) - 1