prepare for remake input handling, prepare other stuff
This commit is contained in:
@ -8,7 +8,10 @@ from utils import debug
|
||||
class commandManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def initialize(self, environment):
|
||||
return environment
|
||||
def shutdown(self, environment):
|
||||
return environment
|
||||
def loadCommands(self, environment, section='commands'):
|
||||
commandFolder = "commands/" + section +"/"
|
||||
commandList = glob.glob(commandFolder+'*')
|
||||
@ -23,6 +26,7 @@ class commandManager():
|
||||
command_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(command_mod)
|
||||
environment['commands'][section][fileName] = command_mod.command()
|
||||
environment['commands'][section][fileName].initialize(environment)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Error while loading command:" + currCommand ,debug.debugLevel.ERROR)
|
||||
|
@ -2,7 +2,10 @@
|
||||
import time
|
||||
|
||||
input = {
|
||||
'currShortcut': {},
|
||||
'currInput': {},
|
||||
'prevInput': {},
|
||||
'currEvent': None,
|
||||
'firstEvent': {},
|
||||
'currShortcutString': '',
|
||||
'consumeKey': False,
|
||||
'fenrirKey': ['82'],
|
||||
|
@ -1,75 +1,36 @@
|
||||
#!/bin/python
|
||||
|
||||
import evdev
|
||||
from evdev import InputDevice, UInput
|
||||
from select import select
|
||||
import time
|
||||
from utils import debug
|
||||
|
||||
class inputManager():
|
||||
def __init__(self):
|
||||
self.iDevices = {}
|
||||
self.uDevices = {}
|
||||
self.getInputDevices()
|
||||
self.grabDevices()
|
||||
self.ignoreKeyRelease = 0
|
||||
pass
|
||||
def initialize(self, environment):
|
||||
return environment
|
||||
def shutdown(self, environment):
|
||||
return environment
|
||||
def getInput(self, environment):
|
||||
environment, timeout = environment['runtime']['inputDriver'].getInput(environment)
|
||||
return environment, timeout
|
||||
def grabDevices(self, environment):
|
||||
environment['runtime']['inputDriver'].grabDevices(environment)
|
||||
|
||||
def proceedInputEvents(self, environment):
|
||||
timeout = True
|
||||
if not environment['input']['keyForeward']:
|
||||
self.ignoreKeyRelease = 0
|
||||
try:
|
||||
r, w, x = select(self.iDevices, [], [], environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'screen', 'screenUpdateDelay'))
|
||||
if r != []:
|
||||
timeout = False
|
||||
for fd in r:
|
||||
for event in self.iDevices[fd].read():
|
||||
if self.isFenrirKey(environment, event):
|
||||
environment['input']['consumeKey'] = not environment['input']['keyForeward'] and not environment['generalInformation']['suspend']
|
||||
if self.isConsumeKeypress(environment):
|
||||
self.writeUInput(self.uDevices[fd], event,environment)
|
||||
keyString = ''
|
||||
if self.isFenrirKey(environment, event):
|
||||
keyString = 'FENRIR'
|
||||
else:
|
||||
keyString = str(event.code)
|
||||
if event.type == evdev.ecodes.EV_KEY:
|
||||
if event.value != 0:
|
||||
environment['input']['currShortcut'][keyString] = 1 #event.value
|
||||
else:
|
||||
try:
|
||||
del(environment['input']['currShortcut'][keyString])
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Error while inputHandling",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.freeDevices()
|
||||
time.sleep(0.01)
|
||||
environment['input']['currShortcutString'] = self.getShortcutString(environment)
|
||||
if not timeout:
|
||||
environment['input']['lastInputTime'] = time.time()
|
||||
environment['input']['consumeKey'] = environment['input']['currShortcut'] != {} and environment['input']['consumeKey']
|
||||
if (environment['input']['keyForeward'] and environment['input']['currShortcut'] == {}):
|
||||
self.ignoreKeyRelease += 1
|
||||
if self.ignoreKeyRelease >= 2: # a hack... has to bee done more clean
|
||||
environment['input']['keyForeward'] = environment['input']['keyForeward'] and not environment['input']['currShortcut'] == {}
|
||||
|
||||
return environment, timeout
|
||||
|
||||
def isConsumeKeypress(self, environment):
|
||||
return not environment['input']['consumeKey'] or \
|
||||
environment['input']['keyForeward'] or \
|
||||
def releaseDevices(self, environment):
|
||||
environment['runtime']['inputDriver'].releaseDevices(environment)
|
||||
|
||||
def isConsumeInput(self, environment):
|
||||
return environment['input']['consumeKey'] and \
|
||||
not environment['input']['keyForeward'] or \
|
||||
not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices')
|
||||
|
||||
def writeUInput(self, uDevice, event,environment):
|
||||
|
||||
def passInput(self, environment):
|
||||
try:
|
||||
uDevice.write_event(event)
|
||||
uDevice.syn()
|
||||
environment['runtime']['inputDriver']
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Error while writeUInput",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR)
|
||||
|
||||
environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR)
|
||||
return environment
|
||||
def getShortcutString(self, environment):
|
||||
if environment['input']['currShortcut'] == {}:
|
||||
return ''
|
||||
@ -78,50 +39,6 @@ class inputManager():
|
||||
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
|
||||
currShortcutStringList = sorted(currShortcutStringList)
|
||||
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
|
||||
|
||||
def isFenrirKey(self,environment, event):
|
||||
return str(event.code) in environment['input']['fenrirKey']
|
||||
|
||||
def getInputDevices(self):
|
||||
self.iDevices = map(evdev.InputDevice, (evdev.list_devices()))
|
||||
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
|
||||
|
||||
def grabDevices(self):
|
||||
# if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices'):
|
||||
# return
|
||||
for fd in self.iDevices:
|
||||
dev = self.iDevices[fd]
|
||||
cap = dev.capabilities()
|
||||
del cap[0]
|
||||
self.uDevices[fd] = UInput(
|
||||
cap,
|
||||
dev.name,
|
||||
#dev.info.vendor,
|
||||
#dev.info.product,
|
||||
#dev.version,
|
||||
#dev.info.bustype,
|
||||
#'/dev/uinput'
|
||||
)
|
||||
dev.grab()
|
||||
|
||||
def freeDevices(self):
|
||||
for fd in self.iDevices:
|
||||
try:
|
||||
self.iDevices[fd].ungrab()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
self.iDevices[fd].close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
self.uDevices[fd].close()
|
||||
except:
|
||||
pass
|
||||
|
||||
self.iDevices.clear()
|
||||
self.uDevices.clear()
|
||||
|
||||
def __del__(self):
|
||||
self.freeDevices()
|
||||
|
||||
|
||||
return str(event.code) in environment['input']['fenrirKey']
|
||||
|
@ -4,6 +4,10 @@ from utils import debug
|
||||
class outputManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
def initialize(self, environment):
|
||||
return environment
|
||||
def shutdown(self, environment):
|
||||
return environment
|
||||
def presentText(self, environment, text, interrupt=True, soundIcon = ''):
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO)
|
||||
if self.playSoundIcon(environment, soundIcon, interrupt):
|
||||
|
@ -1,13 +1,13 @@
|
||||
#!/bin/python
|
||||
from _thread import allocate_lock
|
||||
|
||||
runtime = {
|
||||
'speechDriver': None,
|
||||
'screenDriver': None,
|
||||
'soundDriver': None,
|
||||
'inputDriver': None,
|
||||
'brailleDriver': None,
|
||||
'inputManager': None,
|
||||
'commandManager': None,
|
||||
'screenManager': None,
|
||||
'debug':None,
|
||||
'globalLock': allocate_lock(),
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/python
|
||||
|
||||
import time
|
||||
|
||||
screenData = {
|
||||
'columns': 0,
|
||||
'lines': 0,
|
||||
@ -19,4 +21,5 @@ screenData = {
|
||||
'newContentAttrib': b'',
|
||||
'oldTTY':'-1',
|
||||
'newTTY':'0',
|
||||
'lastScreenUpdate': time.time()
|
||||
}
|
||||
|
21
src/fenrir-package/core/screenManager.py
Normal file
21
src/fenrir-package/core/screenManager.py
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/python
|
||||
import time
|
||||
from utils import debug
|
||||
|
||||
class screenManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
def initialize(self, environment):
|
||||
return environment
|
||||
def shutdown(self, environment):
|
||||
return environment
|
||||
def update(self, environment):
|
||||
environment['generalInformation']['suspend'] = self.isSuspendingScreen(environment)
|
||||
if not environment['generalInformation']['suspend']:
|
||||
environment = environment['runtime']['screenDriver'].update(environment)
|
||||
return environment
|
||||
|
||||
def isSuspendingScreen(self, environment):
|
||||
return environment['generalInformation']['suspend'] = environment['runtime']['screenDriver'].getCurrScreen() in \
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'suspendingScreen').split(',')
|
||||
|
@ -6,6 +6,7 @@ from configparser import ConfigParser
|
||||
from core import inputManager
|
||||
from core import outputManager
|
||||
from core import commandManager
|
||||
from core import screenManager
|
||||
from core import environment
|
||||
from core.settings import settings
|
||||
from utils import debug
|
||||
@ -13,7 +14,10 @@ from utils import debug
|
||||
class settingsManager():
|
||||
def __init__(self):
|
||||
self.settings = settings
|
||||
|
||||
def initialize(self, environment):
|
||||
return environment
|
||||
def shutdown(self, environment):
|
||||
return environment
|
||||
def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.conf'):
|
||||
kbConfig = open(kbConfigPath,"r")
|
||||
while(True):
|
||||
@ -155,6 +159,7 @@ class settingsManager():
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
environment['runtime']['speechDriver'] = driver_mod.speech()
|
||||
environment['runtime']['speechDriver'].initialize(environment)
|
||||
return environment
|
||||
|
||||
def loadSoundDriver(self, environment, driverName):
|
||||
@ -163,7 +168,8 @@ class settingsManager():
|
||||
spec = importlib.util.spec_from_file_location(driverName, 'sound/' + driverName + '.py')
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
environment['runtime']['soundDriver'] = driver_mod.sound()
|
||||
environment['runtime']['soundDriver'] = driver_mod.sound()
|
||||
environment['runtime']['soundDriver'].initialize(environment)
|
||||
return environment
|
||||
|
||||
def loadScreenDriver(self, environment, driverName):
|
||||
@ -171,6 +177,15 @@ class settingsManager():
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
environment['runtime']['screenDriver'] = driver_mod.screen()
|
||||
environment['runtime']['screenDriver'].initialize(environment)
|
||||
return environment
|
||||
|
||||
def loadInputDriver(self, environment, driverName):
|
||||
spec = importlib.util.spec_from_file_location(driverName, 'input/' + driverName + '.py')
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
environment['runtime']['inputDriver'] = driver_mod.screen()
|
||||
environment['runtime']['inputDriver'].initialize(environment)
|
||||
return environment
|
||||
|
||||
def setFenrirKeys(self, environment, keys):
|
||||
@ -215,9 +230,20 @@ class settingsManager():
|
||||
else:
|
||||
environment = environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
|
||||
|
||||
environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||
environment['runtime']['outputManager'] = outputManager.outputManager()
|
||||
environment['runtime']['commandManager'] = commandManager.commandManager()
|
||||
if environment['runtime']['inputManager'] == None:
|
||||
environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||
environment = environment['runtime']['inputManager'].initialize(environment)
|
||||
if environment['runtime']['outputManager'] == None:
|
||||
environment['runtime']['outputManager'] = outputManager.outputManager()
|
||||
environment = environment['runtime']['outputManager'].initialize(environment)
|
||||
if environment['runtime']['commandManager'] == None:
|
||||
environment['runtime']['commandManager'] = commandManager.commandManager()
|
||||
environment = environment['runtime']['commandManager'].initialize(environment)
|
||||
if environment['runtime']['screenManager'] == None:
|
||||
environment['runtime']['screenManager'] = screenManager.screenManager()
|
||||
environment = environment['runtime']['screenManager'].initialize(environment)
|
||||
|
||||
|
||||
environment = environment['runtime']['commandManager'].loadCommands(environment,'commands')
|
||||
environment = environment['runtime']['commandManager'].loadCommands(environment,'onInput')
|
||||
environment = environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
|
||||
@ -228,7 +254,8 @@ class settingsManager():
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'))
|
||||
environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'))
|
||||
|
||||
environment = environment['runtime']['settingsManager'].loadInputDriver(environment,\
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'))
|
||||
environment['runtime']['debug'].writeDebugOut(environment,'\/-------environment-------\/',debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(environment),debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,'\/-------settings.conf-------\/',debug.debugLevel.ERROR)
|
||||
|
Reference in New Issue
Block a user