Progress bar panel
Posted April 23rd, 2008 by aclight
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.
Progress bar panel
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:
- 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
DoUpdateso that Igor will redraw the progress bar control. - 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
Just some thoughts ...
Cool!
Would a better reference to the control variable be ...
... 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 ...
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH