internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: qtile/qtile

Issue:
Battery and Image widgets gone from the docs
If you compare the docs for [v0.12.0](http://docs.qtile.org/en/v0.12.0/manual/ref/widgets.html) with [v0.13.0](http://docs.qtile.org/en/v0.13.0/manual/ref/widgets.html) you may notice that:

- `libqtile.widget.Battery` and `libqtile.widget.BatteryIcon` are missing in 0.13.0,
- the description of `libqtile.widget.Image` in 0.13.0 consists of:
  `alias of libqtile.widget.import_error.make_error.<locals>.ImportErrorWidget`

This is most likely due to some modules missing from the documentation building environment. Somewhere in your Sphinx logs there are probably messages like these:

        Unmet dependencies for optional Widget: '.widget.battery.Battery'
        Unmet dependencies for optional Widget: '.widget.battery.BatteryIcon'
        Unmet dependencies for optional Widget: '.widget.image.Image'

My guess is that this has something to do with importing `images` from `..`, as those are the only imports that had changed for the affected widgets.

Note that the docs for the `Volume` widget are OK despite `from .. import images` in the widget code. But here the import is done lazily in a setup function rather than at the top of the module:
https://github.com/qtile/qtile/blob/78d0c9b3d13cddd88795d7607af47abb10d50e1b/libqtile/widget/volume.py#L170-L171


Discussion:
After some further research I think you may be able to fix this by adding `cairocffi.pixbuf` to `MOCK_MODULES` in `docs/conf.py`. But I'm not familiar enough with ReadTheDocs to be able to say that for sure.

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -27,6 +27,7 @@ def __dir__(self):
     'libqtile._ffi_pango',
     'libqtile.core._ffi_xcursors',
     'cairocffi',
+    'cairocffi.pixbuf',
     'cffi',
     'dateutil',
     'dateutil.parser',


Test patch:
Repository: qtile/qtile

Issue:
Exception in Battery widget
In `LinuxBattery`, the implementation searches for the correct files to get batttery information from and uses the first it finds. However, it reports missing files as exceptions in the log. I believe this is incorrect, since the behavior is expected is the file name differs. The bad line is: https://github.com/qtile/qtile/blob/master/libqtile/widget/battery.py#L235

Also worth changing: the try block should only contain the `open` statement and the `except` should only catch `FileNotFoundError`—everything else should be properly raised.

I can make a PR if you prefer.


Discussion:

Resolving patch:
diff --git a/libqtile/widget/battery.py b/libqtile/widget/battery.py
--- a/libqtile/widget/battery.py
+++ b/libqtile/widget/battery.py
@@ -218,21 +218,21 @@ def _get_battery_name(self):
         return 'BAT0'
 
     def _load_file(self, name) -> Optional[Tuple[str, str]]:
-        try:
-            path = os.path.join(self.BAT_DIR, self.battery, name)
-            if 'energy' in name or 'power' in name:
-                value_type = 'uW'
-            elif 'charge' in name:
-                value_type = 'uAh'
-            elif 'current' in name:
-                value_type = 'uA'
-            else:
-                value_type = ''
+        path = os.path.join(self.BAT_DIR, self.battery, name)
+        if 'energy' in name or 'power' in name:
+            value_type = 'uW'
+        elif 'charge' in name:
+            value_type = 'uAh'
+        elif 'current' in name:
+            value_type = 'uA'
+        else:
+            value_type = ''
 
+        try:
             with open(path, 'r') as f:
                 return f.read().strip(), value_type
-        except Exception:
-            logger.exception("Failed to get %s" % name)
+        except FileNotFoundError:
+            logger.debug("Failed to get %s" % name)
         return None
 
     def _get_param(self, name) -> Tuple[str, str]:


Test patch:
Repository: qtile/qtile

Issue:
docs: Missing deps when building widget docs gives "alias to ImportErrorWidget"
See http://docs.qtile.org/en/latest/manual/ref/widgets.html#memory for example.

I guess the widget dependencies are not installed while building the docs, resulting in Sphinx telling the widget is an alias to `libqtile.widget.import_error.make_error.<locals>.ImportErrorWidget`.

EDIT: okay I see where the deps are listed: in `docs/conf.py`. Indeed `mpd` is present but `psutil` is not, so the `Memory` widget's docs do not build.


Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -36,6 +36,7 @@ def __dir__(self):
     'iwlib',
     'keyring',
     'mpd',
+    'psutil',
     'trollius',
     'xcffib',
     'xcffib.randr',


Test patch:
Repository: qtile/qtile

Issue:
Battery widget error: Unable to read status for status_file
Qtile 0.14.2 - Arch Linux

My battery widget config:
```python
Battery(
	battery = 0,
	format = "{char} {percent:0.1%}",
	update_interval = 5,
	low_percentage = 0.05,
	full_char = "",
	charge_char = "+",
	discharge_char = "-",
	empty_char = "",
	low_foreground = self.color.red
)

```

Qtile log:
```
2019-10-14 23:11:33,865 ERROR libqtile battery.py:_load_file():L235 Failed to get status
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/libqtile/widget/battery.py", line 222, in _load_file
    path = os.path.join(self.BAT_DIR, self.battery, name)
  File "/usr/lib/python3.7/posixpath.py", line 94, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib/python3.7/genericpath.py", line 149, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'int'
```


Discussion:
The solution is put this on 222L:
```python
path = os.path.join(self.BAT_DIR, "BAT" + str(self.battery), name)
```

Resolving patch:
diff --git a/libqtile/widget/battery.py b/libqtile/widget/battery.py
--- a/libqtile/widget/battery.py
+++ b/libqtile/widget/battery.py
@@ -209,6 +209,8 @@ def __init__(self, **config):
 
         configurable.Configurable.__init__(self, **config)
         self.add_defaults(_LinuxBattery.defaults)
+        if isinstance(self.battery, int):
+            self.battery = "BAT{}".format(self.battery)
 
     def _get_battery_name(self):
         if os.path.isdir(self.BAT_DIR):
@@ -315,7 +317,7 @@ class Battery(base.ThreadedPollText):
         ('low_percentage', 0.10, "Indicates when to use the low_foreground color 0 < x < 1"),
         ('low_foreground', 'FF0000', 'Font color on low battery'),
         ('update_interval', 60, 'Seconds between status updates'),
-        ('battery', 0, 'Which battery should be monitored'),
+        ('battery', 0, 'Which battery should be monitored (battery number or name)'),
     ]
 
     def __init__(self, **config) -> None:


Test patch:
Repository: qtile/qtile

Issue:
EzKey does not allow description
I think the [EzKey constructor](https://github.com/qtile/qtile/blob/master/libqtile/config.py#L155) does not allow a description (no `kwds` variable) although [Key constructor](https://github.com/qtile/qtile/blob/master/libqtile/config.py#L53) does. 

Edit: Why do you set the description within a dictionary instead of having a constructor argument for it?

Edit 2: Forgot my versions and stuff:

|    Item   |     Version    |
|:---------:|:--------------:|
|   Qtile (from official repositories)   |     0.14.2     |
| ArchLinux | 5.4.6-arch3-1 |



Discussion:
Indeed, it looks like the keyworded arguments were forgotten.

As for your second question, the documentation seems incorrect: you don't have to pass a dictionary, just a `desc` keyworded argument. The dictionary is just a way to pack all keyworded arguments in the function, as seen with the `**` notation.
Thank you for your responses! Would you like for me to create a pull-request with the keyworded argument added to EzKey class constructor?
Of course, please do!

Resolving patch:
diff --git a/libqtile/config.py b/libqtile/config.py
--- a/libqtile/config.py
+++ b/libqtile/config.py
@@ -152,9 +152,9 @@ def parse(self, spec):
 
 
 class EzKey(EzConfig, Key):
-    def __init__(self, keydef, *commands):
+    def __init__(self, keydef, *commands, **kwargs):
         modkeys, key = self.parse(keydef)
-        super().__init__(modkeys, key, *commands)
+        super().__init__(modkeys, key, *commands, **kwargs)
 
 
 class EzClick(EzConfig, Click):


Test patch:
Repository: qtile/qtile

Issue:
Improve documentation for image widget
I wanted to add icons to my bar and found the image widget to do that. But from the documentation it seems quite inflexible. From the documentation my only option for resizing and positioning is scale, which means I can either keep the original size or resize it to the size of the bar. While investigating the source code to write a patch to address this issue I found that there is already an option for that. margin_x and margin_y can be used to make the image smaller and keep it centered. This options are not in the documentation for image. The auto generator is not able to find these options for this widget. Maybe this is the case with even more widgets.


Discussion:

Resolving patch:
diff --git a/libqtile/widget/base.py b/libqtile/widget/base.py
--- a/libqtile/widget/base.py
+++ b/libqtile/widget/base.py
@@ -545,7 +545,7 @@ def poll(self):
 # these two classes below look SUSPICIOUSLY similar
 
 
-class PaddingMixin:
+class PaddingMixin(configurable.Configurable):
     """Mixin that provides padding(_x|_y|)
 
     To use it, subclass and add this to __init__:
@@ -563,7 +563,7 @@ class PaddingMixin:
     padding_y = configurable.ExtraFallback('padding_y', 'padding')
 
 
-class MarginMixin:
+class MarginMixin(configurable.Configurable):
     """Mixin that provides margin(_x|_y|)
 
     To use it, subclass and add this to __init__:


Test patch:
Repository: qtile/qtile

Issue:
Jetbrain's products loose focus
# 2020-05-21 update

Fixes have been merged in master, thus this shouldn't be a problem anymore. Feedback welcome!

# 2020-04-28 update

The main problem is that Jetbrain's products after focusing other window and back looses focus in editor frame. You can't enter any text. This even happens then navigating between Jetbrain's tabs. Additionally popups loose focus, too.
Confirmed on phpStorm, pyCharm, AndroidStudio.

What has been tried:
- set `_JAVA_AWT_WM_NONREPARENTING=1` environment variable
- set ``wmname="LG3D"  in Qtile config
 
revision 28d5c30 is the start of this bug
revision before (0617235) works as expected

workarounds: 
- revert to 0.14.2
- use Xephyr


Discussion:

Resolving patch:
diff --git a/libqtile/backend/x11/xcore.py b/libqtile/backend/x11/xcore.py
--- a/libqtile/backend/x11/xcore.py
+++ b/libqtile/backend/x11/xcore.py
@@ -86,9 +86,9 @@ def __init__(self, display_name: str = None) -> None:
 
         self._last_event_timestamp = xcffib.CurrentTime
 
-        wmname = "qtile"
+        self._wmname = "qtile"
         self._supporting_wm_check_window = self.conn.create_window(-1, -1, 1, 1)
-        self._supporting_wm_check_window.set_property("_NET_WM_NAME", wmname)
+        self._supporting_wm_check_window.set_property("_NET_WM_NAME", self._wmname)
         self._supporting_wm_check_window.set_property(
             "_NET_SUPPORTING_WM_CHECK", self._supporting_wm_check_window.wid
         )
@@ -151,6 +151,15 @@ def get_screen_info(self) -> List[Tuple[int, int, int, int]]:
 
         return [(x, y, w, h) for (x, y), (w, h) in xywh.items()]
 
+    @property
+    def wmname(self):
+        return self._wmname
+
+    @wmname.setter
+    def wmname(self, wmname):
+        self._wmname = wmname
+        self._supporting_wm_check_window.set_property("_NET_WM_NAME", wmname)
+
     @property
     def masks(self) -> Tuple[int, int]:
         return self._numlock_mask, self._valid_mask
diff --git a/libqtile/core/manager.py b/libqtile/core/manager.py
--- a/libqtile/core/manager.py
+++ b/libqtile/core/manager.py
@@ -96,6 +96,7 @@ def __init__(
 
         self.numlock_mask, self.valid_mask = self.core.masks
 
+        self.core.wmname = getattr(self.config, "wmname", "qtile")
         if config.main:
             config.main(self)
 


Test patch:
Repository: qtile/qtile

Issue:
Venv install effects on shell environment
Hey

I've been using qtile for a few days, I quite like it! It is running in a Python3.7 venv on Debian 10, and has been installed following the 'Fedora example' given in the doc (http://docs.qtile.org/en/latest/manual/install/index.html#installing-from-source), with no real issue.

However when opening a terminal (with `lazy.spawn(...)`), the shell environment looks partly modified by the Qtile venv:
`$PATH = <qtitle_repo_path>/venv/bin : [...]`
`$VIRTUAL_ENV = <qtile_repo_path>/venv`
I'm guessing that the Python process running Qtile passes by default the shell environment for children, thought I'm not sure why then `$PS1` is not the venv one.

I ended up adding a optional kwarg `env` to `core.manager.Qtile.cmd_spawn` used with `os.execvpe`, to allow the use of a 'cleaned' env.

It seems to be working so far, but I'm wondering if I haven't missed anything, like a more natural way to deal with this, or if my install is faulty. Also I didn't try any packaging-like solution, like using zipapp.



Discussion:
I don't think there really is a nice way of dealing with this; is this causing you issues, with running venvs in child shells I guess? I suppose we should clean some of the things (maybe VIRTUAL_ENV), but it does seem reasonable to want to pass through most of the environment.
No problem when running venvs so far.
Actually I came across the matter only once, when compiling vim with python3 support. The changes in the env were messing with the configuration for as where to find `Python.h`, even with many flags explicitely set.
But then, passing a cleaned env (by that I mean removing `<qtitle_repo_path>/venv/bin` from `PATH` and unsetting `VIRTUAL_ENV`) was enough for the build to succeed painlessly.
Yeah, I can see where having VIRTUAL_ENV set at least would cause a problem. I'll go ahead and send a patch to unset that.

Resolving patch:
diff --git a/libqtile/core/manager.py b/libqtile/core/manager.py
--- a/libqtile/core/manager.py
+++ b/libqtile/core/manager.py
@@ -1128,6 +1128,14 @@ def cmd_spawn(self, cmd):
             pid2 = os.fork()
             if pid2 == 0:
                 os.close(w)
+                try:
+                    # if qtile was installed in a virutal env, we don't
+                    # necessarily want to propagate that to children
+                    # applications, since it may change e.g. the behavior
+                    # of shells that spawn python applications
+                    del os.environ['VIRTUAL_ENV']
+                except KeyError:
+                    pass
 
                 # Open /dev/null as stdin, stdout, stderr
                 try:


Test patch:
Repository: qtile/qtile

Issue:
qtile error to load



Discussion:

Resolving patch:
diff --git a/libqtile/scripts/qtile.py b/libqtile/scripts/qtile.py
--- a/libqtile/scripts/qtile.py
+++ b/libqtile/scripts/qtile.py
@@ -29,7 +29,11 @@
 from libqtile import confreader
 from libqtile.backend.x11 import xcore
 
-locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())  # type: ignore
+try:
+    locale.setlocale(locale.LC_ALL, locale.getdefaultlocale())  # type: ignore
+except locale.Error:
+    pass
+
 
 try:
     import pkg_resources


Test patch:
Repository: qtile/qtile

Issue:
libqtile utils.py:safe_import():L192  Unmet dependencies for optional Widget: '.widget.launchbar.LaunchBar', No module named 'xdg.IconTheme'
It seems there's confusion about the `xdg` dependency that is used. The code expects [PyXDG](https://freedesktop.org/wiki/Software/pyxdg/) while the actual installed version is [xdg](https://pypi.org/project/xdg/). The latter does not have an `IconTheme` submodule, explaining the message.

The distribution name for `pyxdg` is  `pyxdg` (not `xdg`).

https://github.com/qtile/qtile/blob/0d8b6e5de1cacb9827c4b30ce7ed8da4bb686f26/libqtile/widget/launchbar.py#L49


Discussion:

Resolving patch:
diff --git a/libqtile/widget/launchbar.py b/libqtile/widget/launchbar.py
--- a/libqtile/widget/launchbar.py
+++ b/libqtile/widget/launchbar.py
@@ -52,6 +52,10 @@
 class LaunchBar(base._Widget):
     """A widget that display icons to launch the associated command
 
+    Widget requirements: pyxdg_.
+
+    .. _pyxdg: https://freedesktop.org/wiki/Software/pyxdg/
+
     Parameters
     ==========
     progs :


Test patch:
Repository: qtile/qtile

Issue:
widget.WindowTabs default selected task indicator produces invalid pango markup
# Issue description

The default _selected task indicator_ (``("<", ">")``) for ``widget.WindowTabs`` produces invalid pango markup and thus the call to ``pango_parse_markup`` fails.

It leads to invalid tag names for single word window names (e.g. ``<terminal>``) or invalid syntax for multiword names (e.g. ``<qtile - Mozilla Firefox>``).

Possible fixes:

- change default to e.g. ``('[', ']')`` or different foreground color
- default to no markup
- at least add a note in the documentation, but defaults should be working

If this is wanted, I'm happy to prepare a PR based on the outcome of the discussion here.

# Qtile version

Qtile version ``0.15.1``. Also [latest revision of libqtile/widget/windowtabs.py](https://github.com/qtile/qtile/blob/d47347ad0f37b4a5735faa8b7061f484e8cf81d9/libqtile/widget/windowtabs.py) (d47347a)

# Configuration

Use default ``widget.WindowTabs()``



Discussion:
Thanks for the report! I'd say maybe just use `("<b>", "</b>")`?

Resolving patch:
diff --git a/libqtile/widget/windowtabs.py b/libqtile/widget/windowtabs.py
--- a/libqtile/widget/windowtabs.py
+++ b/libqtile/widget/windowtabs.py
@@ -35,7 +35,7 @@ class WindowTabs(base._TextBox):
     orientations = base.ORIENTATION_HORIZONTAL
     defaults = [
         ("separator", " | ", "Task separator text."),
-        ("selected", ("<", ">"), "Selected task indicator"),
+        ("selected", ("<b>", "</b>"), "Selected task indicator"),
     ]
 
     def __init__(self, **config):


Test patch:
Repository: qtile/qtile

Issue:
Can't use asyncio event loop in widgets
I am creating a widget that uses asyncio to run some external command (with `asyncio.create_subprocess_exec`). It doesn't work, and raises the `RuntimeError("Cannot add child handler, the child watcher does not have a loop attached")` exception instead.

If my understanding of the code is correct, calling `set_event_loop` after `new_event_loop` should fix this issue, but I'm not sure whether it will cause other problems.


Discussion:
Do you need stdout or stderr from the program? If not you could just use `qtile.cmd_spawn()`.
You can also get at the underlying eventloop with `qtile._eventloop`, so you can call `qtile._eventloop.subprocess_exec`
I need the stdout in this case, so I can't use `cmd_spawn()`.

Using `qtile._eventloop` explicitly won't help here. `subprocess_exec()` uses `asyncio.get_child_watcher()` internally, which uses the event loop set with `set_event_loop()`.

I just stumbled upon this because I was getting the same error (but completely unrelated to qtile, I don't even know what that is).
I still have no clue about anything related with `asyncio`, but in my case something like this helped (called from the main thread):

    asyncio.get_child_watcher().attach_loop(my_loop)
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

Resolving patch:
diff --git a/libqtile/core/session_manager.py b/libqtile/core/session_manager.py
--- a/libqtile/core/session_manager.py
+++ b/libqtile/core/session_manager.py
@@ -25,6 +25,7 @@ def __init__(
             The state to restart the qtile instance with.
         """
         eventloop = asyncio.new_event_loop()
+        asyncio.set_event_loop(eventloop)
 
         self.qtile = Qtile(kore, config, eventloop, no_spawn=no_spawn, state=state)
 


Test patch:
Repository: qtile/qtile

Issue:
lazy.when
# Issue description

I found this quite oldy [`config.py`](https://gist.github.com/cjbarnes18/4151805) that uses a `when` operation to limit the keybinding to a layout but it throws an exception. I also couldn't find it in the docs, so is it supposed to exist? Is there another similar intended way to limit key bindings to a layout.


```python
from libqtile.lazy import lazy
```
...
```python
    Key([mod], 'Left',
        lazy.layout.left().when('xmonadtall'))
```

# Qtile version

v0.15.0

# Stack traces

```
libqtile xcore.py:_xpoll():L277  Got an exception in poll loop
Traceback (most recent call last):
  File "/share/git/qtile/libqtile/backend/x11/xcore.py", line 246, in _xpoll
    ret = target(event)
  File "/share/git/qtile/libqtile/backend/x11/xcore.py", line 494, in handle_KeyPress
    self.qtile.process_key_event(keysym, event.state & self._valid_mask)
  File "/share/git/qtile/libqtile/core/manager.py", line 342, in process_key_event
    if cmd.check(self):
AttributeError: 'NoneType' object has no attribute 'check'
```

Thanks for any help


Discussion:
Yep, it's still supposed to work as it's still in the code: https://github.com/qtile/qtile/blob/09b7d517312886b7af47c8c1e13bca88f845ccff/libqtile/lazy.py#L72-L74

That being said I don't see any unit test for this which is probably why it doesn't work anymore.



Resolving patch:
diff --git a/libqtile/lazy.py b/libqtile/lazy.py
--- a/libqtile/lazy.py
+++ b/libqtile/lazy.py
@@ -72,6 +72,7 @@ def kwargs(self) -> Dict:
     def when(self, layout=None, when_floating=True):
         self._layout = layout
         self._when_floating = when_floating
+        return self
 
     def check(self, q) -> bool:
         if self._layout is not None:


Test patch:
Repository: qtile/qtile

Issue:
Ampersands need to be escaped in WindowName widget
# Issue description
Ampersands in window names need to be changed in WindowName widget to "&amp;" before being passed to Pango/Cairo

# Qtile version
0.15.1

# Stack traces
Exception: parse_markup() failed for b'Seth Lakeman - King & Country'
2020-04-27 19:12:00,744 ERROR libqtile hook.py:fire():L373 Error in hook focus_change
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/libqtile/hook.py", line 371, in fire
    i(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/libqtile/widget/windowname.py", line 67, in update
    self.text = "%s%s" % (state, w.name if w and w.name else " ")
  File "/usr/lib/python3.8/site-packages/libqtile/widget/base.py", line 323, in text
    self.layout.text = self.formatted_text
  File "/usr/lib/python3.8/site-packages/libqtile/drawer.py", line 70, in text
    attrlist, value, accel_char = pangocffi.parse_markup(value)
  File "/usr/lib/python3.8/site-packages/libqtile/pangocffi.py", line 173, in parse_markup
    raise Exception("parse_markup() failed for %s" % value)
Exception: parse_markup() failed for b'Seth Lakeman - King & Country'

# Configuration
N/A


Discussion:

Resolving patch:
diff --git a/libqtile/widget/windowname.py b/libqtile/widget/windowname.py
--- a/libqtile/widget/windowname.py
+++ b/libqtile/widget/windowname.py
@@ -24,7 +24,7 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-from libqtile import bar, hook
+from libqtile import bar, hook, pangocffi
 from libqtile.widget import base
 
 
@@ -64,5 +64,6 @@ def update(self, *args):
                 state = '_ '
             elif w.floating:
                 state = 'V '
-        self.text = "%s%s" % (state, w.name if w and w.name else " ")
+        unescaped = "%s%s" % (state, w.name if w and w.name else " ")
+        self.text = pangocffi.markup_escape_text(unescaped)
         self.bar.draw()


Test patch: