initial binding import

This commit is contained in:
chrys 2016-07-10 18:34:44 +02:00
parent 9b5b634fcf
commit a6fc0fbf1b
5 changed files with 76 additions and 5 deletions

View File

@ -1 +1,3 @@
2-KEY_LEFTCTRL,1-KEY_LEFTSHIFT=curr_line
2-KEY_LEFTCTRL,1-KEY_A=shut_up

View File

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

View File

@ -22,12 +22,72 @@ class inputManager():
del(currShortcut[str(event.code)])
environment['input']['currShortcut'] = currShortcut
environment['input']['currShortcutString'] = self.getShortcutString(environment)
print(environment['input']['currShortcutString'])
return environment
def getShortcutString(self, environment):
if environment['input']['currShortcut'] == {}:
return ''
currShortcutStringList = []
for key in sorted(environment['input']['currShortcut'] ):
for key in environment['input']['currShortcut']:
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
currShortcutStringList = sorted(currShortcutStringList)
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
def loadShortcuts(self, environment, kbConfigPath='/home/chrys/Projekte/fenrir/fenrir/config/keyboard/desktop.kb'):
kbConfig = open(kbConfigPath,"r")
while(True):
line = kbConfig.readline()
if not line:
break
line = line.replace('\n','')
if line.replace(" ","").startswith("#"):
continue
if line.count("=") != 1:
continue
sepLine = line.split('=')
commandString = sepLine[1]
keys = sepLine[0].replace(" ","").split(',')
currShortcut = []
validKeyString = True
for key in keys:
if len(key) < 3:
validKeyString = False
break
if not key[0] in ['0','1','2']:
validKeyString = False
break
if key[1] != '-':
validKeyString = False
break
if key[2:] != '':
keyInt = self.getCodeForKeyID(key[2:])
else:
validKeyString = False
break
if keyInt == 0:
validKeyString = False
break
if not validKeyString:
break
else:
currShortcut.append(key[0] + '-' + str(keyInt))
print(currShortcut)
if validKeyString:
keyString = ''
for k in sorted(currShortcut):
if keyString != '':
keyString += ','
keyString += k
print(keyString)
print(commandString)
environment['bindings'][keyString] = commandString
kbConfig.close()
print(environment['bindings'])
return environment
def getCodeForKeyID(self, keyID):
try:
return evdev.ecodes.ecodes[keyID.upper()]
except:
return 0

View File

@ -26,6 +26,7 @@ class fenrir():
self.threadHandleCommandQueue = None
self.environment = environment.environment
self.environment['runtime']['inputManager'] = inputManager.inputManager()
self.environment = self.environment['runtime']['inputManager'].loadShortcuts(self.environment)
self.environment['runtime']['commandManager'] = commandManager.commandManager()
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'commands')
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onInput')

View File

@ -21,6 +21,8 @@ class screenManager():
vcsa = open(self.vcsaDevicePath + environment['screenData']['newTTY'] ,'rb',0)
environment['screenData']['newContentBytes'] = vcsa.read()
vcsa.close()
if len(environment['screenData']['newContentBytes']) < 5:
return environment
except:
return environment
@ -43,11 +45,19 @@ class screenManager():
environment['screenData']['oldContentText'] = ''
environment['screenData']['oldCursor']['x'] = 0
environment['screenData']['oldCursor']['y'] = 0
environment['runtime']['speechDriver'].cancel()
print('runs')
# changes on the screen
if environment['screenData']['oldContentBytes'] != environment['screenData']['newContentBytes']:
if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \
(len(environment['screenData']['newContentText']) > 0):
print('runs1')
diff = difflib.ndiff(environment['screenData']['oldContentText'], environment['screenData']['newContentText'])
print('runs2')
print(environment['screenData']['oldContentText'])
print(environment['screenData']['newContentText'])
environment['screenData']['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
print(environment['screenData']['delta'])
print('______________________________________')
if ((len(environment['screenData']['delta']) < 3)):
environment['runtime']['speechDriver'].cancel()
environment['runtime']['speechDriver'].speak(environment['screenData']['delta'])