pbatt - Real GTK2 Battery Monitor

Stuff that has yet to be sorted into a category.
Message
Author
brad_chuck
Posts: 286
Joined: Tue 16 Aug 2005, 03:47
Location: Appalachian Mountains

pbatt - Real GTK2 Battery Monitor

#1 Post by brad_chuck »

I wrote "batmon" a long time ago. Well this is what I was trying to do with "batmon"

Pbatt is a 6k battery monitoring tray icon.

This is not complete. I have been working on it for some time and thought it would be good to let others see it.

Pbatt uses the GTK2 tray icon. It sends commands to a shell script (bevent) every 2 seconds.

The idea is that bevent is YOUR program. Pbatt is like a framework for your battery script (bevent). Basically you get to decide what you would like it to do. What the tool tip is... What icons to show and when... What to do when you click the icon...

Or you can just leave it alone.

Below is a list of the functions that the bevent script should provide. (pevent does not have to be a shell script by the way)

bevent -i -> Returns an icon name ie "/root/my-icon.xpm"
bevent -t -> Returns the tool tip for the icon
bevent -l -> Handles the left mouse click on icon
bevent -r -> Handles the right mouse click on icon

Please post bugs or comments.


This is a good framework for other apps along the same lines. You could use the same program to monitor other things. Disk space... Wifi connection... really anything that you can get data on with a shell script (quite a few things).

I know there will be bugs with multiple batteries. I have not worked this part out yet. I only have one. Will need some help.

If you don't use the dotpet. Copy both bevent and pbatt somewhere in your path and run pbatt.
Attachments
pbatt-0.0.1.tar.gz
(16.82 KiB) Downloaded 740 times
pbatt-0.0.1.pet
(4.62 KiB) Downloaded 1118 times
pbatt.png
(11.19 KiB) Downloaded 2900 times

User avatar
Tid
Posts: 16
Joined: Tue 09 Dec 2008, 21:05
Location: Canton, OH USA

#2 Post by Tid »

I am very new to Linux and I am running Boxpup 4.1.1 and realized there was no battery monitor notification on the desktop anywhere. I run puppy on a Dell 600m and need something showing my battery. I really don't like how asapm looks and have been trying to find something like your design however I don't know how to get it. Like I said, I am new to Linux and apologize for my ignorance. Will you please provide me some steps to get this app to work?

Thanks so much!

brad_chuck
Posts: 286
Joined: Tue 16 Aug 2005, 03:47
Location: Appalachian Mountains

#3 Post by brad_chuck »

Click on the Pbatt-0.0.1.pet file above. When asked click on the "Open with petget" option.

Then click Install.

That's it.

iscraigh
Posts: 276
Joined: Sun 03 Sep 2006, 05:50

#4 Post by iscraigh »

I have included this in my soon to be released aspire one remaster.

Thanks very much

Craig

magerlab
Posts: 739
Joined: Sun 08 Jul 2007, 20:08

#5 Post by magerlab »

