The real work takes place in the sub OnTest lines , where our example progress dialog is initialized and displayed. Line 53 sets up the number of dummy items we'll be using to drive the process dialog. Lines 54 to 60 create a new Wx:: This particular example has all of the options this particular sort of dialog can possess enabled.
Let's examine the parameters we're passing to the constructor: We've got a string value that will be displayed in the titlebar of the dialog. Our example value is set to "Progress Dialog Example" "An Example" is what the dialog will show as the initial line of text. This is a good place for, e. The maximum value that the progress meter is working towards.
This is used with the Update method, described below A reference to a Wx:: Frame or potentially a Wx:: If this option is not set, the dialog will still be modal to its parent, but not to sibling windows. When this button is pressed by the user, the dialog will close.
This action can be checked by examining the return value of the Update method explained below. This does not cancel any of the script's processing, but simply flags the user's desire to end processing. If the constructor succeeds, the dialog displays automatically. Lines are where the script processes data, and updates the dialog. Line 64 gives us the only method of communicating to the dialog, the Update method.
Update takes 2 parameters A numeric value. Should be a positive value, and equal or less than the the maximum set in the constructor. Setting this value above the maximum will have unintended consequences. A string value used to update the text message in the dialog. This parameter is optional. If it's missing, the text message will remain the same as when the dialog was created, or what it was set to during the last update.
If it's set to zero, we exit the loop, ending our processing early. In a weightier script, you may have to perform clean up duties if this occurs. Line 66 shows where any real processing would occur. Finally, line 68 calls Destroy, and cleans up the dialog. There is another method to Wx:: ProgressDialog not discussed here, called Resume, which should only be called after the user's chosen to abort the dialog. Resume will redisplay the dialog from the point when the user clicked "Cancel".
It is still the programmer's duty to make sure that the data being processed remains in sync with the dialog. Do not call Resume if you've already called Destroy on a dialog.
An example Let's say we've created the world's greatest GUI file copying utility, ever. We'd like to have the app display which file it's currently copying, and give the user the chance to stop copying if he chooses.
We also want to show the estimated time remaining to complete the copying, but aren't entirely concerned about the elapsed time, nor the total time the copying should take.
We also have an array, items, which contains the names of the files we're copying. Here's how the dialog would be created: Yield ; redraw, etc.