Progress bar panel

Using the built in ValDisplay control type makes it pretty easy to create a progress bar that can be used to indicate how close some process is to being completed.
[img_assist|nid=620|title=Progress bar panel|desc=|link=node|align=right|width=230|height=157]

To use the code below, you'll need to create a global variable in the root data folder named percentFinished and you need to update this variable in your loop. Keep the following points in mind:

  1. If you're doing all of your processing in one loop/function that doesn't return until the process is complete, you'll need to periodically call DoUpdate so that Igor will redraw the progress bar control.

  2. Again, if you're doing everything in one big loop, the Abort button on the panel may be useless, since Igor might not process the button push event until the loop has finished. The behavior here may depend on what version of Igor you're running. I used this code originally within a background task, and each time the background task function was called I processed a chunk of data, updated the percentFinished variable, and then returned until the background task was called again.



Window pnlProgress() : Panel
    PauseUpdate; Silent 1       // building window...
    NewPanel /W=(267,122,480,236) as "Progress"
    SetDrawLayer UserBack
    SetDrawEnv fsize= 16
    DrawText 74,23,"Progress:"
    ValDisplay valdispProgress,pos={8,28},size={200,45},frame=4
    ValDisplay valdispProgress,limits={0,100,0},barmisc={10,1},bodyWidth= 200
    ValDisplay valdispProgress,value= #"percentFinished"
    Button buttonAbort,pos={73,78},size={70,30},proc=Button_Abort,title="Abort"
    Button buttonAbort,fSize=14
End
 
Function Button_Abort(ba) : ButtonControl
    STRUCT WMButtonAction &ba
    switch( ba.eventCode )
        case 2: // mouse up
            <add code here to abort the loop or process>
            break
    endswitch
    return 0
End
Just some thoughts ...

Cool!

Would a better reference to the control variable be ...

    ValDisplay valdispProgress, value=#"root:percentFinished"


... in case processing is done outside root. Also, by changing to NewPanel/N=pnl_Panel/W=..., this part could be added (running as a background task?) to automatically kill the panel ...

Function pnl_KillPanel()
    NVAR pc = root:percentFinished
    if (pc>=100)
         KillPanel pnl_Panel
         <do other things when processing is done>
    endif
    return 0
end


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Is it possible change the height of the progress bar?

I played around with the parameters, but the white bar always has the same height - which is too big for my application....
It is possible to get the Abort button to function more promptly. Simply use the GetMouse operation in your main loop or whenever the progress bar is to be updated. The GetMouse operation detects if the Mouse is down, and what its location is. Test for mouse down, and location in the Abort button (known from the pnlProgress parameters); if all Mouse conditions are satisfied, program your main loop function to stop (e.g. break from a For loop, or set a Do - While condition false).
DisplayHelpTopic "GetMouse"

Quote:

The GetMouse operation returns information about the position of the input mouse, and the state of the mouse buttons.
GetMouse is useful in situations such as background tasks where the mouse position and state aren't available as they are in control procedures and window hook functions.
GetMouse was added in Igor 6.30.
I have a nooby question: Where exactly one should put this code in? It cannot be inserted into function's body... When one has to call doupdate? In the loop or outside? Help...

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More