Blinking text

From awesome
Jump to: navigation, search

First, you will need this function:

blinkers = {}
function blinking(tb,iv)
    if (tb==nil) then 
        return
    end
    local fiv = iv or 1
    if blinkers[tb] then
        if blinkers[tb].timer.started then
            blinkers[tb].timer:stop()
        else
            blinkers[tb].timer:start()
        end
    else
        if (tb.text == nil) then
            return
        end
        blinkers[tb]= {}
        blinkers[tb].timer = timer({timeout=fiv})
        blinkers[tb].text = tb.text
        blinkers[tb].empty = 0

        blinkers[tb].timer:add_signal("timeout", function ()
            if (blinkers[tb].empty==1) then
                tb.text = blinkers[tb].text
                blinkers[tb].empty=0
            else
                blinkers[tb].empty=1
                tb.text = ""
            end
        end)

        blinkers[tb].timer:start()

    end
end

After this you can use blinking(any_textbox_widget,blinking_interval_in_seconds). The call of blinking function toggles the blinking of text.

I'm using blinking when I've any "critical" situation (e.g. battery charge or free space on a partition is very low, etc.).

Personal tools