add some command handling

This commit is contained in:
chrys 2016-07-08 18:33:32 +02:00
parent fb63606bfb
commit 7a737c7797
8 changed files with 67 additions and 12 deletions

View File

@ -4,7 +4,10 @@ class command():
def __init__(self):
pass
def run(self, environment):
pass
print('fire')
#print(environment['screenData']['newContentText'])i
print(environment['screenData']['newCursor']['x'])
environment['runtime']['speechDriver'].speak(environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['x']-1])
def setCallback(self, callback):
pass
def shutdown(self):

View File

@ -1,4 +1,5 @@
#!/bin/python
bindings = {
'2-29,1-42':'curr_line',
}

View File

@ -3,3 +3,30 @@
class commandManager():
def __init__(self):
pass
def loadCommands(self, environment):
return environment
def executeCommand(self, environment):
print(environment['commandInfo']['currCommand'])
if self.isCommandDefined(environment):
environment['commands'][environment['commandInfo']['currCommand']].run(environment)
environment['commandInfo']['currCommand'] = ''
return environment
def executeNextCommand(self, environment):
pass
def isShortcutDefined(self, environment):
return( environment['input']['currShortcutString'] in environment['bindings'])
def getCommandForShortcut(self, environment):
if not self.isShortcutDefined(environment):
return environment
environment['commandInfo']['currCommand'] = environment['bindings'][environment['input']['currShortcutString']]
return environment
def isCommandDefined(self, environment):
return( environment['commandInfo']['currCommand'] in environment['commands'])
def enqueueCommand(self, environment):
if not self.isCommandDefined(environment):
return False
return True

View File

@ -6,6 +6,8 @@ from core import bindings
from core import runtime
from core import screenData
from core import generalInformation
from core import commands
from core import input
environment = {
'screenData': screenData.screenData,
@ -13,6 +15,9 @@ environment = {
'generalInformation': generalInformation.generalInformation,
'settings': settings.settings,
'bindings': bindings.bindings,
'commands': commands.commands,
'input': input.input,
'commandInfo': commands.commandInfo,
'soundIcons': soundIcons.soundIcons,
'autospeak': ['speak_delta']
}

View File

@ -10,15 +10,24 @@ class inputManager():
self.devices = {dev.fd: dev for dev in self.devices}
for dev in self.devices.values(): print(dev)
def getShortcutCommand(self, environment, shortcuts):
if not shortcuts:
return ''
return ''
def getKeyPressed(self, environment):
r, w, x = select(self.devices, [], [])
currShortcut = environment['input']['currShortcut']
for fd in r:
for event in self.devices[fd].read():
if event.type == evdev.ecodes.EV_KEY:
print(evdev.categorize(event))
if event.value != 0:
currShortcut[str(event.code)] = event.value
else:
del(currShortcut[str(event.code)])
environment['input']['currShortcut'] = currShortcut
environment['input']['currShortcutString'] = self.getShortcutString(environment)
return environment
def getShortcutString(self, environment):
if environment['input']['currShortcut'] == {}:
return ''
currShortcutStringList = []
for key in sorted(environment['input']['currShortcut'] ):
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")

View File

@ -5,5 +5,6 @@ runtime = {
'screenDriver': None,
'soundDriver': None,
'inputManager': None,
'commandManager': None,
'debug':None,
}

View File

@ -11,6 +11,7 @@ if not os.getcwd() in sys.path:
from threading import Thread
from core import environment
from core import inputManager
from core import commandManager
from utils import debug
from speech import espeak as es
@ -24,6 +25,7 @@ class fenrir():
self.threadHandleCommandQueue = None
self.environment = environment.environment
self.environment['runtime']['inputManager'] = inputManager.inputManager()
self.environment['runtime']['commandManager'] = commandManager.commandManager()
self.environment['runtime']['debug'] = debug.debug()
signal.signal(signal.SIGINT, self.captureSignal)
@ -34,10 +36,10 @@ class fenrir():
def proceed(self):
self.threadUpdateScreen = Thread(target=self.updateScreen, args=())
self.threadHandleInput = Thread(target=self.handleInput, args=())
self.threadCommandQueue = Thread(target=self.handleCommandQueue, args=())
self.threadCommands = Thread(target=self.handleCommands, args=())
self.threadUpdateScreen.start()
self.threadHandleInput.start()
self.threadCommandQueue.start()
self.threadCommands.start()
while(self.environment['generalInformation']['running']):
time.sleep(0.2)
self.shutdown()
@ -45,14 +47,21 @@ class fenrir():
def handleInput(self):
while(self.environment['generalInformation']['running']):
self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment)
if self.environment['input']['currShortcutString'] == '':
self.environment['commandInfo']['currCommand'] = ''
def updateScreen(self):
while(self.environment['generalInformation']['running']):
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
def handleCommandQueue(self):
def handleCommands(self):
while(self.environment['generalInformation']['running']):
self.environment = self.environment # command queue here
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
#self.environment['input']['currShortcut'] = {}
#self.environment['input']['currShortcutString'] = ''
if self.environment['input']['currShortcutString'] != '':
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment)
time.sleep(0.5)
def shutdown(self):
self.environment['generalInformation']['running'] = False

View File

@ -20,7 +20,7 @@ class screenManager():
environment['screenData']['newContentBytes'] = vcsa.read()
vcsa.close()
except:
return runtime
return environment
# get metadata like cursor or screensize
environment['screenData']['lines'] = int( environment['screenData']['newContentBytes'][0])