t-wissmann / barpyrus

A python wrapper for lemonbar
Other
33 stars 7 forks source link

How to change color of HLWM Tags in bar? #16

Closed jsav0 closed 3 years ago

jsav0 commented 3 years ago

The custom color theme function does not seem to affect HLWMTags like it does the other elements.

gold = Theme(bg = '#ee121212', fg = '#ceaf51', padding = (3,3))
# Widget configuration:
bar = lemonbar.Lemonbar(geometry = (x,y,width,height))
bar.widget = W.ListLayout([
    W.RawLabel('%{l}'),
    gold(hlwm.HLWMTags(hc, monitor)),
    W.RawLabel('%{c}'),
    gold(hlwm.HLWMWindowTitle(hc)),
    W.RawLabel('%{r}'),
    gold(W.DateTime('%B %d, %H:%M |')),
])

1

How can the tag colors be changed?

t-wissmann commented 3 years ago

They are hard-wired to use the colors https://github.com/t-wissmann/barpyrus/blob/master/barpyrus/colors.py which you can modify:

import colors
colors.BG1 = 'red'
jsav0 commented 3 years ago

Perfect. thanks

jsav0 commented 3 years ago

They are hard-wired to use the colors https://github.com/t-wissmann/barpyrus/blob/master/barpyrus/colors.py which you can modify:

import colors
colors.BG1 = 'red'

I imagine it needs to be: from barpyrus import colors i'm making the change in my config.py, but that doesn't appear to affect a color change of the tags either. They are still defaulting to the hardcoded colors.

t-wissmann commented 3 years ago

Ah. Due to lack of time, I can't look into it right now. But the following should work and is in fact more flexible:

Define a function in your config.py that renders a tag, e.g. I have:


def simple_tag_renderer(self, painter): # self is a HLWMTagInfo object
    self.activecolor = '#86AB5F'
    if self.empty:
        return
    #painter.ol('#ffffff' if self.focused else None)
    painter.set_flag(painter.underline, True if self.visible else False)
    painter.fg('#a0a0a0' if self.occupied else '#909090')
    if self.urgent:
        painter.ol('#FF7F27')
        painter.fg('#FF7F27')
        painter.set_flag(painter.underline, True)
        painter.bg('#57000F')
    elif self.here:
        painter.fg('#ffffff')
        painter.ol(self.activecolor if self.focused else '#ffffff')
        painter.bg(self.emphbg)
    else:
        painter.ol('#454545')
    painter.space(1)
    painter += self.name
    painter.space(1)
    painter.bg()
    painter.ol()
    painter.set_flag(painter.underline, False)
    painter.space(1)

And in the widget list of the bar, you can then pass it to the HLWMTags widget:

    hlwm.HLWMTags(hc, monitor, tag_renderer = simple_tag_renderer),
jsav0 commented 3 years ago

Thanks for sharing, I'll try that out

jsav0 commented 3 years ago

the solution worked great. Thanks

t-wissmann commented 3 years ago

Thanks for your feedback!