Merge pull request #859 from tobi-wan-kenobi/858
[core/input] methods can be event callbacks
This commit is contained in:
commit
bf7aac4e6e
2 changed files with 7 additions and 1 deletions
|
@ -54,8 +54,11 @@ def register(obj, button=None, cmd=None, wait=False):
|
||||||
event_id = __event_id(obj.id if obj is not None else "", button)
|
event_id = __event_id(obj.id if obj is not None else "", button)
|
||||||
logging.debug("registering callback {}".format(event_id))
|
logging.debug("registering callback {}".format(event_id))
|
||||||
core.event.unregister(event_id) # make sure there's always only one input event
|
core.event.unregister(event_id) # make sure there's always only one input event
|
||||||
|
|
||||||
if callable(cmd):
|
if callable(cmd):
|
||||||
core.event.register_exclusive(event_id, cmd)
|
core.event.register_exclusive(event_id, cmd)
|
||||||
|
elif obj and hasattr(obj, cmd) and callable(getattr(obj, cmd)):
|
||||||
|
core.event.register_exclusive(event_id, lambda event: getattr(obj, cmd)(event))
|
||||||
else:
|
else:
|
||||||
core.event.register_exclusive(event_id, lambda event: __execute(event, cmd, wait))
|
core.event.register_exclusive(event_id, lambda event: __execute(event, cmd, wait))
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ Parameters:
|
||||||
import core.module
|
import core.module
|
||||||
import core.widget
|
import core.widget
|
||||||
import core.decorators
|
import core.decorators
|
||||||
|
import core.input
|
||||||
|
|
||||||
class Module(core.module.Module):
|
class Module(core.module.Module):
|
||||||
@core.decorators.every(minutes=60)
|
@core.decorators.every(minutes=60)
|
||||||
|
@ -20,5 +20,8 @@ class Module(core.module.Module):
|
||||||
def text(self, _):
|
def text(self, _):
|
||||||
return self.__text
|
return self.__text
|
||||||
|
|
||||||
|
def update_text(self, event):
|
||||||
|
self.__text = core.input.button_name(event["button"])
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue