SHList2.tcl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: SHList2.tcl,v 1.4 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 how to use multiple columns and multiple styles
  13. # in the tixHList widget
  14. #
  15. # In a tixHList widget, you can have one ore more columns.
  16. #
  17. proc RunSample {w} {
  18. # We create the frame and the ScrolledHList widget
  19. # at the top of the dialog box
  20. #
  21. frame $w.top -relief raised -bd 1
  22. # Put a simple hierachy into the HList (two levels). Use colors and
  23. # separator widgets (frames) to make the list look fancy
  24. #
  25. tixScrolledHList $w.top.a -options {
  26. hlist.columns 3
  27. hlist.header true
  28. }
  29. pack $w.top.a -expand yes -fill both -padx 10 -pady 10 -side left
  30. set hlist [$w.top.a subwidget hlist]
  31. # Create the title for the HList widget
  32. # >> Notice that we have set the hlist.header subwidget option to true
  33. # so that the header is displayed
  34. #
  35. # First some styles for the headers
  36. set style(header) [tixDisplayStyle text -refwindow $hlist \
  37. -fg black -anchor c \
  38. -padx 8 -pady 2\
  39. -font [tix option get bold_font ]]
  40. $hlist header create 0 -itemtype text -text Name \
  41. -style $style(header)
  42. $hlist header create 1 -itemtype text -text Position \
  43. -style $style(header)
  44. # Notice that we use 3 columns in the hlist widget. This way when the user
  45. # expands the windows wide, the right side of the header doesn't look
  46. # chopped off. The following line ensures that the 3 column header is
  47. # not shown unless the hlist window is wider than its contents.
  48. #
  49. $hlist column width 2 0
  50. # This is our little relational database
  51. #
  52. set boss {doe "John Doe" Director}
  53. set managers {
  54. {jeff "Jeff Waxman" Manager}
  55. {john "John Lee" Manager}
  56. {peter "Peter Kenson" Manager}
  57. }
  58. set employees {
  59. {alex john "Alex Kellman" Clerk}
  60. {alan john "Alan Adams" Clerk}
  61. {andy peter "Andreas Crawford" Salesman}
  62. {doug jeff "Douglas Bloom" Clerk}
  63. {jon peter "Jon Baraki" Salesman}
  64. {chris jeff "Chris Geoffrey" Clerk}
  65. {chuck jeff "Chuck McLean" Cleaner}
  66. }
  67. set style(mgr_name) [tixDisplayStyle text -refwindow $hlist \
  68. -font [tix option get bold_font ]]
  69. set style(mgr_posn) [tixDisplayStyle text -refwindow $hlist \
  70. -padx 8]
  71. set style(empl_name) [tixDisplayStyle text -refwindow $hlist \
  72. -font [tix option get bold_font ]]
  73. set style(empl_posn) [tixDisplayStyle text -refwindow $hlist \
  74. -padx 8 ]
  75. # Let configure the appearance of the HList subwidget
  76. #
  77. $hlist config -separator "." -width 25 -drawbranch 0 -indent 10
  78. $hlist column width 0 -char 20
  79. # Create the boss
  80. #
  81. $hlist add . -itemtype text -text [lindex $boss 1] \
  82. -style $style(mgr_name)
  83. $hlist item create . 1 -itemtype text -text [lindex $boss 2] \
  84. -style $style(mgr_posn)
  85. # Create the managers
  86. #
  87. set index 0
  88. foreach line $managers {
  89. set row [$hlist add .[lindex $line 0] -itemtype text \
  90. -text [lindex $line 1] -style $style(mgr_name)]
  91. $hlist item create $row 1 -itemtype text -text [lindex $line 2] \
  92. -style $style(mgr_posn)
  93. incr index
  94. }
  95. foreach line $employees {
  96. # "." is the separator character we chose above
  97. #
  98. set entrypath .[lindex $line 1].[lindex $line 0]
  99. # ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
  100. # parent entryPath / child's name
  101. set row [$hlist add $entrypath -text [lindex $line 2] \
  102. -style $style(empl_name)]
  103. $hlist item create $row 1 -itemtype text -text [lindex $line 3] \
  104. -style $style(empl_posn)
  105. # [Hint] Make sure the .[lindex $line 1].[lindex $line 0] you choose
  106. # are unique names. If you cannot be sure of this (because of
  107. # the structure of your database, e.g.) you can use the
  108. # "addchild" widget command instead:
  109. #
  110. # $hlist addchild [lindex $line 1] -text [lindex $line 2]
  111. # ^^^^^^^^^^^^^^^^
  112. # parent entryPath
  113. }
  114. # Use a ButtonBox to hold the buttons.
  115. #
  116. tixButtonBox $w.box -orientation horizontal
  117. $w.box add ok -text Ok -underline 0 -command "destroy $w" \
  118. -width 6
  119. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  120. -width 6
  121. pack $w.box -side bottom -fill x
  122. pack $w.top -side top -fill both -expand yes
  123. }
  124. # This "if" statement makes it possible to run this script file inside or
  125. # outside of the main demo program "widget".
  126. #
  127. if {![info exists tix_demo_running]} {
  128. wm withdraw .
  129. set w .demo
  130. toplevel $w; wm transient $w ""
  131. RunSample $w
  132. bind .demo <Destroy> exit
  133. }