SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-09-10 08:03:02

richjack
Member
Registered: 2010-08-11
Posts: 24

Laptop battery monitor script I'd like to share (with tray icon)

Hello all

I have been developing a laptop battery system tray applet for my own distro and I'd like to share it here. I am really interested in users testing this script and providing some feedback. I hope to develop a number of simple scripts that can be used on any distro and this is the first.

The link to the download, instructions and screenshots is here:
http://chameleonos.wordpress.com/projects/battmon/

The reason for creating this script is because I hate the battery monitor on LXPanel and if you are using Tint2 or any other panel, it saves you having to install Gnome-power-manager and all its deps (yes I know you could display battery in conky, but I specifically wanted a system tray icon).

Basically this is a bash/zenity script that uses acpi to check the battery status and provide a system tray icon that updates to indicate current battery levels. It will provide warnings when running on battery if the level drops below 20%, 15%, 10% and 5%. If you have pm-utils installed on your system, then you can ask the scipt to hibernate the laptop when the level reaches 5%. Obviously hibernation on Linux is a bit hit and miss.

There are a few command line parameters detailed on the site so you can control the amount of delay between battery checks or even specify an alternative icon directory (but for now you will have to use my naming scheme smile ).

I will say this now, that I have gone with some bespoke icons that do not match the ones on the Gnome icon specification but that provide a wider range of level indicators. During the next update I intend to add in a command line parameter so that the script will use icons from your current icon theme if you want it to.

I know that there are some awesome bash and python scripters using these forums and I'm sure that if any of you take a look at my script you'll be able to suggest much better use of code (my bash is pretty basic self taught from Googling and trial and error). If anyone want to rewrite it in Python, be my guest!

Cheers all
richjack

Offline

Be excellent to each other!

#2 2010-09-10 09:00:35

Istvan
#! CrunchBanger
From: Budapest, Hungary
Registered: 2010-02-20
Posts: 147

Re: Laptop battery monitor script I'd like to share (with tray icon)

