From 8ecdcd1bc101c67e38a4c27a96e17cfe27966756 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Tue, 14 May 2013 02:15:01 +0200 Subject: [PATCH] Configuration now allows modifying the dictionary. --- py/configs/example_conf.py | 48 ++++++++++++++++++++++++++++++++++++++ py/configs/touchscreen.py | 17 ++++++++++++++ py/create.py | 17 ++------------ 3 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 py/configs/example_conf.py diff --git a/py/configs/example_conf.py b/py/configs/example_conf.py new file mode 100644 index 0000000..a378def --- /dev/null +++ b/py/configs/example_conf.py @@ -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 diff --git a/py/configs/touchscreen.py b/py/configs/touchscreen.py index e2b6c94..cb7d3cd 100644 --- a/py/configs/touchscreen.py +++ b/py/configs/touchscreen.py @@ -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 + } + + diff --git a/py/create.py b/py/create.py index 2e19e73..ef22bac 100644 --- a/py/create.py +++ b/py/create.py @@ -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)