0

I am exploring Awesome WM and Vicious, and I'd like to create an wibox.widget.imagebox based battery widget using vicious.widgets.bat template.

So here's a problem: how to change image property of the widget.

The icons are set in theme.lua:

local icons_dir = os.getenv("HOME") .. "/.config/awesome/deco/icons/"

...

theme.battery = {}
for i = 0, 10 do
    theme.battery[i] = icons_dir.."bat/b"..(i*10)..".svg"
end

theme.battery_charging = {}
for i = 0, 10 do
    theme.battery_charging[i] = icons_dir.."bat/b"..(i*10).."c.svg"
end

This doesn't work:

mybat = wibox.widget.imagebox()
vicious.register(mybat, vicious.widgets.bat,
                 function (widget, args)
                     if args[1] == "+" then
                         return beautiful.battery_charging[((args[2] + 5) - (args[2] + 5) % 10) / 10]
                     else
                         return beautiful.battery[((args[2] + 5) - (args[2] + 5) % 10) / 10]
                     end
                 end, 30, "BAT0")

Interestingly, if we set mybat as a wibox.widget.textbox widget, it correctly shows the proper path to icon.

Neither works this:

mybat = wibox.widget.imagebox()
vicious.register(mybat, vicious.widgets.bat,
                 function (widget, args)
                     if args[1] == "+" then
                         widget.image = beautiful.battery_charging[((args[2] + 5) - (args[2] + 5) % 10) / 10]
                     else
                         widget.image = beautiful.battery[((args[2] + 5) - (args[2] + 5) % 10) / 10]
                     end
                 end, 30, "BAT0")

mybat simply remains empty.

Does anybody know how to dynamically change imagebox content?

1 Answers1

-1

Sorry about that i rushed it here you go.

 vicious.battery = wibox.widget.imagebox()
 vicious.battery:set_image("battery.png")


 vicious.battery:set_width(50)
 vicious.battery:set_height(50)
 vicious.battery:set_background_color("#000000")
 vicious.battery:set_border_color("#FFFFFF")
 vicious.battery:set_border_width(2)


 vicious.register(vicious.battery, vicious.widgets.bat, "$2", 61, 
 "BAT0")
Speezy
  • 50
  • 4
  • 1
    This uses an entirely different library (_lain_) than the one that was asked about (_vicious_). – Lucas S. Oct 23 '22 at 18:05
  • 1
    The edited version now shows no relation to the question, which is about the image being changed based on the battery level. – Lucas S. Oct 23 '22 at 18:23
  • Thanks. I was surprised that there's the 'imagebox' class has ':set_image()' method, since it's not documented on the awesomewm website. I should have looked the source code – Andrey Voeyko Oct 31 '22 at 13:49