From 1d8d6471eecbf1121527bce92d585a601cf62dd6 Mon Sep 17 00:00:00 2001 From: chrys Date: Thu, 7 Jul 2016 23:59:21 +0200 Subject: [PATCH] multi threading --- src/fenrir-package/core/inputManager.py | 2 +- src/fenrir-package/fenrir.py | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 8f4fb533..e1130c96 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -21,4 +21,4 @@ class inputManager(): for event in self.devices[fd].read(): if event.type == evdev.ecodes.EV_KEY: print(evdev.categorize(event)) - + return runtime diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 00ec0005..34c64360 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -3,14 +3,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import os, sys +import os, sys, time DEBUG = False if not os.getcwd() in sys.path: sys.path.append(os.getcwd()) - +from threading import Thread from core import environment from core import inputManager from utils import debug @@ -21,6 +21,8 @@ from screen import linux as lx class fenrir(): def __init__(self): + self.threadUpdateScreen = None + self.threadHandleInput = None self.runtime = environment.runtime self.runtime['inputManager'] = inputManager.inputManager() if DEBUG: @@ -37,13 +39,25 @@ class fenrir(): self.runtime['screenDriver'] = lx.screenManager() def proceed(self): + self.threadUpdateScreen = Thread(target=self.updateScreen, args=()) + self.threadHandleInput = Thread(target=self.handleInput, args=()) + self.threadUpdateScreen.start() + self.threadHandleInput.start() while(self.runtime['running']): - self.runtime = self.runtime['screenDriver'].analyzeScreen(self.runtime) -# self.runtime = self.runtime['inputManager'].getKeyPressed(self.runtime) + time.sleep(2) self.shutdown() + def handleInput(self): + while(self.runtime['running']): + self.runtime = self.runtime['inputManager'].getKeyPressed(self.runtime) + + def updateScreen(self): + while(self.runtime['running']): + self.runtime = self.runtime['screenDriver'].analyzeScreen(self.runtime) + def shutdown(self): - pass + self.threadUpdateScreen.stop() + self.threadHandleInput.stop() app = fenrir() app.proceed()