add keyecho to tutorial mode

This commit is contained in:
chrys 2019-03-03 20:57:58 +01:00
parent 49c9645b8a
commit da8e28540e
4 changed files with 60 additions and 23 deletions

View File

@ -0,0 +1,23 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'No description found'
def run(self):
if self.env['runtime']['helpManager'].isTutorialMode():
self.env['runtime']['inputManager'].keyEcho(event)
def setCallback(self, callback):
pass

View File

@ -37,14 +37,11 @@ class commandManager():
return None return None
if not os.path.exists(filepath): if not os.path.exists(filepath):
self.env['runtime']['debug'].writeDebugOut("loadFile: filepath not exists:" + filepath ,debug.debugLevel.WARNING) self.env['runtime']['debug'].writeDebugOut("loadFile: filepath not exists:" + filepath ,debug.debugLevel.WARNING)
print('1')
return None return None
if os.path.isdir(filepath): if os.path.isdir(filepath):
print('2')
self.env['runtime']['debug'].writeDebugOut("loadFile: filepath is a directory:" + filepath ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("loadFile: filepath is a directory:" + filepath ,debug.debugLevel.ERROR)
return None return None
if not os.access(filepath, os.R_OK): if not os.access(filepath, os.R_OK):
print('3')
self.env['runtime']['debug'].writeDebugOut("loadFile: filepath not readable:" + filepath ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("loadFile: filepath not readable:" + filepath ,debug.debugLevel.ERROR)
return None return None
@ -149,18 +146,18 @@ class commandManager():
if not self.env['runtime']['inputManager'].isValidKey(key.upper()): if not self.env['runtime']['inputManager'].isValidKey(key.upper()):
self.env['runtime']['debug'].writeDebugOut("invalid key : "+ key.upper() + ' script:' + fileName ,debug.debugLevel.WARNING) self.env['runtime']['debug'].writeDebugOut("invalid key : "+ key.upper() + ' script:' + fileName ,debug.debugLevel.WARNING)
invalid = True invalid = True
break break
shortcutKeys.append(key.upper()) shortcutKeys.append(key.upper())
if invalid: if invalid:
continue continue
if not 'KEY_SCRIPT' in shortcutKeys: if not 'KEY_SCRIPT' in shortcutKeys:
shortcutKeys.append('KEY_SCRIPT') shortcutKeys.append('KEY_SCRIPT')
shortcut.append(1) shortcut.append(1)
shortcut.append(sorted(shortcutKeys)) shortcut.append(sorted(shortcutKeys))
self.env['bindings'][str(shortcut)] = fileName.upper() self.env['bindings'][str(shortcut)] = fileName.upper()
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Loading script:" + fileName ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("Loading script:" + fileName ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
continue continue
def shutdownCommands(self, section): def shutdownCommands(self, section):
for command in sorted(self.env['commands'][section]): for command in sorted(self.env['commands'][section]):
@ -177,36 +174,36 @@ class commandManager():
return return
#unload #unload
oldScript = unLoadScript oldScript = unLoadScript
if self.commandExists(oldScript, trigger): if self.commandExists(oldScript, trigger):
try: try:
self.env['runtime']['debug'].writeDebugOut("Executing switchtrigger.unload:" + trigger + "." + oldScript ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Executing switchtrigger.unload:" + trigger + "." + oldScript ,debug.debugLevel.INFO)
self.env['commands'][trigger][oldScript].unload() self.env['commands'][trigger][oldScript].unload()
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + oldScript ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + oldScript ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
#load #load
newScript = loadScript newScript = loadScript
if self.commandExists(newScript, trigger): if self.commandExists(newScript, trigger):
try: try:
self.env['runtime']['debug'].writeDebugOut("Executing switchtrigger.load:" + trigger + "." + newScript ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Executing switchtrigger.load:" + trigger + "." + newScript ,debug.debugLevel.INFO)
self.env['commands'][trigger][newScript].load() self.env['commands'][trigger][newScript].load()
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + newScript ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + newScript ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
def executeDefaultTrigger(self, trigger, force=False): def executeDefaultTrigger(self, trigger, force=False):
if not force: if not force:
if self.env['runtime']['screenManager'].isSuspendingScreen(): if self.env['runtime']['screenManager'].isSuspendingScreen():
return return
for command in sorted(self.env['commands'][trigger]): for command in sorted(self.env['commands'][trigger]):
if self.commandExists(command, trigger): if self.commandExists(command, trigger):
try: try:
if self.env['commandsIgnore'][trigger][command[command.find('-')+1:]+'_IGNORE']: if self.env['commandsIgnore'][trigger][command[command.find('-')+1:]+'_IGNORE']:
self.env['commandsIgnore'][trigger][command[command.find('-')+1:]+'_IGNORE'] = False self.env['commandsIgnore'][trigger][command[command.find('-')+1:]+'_IGNORE'] = False
self.env['runtime']['debug'].writeDebugOut("Ignore trigger.command:" + trigger + "." + command ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Ignore trigger.command:" + trigger + "." + command ,debug.debugLevel.INFO)
else: else:
self.env['runtime']['debug'].writeDebugOut("Executing trigger.command:" + trigger + "." + command ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Executing trigger.command:" + trigger + "." + command ,debug.debugLevel.INFO)
self.env['commands'][trigger][command].run() self.env['commands'][trigger][command].run()
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + command + str(e) ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + command + str(e) ,debug.debugLevel.ERROR)
@ -216,11 +213,11 @@ class commandManager():
if self.commandExists(command, section): if self.commandExists(command, section):
try: try:
if self.env['runtime']['helpManager'].isTutorialMode() and section != 'help': if self.env['runtime']['helpManager'].isTutorialMode() and section != 'help':
self.env['runtime']['debug'].writeDebugOut("Tutorial for command:" + section + "." + command ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Tutorial for command:" + section + "." + command ,debug.debugLevel.INFO)
description = self.getCommandDescription(command, section) description = self.getCommandDescription(command, section)
self.env['runtime']['outputManager'].presentText(description, interrupt=True) self.env['runtime']['outputManager'].presentText(description, interrupt=False)
else: else:
self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.INFO)
self.runCommand(command, section) self.runCommand(command, section)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command +' ' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command +' ' + str(e),debug.debugLevel.ERROR)

View File

@ -68,6 +68,8 @@ class fenrirManager():
else: else:
if self.environment['runtime']['helpManager'].isTutorialMode(): if self.environment['runtime']['helpManager'].isTutorialMode():
self.environment['runtime']['inputManager'].clearEventBuffer() self.environment['runtime']['inputManager'].clearEventBuffer()
self.environment['runtime']['inputManager'].keyEcho(event['Data'])
if self.environment['runtime']['vmenuManager'].getActive(): if self.environment['runtime']['vmenuManager'].getActive():
self.environment['runtime']['inputManager'].clearEventBuffer() self.environment['runtime']['inputManager'].clearEventBuffer()
@ -112,11 +114,11 @@ class fenrirManager():
return return
# default # default
self.environment['runtime']['commandManager'].executeCommand( command, 'commands') self.environment['runtime']['commandManager'].executeCommand( command, 'commands')
def handleRemoteIncomming(self, event): def handleRemoteIncomming(self, event):
if not event['Data']: if not event['Data']:
return return
self.environment['runtime']['remoteManager'].handleRemoteIncomming(event['Data']) self.environment['runtime']['remoteManager'].handleRemoteIncomming(event['Data'])
def handleScreenChange(self, event): def handleScreenChange(self, event):
self.environment['runtime']['screenManager'].hanldeScreenChange(event['Data']) self.environment['runtime']['screenManager'].hanldeScreenChange(event['Data'])
''' '''

View File

@ -33,6 +33,7 @@ class inputManager():
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2) self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
self.lastDeepestInput = [] self.lastDeepestInput = []
self.lastEvent = None
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.lastInputTime = time.time() self.lastInputTime = time.time()
def shutdown(self): def shutdown(self):
@ -79,10 +80,12 @@ class inputManager():
time.sleep(value) time.sleep(value)
else: else:
self.env['runtime']['inputDriver'].sendKey(key, value) self.env['runtime']['inputDriver'].sendKey(key, value)
def getLastEvent(self):
return self.lastEvent
def handleInputEvent(self, eventData): def handleInputEvent(self, eventData):
#print(eventData)
if not eventData: if not eventData:
return return
self.lastEvent = eventData
# a hang apears.. try to fix # a hang apears.. try to fix
if self.env['input']['eventBuffer'] == []: if self.env['input']['eventBuffer'] == []:
if self.env['input']['currInput'] != []: if self.env['input']['currInput'] != []:
@ -265,6 +268,18 @@ class inputManager():
if not self.shortcutExists(shortcut): if not self.shortcutExists(shortcut):
return '' return ''
return self.env['bindings'][shortcut] return self.env['bindings'][shortcut]
def keyEcho(self, eventData = None):
if not eventData:
eventData = self.env['runtime']['inputManager'].getLastEvent()
if not eventData:
return
keyName = ''
if eventData['EventState'] == 1:
keyName = eventData['EventName'].lower()
if keyName.startswith('key_'):
keyName = keyName[4:]
self.env['runtime']['outputManager'].presentText(_(keyName), interrupt=True)
def shortcutExists(self, shortcut): def shortcutExists(self, shortcut):
return(shortcut in self.env['bindings']) return(shortcut in self.env['bindings'])