elParaguayo/qtile-extras

Decorations not applying to custom widgets

Closed this issue · 2 comments

a-loca commented

I have a simple custom script that prints out the percentage of memory currently being used. Technically Qtile's Memory widget works just fine, but I wanted the percentage to be calculated as Active/Total, like htop or bottom do.

Below is the script:

class MemoryPercentage(base.ThreadPoolText):
    defaults = [
        (
            "format",
            # Default value to be returned
            "{Percentage:.1f}%",
            "Formatting for field names.",
        ),
        ("update_interval", 1.0, "Update interval for the Memory"),
    ]

    def __init__(self, **config):
        super().__init__("", **config)
        self.add_defaults(MemoryPercentage.defaults)

    def poll(self):
        mem_info = psutil.virtual_memory()
        val = {}
        val["Percentage"] = mem_info.active / mem_info.total * 100
        return self.format.format(**val)

The code is identical to the default script for the Memory widget, I just added the Percentage field.

I have a RectDecoration to get the effect with darker background and rounded edges, and it works correctly with the Memory widget and all the other default Qtile widgets. However, it does not work with custom scripts.

Below is the code for the decoration:

decor = {
    "decorations": [
        RectDecoration(
            colour=colors[14], radius=15, filled=True, padding_y=10, group=True
        ),
    ]
}

Then I add my widget to the bar:

# CPU widget,
MemoryPercentage(
        **decor,
        fmt="{} ",
        mouse_callbacks={"Button1": lambda: qtile.cmd_spawn("alacritty -e btm")},
),
# Spacer, Volume widget

This is what is printed in the bar:
image

RectDecorations should also include MemoryPercentage and then close itself, rather than end abruptly.

This happens to me with all the other custom widgets I have written, such as one for a "Do Not Disturb" button or another one for music play and pause buttons.
I don't know if this is actually a qtile-extras problem or something I am doing wrong, I apologize if this is the case. I can't figure out where the issue is coming from, especially in this case where the custom script was written identically to how it is done in qtile.

a-loca commented

I'm dumb, sorry about that. Works perfectly. Should have read the documentation more attentively.