User Tools

Site Tools


Progress

Summary

Below is an example demonstrating how you can cause a modal progress dialog to be displayed and report progress via script.

API Areas of Interest

Example

Progress.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Declare the total number of cycles
	var nCycles = 100000;
	// Declare how frequently you want to update the progress
	var nFrequency = 100;
 
	// Define whether or not the user can cancel
	var bCancellable = true;
 
	// Start the progress
	startProgress( text( "This is a simple progress test." ), nCycles/nFrequency, bCancellable, true );
 
	// Iterate over the cycles
	for( var i = 0; i < nCycles; i += 1 ){
		// If the current iteration is divisible by the frequency with no remainder
		if( i % nFrequency == 0 ){
			// Step the progress by 1
			stepProgress( 1 );
 
			// If the current iteration is later than the first and it is
			// divisible by 100 times the frequency with no remainder
			if( i > 0 && i % (nFrequency * 100) == 0 ){
				// Post a status update; but do not write to the log
				App.statusLine( i, false );
			}
 
			// Slow progress down enough to be able to see things happen
			sleep( 5 );
		}
 
		// If the user is allowed to cancel
		if( bCancellable ){
			// Process events so that we can check user interaction
			processEvents();
 
			// If the user cancelled
			if( progressIsCancelled() ){
				// Post a status update
				App.statusLine( text( "User cancelled simple progress test." ) );
				// We are done...
				break;
			}
		}
	}
 
	// Finish the progress
	finishProgress();
 
// Finalize the function and invoke
})();