add initial tutorial menu

This commit is contained in:
chrys 2017-07-12 23:13:37 +02:00
parent 11c97cf955
commit 6133f100f8
12 changed files with 216 additions and 43 deletions

View File

@ -10,6 +10,9 @@ from array import array
import struct import struct
import errno import errno
import sys import sys
import time
ttyno = 4 ttyno = 4
tty = open('/dev/tty%d' % ttyno, 'rb') tty = open('/dev/tty%d' % ttyno, 'rb')
@ -19,7 +22,7 @@ head = vcs.read(4)
rows = int(head[0]) rows = int(head[0])
cols = int(head[1]) cols = int(head[1])
s = time.time()
GIO_UNIMAP = 0x4B66 GIO_UNIMAP = 0x4B66
VT_GETHIFONTMASK = 0x560D VT_GETHIFONTMASK = 0x560D
himask = array("H", (0,)) himask = array("H", (0,))
@ -51,6 +54,7 @@ for u, b in zip(utable[::2], utable[1::2]):
allText = [] allText = []
allAttrib = [] allAttrib = []
for y in range(rows): for y in range(rows):
lineText = '' lineText = ''
lineAttrib = [] lineAttrib = []
@ -64,13 +68,14 @@ for y in range(rows):
lineAttrib.append(attr) lineAttrib.append(attr)
ink = attr & 0x0F ink = attr & 0x0F
paper = (attr>>4) & 0x0F paper = (attr>>4) & 0x0F
if (ink != 7) or (paper != 0): #if (ink != 7) or (paper != 0):
print(ink,paper) # print(ink,paper)
if sh & hichar: if sh & hichar:
ch |= 0x100 ch |= 0x100
lineText += chr(charmap.get(ch, u'?')) lineText += chr(charmap.get(ch, u'?'))
allText.append(lineText) allText.append(lineText)
allAttrib.append(lineAttrib) allAttrib.append(lineAttrib)
print(allText) #print(allText)
print(allAttrib) #print(allAttrib)
print(time.time() -s)

View File

@ -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

View File

@ -0,0 +1,2 @@
this folder contains help and tutorial related functions.
those are not bindable but hard coded.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -16,7 +16,7 @@ class commandManager():
self.env = environment self.env = environment
# commands # commands
self.env['commands'] = {} self.env['commands'] = {}
self.env['commandsIgnore'] = {} self.env['commandsIgnore'] = {}
for commandFolder in self.env['general']['commandFolderList']: for commandFolder in self.env['general']['commandFolderList']:
self.env['runtime']['commandManager'].loadCommands(commandFolder) self.env['runtime']['commandManager'].loadCommands(commandFolder)
if self.env['runtime']['settingsManager'].getSetting('general', 'commandPath') != '': if self.env['runtime']['settingsManager'].getSetting('general', 'commandPath') != '':
@ -182,19 +182,34 @@ class commandManager():
return return
if self.commandExists(command, section): if self.commandExists(command, section):
try: 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) 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) self.env['runtime']['outputManager'].presentText(description, interrupt=True)
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.env['commands'][section][command].run() self.runCommand(command, section)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command +' ' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(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.clearCommandQueued()
self.env['commandInfo']['lastCommandExecutionTime'] = time.time() 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): def isCommandQueued(self):
return self.env['commandInfo']['currCommand'] != '' return self.env['commandInfo']['currCommand'] != ''

View File

@ -54,13 +54,16 @@ class fenrirManager():
startTime = time.time() startTime = time.time()
if eventReceived: if eventReceived:
self.prepareCommand() 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() self.environment['runtime']['inputManager'].writeEventBuffer()
if self.environment['runtime']['inputManager'].noKeyPressed(): if self.environment['runtime']['inputManager'].noKeyPressed():
if self.wasCommand: if self.wasCommand:
self.wasCommand = False self.wasCommand = False
self.environment['runtime']['inputManager'].clearEventBuffer() self.environment['runtime']['inputManager'].clearEventBuffer()
if self.environment['general']['tutorialMode']: if self.environment['runtime']['helpManager'].isTutorialMode():
self.environment['runtime']['inputManager'].clearEventBuffer() self.environment['runtime']['inputManager'].clearEventBuffer()
if self.environment['input']['keyForeward'] > 0: if self.environment['input']['keyForeward'] > 0:
self.environment['input']['keyForeward'] -=1 self.environment['input']['keyForeward'] -=1

View File

@ -12,7 +12,7 @@ generalData = {
'currUser':'', 'currUser':'',
'prevUser':'', 'prevUser':'',
'managerList':['eventManager','punctuationManager','cursorManager','applicationManager','commandManager' 'managerList':['eventManager','punctuationManager','cursorManager','applicationManager','commandManager'
,'screenManager','inputManager','outputManager','debug'], ,'screenManager','inputManager','outputManager','helpManager','debug'],
'commandFolderList':['commands','onInput', 'onCursorChange', 'onScreenUpdate','onScreenChanged','onHeartBeat', 'onPlugInputDevice' 'commandFolderList':['commands','onInput', 'onCursorChange', 'onScreenUpdate','onScreenChanged','onHeartBeat', 'onPlugInputDevice'
,'onApplicationChange','onSwitchApplicationProfile',], ,'onApplicationChange','onSwitchApplicationProfile','help',],
} }

75
src/fenrir/core/helpManager.py Executable file
View File

@ -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

View File

@ -15,6 +15,7 @@ from core import screenManager
from core import punctuationManager from core import punctuationManager
from core import cursorManager from core import cursorManager
from core import applicationManager from core import applicationManager
from core import helpManager
from core import environment from core import environment
from core import inputData from core import inputData
from core.settingsData import settingsData from core.settingsData import settingsData
@ -328,7 +329,8 @@ class settingsManager():
environment['runtime']['cursorManager'].initialize(environment) environment['runtime']['cursorManager'].initialize(environment)
environment['runtime']['applicationManager'] = applicationManager.applicationManager() environment['runtime']['applicationManager'] = applicationManager.applicationManager()
environment['runtime']['applicationManager'].initialize(environment) environment['runtime']['applicationManager'].initialize(environment)
environment['runtime']['helpManager'] = helpManager.helpManager()
environment['runtime']['helpManager'].initialize(environment)
if environment['runtime']['screenManager'] == None: if environment['runtime']['screenManager'] == None:
environment['runtime']['screenManager'] = screenManager.screenManager() environment['runtime']['screenManager'] = screenManager.screenManager()
environment['runtime']['screenManager'].initialize(environment) environment['runtime']['screenManager'].initialize(environment)