|
Class: ProgressIndicator
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--View
|
+--ProgressIndicator
|
+--RoundProgressIndicator
- Package:
- stx:libwidg2
- Category:
- Views-Misc
- Version:
- rev:
1.91
date: 2019/03/13 09:30:41
- user: cg
- file: ProgressIndicator.st directory: libwidg2
- module: stx stc-classLibrary: libwidg2
- Author:
- Claus Gittinger
a view showing a rectangle filled according the percentage value.
Can be used as a progress indicator a la MSwindows;
it can also be configured as a non-percentage busy indication
via the showBusyIndication flag (a la netscape).
Can be used as a widget within an application, or
via the convenient #inBox: instance creation messages,
which shows a progressDisplay in a modalBox, while some
action is performed.
See examples.
ActionWaitBox
AnimatedLabel
instance creation
-
inBox
-
create a topView containing an instance of myself,
for later use with #showProgressOf:
-
inBoxWithLabel: aLabel
-
create a topView containing an instance of myself,
for later use with #showProgressOf:
-
inBoxWithLabel: aLabel abortable: abortable
-
create a topView containing an instance of myself,
for later use with #showProgressOf:
-
inBoxWithLabel: aLabel icon: anIcon text: text abortable: abortable view: additionalView closeWhenDone: closeWhenDoneBoolean
-
create a topView containing an instance of myself,
return the new instance, for later use with #showProgressOf:
-
inBoxWithLabel: aLabel text: text abortable: abortable
-
create a topView containing an instance of myself,
for later use with #showProgressOf:
-
inBoxWithLabel: aLabel text: text abortable: abortable view: additionalView
-
create a topView containing an instance of myself,
for later use with #showProgressOf:
-
inBoxWithLabel: aLabel text: text abortable: abortable view: additionalView closeWhenDone: closeWhenDoneBoolean
-
create a topView containing an instance of myself,
for later use with #showProgressOf:
-
progressOpenOn: progressModel label: aLabel
-
create and open a progressIndicator dialog window,
bit do not open it modal; instead, it is opened modeless
and control returns to the caller.
The models value is assumed to be 0..1
(which is for compatibility and different from ST/X's percentage use)
Added for VW compatibility (RB).
-
progressOpenOn: progressModel title: title label: aLabel
-
create and open a progressIndicator dialog window,
bit do not open it modal; instead, it is opened modeless
and control returns to the caller.
The models value is assumed to be 0..1
(which is for compatibility and different from ST/X's percentage use)
Added for VW compatibility (RB).
simple public API
-
displayBusyIndicator: aLabel abortable: abortable at: aPoint during: aBlock
-
easy interface - show progress while evaluating aBlock.
The block is passed the progressIndicator as argument
so the block can change the label and/or change the progress value.
usage example(s):
ProgressIndicator
displayBusyIndicator:'doobidoobidoo...'
abortable:true
at:(Screen default center)
during:[
200 to:400 by:5 do:[:i |
Delay waitForSeconds:0.1.
]
].
ProgressIndicator
displayBusyIndicator:'doobidoobidoo...'
abortable:true
at:(Screen default center)
during:[
Delay waitForSeconds:3.
].
|
-
displayBusyIndicator: aLabel at: aPoint during: aBlock
-
easy interface - show progress while evaluating aBlock.
The block is passed a valueHolder, which is to be set to values from
startValue to endValue during the block's evaluation.
This is scaled to 0..100% completion.
Set the valueHolder to nil, to get a busy-indicator
usage example(s):
ProgressIndicator
displayBusyIndicator:'doobidoobidoo...'
at:(Screen default center)
during:[
200 to:400 by:5 do:[:i |
Delay waitForSeconds:0.1.
]
].
|
-
displayBusyIndicator: aLabel message: messageString abortable: abortable at: aPoint during: aBlock
-
easy interface - show progress while evaluating aBlock.
The block is passed the progressIndicator as argument
so the block can change the label and/or change the progress value.
usage example(s):
ProgressIndicator
displayBusyIndicator:'doobidoobidoo...'
abortable:true
at:(Screen default center)
during:[
200 to:400 by:5 do:[:i |
Delay waitForSeconds:0.1.
]
].
ProgressIndicator
displayBusyIndicator:'doobidoobidoo...'
abortable:true
at:(Screen default center)
during:[
Delay waitForSeconds:3.
].
|
-
displayBusyIndicator: aLabel message: messageString at: aPoint during: aBlock
-
easy interface - show progress while evaluating aBlock.
The block is passed a valueHolder, which is to be set to values from
startValue to endValue during the block's evaluation.
This is scaled to 0..100% completion.
Set the valueHolder to nil, to get a busy-indicator
usage example(s):
ProgressIndicator
displayBusyIndicator:'doobidoobidoo...'
message:'message'
at:(Screen default center)
during:[
200 to:400 by:5 do:[:i |
Delay waitForSeconds:0.1.
]
].
|
-
displayProgress: aLabel at: aPoint from: startValue to: endValue during: aBlock
-
easy interface - show progress while evaluating aBlock.
The block is passed a valueHolder, which is to be set to values from
startValue to endValue during the block's evaluation.
This is scaled to 0..100% completion.
Set the valueHolder to nil, to get a busy-indicator
usage example(s):
ProgressIndicator
displayProgress:'doobidoobidoo...'
at:(Screen default center)
from:200 to:400
during:[:val |
200 to:400 by:5 do:[:i |
val value:i.
Delay waitForSeconds:0.1.
]
].
|
-
displayProgress: aLabel message: messageString at: aPoint from: startValue to: endValue during: aBlock
-
easy interface - show progress while evaluating aBlock.
The block is passed a valueHolder, which is to be set to values from
startValue to endValue during the block's evaluation.
This is scaled to 0..100% completion.
Set the valueHolder to nil, to get a busy-indicator
usage example(s):
ProgressIndicator
displayProgress:'doobidoobidoo...'
at:(Screen default center)
from:200 to:400
during:[:val |
200 to:400 by:5 do:[:i |
val value:i.
Delay waitForSeconds:0.1.
]
].
|
-
displayProgressNotifications: aLabel abortable: abortable at: aPointOrNil during: aBlock
-
easy interface - show progress as provided by progressNotifications
while evaluating aBlock.
The block is passed the progressIndicator as optional argument,
however, progressNotifications are handled and update the percentage.
usage example(s):
ProgressIndicator
displayProgressNotifications:'doobidoobidoo...'
abortable:true
at:nil
during:[
200 to:400 by:5 do:[:i |
Delay waitForSeconds:0.1.
ProgressNotification progressPercentage:(i / 4).
]
].
|
usage example(s):
ProgressIndicator
displayProgressNotifications:'doobidoobidoo...'
abortable:true
at:nil
during:[
Delay waitForSeconds:3.
].
|
-
displayProgressNotifications: aLabel message: messageString abortable: abortable at: aPointOrNil during: aBlock
-
easy interface - show progress as provided by progressNotifications
while evaluating aBlock.
The block is passed the progressIndicator as optional argument,
however, progressNotifications are handled and update the percentage.
usage example(s):
ProgressIndicator
displayProgressNotifications:'doobidoobidoo...'
abortable:true
at:nil
during:[
200 to:400 by:5 do:[:i |
Delay waitForSeconds:0.1.
ProgressNotification progressPercentage:(i / 4).
]
].
|
usage example(s):
ProgressIndicator
displayProgressNotifications:'doobidoobidoo...'
abortable:true
at:nil
during:[
Delay waitForSeconds:3.
].
|
accessing
-
labelWidget
-
-
model: aValueHolder
-
set my percentage holder
-
percentage: aNumber
-
set the percentage
-
showBusyIndication: aBooleanHolder
-
switch between percentage mode (if false) and busy indication (if true)
accessing-behavior
-
closeTopWhenDone: aBoolean
-
set/clear the close-topView-when-done flag
-
finishAction: aBlock
-
define an action to be performed when finished
accessing-look
-
backgroundColor
-
return the percentage displays background color
-
backgroundColor: aColor
-
set the percentage display's background color
-
foregroundColor
-
return the percentage displays foreground color
-
foregroundColor: aColor
-
set the percentage display's foreground color
-
showPercentage
-
return the flag controlling if the percentage is to be shown numerically
-
showPercentage: aBoolean
-
set/clear the flag controlling if the percentage is to be shown numerically
change & update
-
update: aspect with: aParameter from: changedObject
-
react upon value changes of my model
drawing
-
redraw
-
redraw the percentage bar and optional percentage string
-
sizeChanged: how
-
(comment from inherited method)
tell subviews that I changed size.
How is either #smaller, #larger or nil, and is used to control the order,
in which subviews are notified (possibly reducing redraw activity)
initialization & release
-
destroy
-
(comment from inherited method)
unmap & destroy - make me invisible, destroy subviews then
make me unknown to the device
-
initStyle
-
initialize styleSheet values
-
initialize
-
(comment from inherited method)
must be called if redefined
-
mapped
-
-
release
-
-
unmapped
-
private
-
connectToTop: top label: label
-
I am a modal progressindicator (running in a resizable topview)
-
startBusyIndicationProcess
-
-
stopBusyIndicationProcess
-
-
updateBusyIndicatorPosition
-
busyPosition >= 80 ifTrue:[
queries
-
computePreferredExtent
-
return my preferred extent
showing progress
-
new_showBusyIndicatorDuring: aBlock
-
show progress, while evaluating aBlock.
If the receiver has been created with inBox, show the
box centered on the screen. If not, the view is assumed to
be contained in another view, and no special startup actions
are performed.
Caveat: cannot (currently) suppress close of the box ...
-
new_showProgressOf: aBlock
-
show progress, while evaluating aBlock.
If the receiver has been created with inBox, show the
box centered on the screen. If not, the view is assumed to
be contained in another view, and no special startup actions
are performed.
The block is passed two arguments, the progressValue,
which should be set to the percentage from time-to-time
within the block and an action value, which should be set to
the currently performed action (a string) from time to time.
The second valueHolder can be left unchanged.
Caveat: cannot (currently) suppress close of the box ...
-
old_showBusyIndicatorDuring: aBlock
-
show progress, while evaluating aBlock.
If the receiver has been created with inBox, show the
box centered on the screen. If not, the view is assumed to
be contained in another view, and no special startup actions
are performed.
Caveat: cannot (currently) suppress close of the box ...
-
old_showProgressOf: aBlock
-
show progress, while evaluating aBlock.
If the receiver has been created with inBox, show the
box centered on the screen. If not, the view is assumed to
be contained in another view, and no special startup actions
are performed.
The block is passed two arguments, the progressValue,
which should be set to the percentage from time-to-time
within the block and an action value, which should be set to
the currently performed action (a string) from time to time.
The second valueHolder can be left unchanged.
Caveat: cannot (currently) suppress close of the box ...
-
showBusyIndicatorDuring: aBlock
-
show progress, while evaluating aBlock.
If the receiver has been created with inBox, show the
box centered on the screen. If not, the view is assumed to
be contained in another view, and no special startup actions
are performed.
Caveat: cannot (currently) suppress close of the box ...
-
showProgressOf: aBlock
-
show progress, while evaluating aBlock.
If the receiver has been created with inBox, show the
box centered on the screen. If not, the view is assumed to
be contained in another view, and no special startup actions
are performed.
The block is passed two arguments, the progressValue,
which should be set to the percentage from time-to-time
within the block and an action value, which should be set to
the currently performed action (a string) from time to time.
The second valueHolder can be left unchanged.
Caveat: cannot (currently) suppress close of the box ...
usage example(s):
^ self old_showProgressOf:aBlock
|
basic (internal) interface
(if progress indicator is to be used in a complex box ...):
Before you get frustrated - see the convenient-interface examples
at the end ;-)
|top p h|
top := ModalBox new.
top extent:300@100.
top label:'Progress'.
p := ProgressIndicator in:top.
p origin:(0.0@0.5) corner:(1.0@0.5).
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
bottomInset:(h // 2) negated;
leftInset:5;
rightInset:5.
[
1 to:100 do:[:val |
(Delay forSeconds:0.05) wait.
p percentage:val
].
top hide.
] fork.
top open.
|
as a busy indicator
|top p h|
top := ModalBox new.
top extent:300@100.
top label:'Busy'.
p := ProgressIndicator in:top.
p origin:(0.0@0.5) corner:(1.0@0.5).
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
bottomInset:(h // 2) negated;
leftInset:5;
rightInset:5.
p showBusyIndication:true.
[
'do something here ....'.
(Delay forSeconds:5) wait.
top hide.
] fork.
top open.
|
changing colors, turning percentage display off:
|top p h|
top := StandardSystemView new.
top extent:300@100.
top label:'Progress'.
p := ProgressIndicator in:top.
p origin:(0.0@0.5) corner:(1.0@0.5).
p level:-1.
p showPercentage:false.
p foregroundColor:(Color red).
h := 10.
p topInset:(h // 2) negated;
bottomInset:(h // 2) negated;
leftInset:5;
rightInset:5.
top open.
[
1 to:100 do:[:val |
(Delay forSeconds:0.05) wait.
p percentage:val
]
] fork
|
as a busy indicator and percentage display (as in netscape)
|top p h|
top := ModalBox new.
top extent:300@60.
top label:'Busy'.
p := ProgressIndicator in:top.
p origin:(0.0@0.5) corner:(1.0@0.5).
p level:-1.
p showPercentage:false.
p backgroundColor:(Color cyan).
h := p preferredExtent y.
p topInset:(h // 3) negated;
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:'Percentage'.
p showBusyIndication:false.
1 to:100 do:[:i |
(Delay forSeconds:0.05) wait.
p percentage:i.
].
top hide.
] fork.
top open.
|
with border (2D look):
|top p h|
top := StandardSystemView new.
top extent:300@100.
top label:'Progress'.
p := ProgressIndicator in:top.
p origin:(0.0@0.5) corner:(1.0@0.5).
p borderWidth:1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
bottomInset:(h // 2) negated;
leftInset:5;
rightInset:5.
top open.
[
1 to:100 do:[:val |
(Delay forSeconds:0.05) wait.
p percentage:val
]
] fork
|
getting progress from a model:
|model top p h|
model := 0 asValue.
top := StandardSystemView new.
top extent:300@100.
top label:'Progress'.
p := ProgressIndicator in:top.
p model:model.
p origin:(0.0@0.5) corner:(1.0@0.5).
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
bottomInset:(h // 2) negated;
leftInset:5;
rightInset:5.
top open.
[
1 to:100 do:[:val |
(Delay forSeconds:0.05) wait.
model value:val
]
] fork
|
concrete example:
search all files in the source directory for a string
using grep. Show progress while doing so.
|top p h names done|
top := StandardSystemView new.
top extent:300@100.
top label:'Searching ...'.
p := ProgressIndicator in:top.
p origin:(0.0@0.5) corner:(1.0@0.5).
p level:-1.
h := p preferredExtent y.
p topInset:(h // 2) negated;
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|
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
|
using the convenient inBox-interface
(this creates a box and an activity label and evaluates a block
to indicate ...)
basic interface demonstration:
|p|
p := ProgressIndicator
inBoxWithLabel:'doing something ...'
abortable:true.
p showProgressOf:
[: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
]
]
|
above search example using this convenient interface:
|p|
p := ProgressIndicator
inBoxWithLabel:'searching files ...'
abortable:false.
p showProgressOf:
[:progressValue :currentAction |
|names nDone|
names := 'source' asFilename directoryContents.
nDone := 0.
names do:[:aName |
|fn stream line|
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
].
].
|
a nice example: copying files a la windows ...
the following copies all files to /dev/null.
|p|
(ProgressIndicator
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|
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'.
]
].
].
].
|
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.
].
|
|