dylanaraps / pywal

🎨 Generate and change color-schemes on the fly.
MIT License
8.34k stars 325 forks source link

How to use pywal with qtile? #632

Closed hamensman closed 2 years ago

hamensman commented 3 years ago

I can see the bit for code provided for qtille (https://github.com/dylanaraps/pywal/wiki/Customization#qtile) but I'm not really sure how to integrate it with my config.

Right now, I use the pywal functionality in Luke Smith's setbg script to change the colour of my terminal emulator (https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/setbg). This script changes the wallpaper and then uses pywal on the new wallpaper.

Does the qtile customisation code which pywal's wiki provids change both the terminal and bar colour? I'm not really sure how to add it to my config: haman_config.txt (rename to config.py accordingly)

diego-rapoport commented 2 years ago

First you just copy exactly how the code shows. That will make a variable called colors, which is a list of all colors provided by pywal. An object inside a list you can call by using square brackets like the example: colors[0], which is the first color of the list. Then you just substitute the colors you whish where there's color to add like the background variable of the bar. So you would set something like background=color[2], or a list of colors if you want some gradient effect: background=[color[0], color[1]].

For any other setting that accepts colors you could do that way.

hamensman commented 2 years ago

I tried rewriting init_colors() (in my config) to be identical to the code provided. This was just to try keeping consistent with the fact that in my config, colours, widgets, the bar, etc. are written as functions.

# my username is just 'user'
colors = []
cache='/home/user/.cache/wal/colors'
def init_colors(cache):
    with open(cache, 'r') as file:
        for i in range(8):
            colors.append(file.readline().strip())
    colors.append('#ffffff')
    lazy.reload()
init_colors(cache)

Would I need to rewrite how I'm declaring the widgets, bar, etc. if that is indeed a problem?

I've also just tried removing the init_colors() functions (and the colors = init_colors() bit from my config) and just copying that code verbatim. That too hasn't worked.

diego-rapoport commented 2 years ago

Can you show me how is your config set? At least one widget or bar and how you tried to put the colors on. You need init_colors(cache) because if you don't call the function you'll just have an empty colors variable.

hamensman commented 2 years ago

I uploaded my config in my original post/comment.

diego-rapoport commented 2 years ago

Sorry, forgot to check. But it seems you already are using the colors in the proper way on your widgets. Did you fully rewrite your previous init_colors()? And when you say it didn't work, you're saying the colors weren't what you expected, no colors at all ou something different?

Just make sure you're not rewriting the colors variable elsewhere.

hamensman commented 2 years ago

This config is untouched. So this is without adding any pywal code.

And, I mean that when I save the config try to restart qtile, it doesn't restart because there is a config error. So if I were then to reboot, the default config would show up instead (again, because of config error).

diego-rapoport commented 2 years ago

Look at $HOME/.local/share/qtile/qtile.log to see what is accusing as an error.

hamensman commented 2 years ago

This (qtile.log) is what I get if i rewrite init_colors() from

def init_colors():
    return [["#2E3440", "#2E3440"], # color 0
            ["#2E3440", "#2E3440"], # color 1
            ["#c0c5ce", "#c0c5ce"], # color 2
            ["#fba922", "#fba922"], # color 3
            ["#3384d0", "#3384d0"], # color 4
            ["#f3f4f5", "#f3f4f5"], # color 5
            ["#cd1f3f", "#cd1f3f"], # color 6
            ["#62FF00", "#62FF00"], # color 7
            ["#6790eb", "#6790eb"], # color 8
            ["#a9a9a9", "#a9a9a9"]] # color 9

to

colors = []
cache='/home/user/.cache/wal/colors'
def init_colors(cache):
    with open(cache, 'r') as file:
        for i in range(8):
            colors.append(file.readline().strip())
    colors.append('#ffffff')
    lazy.reload()
init_colors(cache)
diego-rapoport commented 2 years ago

It's very odd because here is saying you're missing the argument cache, which you are providing when you call the function. Are you also doing something like colors = init_colors() somewhere in your code or even calling the function like init_colors() without any arguments? Here is saying the line with that problem is 231. If you're doing, cut that line off, try again e send me your log again.

hamensman commented 2 years ago

Are you also doing something like colors = init_colors() somewhere

I indeed did that exactly.

Here's with that taken off: qtile.log

diego-rapoport commented 2 years ago

All right, now everything seems to be working. The problem now is that you're trying to use an index that's not available. Remember I told you that color would go from 0 to 8? You have set active = colors[9] in line 243 but that index does not exist. Try to checkout your config for any other inconsistence like that and keep colors[n] where n is between 0 and 8.

hamensman commented 2 years ago

Ahhhhh. Yep. That solved it. Thanks diego-rapoport.

Now with that fixed, I'm just wondering if, say, colour changes of the bar can be shown without having to restart qtile?

diego-rapoport commented 2 years ago

Do you mean a background or pywal change of some sort and then suddenly the colors change either? If that's the case, you'll need to look for updating qtile without restart if that's even possible. Possibly some last versions of it could make it work, but I don't know for sure because I don't use it that way. Other way around could be making a qtile hook. That would make the restart automatically triggered when you have some sort of change.

hamensman commented 2 years ago

I'll look into that. Since the original issue has been solved though, I shall close it here.

Highly appreciate your patience.