core: Improve the support of other button

* This commit fix #259
* Change 'unhandled' callback by 'other'
* Add the an optional parameter 'button_id' for all callbacks

Signed-off-by: Mathis FELARDOS <mathis.felardos@gmail.com>
This commit is contained in:
Mathis FELARDOS 2016-03-25 22:18:14 +01:00
parent 95f625cd6b
commit f26a9f9d1d
2 changed files with 22 additions and 18 deletions

View File

@ -32,14 +32,16 @@ class CommandEndpoint:
for cmd in self.io_handler_factory().read(): for cmd in self.io_handler_factory().read():
target_module = self.modules.get(cmd["instance"]) target_module = self.modules.get(cmd["instance"])
button = cmd["button"]
kwargs = {"button_id": button}
try: try:
pos = {"pos_x": int(cmd["x"]), kwargs.update({"pos_x": cmd["x"],
"pos_y": int(cmd["y"])} "pos_y": cmd["y"]})
except Exception: except Exception:
pos = {} continue
if target_module: if target_module:
target_module.on_click(cmd["button"], **pos) target_module.on_click(button, **kwargs)
target_module.run() target_module.run()
self.io.async_refresh() self.io.async_refresh()

View File

@ -36,8 +36,8 @@ class Module(SettingsBase):
('on_doublerightclick', "Callback called on double right click (see :ref:`callbacks`)"), ('on_doublerightclick', "Callback called on double right click (see :ref:`callbacks`)"),
('on_doubleupscroll', "Callback called on double scroll up (see :ref:`callbacks`)"), ('on_doubleupscroll', "Callback called on double scroll up (see :ref:`callbacks`)"),
('on_doubledownscroll', "Callback called on double scroll down (see :ref:`callbacks`)"), ('on_doubledownscroll', "Callback called on double scroll down (see :ref:`callbacks`)"),
('on_unhandledclick', "Callback called on unhandled click (see :ref:`callbacks`)"), ('on_otherclick', "Callback called on other click (see :ref:`callbacks`)"),
('on_doubleunhandledclick', "Callback called on double unhandled click (see :ref:`callbacks`)"), ('on_doubleotherclick', "Callback called on double other click (see :ref:`callbacks`)"),
('multi_click_timeout', "Time (in seconds) before a single click is executed."), ('multi_click_timeout', "Time (in seconds) before a single click is executed."),
('hints', "Additional output blocks for module output (see :ref:`hints`)"), ('hints', "Additional output blocks for module output (see :ref:`hints`)"),
) )
@ -53,8 +53,8 @@ class Module(SettingsBase):
on_doubleupscroll = None on_doubleupscroll = None
on_doubledownscroll = None on_doubledownscroll = None
on_unhandledclick = None on_otherclick = None
on_doubleunhandledclick = None on_doubleotherclick = None
multi_click_timeout = 0.25 multi_click_timeout = 0.25
@ -171,14 +171,16 @@ class Module(SettingsBase):
Currently implemented events are: Currently implemented events are:
=========== ================ ========= ============ ================ =========
Event Callback setting Button ID Event Callback setting Button ID
=========== ================ ========= ============ ================ =========
Left click on_leftclick 1 Left click on_leftclick 1
Middle click on_middleclick 2
Right click on_rightclick 3 Right click on_rightclick 3
Scroll up on_upscroll 4 Scroll up on_upscroll 4
Scroll down on_downscroll 5 Scroll down on_downscroll 5
=========== ================ ========= Others on_otherclick > 5
============ ================ =========
The action is determined by the nature (type and value) of the callback The action is determined by the nature (type and value) of the callback
setting in the following order: setting in the following order:
@ -206,8 +208,8 @@ class Module(SettingsBase):
try: try:
action = actions[button - 1] action = actions[button - 1]
except (TypeError, IndexError): except (TypeError, IndexError):
self.__log_button_event(button, None, None, "Unhandled button") self.__log_button_event(button, None, None, "Other button")
action = "unhandled" action = "otherclick"
m_click = self.__multi_click m_click = self.__multi_click