Posted to tcl by Stu at Sun Oct 02 13:30:53 GMT 2022view raw

  1. # May need high keyboard repeat rate to be observable.
  2. # xset r rate 100 100; wish tvjitter.tcl; xset r rate
  3.  
  4. bind . <Control-q> exit
  5.  
  6. proc randstr {{length {6}}} {
  7. set str ""
  8. for {set i 0} {$i < $length} {incr i} {
  9. append str [format %c [expr {97 + int(rand() * 26)}]]
  10. }
  11. return $str
  12. }
  13.  
  14. set extra [list]
  15. #lappend extra -show headings
  16.  
  17. grid [ttk::treeview .t -columns {a b c} -height 30 {*}$extra]
  18. bind .t <Key-Down> [list down]
  19.  
  20. proc down {} {
  21. set item [.t next [.t focus]]
  22. if {$item eq ""} { return -code break }
  23. set index [.t index $item]
  24. .t focus $item
  25.  
  26. # Try with one of these. Is there noticeable jitter?
  27. .t see $item
  28. #if {$index > 29} {.t yview scroll 1 units}
  29. #.t yview moveto [expr {double($index - 29) / 500.0}]
  30.  
  31. .t selection set [list $item]
  32. return -code break
  33. }
  34.  
  35. for {set i 0} {$i < 500} {incr i} {
  36. .t insert {} end -values [list $i [randstr] [randstr]]
  37. }
  38.  
  39. focus .t
  40. .t focus I001
  41. .t selection set I001