#!/usr/bin/wish proc manyset {list args} { foreach val $list var $args { upvar 1 $var my set my $val } } set progname ypp-chatlog-alerter set height 5 proc menuent {w l a x} { set c [list .mbar.$w add command -label $l -command $x] if {[string length $a]} { lappend c -accel Command-$a } eval $c } proc menus {} { global height menu .mbar -tearoff 0 foreach w {file edit} l {File Edit} { menu .mbar.$w -tearoff 0 .mbar add cascade -menu .mbar.$w -label $l } foreach l {Open Quit} a {O Q} x {newfile exit} { menuent file $l $a $x } foreach l {Cut Copy Paste Clear} a {X C V {}} { menuent edit $l $a [list event generate {[focus]} <<$l>>]] } . configure -menu .mbar } proc nonportability {} { global progname defaultfile switch -exact [tk windowingsystem] { aqua { set defaultfile ~/Library/Preferences/$progname.prefs } x11 { set defaultfile ~/.$progname.rc } default { error ? } } } proc widgets {} { global height listbox .t -width 5 -height $height -borderwidth 0 listbox .p -width 14 -height $height -borderwidth 0 listbox .m -width 80 -height $height -borderwidth 0 pack .t .p .m -side left } proc newfile {} { global currentfile defaultfile set newfile [tk_getOpenFile -multiple 0 -initialfile $currentfile \ -title "Select YPP log to track"] if {![string length $newfile]} return set currentfile $newfile set newdefaults [open $defaultfile.new w] puts $newdefaults "[list set currentfile $currentfile]" close $newdefaults file rename -force $defaultfile.new $defaultfile #fixme refresh } set lw_ls {times pirates messages} set lw_ws {t p m} proc for_lw {body} { global lw_ls lw_ws uplevel 1 [list \ foreach l $lw_ls \ w $lw_ws \ $body] } set e_life 120 set tint_switch 90 set tint_switched [expr { exp( -($tint_switch+0.0) / $e_life ) }] proc retint {} { global times e_life set i 0 set now [clock seconds] foreach time $times { set agescale [expr { exp( -($now >= $time ? $now-$time : 0) / $e_life ) }] } } proc tintentry {w y tint} { global tint_switched #puts "$tint $tint_switched" set yellow [format "%02x" [expr {round( 255 * ( $tint >= $tint_switched ? $tint : 0 ) )}]] set black [format "%02x" [expr {round( 255 * ( $tint >= $tint_switched ? 0 : ($tint / $tint_switched)*0.75 + 0.25 ) )}]] $w itemconfigure $y \ -foreground [format "#${black}${black}${black}"] \ -background [format "#${yellow}${yellow}00"] } proc clearlists {} { global height global times pirates messages set currentfile {} for_lw { .$w delete 0 end; set $l {} } for {set i 0} {$i<$height} {incr i} { for_lw { lappend $l {}; .$w insert end {} } } } proc showtints {} { global e_life set divs 20 listbox .tints -width 60 -height [expr {$divs+1}] for {set y 0} {$y <= $divs} {incr y} { set tint [expr {($y+0.0)/$divs}] puts "$y $tint" .tints insert end \ "[format "#%2d %6f %4ds" $y $tint [expr {round( $tint > 0 ? -log($tint) * $e_life : "9999" )}]] The quick brown fox jumped over the lazy dog" tintentry .tints $y $tint } pack .tints -side bottom } proc parseargs {} { global argv foreach arg $argv { if {![string compare $arg --test-tints]} { showtints } else { error "unknown option $arg" } } } menus nonportability parseargs widgets clearlists if {[file exists $defaultfile]} { source $defaultfile } #fixme refresh