2 if {[file exists /proc/apm]} {
7 set c [canvas .apm -width 62 -height 15 -relief sunken -bd 1]
9 $c create rectangle 10 3 30 13 -outline black
10 $c create rectangle 30 6 33 10 -outline black -fill black
12 $c create rectangle 10 3 30 13 -outline black -stipple @[file join $tk_library demos images gray25.bmp] -fill black -tag energy
14 $c create polygon 2 1 6 8 3 8 8 15 6 9 9 9 5 1 -outline red -fill red -tag power
16 $c create polygon 35 8 38 5 38 11 -fill black -outline black -tag charge
17 $c create polygon 35 5 35 11 38 8 -fill black -outline black -tag discharge
18 $c create text 61 9 -anchor e -text 100% -font 6x10 -tag pwtext
19 bind .apm <Enter> ::apm::start_help
20 bind .apm <Leave> ::apm::cancel_help
21 bind .apm <Motion> ::apm::reset_help
27 proc toggle_item {tag state} {
30 .apm itemconfig $tag -fill $colors($tag) -outline $colors($tag)
32 .apm itemconfig $tag -fill {} -outline {}
36 proc set_power {percent} {
37 set x [expr 20*$percent/100+10]
38 .apm coords energy 10 3 $x 13
39 .apm itemconfig pwtext -text "$percent%"
42 set f [open /proc/apm]
46 set battery [expr [lindex $status 5]]
48 if {[lindex $status 3] == 1} {
50 toggle_item discharge 0
52 if {$battery!=255 && ($battery&8)} {
54 append help " charging [calc_time $status] to complete"
57 append help " not charging"
59 .apm configure -background [lindex [.apm configure -background] 3]
62 toggle_item discharge 1
64 if {$battery != 255} {
66 .apm configure -background yellow
67 } elseif {$battery & 2} {
68 .apm configure -background #ff7777
70 .apm configure -background [lindex [.apm configure -background] 3]
73 append help "Battery [calc_time $status] remains"
75 set_power [scan [lindex $status 6] "%d%%"]
76 after 5000 ::apm::update
79 proc calc_time {apm_status} {
80 set units [lindex $apm_status 8]
81 set count [lindex $apm_status 7]
82 if {![regexp {[0-9]+} $count]} {
85 if {$units == "sec"} {
86 set sec [expr $count % 60]
87 set min1 [expr $count / 60]
88 set min [expr $min1 % 60]
89 set hours [expr $min1 /60]
90 return [format "%d:%02d:%02d" $hours $min $sec]
92 set min [expr $count % 60]
93 set hours [expr $count / 60]
94 return [format "%d:%02d" $hours $min]
98 variable help_after_id
99 if [info exists help_after_id] {
100 after cancel $help_after_id
103 if {[wm state .apm.help]=="normal"} {
104 wm withdraw .apm.help
108 variable help_after_id
109 set help_after_id [after 1000 ::apm::show_help]
116 wm geometry .apm.help +[expr [winfo pointerx .]+2]+[expr [winfo pointery .]+2]
117 wm deiconify .apm.help
122 wm withdraw .apm.help
123 wm overrideredirect .apm.help y
124 label .apm.help.l -textvar ::apm::help -background yellow -font 6x10
125 pack .apm.help.l -side left