fenrir/src/fenrir-package/fenrir.py

82 lines
4.2 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.
import os, sys, time, signal
if not os.getcwd() in sys.path:
sys.path.append(os.getcwd())
2016-07-07 17:59:21 -04:00
from threading import Thread
from core import environment
2016-07-07 15:40:10 -04:00
from core import inputManager
2016-07-08 12:33:32 -04:00
from core import commandManager
2016-07-11 05:40:09 -04:00
from core import settingsManager
from utils import debug
2016-07-07 15:40:10 -04:00
class fenrir():
def __init__(self):
2016-07-07 17:59:21 -04:00
self.threadHandleInput = None
2016-07-08 05:29:50 -04:00
self.environment = environment.environment
self.environment['runtime']['inputManager'] = inputManager.inputManager()
2016-07-11 18:17:44 -04:00
self.environment['runtime']['settingsManager'] = settingsManager.settingsManager()
2016-07-11 05:40:09 -04:00
self.environment = self.environment['runtime']['settingsManager'].loadShortcuts(self.environment)
2016-07-12 17:09:11 -04:00
self.environment = self.environment['runtime']['settingsManager'].loadSettings(self.environment)
2016-07-08 12:33:32 -04:00
self.environment['runtime']['commandManager'] = commandManager.commandManager()
2016-07-10 09:43:15 -04:00
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'commands')
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onInput')
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onScreenChanged')
2016-07-08 06:30:47 -04:00
self.environment['runtime']['debug'] = debug.debug()
signal.signal(signal.SIGINT, self.captureSignal)
2016-07-12 17:09:11 -04:00
self.environment = self.environment['runtime']['settingsManager'].loadSpeechDriver(self.environment,\
self.environment['runtime']['settingsManager'].getSetting(self.environment,'speech', 'driver'))
self.environment = self.environment['runtime']['settingsManager'].loadScreenDriver(self.environment,\
self.environment['runtime']['settingsManager'].getSetting(self.environment,'screen', 'driver'))
self.environment = self.environment['runtime']['settingsManager'].loadSoundDriver(self.environment,\
self.environment['runtime']['settingsManager'].getSetting(self.environment,'sound', 'driver'))
def proceed(self):
2016-07-07 17:59:21 -04:00
self.threadHandleInput = Thread(target=self.handleInput, args=())
2016-07-12 10:51:26 -04:00
self.threadHandleInput.start()
2016-07-13 15:40:19 -04:00
self.updateScreen()
2016-07-08 05:29:50 -04:00
while(self.environment['generalInformation']['running']):
2016-07-12 11:13:59 -04:00
self.updateScreen()
2016-07-07 15:53:37 -04:00
self.shutdown()
2016-07-07 17:59:21 -04:00
def handleInput(self):
2016-07-12 10:51:26 -04:00
while(self.environment['generalInformation']['running']):
self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment)
2016-07-12 17:09:11 -04:00
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
2016-07-12 10:51:26 -04:00
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
2016-07-12 17:09:11 -04:00
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
2016-07-12 10:51:26 -04:00
if self.environment['input']['currShortcutString'] != '':
self.handleCommands()
2016-07-07 17:59:21 -04:00
def updateScreen(self):
2016-07-12 10:51:26 -04:00
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
2016-07-12 17:09:11 -04:00
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
2016-07-12 10:51:26 -04:00
time.sleep(0.5)
2016-07-07 17:59:21 -04:00
2016-07-08 12:33:32 -04:00
def handleCommands(self):
2016-07-10 17:02:17 -04:00
if (self.environment['commandInfo']['currCommand'] != '') and \
(time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.4):
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
2016-07-07 18:07:03 -04:00
2016-07-07 13:56:46 -04:00
def shutdown(self):
2016-07-08 05:29:50 -04:00
self.environment['generalInformation']['running'] = False
if self.environment['runtime']['speechDriver'] != None:
self.environment['runtime']['speechDriver'].shutdown()
if self.environment['runtime']['debug'] != None:
self.environment['runtime']['debug'].closeDebugFile()
2016-07-08 06:30:47 -04:00
if self.environment['runtime']['soundDriver'] != None:
self.environment['runtime']['soundDriver'].shutdown()
def captureSignal(self, siginit, frame):
self.shutdown()
app = fenrir()
app.proceed()