‎04-07-2012 01:12 PM - last edited on ‎06-07-2012 09:20 AM by François
This article teach how to implement a progress bar (called also gauge) to show the execution progression of a script. The progress bar can be put inside an existing window or can create a new window if required. It is useful to give a visual feedback to the user while MEGA is executing a time consuming script.
When executing a time consuming script you can setup a Progress Bar to let the user know that something is happening, and also show an estimation of the progress if you know how much steps you will need to complete.
Mega has the MegaProgressControl object to implement progress bars.
If you are inside a wizard then the progress bar will be put in the bottom left corner of the wizard.
If you are not in a wizard then a new popup window will appears, just with the progress bar and a status line.
To create this use the following code (root is a MegaRoot😞
JAVA
MegaProgressControl pBar = new MegaProgressControl(root);
pBar.create();
pBar.text("I'm a progress bar");
pBar.setRange(0, 1000);
for(int i=0; i<1000; i++) {
pBar.status("We are at " + i);
pBar.setGauge(i);
}
pBar.destroy();
VB
set pBar = root.ContextObject("#Window")
pBar.create
pBar.text = "I'm a progress bar"
pBar.setRange 1, 1000
for i=1 to 1000
pBar.status = "We are at " & i
pBar.setGauge i
next
pBar.destroy
If you want to know if the user clicked on the "Abort" button then check the value pBar.isAborted() (method in Java, value in VB),if the result id true then the user clicked on the abourt button.
The list of available methods is (Java version, but VB is pretty the same, just use all methods as properties in VB):
Let the user know what's happening!