fenrir/src/fenrirscreenreader/core/vmenuManager.py

66 lines
2.3 KiB
Python
Raw Normal View History

2019-01-21 18:16:41 -05:00
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
class vmenuManager():
def __init__(self):
2019-01-21 18:37:07 -05:00
self.menuDict = {}
self.currMenu = {}
self.currIndex = None
self.currLevel = None
self.active = False
2019-01-21 18:16:41 -05:00
def initialize(self, environment):
self.env = environment
def shutdown(self):
2019-01-21 18:37:07 -05:00
pass
def getActive(self):
return self.active
def togglelMode(self):
self.setActive(not self.getActive())
def setActive(self, active):
self.active = active
if active:
2019-01-21 18:16:41 -05:00
self.createHelpDict()
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:
del(self.env['bindings'][str([1, ['KEY_ESC']])])
del(self.env['bindings'][str([1, ['KEY_UP']])])
del(self.env['bindings'][str([1, ['KEY_DOWN']])])
del(self.env['bindings'][str([1, ['KEY_SPACE']])])
except:
pass
2019-01-21 18:37:07 -05:00
2019-01-21 18:16:41 -05:00
def createHelpDict(self, section = 'commands'):
2019-01-21 18:37:07 -05:00
self.menuDict = {}
#for command in sorted(self.env['commands'][section].keys()):
# self.menuDict[len(self.menuDict)] = self.getCommandHelpText(command, section)
if len(self.menuDict) > 0:
self.currIndex = 0
2019-01-21 18:16:41 -05:00
else:
2019-01-21 18:37:07 -05:00
self.currIndex = None
2019-01-21 18:16:41 -05:00
def getHelpForCurrentIndex(self):
2019-01-21 18:37:07 -05:00
if self.currIndex == None:
2019-01-21 18:16:41 -05:00
return ''
2019-01-21 18:37:07 -05:00
return self.menuDict[self.currIndex]
2019-01-21 18:16:41 -05:00
def nextIndex(self):
2019-01-21 18:37:07 -05:00
if self.currIndex == None:
2019-01-21 18:16:41 -05:00
return
2019-01-21 18:37:07 -05:00
self.currIndex += 1
if self.currIndex >= len(self.menuDict):
self.currIndex = 0
2019-01-21 18:16:41 -05:00
def prevIndex(self):
2019-01-21 18:37:07 -05:00
if self.currIndex == None:
2019-01-21 18:16:41 -05:00
return
2019-01-21 18:37:07 -05:00
self.currIndex -= 1
if self.currIndex < 0:
self.currIndex = len(self.menuDict) - 1