SHList.tcl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: SHList.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "widget": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program using tixwish.
  12. # This file demonstrates the use of the tixScrolledHList widget.
  13. #
  14. proc RunSample {w} {
  15. # We create the frame and the ScrolledHList widget
  16. # at the top of the dialog box
  17. #
  18. frame $w.top -relief raised -bd 1
  19. # Put a simple hierachy into the HList (two levels). Use colors and
  20. # separator widgets (frames) to make the list look fancy
  21. #
  22. tixScrolledHList $w.top.a
  23. pack $w.top.a -expand yes -fill both -padx 10 -pady 10 -side left
  24. # This is our little relational database
  25. #
  26. set bosses {
  27. {jeff "Jeff Waxman"}
  28. {john "John Lee"}
  29. {peter "Peter Kenson"}
  30. }
  31. set employees {
  32. {alex john "Alex Kellman"}
  33. {alan john "Alan Adams"}
  34. {andy peter "Andreas Crawford"}
  35. {doug jeff "Douglas Bloom"}
  36. {jon peter "Jon Baraki"}
  37. {chris jeff "Chris Geoffrey"}
  38. {chuck jeff "Chuck McLean"}
  39. }
  40. set hlist [$w.top.a subwidget hlist]
  41. # Let configure the appearance of the HList subwidget
  42. #
  43. $hlist config -separator "." -width 25 -drawbranch 0 -indent 10
  44. set index 0
  45. foreach line $bosses {
  46. if {$index != 0} {
  47. frame $hlist.sep$index -bd 2 -height 2 -width 150 -relief sunken \
  48. -bg [$hlist cget -bg]
  49. $hlist addchild {} -itemtype window \
  50. -window $hlist.sep$index -state disabled
  51. }
  52. $hlist add [lindex $line 0] -itemtype text \
  53. -text [lindex $line 1]
  54. incr index
  55. }
  56. foreach line $employees {
  57. # "." is the separator character we chose above
  58. #
  59. set entrypath [lindex $line 1].[lindex $line 0]
  60. # ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
  61. # parent entryPath / child's name
  62. $hlist add $entrypath -text [lindex $line 2]
  63. # [Hint] Make sure the [lindex $line 1].[lindex $line 0] you choose
  64. # are unique names. If you cannot be sure of this (because of
  65. # the structure of your database, e.g.) you can use the
  66. # "addchild" widget command instead:
  67. #
  68. # $hlist addchild [lindex $line 1] -text [lindex $line 2]
  69. # ^^^^^^^^^^^^^^^^
  70. # parent entryPath
  71. }
  72. # Use a ButtonBox to hold the buttons.
  73. #
  74. tixButtonBox $w.box -orientation horizontal
  75. $w.box add ok -text Ok -underline 0 -command "destroy $w" \
  76. -width 6
  77. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  78. -width 6
  79. pack $w.box -side bottom -fill x
  80. pack $w.top -side top -fill both -expand yes
  81. }
  82. # This "if" statement makes it possible to run this script file inside or
  83. # outside of the main demo program "widget".
  84. #
  85. if {![info exists tix_demo_running]} {
  86. wm withdraw .
  87. set w .demo
  88. toplevel $w; wm transient $w ""
  89. RunSample $w
  90. bind .demo <Destroy> exit
  91. }