0

I want to create a simple widget which is a progress bar that gets its value set to 1 when we click it with left mouse button.

   local myFirstWidget = wibox.widget {
        {
            value = 0.5,
            color = "#ff0000",
            widget = wibox.widget.progressbar,
            width = 100,
            forced_height = 20,
            shape = gears.shape.rounded_bar,
            border_width = 2,
            border_color = beautiful.border_color,
            ticks = true,
            clip = true,
            margins = {top = 5, bottom = 5},
            paddings = 2
        },
        layout = wibox.layout.fixed.horizontal
    }

    myFirstWidget:connect_signal("button::press",
                                 function(w, _, _, btn) w.value = 1 end)

When I press the bar - nothing really happens. And if I use

w.set_value(1)

then clicking the bar shows an error

attempt to call a nil value (field 'set_value')

How do I make it work?

Sap Green
  • 11
  • 1
  • 3

1 Answers1

0

It turnes out that w is the "parent" widget which contains progressbar widget. So I had to do it this way

myFirstWidget:connect_signal("button::press", function(w)
    local children = w:get_all_children()
    children[1].value = 1;
end)

so basically I retrieve a table of all children widgets and then use [1] to refer to the first widget in the table and after that I assign a value to its property

Sap Green
  • 11
  • 1
  • 3