core: Add the middle click support and unhandled button support

* This commit fix #259
* Support of middle click button
* Add an unhandled click events for all button that will not be handled
* Remove the return type of on_click: it became useless now
* Fix the unique call of on_click in CommandEndpoint

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

View File

@ -38,7 +38,8 @@ class CommandEndpoint:
except Exception:
pos = {}
if target_module and target_module.on_click(cmd["button"], **pos):
if target_module:
target_module.on_click(cmd["button"], **pos)
target_module.run()
self.io.async_refresh()

View File

@ -26,26 +26,36 @@ class Module(SettingsBase):
settings = (
('on_leftclick', "Callback called on left click (see :ref:`callbacks`)"),
('on_middleclick', "Callback called on middle click (see :ref:`callbacks`)"),
('on_rightclick', "Callback called on right click (see :ref:`callbacks`)"),
('on_upscroll', "Callback called on scrolling up (see :ref:`callbacks`)"),
('on_downscroll', "Callback called on scrolling down (see :ref:`callbacks`)"),
('on_doubleleftclick', "Callback called on double left click (see :ref:`callbacks`)"),
('on_doubleleftclick', "Callback called on double left click (see :ref:`callbacks`)"),
('on_doublemiddleclick', "Callback called on double middle 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_doubledownscroll', "Callback called on double scroll down (see :ref:`callbacks`)"),
('on_unhandledclick', "Callback called on unhandled click (see :ref:`callbacks`)"),
('on_doubleunhandledclick', "Callback called on double unhandled click (see :ref:`callbacks`)"),
('multi_click_timeout', "Time (in seconds) before a single click is executed."),
('hints', "Additional output blocks for module output (see :ref:`hints`)"),
)
on_leftclick = None
on_middleclick = None
on_rightclick = None
on_upscroll = None
on_downscroll = None
on_doubleleftclick = None
on_doublemiddleclick = None
on_doublerightclick = None
on_doubleupscroll = None
on_doubledownscroll = None
on_unhandledclick = None
on_doubleunhandledclick = None
multi_click_timeout = 0.25
hints = {"markup": "none"}
@ -189,21 +199,15 @@ class Module(SettingsBase):
positions of the mouse where the click occured.
:return: Returns ``True`` if a valid callback action was executed.
``False`` otherwise.
:rtype: bool
"""
if button == 1: # Left mouse button
action = 'leftclick'
elif button == 3: # Right mouse button
action = 'rightclick'
elif button == 4: # mouse wheel up
action = 'upscroll'
elif button == 5: # mouse wheel down
action = 'downscroll'
else:
actions = ['leftclick', 'middleclick', 'rightclick',
'upscroll', 'downscroll']
try:
action = actions[button - 1]
except (TypeError, IndexError):
self.__log_button_event(button, None, None, "Unhandled button")
return False
action = "unhandled"
m_click = self.__multi_click
@ -225,8 +229,6 @@ class Module(SettingsBase):
else:
self.__button_callback_handler(button, cb, **kwargs)
return True
def move(self, position):
self.position = position
return self