is it possible to use this anyhow for keyboard layout indicator?
if a script reads data from xorg.conf( there's a line for keyboard layouts) and shows the current layout in the tray

i use now asapm -withdrawn for battery monitoring in boxpup
but i'll test bevent also

brad_chuck
Posts: 286
Joined: Tue 16 Aug 2005, 03:47
Location: Appalachian Mountains

#6 Post by brad_chuck »

Yes you can monitor anything you like. All the GTK program does is ask bevent what to display every 2 seconds. So for right now open up /usr/local/bin/bevent and edit it.

I am planning on making this easier by letting you pass the name of the script file to Pbatt. Will change name as well to avoid confusion.

So for example you would type

Ptrayicon --script="keboardevent" --time="2"

Then keyboardevent would be a shell script that monitors the keyboard. --time would be how often it should update things.

check back later....

Don't like aspm for 2 reasons;

1. Looks bad / No tooltip.
2. Not flexible enough (I like to tinker)

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#7 Post by HairyWill »

Nice.
I looked at this type of solution for the volume control. The problem in that instance was the response time. If you are twiddling a volume knob you expect the visual feedback immediately and I didn't want to call a shell script every 100 milliseconds to update the icon. In the case of background monitoring this reponse time is much less critical.

I'm not sure how expensive it is to reload the icon every cycle, you might consider storing the last icon name and then comparing with the new one before deciding whether to load it.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
Tid
Posts: 16
Joined: Tue 09 Dec 2008, 21:05
Location: Canton, OH USA

#8 Post by Tid »

Hey, thanks for the info. I opened the pbatt-0.0.1.pet with petget and installed the pbatt successfully. The system automatically placed a pbatt file in the startup and when I boot from my flash drive I get the "pluged in" icon in the tool bar, however when I unplug my charger I receive a message that says:

Battery Charge is at %
Switch to AC power NOW!

And has an ok button. No matter how many times I hit the ok, the message keeps popping up and I don't get the blue battery icon. I have to plug the computer back in to get rid of the message. Do you guys have any idea what I did wrong?

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#9 Post by HairyWill »

what do you get for the following commands

Code: Select all

ls /proc/acpi/battery
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/battery/BAT1/state
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
Tid
Posts: 16
Joined: Tue 09 Dec 2008, 21:05
Location: Canton, OH USA

#10 Post by Tid »

BATO BAT1

present: yes
capacity state: ok
charging state: charging
present rate: 8774mw

present: no

also, when I unplug the laptop and run cat /proc/acpi/battery/BAT0/state I get:

present: yes
capacity state: ok
charging state: discharging
present rate: 16608mw
remaining capacity: 53000mwh
present voltage: 12312mv

brad_chuck
Posts: 286
Joined: Tue 16 Aug 2005, 03:47
Location: Appalachian Mountains

#11 Post by brad_chuck »

Replace line 34 in /usr/local/bin/bevent with;

Code: Select all

for a in BAT0; do
That should "fix" your system. I will have to update the code to look for this..

Thanks for finding the bug.

User avatar
Tid
Posts: 16
Joined: Tue 09 Dec 2008, 21:05
Location: Canton, OH USA

#12 Post by Tid »

Awesome, thanks for the insight!! Works well.

User avatar
ttuuxxx
Posts: 11171
Joined: Sat 05 May 2007, 10:00
Location: Ontario Canada,Sydney Australia
Contact:

#13 Post by ttuuxxx »

Hi I don't use a laptop but I came across some GPL icons you might want to use?
http://www.e17-stuff.org/content/show.p ... tent=73935
ttuuxxx
http://audio.online-convert.com/ <-- excellent site
http://samples.mplayerhq.hu/A-codecs/ <-- Codec Test Files
http://html5games.com/ <-- excellent HTML5 games :)

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#14 Post by Dougal »

I'm not really fond of these apps that use scripts to get info...
In any case, I updated the script so it only does what is needed for the option it is run with.
I'll probably add support for APM andacpi-in-/sys today, too.
Last edited by Dougal on Sun 12 Apr 2009, 09:26, edited 1 time in total.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
ttuuxxx
Posts: 11171
Joined: Sat 05 May 2007, 10:00
Location: Ontario Canada,Sydney Australia
Contact:

#15 Post by ttuuxxx »

Hi guys I looked at the scrip and it looks like your only using 3 icons, full, half-full and empty shouldn't you have 1 more icon before empty, like 1/4 or 25% left, Its a bit of a stretch to go from half to straight empty, would most people think well its ok I have 50% left and 2 seconds later its emptied.
Or maybe a popup warning "Danger will Robertson you have on 10% left to your battery" The robot voice would be cool. LOL
ttuuxxx
Or maybe just the tradition puppy bark you hear on startup like 3 times in a row?
Attachments
DangerWill.tar.gz
(15.89 KiB) Downloaded 630 times
http://audio.online-convert.com/ <-- excellent site
http://samples.mplayerhq.hu/A-codecs/ <-- Codec Test Files
http://html5games.com/ <-- excellent HTML5 games :)

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#16 Post by HairyWill »

Dougal wrote:I'm not really fond of these apps that use scripts to get info...
But isn't that the whole point of this app in the generic sense.

It provides an interface to allow a script to control a status icon.

I'm interested in what your objection is providing they are not called too often. Every 30 seconds would be acceptable for a battery monitor.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

brad_chuck
Posts: 286
Joined: Tue 16 Aug 2005, 03:47
Location: Appalachian Mountains

#17 Post by brad_chuck »

The "event" program does not have to be a script. Write it in c... have fun with that.

The idea is that YOU get to make the "event" program do whatever you would like. I like shell scripts.

The script I provided was just an example. Will have to work on a "production" in the next few weeks. Any help here would be great.

HairyWill - Thanks for the icon tip this will help.

Still have to work on a few things. Will have another "preview" out soon.

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#18 Post by Dougal »

brad_chuck wrote:The "event" program does not have to be a script. Write it in c... have fun with that.

The idea is that YOU get to make the "event" program do whatever you would like. I like shell scripts.
Yeah, I realized that and I like shell scripts, too.
My point is that if you're already running that applet, you might as well have it do everything, rather that call an external script every two seconds (and you actually call it twice every time, with "-i" and "-t").
I remember in the past, I used to look in top and keep seeing lots of instances of calcfreespace.sh, which was run by the freememapplet. I just ended up using a vfs function to get the free space and got rid of the shell script.

Note that in the case of the battery applet, for example, you're also losing the history, which can be useful: battery applets will usually average the (dis)charging rate to calculate the time left, since the momentary value can fluctuate...
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#19 Post by Dougal »

I've made another couple of updates:
0.2: adds checking for info in /sys/class/power_supply.
I hope the rate code is ok, as I'm testing with a bad bios that doesn't supply the rate info.

0.2.1: adds use of the GlossyPower icons linked in the previous page (so it has 10 different battery icons). We still probably need to find a nicer "online" icon.
Note that the icons are originally huge (518 pixels tall), so I just scaled them to 1/20 and they are now 26 pixels tall and about 12 wide. What this means is that they get stretched a little horizontally and the battery looks a little fat... this can be solved by just editing them manually and extending the size of the canvas.

If anybody want APM support, it could help if they post here the output of "cat /proc/apm".

Ive also gone on to implement support for multiple batteries, but wasn't sure exactly how to present the data: I currently present a total (an average of charge percentage and a sum of the times), but wasn't sure if it's correct/the best way.
Last edited by Dougal on Sun 12 Apr 2009, 09:35, edited 1 time in total.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
Tid
Posts: 16
Joined: Tue 09 Dec 2008, 21:05
Location: Canton, OH USA

#20 Post by Tid »

Does anyone know where I can get the traditional woof woof sound? I like the idea of adding the bark when the battery is getting low.

Dougal, check out these battery icons!! http://www.kde-look.org/content/show.ph ... tent=93465
Last edited by Tid on Tue 16 Dec 2008, 21:30, edited 1 time in total.

Post Reply