We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
widget.box does not close
Hi,

  I'm running qtile on arch and after the latest update the widget.box does not close.  It was working fine before the update.  

![qtilewidgetbox1](https://user-images.githubusercontent.com/10890303/150229622-6b4c0742-317b-42f5-829c-82cf3d2ce4c2.png)

![qtilewidgetbox2](https://user-images.githubusercontent.com/10890303/150229671-4abc6d90-8bda-438f-8c36-bdd1d0432fa6.png)
 

--- 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 from libqtile import bar
21 from libqtile.log_utils import logger
22 from libqtile.widget import Systray, base
23 
24 
25 class WidgetBox(base._Widget):
26     """A widget to declutter your bar.
27 
28     WidgetBox is a widget that hides widgets by default but shows them when
29     the box is opened.
30 
31     Widgets that are hidden will still update etc. as if they were on the main
32     bar.
33 
34     Button clicks are passed to widgets when they are visible so callbacks will
35     work.
36 
37     Widgets in the box also remain accessible via command interfaces.
38 
39     Widgets can only be added to the box via the configuration file. The widget
40     is configured by adding widgets to the "widgets" parameter as follows::
41 
42         widget.WidgetBox(widgets=[
43             widget.TextBox(text="This widget is in the box"),
44             widget.Memory()
45             ]
46         ),
47     """
48 
49     orientations = base.ORIENTATION_HORIZONTAL
50     defaults = [
51         ("font", "sans", "Text font"),
52         ("fontsize", None, "Font pixel size. Calculated if None."),
53         ("fontshadow", None, "font shadow color, default is None(no shadow)"),
54         ("foreground", "#ffffff", "Foreground colour."),
55         (
56             "close_button_location",
57             "left",
58             "Location of close button when box open ('left' or 'right')",
59         ),
60         ("text_closed", "[<]", "Text when box is closed"),
61         ("text_open", "[>]", "Text when box is open"),
62     ]
63 
64     def __init__(self, widgets: list = None, **config):
65         base._Widget.__init__(self, bar.CALCULATED, **config)
66         self.add_defaults(WidgetBox.defaults)
67         self.box_is_open = False
68         self.widgets = widgets if widgets is not None else []
69         self.add_callbacks({"Button1": self.cmd_toggle})
70 
71         self.close_button_location: str
72         if self.close_button_location not in ["left", "right"]:
73             val = self.close_button_location
74             msg = "Invalid value for 'close_button_location': {}".format(val)
75             logger.warning(msg)
76             self.close_button_location = "left"
77 
78     def _configure(self, qtile, bar):
79         base._Widget._configure(self, qtile, bar)
80 
81         self.layout = self.drawer.textlayout(
82             self.text_closed,
83             self.foreground,
84             self.font,
85             self.fontsize,
86             self.fontshadow,
87             markup=False,
88         )
89 
90         for idx, w in enumerate(self.widgets):
91             if w.configured:
92                 w = w.create_mirror()
93                 self.widgets[idx] = w
94             self.qtile.register_widget(w)
95             w._configure(self.qtile, self.bar)
96 
97             # In case the widget is mirrored, we need to draw it once so the
98             # mirror can copy the surface but draw it off screen
99             w.offsetx = self.bar.width
100             self.qtile.call_soon(w.draw)
101 
102         # Disable drawing of the widget's contents
103         for w in self.widgets:
104             w.drawer.disable()
105 
106     def calculate_length(self):
107         return self.layout.width
108 
109     def set_box_label(self):
110         self.layout.text = self.text_open if self.box_is_open else self.text_closed
111 
112     def toggle_widgets(self):
113         for widget in self.widgets:
114             try:
115                 self.bar.widgets.remove(widget)
116                 # Override drawer.drawer with a no-op
117                 widget.drawer.disable()
118 
119                 # Systray widget needs some additional steps to hide as the icons
120                 # are separate _Window instances.
121                 # Systray unhides icons when it draws so we only need to hide them.
122                 if isinstance(widget, Systray):
123                     for icon in widget.icons.values():
124                         icon.hide()
125 
126             except ValueError:
127                 continue
128 
129         index = self.bar.widgets.index(self)
130 
131         if self.close_button_location == "left":
132             index += 1
133 
134         if self.box_is_open:
135 
136             # Need to reverse list as widgets get added in front of eachother.
137             for widget in self.widgets[::-1]:
138                 # enable drawing again
139                 widget.drawer.enable()
140                 self.bar.widgets.insert(index, widget)
141 
142     def draw(self):
143         self.drawer.clear(self.background or self.bar.background)
144 
145         self.layout.draw(0, int(self.bar.height / 2.0 - self.layout.height / 2.0) + 1)
146 
147         self.drawer.draw(offsetx=self.offsetx, offsety=self.offsety, width=self.width)
148 
149     def cmd_toggle(self):
150         """Toggle box state"""
151         self.box_is_open = not self.box_is_open
152         self.toggle_widgets()
153         self.set_box_label()
154         self.bar.draw()
155
```
--- 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
@@ -120,7 +120,7 @@
                 # are separate _Window instances.
                 # Systray unhides icons when it draws so we only need to hide them.
                 if isinstance(widget, Systray):
-                    for icon in widget.icons.values():
+                    for icon in widget.tray_icons:
                         icon.hide()
 
             except ValueError:

{"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@@ -120,7 +120,7 @@\n                 # are separate _Window instances.\n                 # Systray unhides icons when it draws so we only need to hide them.\n                 if isinstance(widget, Systray):\n-                    for icon in widget.icons.values():\n+                    for icon in widget.tray_icons:\n                         icon.hide()\n \n             except ValueError:\n", "issue": "widget.box does not close\nHi,\r\n\r\n  I'm running qtile on arch and after the latest update the widget.box does not close.  It was working fine before the update.  \r\n\r\n![qtilewidgetbox1](https://user-images.githubusercontent.com/10890303/150229622-6b4c0742-317b-42f5-829c-82cf3d2ce4c2.png)\r\n\r\n![qtilewidgetbox2](https://user-images.githubusercontent.com/10890303/150229671-4abc6d90-8bda-438f-8c36-bdd1d0432fa6.png)\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.\nfrom libqtile import bar\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import Systray, base\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\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\"font\", \"sans\", \"Text font\"),\n        (\"fontsize\", None, \"Font pixel size. Calculated if None.\"),\n        (\"fontshadow\", None, \"font shadow color, default is None(no shadow)\"),\n        (\"foreground\", \"#ffffff\", \"Foreground colour.\"),\n        (\n            \"close_button_location\",\n            \"left\",\n            \"Location of close button when box open ('left' or 'right')\",\n        ),\n        (\"text_closed\", \"[<]\", \"Text when box is closed\"),\n        (\"text_open\", \"[>]\", \"Text when box is open\"),\n    ]\n\n    def __init__(self, widgets: list = None, **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 if widgets is not None else []\n        self.add_callbacks({\"Button1\": self.cmd_toggle})\n\n        self.close_button_location: str\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        # Disable drawing of the widget's contents\n        for w in self.widgets:\n            w.drawer.disable()\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 else self.text_closed\n\n    def toggle_widgets(self):\n        for widget in self.widgets:\n            try:\n                self.bar.widgets.remove(widget)\n                # Override drawer.drawer with a no-op\n                widget.drawer.disable()\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(widget, Systray):\n                    for icon in 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 widget in self.widgets[::-1]:\n                # enable drawing again\n                widget.drawer.enable()\n                self.bar.widgets.insert(index, widget)\n\n    def draw(self):\n        self.drawer.clear(self.background or self.bar.background)\n\n        self.layout.draw(0, int(self.bar.height / 2.0 - self.layout.height / 2.0) + 1)\n\n        self.drawer.draw(offsetx=self.offsetx, offsety=self.offsety, width=self.width)\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.\nfrom libqtile import bar\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import Systray, base\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\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\"font\", \"sans\", \"Text font\"),\n        (\"fontsize\", None, \"Font pixel size. Calculated if None.\"),\n        (\"fontshadow\", None, \"font shadow color, default is None(no shadow)\"),\n        (\"foreground\", \"#ffffff\", \"Foreground colour.\"),\n        (\n            \"close_button_location\",\n            \"left\",\n            \"Location of close button when box open ('left' or 'right')\",\n        ),\n        (\"text_closed\", \"[<]\", \"Text when box is closed\"),\n        (\"text_open\", \"[>]\", \"Text when box is open\"),\n    ]\n\n    def __init__(self, widgets: list = None, **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 if widgets is not None else []\n        self.add_callbacks({\"Button1\": self.cmd_toggle})\n\n        self.close_button_location: str\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        # Disable drawing of the widget's contents\n        for w in self.widgets:\n            w.drawer.disable()\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 else self.text_closed\n\n    def toggle_widgets(self):\n        for widget in self.widgets:\n            try:\n                self.bar.widgets.remove(widget)\n                # Override drawer.drawer with a no-op\n                widget.drawer.disable()\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(widget, Systray):\n                    for icon in widget.tray_icons:\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 widget in self.widgets[::-1]:\n                # enable drawing again\n                widget.drawer.enable()\n                self.bar.widgets.insert(index, widget)\n\n    def draw(self):\n        self.drawer.clear(self.background or self.bar.background)\n\n        self.layout.draw(0, int(self.bar.height / 2.0 - self.layout.height / 2.0) + 1)\n\n        self.drawer.draw(offsetx=self.offsetx, offsety=self.offsety, width=self.width)\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"}]}