Version 5 of chatTemp

Updated 2003-08-27 08:07:17

This is a page for longer things that I'm not sure whether or not belong on the Wiki or how to categorize them. In hindsight I maybe should have used the name chat temp. Oh well...


 #GPS
 proc blink.me {win i} {
  set cur [$win curselection]
  set fg [$win cget -foreground]
  set bg [$win cget -background] 

  foreach {bg fg} [list $fg $bg] break
  $win configure -foreground $fg
  $win configure -background $bg
  incr i 
  if {$i > 5} return
  after 50 [list blink.me $win $i] 
 }
 pack [listbox .l]; .l insert end Hello World
 bind .l <<ListboxSelect>> {blink.me %W 0}

hmm... Now that was a little annoying. It flashes too much. Let's make it only flash 2 colors or maybe even 3 and then reset. I think passing it a list of colors might work better.

 #GPS
 proc blink.this {win colList i} {
  set cur [$win curselection]
  foreach {bg fg} $colList break
  $win itemconfigure $cur -selectforeground $fg -selectbackground $bg
  incr i 
  if {$i > 5} {
   $win itemconfigure $cur -selectforeground {} -selectbackground {}
   return
  }
  after 50 [list blink.this $win [list $fg $bg] $i]
 }

 pack [listbox .l]; .l insert end Hello World this is George!
 bind .l <<ListboxSelect>> {blink.this %W {red blue} 0}

Abhishek I hope this helps:

 #! /bin/wish8.3
 proc toolbar:make {win arPtr} {
        upvar $arPtr ar
        set i 0; 
        foreach {name mem} [array get ar] {
                set img [lindex $mem 0]
                set cmd [lindex $mem 1]
                pack [button $win.$name -image $img -command $cmd] -side left
                incr i
        }
 }

 proc toolbar:disable {win arPtr key disFile} {
        upvar $arPtr ar
        set img [lindex $ar($key) 0]
        $img read ./$disFile
        $win.$key config -state disabled
 }

 pack [frame .f -relief groove -bd 1]
 set ar(hello) [list [image create photo -file ./hello.gif] {puts "Hello World"}]
 set ar(goodbye) [list [image create photo -file ./goodbye.gif] exit]
 toolbar:make .f ar


 pack [button .b -text "Disable Hello" -command {toolbar:disable .f ar hello ./goodbye.gif}]

jmn 2003-08-26 Proc size performance

 set bigStuff ""
 for {set i 0} {$i <= 700} {incr i} {
         append bigStuff "set x$i v$i ;\n"
 }
 proc small {args} {
         set v1 [lindex $args 0]
         if {$v1 eq "goFast"} {        
                 return $v1;
         } else {
                 return "slow"
         }
 }
 proc big {args} [string map "@bigStuff@ [list $bigStuff]" {
         set v1 [lindex $args 0]
         if {$v1 eq "goFast"} {        
                 return $v1;
         } else {
                 @bigStuff@
                 return "slow"
         }
 }]
 small goFast v1 v2
 small goSlow v1 v2
 big goFast v1 v2
 big goSlow v1 v2
 proc dotimes {{n 1000}} {
           puts "small goFast: [time {small        goFast val1 val2} $n]"
         puts "small goSlow: [time {small        goSlow val1 val2} $n]"
         puts "big   goFast: [time {big        goFast val1 val2} $n]"
         puts "big   goSlow: [time {big        goSlow val1 val2} $n]"
 }