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

@ -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,
}