User Tools

Site Tools


Background Progress

Summary

Below is an example demonstrating how you can cause the background_progress indicator to be displayed in the Status Bar and report progress via script.

API Areas of Interest

Example

Background_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
	startBackgroundProgress( text( "This is a simple background progress test." ), nCycles/nFrequency, bCancellable );
 
	// 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
			stepBackgroundProgress( 1 );
 
			// Force any pending events to be processed
			// i.e. updating the status bar progress indicator
			processEvents();
		}
 
		// If the user is allowed to cancel
		if( bCancellable ){
			// Process events so that we can check user interaction
			processEvents();
 
			// If the user cancelled
			if( App.isKeySequenceDown( "Esc" ) ){
				// Post a status update
				App.statusLine( text( "User cancelled simple background progress test." ) );
				// We are done...
				break;
			}
		}
	}
 
	// Finish the progress
	finishBackgroundProgress();
 
// Finalize the function and invoke
})();