bind . <Enter> {
set entered 1
set mTime 0
doUpdate
}
bind . <Leave> {
set entered 0
set mTime 0
doUpdate
}
proc doUpdate {} {
global mTime statusFile timeout
after $timeout doUpdate
set currentTime [file mtime $statusFile]
if { $currentTime <= $mTime } {
return
}
set mTime $currentTime
set f [open $statusFile "r"]
# APC : Jul 09 09:11:22
# CABLE : APC Cable 940-0095A
# UPSMODEL : BackUPS Pro
# UPSMODE : Stand Alone
# LINEFAIL : OK
# BATTSTAT : OK
# LINEVOLT : OK
# LASTEVNT : LINE VOLTAGE INCREASE
global eventTime
gets $f; gets $f; gets $f; gets $f
foreach entry {f s v} {
.${entry}.s configure -text "N/A"
}
while { 1 } {
parseLine [gets $f]
if { [eof $f] } break
}
close $f
}
proc now {} {
return [clock format [clock seconds]]
}
set lastValue ""
set eventTime [now]
proc parseLine { line } {
set l [split $line]
set keyword [lindex $l 0]
set value [getValue $l]
switch $keyword {
"LINEFAIL" {
setValue .f.s $value
}
"BATTSTAT" {
setValue .s.s $value
}
"LINEVOLT" {
setValue .v.s $value
}
"LASTEVNT" {
global entered
if { $entered == 1 } {
global eventTime
setValue .e.s $eventTime
} else {
setValue .e.s $value
}
global lastValue
if { "$value" != "$lastValue" } {
global eventTime
set eventTime [now]
set lastValue $value
}
}
}
}
proc setValue { widget text } {
$widget configure -text $text
foreach pattern { fail off down } {
if { [regexp ".*${pattern}.*" [string tolower $text]] } {
$widget configure -foreground red
return
}
}
$widget configure -foreground blue
}
proc getValue { line } {
return [string range $line [expr [string first ":" $line] + 2] end]
}
doUpdate
--
Best regards, -- Boris.
Any sufficiently advanced operating system is indistinguishable from Unix.
--- Gnus v5.5/XEmacs 20.3 - "London"
* Origin: Linux inside (2:5020/510@fidonet)