eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ProgressIndicator':

Home

everywhere
www.exept.de
for:
[back]

Class: ProgressIndicator


Inheritance:

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

Package:
stx:libwidg2
Category:
Views-Misc
Version:
rev: 1.60 date: 2009/10/26 15:24:04
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).

simple puplic 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.

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

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

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.


Instance protocol:

accessing
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 displays background color

o  foregroundColor
return the percentage displays foreground color

o  foregroundColor: aColor
set the percentage displays 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

initialization & release
o  destroy

o  initStyle
initialize styleSheet values

o  initialize

o  mapped

o  unmapped

private
o  connectToTop: top label: label

o  startBusyIndicationProcess

o  stopBusyIndicationProcess

o  updateBusyIndicatorPosition

queries
o  preferredExtent
return my preferred extent

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


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


ST/X 6.1.1; WebServer 1.620 at exept:8081; Tue, 22 May 2012 21:46:25 GMT