fenrir/src/fenrir-package/fenrir.py

86 lines
4.0 KiB
Python
Raw Normal View History

#!/bin/python
2016-07-08 19:01:00 -04:00
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
2016-08-30 16:41:14 -04:00
import os, sys, signal, time
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-08-30 16:52:54 -04:00
from utils import debug
2016-07-07 15:40:10 -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
signal.signal(signal.SIGINT, self.captureSignal)
2016-07-14 16:15:10 -04:00
def proceed(self):
self.environment['runtime']['outputManager'].presentText(self.environment, "Start Fenrir", soundIcon='ScreenReaderOn', interrupt=True)
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-02 12:08:44 -04:00
self.environment['runtime']['debug'].writeDebugOut(self.environment,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):
time.sleep(3)
timeout = self.environment['runtime']['inputManager'].proceedInputEvent(self.environment)
timeout = False
2016-08-30 17:51:17 -04:00
try:
self.environment['runtime']['screenManager'].update(self.environment)
2016-08-30 17:51:17 -04:00
except Exception as e:
2016-09-12 16:17:10 -04:00
print(e)
2016-09-02 12:08:44 -04:00
self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR)
2016-09-12 16:17:10 -04:00
if not (self.environment['input']['keyForeward'] or timeout):
#currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
shortcut = "[1, ['KEY_FENRIR', 'KEY_T']]"
2016-09-16 19:59:38 -04:00
command = self.environment['runtime']['inputManager'].getCommandForShortcut(self.environment, shortcut)
self.environment['runtime']['commandManager'].queueCommand(self.environment, command)
if not timeout:
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
2016-08-26 04:53:24 -04:00
if not self.environment['input']['keyForeward']:
self.handleCommands()
2016-07-07 17:59:21 -04:00
2016-07-08 12:33:32 -04:00
def handleCommands(self):
if self.environment['runtime']['commandManager'].isCommandQueued(self.environment):
self.environment['runtime']['commandManager'].executeCommand(self.environment, 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):
if self.environment['runtime']['inputManager']:
self.environment['runtime']['inputManager'].shutdown(self.environment)
2016-09-14 18:21:22 -04:00
self.environment['runtime']['outputManager'].presentText(self.environment, "Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True)
time.sleep(1.0) # wait a little before splatter it :)
2016-09-14 18:21:22 -04:00
if self.environment['runtime']['screenManager']:
self.environment['runtime']['screenManager'].shutdown(self.environment)
if self.environment['runtime']['commandManager']:
self.environment['runtime']['commandManager'].shutdown(self.environment)
2016-09-14 18:21:22 -04:00
if self.environment['runtime']['outputManager']:
self.environment['runtime']['outputManager'].shutdown(self.environment)
2016-09-14 18:04:36 -04:00
if self.environment['runtime']['debug']:
self.environment['runtime']['debug'].closeDebugFile()
2016-09-14 18:21:22 -04:00
time.sleep(0.8) # wait a little before splatter it :)
self.environment = None
2016-09-15 05:30:34 -04:00
if __name__ == "__main__":
app = fenrir()
app.proceed()