author | Claus Gittinger <cg@exept.de> |
Mon, 06 Mar 2006 09:55:21 +0100 | |
changeset 2931 | 74fc63bea835 |
parent 2921 | 1e8c394e895e |
child 3425 | 20459e327062 |
permissions | -rw-r--r-- |
62 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
50 | 12 |
|
2563 | 13 |
"{ Package: 'stx:libwidg2' }" |
1789 | 14 |
|
50 | 15 |
View subclass:#ProgressIndicator |
826 | 16 |
instanceVariableNames:'percentage showPercentage fgColor bgColor connectedTop |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
17 |
connectedLabel collector finishAction closeTopWhenDone showBusy |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
18 |
busyPosition busyDelta busyIndicationProcess' |
183 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Views-Misc' |
|
50 | 22 |
! |
23 |
||
334 | 24 |
!ProgressIndicator class methodsFor:'documentation'! |
50 | 25 |
|
62 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
50 | 40 |
documentation |
41 |
" |
|
42 |
a view showing a rectangle filled according the percentage value. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
43 |
Can be used as a progress indicator a la MSwindows; |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
44 |
it can also be configured as a non-percentage busy indication |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
45 |
via the showBusyIndication flag (a la netscape). |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
46 |
|
574 | 47 |
Can be used as a widget within an application, or |
48 |
via the convenient #inBox: instance creation messages, |
|
49 |
which shows a progressDisplay in a modalBox, while some |
|
50 |
action is performed. |
|
51 |
See examples. |
|
183 | 52 |
|
53 |
[author:] |
|
2563 | 54 |
Claus Gittinger |
183 | 55 |
|
56 |
[see also:] |
|
2563 | 57 |
ActionWaitBox AnimatedLabel |
50 | 58 |
" |
59 |
! |
|
60 |
||
61 |
examples |
|
62 |
" |
|
62 | 63 |
basic (internal) interface |
64 |
(if progress indicator is to be used in a complex box ...): |
|
50 | 65 |
|
183 | 66 |
Before you get frustrated - see the convenient-interface examples |
67 |
at the end ;-) |
|
68 |
||
2563 | 69 |
[exBegin] |
50 | 70 |
|top p h| |
71 |
||
62 | 72 |
top := ModalBox new. |
50 | 73 |
top extent:300@100. |
74 |
top label:'Progress'. |
|
75 |
p := ProgressIndicator in:top. |
|
76 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
77 |
p level:-1. |
|
62 | 78 |
h := p preferredExtent y. |
50 | 79 |
p topInset:(h // 2) negated; |
2563 | 80 |
bottomInset:(h // 2) negated; |
81 |
leftInset:5; |
|
82 |
rightInset:5. |
|
50 | 83 |
|
84 |
[ |
|
2563 | 85 |
1 to:100 do:[:val | |
86 |
(Delay forSeconds:0.05) wait. |
|
87 |
p percentage:val |
|
88 |
]. |
|
89 |
top hide. |
|
62 | 90 |
] fork. |
91 |
top open. |
|
2563 | 92 |
[exEnd] |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
93 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
94 |
as a busy indicator |
2563 | 95 |
[exBegin] |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
96 |
|top p h| |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
97 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
98 |
top := ModalBox new. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
99 |
top extent:300@100. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
100 |
top label:'Busy'. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
101 |
p := ProgressIndicator in:top. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
102 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
103 |
p level:-1. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
104 |
h := p preferredExtent y. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
105 |
p topInset:(h // 2) negated; |
2563 | 106 |
bottomInset:(h // 2) negated; |
107 |
leftInset:5; |
|
108 |
rightInset:5. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
109 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
110 |
p showBusyIndication:true. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
111 |
[ |
2563 | 112 |
'do something here ....'. |
113 |
(Delay forSeconds:5) wait. |
|
114 |
top hide. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
115 |
] fork. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
116 |
top open. |
2563 | 117 |
[exEnd] |
50 | 118 |
|
119 |
changing colors, turning percentage display off: |
|
2563 | 120 |
[exBegin] |
50 | 121 |
|top p h| |
122 |
||
123 |
top := StandardSystemView new. |
|
124 |
top extent:300@100. |
|
125 |
top label:'Progress'. |
|
126 |
p := ProgressIndicator in:top. |
|
127 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
128 |
p level:-1. |
|
129 |
p showPercentage:false. |
|
130 |
p foregroundColor:(Color red). |
|
131 |
h := 10. |
|
132 |
p topInset:(h // 2) negated; |
|
2563 | 133 |
bottomInset:(h // 2) negated; |
134 |
leftInset:5; |
|
135 |
rightInset:5. |
|
50 | 136 |
top open. |
137 |
[ |
|
2563 | 138 |
1 to:100 do:[:val | |
139 |
(Delay forSeconds:0.05) wait. |
|
140 |
p percentage:val |
|
141 |
] |
|
50 | 142 |
] fork |
2563 | 143 |
[exEnd] |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
144 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
145 |
as a busy indicator and percentage display (as in netscape) |
2563 | 146 |
[exBegin] |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
147 |
|top p h| |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
148 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
149 |
top := ModalBox new. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
150 |
top extent:300@60. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
151 |
top label:'Busy'. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
152 |
p := ProgressIndicator in:top. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
153 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
154 |
p level:-1. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
155 |
p showPercentage:false. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
156 |
p backgroundColor:(Color cyan). |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
157 |
h := p preferredExtent y. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
158 |
p topInset:(h // 3) negated; |
2563 | 159 |
bottomInset:(h // 3) negated; |
160 |
leftInset:5; |
|
161 |
rightInset:5. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
162 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
163 |
p showBusyIndication:true. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
164 |
[ |
2563 | 165 |
top label:'Busy'. |
166 |
1 to:100 do:[:i | |
|
167 |
(Delay forSeconds:0.05) wait. |
|
168 |
]. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
169 |
|
2563 | 170 |
top label:'Percentage'. |
171 |
p showBusyIndication:false. |
|
172 |
1 to:100 do:[:i | |
|
173 |
(Delay forSeconds:0.05) wait. |
|
174 |
p percentage:i. |
|
175 |
]. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
176 |
|
2563 | 177 |
top hide. |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
178 |
] fork. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
179 |
top open. |
2563 | 180 |
[exEnd] |
50 | 181 |
|
182 |
with border (2D look): |
|
2563 | 183 |
[exBegin] |
50 | 184 |
|top p h| |
185 |
||
186 |
top := StandardSystemView new. |
|
187 |
top extent:300@100. |
|
188 |
top label:'Progress'. |
|
189 |
p := ProgressIndicator in:top. |
|
190 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
191 |
p borderWidth:1. |
|
62 | 192 |
h := p preferredExtent y. |
50 | 193 |
p topInset:(h // 2) negated; |
2563 | 194 |
bottomInset:(h // 2) negated; |
195 |
leftInset:5; |
|
196 |
rightInset:5. |
|
50 | 197 |
top open. |
198 |
[ |
|
2563 | 199 |
1 to:100 do:[:val | |
200 |
(Delay forSeconds:0.05) wait. |
|
201 |
p percentage:val |
|
202 |
] |
|
50 | 203 |
] fork |
2563 | 204 |
[exEnd] |
50 | 205 |
|
206 |
||
207 |
getting progress from a model: |
|
2563 | 208 |
[exBegin] |
50 | 209 |
|model top p h| |
210 |
||
211 |
model := 0 asValue. |
|
212 |
||
213 |
top := StandardSystemView new. |
|
214 |
top extent:300@100. |
|
215 |
top label:'Progress'. |
|
216 |
p := ProgressIndicator in:top. |
|
217 |
p model:model. |
|
218 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
219 |
p level:-1. |
|
62 | 220 |
h := p preferredExtent y. |
50 | 221 |
p topInset:(h // 2) negated; |
2563 | 222 |
bottomInset:(h // 2) negated; |
223 |
leftInset:5; |
|
224 |
rightInset:5. |
|
50 | 225 |
top open. |
226 |
||
227 |
[ |
|
2563 | 228 |
1 to:100 do:[:val | |
229 |
(Delay forSeconds:0.05) wait. |
|
230 |
model value:val |
|
231 |
] |
|
50 | 232 |
] fork |
2563 | 233 |
[exEnd] |
50 | 234 |
|
62 | 235 |
|
50 | 236 |
concrete example: |
237 |
search all files in the source directory for a string |
|
238 |
using grep. Show progress while doing so. |
|
2563 | 239 |
[exBegin] |
50 | 240 |
|top p h names done| |
241 |
||
242 |
top := StandardSystemView new. |
|
243 |
top extent:300@100. |
|
244 |
top label:'Searching ...'. |
|
245 |
p := ProgressIndicator in:top. |
|
246 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
247 |
p level:-1. |
|
62 | 248 |
h := p preferredExtent y. |
50 | 249 |
p topInset:(h // 2) negated; |
2563 | 250 |
bottomInset:(h // 2) negated; |
251 |
leftInset:5; |
|
252 |
rightInset:5. |
|
50 | 253 |
top openWithPriority:(Processor activePriority + 1). |
254 |
||
255 |
names := 'source' asFilename directoryContents. |
|
256 |
done := 0. |
|
257 |
names do:[:aName | |
|
2563 | 258 |
|fn stream line| |
50 | 259 |
|
2563 | 260 |
p percentage:(done / names size * 100). |
261 |
fn := ('source/' , aName) asFilename. |
|
262 |
fn isDirectory ifFalse:[ |
|
263 |
stream := fn readStream. |
|
264 |
[stream atEnd] whileFalse:[ |
|
265 |
line := stream nextLine. |
|
266 |
(line findString:'subclass:') ~~ 0 ifTrue:[ |
|
267 |
Transcript showCR:line |
|
268 |
]. |
|
269 |
]. |
|
270 |
stream close. |
|
271 |
]. |
|
272 |
done := done + 1 |
|
50 | 273 |
]. |
274 |
||
275 |
top destroy |
|
2563 | 276 |
[exEnd] |
62 | 277 |
|
278 |
||
279 |
using the convenient inBox-interface |
|
280 |
||
281 |
(this creates a box and an activity label and evaluates a block |
|
282 |
to indicate ...) |
|
283 |
||
284 |
basic interface demonstration: |
|
2563 | 285 |
[exBegin] |
62 | 286 |
|p| |
287 |
||
288 |
p := ProgressIndicator |
|
2563 | 289 |
inBoxWithLabel:'doing something ...' |
290 |
abortable:true. |
|
62 | 291 |
p showProgressOf: |
2563 | 292 |
[:progressValue :currentAction | |
62 | 293 |
|
2563 | 294 |
1 to:100 do:[:val | |
295 |
(Delay forSeconds:0.05) wait. |
|
296 |
val == 25 ifTrue:[ |
|
297 |
currentAction value:'still going ...' |
|
298 |
]. |
|
299 |
val == 50 ifTrue:[ |
|
300 |
currentAction value:'halfway through ...' |
|
301 |
]. |
|
302 |
val == 75 ifTrue:[ |
|
303 |
currentAction value:'almost finished ...' |
|
304 |
]. |
|
305 |
progressValue value:val |
|
306 |
] |
|
307 |
] |
|
308 |
[exEnd] |
|
62 | 309 |
|
310 |
||
311 |
above search example using this convenient interface: |
|
2563 | 312 |
[exBegin] |
62 | 313 |
|p| |
314 |
||
183 | 315 |
p := ProgressIndicator |
2563 | 316 |
inBoxWithLabel:'searching files ...' |
317 |
abortable:false. |
|
62 | 318 |
p showProgressOf: |
2563 | 319 |
[:progressValue :currentAction | |
320 |
|names nDone| |
|
62 | 321 |
|
2563 | 322 |
names := 'source' asFilename directoryContents. |
323 |
nDone := 0. |
|
324 |
names do:[:aName | |
|
325 |
|fn stream line| |
|
183 | 326 |
|
2563 | 327 |
progressValue value:(nDone / names size * 100). |
328 |
currentAction value:'searching ' , 'source/' , aName , ' ...'. |
|
62 | 329 |
|
2563 | 330 |
fn := ('source/' , aName) asFilename. |
331 |
fn isDirectory ifFalse:[ |
|
332 |
stream := fn readStream. |
|
333 |
[stream atEnd] whileFalse:[ |
|
334 |
line := stream nextLine. |
|
335 |
(line findString:'subclass:') ~~ 0 ifTrue:[ |
|
336 |
Transcript showCR:line |
|
337 |
]. |
|
338 |
]. |
|
339 |
stream close. |
|
340 |
]. |
|
341 |
nDone := nDone + 1 |
|
342 |
]. |
|
343 |
]. |
|
344 |
[exEnd] |
|
62 | 345 |
|
346 |
||
347 |
a nice example: copying files a la windows ... |
|
183 | 348 |
the following copies all files to /dev/null. |
2563 | 349 |
[exBegin] |
62 | 350 |
|p| |
351 |
||
352 |
(ProgressIndicator |
|
2563 | 353 |
inBoxWithLabel:'copy files to /dev/null ...' |
354 |
abortable:true) |
|
355 |
showProgressOf: |
|
356 |
[:progressValue :currentAction | |
|
357 |
|files nFiles nDone| |
|
62 | 358 |
|
2563 | 359 |
files := '.' asFilename directoryContents. |
360 |
nFiles := files size. |
|
361 |
nDone := 0. |
|
362 |
files do:[:aFileName | |
|
363 |
|percent| |
|
50 | 364 |
|
2563 | 365 |
nDone := nDone + 1. |
366 |
percent := nDone / nFiles * 100. |
|
367 |
progressValue value:percent. |
|
368 |
aFileName asFilename isDirectory ifTrue:[ |
|
369 |
Transcript showCR:('skipping ' , aFileName , ' ...'). |
|
370 |
currentAction value:('skipping ' , aFileName , ' ...'). |
|
371 |
] ifFalse:[ |
|
372 |
Transcript showCR:('copying ' , aFileName , ' ...'). |
|
373 |
currentAction value:('copying ' , aFileName , ' ...'). |
|
374 |
Object errorSignal handle:[:ex | |
|
375 |
self warn:'an error occurred while copying ' , aFileName. |
|
376 |
ex return |
|
377 |
] do:[ |
|
378 |
aFileName asFilename copyTo:'/dev/null'. |
|
379 |
] |
|
380 |
]. |
|
381 |
]. |
|
382 |
]. |
|
383 |
[exEnd] |
|
183 | 384 |
" |
50 | 385 |
! ! |
386 |
||
334 | 387 |
!ProgressIndicator class methodsFor:'instance creation'! |
62 | 388 |
|
2850 | 389 |
displayBusyIndicator:aLabel at:aPoint during:aBlock |
390 |
"easy interface - show progress while evaluating aBlock. |
|
391 |
The block is passed a valueHolder, which is to be set to values from |
|
392 |
startValue to endValue during the blocks evaluation. |
|
393 |
This is scaled to 0..100% completion. |
|
394 |
Set the valueHolder to nil, to get a busy-indicator" |
|
395 |
||
396 |
|p| |
|
397 |
||
398 |
p := self |
|
399 |
inBoxWithLabel:aLabel |
|
400 |
icon:nil |
|
401 |
text:aLabel |
|
402 |
abortable:false |
|
403 |
view:nil |
|
404 |
closeWhenDone:true. |
|
405 |
||
406 |
p showBusyIndication:true. |
|
407 |
p showBusyIndicatorDuring:[ |
|
2931 | 408 |
CannotReturnError catch:[ |
2850 | 409 |
aBlock value. |
410 |
] |
|
411 |
] |
|
412 |
||
413 |
" |
|
414 |
ProgressIndicator |
|
415 |
displayBusyIndicator:'doobidoobidoo...' |
|
416 |
at:(Screen default center) |
|
417 |
during:[ |
|
418 |
200 to:400 by:5 do:[:i | |
|
419 |
Delay waitForSeconds:0.1. |
|
420 |
] |
|
421 |
]. |
|
422 |
" |
|
423 |
! |
|
424 |
||
1462 | 425 |
displayProgress:aLabel at:aPoint from:startValue to:endValue during:aBlock |
426 |
"easy interface - show progress while evaluating aBlock. |
|
427 |
The block is passed a valueHolder, which is to be set to values from |
|
428 |
startValue to endValue during the blocks evaluation. |
|
2435 | 429 |
This is scaled to 0..100% completion. |
430 |
Set the valueHolder to nil, to get a busy-indicator" |
|
1462 | 431 |
|
432 |
|p| |
|
433 |
||
434 |
p := self |
|
2931 | 435 |
inBoxWithLabel:aLabel |
436 |
icon:nil |
|
437 |
text:aLabel |
|
438 |
abortable:false |
|
439 |
view:nil |
|
440 |
closeWhenDone:true. |
|
1462 | 441 |
|
442 |
p showProgressOf:[:progressValue :currentAction | |
|
2931 | 443 |
|scaler| |
1463 | 444 |
|
2931 | 445 |
scaler := [:scaledValue | |
446 |
|newPercentage oldPercentage oldLabel| |
|
2435 | 447 |
|
2931 | 448 |
scaledValue isNil ifTrue:[ |
449 |
p showBusyIndication:true |
|
450 |
] ifFalse:[ |
|
451 |
p showBusyIndication:false. |
|
452 |
oldPercentage := progressValue value. |
|
453 |
newPercentage := (scaledValue - startValue) / (endValue-startValue) * 100. |
|
454 |
newPercentage ~= oldPercentage ifTrue:[ |
|
455 |
progressValue value:newPercentage. |
|
456 |
]. |
|
457 |
oldLabel := currentAction value. |
|
458 |
oldLabel ~= aLabel ifTrue:[ |
|
459 |
currentAction value:aLabel. |
|
460 |
] |
|
461 |
] |
|
462 |
]. |
|
463 |
CannotReturnError catch:[ |
|
464 |
aBlock value:scaler. |
|
465 |
] |
|
1462 | 466 |
] |
467 |
||
468 |
" |
|
469 |
ProgressIndicator |
|
2931 | 470 |
displayProgress:'doobidoobidoo...' |
471 |
at:(Screen default center) |
|
472 |
from:200 |
|
473 |
to:400 |
|
474 |
during:[:val | |
|
475 |
200 to:400 by:5 do:[:i | |
|
476 |
val value:i. |
|
477 |
Delay waitForSeconds:0.1. |
|
478 |
] |
|
479 |
]. |
|
1462 | 480 |
" |
481 |
! |
|
482 |
||
62 | 483 |
inBox |
574 | 484 |
"create a topView containing an instance of myself, |
485 |
for later use with #showProgressOf:" |
|
486 |
||
487 |
^ self inBoxWithLabel:'executing ...' abortable:false |
|
488 |
||
489 |
"Modified: 22.10.1997 / 21:08:37 / cg" |
|
62 | 490 |
! |
491 |
||
492 |
inBoxWithLabel:aLabel |
|
493 |
"create a topView containing an instance of myself, |
|
494 |
for later use with #showProgressOf:" |
|
495 |
||
496 |
^ self inBoxWithLabel:aLabel abortable:false |
|
497 |
! |
|
498 |
||
499 |
inBoxWithLabel:aLabel abortable:abortable |
|
500 |
"create a topView containing an instance of myself, |
|
501 |
for later use with #showProgressOf:" |
|
502 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
503 |
^ self |
634 | 504 |
inBoxWithLabel:aLabel |
505 |
text:'' |
|
506 |
abortable:abortable |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
507 |
|
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
508 |
"Modified: 17.7.1996 / 15:14:58 / cg" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
509 |
! |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
510 |
|
237 | 511 |
inBoxWithLabel:aLabel icon:anIcon text:text abortable:abortable view:additionalView closeWhenDone:closeWhenDoneBoolean |
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
512 |
"create a topView containing an instance of myself, |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
513 |
for later use with #showProgressOf:" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
514 |
|
2436 | 515 |
|top p l y y2| |
62 | 516 |
|
517 |
top := Dialog new. |
|
518 |
top label:aLabel. |
|
519 |
top cursor:(Cursor wait). |
|
826 | 520 |
y2 := 0. |
237 | 521 |
anIcon notNil ifTrue:[ |
2563 | 522 |
y := top yPosition. |
523 |
l := top addTextLabel:anIcon. |
|
524 |
l borderWidth:0. |
|
525 |
l adjust:#left. |
|
526 |
l cursor:(Cursor wait). |
|
527 |
y2 := top yPosition. |
|
528 |
top yPosition:y. |
|
237 | 529 |
]. |
530 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
531 |
l := top addTextLabel:text. |
62 | 532 |
l borderWidth:0. |
74 | 533 |
l adjust:#left. |
62 | 534 |
l cursor:(Cursor wait). |
826 | 535 |
anIcon notNil ifTrue: [l leftInset:(anIcon width + 10)]. |
237 | 536 |
|
537 |
top yPosition:(top yPosition max:y2). |
|
62 | 538 |
|
539 |
top addVerticalSpace. |
|
540 |
||
541 |
p := ProgressIndicator new. |
|
542 |
p extent:(1.0 @ p preferredExtent y). |
|
543 |
p level:-1. |
|
544 |
p leftInset:5; |
|
545 |
rightInset:5. |
|
546 |
p cursor:(Cursor wait). |
|
237 | 547 |
p closeTopWhenDone:closeWhenDoneBoolean. |
62 | 548 |
p connectToTop:top label:l. |
549 |
||
550 |
top addComponent:p. |
|
551 |
||
237 | 552 |
additionalView notNil ifTrue:[ |
2563 | 553 |
top addComponent:additionalView. |
554 |
additionalView extent:(1.0 @ additionalView preferredExtent y). |
|
237 | 555 |
]. |
556 |
||
62 | 557 |
abortable ifTrue:[ |
2563 | 558 |
top addVerticalSpace. |
559 |
top addAbortButton |
|
62 | 560 |
]. |
561 |
||
562 |
^ p |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
563 |
|
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
564 |
"Created: 17.7.1996 / 15:14:33 / cg" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
565 |
"Modified: 17.7.1996 / 15:16:58 / cg" |
237 | 566 |
! |
567 |
||
568 |
inBoxWithLabel:aLabel text:text abortable:abortable |
|
569 |
"create a topView containing an instance of myself, |
|
570 |
for later use with #showProgressOf:" |
|
571 |
||
572 |
^ self |
|
634 | 573 |
inBoxWithLabel:aLabel |
574 |
text:text |
|
575 |
abortable:abortable |
|
576 |
view:nil |
|
237 | 577 |
|
578 |
! |
|
579 |
||
580 |
inBoxWithLabel:aLabel text:text abortable:abortable view:additionalView |
|
581 |
"create a topView containing an instance of myself, |
|
582 |
for later use with #showProgressOf:" |
|
583 |
||
584 |
^ self |
|
634 | 585 |
inBoxWithLabel:aLabel |
586 |
text:text |
|
587 |
abortable:abortable |
|
588 |
view:additionalView |
|
589 |
closeWhenDone:true |
|
237 | 590 |
|
591 |
! |
|
592 |
||
593 |
inBoxWithLabel:aLabel text:text abortable:abortable view:additionalView closeWhenDone:closeWhenDoneBoolean |
|
594 |
"create a topView containing an instance of myself, |
|
595 |
for later use with #showProgressOf:" |
|
596 |
||
597 |
^ self |
|
634 | 598 |
inBoxWithLabel:aLabel |
599 |
icon:nil |
|
600 |
text:text |
|
601 |
abortable:abortable |
|
602 |
view:additionalView |
|
603 |
closeWhenDone:closeWhenDoneBoolean |
|
237 | 604 |
|
1681
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
605 |
! |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
606 |
|
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
607 |
progressOpenOn:progressModel label:aLabel |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
608 |
"create and open a progressIndicator dialog window, |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
609 |
bit do not open it modal; instead, it is opened modeless |
1834
ba170c21ed76
defaultExtent computation fixed
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
610 |
and control returns to the caller. |
1681
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
611 |
The models value is assumed to be 0..1 |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
612 |
(which is for compatibility and different from ST/X's percentage use) |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
613 |
Added for VW compatibility (RB)." |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
614 |
|
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
615 |
|p ra| |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
616 |
|
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
617 |
p := self |
2563 | 618 |
inBoxWithLabel:aLabel |
619 |
icon:nil |
|
620 |
text:aLabel |
|
621 |
abortable:false |
|
622 |
view:nil |
|
623 |
closeWhenDone:false. |
|
1681
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
624 |
|
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
625 |
ra := RangeAdaptor on:progressModel start:0 stop:0.01 grid:nil. |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
626 |
p model:ra. |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
627 |
|
2132 | 628 |
p topView openModeless; waitUntilVisible. |
1681
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
629 |
^ p. |
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
630 |
|
9ef9e8ec0f43
progressOpenOn:label: for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
631 |
"Modified: / 4.2.2000 / 01:25:55 / cg" |
62 | 632 |
! ! |
633 |
||
183 | 634 |
!ProgressIndicator methodsFor:'accessing'! |
635 |
||
334 | 636 |
percentage:aNumber |
637 |
"set the percentage" |
|
237 | 638 |
|
183 | 639 |
|newPercentage| |
640 |
||
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
641 |
aNumber < 0 ifTrue:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
642 |
newPercentage := -1. |
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
643 |
] ifFalse:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
644 |
newPercentage := ((aNumber max:0) min:100) rounded. |
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
645 |
]. |
910
5c9592e782fd
always repairNow (to make change visible immediately)
Claus Gittinger <cg@exept.de>
parents:
865
diff
changeset
|
646 |
newPercentage ~= percentage ifTrue:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
647 |
percentage := newPercentage. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
648 |
self invalidateRepairNow:true. |
183 | 649 |
] |
334 | 650 |
|
910
5c9592e782fd
always repairNow (to make change visible immediately)
Claus Gittinger <cg@exept.de>
parents:
865
diff
changeset
|
651 |
"Modified: / 6.6.1998 / 19:43:56 / cg" |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
652 |
! |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
653 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
654 |
showBusyIndication:aBooleanHolder |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
655 |
"switch between percentage mode (if false) and busy indication (if true)" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
656 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
657 |
aBooleanHolder ~~ showBusy ifTrue:[ |
2563 | 658 |
showBusy notNil ifTrue:[ |
659 |
showBusy removeDependent:self. |
|
660 |
]. |
|
661 |
showBusy := aBooleanHolder. |
|
662 |
showBusy addDependent:self. |
|
663 |
(showBusy value) ifTrue:[ |
|
664 |
self startBusyIndicationProcess. |
|
665 |
] ifFalse:[ |
|
666 |
self stopBusyIndicationProcess |
|
667 |
]. |
|
668 |
shown ifTrue:[self redraw] |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
669 |
]. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
670 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
671 |
"Created: / 21.10.1998 / 17:35:16 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
672 |
"Modified: / 21.10.1998 / 18:03:06 / cg" |
334 | 673 |
! ! |
674 |
||
2404 | 675 |
!ProgressIndicator methodsFor:'accessing-behavior'! |
676 |
||
677 |
closeTopWhenDone:aBoolean |
|
678 |
"set/clear the close-topView-when-done flag" |
|
679 |
||
680 |
closeTopWhenDone := aBoolean |
|
681 |
||
682 |
"Created: 3.9.1996 / 14:22:03 / cg" |
|
683 |
"Modified: 29.3.1997 / 16:08:19 / cg" |
|
684 |
! |
|
685 |
||
686 |
finishAction:aBlock |
|
687 |
"define an action to be performed when finished" |
|
688 |
||
689 |
finishAction := aBlock |
|
690 |
||
691 |
"Created: 3.9.1996 / 14:15:15 / cg" |
|
692 |
"Modified: 29.3.1997 / 16:08:35 / cg" |
|
693 |
! ! |
|
694 |
||
695 |
!ProgressIndicator methodsFor:'accessing-look'! |
|
334 | 696 |
|
826 | 697 |
backgroundColor |
698 |
"return the percentage displays background color" |
|
699 |
||
700 |
^ bgColor |
|
701 |
||
702 |
! |
|
703 |
||
704 |
backgroundColor:aColor |
|
705 |
"set the percentage displays background color" |
|
706 |
||
993 | 707 |
aColor ~= bgColor ifTrue:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
708 |
bgColor := aColor. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
709 |
self invalidateRepairNow:true |
826 | 710 |
]. |
711 |
||
993 | 712 |
"Modified: / 20.7.1998 / 23:32:48 / cg" |
826 | 713 |
! |
714 |
||
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
715 |
foregroundColor |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
716 |
"return the percentage displays foreground color" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
717 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
718 |
^ fgColor |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
719 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
720 |
"Created: 29.3.1997 / 16:12:28 / cg" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
721 |
! |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
722 |
|
334 | 723 |
foregroundColor:aColor |
724 |
"set the percentage displays foreground color" |
|
725 |
||
993 | 726 |
aColor ~= fgColor ifTrue:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
727 |
fgColor := aColor. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
728 |
self invalidateRepairNow:true |
336 | 729 |
]. |
334 | 730 |
|
993 | 731 |
"Modified: / 20.7.1998 / 23:27:47 / cg" |
183 | 732 |
! |
733 |
||
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
734 |
showPercentage |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
735 |
"return the flag controlling if the percentage is to be shown numerically" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
736 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
737 |
^ showPercentage |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
738 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
739 |
"Created: 29.3.1997 / 16:12:39 / cg" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
740 |
! |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
741 |
|
183 | 742 |
showPercentage:aBoolean |
334 | 743 |
"set/clear the flag controlling if the percentage is to be shown numerically" |
744 |
||
336 | 745 |
showPercentage := aBoolean. |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
746 |
self invalidateRepairNow:true |
334 | 747 |
|
910
5c9592e782fd
always repairNow (to make change visible immediately)
Claus Gittinger <cg@exept.de>
parents:
865
diff
changeset
|
748 |
"Modified: / 6.6.1998 / 19:28:44 / cg" |
183 | 749 |
! ! |
750 |
||
751 |
!ProgressIndicator methodsFor:'change & update'! |
|
752 |
||
753 |
update:aspect with:aParameter from:changedObject |
|
574 | 754 |
"react upon value changes of my model" |
755 |
||
183 | 756 |
(aspect == aspectMsg |
757 |
and:[changedObject == model]) ifTrue:[ |
|
2563 | 758 |
self percentage:(model perform:aspectMsg). |
759 |
^ self |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
760 |
]. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
761 |
changedObject == showBusy ifTrue:[ |
2563 | 762 |
self redraw. |
763 |
^ self |
|
183 | 764 |
]. |
765 |
^ super update:aspect with:aParameter from:changedObject |
|
574 | 766 |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
767 |
"Modified: / 21.10.1998 / 18:01:52 / cg" |
183 | 768 |
! ! |
769 |
||
770 |
!ProgressIndicator methodsFor:'drawing'! |
|
771 |
||
772 |
redraw |
|
574 | 773 |
"redraw the percentage bar and optional percentage string" |
774 |
||
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
775 |
|s lx rx sx sy sw m2 m w h doBusy| |
183 | 776 |
|
777 |
m := margin + 1. |
|
863 | 778 |
m2 := m*2. |
779 |
||
780 |
w := width - m2. |
|
781 |
h := height - m2. |
|
183 | 782 |
|
910
5c9592e782fd
always repairNow (to make change visible immediately)
Claus Gittinger <cg@exept.de>
parents:
865
diff
changeset
|
783 |
"/ self clear. |
863 | 784 |
|
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
785 |
doBusy := showBusy value. |
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
786 |
doBusy ifFalse:[ |
2563 | 787 |
percentage value < 0 ifTrue:[ |
788 |
self startBusyIndicationProcess. |
|
789 |
doBusy := true. |
|
790 |
]. |
|
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
791 |
]. |
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
792 |
|
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
793 |
doBusy ifTrue:[ |
2563 | 794 |
self paint:bgColor. |
795 |
self fillRectangleX:m y:m width:w height:h. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
796 |
|
2563 | 797 |
lx := (w * busyPosition / 100) rounded. |
798 |
rx := (w * (busyPosition + 20) / 100) rounded. |
|
799 |
rx := rx min:w. |
|
800 |
lx := lx max:m. |
|
801 |
self paint:fgColor. |
|
802 |
self fillRectangleX:lx y:m width:(rx - lx) height:h. |
|
803 |
^ self |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
804 |
]. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
805 |
|
2040
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
806 |
self stopBusyIndicationProcess. |
702df7addef9
busy indicator when percentage is negative
Claus Gittinger <cg@exept.de>
parents:
1935
diff
changeset
|
807 |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
808 |
rx := (w * percentage / 100) rounded. |
826 | 809 |
self paint:bgColor. |
843 | 810 |
self fillRectangleX:m+rx y:m width:w-rx height:h. |
183 | 811 |
|
812 |
showPercentage ifTrue:[ |
|
2563 | 813 |
s := percentage printString , ' %'. |
814 |
font := font onDevice:device. |
|
815 |
sw := font widthOf:s . |
|
816 |
sx := (width - sw) // 2. |
|
817 |
sy := height // 2 + font descent + 2. |
|
347 | 818 |
|
2563 | 819 |
rx <= (sx+sw) ifTrue:[ |
820 |
self paint:Color black. |
|
821 |
self displayString:s x:sx y:sy. |
|
822 |
] |
|
183 | 823 |
]. |
824 |
||
825 |
self paint:fgColor. |
|
826 |
self fillRectangleX:m y:m width:rx height:h. |
|
827 |
||
828 |
showPercentage ifTrue:[ |
|
2563 | 829 |
rx >= sx ifTrue:[ |
830 |
self clippingRectangle:(m@m corner:rx+1 @ h). |
|
831 |
self paint:Color white. |
|
832 |
self displayString:s x:sx y:sy. |
|
833 |
self clippingRectangle:nil |
|
834 |
] |
|
183 | 835 |
] |
347 | 836 |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
837 |
"Modified: / 21.10.1998 / 18:01:58 / cg" |
863 | 838 |
! |
839 |
||
840 |
sizeChanged:how |
|
841 |
super sizeChanged:how. |
|
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
842 |
self invalidate |
863 | 843 |
|
844 |
"Created: / 18.4.1998 / 02:34:37 / cg" |
|
865 | 845 |
"Modified: / 18.4.1998 / 14:09:40 / cg" |
183 | 846 |
! ! |
847 |
||
2501 | 848 |
!ProgressIndicator methodsFor:'initialization & release'! |
183 | 849 |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
850 |
destroy |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
851 |
busyIndicationProcess notNil ifTrue:[ |
2563 | 852 |
self stopBusyIndicationProcess |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
853 |
]. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
854 |
super destroy. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
855 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
856 |
"Created: / 21.10.1998 / 17:29:58 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
857 |
"Modified: / 21.10.1998 / 17:30:36 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
858 |
! |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
859 |
|
574 | 860 |
initStyle |
861 |
"initialize styleSheet values" |
|
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
862 |
|
575 | 863 |
<resource: #style (#'progressIndicator.viewBackground' |
2921 | 864 |
#'progressIndicator.foregroundColor')> |
574 | 865 |
|
866 |
super initStyle. |
|
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
867 |
|
347 | 868 |
self is3D ifTrue:[ |
2921 | 869 |
self level:-1 |
347 | 870 |
]. |
871 |
||
826 | 872 |
bgColor := styleSheet colorAt:'progressIndicator.viewBackground' default:Color white. |
574 | 873 |
fgColor := styleSheet colorAt:'progressIndicator.foregroundColor' default:Color blue. |
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
874 |
fgColor := fgColor onDevice:device. |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
875 |
|
183 | 876 |
showPercentage := true. |
574 | 877 |
! |
878 |
||
879 |
initialize |
|
826 | 880 |
|
574 | 881 |
super initialize. |
826 | 882 |
|
574 | 883 |
percentage := 0. |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
884 |
showBusy := false. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
885 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
886 |
"Modified: / 21.10.1998 / 17:33:02 / cg" |
1935
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
887 |
! |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
888 |
|
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
889 |
mapped |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
890 |
super mapped. |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
891 |
(showBusy value) ifTrue:[ |
2563 | 892 |
self startBusyIndicationProcess. |
1935
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
893 |
]. |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
894 |
! |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
895 |
|
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
896 |
unmapped |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
897 |
super unmapped. |
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
898 |
(showBusy value) ifTrue:[ |
2563 | 899 |
self stopBusyIndicationProcess. |
1935
a2338e64cf2f
terminate/recreate busyIndicator-animation process if unmapped/mapped
frank
parents:
1852
diff
changeset
|
900 |
]. |
574 | 901 |
! ! |
902 |
||
903 |
!ProgressIndicator methodsFor:'private'! |
|
904 |
||
905 |
connectToTop:top label:label |
|
906 |
connectedTop := top. |
|
907 |
connectedLabel := label |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
908 |
! |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
909 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
910 |
startBusyIndicationProcess |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
911 |
busyIndicationProcess isNil ifTrue:[ |
2563 | 912 |
busyPosition := 0. |
913 |
busyDelta := 5. |
|
914 |
busyIndicationProcess := [ |
|
915 |
[self realized] whileTrue:[ |
|
916 |
Delay waitForSeconds:0.2. |
|
917 |
self shown ifTrue:[ |
|
918 |
self updateBusyIndicatorPosition. |
|
919 |
] |
|
920 |
]. |
|
921 |
busyIndicationProcess := nil. |
|
922 |
] fork. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
923 |
]. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
924 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
925 |
"Created: / 21.10.1998 / 18:02:35 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
926 |
"Modified: / 21.10.1998 / 18:03:49 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
927 |
! |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
928 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
929 |
stopBusyIndicationProcess |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
930 |
busyIndicationProcess notNil ifTrue:[ |
2563 | 931 |
busyIndicationProcess terminate. |
932 |
busyIndicationProcess := nil |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
933 |
]. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
934 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
935 |
"Created: / 21.10.1998 / 17:30:19 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
936 |
! |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
937 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
938 |
updateBusyIndicatorPosition |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
939 |
busyPosition := busyPosition + busyDelta. |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
940 |
busyPosition >= 80 ifTrue:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
941 |
busyDelta > 0 ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
942 |
busyDelta := busyDelta negated. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
943 |
] |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
944 |
] ifFalse:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
945 |
busyPosition <= 0 ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
946 |
busyDelta < 0 ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
947 |
busyDelta := busyDelta negated. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
948 |
] |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
949 |
] |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
950 |
]. |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2563
diff
changeset
|
951 |
self invalidate |
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
952 |
|
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
953 |
"Created: / 21.10.1998 / 17:33:28 / cg" |
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
954 |
"Modified: / 21.10.1998 / 17:58:58 / cg" |
183 | 955 |
! ! |
956 |
||
957 |
!ProgressIndicator methodsFor:'queries'! |
|
958 |
||
959 |
preferredExtent |
|
574 | 960 |
"return my preferred extent" |
961 |
||
334 | 962 |
preferredExtent notNil ifTrue:[ |
634 | 963 |
^ preferredExtent |
334 | 964 |
]. |
183 | 965 |
^ 100 @ (font height + font descent + ((margin + 1) * 2)) |
334 | 966 |
|
574 | 967 |
"Modified: 22.10.1997 / 21:07:17 / cg" |
183 | 968 |
! ! |
969 |
||
62 | 970 |
!ProgressIndicator methodsFor:'showing progress'! |
971 |
||
2850 | 972 |
showBusyIndicatorDuring:aBlock |
973 |
"show progress, while evaluating aBlock. |
|
974 |
If the receiver has been created with inBox, show the |
|
975 |
box centered on the screen. If not, the view is assumed to |
|
976 |
be contained in another view, and no special startup actions |
|
977 |
are performed. |
|
978 |
||
979 |
Caveat: cannot (currently) suppress close of the box ..." |
|
980 |
||
981 |
|labelValue p| |
|
982 |
||
983 |
connectedLabel notNil ifTrue:[ |
|
984 |
labelValue := (connectedLabel label ? '') asValue. |
|
985 |
connectedLabel |
|
986 |
model:labelValue; |
|
987 |
aspect:#value; |
|
988 |
labelMessage:#value. |
|
989 |
] ifFalse:[ |
|
990 |
labelValue := '' asValue. |
|
991 |
]. |
|
992 |
||
993 |
||
994 |
"/ the worker process |
|
995 |
||
996 |
p := [ |
|
997 |
[ |
|
998 |
WindowGroup windowGroupQuerySignal handle:[:ex | |
|
999 |
ex proceedWith:self topView windowGroup |
|
1000 |
] do:[ |
|
1001 |
aBlock value |
|
1002 |
] |
|
1003 |
] ensure:[ |
|
1004 |
p := nil. |
|
1005 |
closeTopWhenDone ifTrue:[ |
|
1006 |
connectedTop hide |
|
1007 |
]. |
|
1008 |
finishAction value |
|
1009 |
] |
|
1010 |
] newProcess. |
|
1011 |
||
1012 |
Processor activeProcess |
|
2878 | 1013 |
withHigherPriorityDo: |
1014 |
[ |
|
1015 |
p resume. |
|
1016 |
self topView show. |
|
1017 |
]. |
|
2850 | 1018 |
p notNil ifTrue:[p terminate]. |
1019 |
||
1020 |
" |
|
1021 |
|p| |
|
1022 |
||
1023 |
p := ProgressIndicator inBox. |
|
1024 |
p showBusyIndication:true. |
|
1025 |
p showProgressOf: |
|
1026 |
[:progressValue :currentAction | |
|
1027 |
1 to:200 do:[:percent | |
|
1028 |
(Delay forSeconds:0.05) wait. |
|
1029 |
progressValue value:percent |
|
1030 |
]. |
|
1031 |
]. |
|
1032 |
||
1033 |
'it can be reused ...'. |
|
1034 |
p showBusyIndication:false. |
|
1035 |
p showProgressOf: |
|
1036 |
[:progressValue :currentAction | |
|
1037 |
1 to:100 by:5 do:[:percent | |
|
1038 |
(Delay forSeconds:0.05) wait. |
|
1039 |
progressValue value:percent |
|
1040 |
]. |
|
1041 |
]. |
|
1042 |
||
1043 |
" |
|
1044 |
||
1045 |
"Modified: / 21.10.1998 / 17:37:00 / cg" |
|
1046 |
! |
|
1047 |
||
62 | 1048 |
showProgressOf:aBlock |
1049 |
"show progress, while evaluating aBlock. |
|
1050 |
If the receiver has been created with inBox, show the |
|
1051 |
box centered on the screen. If not, the view is assumed to |
|
1052 |
be contained in another view, and no special startup actions |
|
1053 |
are performed. |
|
1054 |
||
1055 |
The block is passed two arguments, the progressValue, |
|
1056 |
which should be set to the percentage from time-to-time |
|
1057 |
within the block and an action value, which should be set to |
|
1058 |
the currently performed action (a string) from time to time. |
|
1059 |
The second valueHolder can be left unchanged. |
|
1060 |
||
1061 |
Caveat: cannot (currently) suppress close of the box ..." |
|
1062 |
||
221 | 1063 |
|progressValue labelValue p| |
62 | 1064 |
|
1065 |
progressValue := 0 asValue. |
|
1066 |
||
1067 |
connectedLabel notNil ifTrue:[ |
|
2837 | 1068 |
labelValue := (connectedLabel label ? '') asValue. |
1069 |
connectedLabel |
|
1070 |
model:labelValue; |
|
1071 |
aspect:#value; |
|
1072 |
labelMessage:#value. |
|
1834
ba170c21ed76
defaultExtent computation fixed
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1073 |
] ifFalse:[ |
2837 | 1074 |
labelValue := '' asValue. |
62 | 1075 |
]. |
1076 |
||
1834
ba170c21ed76
defaultExtent computation fixed
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1077 |
|
62 | 1078 |
self model:progressValue. |
1079 |
||
221 | 1080 |
"/ the worker process |
1081 |
||
62 | 1082 |
p := [ |
2837 | 1083 |
[ |
1084 |
WindowGroup windowGroupQuerySignal handle:[:ex | |
|
1085 |
ex proceedWith:self topView windowGroup |
|
1086 |
] do:[ |
|
1087 |
aBlock value:progressValue value:labelValue |
|
1088 |
] |
|
1089 |
] ensure:[ |
|
1090 |
p := nil. |
|
1091 |
closeTopWhenDone ifTrue:[ |
|
1092 |
connectedTop hide |
|
1093 |
]. |
|
1094 |
finishAction value |
|
1095 |
] |
|
1850 | 1096 |
] newProcess. |
62 | 1097 |
|
237 | 1098 |
Processor activeProcess |
2878 | 1099 |
withHigherPriorityDo:[ |
2837 | 1100 |
p resume. |
1101 |
self topView show. |
|
1102 |
]. |
|
237 | 1103 |
p notNil ifTrue:[p terminate]. |
62 | 1104 |
|
1105 |
" |
|
1106 |
|p| |
|
1107 |
||
1108 |
p := ProgressIndicator inBox. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
1109 |
p showBusyIndication:true. |
62 | 1110 |
p showProgressOf: |
2837 | 1111 |
[:progressValue :currentAction | |
1112 |
1 to:200 do:[:percent | |
|
1113 |
(Delay forSeconds:0.05) wait. |
|
1114 |
progressValue value:percent |
|
1115 |
]. |
|
1116 |
]. |
|
62 | 1117 |
|
1118 |
'it can be reused ...'. |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
1119 |
p showBusyIndication:false. |
62 | 1120 |
p showProgressOf: |
2837 | 1121 |
[:progressValue :currentAction | |
1122 |
1 to:100 by:5 do:[:percent | |
|
1123 |
(Delay forSeconds:0.05) wait. |
|
1124 |
progressValue value:percent |
|
1125 |
]. |
|
1126 |
]. |
|
62 | 1127 |
|
1128 |
" |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
1129 |
|
1168
35e46761842f
added showBusyIndication mode
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
1130 |
"Modified: / 21.10.1998 / 17:37:00 / cg" |
62 | 1131 |
! ! |
1132 |
||
334 | 1133 |
!ProgressIndicator class methodsFor:'documentation'! |
50 | 1134 |
|
183 | 1135 |
version |
2931 | 1136 |
^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.52 2006-03-06 08:55:21 cg Exp $' |
50 | 1137 |
! ! |