This commit introduces a skeleton that allows personalized callbacks in
a backwards compatible way. Settings 'on_lclick','on_rclick', 'on_scrollup','on_scrolldown' are inherited by all modules. These parameters should be a string. Then when a matching action is detected (ie mouseclick, scrolling), the module check if this string corresponds to a: 1/ python callable 2/ module method, In cases 1 and 2, it calls the python function with the module as the first parameter. Otherwise it considers the string is an external command and launches it via run_through_shell
This commit is contained in:
parent
b0b4d939ec
commit
14c0528be5
@ -28,6 +28,8 @@ class Clock(IntervalModule):
|
|||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
interval = 1
|
interval = 1
|
||||||
current_format_id = 0
|
current_format_id = 0
|
||||||
|
on_scrollup = "next_format"
|
||||||
|
on_scrolldown = "next_format"
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if self.format is None:
|
if self.format is None:
|
||||||
@ -78,8 +80,8 @@ class Clock(IntervalModule):
|
|||||||
if self.color != "i3Bar":
|
if self.color != "i3Bar":
|
||||||
self.output["color"] = self.color
|
self.output["color"] = self.color
|
||||||
|
|
||||||
def on_upscroll(self):
|
def next_format(self):
|
||||||
self.current_format_id = (self.current_format_id + 1) % len(self.format)
|
self.current_format_id = (self.current_format_id + 1) % len(self.format)
|
||||||
|
|
||||||
def on_downscroll(self):
|
def previous_format(self):
|
||||||
self.current_format_id = (self.current_format_id - 1) % len(self.format)
|
self.current_format_id = (self.current_format_id - 1) % len(self.format)
|
||||||
|
@ -7,6 +7,22 @@ class Module(SettingsBase):
|
|||||||
output = None
|
output = None
|
||||||
position = 0
|
position = 0
|
||||||
|
|
||||||
|
settings = (
|
||||||
|
'on_lclick', "Callback called on left click",
|
||||||
|
'on_rclick', "Callback called on right click",
|
||||||
|
'on_scrollup', "Callback called on scrolling up",
|
||||||
|
'on_scrolldown', "Callback called on scrolling down",
|
||||||
|
)
|
||||||
|
|
||||||
|
# this allows for backward compatibility
|
||||||
|
on_lclick = None
|
||||||
|
on_rclick = None
|
||||||
|
on_scrollup = None
|
||||||
|
on_scrolldown = None
|
||||||
|
# on_rclick = "on_rightclick"
|
||||||
|
# on_scrollup = "on_upscroll"
|
||||||
|
# on_scrolldown = "on_downscroll"
|
||||||
|
|
||||||
def registered(self, status_handler):
|
def registered(self, status_handler):
|
||||||
"""Called when this module is registered with a status handler"""
|
"""Called when this module is registered with a status handler"""
|
||||||
|
|
||||||
@ -23,14 +39,22 @@ class Module(SettingsBase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def on_click(self, button):
|
def on_click(self, button):
|
||||||
|
cb = None
|
||||||
if button == 1: # Left mouse button
|
if button == 1: # Left mouse button
|
||||||
self.on_leftclick()
|
cb = self.on_lclick or "on_leftclick"
|
||||||
elif button == 3: # Right mouse button
|
elif button == 3: # Right mouse button
|
||||||
self.on_rightclick()
|
cb = self.on_rclick or "on_rightclick"
|
||||||
elif button == 4: # mouse wheel up
|
elif button == 4: # mouse wheel up
|
||||||
self.on_upscroll()
|
cb = self.on_scrollup or "on_upscroll"
|
||||||
elif button == 5: # mouse wheel down
|
elif button == 5: # mouse wheel down
|
||||||
self.on_downscroll()
|
cb = self.on_scrolldown or "on_downscroll"
|
||||||
|
|
||||||
|
if callable(cb):
|
||||||
|
return cb(self)
|
||||||
|
elif hasattr(self, cb):
|
||||||
|
return getattr(self, cb)()
|
||||||
|
else:
|
||||||
|
return run_through_shell(cb)
|
||||||
|
|
||||||
def move(self, position):
|
def move(self, position):
|
||||||
self.position = position
|
self.position = position
|
||||||
|
Loading…
Reference in New Issue
Block a user