tixwidgets.tcl 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # tixDemo --
  4. #
  5. # This is a demo program of all the available Tix widgets. If
  6. # have installed Tix properly, you can execute this program
  7. # by changing to this directory and executing
  8. # the following in csh
  9. #
  10. # % env TIX_LIBRARY=../library tixwish tixwidgets.tcl
  11. #
  12. # Or this in sh
  13. #
  14. # $ TIX_LIBRARY=../library tixwish tixwidgets.tcl
  15. #
  16. #----------------------------------------------------------------------
  17. #
  18. # This file has not been properly documented. It is NOT intended
  19. # to be used as an introductory demo program about Tix
  20. # programming. For such demos, please see the files in the
  21. # demos/samples directory or go to the "Samples" page in the
  22. # "widget demo"
  23. #
  24. #
  25. # Copyright (c) 1996, Expert Interface Technologies
  26. #
  27. # See the file "license.terms" for information on usage and redistribution
  28. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  29. #
  30. package require Tix
  31. tix initstyle
  32. tk appname "TixDemo#[pid]"
  33. proc tixDemo:MkMainWindow {w} {
  34. global demo auto_path demo_dir
  35. # add this directory to the auto_path
  36. lappend auto_path $demo_dir
  37. tix addbitmapdir [file join $demo_dir bitmaps]
  38. toplevel $w
  39. wm title $w "Tix Widget Demonstration"
  40. wm geometry $w 830x566+100+100
  41. set demo(balloon) [tixBalloon .demos_balloon]
  42. set menu [tixDemo:MkMainMenu $w]
  43. set frame2 [tixDemo:MkMainNoteBook $w]
  44. set frame3 [tixDemo:MkMainStatus $w]
  45. $w configure -menu $menu
  46. pack $frame3 -side bottom -fill x
  47. pack $frame2 -side top -expand yes -fill both -padx 4 -pady 4
  48. $demo(balloon) config -statusbar $demo(statusbar)
  49. set demo(notebook) $frame2
  50. }
  51. proc tixDemo:MkMainMenu {top} {
  52. global useBallons
  53. set m [menu $top.menu -tearoff 0]
  54. $m add cascade -label "File" -menu $m.file -underline 0
  55. $m add cascade -label "Help" -menu $m.help -underline 0
  56. menu $m.file -tearoff 0
  57. $m.file add command -label "Open ... " -command tixDemo:FileOpen \
  58. -underline 1 -accelerator "Ctrl+O"
  59. $m.file add sep
  60. $m.file add command -label "Exit " -command tixDemo:Exit \
  61. -underline 1 -accelerator "Ctrl+X"
  62. menu $m.help -tearoff 0
  63. $m.help add checkbutton -under 0 -label "Balloon Help " \
  64. -variable useBallons -onvalue 1 -offvalue 0
  65. trace variable useBallons w tixDemo:BalloonHelp
  66. set useBallons 1
  67. return $m
  68. }
  69. # Create the main display area of the widget programm. This area should
  70. # utilize the "tixNoteBook" widget once it is available. But now
  71. # we use the cheap substitute "tixStackWindow"
  72. #
  73. proc tixDemo:MkMainNoteBook {top} {
  74. global demo
  75. set hasGL 0
  76. option add *TixNoteBook.tagPadX 6
  77. option add *TixNoteBook.tagPadY 4
  78. option add *TixNoteBook.borderWidth 2
  79. set w [tixNoteBook $top.f2 -ipadx 5 -ipady 5]
  80. $w add wel -createcmd [list tixDemo:CreatePage tixDemo:MkWelcome $w wel] \
  81. -label "Welcome" -under 0
  82. $w add cho -createcmd [list tixDemo:CreatePage MkChoosers $w cho] \
  83. -label "Choosers" -under 0
  84. $w add scr -createcmd [list tixDemo:CreatePage MkScroll $w scr] \
  85. -label "Scrolled Widgets" -under 0
  86. # There currently is no MkManag.tcl that this expects ?!? - JH
  87. # $w add mgr -createcmd [list tixDemo:CreatePage MkManager $w mgr] \
  88. # -label "Manager Widgets" -under 0
  89. $w add dir -createcmd [list tixDemo:CreatePage MkDirList $w dir] \
  90. -label "Directory List" -under 0
  91. $w add exp -createcmd [list tixDemo:CreatePage MkSample $w exp] \
  92. -label "Run Sample Programs" -under 0
  93. if {$hasGL} {
  94. $w add glw -createcmd [list MkGL $w glw] -tag "GL Widgets"
  95. }
  96. return $w
  97. }
  98. proc tixDemo:CreatePage {command w name} {
  99. tixBusy $w on
  100. set code [catch {$command $w $name} err]
  101. tixBusy $w off
  102. return -code $code $err
  103. }
  104. proc tixDemo:MkMainStatus {top} {
  105. global demo demo_dir
  106. set w [frame $top.f3 -relief raised -bd 1]
  107. set demo(statusbar) \
  108. [label $w.status -relief sunken -bd 1]
  109. tixForm $demo(statusbar) -padx 3 -pady 3 -left 0 -right %70
  110. $w.status configure -text [file native $demo_dir]
  111. return $w
  112. }
  113. proc tixDemo:Status {msg} {
  114. global demo
  115. $demo(statusbar) configure -text $msg
  116. }
  117. proc tixDemo:MkWelcome {nb page} {
  118. set w [$nb subwidget $page]
  119. set bar [tixDemo:MkWelcomeBar $w]
  120. set text [tixDemo:MkWelcomeText $w]
  121. pack $bar -side top -fill x -padx 2 -pady 2
  122. pack $text -side top -fill both -expand yes
  123. }
  124. proc tixDemo:MkWelcomeBar {top} {
  125. global demo
  126. set w [frame $top.bar -bd 2 -relief groove]
  127. # Create and configure comboBox 1
  128. #
  129. tixComboBox $w.cbx1 -command [list tixDemo:MainTextFont $top] \
  130. -options {
  131. entry.width 15
  132. listbox.height 3
  133. }
  134. tixComboBox $w.cbx2 -command [list tixDemo:MainTextFont $top] \
  135. -options {
  136. entry.width 4
  137. listbox.height 3
  138. }
  139. set demo(welfont) $w.cbx1
  140. set demo(welsize) $w.cbx2
  141. $w.cbx1 insert end "Courier"
  142. $w.cbx1 insert end "Helvetica"
  143. $w.cbx1 insert end "Lucida"
  144. $w.cbx1 insert end "Times Roman"
  145. $w.cbx2 insert end 8
  146. $w.cbx2 insert end 10
  147. $w.cbx2 insert end 12
  148. $w.cbx2 insert end 14
  149. $w.cbx2 insert end 18
  150. $w.cbx1 pick 1
  151. $w.cbx2 pick 3
  152. # Pack the comboboxes together
  153. #
  154. pack $w.cbx1 $w.cbx2 -side left -padx 4 -pady 4
  155. $demo(balloon) bind $w.cbx1\
  156. -msg "Choose\na font" -statusmsg "Choose a font for this page"
  157. $demo(balloon) bind $w.cbx2\
  158. -msg "Point size" -statusmsg "Choose the font size for this page"
  159. tixDoWhenIdle tixDemo:MainTextFont $top
  160. return $w
  161. }
  162. proc tixDemo:MkWelcomeText {top} {
  163. global demo tix_version
  164. set w [tixScrolledWindow $top.f3 -scrollbar auto]
  165. set win [$w subwidget window]
  166. label $win.title -font [list times -18 bold] \
  167. -bd 0 -width 30 -anchor n\
  168. -text "Welcome to TIX version $tix_version"
  169. message $win.msg -font [list helvetica -14 bold] \
  170. -bd 0 -width 400 -anchor n\
  171. -text "\
  172. Tix $tix_version is a library of mega-widgets based on TK. This program \
  173. demonstrates the widgets in the Tix widget. You can choose the pages \
  174. in this window to look at the corresponding widgets. \
  175. To quit this program, choose the \"File | Exit\" command."
  176. pack $win.title -expand yes -fill both -padx 10 -pady 10
  177. pack $win.msg -expand yes -fill both -padx 10 -pady 10
  178. set demo(welmsg) $win.msg
  179. return $w
  180. }
  181. proc tixDemo:MainTextFont {w args} {
  182. global demo
  183. if {![info exists demo(welmsg)]} {
  184. return
  185. }
  186. set font [$demo(welfont) cget -value]
  187. set point [$demo(welsize) cget -value]
  188. case $font {
  189. "Courier" {
  190. set f courier
  191. }
  192. "Helvetica" {
  193. set f helvetica
  194. }
  195. "Lucida" {
  196. set f lucida
  197. }
  198. default {
  199. set f times
  200. }
  201. }
  202. set xfont [list $f -$point]
  203. if [catch {$demo(welmsg) config -font $xfont} err] {
  204. puts \a$err
  205. }
  206. }
  207. proc tixDemo:FileOpen {} {
  208. global demo demo_dir
  209. set filedlg [tix filedialog tixExFileSelectDialog]
  210. if {![info exists demo(filedialog)]} {
  211. $filedlg subwidget fsbox config -pattern *.tcl
  212. $filedlg subwidget fsbox config -directory [file join $demo_dir samples]
  213. $filedlg config -command tixDemo:FileOpen:Doit
  214. set demo(filedialog) $filedlg
  215. }
  216. $filedlg config -title "Open Tix Sample Programs"
  217. wm transient $filedlg ""
  218. wm deiconify $filedlg
  219. after idle raise $filedlg
  220. $filedlg popup
  221. tixPushGrab $filedlg
  222. }
  223. proc tixDemo:FileOpen:Doit {filename} {
  224. global demo
  225. tixPopGrab
  226. LoadFile $filename
  227. $demo(filedialog) popdown
  228. }
  229. #----------------------------------------------------------------------
  230. # Balloon Help
  231. #----------------------------------------------------------------------
  232. proc tixDemo:BalloonHelp {args} {
  233. global demo useBallons
  234. if {$useBallons} {
  235. $demo(balloon) config -state "both"
  236. } else {
  237. $demo(balloon) config -state "none"
  238. }
  239. }
  240. #----------------------------------------------------------------------
  241. # Self-testing
  242. #
  243. # The following code are called by the Tix test suite. It opens
  244. # every page in the demo program.
  245. #----------------------------------------------------------------------
  246. proc tixDemo:SelfTest {} {
  247. global demo testConfig
  248. if ![info exists testConfig] {
  249. return
  250. }
  251. tixDemo:MkMainWindow .widget
  252. update
  253. foreach p [$demo(notebook) pages] {
  254. $demo(notebook) raise $p
  255. update
  256. }
  257. destroy .widget
  258. }
  259. proc tixDemo:Exit {} {
  260. destroy .widget
  261. }
  262. #----------------------------------------------------------------------
  263. # Start!
  264. #----------------------------------------------------------------------
  265. if {![info exists testConfig]} {
  266. #
  267. # If the testConfig variable exists, we are driven by the regression
  268. # test. In that case, don't open the main window. The test program will
  269. # call Widget:SelfTest
  270. #
  271. set kids [winfo children .]
  272. wm withdraw .
  273. set ::demo_dir [file normalize [file dirname [info script]]]
  274. tixDemo:MkMainWindow .widget
  275. wm transient .widget ""
  276. if {[llength $kids] < 1} {bind .widget <Destroy> "exit"}
  277. }