HList1.tcl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: HList1.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 tixHList widget -- you can
  13. # use to display data in a tree structure. For example, your family tree
  14. #
  15. #
  16. proc RunSample {w} {
  17. # Create the tixHList and the tixLabelEntry widgets on the on the top
  18. # of the dialog box
  19. #
  20. # [Hint] We create the tixHList and and the scrollbar by ourself,
  21. # but it is more convenient to use the tixScrolledHlist widget
  22. # which does all the chores for us.
  23. #
  24. # [Hint] Use of the -browsecmd and -command options:
  25. # We want to set the tixLabelEntry accordingly whenever the user
  26. # single-clicks on an entry in the HList box. Also, when the user
  27. # double-clicks, we want to print out the selection and close
  28. # the dialog box
  29. #
  30. frame $w.top -border 1 -relief raised
  31. tixHList $w.top.h -yscrollcommand "$w.top.s set" -separator / \
  32. -browsecmd "hlist1:browse $w.top.h" \
  33. -command "hlist1:activate $w.top.h"\
  34. -wideselection false \
  35. -indent 15
  36. scrollbar $w.top.s -command "$w.top.h yview" -takefocus 0
  37. # Some icons for our list entries
  38. #
  39. global folder1 folder2
  40. set img1 [image create bitmap -data $folder1]
  41. set img2 [image create bitmap -data $folder2]
  42. # Put our directories into the HList entry
  43. #
  44. set h $w.top.h
  45. set dirs {
  46. /
  47. /lib
  48. /pkg
  49. /usr
  50. /usr/lib
  51. /usr/local
  52. /usr/local/lib
  53. /pkg/lib
  54. }
  55. foreach d $dirs {
  56. $h add $d -itemtype imagetext -text $d -image $img2 -data $d
  57. # We only want the user to select the directories that
  58. # ends by "lib"
  59. if {![string match "*lib" $d]} {
  60. $h entryconfig $d -state disabled -image $img1
  61. }
  62. }
  63. # We use a LabelEntry to hold the installation directory. The user
  64. # can choose from the DirList widget, or he can type in the directory
  65. # manually
  66. #
  67. tixLabelEntry $w.top.e -label "Installation Directory:" -labelside top \
  68. -options {
  69. entry.width 25
  70. entry.textVariable demo_hlist_dir
  71. label.anchor w
  72. }
  73. bind [$w.top.e subwidget entry] <Return> "hlist:okcmd $w"
  74. # Set the default value
  75. #
  76. uplevel #0 set demo_hlist_dir /usr/local/lib
  77. $h anchor set /usr/local/lib
  78. $h select set /usr/local/lib
  79. pack $w.top.h -side left -expand yes -fill both -padx 2 -pady 2
  80. pack $w.top.s -side left -fill y -pady 2
  81. pack $w.top.e -side left -expand yes -fill x -anchor s -padx 4 -pady 2
  82. # Use a ButtonBox to hold the buttons.
  83. #
  84. tixButtonBox $w.box -orientation horizontal
  85. $w.box add ok -text Ok -underline 0 -command "hlist:okcmd $w" \
  86. -width 6
  87. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  88. -width 6
  89. pack $w.box -side bottom -fill x
  90. pack $w.top -side top -fill both -expand yes
  91. }
  92. # In an actual program, you may want to tell the user how much space he has
  93. # left in this directory
  94. #
  95. #
  96. proc hlist1:browse {w dir} {
  97. global demo_hlist_dir
  98. set demo_hlist_dir [$w entrycget $dir -data]
  99. }
  100. # In an actual program, you will install your favorit application
  101. # in the selected directory
  102. #
  103. proc hlist1:activate {w dir} {
  104. global demo_hlist_dir
  105. set demo_hlist_dir [$w entrycget $dir -data]
  106. tixDemo:Status "You have selected the directory $demo_hlist_dir"
  107. destroy [winfo toplevel $w]
  108. }
  109. proc hlist:okcmd {w} {
  110. global demo_hlist_dir
  111. tixDemo:Status "You have selected the directory $demo_hlist_dir"
  112. destroy $w
  113. }
  114. set folder1 {
  115. #define foo_width 16
  116. #define foo_height 12
  117. static unsigned char foo_bits[] = {
  118. 0x00, 0x00, 0x00, 0x3e, 0xfe, 0x41, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
  119. 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};}
  120. set folder2 {
  121. #define foo_width 16
  122. #define foo_height 12
  123. static unsigned char foo_bits[] = {
  124. 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x02, 0x40, 0x02, 0x44, 0xf2, 0x4f,
  125. 0xf2, 0x5f, 0xf2, 0x4f, 0x02, 0x44, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};
  126. }
  127. # This "if" statement makes it possible to run this script file inside or
  128. # outside of the main demo program "widget".
  129. #
  130. if {![info exists tix_demo_running]} {
  131. wm withdraw .
  132. set w .demo
  133. toplevel $w; wm transient $w ""
  134. RunSample $w
  135. bind $w <Destroy> exit
  136. }