Skip to content

Commit

Permalink
Add open and close commands for Widgetbox
Browse files Browse the repository at this point in the history
`Widgetbox` currently only has a `toggle` method for opening and closing
the box. This isn't great for automations where a user specifically
wants to open or close a box.

This PR adds explicit commands for opening and closing.
  • Loading branch information
elParaguayo authored and tych0 committed Feb 13, 2024
1 parent 27c4602 commit 41ea050
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libqtile/widget/widgetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,15 @@ def toggle(self):
self.toggle_widgets()
self.set_box_label()
self.bar.draw()

@expose_command()
def open(self):
"""Open the widgetbox."""
if not self.box_is_open:
self.toggle()

@expose_command()
def close(self):
"""Close the widgetbox."""
if self.box_is_open:
self.toggle()
35 changes: 35 additions & 0 deletions test/widgets/test_widgetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,38 @@ def test_deprecated_configuration(caplog):
box = WidgetBox([tray])
assert box.widgets == [tray]
assert "The use of a positional argument in WidgetBox is deprecated." in caplog.text


def test_widgetbox_open_close_commands(manager_nospawn, minimal_conf_noscreen):
config = minimal_conf_noscreen
tbox = TextBox(text="Text Box")
widget_box = WidgetBox(widgets=[tbox])
config.screens = [libqtile.config.Screen(top=libqtile.bar.Bar([widget_box], 10))]

manager_nospawn.start(config)

topbar = manager_nospawn.c.bar["top"]
widget = manager_nospawn.c.widget["widgetbox"]

def count():
return len(topbar.info()["widgets"])

assert count() == 1

widget.open()
assert count() == 2

widget.open()
assert count() == 2

widget.close()
assert count() == 1

widget.close()
assert count() == 1

widget.toggle()
assert count() == 2

widget.toggle()
assert count() == 1

0 comments on commit 41ea050

Please sign in to comment.