Configuration now allows modifying the dictionary.

This commit is contained in:
Merlijn Wajer 2013-05-14 02:15:01 +02:00
parent 1022db5eaf
commit 8ecdcd1bc1
3 changed files with 67 additions and 15 deletions

View File

@ -0,0 +1,48 @@
from cinput import *
overrule = lambda x: -x*2
passthrough = lambda x: x
config = {
EV_REL : {
#REL_X : {
# 'type' : EV_REL,
# 'code' : REL_X,
# 'value': overrule
#},
#REL_Y : {
# 'type': EV_REL,
# 'code': REL_Y,
# 'value' : overrule
#},
REL_X : {
'type' : EV_REL,
'code' : REL_X,
'value' : lambda x: 0
},
REL_Y : {
'type' : EV_REL,
'code' : REL_Y,
'value' : lambda x: 0
},
REL_WHEEL : {
'type' : EV_REL,
'code' : REL_WHEEL,
'value' : lambda x: -x*2
}
},
EV_KEY : {
BTN_LEFT : {
'type' : EV_KEY,
'code' : BTN_LEFT,
'value' : passthrough
}
}
}
def config_merge(c):
for k, v in config.iteritems():
if k in c:
c[k].update(v)
else:
c[k] = v

View File

@ -44,3 +44,20 @@ config = {
}
}
}
def config_merge(c):
# XXX: We cannot just use update; as it will override everything in say EV_KEY
for k, v in config.iteritems():
if k in c:
c[k].update(v)
else:
c[k] = v
# Uncomment this to make touch click too
c[EV_KEY][BTN_TOUCH] = {
'type' : EV_KEY,
'code' : BTN_TOUCH,
'value' : lambda x: 0
}

View File

@ -16,10 +16,6 @@ import optparse
parser = optparse.OptionParser(description='Create input devices. '
'TODO')
#parser.add_option('-c', '--config', type=str, action='append',
# default=[],
# help='Merge configuration file with default '
# 'configuration (allowed to be used multiple times)')
parser.add_option('-C', '--compat', action='store_true',
help='Enable compatibility mode; for Python < 2.7')
@ -29,19 +25,10 @@ args, cfg = parser.parse_args()
f = pickle.Unpickler(sys.stdin)
conf = f.load()
print conf
for path in cfg:
config = imp.load_source('', path).config
# XXX: We cannot just use update; as it will override everything in say EV_TE
for k, v in config.iteritems():
if k in conf:
conf[k].update(v)
else:
conf[k] = v
#conf.update(config)
print conf
config_merge = imp.load_source('', path).config_merge
config_merge(conf)
m = KeyMapper(conf)