Module: More detailed logs for clickevents as suggested by @teto in #231.

This commit is contained in:
Lukáš Mandák 2015-09-25 19:12:05 +02:00
parent 4aa6b2a73c
commit 6d3c7eddc8

View File

@ -75,6 +75,11 @@ class Module(SettingsBase):
) )
""" """
def log_event(name, button, cb, args, action):
msg = "{}: button={}, cb='{}', args={}, type='{}'".format(
name, button, cb, args, action)
self.logger.debug(msg)
def split_callback_and_args(cb): def split_callback_and_args(cb):
if isinstance(cb, list): if isinstance(cb, list):
return cb[0], cb[1:] return cb[0], cb[1:]
@ -91,23 +96,25 @@ class Module(SettingsBase):
elif button == 5: # mouse wheel down elif button == 5: # mouse wheel down
cb = self.on_downscroll cb = self.on_downscroll
else: else:
self.logger.info("Button '%d' not handled yet." % (button)) log_event(self.__name__, button, None, None, "Unhandled button")
return False return False
if not cb: if not cb:
self.logger.info("no cb attached") log_event(self.__name__, button, None, None, "No callback attached")
return False return False
else: else:
cb, args = split_callback_and_args(cb) cb, args = split_callback_and_args(cb)
self.logger.debug("cb=%s args=%s" % (cb, args))
if callable(cb): if callable(cb):
cb(self, *args) cb(self, *args)
log_event(self.__name__, button, cb, args, "Python callback")
elif hasattr(self, cb): elif hasattr(self, cb):
if cb is not "run": if cb is not "run":
getattr(self, cb)(*args) getattr(self, cb)(*args)
log_event(self.__name__, button, cb, args, "Member callback")
else: else:
execute(cb, detach=True) execute(cb, detach=True)
log_event(self.__name__, button, cb, args, "External command")
return True return True
def move(self, position): def move(self, position):