-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Attached is a New And Improved(tm) version of the last patch. Compare it yourself, you'll see that the new version is better.
Uli - -- "Do you know that books smell like nutmeg or some spice from a foreign land?" -- Faber in Fahrenheit 451 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iQEcBAEBCAAGBQJKfn3hAAoJECLkKOvLj8sG5oEH/0xAEW4hqns6wS9GK7rNsa+F T77YLUFyaulhgnyefUTNrQssIXeniSLQLHPrO8KTeImKKINTs/7t2DFVC5PV9zWI uekyAgHsvFc7jgKkqZ4QZ+Ai8oUuioxT3nAqW78yNOPR4fQq6v86IVm10uPUuGe2 nM1jOcSTbzgRK5xMN7lJ717H8zTTkX7843wVZ1z92HRbj2fABRrNvYPWtvJ4xQJg zoPSpBAcm1JjIG/igE9Xc9PbCGnA6F0hlJlCxr04JLyIJh3sDi28i8j1yr+n3BmV XjcD06glxB0il3hA786fkXS4z8Nn0nrseHxdPiVhLgvb+8QUWwFciLmseJbEOdM= =5wS/ -----END PGP SIGNATURE-----
>From 4917825aa9daa30f11345cee8fd73b64c514b21c Mon Sep 17 00:00:00 2001 From: Uli Schlachter <psyc...@znc.in> Date: Sat, 8 Aug 2009 19:23:29 +0200 Subject: [PATCH 10/10] Convert the wlan module to use a lib.widget.from_data_source() The default look of this widget isn't touched, but it now gets this default via lib.widget.textbox. The usage of this widget slightly changed: Instead of obvious.wlan.set_device("bla") you now do obvious.wlan("bla") which already returns the widget for your widget list. This also removes the now-obsolete wlan.bar. Signed-off-by: Uli Schlachter <psyc...@znc.in> --- init.lua | 1 - wlan/bar.lua | 35 ----------------------------------- wlan/init.lua | 51 ++++++++++++++++++++++++++------------------------- 3 files changed, 26 insertions(+), 61 deletions(-) delete mode 100644 wlan/bar.lua diff --git a/init.lua b/init.lua index 1d87e27..9d13a61 100644 --- a/init.lua +++ b/init.lua @@ -15,6 +15,5 @@ require("obvious.net") require("obvious.popup_run_prompt") require("obvious.volume_alsa") require("obvious.wlan") -require("obvious.wlan.bar") module("obvious") diff --git a/wlan/bar.lua b/wlan/bar.lua deleted file mode 100644 index 71b265c..0000000 --- a/wlan/bar.lua +++ /dev/null @@ -1,35 +0,0 @@ ------------------------------------ --- Author: Uli Schlachter -- --- Copyright 2009 Uli Schlachter -- ------------------------------------ - -local setmetatable = setmetatable -local lib = require("obvious.lib") - -module("obvious.wlan.bar") - -device = "wlan0" -widget = false - -local function update() - local link = lib.wlan(device) - widget:set_value(link / 100) -end - -function set_device(dev) - device = dev - if widget then update() end -end - -local function get(layout) - if not widget then - -- We must wait until now or beautiful isn't initialized yet - widget = lib.widgets.progressbar(layout) - update() - lib.hooks.timer.register(10, 60, update) - lib.hooks.timer.start(update) - end - return widget -end - -setmetatable(_M, { __call = function (_, ...) return get(...) end }) diff --git a/wlan/init.lua b/wlan/init.lua index 8dd4420..1d6f793 100644 --- a/wlan/init.lua +++ b/wlan/init.lua @@ -3,45 +3,46 @@ -- Copyright 2009 Gregor Best -- -------------------------------- -local setmetatable = setmetatable - local string = { format = string.format } -local capi = { - widget = widget +local setmetatable = setmetatable +local lib = { + widget = require("obvious.lib.widget"), + util = require("obvious.lib.util"), + wlan = require("obvious.lib.wlan") } -local awful = require("awful") -local lib = require("obvious.lib") - module("obvious.wlan") -widget = capi.widget({ - type = "textbox", - name = "tb_wlan", - align = "right" -}) -device = "wlan0" - -local function update() - local link = lib.wlan(device) - +local function format(link) local color = "#009000" if link < 50 and link > 10 then color = "#909000" elseif link <= 10 then color = "#900000" end - widget.text = lib.util.colour(color,"â¢") .. string.format(" %03d%%", link) + return lib.util.colour(color,"â¢") .. string.format(" %03d%%", link) end -update() -lib.hooks.timer.register(10, 60, update) -lib.hooks.timer.start(update) -function set_device(dev) - device = dev - update() +local function get_data_source(device) + local device = device or "wlan0" + local data = {} + + data.device = device + data.max = 100 + data.get = function (obj) + return lib.wlan(obj.device) + end + + local ret = lib.widget.from_data_source(data) + -- Due to historic reasons, this widget defaults to a textbox with + -- a "special" format. + ret:set_type("textbox") + ret:set_format(format) + + return ret end -setmetatable(_M, { __call = function () return widget end }) +setmetatable(_M, { __call = function (_, ...) return get_data_source(...) end }) +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:encoding=utf-8:textwidth=80 -- 1.6.3.3