cycle between widgets on mouse click. #2857
-
I want to switch from the clock widget that displays time to another clock widget that displays date with a mouse click similar to widgetBox. widget.WidgetBox(text_closed=" " + str(widget.Clock(format='%I:%M %p').poll()) + " ",
background=colors[1],
text_open=" " + str(widget.Clock(format='%m-%d %a').poll()) + " "), maybe a new widget that would have this functionality would be a nice enhancement. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You don't need the from libqtile import qtile
def toggle_clock():
time_format = '%I:%M %p'
date_format = '%m-%d %a'
# Get the clock widget
clock = qtile.widgets_map["clock"]
# Look for an attribute called "_toggled" which we'll use to track the state
if getattr(clock, "_toggled", False):
# if it's not "toggled" then change to the date format and set the flag
clock.format = date_format
clock._toggled = True
else:
# otherwise, change back to the time format
clock.format = time_format
clock._toggled = False
# This may change the widget length so we should redraw the bar
clock.bar.draw() Then, you define your widget like this: widget.Clock(format='%I:%M %p', mouse_callbacks={"Button1": toggle_clock}) It's untested so there may be some silly mistakes in here but hopefully you get the idea. |
Beta Was this translation helpful? Give feedback.
You don't need the
WidgetBox
for this. Amouse_callback
should be ok. Something like this: