t-wissmann / barpyrus

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

Cilckable areas on conky items #8

Closed cnotis82 closed 2 years ago

cnotis82 commented 4 years ago

It is a great bar for herbstluftwm. I would like to ask you if it is possible to add clickable areas on conky items.

t-wissmann commented 2 years ago

Sorry for missing this question for such a long time. I first thought that it is not possible, but I think I have an idea how it could be accomplished.

t-wissmann commented 2 years ago

I've now added click-support to ConkyGenerator, you can see an example in my config.py. Note that it only works, if you directly pass ConkyGenerator to the ConkyWidget (without calling str() on ConkyGenerator).

Example-snippet:

from barpyrus import conky

# [...]
def spawn_htop(button):
    subprocess.call(['urxvt', '-e', 'htop'])

cg = conky.ConkyGenerator(lemonbar.textpainter())
with cg.clickable([1], spawn_htop):
    with cg.temp_fg('#B7CE42'):
        cg.symbol(0xe026);
    cg += ' '; cg.var('cpu'); cg += '% '
    with cg.temp_fg('#6F99B4'):
        cg.symbol(0xe021);
    cg += ' '; cg.var('memperc'); cg += '% '

# [...]

bar = lemonbar.Lemonbar(geometry=(10,10,800,20))
bar.widget = W.ListLayout([
        W.RawLabel('%{l}'),
        conky.ConkyWidget(cg),
])