File: progressbar.lua

package info (click to toggle)
awesome-extra 2012061101
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 976 kB
  • ctags: 562
  • sloc: sh: 79; awk: 18; makefile: 11
file content (54 lines) | stat: -rw-r--r-- 1,663 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-----------------------------------
-- Author: Uli Schlachter        --
-- Copyright 2009 Uli Schlachter --
-----------------------------------

local beautiful = require("beautiful")
local awful = {
    widget = require("awful.widget")
}
local margins = awful.widget.layout.margins
local setmetatable = setmetatable

module("obvious.lib.widget.progressbar")

function progressbar(layout)
    local theme = beautiful.get()
    local width = theme.progressbar_width or theme.widget_width or 8
    local color = theme.progressbar_fg_color or theme.widget_fg_color or theme.fg_normal
    local back  = theme.progressbar_bg_color or theme.widget_bg_color or theme.bg_normal
    local border= theme.progressbar_border or theme.widget_border or theme.border_normal

    local widget = awful.widget.progressbar({ layout = layout })
    widget:set_vertical(true)

    widget:set_width(width)
    widget:set_color(color)
    widget:set_background_color(back)
    widget:set_border_color(border)

    return widget
end

function create(data, layout)
    local widget = progressbar(layout)

    widget.update = function(widget)
        -- TODO: We don't support data sources without a fixed upper bound
        local max = widget.data.max or 1
        local val = widget.data:get() or max
        widget:set_value(val / max)
    end

    widget.set_margin = function(widget, margin)
        margins[widget.widget] = margin
        return widget
    end

    widget.data = data

    return widget
end

setmetatable(_M, { __call = function (_, ...) return progressbar(...) end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80