User Tools

Site Tools


Wait For Background Progress

Summary

Below are examples demonstrating how you can cause a script to wait for the background_progress indicator to finish before continuing.

API Areas of Interest

Example (Test)

Wait_Background_Progress_Test.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// Initialize 'static' variables that hold modifier key state
	var s_bShiftPressed = false;
	var s_bControlPressed = false;
	var s_bAltPressed = false;
	var s_bMetaPressed = false;
 
	// If the "Action" global transient is defined, and its the correct type
	if( typeof( Action ) != "undefined" && Action.inherits( "DzScriptAction" ) ){
		// If the current key sequence for the action is not pressed
		if( !App.isKeySequenceDown( Action.shortcut ) ){
			updateModifierKeyState();
		}
	// If the "Action" global transient is not defined
	} else if( typeof( Action ) == "undefined" ) {
		updateModifierKeyState();
	}
 
	/*********************************************************************/
	// String : A function for updating the keyboard modifier state
	function updateModifierKeyState()
	{
		// Get the current modifier key state
		var nModifierState = App.modifierKeyState();
		// Update variables that hold modifier key state
		s_bShiftPressed = (nModifierState & 0x02000000) != 0;
		s_bControlPressed = (nModifierState & 0x04000000) != 0;
		s_bAltPressed = (nModifierState & 0x08000000) != 0;
		s_bMetaPressed = (nModifierState & 0x10000000) != 0;
	};
 
	/*********************************************************************/
	// String : A function for printing only if debugging
	function debug()
	{
		// If we are not debugging
		if( !s_bAltPressed ){
			// We are done...
			return;
		}
 
		// Convert the arguments object into an array
		var aArguments = [].slice.call( arguments );
 
		// Print the array
		print( aArguments.join(" ") );
	};
 
	/*********************************************************************/
	// 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;
	};
 
	/*********************************************************************/
	// Define whether or not we are debugging
	var bDebug = s_bAltPressed;
 
	// Define the total number of steps
	var nSteps = 1000;
 
	// If we are debugging
	if( bDebug ){
		// Start a background progress
		startBackgroundProgress( "Background", nSteps, false );
	}
 
	// Initialize working variables
	var bWasBusy = false;
	var nCount = 0;
 
	// While something is happening in the background
	while( backgroundProgressIsActive() ) {
		// If we are debugging and we haven't captured that
		// the background is busy
		if( bDebug && !bWasBusy ){
			// Report that we've started to wait
			debug( "Started Waiting:", (new Date).toTimeString() );
			// Capture that the background was busy
			bWasBusy = true;
		}
 
		// Allow the application to continue working
		processEvents();
 
		// If we are debugging
		if( bDebug ){
			// Increment our count
			nCount += 1;
 
			// Update the background progress to reflect our count
			updateBackgroundProgress( nCount );
 
			// If our count hasn't meet our total steps
			if( nCount < nSteps ){
				// Next!!
				continue;			
			}
 
			// Finish the background progress
			finishBackgroundProgress();
 
			// If we encountered being busy
			if( bWasBusy ){
				// Report that we've finished waiting
				debug( "Finished Waiting:", (new Date).toTimeString() );
			}
		}
	}
 
// Finalize the function and invoke
})();

Example (Simple)

Wait_Background_Progress.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// While something is happening in the background
	while( backgroundProgressIsActive() ) {
		// Allow the application to continue working
		processEvents();
	}
 
// Finalize the function and invoke
})();