--- a/ProgressIndicator.st Sun Oct 30 12:19:57 2011 +0100
+++ b/ProgressIndicator.st Mon Nov 07 22:03:10 2011 +0100
@@ -65,7 +65,7 @@
Before you get frustrated - see the convenient-interface examples
at the end ;-)
- [exBegin]
+ [exBegin]
|top p h|
top := ModalBox new.
@@ -76,22 +76,22 @@
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
- bottomInset:(h // 2) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 2) negated;
+ leftInset:5;
+ rightInset:5.
[
- 1 to:100 do:[:val |
- (Delay forSeconds:0.05) wait.
- p percentage:val
- ].
- top hide.
+ 1 to:100 do:[:val |
+ (Delay forSeconds:0.05) wait.
+ p percentage:val
+ ].
+ top hide.
] fork.
top open.
- [exEnd]
+ [exEnd]
as a busy indicator
- [exBegin]
+ [exBegin]
|top p h|
top := ModalBox new.
@@ -102,21 +102,21 @@
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
- bottomInset:(h // 2) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 2) negated;
+ leftInset:5;
+ rightInset:5.
p showBusyIndication:true.
[
- 'do something here ....'.
- (Delay forSeconds:5) wait.
- top hide.
+ 'do something here ....'.
+ (Delay forSeconds:5) wait.
+ top hide.
] fork.
top open.
- [exEnd]
+ [exEnd]
changing colors, turning percentage display off:
- [exBegin]
+ [exBegin]
|top p h|
top := StandardSystemView new.
@@ -129,20 +129,20 @@
p foregroundColor:(Color red).
h := 10.
p topInset:(h // 2) negated;
- bottomInset:(h // 2) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 2) negated;
+ leftInset:5;
+ rightInset:5.
top open.
[
- 1 to:100 do:[:val |
- (Delay forSeconds:0.05) wait.
- p percentage:val
- ]
+ 1 to:100 do:[:val |
+ (Delay forSeconds:0.05) wait.
+ p percentage:val
+ ]
] fork
- [exEnd]
+ [exEnd]
as a busy indicator and percentage display (as in netscape)
- [exBegin]
+ [exBegin]
|top p h|
top := ModalBox new.
@@ -155,31 +155,31 @@
p backgroundColor:(Color cyan).
h := p preferredExtent y.
p topInset:(h // 3) negated;
- bottomInset:(h // 3) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 3) negated;
+ leftInset:5;
+ rightInset:5.
p showBusyIndication:true.
[
- top label:'Busy'.
- 1 to:100 do:[:i |
- (Delay forSeconds:0.05) wait.
- ].
+ top label:'Busy'.
+ 1 to:100 do:[:i |
+ (Delay forSeconds:0.05) wait.
+ ].
- top label:'Percentage'.
- p showBusyIndication:false.
- 1 to:100 do:[:i |
- (Delay forSeconds:0.05) wait.
- p percentage:i.
- ].
+ top label:'Percentage'.
+ p showBusyIndication:false.
+ 1 to:100 do:[:i |
+ (Delay forSeconds:0.05) wait.
+ p percentage:i.
+ ].
- top hide.
+ top hide.
] fork.
top open.
- [exEnd]
+ [exEnd]
with border (2D look):
- [exBegin]
+ [exBegin]
|top p h|
top := StandardSystemView new.
@@ -190,21 +190,21 @@
p borderWidth:1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
- bottomInset:(h // 2) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 2) negated;
+ leftInset:5;
+ rightInset:5.
top open.
[
- 1 to:100 do:[:val |
- (Delay forSeconds:0.05) wait.
- p percentage:val
- ]
+ 1 to:100 do:[:val |
+ (Delay forSeconds:0.05) wait.
+ p percentage:val
+ ]
] fork
- [exEnd]
+ [exEnd]
getting progress from a model:
- [exBegin]
+ [exBegin]
|model top p h|
model := 0 asValue.
@@ -218,24 +218,24 @@
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
- bottomInset:(h // 2) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 2) negated;
+ leftInset:5;
+ rightInset:5.
top open.
[
- 1 to:100 do:[:val |
- (Delay forSeconds:0.05) wait.
- model value:val
- ]
+ 1 to:100 do:[:val |
+ (Delay forSeconds:0.05) wait.
+ model value:val
+ ]
] fork
- [exEnd]
+ [exEnd]
concrete example:
search all files in the source directory for a string
using grep. Show progress while doing so.
- [exBegin]
+ [exBegin]
|top p h names done|
top := StandardSystemView new.
@@ -246,33 +246,33 @@
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
- bottomInset:(h // 2) negated;
- leftInset:5;
- rightInset:5.
+ bottomInset:(h // 2) negated;
+ leftInset:5;
+ rightInset:5.
top openWithPriority:(Processor activePriority + 1).
names := 'source' asFilename directoryContents.
done := 0.
names do:[:aName |
- |fn stream line|
+ |fn stream line|
- p percentage:(done / names size * 100).
- fn := ('source/' , aName) asFilename.
- fn isDirectory ifFalse:[
- stream := fn readStream.
- [stream atEnd] whileFalse:[
- line := stream nextLine.
- (line findString:'subclass:') ~~ 0 ifTrue:[
- Transcript showCR:line
- ].
- ].
- stream close.
- ].
- done := done + 1
+ p percentage:(done / names size * 100).
+ fn := ('source/' , aName) asFilename.
+ fn isDirectory ifFalse:[
+ stream := fn readStream.
+ [stream atEnd] whileFalse:[
+ line := stream nextLine.
+ (line findString:'subclass:') ~~ 0 ifTrue:[
+ Transcript showCR:line
+ ].
+ ].
+ stream close.
+ ].
+ done := done + 1
].
top destroy
- [exEnd]
+ [exEnd]
using the convenient inBox-interface
@@ -281,105 +281,123 @@
to indicate ...)
basic interface demonstration:
- [exBegin]
+ [exBegin]
|p|
p := ProgressIndicator
- inBoxWithLabel:'doing something ...'
- abortable:true.
+ inBoxWithLabel:'doing something ...'
+ abortable:true.
p showProgressOf:
- [:progressValue :currentAction |
+ [:progressValue :currentAction |
- 1 to:100 do:[:val |
- (Delay forSeconds:0.05) wait.
- val == 25 ifTrue:[
- currentAction value:'still going ...'
- ].
- val == 50 ifTrue:[
- currentAction value:'halfway through ...'
- ].
- val == 75 ifTrue:[
- currentAction value:'almost finished ...'
- ].
- progressValue value:val
- ]
- ]
- [exEnd]
+ 1 to:100 do:[:val |
+ (Delay forSeconds:0.05) wait.
+ val == 25 ifTrue:[
+ currentAction value:'still going ...'
+ ].
+ val == 50 ifTrue:[
+ currentAction value:'halfway through ...'
+ ].
+ val == 75 ifTrue:[
+ currentAction value:'almost finished ...'
+ ].
+ progressValue value:val
+ ]
+ ]
+ [exEnd]
above search example using this convenient interface:
- [exBegin]
+ [exBegin]
|p|
p := ProgressIndicator
- inBoxWithLabel:'searching files ...'
- abortable:false.
+ inBoxWithLabel:'searching files ...'
+ abortable:false.
p showProgressOf:
- [:progressValue :currentAction |
- |names nDone|
+ [:progressValue :currentAction |
+ |names nDone|
- names := 'source' asFilename directoryContents.
- nDone := 0.
- names do:[:aName |
- |fn stream line|
+ names := 'source' asFilename directoryContents.
+ nDone := 0.
+ names do:[:aName |
+ |fn stream line|
- progressValue value:(nDone / names size * 100).
- currentAction value:'searching ' , 'source/' , aName , ' ...'.
+ progressValue value:(nDone / names size * 100).
+ currentAction value:'searching ' , 'source/' , aName , ' ...'.
- fn := ('source/' , aName) asFilename.
- fn isDirectory ifFalse:[
- stream := fn readStream.
- [stream atEnd] whileFalse:[
- line := stream nextLine.
- (line findString:'subclass:') ~~ 0 ifTrue:[
- Transcript showCR:line
- ].
- ].
- stream close.
- ].
- nDone := nDone + 1
- ].
- ].
- [exEnd]
+ fn := ('source/' , aName) asFilename.
+ fn isDirectory ifFalse:[
+ stream := fn readStream.
+ [stream atEnd] whileFalse:[
+ line := stream nextLine.
+ (line findString:'subclass:') ~~ 0 ifTrue:[
+ Transcript showCR:line
+ ].
+ ].
+ stream close.
+ ].
+ nDone := nDone + 1
+ ].
+ ].
+ [exEnd]
a nice example: copying files a la windows ...
the following copies all files to /dev/null.
- [exBegin]
+ [exBegin]
|p|
(ProgressIndicator
- inBoxWithLabel:'copy files to /dev/null ...'
- abortable:true)
- showProgressOf:
- [:progressValue :currentAction |
- |files nFiles nDone|
+ inBoxWithLabel:'copy files to /dev/null ...'
+ abortable:true)
+ showProgressOf:
+ [:progressValue :currentAction |
+ |files nFiles nDone|
- files := '.' asFilename directoryContents.
- nFiles := files size.
- nDone := 0.
- files do:[:aFileName |
- |percent|
+ files := '.' asFilename directoryContents.
+ nFiles := files size.
+ nDone := 0.
+ files do:[:aFileName |
+ |percent|
- nDone := nDone + 1.
- percent := nDone / nFiles * 100.
- progressValue value:percent.
- aFileName asFilename isDirectory ifTrue:[
- Transcript showCR:('skipping ' , aFileName , ' ...').
- currentAction value:('skipping ' , aFileName , ' ...').
- ] ifFalse:[
- Transcript showCR:('copying ' , aFileName , ' ...').
- currentAction value:('copying ' , aFileName , ' ...').
- Object errorSignal handle:[:ex |
- self warn:'an error occurred while copying ' , aFileName.
- ex return
- ] do:[
- aFileName asFilename copyTo:'/dev/null'.
- ]
- ].
- ].
- ].
- [exEnd]
+ nDone := nDone + 1.
+ percent := nDone / nFiles * 100.
+ progressValue value:percent.
+ aFileName asFilename isDirectory ifTrue:[
+ Transcript showCR:('skipping ' , aFileName , ' ...').
+ currentAction value:('skipping ' , aFileName , ' ...').
+ ] ifFalse:[
+ Transcript showCR:('copying ' , aFileName , ' ...').
+ currentAction value:('copying ' , aFileName , ' ...').
+ Object errorSignal handle:[:ex |
+ self warn:'an error occurred while copying ' , aFileName.
+ ex return
+ ] do:[
+ aFileName asFilename copyTo:'/dev/null'.
+ ]
+ ].
+ ].
+ ].
+ [exEnd]
+
+ [exBegin]
+ ProgressIndicator
+ displayBusyIndicator:'Test...'
+ at:(Screen default center)
+ during:[:p |
+ p labelWidget label:'bla...'.
+ Delay waitForSeconds:0.5.
+
+ 1 to:3 do:[:idx |
+ Delay waitForSeconds:0.5.
+ p labelWidget label:('bla %1...' bindWith:idx).
+ ].
+ Delay waitForSeconds:0.5.
+ p labelWidget label:'blabla...'.
+ Delay waitForSeconds:0.5.
+ ].
+ [exEnd]
"
! !
@@ -864,6 +882,12 @@
!ProgressIndicator methodsFor:'accessing'!
+labelWidget
+ ^ connectedLabel
+
+ "Created: / 07-11-2011 / 22:01:00 / cg"
+!
+
percentage:aNumber
"set the percentage"
@@ -1249,7 +1273,7 @@
"/ the worker process
[
- aBlock value
+ aBlock valueWithOptionalArgument:labelValue
] ensure:[
p terminate.
p := nil.
@@ -1401,7 +1425,7 @@
WindowGroup windowGroupQuerySignal handle:[:ex |
ex proceedWith:self topView windowGroup
] do:[
- aBlock value
+ aBlock valueWithOptionalArgument:labelValue
]
] ensure:[
p := nil.
@@ -1447,7 +1471,6 @@
"
- "Modified: / 21-10-1998 / 17:37:00 / cg"
"Created: / 14-09-2011 / 18:41:34 / cg"
!
@@ -1574,7 +1597,7 @@
WindowGroup windowGroupQuerySignal handle:[:ex |
ex proceedWith:self topView windowGroup
] do:[
- aBlock value
+ aBlock valueWithOptionalArgument:labelValue
]
] ensure:[
p := nil.
@@ -1620,7 +1643,7 @@
"
- "Modified: / 21.10.1998 / 17:37:00 / cg"
+ "Modified: / 07-11-2011 / 21:53:46 / cg"
!
showProgressOf:aBlock
@@ -1672,9 +1695,9 @@
!ProgressIndicator class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.68 2011-09-14 16:44:14 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.69 2011-11-07 21:03:10 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.68 2011-09-14 16:44:14 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.69 2011-11-07 21:03:10 cg Exp $'
! !