eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ProgressIndicator':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ProgressIndicator


Inheritance:

   Object
   |
   +--GraphicsMedium
      |
      +--DisplaySurface
         |
         +--SimpleView
            |
            +--View
               |
               +--ProgressIndicator
                  |
                  +--RoundProgressIndicator

Package:
stx:libwidg2
Category:
Views-Misc
Version:
rev: 1.85 date: 2018/03/23 11:19:42
user: cg
file: ProgressIndicator.st directory: libwidg2
module: stx stc-classLibrary: libwidg2
Author:
Claus Gittinger

Description:


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.


Related information:

    ActionWaitBox
    AnimatedLabel

Class protocol:

instance creation
o  inBox
create a topView containing an instance of myself,
for later use with #showProgressOf:

o  inBoxWithLabel: aLabel
create a topView containing an instance of myself,
for later use with #showProgressOf:

o  inBoxWithLabel: aLabel abortable: abortable
create a topView containing an instance of myself,
for later use with #showProgressOf:

o  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:

o  inBoxWithLabel: aLabel text: text abortable: abortable
create a topView containing an instance of myself,
for later use with #showProgressOf:

o  inBoxWithLabel: aLabel text: text abortable: abortable view: additionalView
create a topView containing an instance of myself,
for later use with #showProgressOf:

o  inBoxWithLabel: aLabel text: text abortable: abortable view: additionalView closeWhenDone: closeWhenDoneBoolean
create a topView containing an instance of myself,
for later use with #showProgressOf:

o  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).

o  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
o  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.
        ].

o  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 blocks 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.
            ]
        ].

o  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.
        ].

o  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 blocks 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.
            ]
        ].

o  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 blocks 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.
            ]
        ].

o  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 blocks 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.
            ]
        ].

o  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.
        ].

o  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.
        ].


Instance protocol:

accessing
o  labelWidget

o  model: aValueHolder
set my percentage holder

o  percentage: aNumber
set the percentage

o  showBusyIndication: aBooleanHolder
switch between percentage mode (if false) and busy indication (if true)

accessing-behavior
o  closeTopWhenDone: aBoolean
set/clear the close-topView-when-done flag

o  finishAction: aBlock
define an action to be performed when finished

accessing-look
o  backgroundColor
return the percentage displays background color

o  backgroundColor: aColor
set the percentage display's background color

o  foregroundColor
return the percentage displays foreground color

o  foregroundColor: aColor
set the percentage display's foreground color

o  showPercentage
return the flag controlling if the percentage is to be shown numerically

o  showPercentage: aBoolean
set/clear the flag controlling if the percentage is to be shown numerically

change & update
o  update: aspect with: aParameter from: changedObject
react upon value changes of my model

drawing
o  redraw
redraw the percentage bar and optional percentage string

o  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
o  destroy
(comment from inherited method)
unmap & destroy - make me invisible, destroy subviews then
make me unknown to the device

o  initStyle
initialize styleSheet values

o  initialize
(comment from inherited method)
must be called if redefined

o  mapped

o  release

o  unmapped

private
o  connectToTop: top label: label

o  startBusyIndicationProcess

o  stopBusyIndicationProcess

o  updateBusyIndicatorPosition
busyPosition >= 80 ifTrue:[

queries
o  preferredExtent
return my preferred extent
usage example(s):
If I have an explicit preferredExtent..
usage example(s):
If I have a cached preferredExtent value..

showing progress
o  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 ...

o  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 ...

o  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 ...

o  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 ...

o  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 ...

o  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


Examples:


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.
        ].


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 22 Jul 2018 16:46:26 GMT