User Tools

Site Tools


Simple Input Dialog

Summary

Below is an example demonstrating how to construct a simple input dialog, name it so that its size and position are stored uniquely from other script constructed dialogs, and size it according the current style applied to the user interface. This example also demonstrates how to retrieve the value input by the user and react according to whether the user accepts or cancels.

API Areas of Interest

Example

Simple_Dialog.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// Get the current style
	var oStyle = App.getStyle();
 
	// Get the height for buttons
	var nBtnHeight = oStyle.pixelMetric( "DZ_ButtonHeight" );
 
	// Create a basic dialog
	var wDlg = new DzBasicDialog();
 
	// Get the wrapped widget for the dialog
	var oDlgWgt = wDlg.getWidget();
 
	// Set the title of the dialog
	wDlg.caption = "My Simple Test";
 
	// Strip the space for a settings key
	var sKey = wDlg.caption.replace( / /g, "" ) + "Dlg";
 
	// Set an [unique] object name on the wrapped dialog widget;
	// this is used for recording position and size separately
	// from all other [uniquely named] DzBasicDialog instances
	oDlgWgt.objectName = sKey;
 
	// Create a color widget
	var wColorWgt = new DzColorWgt( wDlg );
	wColorWgt.setFixedHeight( nBtnHeight );
 
	// Add the widget to the dialog
	wDlg.addWidget( wColorWgt );
 
	// Get the minimum size of the dialog
	var sizeHint = oDlgWgt.minimumSizeHint;
 
	// Set the fixed size of the dialog
	wDlg.setFixedSize( sizeHint.width, sizeHint.height );
 
	// If the user accepts the dialog
	if( wDlg.exec() ){
		// Get the color from the widget
		var clrAccepted = wColorWgt.value;
		// Do... something
		print( "R:", clrAccepted.red, "G:", clrAccepted.green, "B:", clrAccepted.blue );
	// If the user rejects the dialog
	} else {
		// Do... something else
		print( "User cancelled." );
	}
 
// Finalize the function and invoke
})();