2016-07-07 13:43:31 -04:00
|
|
|
#!/bin/python
|
2016-07-11 05:37:43 -04:00
|
|
|
from configparser import ConfigParser
|
|
|
|
import settings.settings
|
2016-07-08 06:24:44 -04:00
|
|
|
|
|
|
|
class settingsManager():
|
|
|
|
def __init__(self):
|
2016-07-11 05:37:43 -04:00
|
|
|
|
|
|
|
def loadShortcuts(self, environment, kbConfigPath='../../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))
|
|
|
|
if validKeyString:
|
|
|
|
keyString = ''
|
|
|
|
for k in sorted(currShortcut):
|
|
|
|
if keyString != '':
|
|
|
|
keyString += ','
|
|
|
|
keyString += k
|
|
|
|
environment['bindings'][keyString] = commandString
|
|
|
|
kbConfig.close()
|
|
|
|
return environment
|
|
|
|
|
|
|
|
def getCodeForKeyID(self, keyID):
|
|
|
|
try:
|
|
|
|
return evdev.ecodes.ecodes[keyID.upper()]
|
|
|
|
except:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def loadSettings(self, environment, settingConfigPath='../../config/settings/settings.cfg'):
|
|
|
|
environment['settings'] = ConfigParser()
|
|
|
|
environment['settings'].read(settingConfigPath)
|
|
|
|
return environment
|
|
|
|
|
|
|
|
def getSetting(self, environment, setting):
|
|
|
|
value = True # do be implemented
|
|
|
|
return value
|
|
|
|
|