4 # --------------------------------------------------------------------------
5 # Starting with Tcl 8.x, the BLT commands are stored in their own
6 # namespace called "blt". The idea is to prevent name clashes with
7 # Tcl commands and variables from other packages, such as a "table"
8 # command in two different packages.
10 # You can access the BLT commands in a couple of ways. You can prefix
11 # all the BLT commands with the namespace qualifier "blt::"
14 # blt::table . .g -resize both
16 # or you can import all the command into the global namespace.
18 # namespace import blt::*
20 # table . .g -resize both
22 # --------------------------------------------------------------------------
24 if { $tcl_version >= 8.0 } {
25 namespace import blt::*
26 namespace import -force blt::tile::*
29 source scripts/demo.tcl
30 source scripts/globe.tcl
32 option add *HighlightThickness 0
34 set program [info nameofexecutable]
35 if { [info exists tcl_platform ] } {
36 puts stderr $tcl_platform(platform)
37 if { $tcl_platform(platform) == "windows" } {
38 set shells [glob C:/Program\ Files/Tcl/bin/tclsh8*.exe ]
39 set program [lindex $shells 0]
42 if { ![file executable $program] } {
43 error "Can't execute $program"
46 set command [list $program scripts/bgtest.tcl]
51 colors "#ff8813 #ffaa13 #ffcc13 #ffff13 #ffcc13 #ffaa13 #ff8813"
58 if { [info commands .logo] != ".logo" } {
62 if { $animate(index) >= 0 } {
63 .logo configure -bitmap $animate(prefix).$animate(index)
65 if { $animate(index) >= $animate(numBitmaps) } {
68 after $animate(interval) Animate
72 proc InsertText { string tag } {
73 .text insert end "$tag: " "" $string $tag
74 set textlen [expr int([.text index end])]
75 scan [.vscroll get] "%s %s %s %s" total window first last
76 if { $textlen > $total } {
77 .text yview [expr $textlen-$window]
82 proc DisplayOutput { name1 name2 how } {
85 InsertText "$arr($name2)\n" stdout
89 proc DisplayErrors { name1 name2 how } {
92 InsertText "$arr($name2)\n" stderr
97 option add *text.yScrollCommand { .vscroll set }
98 option add *text.relief sunken
99 option add *text.width 20
100 option add *text.height 10
101 option add *text.height 10
102 option add *text.borderWidth 2
103 option add *vscroll.command { .text yview }
104 option add *vscroll.minSlider 4p
105 option add *stop.command { set results {} }
106 option add *stop.text { stop }
107 option add *logo.padX 4
108 option add *title.text "Catching stdout and stderr"
109 option add *title.font -*-Helvetica-Bold-R-*-*-14-*-*-*-*-*-*-*
111 set visual [winfo screenvisual .]
112 if { [string match *color $visual] } {
113 option add *text.background white
114 option add *text.foreground blue
115 option add *stop.background yellow
116 option add *stop.activeBackground yellow2
117 option add *stop.foreground navyblue
118 option add *start.activeBackground green2
119 option add *start.background green
120 option add *start.foreground navyblue
121 option add *logo.background beige
122 option add *logo.foreground brown
123 option add *logo.foreground green4
124 option add *title.background lightblue
125 option add *logo.background lightblue
127 . configure -bg lightblue
129 trace variable results(stdout) w DisplayOutput
130 trace variable results(stderr) w DisplayErrors
132 proc Start { command } {
133 global results animate
135 if { $animate(index) < 0 } {
136 set results(status) {}
137 eval "bgexec results(status) -lasterror results(stderr) \
138 -lastoutput results(stdout) $command &"
145 global results animate
146 set results(status) {}
147 set animate(index) -1
152 .text tag configure stdout -font -*-Helvetica-Bold-R-*-*-18-*-*-*-*-*-*-* \
154 .text tag configure stderr -font -*-Helvetica-Medium-O-*-*-18-*-*-*-*-*-*-* \
158 button .start -text "Start" -command [list Start $command]
159 button .stop -text "Stop" -command Stop
160 label .logo -bitmap globe.0
163 # Layout widgets in table
165 .title 0,0 -columnspan 4 \
166 .text 1,0 -columnspan 3 \
167 .vscroll 1,3 -fill y \
168 .logo 2,0 -anchor w -padx 10 -reqheight .6i -pady 4 \
173 table configure . c1 c2 -width 1i
174 table configure . c3 r0 r2 -resize none
175 table configure . .start .stop -reqwidth $buttonWidth -anchor e
176 table configure . .title .text -fill both