You are not logged in.

#1 2012-04-03 00:16:15

Babkock
Member
Registered: 2012-04-03
Posts: 13

How to update a textbox widget in Awesome?

Hello, everyone. I created a textbox, named "battext", to tell me my current battery percentage. I use the execute_command function to give me the output of a Perl script, which retrieves only the battery percentage from the output of acpi.

function execute_command(command)
   local fh = io.popen(command)
   local str = ""
   for i in fh:lines() do
      str = str .. i
   end
   io.close(fh)
   return str
end

battext = widget({ type = "textbox", name = "battext" })
battext.text = execute_command("/home/babkock/bin/batterypercent")

This is /home/babkock/bin/batterypercent, the Perl script I mentioned:

#!/usr/bin/perl
print '',( `acpi` =~ /(\d+)%/ )[ 0 ] // '??', "%\n";

Now, the problem is, the battery percentage changes, but the textbox stays the same. When I start Awesome, the textbox will say something like "85%", and after a few minutes, the Perl script outputs "80%", so the textbox is wrong. How do I update the textbox? I've read about "signals" and "hooks", but those are tied to events. I just want an endless while loop that changes the textbox to run in the background. How do I go about doing this? Can I use a signal or a hook with a standard boolean logic conditional, so I can just compare the output of the Perl script to the content of the textbox?

Thanks.

Offline

#2 2012-04-03 00:52:26

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

Re: How to update a textbox widget in Awesome?

Your code is executed only once. You need a timer to fire periodically. Read up https://awesome.naquadah.org/wiki/Widge … me#textbox


You need to install an RTFM interface.

Offline

#3 2012-04-03 01:05:16

Babkock
Member
Registered: 2012-04-03
Posts: 13

Re: How to update a textbox widget in Awesome?

Thanks anrxc, that worked smile

Offline

Board footer

Powered by FluxBB