author | Claus Gittinger <cg@exept.de> |
Tue, 03 Sep 1996 15:15:52 +0200 | |
changeset 237 | ecea4b3a34ce |
parent 221 | 976e5a608dfb |
child 334 | 8af14110efdb |
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 |
|
13 |
View subclass:#ProgressIndicator |
|
237 | 14 |
instanceVariableNames:'percentage showPercentage fgColor connectedTop connectedLabel |
15 |
collector finishAction closeTopWhenDone' |
|
183 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Misc' |
|
50 | 19 |
! |
20 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
21 |
!ProgressIndicator class methodsFor:'documentation'! |
50 | 22 |
|
62 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
50 | 37 |
documentation |
38 |
" |
|
39 |
a view showing a rectangle filled according the percentage value. |
|
40 |
Can be used as a progress indicator a la MSwindows. |
|
183 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
44 |
||
45 |
[see also:] |
|
46 |
ActionWaitBox AnimatedLabel |
|
50 | 47 |
" |
48 |
! |
|
49 |
||
50 |
examples |
|
51 |
" |
|
62 | 52 |
basic (internal) interface |
53 |
(if progress indicator is to be used in a complex box ...): |
|
50 | 54 |
|
183 | 55 |
Before you get frustrated - see the convenient-interface examples |
56 |
at the end ;-) |
|
57 |
||
58 |
[exBegin] |
|
50 | 59 |
|top p h| |
60 |
||
62 | 61 |
top := ModalBox new. |
50 | 62 |
top extent:300@100. |
63 |
top label:'Progress'. |
|
64 |
p := ProgressIndicator in:top. |
|
65 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
66 |
p level:-1. |
|
62 | 67 |
h := p preferredExtent y. |
50 | 68 |
p topInset:(h // 2) negated; |
183 | 69 |
bottomInset:(h // 2) negated; |
70 |
leftInset:5; |
|
71 |
rightInset:5. |
|
50 | 72 |
|
73 |
[ |
|
183 | 74 |
1 to:100 do:[:val | |
75 |
(Delay forSeconds:0.05) wait. |
|
76 |
p percentage:val |
|
77 |
]. |
|
78 |
top hide. |
|
62 | 79 |
] fork. |
80 |
top open. |
|
183 | 81 |
[exEnd] |
50 | 82 |
|
83 |
changing colors, turning percentage display off: |
|
183 | 84 |
[exBegin] |
50 | 85 |
|top p h| |
86 |
||
87 |
top := StandardSystemView new. |
|
88 |
top extent:300@100. |
|
89 |
top label:'Progress'. |
|
90 |
p := ProgressIndicator in:top. |
|
91 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
92 |
p level:-1. |
|
93 |
p showPercentage:false. |
|
94 |
p foregroundColor:(Color red). |
|
95 |
h := 10. |
|
96 |
p topInset:(h // 2) negated; |
|
183 | 97 |
bottomInset:(h // 2) negated; |
98 |
leftInset:5; |
|
99 |
rightInset:5. |
|
50 | 100 |
top open. |
101 |
[ |
|
183 | 102 |
1 to:100 do:[:val | |
103 |
(Delay forSeconds:0.05) wait. |
|
104 |
p percentage:val |
|
105 |
] |
|
50 | 106 |
] fork |
183 | 107 |
[exEnd] |
50 | 108 |
|
109 |
with border (2D look): |
|
183 | 110 |
[exBegin] |
50 | 111 |
|top p h| |
112 |
||
113 |
top := StandardSystemView new. |
|
114 |
top extent:300@100. |
|
115 |
top label:'Progress'. |
|
116 |
p := ProgressIndicator in:top. |
|
117 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
118 |
p borderWidth:1. |
|
62 | 119 |
h := p preferredExtent y. |
50 | 120 |
p topInset:(h // 2) negated; |
183 | 121 |
bottomInset:(h // 2) negated; |
122 |
leftInset:5; |
|
123 |
rightInset:5. |
|
50 | 124 |
top open. |
125 |
[ |
|
183 | 126 |
1 to:100 do:[:val | |
127 |
(Delay forSeconds:0.05) wait. |
|
128 |
p percentage:val |
|
129 |
] |
|
50 | 130 |
] fork |
183 | 131 |
[exEnd] |
50 | 132 |
|
133 |
||
134 |
getting progress from a model: |
|
183 | 135 |
[exBegin] |
50 | 136 |
|model top p h| |
137 |
||
138 |
model := 0 asValue. |
|
139 |
||
140 |
top := StandardSystemView new. |
|
141 |
top extent:300@100. |
|
142 |
top label:'Progress'. |
|
143 |
p := ProgressIndicator in:top. |
|
144 |
p model:model. |
|
145 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
146 |
p level:-1. |
|
62 | 147 |
h := p preferredExtent y. |
50 | 148 |
p topInset:(h // 2) negated; |
183 | 149 |
bottomInset:(h // 2) negated; |
150 |
leftInset:5; |
|
151 |
rightInset:5. |
|
50 | 152 |
top open. |
153 |
||
154 |
[ |
|
183 | 155 |
1 to:100 do:[:val | |
156 |
(Delay forSeconds:0.05) wait. |
|
157 |
model value:val |
|
158 |
] |
|
50 | 159 |
] fork |
183 | 160 |
[exEnd] |
50 | 161 |
|
62 | 162 |
|
50 | 163 |
concrete example: |
164 |
search all files in the source directory for a string |
|
165 |
using grep. Show progress while doing so. |
|
183 | 166 |
[exBegin] |
50 | 167 |
|top p h names done| |
168 |
||
169 |
top := StandardSystemView new. |
|
170 |
top extent:300@100. |
|
171 |
top label:'Searching ...'. |
|
172 |
p := ProgressIndicator in:top. |
|
173 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
174 |
p level:-1. |
|
62 | 175 |
h := p preferredExtent y. |
50 | 176 |
p topInset:(h // 2) negated; |
183 | 177 |
bottomInset:(h // 2) negated; |
178 |
leftInset:5; |
|
179 |
rightInset:5. |
|
50 | 180 |
top openWithPriority:(Processor activePriority + 1). |
181 |
||
182 |
names := 'source' asFilename directoryContents. |
|
183 |
done := 0. |
|
184 |
names do:[:aName | |
|
183 | 185 |
|fn stream line| |
50 | 186 |
|
183 | 187 |
p percentage:(done / names size * 100). |
188 |
fn := ('source/' , aName) asFilename. |
|
189 |
fn isDirectory ifFalse:[ |
|
190 |
stream := fn readStream. |
|
191 |
[stream atEnd] whileFalse:[ |
|
192 |
line := stream nextLine. |
|
193 |
(line findString:'subclass:') ~~ 0 ifTrue:[ |
|
184 | 194 |
Transcript showCR:line |
183 | 195 |
]. |
196 |
]. |
|
197 |
stream close. |
|
198 |
]. |
|
199 |
done := done + 1 |
|
50 | 200 |
]. |
201 |
||
202 |
top destroy |
|
183 | 203 |
[exEnd] |
62 | 204 |
|
205 |
||
206 |
using the convenient inBox-interface |
|
207 |
||
208 |
(this creates a box and an activity label and evaluates a block |
|
209 |
to indicate ...) |
|
210 |
||
211 |
basic interface demonstration: |
|
183 | 212 |
[exBegin] |
62 | 213 |
|p| |
214 |
||
215 |
p := ProgressIndicator |
|
183 | 216 |
inBoxWithLabel:'doing something ...' |
217 |
abortable:true. |
|
62 | 218 |
p showProgressOf: |
183 | 219 |
[:progressValue :currentAction | |
62 | 220 |
|
183 | 221 |
1 to:100 do:[:val | |
222 |
(Delay forSeconds:0.05) wait. |
|
223 |
val == 25 ifTrue:[ |
|
224 |
currentAction value:'still going ...' |
|
225 |
]. |
|
226 |
val == 50 ifTrue:[ |
|
227 |
currentAction value:'halfway through ...' |
|
228 |
]. |
|
229 |
val == 75 ifTrue:[ |
|
230 |
currentAction value:'almost finished ...' |
|
231 |
]. |
|
232 |
progressValue value:val |
|
233 |
] |
|
234 |
] |
|
235 |
[exEnd] |
|
62 | 236 |
|
237 |
||
238 |
above search example using this convenient interface: |
|
183 | 239 |
[exBegin] |
62 | 240 |
|p| |
241 |
||
183 | 242 |
p := ProgressIndicator |
243 |
inBoxWithLabel:'searching files ...' |
|
244 |
abortable:false. |
|
62 | 245 |
p showProgressOf: |
183 | 246 |
[:progressValue :currentAction | |
247 |
|names nDone| |
|
62 | 248 |
|
183 | 249 |
names := 'source' asFilename directoryContents. |
250 |
nDone := 0. |
|
251 |
names do:[:aName | |
|
252 |
|fn stream line| |
|
253 |
||
254 |
progressValue value:(nDone / names size * 100). |
|
255 |
currentAction value:'searching ' , 'source/' , aName , ' ...'. |
|
62 | 256 |
|
183 | 257 |
fn := ('source/' , aName) asFilename. |
258 |
fn isDirectory ifFalse:[ |
|
259 |
stream := fn readStream. |
|
260 |
[stream atEnd] whileFalse:[ |
|
261 |
line := stream nextLine. |
|
262 |
(line findString:'subclass:') ~~ 0 ifTrue:[ |
|
184 | 263 |
Transcript showCR:line |
183 | 264 |
]. |
265 |
]. |
|
266 |
stream close. |
|
267 |
]. |
|
268 |
nDone := nDone + 1 |
|
269 |
]. |
|
270 |
]. |
|
271 |
[exEnd] |
|
62 | 272 |
|
273 |
||
274 |
a nice example: copying files a la windows ... |
|
183 | 275 |
the following copies all files to /dev/null. |
276 |
[exBegin] |
|
62 | 277 |
|p| |
278 |
||
279 |
(ProgressIndicator |
|
183 | 280 |
inBoxWithLabel:'copy files to /dev/null ...' |
281 |
abortable:true) |
|
282 |
showProgressOf: |
|
283 |
[:progressValue :currentAction | |
|
284 |
|files nFiles nDone| |
|
62 | 285 |
|
183 | 286 |
files := '.' asFilename directoryContents. |
287 |
nFiles := files size. |
|
288 |
nDone := 0. |
|
289 |
files do:[:aFileName | |
|
290 |
|percent| |
|
50 | 291 |
|
183 | 292 |
nDone := nDone + 1. |
293 |
percent := nDone / nFiles * 100. |
|
294 |
progressValue value:percent. |
|
295 |
aFileName asFilename isDirectory ifTrue:[ |
|
184 | 296 |
Transcript showCR:('skipping ' , aFileName , ' ...'). |
183 | 297 |
currentAction value:('skipping ' , aFileName , ' ...'). |
298 |
] ifFalse:[ |
|
184 | 299 |
Transcript showCR:('copying ' , aFileName , ' ...'). |
183 | 300 |
currentAction value:('copying ' , aFileName , ' ...'). |
301 |
Object errorSignal handle:[:ex | |
|
302 |
self warn:'an error occurred while copying ' , aFileName. |
|
303 |
ex return |
|
304 |
] do:[ |
|
305 |
aFileName asFilename copyTo:'/dev/null'. |
|
306 |
] |
|
307 |
]. |
|
308 |
]. |
|
309 |
]. |
|
310 |
[exEnd] |
|
311 |
" |
|
50 | 312 |
! ! |
313 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
314 |
!ProgressIndicator class methodsFor:'instance creation'! |
62 | 315 |
|
316 |
inBox |
|
317 |
^ self inBoxWithLabel:'executing ...' abortable:false |
|
318 |
! |
|
319 |
||
320 |
inBoxWithLabel:aLabel |
|
321 |
"create a topView containing an instance of myself, |
|
322 |
for later use with #showProgressOf:" |
|
323 |
||
324 |
^ self inBoxWithLabel:aLabel abortable:false |
|
325 |
! |
|
326 |
||
327 |
inBoxWithLabel:aLabel abortable:abortable |
|
328 |
"create a topView containing an instance of myself, |
|
329 |
for later use with #showProgressOf:" |
|
330 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
331 |
^ self |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
332 |
inBoxWithLabel:aLabel |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
333 |
text:'' |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
334 |
abortable:abortable |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
335 |
|
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
336 |
"Modified: 17.7.1996 / 15:14:58 / cg" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
337 |
! |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
338 |
|
237 | 339 |
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
|
340 |
"create a topView containing an instance of myself, |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
341 |
for later use with #showProgressOf:" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
342 |
|
237 | 343 |
|top p l h y y2| |
62 | 344 |
|
345 |
top := Dialog new. |
|
346 |
top label:aLabel. |
|
347 |
top cursor:(Cursor wait). |
|
348 |
||
237 | 349 |
anIcon notNil ifTrue:[ |
350 |
y := top yPosition. |
|
351 |
l := top addTextLabel:anIcon. |
|
352 |
l borderWidth:0. |
|
353 |
l adjust:#left. |
|
354 |
l cursor:(Cursor wait). |
|
355 |
y2 := top yPosition. |
|
356 |
top yPosition:y. |
|
357 |
]. |
|
358 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
359 |
l := top addTextLabel:text. |
62 | 360 |
l borderWidth:0. |
74 | 361 |
l adjust:#left. |
62 | 362 |
l cursor:(Cursor wait). |
237 | 363 |
l leftInset:(anIcon width + 10). |
364 |
||
365 |
top yPosition:(top yPosition max:y2). |
|
62 | 366 |
|
367 |
top addVerticalSpace. |
|
368 |
||
369 |
p := ProgressIndicator new. |
|
370 |
p extent:(1.0 @ p preferredExtent y). |
|
371 |
p level:-1. |
|
372 |
p leftInset:5; |
|
373 |
rightInset:5. |
|
374 |
p cursor:(Cursor wait). |
|
237 | 375 |
p closeTopWhenDone:closeWhenDoneBoolean. |
62 | 376 |
p connectToTop:top label:l. |
377 |
||
378 |
top addComponent:p. |
|
379 |
||
237 | 380 |
additionalView notNil ifTrue:[ |
381 |
top addComponent:additionalView. |
|
382 |
additionalView extent:(1.0 @ additionalView preferredExtent y). |
|
383 |
]. |
|
384 |
||
62 | 385 |
abortable ifTrue:[ |
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
386 |
top addVerticalSpace. |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
387 |
top addAbortButton |
62 | 388 |
]. |
389 |
||
390 |
^ p |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
391 |
|
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
392 |
"Created: 17.7.1996 / 15:14:33 / cg" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
393 |
"Modified: 17.7.1996 / 15:16:58 / cg" |
237 | 394 |
! |
395 |
||
396 |
inBoxWithLabel:aLabel text:text abortable:abortable |
|
397 |
"create a topView containing an instance of myself, |
|
398 |
for later use with #showProgressOf:" |
|
399 |
||
400 |
^ self |
|
401 |
inBoxWithLabel:aLabel |
|
402 |
text:text |
|
403 |
abortable:abortable |
|
404 |
view:nil |
|
405 |
||
406 |
! |
|
407 |
||
408 |
inBoxWithLabel:aLabel text:text abortable:abortable view:additionalView |
|
409 |
"create a topView containing an instance of myself, |
|
410 |
for later use with #showProgressOf:" |
|
411 |
||
412 |
^ self |
|
413 |
inBoxWithLabel:aLabel |
|
414 |
text:text |
|
415 |
abortable:abortable |
|
416 |
view:additionalView |
|
417 |
closeWhenDone:true |
|
418 |
||
419 |
! |
|
420 |
||
421 |
inBoxWithLabel:aLabel text:text abortable:abortable view:additionalView closeWhenDone:closeWhenDoneBoolean |
|
422 |
"create a topView containing an instance of myself, |
|
423 |
for later use with #showProgressOf:" |
|
424 |
||
425 |
^ self |
|
426 |
inBoxWithLabel:aLabel |
|
427 |
icon:nil |
|
428 |
text:text |
|
429 |
abortable:abortable |
|
430 |
view:additionalView |
|
431 |
closeWhenDone:closeWhenDoneBoolean |
|
432 |
||
62 | 433 |
! ! |
434 |
||
183 | 435 |
!ProgressIndicator methodsFor:'accessing'! |
436 |
||
237 | 437 |
closeTopWhenDone:aBoolean |
438 |
closeTopWhenDone := aBoolean |
|
439 |
||
440 |
"Created: 3.9.1996 / 14:22:03 / cg" |
|
441 |
! |
|
442 |
||
443 |
finishAction:aBlock |
|
444 |
finishAction := aBlock |
|
445 |
||
446 |
"Created: 3.9.1996 / 14:15:15 / cg" |
|
447 |
! |
|
448 |
||
183 | 449 |
foregroundColor:aColor |
450 |
fgColor := aColor |
|
451 |
! |
|
452 |
||
453 |
percentage:aNumber |
|
454 |
|newPercentage| |
|
455 |
||
456 |
newPercentage := ((aNumber max:0) min:100) rounded. |
|
457 |
newPercentage ~~ percentage ifTrue:[ |
|
458 |
percentage := newPercentage. |
|
459 |
shown ifTrue:[self redraw]. |
|
460 |
] |
|
461 |
! |
|
462 |
||
463 |
showPercentage:aBoolean |
|
464 |
showPercentage := aBoolean |
|
465 |
! ! |
|
466 |
||
467 |
!ProgressIndicator methodsFor:'change & update'! |
|
468 |
||
469 |
update:aspect with:aParameter from:changedObject |
|
470 |
(aspect == aspectMsg |
|
471 |
and:[changedObject == model]) ifTrue:[ |
|
472 |
self percentage:(model perform:aspectMsg). |
|
473 |
^ self |
|
474 |
]. |
|
475 |
^ super update:aspect with:aParameter from:changedObject |
|
476 |
! ! |
|
477 |
||
478 |
!ProgressIndicator methodsFor:'drawing'! |
|
479 |
||
480 |
redraw |
|
481 |
|s rx sx sy sw m w h| |
|
482 |
||
483 |
m := margin + 1. |
|
484 |
w := width - (m*2). |
|
485 |
h := height - (m*2). |
|
486 |
||
487 |
s := percentage printString , ' %'. |
|
488 |
sw := font widthOf:s. |
|
489 |
sx := (width - sw) // 2. |
|
490 |
sy := height // 2 + font descent + 2. |
|
491 |
||
492 |
rx := (w * percentage / 100) rounded. |
|
493 |
||
494 |
self paint:Color white. |
|
495 |
self fillRectangleX:m y:m width:w height:h. |
|
496 |
||
497 |
showPercentage ifTrue:[ |
|
201 | 498 |
rx <= (sx+sw) ifTrue:[ |
499 |
self paint:Color black. |
|
500 |
self displayString:s x:sx y:sy. |
|
501 |
] |
|
183 | 502 |
]. |
503 |
||
504 |
self paint:fgColor. |
|
505 |
self fillRectangleX:m y:m width:rx height:h. |
|
506 |
||
507 |
showPercentage ifTrue:[ |
|
201 | 508 |
rx >= sx ifTrue:[ |
509 |
self clippingRectangle:(m@m corner:rx+1 @ h). |
|
510 |
self paint:Color white. |
|
511 |
self displayString:s x:sx y:sy. |
|
512 |
self clippingRectangle:nil |
|
513 |
] |
|
183 | 514 |
] |
515 |
! ! |
|
516 |
||
517 |
!ProgressIndicator methodsFor:'initialization'! |
|
518 |
||
519 |
initialize |
|
520 |
super initialize. |
|
521 |
viewBackground := styleSheet colorAt:'progressIndicatorViewBackground' default:Color white. |
|
522 |
fgColor := styleSheet colorAt:'progressIndicatorForegroundColor' default:Color blue. |
|
523 |
percentage := 0. |
|
524 |
showPercentage := true. |
|
525 |
! ! |
|
526 |
||
527 |
!ProgressIndicator methodsFor:'queries'! |
|
528 |
||
529 |
preferredExtent |
|
530 |
^ 100 @ (font height + font descent + ((margin + 1) * 2)) |
|
531 |
! ! |
|
532 |
||
62 | 533 |
!ProgressIndicator methodsFor:'showing progress'! |
534 |
||
535 |
connectToTop:top label:label |
|
536 |
connectedTop := top. |
|
537 |
connectedLabel := label |
|
538 |
! |
|
539 |
||
540 |
showProgressOf:aBlock |
|
541 |
"show progress, while evaluating aBlock. |
|
542 |
If the receiver has been created with inBox, show the |
|
543 |
box centered on the screen. If not, the view is assumed to |
|
544 |
be contained in another view, and no special startup actions |
|
545 |
are performed. |
|
546 |
||
547 |
The block is passed two arguments, the progressValue, |
|
548 |
which should be set to the percentage from time-to-time |
|
549 |
within the block and an action value, which should be set to |
|
550 |
the currently performed action (a string) from time to time. |
|
551 |
The second valueHolder can be left unchanged. |
|
552 |
||
553 |
Caveat: cannot (currently) suppress close of the box ..." |
|
554 |
||
221 | 555 |
|progressValue labelValue p| |
62 | 556 |
|
557 |
progressValue := 0 asValue. |
|
558 |
labelValue := '' asValue. |
|
559 |
||
560 |
connectedLabel notNil ifTrue:[ |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
561 |
connectedLabel |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
562 |
model:labelValue; |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
563 |
aspect:#value; |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
564 |
labelMessage:#value. |
62 | 565 |
]. |
566 |
||
567 |
self model:progressValue. |
|
568 |
||
221 | 569 |
"/ the worker process |
570 |
||
62 | 571 |
p := [ |
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
572 |
[ |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
573 |
WindowGroup windowGroupQuerySignal handle:[:ex | |
221 | 574 |
ex proceedWith:self topView windowGroup |
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
575 |
] do:[ |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
576 |
aBlock value:progressValue value:labelValue |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
577 |
] |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
578 |
] valueNowOrOnUnwindDo:[ |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
579 |
p := nil. |
237 | 580 |
closeTopWhenDone ifTrue:[ |
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
581 |
connectedTop hide |
237 | 582 |
]. |
583 |
finishAction notNil ifTrue:[ |
|
584 |
finishAction value |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
585 |
] |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
586 |
] |
62 | 587 |
] fork. |
588 |
||
237 | 589 |
Processor activeProcess |
590 |
withPriority:(Processor activePriority + 1) |
|
591 |
do:[ |
|
592 |
self topView show. |
|
593 |
]. |
|
594 |
p notNil ifTrue:[p terminate]. |
|
62 | 595 |
|
596 |
" |
|
597 |
|p| |
|
598 |
||
599 |
p := ProgressIndicator inBox. |
|
600 |
p showProgressOf: |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
601 |
[:progressValue :currentAction | |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
602 |
1 to:100 do:[:percent | |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
603 |
(Delay forSeconds:0.05) wait. |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
604 |
progressValue value:percent |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
605 |
]. |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
606 |
]. |
62 | 607 |
|
608 |
'it can be reused ...'. |
|
609 |
p showProgressOf: |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
610 |
[:progressValue :currentAction | |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
611 |
1 to:100 by:5 do:[:percent | |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
612 |
(Delay forSeconds:0.05) wait. |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
613 |
progressValue value:percent |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
614 |
]. |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
615 |
]. |
62 | 616 |
|
617 |
" |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
618 |
|
237 | 619 |
"Modified: 3.9.1996 / 14:22:43 / cg" |
62 | 620 |
! ! |
621 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
622 |
!ProgressIndicator class methodsFor:'documentation'! |
50 | 623 |
|
183 | 624 |
version |
237 | 625 |
^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.11 1996-09-03 13:15:52 cg Exp $' |
50 | 626 |
! ! |