Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Nov 1997 13:50:00 +1030
From:      Mike Smith <mike@smith.net.au>
To:        Warner Losh <imp@village.org>
Cc:        mobile@freebsd.org
Subject:   Re: A little tk program 
Message-ID:  <199711100320.NAA00665@word.smith.net.au>
In-Reply-To: Your message of "Sun, 09 Nov 1997 19:27:46 PDT." <199711100227.TAA20649@harmony.village.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
> ok.  I have a small tcl/tk prorgam that works under tk 4.2 (since I
> have ical installed).  It displays the current battary level.  It
> should work with 8.0 as well.  Enjoy.  Comments welcome.  Only about
> 1M of memory is needed :-(.

... but if ical is running that's shared.  8)  If you were feeling 
enthusiastic, you could have it change its icon title while minimised,
eg. from [##########] 100  to [          ] 0...

> Warner
> 
> P.S. You need to run this as root, or have apm be setuid root.

Er, I don't think so.  Certainly, apm will give me power status as 
non-root.

> P.P.S.  Mike Smith: now I understand why you like tk so much....

*grin*

> scale .scale -from 0 -to 100 \
> 	-length 100 \
> 	-variable batteryLevel \
> 	-orient horizontal \
> 	-showvalue true

Wow, now I can set the battery level too! 8)

Here's a slightly modified version that implements a bargraph in the 
icon title, adds some colour and shrinks it a little to make the most 
of precious laptop real estate.  You might also want to configure your 
window manager to hide the decorations on the window to make it smaller 
again.

mike

#!/bin/sh
# tcl magic \
exec wish8.0 -f $0 $*

proc updateBattery {} {
	global batteryLevel;

	set batteryLevel [exec apm -l];
	set hashes [string range "##########" 0 [expr $batteryLevel / 10]];
	wm iconname . [format "\[%-10s\] %d%%" $hashes $batteryLevel];
	if {$batteryLevel < 20} {
		.scale configure -troughcolor red;
	} else {
		if {$batteryLevel < 40} {
			.scale configure -troughcolor yellow;
		} else {
			.scale configure -troughcolor green;
		}
	}
	after 30000 updateBattery;
}

label .label -text "Battery Level" -font 6x10;
pack .label -side left;
scale .scale -from 0 -to 100 \
	-length 100 \
	-variable batteryLevel \
	-orient horizontal \
	-showvalue true \
	-font 5x8 \
	-width 5 \
	-sliderlength 4 \
	-state disabled;
pack .scale -side right;
wm title . "batterylevel";
update idletasks;
wm resizable . 0 0;
updateBattery;






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199711100320.NAA00665>