We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
WidgetBox does not fully re-expand on click
# Issue description

On first click, WidgetBox expands properly, but clicking a second time does not hide all widgets.

Specifically, in my configuration (below), the Wallpaper is shown/hidden properly, but the Systray does not hide again.

# Qtile version

qtile-0.17.1.dev82+geb8722ec

# Stack traces

no errors in qtile.log

# Configuration

```
            widget.WidgetBox(widgets=[
                widget.Wallpaper(directory='~/Downloads/wallpaper/', wallpaper_command=None, random_selection=True, label='\u0394'),
                widget.Systray(padding=1, icon_size=22),
                ], close_button_location='right',
            ),
```



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `libqtile/widget/widgetbox.py`
Content:
```
1 # Copyright (c) 2020 elParaguayo
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20 
21 from collections import namedtuple
22 
23 from libqtile import bar
24 from libqtile.log_utils import logger
25 from libqtile.widget import base
26 
27 BoxedWidget = namedtuple("BoxedWidget", ["widget", "draw"])
28 
29 
30 def _no_draw(*args, **kwargs):
31     pass
32 
33 
34 class WidgetBox(base._Widget):
35     """A widget to declutter your bar.
36 
37     WidgetBox is a widget that hides widgets by default but shows them when
38     the box is opened.
39 
40     Widgets that are hidden will still update etc. as if they were on the main
41     bar.
42 
43     Button clicks are passed to widgets when they are visible so callbacks will
44     work.
45 
46     Widgets in the box also remain accessible via command interfaces.
47 
48     Widgets can only be added to the box via the configuration file. The widget
49     is configured by adding widgets to the "widgets" parameter as follows::
50 
51         widget.WidgetBox(widgets=[
52             widget.TextBox(text="This widget is in the box"),
53             widget.Memory()
54             ]
55         ),
56     """
57     orientations = base.ORIENTATION_HORIZONTAL
58     defaults = [
59         (
60             "font",
61             "sans",
62             "Text font"
63         ),
64         (
65             "fontsize",
66             None,
67             "Font pixel size. Calculated if None."
68         ),
69         (
70             "fontshadow",
71             None,
72             "font shadow color, default is None(no shadow)"
73         ),
74         (
75             "foreground",
76             "#ffffff",
77             "Foreground colour."
78         ),
79         (
80             "close_button_location",
81             "left",
82             "Location of close button when box open ('left' or 'right')"
83         ),
84         (
85             "text_closed",
86             "[<]",
87             "Text when box is closed"
88         ),
89         (
90             "text_open",
91             "[>]",
92             "Text when box is open"
93         ),
94     ]
95 
96     def __init__(self, widgets=list(), **config):
97         base._Widget.__init__(self, bar.CALCULATED, **config)
98         self.add_defaults(WidgetBox.defaults)
99         self.box_is_open = False
100         self._widgets = widgets
101         self.add_callbacks({"Button1": self.cmd_toggle})
102 
103         if self.close_button_location not in ["left", "right"]:
104             val = self.close_button_location
105             msg = "Invalid value for 'close_button_location': {}".format(val)
106             logger.warning(msg)
107             self.close_button_location = "left"
108 
109     def _configure(self, qtile, bar):
110         base._Widget._configure(self, qtile, bar)
111 
112         self.layout = self.drawer.textlayout(
113             self.text_closed,
114             self.foreground,
115             self.font,
116             self.fontsize,
117             self.fontshadow,
118             markup=False,
119         )
120 
121         for idx, w in enumerate(self._widgets):
122             if w.configured:
123                 w = w.create_mirror()
124                 self._widgets[idx] = w
125             self.qtile.register_widget(w)
126             w._configure(self.qtile, self.bar)
127 
128             # In case the widget is mirrored, we need to draw it once so the
129             # mirror can copy the surface but draw it off screen
130             w.offsetx = self.bar.width
131             self.qtile.call_soon(w.draw)
132 
133         # We need to stop hidden widgets from drawing while hidden
134         # (e.g. draw could be triggered by a timer) so we take a reference to
135         # the widget's drawer.draw method
136         self.widgets = [BoxedWidget(w, w.drawer.draw) for w in self._widgets]
137 
138         # # Overwrite the current drawer.draw method with a no-op
139         for w in self.widgets:
140             w.widget.drawer.draw = _no_draw
141 
142     def calculate_length(self):
143         return self.layout.width
144 
145     def set_box_label(self):
146         self.layout.text = (self.text_open if self.box_is_open
147                             else self.text_closed)
148 
149     def toggle_widgets(self):
150         for item in self.widgets:
151             try:
152                 self.bar.widgets.remove(item.widget)
153                 # Override drawer.drawer with a no-op
154                 item.widget.drawer.draw = _no_draw
155             except ValueError:
156                 continue
157 
158         index = self.bar.widgets.index(self)
159 
160         if self.close_button_location == "left":
161             index += 1
162 
163         if self.box_is_open:
164 
165             # Need to reverse list as widgets get added in front of eachother.
166             for item in self.widgets[::-1]:
167                 # Restore the original drawer.draw method
168                 item.widget.drawer.draw = item.draw
169                 self.bar.widgets.insert(index, item.widget)
170 
171     def draw(self):
172         self.drawer.clear(self.background or self.bar.background)
173 
174         self.layout.draw(0,
175                          int(self.bar.height / 2.0 -
176                              self.layout.height / 2.0) + 1)
177 
178         self.drawer.draw(offsetx=self.offsetx, width=self.width)
179 
180     def button_press(self, x, y, button):
181         name = "Button{}".format(button)
182         if name in self.mouse_callbacks:
183             self.mouse_callbacks[name]()
184 
185     def cmd_toggle(self):
186         """Toggle box state"""
187         self.box_is_open = not self.box_is_open
188         self.toggle_widgets()
189         self.set_box_label()
190         self.bar.draw()
191
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/libqtile/widget/widgetbox.py b/libqtile/widget/widgetbox.py
--- a/libqtile/widget/widgetbox.py
+++ b/libqtile/widget/widgetbox.py
@@ -22,7 +22,7 @@
 
 from libqtile import bar
 from libqtile.log_utils import logger
-from libqtile.widget import base
+from libqtile.widget import Systray, base
 
 BoxedWidget = namedtuple("BoxedWidget", ["widget", "draw"])
 
@@ -152,6 +152,14 @@
                 self.bar.widgets.remove(item.widget)
                 # Override drawer.drawer with a no-op
                 item.widget.drawer.draw = _no_draw
+
+                # Systray widget needs some additional steps to hide as the icons
+                # are separate _Window instances.
+                # Systray unhides icons when it draws so we only need to hide them.
+                if isinstance(item.widget, Systray):
+                    for icon in item.widget.icons.values():
+                        icon.hide()
+
             except ValueError:
                 continue

{"golden_diff": "diff --git a/libqtile/widget/widgetbox.py b/libqtile/widget/widgetbox.py\n--- a/libqtile/widget/widgetbox.py\n+++ b/libqtile/widget/widgetbox.py\n@@ -22,7 +22,7 @@\n \n from libqtile import bar\n from libqtile.log_utils import logger\n-from libqtile.widget import base\n+from libqtile.widget import Systray, base\n \n BoxedWidget = namedtuple(\"BoxedWidget\", [\"widget\", \"draw\"])\n \n@@ -152,6 +152,14 @@\n                 self.bar.widgets.remove(item.widget)\n                 # Override drawer.drawer with a no-op\n                 item.widget.drawer.draw = _no_draw\n+\n+                # Systray widget needs some additional steps to hide as the icons\n+                # are separate _Window instances.\n+                # Systray unhides icons when it draws so we only need to hide them.\n+                if isinstance(item.widget, Systray):\n+                    for icon in item.widget.icons.values():\n+                        icon.hide()\n+\n             except ValueError:\n                 continue\n", "issue": "WidgetBox does not fully re-expand on click\n# Issue description\r\n\r\nOn first click, WidgetBox expands properly, but clicking a second time does not hide all widgets.\r\n\r\nSpecifically, in my configuration (below), the Wallpaper is shown/hidden properly, but the Systray does not hide again.\r\n\r\n# Qtile version\r\n\r\nqtile-0.17.1.dev82+geb8722ec\r\n\r\n# Stack traces\r\n\r\nno errors in qtile.log\r\n\r\n# Configuration\r\n\r\n```\r\n            widget.WidgetBox(widgets=[\r\n                widget.Wallpaper(directory='~/Downloads/wallpaper/', wallpaper_command=None, random_selection=True, label='\\u0394'),\r\n                widget.Systray(padding=1, icon_size=22),\r\n                ], close_button_location='right',\r\n            ),\r\n```\r\n\r\n\n", "before_files": [{"content": "# Copyright (c) 2020 elParaguayo\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nfrom collections import namedtuple\n\nfrom libqtile import bar\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import base\n\nBoxedWidget = namedtuple(\"BoxedWidget\", [\"widget\", \"draw\"])\n\n\ndef _no_draw(*args, **kwargs):\n    pass\n\n\nclass WidgetBox(base._Widget):\n    \"\"\"A widget to declutter your bar.\n\n    WidgetBox is a widget that hides widgets by default but shows them when\n    the box is opened.\n\n    Widgets that are hidden will still update etc. as if they were on the main\n    bar.\n\n    Button clicks are passed to widgets when they are visible so callbacks will\n    work.\n\n    Widgets in the box also remain accessible via command interfaces.\n\n    Widgets can only be added to the box via the configuration file. The widget\n    is configured by adding widgets to the \"widgets\" parameter as follows::\n\n        widget.WidgetBox(widgets=[\n            widget.TextBox(text=\"This widget is in the box\"),\n            widget.Memory()\n            ]\n        ),\n    \"\"\"\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\n            \"font\",\n            \"sans\",\n            \"Text font\"\n        ),\n        (\n            \"fontsize\",\n            None,\n            \"Font pixel size. Calculated if None.\"\n        ),\n        (\n            \"fontshadow\",\n            None,\n            \"font shadow color, default is None(no shadow)\"\n        ),\n        (\n            \"foreground\",\n            \"#ffffff\",\n            \"Foreground colour.\"\n        ),\n        (\n            \"close_button_location\",\n            \"left\",\n            \"Location of close button when box open ('left' or 'right')\"\n        ),\n        (\n            \"text_closed\",\n            \"[<]\",\n            \"Text when box is closed\"\n        ),\n        (\n            \"text_open\",\n            \"[>]\",\n            \"Text when box is open\"\n        ),\n    ]\n\n    def __init__(self, widgets=list(), **config):\n        base._Widget.__init__(self, bar.CALCULATED, **config)\n        self.add_defaults(WidgetBox.defaults)\n        self.box_is_open = False\n        self._widgets = widgets\n        self.add_callbacks({\"Button1\": self.cmd_toggle})\n\n        if self.close_button_location not in [\"left\", \"right\"]:\n            val = self.close_button_location\n            msg = \"Invalid value for 'close_button_location': {}\".format(val)\n            logger.warning(msg)\n            self.close_button_location = \"left\"\n\n    def _configure(self, qtile, bar):\n        base._Widget._configure(self, qtile, bar)\n\n        self.layout = self.drawer.textlayout(\n            self.text_closed,\n            self.foreground,\n            self.font,\n            self.fontsize,\n            self.fontshadow,\n            markup=False,\n        )\n\n        for idx, w in enumerate(self._widgets):\n            if w.configured:\n                w = w.create_mirror()\n                self._widgets[idx] = w\n            self.qtile.register_widget(w)\n            w._configure(self.qtile, self.bar)\n\n            # In case the widget is mirrored, we need to draw it once so the\n            # mirror can copy the surface but draw it off screen\n            w.offsetx = self.bar.width\n            self.qtile.call_soon(w.draw)\n\n        # We need to stop hidden widgets from drawing while hidden\n        # (e.g. draw could be triggered by a timer) so we take a reference to\n        # the widget's drawer.draw method\n        self.widgets = [BoxedWidget(w, w.drawer.draw) for w in self._widgets]\n\n        # # Overwrite the current drawer.draw method with a no-op\n        for w in self.widgets:\n            w.widget.drawer.draw = _no_draw\n\n    def calculate_length(self):\n        return self.layout.width\n\n    def set_box_label(self):\n        self.layout.text = (self.text_open if self.box_is_open\n                            else self.text_closed)\n\n    def toggle_widgets(self):\n        for item in self.widgets:\n            try:\n                self.bar.widgets.remove(item.widget)\n                # Override drawer.drawer with a no-op\n                item.widget.drawer.draw = _no_draw\n            except ValueError:\n                continue\n\n        index = self.bar.widgets.index(self)\n\n        if self.close_button_location == \"left\":\n            index += 1\n\n        if self.box_is_open:\n\n            # Need to reverse list as widgets get added in front of eachother.\n            for item in self.widgets[::-1]:\n                # Restore the original drawer.draw method\n                item.widget.drawer.draw = item.draw\n                self.bar.widgets.insert(index, item.widget)\n\n    def draw(self):\n        self.drawer.clear(self.background or self.bar.background)\n\n        self.layout.draw(0,\n                         int(self.bar.height / 2.0 -\n                             self.layout.height / 2.0) + 1)\n\n        self.drawer.draw(offsetx=self.offsetx, width=self.width)\n\n    def button_press(self, x, y, button):\n        name = \"Button{}\".format(button)\n        if name in self.mouse_callbacks:\n            self.mouse_callbacks[name]()\n\n    def cmd_toggle(self):\n        \"\"\"Toggle box state\"\"\"\n        self.box_is_open = not self.box_is_open\n        self.toggle_widgets()\n        self.set_box_label()\n        self.bar.draw()\n", "path": "libqtile/widget/widgetbox.py"}], "after_files": [{"content": "# Copyright (c) 2020 elParaguayo\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nfrom collections import namedtuple\n\nfrom libqtile import bar\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import Systray, base\n\nBoxedWidget = namedtuple(\"BoxedWidget\", [\"widget\", \"draw\"])\n\n\ndef _no_draw(*args, **kwargs):\n    pass\n\n\nclass WidgetBox(base._Widget):\n    \"\"\"A widget to declutter your bar.\n\n    WidgetBox is a widget that hides widgets by default but shows them when\n    the box is opened.\n\n    Widgets that are hidden will still update etc. as if they were on the main\n    bar.\n\n    Button clicks are passed to widgets when they are visible so callbacks will\n    work.\n\n    Widgets in the box also remain accessible via command interfaces.\n\n    Widgets can only be added to the box via the configuration file. The widget\n    is configured by adding widgets to the \"widgets\" parameter as follows::\n\n        widget.WidgetBox(widgets=[\n            widget.TextBox(text=\"This widget is in the box\"),\n            widget.Memory()\n            ]\n        ),\n    \"\"\"\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\n            \"font\",\n            \"sans\",\n            \"Text font\"\n        ),\n        (\n            \"fontsize\",\n            None,\n            \"Font pixel size. Calculated if None.\"\n        ),\n        (\n            \"fontshadow\",\n            None,\n            \"font shadow color, default is None(no shadow)\"\n        ),\n        (\n            \"foreground\",\n            \"#ffffff\",\n            \"Foreground colour.\"\n        ),\n        (\n            \"close_button_location\",\n            \"left\",\n            \"Location of close button when box open ('left' or 'right')\"\n        ),\n        (\n            \"text_closed\",\n            \"[<]\",\n            \"Text when box is closed\"\n        ),\n        (\n            \"text_open\",\n            \"[>]\",\n            \"Text when box is open\"\n        ),\n    ]\n\n    def __init__(self, widgets=list(), **config):\n        base._Widget.__init__(self, bar.CALCULATED, **config)\n        self.add_defaults(WidgetBox.defaults)\n        self.box_is_open = False\n        self._widgets = widgets\n        self.add_callbacks({\"Button1\": self.cmd_toggle})\n\n        if self.close_button_location not in [\"left\", \"right\"]:\n            val = self.close_button_location\n            msg = \"Invalid value for 'close_button_location': {}\".format(val)\n            logger.warning(msg)\n            self.close_button_location = \"left\"\n\n    def _configure(self, qtile, bar):\n        base._Widget._configure(self, qtile, bar)\n\n        self.layout = self.drawer.textlayout(\n            self.text_closed,\n            self.foreground,\n            self.font,\n            self.fontsize,\n            self.fontshadow,\n            markup=False,\n        )\n\n        for idx, w in enumerate(self._widgets):\n            if w.configured:\n                w = w.create_mirror()\n                self._widgets[idx] = w\n            self.qtile.register_widget(w)\n            w._configure(self.qtile, self.bar)\n\n            # In case the widget is mirrored, we need to draw it once so the\n            # mirror can copy the surface but draw it off screen\n            w.offsetx = self.bar.width\n            self.qtile.call_soon(w.draw)\n\n        # We need to stop hidden widgets from drawing while hidden\n        # (e.g. draw could be triggered by a timer) so we take a reference to\n        # the widget's drawer.draw method\n        self.widgets = [BoxedWidget(w, w.drawer.draw) for w in self._widgets]\n\n        # # Overwrite the current drawer.draw method with a no-op\n        for w in self.widgets:\n            w.widget.drawer.draw = _no_draw\n\n    def calculate_length(self):\n        return self.layout.width\n\n    def set_box_label(self):\n        self.layout.text = (self.text_open if self.box_is_open\n                            else self.text_closed)\n\n    def toggle_widgets(self):\n        for item in self.widgets:\n            try:\n                self.bar.widgets.remove(item.widget)\n                # Override drawer.drawer with a no-op\n                item.widget.drawer.draw = _no_draw\n\n                # Systray widget needs some additional steps to hide as the icons\n                # are separate _Window instances.\n                # Systray unhides icons when it draws so we only need to hide them.\n                if isinstance(item.widget, Systray):\n                    for icon in item.widget.icons.values():\n                        icon.hide()\n\n            except ValueError:\n                continue\n\n        index = self.bar.widgets.index(self)\n\n        if self.close_button_location == \"left\":\n            index += 1\n\n        if self.box_is_open:\n\n            # Need to reverse list as widgets get added in front of eachother.\n            for item in self.widgets[::-1]:\n                # Restore the original drawer.draw method\n                item.widget.drawer.draw = item.draw\n                self.bar.widgets.insert(index, item.widget)\n\n    def draw(self):\n        self.drawer.clear(self.background or self.bar.background)\n\n        self.layout.draw(0,\n                         int(self.bar.height / 2.0 -\n                             self.layout.height / 2.0) + 1)\n\n        self.drawer.draw(offsetx=self.offsetx, width=self.width)\n\n    def button_press(self, x, y, button):\n        name = \"Button{}\".format(button)\n        if name in self.mouse_callbacks:\n            self.mouse_callbacks[name]()\n\n    def cmd_toggle(self):\n        \"\"\"Toggle box state\"\"\"\n        self.box_is_open = not self.box_is_open\n        self.toggle_widgets()\n        self.set_box_label()\n        self.bar.draw()\n", "path": "libqtile/widget/widgetbox.py"}]}