You are not logged in.

#1 2012-04-27 19:02:36

ibrunton
Member
From: Canada
Registered: 2011-05-05
Posts: 270

awesome wm: Accessing returned data from widgets

I have a widget that tells me the number of unread email messages I have.  I would like to be able to click on the widget and get a popup showing the senders and subjects of those emails.  If the widget returns something like this:

local messages = {
   count = 2,
   msgs = {
      { sender = 'John Doe', subject = 'Hello, World' },
      { sender = 'Plain Jane', subject = 'Goodnight, Gracie' }
   }
}

to something like this:

emailwidget = widget ({ type = "textbox" })
vicious.register (emailwidget, vicious.widgets.my_custom_email_widget, "emails: ${count}")

is it possible to then access the table "msgs" with further code? For example, with something like this, from the awesome wiki:

mytextbox:buttons(awful.util.table.join(
   awful.button({ }, 1, function () naughty.notify ({title="You have 2 messages", text="..." end)
 ))

I'm guessing I could make "messages" global rather than local, but that seems inelegant and probably bad programming practice to boot.

Any ideas?

Thanks

Offline

#2 2012-04-28 20:08:11

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 835
Website

Re: awesome wm: Accessing returned data from widgets

Hello,
yes you can make 'messages' global for one solution.

> vicious.register (emailwidget, vicious.widgets.my_custom_email_widget,

Btw you don't necesarily have to make a real module to make use of vicious helpers. You can register a
function from your rc.lua as a widget type.

> "emails: ${count}")

And here is another solution. Make a format function which will populate your object at the same time it
updates text of your widget. Edit: see vicious README on 'format functions'.

Speaking of objects you should look into awful tooltips, which are real tooltips attached to objects unlike the
naughty object you are trying to create now. Naughty would be more useful when you want to spawn a notification
each time a new message arrives, which also makes sense to do from a format function.

Last edited by anrxc (2012-04-28 20:08:36)


You need to install an RTFM interface.

Offline

#3 2012-04-28 22:18:40

ibrunton
Member
From: Canada
Registered: 2011-05-05
Posts: 270

Re: awesome wm: Accessing returned data from widgets

anrxc wrote:

Hello,
yes you can make 'messages' global for one solution.

> vicious.register (emailwidget, vicious.widgets.my_custom_email_widget,

Btw you don't necesarily have to make a real module to make use of vicious helpers. You can register a
function from your rc.lua as a widget type.

> "emails: ${count}")

And here is another solution. Make a format function which will populate your object at the same time it
updates text of your widget. Edit: see vicious README on 'format functions'.

Speaking of objects you should look into awful tooltips, which are real tooltips attached to objects unlike the
naughty object you are trying to create now. Naughty would be more useful when you want to spawn a notification
each time a new message arrives, which also makes sense to do from a format function.

Thanks for the suggestions.  I've been trying to implement the tooltip, having pretty much copied the code from here, but I keep getting this error message: "/usr/share/awesome/lib/awful/tooltip.lua:127: attempt to concatenate local 'text' (a nil value)". As near as I can determine, nothing is getting passed to the tooltip.

emailwidget = widget ({type = "textbox"})
inbox = {}
tt = awful.tooltip ({ objects = {emailwidget},
   timer_function = function ()
      return inbox[1] -- just for simplicity's sake, to get started
   end
})

vicious.register (emailwidget, vicious.widgets.custom_email_widget,
   function ()
      -- code here to update text of widget
      inbox:insert (args["{subject}"]) --again, just 1 to make it simple at this stage
   end, 300)

Somewhere between that inbox:insert... line and the tooltip library, the data is getting lost. (I've also tried inbox.insert, and I've also tried passing a hard-coded string, with the same result.)

EDIT:  Oops, my bad. In that "--code here to update text of widget" I forgot I had a "return" statement, so it was never getting to the insert statement.

Last edited by ibrunton (2012-04-29 12:10:20)

Offline

Board footer

Powered by FluxBB