Debian Codegraph @

demos/busy1.tcl

raw
1 #!../src/bltwish
2
3 package require BLT
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.
9 #
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::"
12 #
13 # blt::graph .g
14 # blt::table . .g -resize both
15 #
16 # or you can import all the command into the global namespace.
17 #
18 # namespace import blt::*
19 # graph .g
20 # table . .g -resize both
21 #
22 # --------------------------------------------------------------------------
23
24 if { $tcl_version >= 8.0 } {
25 namespace import blt::*
26 namespace import -force blt::tile::*
27 }
28 source scripts/demo.tcl
29
30 #
31 # Script to test the "busy" command.
32 #
33
34 #
35 # General widget class resource attributes
36 #
37 option add *Button.padX 10
38 option add *Button.padY 2
39 option add *Scale.relief sunken
40 #option add *Scale.orient horizontal
41 option add *Entry.relief sunken
42 option add *Frame.borderWidth 2
43
44 set visual [winfo screenvisual .]
45 if { $visual == "staticgray" || $visual == "grayscale" } {
46 set activeBg black
47 set normalBg white
48 set bitmapFg black
49 set bitmapBg white
50 option add *f1.background white
51 } else {
52 set activeBg red
53 set normalBg springgreen
54 set bitmapFg blue
55 set bitmapBg green
56 option add *Button.background khaki2
57 option add *Button.activeBackground khaki1
58 option add *Frame.background khaki2
59 option add *f2.tile textureBg
60 # option add *Button.tile textureBg
61
62 option add *releaseButton.background limegreen
63 option add *releaseButton.activeBackground springgreen
64 option add *releaseButton.foreground black
65
66 option add *holdButton.background red
67 option add *holdButton.activeBackground pink
68 option add *holdButton.foreground black
69 option add *f1.background springgreen
70 }
71
72 #
73 # Instance specific widget options
74 #
75 option add *f1.relief sunken
76 option add *f1.background $normalBg
77 option add *testButton.text "Test"
78 option add *quitButton.text "Quit"
79 option add *newButton.text "New\nButton"
80 option add *holdButton.text "Hold"
81 option add *releaseButton.text "Release"
82 option add *buttonLabel.text "Buttons"
83 option add *entryLabel.text "Entries"
84 option add *scaleLabel.text "Scales"
85 option add *textLabel.text "Text"
86
87 bind keepRaised <Visibility> { raise %W }
88
89 proc KeepRaised { w } {
90 bindtags $w keepRaised
91 }
92
93 set file ./images/chalk.gif
94 image create photo textureBg -file $file
95
96 #
97 # This never gets used; it's reset by the Animate proc. It's
98 # here to just demonstrate how to set busy window options via
99 # the host window path name
100 #
101 #option add *f1.busyCursor bogosity
102
103 #
104 # Counter for new buttons created by the "New button" button
105 #
106 set numWin 0
107
108 #
109 # Create two frames. The top frame will be the host window for the
110 # busy window. It'll contain widgets to test the effectiveness of
111 # the busy window. The bottom frame will contain buttons to
112 # control the testing.
113 #
114 frame .f1
115 frame .f2
116
117 #
118 # Create some widgets to test the busy window and its cursor
119 #
120 label .buttonLabel
121 button .testButton -command {
122 puts stdout "Not busy."
123 }
124 button .quitButton -command { exit }
125 entry .entry
126 scale .scale
127 text .text -width 20 -height 4
128
129 #
130 # The following buttons sit in the lower frame to control the demo
131 #
132 button .newButton -command {
133 global numWin
134 incr numWin
135 set name button#${numWin}
136 button .f1.$name -text "$name" \
137 -command [list .f1 configure -bg blue]
138 table .f1 \
139 .f1.$name $numWin+3,0 -padx 10 -pady 10
140 }
141
142 button .holdButton -command {
143 if { [busy isbusy .f1] == "" } {
144 global activeBg
145 .f1 configure -bg $activeBg
146 }
147 busy .f1
148 focus -force .
149 }
150
151 button .releaseButton -command {
152 if { [busy isbusy .f1] == ".f1" } {
153 busy release .f1
154 }
155 global normalBg
156 .f1 configure -bg $normalBg
157 }
158
159 #
160 # Notice that the widgets packed in .f1 and .f2 are not their children
161 #
162 table .f1 \
163 0,0 .testButton \
164 1,0 .scale -fill y \
165 0,1 .entry -fill x \
166 1,1 .text -fill both \
167 2,0 .quitButton -cspan 2
168
169 table .f2 \
170 0,0 .holdButton \
171 0,1 .releaseButton \
172 0,2 .newButton
173
174 table configure .f1 \
175 .testButton .scale .entry .quitButton -padx 10 -pady 10
176 table configure .f2 \
177 .newButton .holdButton .releaseButton -padx 10 -pady 4 -reqwidth 1.i
178
179 table configure .f1 r0 r2 -resize none
180 table configure .f2 r* -resize none
181
182 #
183 # Finally, realize and map the top level window
184 #
185 table . \
186 0,0 .f1 -fill both \
187 1,0 .f2 -fill both
188
189 table configure . r1 -resize none
190
191 table configure .f1 c1 -weight 2.0
192
193 # Initialize a list of bitmap file names which make up the animated
194 # fish cursor. The bitmap mask files have a "m" appended to them.
195
196 set bitmapList {
197 left left1 mid right1 right
198 }
199
200 #
201 # Simple cursor animation routine: Uses the "after" command to
202 # circulate through a list of cursors every 0.075 seconds. The
203 # first pass through the cursor list may appear sluggish because
204 # the bitmaps have to be read from the disk. Tk's cursor cache
205 # takes care of it afterwards.
206 #
207 proc StartAnimation { widget count } {
208 global bitmapList
209 set prefix bitmaps/fish/[lindex $bitmapList $count]
210 set cursor [list @${prefix}.xbm ${prefix}m.xbm blue green ]
211 busy configure $widget -cursor $cursor
212
213 incr count
214 set limit [llength $bitmapList]
215 if { $count >= $limit } {
216 set count 0
217 }
218 global afterId
219 set afterId($widget) [after 125 StartAnimation $widget $count]
220 }
221
222 proc StopAnimation { widget } {
223 global afterId
224 after cancel $afterId($widget)
225 }
226
227 proc TranslateBusy { window } {
228 set widget [string trimright $window "_Busy"]
229 if { $widget != "." } {
230 set widget [string trimright $widget "."]
231 }
232 return $widget
233 }
234
235 if { [info exists tcl_platform] && $tcl_platform(platform) == "unix" } {
236 bind Busy <Map> {
237 StartAnimation [TranslateBusy %W] 0
238 }
239 bind Busy <Unmap> {
240 StopAnimation [TranslateBusy %W]
241 }
242 }
243
244 #
245 # For testing, allow the top level window to be resized
246 #
247 wm min . 0 0
248
249 #
250 # Force the demo to stay raised
251 #
252 raise .
253 KeepRaised .
254