prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Chord widget doesn't have default background colour
  ### The issue:
  
  The background colour is set by looking up the chord name in a dictionary. If the name is not in the dictionary then the chord will be displayed with whatever the current background colour is.
  
  The widget needs to be updated to restore colours to defaults.
  
  ### Required:
  
  - [X] I have searched past issues to see if this bug has already been reported.
  
  --- 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/chord.py`
  Content:
  ```
  1 # Copyright (c) 2014 Sean Vig
  2 # Copyright (c) 2014 roger
  3 # Copyright (c) 2014 Adi Sieker
  4 # Copyright (c) 2014 Tycho Andersen
  5 #
  6 # Permission is hereby granted, free of charge, to any person obtaining a copy
  7 # of this software and associated documentation files (the "Software"), to deal
  8 # in the Software without restriction, including without limitation the rights
  9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10 # copies of the Software, and to permit persons to whom the Software is
  11 # furnished to do so, subject to the following conditions:
  12 #
  13 # The above copyright notice and this permission notice shall be included in
  14 # all copies or substantial portions of the Software.
  15 #
  16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22 # SOFTWARE.
  23 
  24 from libqtile import bar, hook
  25 from libqtile.widget import base
  26 
  27 
  28 class Chord(base._TextBox):
  29     """Display current key chord"""
  30 
  31     defaults = [
  32         ("chords_colors", {}, "colors per chord in form of tuple ('bg', 'fg')."),
  33         (
  34             "name_transform",
  35             lambda txt: txt,
  36             "preprocessor for chord name it is pure function string -> string",
  37         ),
  38     ]
  39 
  40     def __init__(self, width=bar.CALCULATED, **config):
  41         base._TextBox.__init__(self, "", width, **config)
  42         self.add_defaults(Chord.defaults)
  43 
  44     def _configure(self, qtile, bar):
  45         base._TextBox._configure(self, qtile, bar)
  46         self.text = ""
  47         self._setup_hooks()
  48 
  49     def _setup_hooks(self):
  50         def hook_enter_chord(chord_name):
  51             if chord_name is True:
  52                 self.text = ""
  53                 return
  54 
  55             self.text = self.name_transform(chord_name)
  56             if chord_name in self.chords_colors:
  57                 (self.background, self.foreground) = self.chords_colors.get(chord_name)
  58 
  59             self.bar.draw()
  60 
  61         hook.subscribe.enter_chord(hook_enter_chord)
  62         hook.subscribe.leave_chord(self.clear)
  63 
  64     def clear(self, *args):
  65         self.text = ""
  66         self.bar.draw()
  67
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/libqtile/widget/chord.py b/libqtile/widget/chord.py
  --- a/libqtile/widget/chord.py
  +++ b/libqtile/widget/chord.py
  @@ -29,7 +29,13 @@
       """Display current key chord"""
   
       defaults = [
  -        ("chords_colors", {}, "colors per chord in form of tuple ('bg', 'fg')."),
  +        (
  +            "chords_colors",
  +            {},
  +            "colors per chord in form of tuple {'chord_name': ('bg', 'fg')}. "
  +            "Where a chord name is not in the dictionary, the default ``background`` and ``foreground``"
  +            " values will be used.",
  +        ),
           (
               "name_transform",
               lambda txt: txt,
  @@ -43,6 +49,8 @@
   
       def _configure(self, qtile, bar):
           base._TextBox._configure(self, qtile, bar)
  +        self.default_background = self.background
  +        self.default_foreground = self.foreground
           self.text = ""
           self._setup_hooks()
   
  @@ -50,17 +58,25 @@
           def hook_enter_chord(chord_name):
               if chord_name is True:
                   self.text = ""
  +                self.reset_colours()
                   return
   
               self.text = self.name_transform(chord_name)
               if chord_name in self.chords_colors:
                   (self.background, self.foreground) = self.chords_colors.get(chord_name)
  +            else:
  +                self.reset_colours()
   
               self.bar.draw()
   
           hook.subscribe.enter_chord(hook_enter_chord)
           hook.subscribe.leave_chord(self.clear)
   
  +    def reset_colours(self):
  +        self.background = self.default_background
  +        self.foreground = self.default_foreground
  +
       def clear(self, *args):
  +        self.reset_colours()
           self.text = ""
           self.bar.draw()
  
verification_info: {"golden_diff": "diff --git a/libqtile/widget/chord.py b/libqtile/widget/chord.py\n--- a/libqtile/widget/chord.py\n+++ b/libqtile/widget/chord.py\n@@ -29,7 +29,13 @@\n     \"\"\"Display current key chord\"\"\"\n \n     defaults = [\n-        (\"chords_colors\", {}, \"colors per chord in form of tuple ('bg', 'fg').\"),\n+        (\n+            \"chords_colors\",\n+            {},\n+            \"colors per chord in form of tuple {'chord_name': ('bg', 'fg')}. \"\n+            \"Where a chord name is not in the dictionary, the default ``background`` and ``foreground``\"\n+            \" values will be used.\",\n+        ),\n         (\n             \"name_transform\",\n             lambda txt: txt,\n@@ -43,6 +49,8 @@\n \n     def _configure(self, qtile, bar):\n         base._TextBox._configure(self, qtile, bar)\n+        self.default_background = self.background\n+        self.default_foreground = self.foreground\n         self.text = \"\"\n         self._setup_hooks()\n \n@@ -50,17 +58,25 @@\n         def hook_enter_chord(chord_name):\n             if chord_name is True:\n                 self.text = \"\"\n+                self.reset_colours()\n                 return\n \n             self.text = self.name_transform(chord_name)\n             if chord_name in self.chords_colors:\n                 (self.background, self.foreground) = self.chords_colors.get(chord_name)\n+            else:\n+                self.reset_colours()\n \n             self.bar.draw()\n \n         hook.subscribe.enter_chord(hook_enter_chord)\n         hook.subscribe.leave_chord(self.clear)\n \n+    def reset_colours(self):\n+        self.background = self.default_background\n+        self.foreground = self.default_foreground\n+\n     def clear(self, *args):\n+        self.reset_colours()\n         self.text = \"\"\n         self.bar.draw()\n", "issue": "Chord widget doesn't have default background colour\n### The issue:\n\nThe background colour is set by looking up the chord name in a dictionary. If the name is not in the dictionary then the chord will be displayed with whatever the current background colour is.\r\n\r\nThe widget needs to be updated to restore colours to defaults.\n\n### Required:\n\n- [X] I have searched past issues to see if this bug has already been reported.\n", "before_files": [{"content": "# Copyright (c) 2014 Sean Vig\n# Copyright (c) 2014 roger\n# Copyright (c) 2014 Adi Sieker\n# Copyright (c) 2014 Tycho Andersen\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 libqtile import bar, hook\nfrom libqtile.widget import base\n\n\nclass Chord(base._TextBox):\n    \"\"\"Display current key chord\"\"\"\n\n    defaults = [\n        (\"chords_colors\", {}, \"colors per chord in form of tuple ('bg', 'fg').\"),\n        (\n            \"name_transform\",\n            lambda txt: txt,\n            \"preprocessor for chord name it is pure function string -> string\",\n        ),\n    ]\n\n    def __init__(self, width=bar.CALCULATED, **config):\n        base._TextBox.__init__(self, \"\", width, **config)\n        self.add_defaults(Chord.defaults)\n\n    def _configure(self, qtile, bar):\n        base._TextBox._configure(self, qtile, bar)\n        self.text = \"\"\n        self._setup_hooks()\n\n    def _setup_hooks(self):\n        def hook_enter_chord(chord_name):\n            if chord_name is True:\n                self.text = \"\"\n                return\n\n            self.text = self.name_transform(chord_name)\n            if chord_name in self.chords_colors:\n                (self.background, self.foreground) = self.chords_colors.get(chord_name)\n\n            self.bar.draw()\n\n        hook.subscribe.enter_chord(hook_enter_chord)\n        hook.subscribe.leave_chord(self.clear)\n\n    def clear(self, *args):\n        self.text = \"\"\n        self.bar.draw()\n", "path": "libqtile/widget/chord.py"}], "after_files": [{"content": "# Copyright (c) 2014 Sean Vig\n# Copyright (c) 2014 roger\n# Copyright (c) 2014 Adi Sieker\n# Copyright (c) 2014 Tycho Andersen\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 libqtile import bar, hook\nfrom libqtile.widget import base\n\n\nclass Chord(base._TextBox):\n    \"\"\"Display current key chord\"\"\"\n\n    defaults = [\n        (\n            \"chords_colors\",\n            {},\n            \"colors per chord in form of tuple {'chord_name': ('bg', 'fg')}. \"\n            \"Where a chord name is not in the dictionary, the default ``background`` and ``foreground``\"\n            \" values will be used.\",\n        ),\n        (\n            \"name_transform\",\n            lambda txt: txt,\n            \"preprocessor for chord name it is pure function string -> string\",\n        ),\n    ]\n\n    def __init__(self, width=bar.CALCULATED, **config):\n        base._TextBox.__init__(self, \"\", width, **config)\n        self.add_defaults(Chord.defaults)\n\n    def _configure(self, qtile, bar):\n        base._TextBox._configure(self, qtile, bar)\n        self.default_background = self.background\n        self.default_foreground = self.foreground\n        self.text = \"\"\n        self._setup_hooks()\n\n    def _setup_hooks(self):\n        def hook_enter_chord(chord_name):\n            if chord_name is True:\n                self.text = \"\"\n                self.reset_colours()\n                return\n\n            self.text = self.name_transform(chord_name)\n            if chord_name in self.chords_colors:\n                (self.background, self.foreground) = self.chords_colors.get(chord_name)\n            else:\n                self.reset_colours()\n\n            self.bar.draw()\n\n        hook.subscribe.enter_chord(hook_enter_chord)\n        hook.subscribe.leave_chord(self.clear)\n\n    def reset_colours(self):\n        self.background = self.default_background\n        self.foreground = self.default_foreground\n\n    def clear(self, *args):\n        self.reset_colours()\n        self.text = \"\"\n        self.bar.draw()\n", "path": "libqtile/widget/chord.py"}]}