diff --git a/play zone/charmapTTY.py b/play zone/charmapTTY.py index 92831055..3761274d 100755 --- a/play zone/charmapTTY.py +++ b/play zone/charmapTTY.py @@ -10,6 +10,9 @@ from array import array import struct import errno import sys +import time + + ttyno = 4 tty = open('/dev/tty%d' % ttyno, 'rb') @@ -19,7 +22,7 @@ head = vcs.read(4) rows = int(head[0]) cols = int(head[1]) - +s = time.time() GIO_UNIMAP = 0x4B66 VT_GETHIFONTMASK = 0x560D himask = array("H", (0,)) @@ -51,6 +54,7 @@ for u, b in zip(utable[::2], utable[1::2]): allText = [] allAttrib = [] + for y in range(rows): lineText = '' lineAttrib = [] @@ -64,13 +68,14 @@ for y in range(rows): lineAttrib.append(attr) ink = attr & 0x0F paper = (attr>>4) & 0x0F - if (ink != 7) or (paper != 0): - print(ink,paper) + #if (ink != 7) or (paper != 0): + # print(ink,paper) if sh & hichar: ch |= 0x100 lineText += chr(charmap.get(ch, u'?')) allText.append(lineText) allAttrib.append(lineAttrib) -print(allText) -print(allAttrib) +#print(allText) +#print(allAttrib) +print(time.time() -s) diff --git a/src/fenrir/commands/commands/toggle_tutorial_mode.py b/src/fenrir/commands/commands/toggle_tutorial_mode.py deleted file mode 100644 index 0fab4dfa..00000000 --- a/src/fenrir/commands/commands/toggle_tutorial_mode.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/python -# -*- coding: utf-8 -*- - -# Fenrir TTY screen reader -# By Chrys, Storm Dragon, and contributers. - -from core import debug - -class command(): - def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - self.env['general']['tutorialMode'] = False - return _('You are leaving the tutorial mode. Press that shortcut again to enter the tutorial mode again.') - - def run(self): - text = _('you entered the tutorial mode. In that mode the commands are not executed. but you get a description of what the shortcut does. To leave the tutorial mode, press that shortcut again.') - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - self.env['general']['tutorialMode'] = True - - def setCallback(self, callback): - pass diff --git a/src/fenrir/commands/help/Readme.txt b/src/fenrir/commands/help/Readme.txt new file mode 100644 index 00000000..c90f7a6b --- /dev/null +++ b/src/fenrir/commands/help/Readme.txt @@ -0,0 +1,2 @@ +this folder contains help and tutorial related functions. +those are not bindable but hard coded. diff --git a/src/fenrir/commands/help/curr_help.py b/src/fenrir/commands/help/curr_help.py new file mode 100644 index 00000000..1de0abc5 --- /dev/null +++ b/src/fenrir/commands/help/curr_help.py @@ -0,0 +1,22 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('get current help message') + def run(self): + text = self.env['runtime']['helpManager'].getHelpForCurrentIndex() + self.env['runtime']['outputManager'].presentText(text, interrupt=True) + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/help/next_help.py b/src/fenrir/commands/help/next_help.py new file mode 100644 index 00000000..0f268aa8 --- /dev/null +++ b/src/fenrir/commands/help/next_help.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('get next help message') + def run(self): + self.env['runtime']['helpManager'].nextIndex() + text = self.env['runtime']['helpManager'].getHelpForCurrentIndex() + self.env['runtime']['outputManager'].presentText(text, interrupt=True) + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/help/prev_help.py b/src/fenrir/commands/help/prev_help.py new file mode 100644 index 00000000..31eccbb6 --- /dev/null +++ b/src/fenrir/commands/help/prev_help.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('get prev help message') + def run(self): + self.env['runtime']['helpManager'].prevIndex() + text = self.env['runtime']['helpManager'].getHelpForCurrentIndex() + self.env['runtime']['outputManager'].presentText(text, interrupt=True) + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/help/toggle_tutorial_mode.py b/src/fenrir/commands/help/toggle_tutorial_mode.py new file mode 100644 index 00000000..806f521f --- /dev/null +++ b/src/fenrir/commands/help/toggle_tutorial_mode.py @@ -0,0 +1,29 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('Toggle the Tutorial mode') + def run(self): + print('TM') + text = '' + if self.env['runtime']['helpManager'].isTutorialMode(): + text = _('You are leaving the tutorial mode. Press that shortcut again to enter the tutorial mode again.') + else: + text = _('you entered the tutorial mode. In that mode the commands are not executed. but you get a description of what the shortcut does. To leave the tutorial mode, press that shortcut again.') + self.env['runtime']['helpManager'].toggleTutorialMode() + self.env['runtime']['outputManager'].presentText(text, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/core/commandManager.py b/src/fenrir/core/commandManager.py index 24e361da..d387b0eb 100644 --- a/src/fenrir/core/commandManager.py +++ b/src/fenrir/core/commandManager.py @@ -16,7 +16,7 @@ class commandManager(): self.env = environment # commands self.env['commands'] = {} - self.env['commandsIgnore'] = {} + self.env['commandsIgnore'] = {} for commandFolder in self.env['general']['commandFolderList']: self.env['runtime']['commandManager'].loadCommands(commandFolder) if self.env['runtime']['settingsManager'].getSetting('general', 'commandPath') != '': @@ -182,19 +182,34 @@ class commandManager(): return if self.commandExists(command, section): try: - if self.env['general']['tutorialMode']: + if self.env['runtime']['helpManager'].isTutorialMode(): self.env['runtime']['debug'].writeDebugOut("Tutorial for command:" + section + "." + command ,debug.debugLevel.INFO) - description = self.env['commands'][section][command].getDescription() + description = self.getCommandDescription(section, command) self.env['runtime']['outputManager'].presentText(description, interrupt=True) else: self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.INFO) - self.env['commands'][section][command].run() + self.runCommand(command, section) except Exception as e: - self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.ERROR) - self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command +' ' + str(e),debug.debugLevel.ERROR) + + def runCommand(self, command, section = 'commands'): + if self.commandExists(command, section): + try: + self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.INFO) + print(command, section) + self.env['commands'][section][command].run() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command +' ' + str(e),debug.debugLevel.ERROR) self.clearCommandQueued() self.env['commandInfo']['lastCommandExecutionTime'] = time.time() - + + def getCommandDescription(self, command, section = 'commands'): + if self.commandExists(command, section): + try: + return self.env['commands'][section][command].getDescription() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('commandManager.getCommandDescription:' + str(e),debug.debugLevel.ERROR) + def isCommandQueued(self): return self.env['commandInfo']['currCommand'] != '' diff --git a/src/fenrir/core/fenrirManager.py b/src/fenrir/core/fenrirManager.py index 8d10e4e7..6f12c530 100644 --- a/src/fenrir/core/fenrirManager.py +++ b/src/fenrir/core/fenrirManager.py @@ -54,13 +54,16 @@ class fenrirManager(): startTime = time.time() if eventReceived: self.prepareCommand() - if not (self.wasCommand or self.environment['general']['tutorialMode']) or self.environment['runtime']['screenManager'].isSuspendingScreen(): + if not self.environment['runtime']['screenManager'].isSuspendingScreen(): + if self.environment['runtime']['helpManager'].handleTutorialMode(): + self.wasCommand = True + if not (self.wasCommand or self.environment['runtime']['helpManager'].isTutorialMode()) or self.environment['runtime']['screenManager'].isSuspendingScreen(): self.environment['runtime']['inputManager'].writeEventBuffer() if self.environment['runtime']['inputManager'].noKeyPressed(): if self.wasCommand: self.wasCommand = False self.environment['runtime']['inputManager'].clearEventBuffer() - if self.environment['general']['tutorialMode']: + if self.environment['runtime']['helpManager'].isTutorialMode(): self.environment['runtime']['inputManager'].clearEventBuffer() if self.environment['input']['keyForeward'] > 0: self.environment['input']['keyForeward'] -=1 diff --git a/src/fenrir/core/generalData.py b/src/fenrir/core/generalData.py index ff89e64c..12056612 100644 --- a/src/fenrir/core/generalData.py +++ b/src/fenrir/core/generalData.py @@ -12,7 +12,7 @@ generalData = { 'currUser':'', 'prevUser':'', 'managerList':['eventManager','punctuationManager','cursorManager','applicationManager','commandManager' - ,'screenManager','inputManager','outputManager','debug'], + ,'screenManager','inputManager','outputManager','helpManager','debug'], 'commandFolderList':['commands','onInput', 'onCursorChange', 'onScreenUpdate','onScreenChanged','onHeartBeat', 'onPlugInputDevice' - ,'onApplicationChange','onSwitchApplicationProfile',], + ,'onApplicationChange','onSwitchApplicationProfile','help',], } diff --git a/src/fenrir/core/helpManager.py b/src/fenrir/core/helpManager.py new file mode 100755 index 00000000..bc6f3d92 --- /dev/null +++ b/src/fenrir/core/helpManager.py @@ -0,0 +1,75 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + + +class helpManager(): + def __init__(self): + self.helpDict = None + self.tutorialListIndex = None + def initialize(self, environment): + self.env = environment + self.createHelpDict() + + def shutdown(self): + pass + def toggleTutorialMode(self): + self.setTutorialMode(not self.env['general']['tutorialMode']) + def setTutorialMode(self, newTutorialMode): + self.env['general']['tutorialMode'] = newTutorialMode + 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('_',' ') + helptext = commandName + ', Shortcut , Description' + self.env['runtime']['commandManager'].getCommandDescription( command, section = 'commands') + return helptext + 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) + if len(self.helpDict) > 0: + self.tutorialListIndex = 0 + def getHelpForCurrentIndex(self): + if self.tutorialListIndex == None: + return '' + return self.helpDict[self.tutorialListIndex] + def nextIndex(self): + if self.tutorialListIndex == None: + return + self.tutorialListIndex += 1 + if self.tutorialListIndex >= len(self.helpDict): + self.tutorialListIndex = 0 + def prevIndex(self): + if self.tutorialListIndex == None: + return + self.tutorialListIndex -= 1 + if self.tutorialListIndex < 0: + self.tutorialListIndex = len(self.helpDict) - 1 + def handleTutorialMode(self): + if self.env['runtime']['inputManager'].noKeyPressed(): + return + if self.env['input']['currInput'] in [['KEY_F1', 'KEY_FENRIR']]: + self.env['runtime']['commandManager'].runCommand('TOGGLE_TUTORIAL_MODE', 'help') + return True + if not self.isTutorialMode(): + return + if self.env['input']['currInput'] in [['KEY_ESC']]: + self.env['runtime']['commandManager'].runCommand('TOGGLE_TUTORIAL_MODE', 'help') + return True + if self.env['input']['currInput'] in [['KEY_UP']]: + self.env['runtime']['commandManager'].runCommand('PREV_HELP', 'help') + return True + if self.env['input']['currInput'] in [['KEY_DOWN']]: + self.env['runtime']['commandManager'].runCommand('NEXT_HELP', 'help') + return True + if self.env['input']['currInput'] in [['KEY_SPACE']]: + self.env['runtime']['commandManager'].runCommand('CURR_HELP', 'help') + return True + return False diff --git a/src/fenrir/core/settingsManager.py b/src/fenrir/core/settingsManager.py index eac42f6f..910fb356 100644 --- a/src/fenrir/core/settingsManager.py +++ b/src/fenrir/core/settingsManager.py @@ -15,6 +15,7 @@ from core import screenManager from core import punctuationManager from core import cursorManager from core import applicationManager +from core import helpManager from core import environment from core import inputData from core.settingsData import settingsData @@ -328,7 +329,8 @@ class settingsManager(): environment['runtime']['cursorManager'].initialize(environment) environment['runtime']['applicationManager'] = applicationManager.applicationManager() environment['runtime']['applicationManager'].initialize(environment) - + environment['runtime']['helpManager'] = helpManager.helpManager() + environment['runtime']['helpManager'].initialize(environment) if environment['runtime']['screenManager'] == None: environment['runtime']['screenManager'] = screenManager.screenManager() environment['runtime']['screenManager'].initialize(environment)