(zenity:14058): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_from_file_at_scale: assertion `width > 0 || width == -1' failed
I had this problem :-(


Ha ezt el tudod olvasni, biztosan nem vagy rövidlátó.

Offline

#3 2010-09-10 09:27:03

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

Did the system tray icon show up though?

Offline

#4 2010-09-10 10:20:34

Istvan
#! CrunchBanger
From: Budapest, Hungary
Registered: 2010-02-20
Posts: 147

Re: Laptop battery monitor script I'd like to share (with tray icon)

Yes it did. But aborted in ten secs.
I have Zenity version 2.26


Ha ezt el tudod olvasni, biztosan nem vagy rövidlátó.

Offline

#5 2010-09-10 10:52:08

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

Hmmm, I'll look into it and let you know what version of zenity I'm using...

Offline

#6 2010-09-10 13:42:48

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

I'm using Zenity 2.30 on a Unity Linux base.

I can confirm that this error message exists, however, on my system it can be ignored - the applet works regardless!

I'm not sure what is causing the error but it must be a bug in zenity or gtk+. If anyone has come across this before I'd be grateful for some advice.

What is strange is that if you call zenity from the command line like this, using one of the same icons:
zenity --notification --window-icon="/usr/local/share/battmon/icons/battery_charging_0-5.png" there is no error neutral

Perhaps it does require a rewrite in python, but I don't understand why it is quitting on you. Perhaps you could update zenity and see what happens..?

Offline

#7 2010-09-10 15:51:28

Istvan
#! CrunchBanger
From: Budapest, Hungary
Registered: 2010-02-20
Posts: 147

Re: Laptop battery monitor script I'd like to share (with tray icon)

I have already upgraded zenity to 2.28 . A later version cannot be installed because of dependency problems.
I had the same error message, and also aborted the same way.


Ha ezt el tudod olvasni, biztosan nem vagy rövidlátó.

Offline

#8 2010-09-10 19:52:46

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

Well thanks for trying Istvan, I do appreciate it and I'll continue to look into a solution. Not much has turned up by Googling yet though...

In case this is of any use, currently I am running:

  • zenity version 2.30

  • gtk+2.0 version 2.20

  • libgdk_pixbuf2.0 version 2.20

  • bash version 4.1


On my system, the icon sits happily in the system tray using LXPanel, tint2 or XFCE Panel.

Last edited by richjack (2010-09-10 20:08:28)

Offline

#9 2010-09-10 20:52:37

Istvan
#! CrunchBanger
From: Budapest, Hungary
Registered: 2010-02-20
Posts: 147

Re: Laptop battery monitor script I'd like to share (with tray icon)

Meanwhile i tested on a Statler box, with later packages. It works :-)
I will give it another try on my old 9.04 Crunch laptop . Perhaps I can upgrade some more packages . Sure this problem is caused by old packages.
How can I hack the script not to hibernate the system but simply shutdown ?
Thank you, richjack for this wonderful app.


Ha ezt el tudod olvasni, biztosan nem vagy rövidlátó.

Offline

#10 2010-09-10 23:03:32

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

Phew, so glad it works... I will put the versions on the website that are required and at some point update the configure script to try and check for version numbers.

To hack the script as you mentioned, go to line 265 and change "pm-hibernate" for whatever command you normally use to shutdown the system (I'm not sure which one you use in Crunchbang):

sudo shutdown -h now
gdm-control --shutdown && openbox --exit
pm-shutdown

Again, I could add that as a command line parameter in future versions.

Thanks for persevering and feeding back smile

Offline

#11 2010-09-14 18:23:01

the real dave
#! CrunchBanger
From: Cork, Ireland
Registered: 2010-03-15
Posts: 145
Website

Re: Laptop battery monitor script I'd like to share (with tray icon)

I was looking for something nice and small to simply display my battery status, and this is perfect mate. It seems to be working just as it should. Is it possible to change the icons the applet uses?


Linux Expresso -My collection of Computer madness
HTML5 Responsive Webpage

Offline

#12 2010-09-14 19:50:46

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

Great, glad it works smile

If you look in /usr/local/share/battmon/icons you'll see all the icons and importantly the icon names.

You can also type battmon -f to print all the filenames in a terminal.

What you will need to do is to make sure you have an icon matching every icon name in the original icon set. I'm afraid because I wanted a gradual change in the icon, there's a lot of icon names matching some pretty random charge levels! Anyway, you can create your own icon folder anywhere you want eg at ~/battmon if you want. Copy some icons from an icon set that you like - you will want the 22x22 icons. Then create copies matching all the original filenames. It doesn't matter if you want to use the same icon more than once - just copy it and change the filename accordingly (or create a symlink).

Then invoke battmon with the command:

battmon -d $HOME/path/to/icons

And it should use your new icons!

In future versions I plan to add support for using icons from your current icon set or to use any icons using the more conventional Gnome icon specs.

Offline

#13 2010-09-14 21:07:29

the real dave
#! CrunchBanger
From: Cork, Ireland
Registered: 2010-03-15
Posts: 145
Website

Re: Laptop battery monitor script I'd like to share (with tray icon)

Awesome, I'll try that out and post back a screenshot.

Also, is it possible to prevent it from repeatedly telling me my battery is removed when I take it out, or perhaps just notify me once?

Cheers.


Linux Expresso -My collection of Computer madness
HTML5 Responsive Webpage

Offline

#14 2010-09-14 21:56:44

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

the real dave wrote:

Also, is it possible to prevent it from repeatedly telling me my battery is removed when I take it out, or perhaps just notify me once?

I see what you mean - the notification keeps recurring because there's a loop in the script to check whether the battery is inserted at all and there is a function that reset the loops after each sleep (just in case you reinsert the battery). The best thing to do for now is to edit out lines 148-151 inclusive in /usr/local/bin/battmon by adding a # symbol at the start of the line. You should still get the change in icon.

Also if you want the icon there on start-up whether or not you have a battery, edit out lines 118-122 inclusive otherwise the applet will close if you start it and no battery is present (this is so that it doesn't waste unnecessary resources on a desktop PC).

It's useful feedback for improvements to the next version, thanks smile

Offline

#15 2010-09-28 13:46:33

Tunafish
#! Die Hard
From: the Netherlands
Registered: 2010-03-07
Posts: 1,201

Re: Laptop battery monitor script I'd like to share (with tray icon)

Hi Richjack,

I just installed your battery script. Installation gave some problems:
pm-utils is installed on my system.
./configure reports it as not installed.

And i had to manually make the /usr/local/bin/battmon file executable. This can also be some mistake i made, i'm not very experienced in installing scripts. hmm

When i start the script from terminal, i get an error:

(zenity:13929): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_from_file_at_scale: assertion `width > 0 || width == -1' failed

(zenity:13929): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_from_file_at_scale: assertion `width > 0 || width == -1' failed

The good news: the script is running, shows the tray icon and notices when i unplug my laptop. smile

Tuna.


sed 's/stress/relaxation/g'
Privacy & Security on #!

Offline

#16 2010-09-28 13:53:02

richjack
Member
Registered: 2010-08-11
Posts: 24

Re: Laptop battery monitor script I'd like to share (with tray icon)

Thank you Tuna for testing and reporting back.

I will look into why the file wasn't executable.
It is very possible that pm-utils in Crunchbang are filed differently than in Unity Linux (which is what I developed it on).

Yes, that terminal output error is some sort of bug in zenity, but it's non-critical. Glad it works smile

Cheers
richjack

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo