Posted to tcl by aspect at Sat May 17 04:41:46 GMT 2014view raw

  1. # use as you would a labelframe: eg:
  2. # grid [CollapsingFrame .f -text "Clicky"] -sticky nsew
  3. # grid [text .t1] -in .f -sticky nsew
  4.  
  5. snit::widgetadaptor CollapsingFrame {
  6. component b
  7. delegate option -text to b
  8. delegate option -textvariable to b
  9. delegate option * to hull
  10. delegate method * to hull
  11. constructor args {
  12. installhull using labelframe
  13. install b using label $win.b
  14. $self configurelist $args
  15. $self configure -labelwidget $b
  16. bind $b <1> [mymethod collapse]
  17. }
  18. method collapse {} {
  19. set C "+" ;#\u25ba
  20. set O "-" ;#\u25bc
  21. set h [winfo height $b]
  22. incr h 2
  23. set f [winfo parent $b]
  24. set title [$b cget -text]
  25. set title [string trimleft $title "$C$O "]
  26. if {[grid propagate $f]} {
  27. grid propagate $f 0
  28. $f configure -height $h
  29. $b configure -text "$C $title"
  30. } else {
  31. grid propagate $f 1
  32. $f configure -height 0
  33. $b configure -text "$O $title"
  34. }
  35. }
  36. }
  37.