From 9c0b22dc88439954fc899a731e840fd98f25ddf9 Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 25 Sep 2013 09:35:38 +0800 Subject: [PATCH 1/5] create task widget template, based on calendar widget --- widgets/task.lua | 126 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 widgets/task.lua diff --git a/widgets/task.lua b/widgets/task.lua new file mode 100644 index 0000000..31499f1 --- /dev/null +++ b/widgets/task.lua @@ -0,0 +1,126 @@ + +--[[ + + Licensed under GNU General Public License v2 + * (c) 2013, Jan Xie + +--]] + +local icons_dir = require("lain.helpers").icons_dir + +local awful = require("awful") +local beautiful = require("beautiful") +local naughty = require("naughty") + +local io = io +local os = { date = os.date } +local tonumber = tonumber + +local setmetatable = setmetatable + +-- task notification +-- lain.widgets.task +local task = {} +local task_notification = nil + +function task:hide() + if task_notification ~= nil then + naughty.destroy(task_notification) + task_notification = nil + end +end + +function task:show(t_out, inc_offset) + task:hide() + + local offs = inc_offset or 0 + local tims = t_out or 0 + local f, c_text + local today = tonumber(os.date('%d')) + local init_t = '/usr/bin/cal | sed -r -e "s/(^| )( ' + -- let's take font only, font size is set in task table + local font = beautiful.font:sub(beautiful.font:find(""), + beautiful.font:find(" ")) + + if offs == 0 + then -- current month showing, today highlighted + if today >= 10 + then + init_t = '/usr/bin/cal | sed -r -e "s/(^| )(' + end + + task.offset = 0 + task.notify_icon = task.icons .. today .. ".png" + + -- bg and fg inverted to highlight today + f = io.popen( init_t .. today .. + ')($| )/\\1\\2<\\/span><\\/b>\\3/"' ) + + else -- no current month showing, no day to highlight + local month = tonumber(os.date('%m')) + local year = tonumber(os.date('%Y')) + + task.offset = task.offset + offs + month = month + task.offset + + if month > 12 then + month = month % 12 + year = year + 1 + if month <= 0 then + month = 12 + end + elseif month < 1 then + month = month + 12 + year = year - 1 + if month <= 0 then + month = 1 + end + end + + task.notify_icon = nil + + f = io.popen('/usr/bin/cal ' .. month .. ' ' .. year) + end + + + --c_text = "" + --.. f:read() .. "\n\n" + --.. f:read() .. "\n" + --.. f:read("*all"):gsub("\n*$", "") + --.. "" + c_text = "hello tasks!" + f:close() + + task_notification = naughty.notify({ text = c_text, + icon = task.notify_icon, + position = task.position, + fg = task.fg, + bg = task.bg, + timeout = tims }) +end + +function task:attach(widget, args) + local args = args or {} + task.icons = args.icons or icons_dir .. "cal/white/" + task.font_size = tonumber(args.font_size) or 12 + task.fg = args.fg or beautiful.fg_normal or "#FFFFFF" + task.bg = args.bg or beautiful.bg_normal or "#FFFFFF" + task.position = args.position or "top_right" + + task.offset = 0 + task.notify_icon = nil + + widget:connect_signal("mouse::enter", function () task:show() end) + widget:connect_signal("mouse::leave", function () task:hide() end) + widget:buttons(awful.util.table.join( awful.button({ }, 1, function () + task:show(0, -1) end), + awful.button({ }, 3, function () + task:show(0, 1) end) )) +end + +return setmetatable(task, { __call = function(_, ...) return create(...) end }) From 1a31a15405c5f125f526f6d1554ea12b55940018 Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 25 Sep 2013 10:03:11 +0800 Subject: [PATCH 2/5] clean a little bit --- widgets/task.lua | 70 +++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 49 deletions(-) diff --git a/widgets/task.lua b/widgets/task.lua index 31499f1..cf84cbc 100644 --- a/widgets/task.lua +++ b/widgets/task.lua @@ -30,10 +30,9 @@ function task:hide() end end -function task:show(t_out, inc_offset) +function task:show(t_out) task:hide() - local offs = inc_offset or 0 local tims = t_out or 0 local f, c_text local today = tonumber(os.date('%d')) @@ -42,50 +41,23 @@ function task:show(t_out, inc_offset) local font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")) - if offs == 0 - then -- current month showing, today highlighted - if today >= 10 - then - init_t = '/usr/bin/cal | sed -r -e "s/(^| )(' - end - - task.offset = 0 - task.notify_icon = task.icons .. today .. ".png" - - -- bg and fg inverted to highlight today - f = io.popen( init_t .. today .. - ')($| )/\\1\\2<\\/span><\\/b>\\3/"' ) - - else -- no current month showing, no day to highlight - local month = tonumber(os.date('%m')) - local year = tonumber(os.date('%Y')) - - task.offset = task.offset + offs - month = month + task.offset - - if month > 12 then - month = month % 12 - year = year + 1 - if month <= 0 then - month = 12 - end - elseif month < 1 then - month = month + 12 - year = year - 1 - if month <= 0 then - month = 1 - end - end - - task.notify_icon = nil - - f = io.popen('/usr/bin/cal ' .. month .. ' ' .. year) + if today >= 10 + then + init_t = '/usr/bin/cal | sed -r -e "s/(^| )(' end + task.offset = 0 + --task.notify_icon = task.icons .. today .. ".png" + + -- bg and fg inverted to highlight today + --f = io.popen( init_t .. today .. + --')($| )/\\1\\2<\\/span><\\/b>\\3/"' ) + + --c_text = "" @@ -94,13 +66,13 @@ function task:show(t_out, inc_offset) --.. f:read("*all"):gsub("\n*$", "") --.. "" c_text = "hello tasks!" - f:close() + --f:close() task_notification = naughty.notify({ text = c_text, - icon = task.notify_icon, - position = task.position, - fg = task.fg, - bg = task.bg, + --icon = task.notify_icon, + --position = task.position, + --fg = task.fg, + --bg = task.bg, timeout = tims }) end From 37b61468dd884e5bc8a4bcee51f63cfbab425544 Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 25 Sep 2013 10:24:54 +0800 Subject: [PATCH 3/5] show next tasks --- widgets/task.lua | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/widgets/task.lua b/widgets/task.lua index cf84cbc..b313e8d 100644 --- a/widgets/task.lua +++ b/widgets/task.lua @@ -13,7 +13,6 @@ local beautiful = require("beautiful") local naughty = require("naughty") local io = io -local os = { date = os.date } local tonumber = tonumber local setmetatable = setmetatable @@ -35,38 +34,19 @@ function task:show(t_out) local tims = t_out or 0 local f, c_text - local today = tonumber(os.date('%d')) - local init_t = '/usr/bin/cal | sed -r -e "s/(^| )( ' -- let's take font only, font size is set in task table local font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")) - if today >= 10 - then - init_t = '/usr/bin/cal | sed -r -e "s/(^| )(' - end - task.offset = 0 --task.notify_icon = task.icons .. today .. ".png" - -- bg and fg inverted to highlight today - --f = io.popen( init_t .. today .. - --')($| )/\\1\\2<\\/span><\\/b>\\3/"' ) - - - - --c_text = "" - --.. f:read() .. "\n\n" - --.. f:read() .. "\n" - --.. f:read("*all"):gsub("\n*$", "") - --.. "" - c_text = "hello tasks!" - --f:close() + f = io.popen('task') + c_text = "[Next Tasks]\n" + .. f:read("*all") .. "\n" + .. "" + f:close() task_notification = naughty.notify({ text = c_text, --icon = task.notify_icon, From f143ba3231276a21911dd49450033a3f2d182ea3 Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 25 Sep 2013 10:51:01 +0800 Subject: [PATCH 4/5] add icon for task widget --- icons/taskwarrior.png | Bin 0 -> 1280 bytes widgets/task.lua | 18 ++++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 icons/taskwarrior.png diff --git a/icons/taskwarrior.png b/icons/taskwarrior.png new file mode 100644 index 0000000000000000000000000000000000000000..171af60260bcba14cafa18f1530935841d6f38b4 GIT binary patch literal 1280 zcmV+b1^@bqP)WFU8GbZ8()Nlj2>E@cM*00d-7L_t(I%XL&;XcSiz z{?5HSJIN&3S=Oz)M7Bw65K{%U4~A|^9$L~C3|OS-Tg`(%eJCg<_$GmZ(ozdrXi<{~ zp;%1BK&VY(=;D5Q!bZVbY1sWB9R!Zs;c@c8jUUkz{QIf z(b3TX03ZP9?d`>Z0|x*Au~_Vw<2avIRaHfp*>GJKm6eqyGb5kRt3n83X3aFsIU&UF z+qZB31po#H2C!$(9?+RHXK?iBQ2;g9i`Ng9i_e8HSMwhr=J0iD7wp`L~ggksS>U4SIcj zy*@rZ-keUSuP`&18LFzjQ(Ig6xoz8<+uPfB5fLaBiv=9V>DP6=LDRI2%nTwzI-S1T z)YSAL-h`N#m>BZ={U4VKr_<@X%pBUXWy?mfxVX4W)3mVH>s?>|PBSwz-{Sw_CK8G7 z%VRZ7+bo25e&^1eLn0Uqe(AbyR!Ui2o^|r%$-mzsh)5*z*fh=6yQ-@GbUHl~3WW~Q zZECkHD-a9@FElnbIxC5Cc6RnxpU+n#gm`U~R8@`Gww(|} z#BXbD+qP{T$z<|J0K#=$Yi@3?tGT)PE7x_a*Tyn45fKZ^vfOMoOXVaHA(2Q-u84LK zk;BaKojZ5_1OSF%Oso|&P4kJAa)U5Ua}$>?8naky#ba!_r*R-^H&SWwv$8jE)xid6PdpDIz^$6E>Z`!u~ z+%(NuA_6l*)3myW4ZUYb{=kaE;`#IEKbW4Lj_JC7SV}1Xz_Ki(P$(2$zI=Hc z0GB>POifLVEG#Tc)YaAPRTRZnwgBMudf~b*Gc!pk%ilWl^y$;SU@%D6u3h_D(==ON zy?Pb>{r$YKu+Z1u-o7`R%@!QTnfG`+>*XtyS|%wagb=W8JD161?q@QY*_xV~^ySN! zzd3Q@gn8q}jaTbyaBvX2ckf0|Pfx|xty}l{{r>NY#p0tvq3}Y}wA$+G>M#H{3}ZHz z%Pm$`R&F4o(DL%~@v*V7>z$pQ_R!D}+S=McZ<%TD=;-M2Kp@b;%swH+la<}sNJR6= qWb#5Z8vPkS@$A{NICA93YT|!n4[Next Tasks]\n" + .. task.font_size+2 .. "'>Tasks next\n" + .. "" .. f:read("*all") .. "\n" .. "" f:close() task_notification = naughty.notify({ text = c_text, - --icon = task.notify_icon, - --position = task.position, - --fg = task.fg, - --bg = task.bg, + icon = task.notify_icon, + position = task.position, + fg = task.fg, + bg = task.bg, timeout = tims }) end function task:attach(widget, args) local args = args or {} - task.icons = args.icons or icons_dir .. "cal/white/" task.font_size = tonumber(args.font_size) or 12 task.fg = args.fg or beautiful.fg_normal or "#FFFFFF" task.bg = args.bg or beautiful.bg_normal or "#FFFFFF" task.position = args.position or "top_right" - task.offset = 0 - task.notify_icon = nil + task.notify_icon = icons_dir .. "taskwarrior.png" widget:connect_signal("mouse::enter", function () task:show() end) widget:connect_signal("mouse::leave", function () task:hide() end) From a45d345b60cd0268def1dde24d7618b6ab1b8070 Mon Sep 17 00:00:00 2001 From: Jan Xie Date: Wed, 25 Sep 2013 11:20:13 +0800 Subject: [PATCH 5/5] add prompt function for task widget --- widgets/task.lua | 66 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/widgets/task.lua b/widgets/task.lua index fdf439a..f2b49f4 100644 --- a/widgets/task.lua +++ b/widgets/task.lua @@ -29,20 +29,15 @@ function task:hide() end end -function task:show(t_out) +function task:show() task:hide() - local tims = t_out or 0 local f, c_text - -- let's take font only, font size is set in task table - local font = beautiful.font:sub(beautiful.font:find(""), - beautiful.font:find(" ")) - f = io.popen('task') - c_text = "Tasks next\n" - .. "" .. f:read("*all") .. "\n" .. "" @@ -53,15 +48,68 @@ function task:show(t_out) position = task.position, fg = task.fg, bg = task.bg, - timeout = tims }) + timeout = task.timeout }) +end + +function task:add(...) + local f = io.popen("task add " .. ...) + c_text = "" + .. f:read("*all") .. "\n" + .. "" + + naughty.notify({ text = c_text, + icon = task.notify_icon, + position = task.position, + fg = task.fg, + bg = task.bg, + timeout = task.timeout}) +end + +function task:prompt_add() + awful.prompt.run( { prompt = "Add task: " }, + mypromptbox[mouse.screen].widget, + function (...) + task:add(...) + end, + nil, + awful.util.getdir("cache") .. "/history_task_add") +end + +function task:execute(...) + local f = io.popen("task " .. ...) + c_text = "" + .. f:read("*all") .. "\n" + .. "" + + naughty.notify({ text = c_text, + icon = task.notify_icon, + position = task.position, + fg = task.fg, + bg = task.bg, + timeout = task.timeout}) +end + +function task:prompt() + awful.prompt.run( { prompt = "Task: " }, + mypromptbox[mouse.screen].widget, + function (...) + task:execute(...) + end, + nil, + awful.util.getdir("cache") .. "/history_task") end function task:attach(widget, args) local args = args or {} task.font_size = tonumber(args.font_size) or 12 + task.font = beautiful.font:sub(beautiful.font:find(""), + beautiful.font:find(" ")) task.fg = args.fg or beautiful.fg_normal or "#FFFFFF" task.bg = args.bg or beautiful.bg_normal or "#FFFFFF" task.position = args.position or "top_right" + task.timeout = args.timeout or 7 task.notify_icon = icons_dir .. "taskwarrior.png"