2016-07-07 13:43:31 -04:00
|
|
|
#!/bin/python
|
2016-07-08 19:01:00 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-07-07 13:43:31 -04:00
|
|
|
|
|
|
|
# Fenrir TTY screen reader
|
|
|
|
# By Chrys, Storm Dragon, and contributers.
|
|
|
|
|
2016-08-30 16:41:14 -04:00
|
|
|
import os, sys, signal, time
|
2016-07-07 13:43:31 -04:00
|
|
|
|
|
|
|
if not os.getcwd() in sys.path:
|
|
|
|
sys.path.append(os.getcwd())
|
|
|
|
|
2016-07-11 05:40:09 -04:00
|
|
|
from core import settingsManager
|
2016-09-19 16:15:58 -04:00
|
|
|
from core import debug
|
2016-07-07 15:40:10 -04:00
|
|
|
|
2016-07-07 13:43:31 -04:00
|
|
|
class fenrir():
|
|
|
|
def __init__(self):
|
2016-09-15 05:32:16 -04:00
|
|
|
try:
|
|
|
|
self.environment = settingsManager.settingsManager().initFenrirConfig()
|
|
|
|
if not self.environment:
|
|
|
|
raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable')
|
|
|
|
except RuntimeError:
|
|
|
|
raise
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['outputManager'].presentText("Start Fenrir", soundIcon='ScreenReaderOn', interrupt=True)
|
2016-07-08 03:49:59 -04:00
|
|
|
signal.signal(signal.SIGINT, self.captureSignal)
|
2016-09-20 10:49:44 -04:00
|
|
|
signal.signal(signal.SIGTERM, self.captureSignal)
|
2016-09-25 09:20:40 -04:00
|
|
|
self.wasCommand = False
|
2016-09-25 13:03:08 -04:00
|
|
|
self.currShortcutLenght = 0
|
2016-09-20 10:49:44 -04:00
|
|
|
def proceed(self):
|
2016-08-10 08:32:13 -04:00
|
|
|
while(self.environment['generalInformation']['running']):
|
2016-08-31 08:13:28 -04:00
|
|
|
try:
|
|
|
|
self.handleProcess()
|
|
|
|
except Exception as e:
|
2016-09-02 20:22:56 -04:00
|
|
|
print(e)
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-07-07 15:53:37 -04:00
|
|
|
self.shutdown()
|
|
|
|
|
2016-08-21 16:23:53 -04:00
|
|
|
def handleProcess(self):
|
2016-09-21 17:17:54 -04:00
|
|
|
eventReceived = self.environment['runtime']['inputManager'].getInputEvent()
|
2016-09-25 09:20:40 -04:00
|
|
|
|
2016-09-21 04:01:57 -04:00
|
|
|
if eventReceived:
|
2016-09-17 17:38:40 -04:00
|
|
|
self.prepareCommand()
|
2016-09-25 09:20:40 -04:00
|
|
|
#if not (self.environment['runtime']['inputManager'].isConsumeInput() or \
|
|
|
|
# self.environment['runtime']['inputManager'].isFenrirKeyPressed()) and \
|
|
|
|
# not self.environment['runtime']['commandManager'].isCommandQueued():
|
2016-09-25 13:03:08 -04:00
|
|
|
print('vor',self.wasCommand,self.currShortcutLenght)
|
2016-09-25 09:20:40 -04:00
|
|
|
if not self.wasCommand:
|
2016-09-25 13:03:08 -04:00
|
|
|
print('dri')
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['inputManager'].writeEventBuffer()
|
2016-09-25 09:20:40 -04:00
|
|
|
if self.environment['runtime']['inputManager'].noKeyPressed():
|
2016-09-25 13:03:08 -04:00
|
|
|
if self.wasCommand:
|
|
|
|
print('mache falsch')
|
|
|
|
self.wasCommand = False
|
|
|
|
self.environment['runtime']['inputManager'].clearEventBuffer()
|
|
|
|
self.currShortcutLenght = 0
|
2016-09-25 09:20:40 -04:00
|
|
|
self.environment['runtime']['screenManager'].update()
|
2016-09-25 13:03:08 -04:00
|
|
|
print('nach',self.wasCommand,self.currShortcutLenght)
|
2016-09-25 09:20:40 -04:00
|
|
|
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
|
|
|
|
else:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['screenManager'].update()
|
2016-09-25 09:20:40 -04:00
|
|
|
|
2016-09-23 03:50:44 -04:00
|
|
|
if self.environment['runtime']['applicationManager'].isApplicationChange():
|
2016-09-22 05:23:49 -04:00
|
|
|
self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange')
|
2016-09-22 15:56:37 -04:00
|
|
|
self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \
|
2016-09-23 03:53:24 -04:00
|
|
|
self.environment['runtime']['applicationManager'].getPrevApplication(), \
|
|
|
|
self.environment['runtime']['applicationManager'].getCurrentApplication())
|
2016-09-25 09:20:40 -04:00
|
|
|
|
2016-09-23 03:50:44 -04:00
|
|
|
if self.environment['runtime']['screenManager'].isScreenChange():
|
2016-09-22 05:23:49 -04:00
|
|
|
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged')
|
2016-09-23 20:45:12 -04:00
|
|
|
else:
|
|
|
|
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
|
|
|
|
|
2016-09-17 17:38:40 -04:00
|
|
|
self.handleCommands()
|
2016-07-07 17:59:21 -04:00
|
|
|
|
2016-09-17 17:38:40 -04:00
|
|
|
def prepareCommand(self):
|
|
|
|
if self.environment['input']['keyForeward']:
|
|
|
|
return
|
2016-09-21 17:17:54 -04:00
|
|
|
shortcut = self.environment['runtime']['inputManager'].getCurrShortcut()
|
2016-09-25 10:09:17 -04:00
|
|
|
print(shortcut)
|
2016-09-21 17:17:54 -04:00
|
|
|
command = self.environment['runtime']['inputManager'].getCommandForShortcut(shortcut)
|
2016-09-25 09:20:40 -04:00
|
|
|
self.environment['runtime']['commandManager'].queueCommand(command)
|
2016-09-25 13:03:08 -04:00
|
|
|
if self.currShortcutLenght < len(self.environment['input']['currInput']):
|
|
|
|
self.wasCommand = command != ''
|
|
|
|
self.currShortcutLenght = len(self.environment['input']['currInput'])
|
2016-07-08 12:33:32 -04:00
|
|
|
def handleCommands(self):
|
2016-09-20 10:57:22 -04:00
|
|
|
if time.time() - self.environment['commandInfo']['lastCommandExecutionTime'] < 0.2:
|
|
|
|
return
|
2016-09-21 17:17:54 -04:00
|
|
|
if not self.environment['runtime']['commandManager'].isCommandQueued():
|
2016-09-20 10:57:22 -04:00
|
|
|
return
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['commandManager'].executeCommand( self.environment['commandInfo']['currCommand'], 'commands')
|
2016-08-21 16:23:53 -04:00
|
|
|
|
2016-08-10 09:30:43 -04:00
|
|
|
def shutdownRequest(self):
|
|
|
|
self.environment['generalInformation']['running'] = False
|
2016-08-21 16:23:53 -04:00
|
|
|
|
|
|
|
def captureSignal(self, siginit, frame):
|
|
|
|
self.shutdownRequest()
|
|
|
|
|
2016-09-14 18:21:22 -04:00
|
|
|
def shutdown(self):
|
2016-09-16 19:04:03 -04:00
|
|
|
if self.environment['runtime']['inputManager']:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['inputManager'].shutdown()
|
2016-09-21 10:59:05 -04:00
|
|
|
del self.environment['runtime']['inputManager']
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['outputManager'].presentText("Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True)
|
2016-09-22 11:07:17 -04:00
|
|
|
time.sleep(.3) # wait a little for sound
|
2016-09-16 19:04:03 -04:00
|
|
|
|
2016-09-14 18:21:22 -04:00
|
|
|
if self.environment['runtime']['screenManager']:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['screenManager'].shutdown()
|
2016-09-21 10:59:05 -04:00
|
|
|
del self.environment['runtime']['screenManager']
|
2016-09-14 18:21:22 -04:00
|
|
|
if self.environment['runtime']['commandManager']:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['commandManager'].shutdown()
|
2016-09-21 10:59:05 -04:00
|
|
|
del self.environment['runtime']['commandManager']
|
2016-09-14 18:21:22 -04:00
|
|
|
if self.environment['runtime']['outputManager']:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['outputManager'].shutdown()
|
2016-09-21 10:59:05 -04:00
|
|
|
del self.environment['runtime']['outputManager']
|
2016-09-22 10:11:36 -04:00
|
|
|
if self.environment['runtime']['punctuationManager']:
|
|
|
|
self.environment['runtime']['punctuationManager'].shutdown()
|
|
|
|
del self.environment['runtime']['punctuationManager']
|
2016-09-23 06:30:16 -04:00
|
|
|
if self.environment['runtime']['cursorManager']:
|
|
|
|
self.environment['runtime']['cursorManager'].shutdown()
|
|
|
|
del self.environment['runtime']['cursorManager']
|
2016-09-23 03:50:44 -04:00
|
|
|
if self.environment['runtime']['applicationManager']:
|
|
|
|
self.environment['runtime']['applicationManager'].shutdown()
|
|
|
|
del self.environment['runtime']['applicationManager']
|
|
|
|
|
2016-09-14 18:04:36 -04:00
|
|
|
if self.environment['runtime']['debug']:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.environment['runtime']['debug'].shutdown()
|
2016-09-21 10:59:05 -04:00
|
|
|
del self.environment['runtime']['debug']
|
2016-09-20 10:49:44 -04:00
|
|
|
time.sleep(0.5) # wait a little before splatter it :)
|
2016-09-02 16:13:33 -04:00
|
|
|
self.environment = None
|
2016-07-07 13:43:31 -04:00
|
|
|
|
2016-09-15 05:30:34 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app = fenrir()
|
|
|
|
app.proceed()
|
2016-09-21 11:01:11 -04:00
|
|
|
del app
|