/**********************************************************************
This script is provided as part of the Daz Script Documentation. The
contents of this script, and\or any portion thereof, may only be used
in accordance with the following license:
Creative Commons Attribution 3.0 Unported (CC BY 3.0)
- http://creativecommons.org/licenses/by/3.0
To contact Daz 3D or for more information about Daz Script visit the
Daz 3D website:
- http://www.daz3d.com
**********************************************************************/
// Source: /public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/simple_text_browser_dialog/start
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sSearchPath, sFileName ){
/*********************************************************************/
// 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;
};
/*********************************************************************/
// void : A function for updating the dialog caption;
// 'this' is assumed to be a DzBasicDialog
function updateDialogCaption( sCaption )
{
// Find a child widget by name
var wBrowser = this.findChildOfWidget( "ContentsTBrwsr" );
// If a widget was found and its the type we want
if( wBrowser && wBrowser.inherits( "QTextBrowser" ) ){
// Get the title of the document
var sTitle = wBrowser.documentTitle;
// If the title is not empty
if( !sTitle.isEmpty() ){
// Update the caption for the dialog
this.caption = sTitle;
// We're done...
return;
}
}
// Update the caption for the dialog
this.caption = sCaption;
};
/*********************************************************************/
// void : A function for updating the enabled state of a button;
// 'this' is assumed to be a DzPushButton
function updateButtonState( bYesNo )
{
// Update the enabled state of the button
this.enabled = bYesNo;
};
/*********************************************************************/
// void : A function for moving forward in a text browser's history;
// 'this' is assumed to be a DzTextBrowser
function nextClicked()
{
// Move forward in the history
this.forward();
};
/*********************************************************************/
// void : A function for moving backward in a text browser's history;
// 'this' is assumed to be a DzTextBrowser
function backClicked()
{
// Move backward in the history
this.backward();
};
/*********************************************************************/
// If the application version is earlier than 4.9.3.93
if( App.version64 < 0x000400090003005d ){
// Provide feedback
MessageBox.information(
text("This script requires %1 4.9.3.93 or newer to continue.")
.arg( App.appName ), text("Version Error"), text("&Ok") );
// We're done..
return;
}
// Get the current style
var oStyle = App.getStyle();
// Get the height for buttons
var nBtnHeight = oStyle.pixelMetric( "DZ_ButtonHeight" );
// Define the template for What's This text
var sWhatsThis = "%1
%2";
// 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 Text Browser";
// 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 text browser
var wBrowser = new DzTextBrowser( wDlg );
wBrowser.getWidget().objectName = "ContentsTBrwsr";
wBrowser.openExternalLinks = true;
wBrowser.whatsThis = sWhatsThis.arg( text("Page Contents") )
.arg( text("Displays the contents of a text file or HTML page.") );
wBrowser.sourceChanged.connect( wDlg, updateDialogCaption );
// Add the browser to the dialog
wDlg.addWidget( wBrowser );
// Create a forward button
var wNextBtn = new DzPushButton( wDlg );
wNextBtn.getWidget().objectName = "NextBtn";
wNextBtn.text = ">>";
wNextBtn.enabled = false;
wNextBtn.setFixedWidth( nBtnHeight * 2 );
wNextBtn.toolTip = text("Click here to go forward in the browser history.");
wNextBtn.whatsThis = sWhatsThis.arg( text("Go Forward") ).arg( wNextBtn.toolTip );
wBrowser.forwardAvailable.connect( wNextBtn, updateButtonState );
wNextBtn.clicked.connect( wBrowser, nextClicked );
// Add the button to the dialog
wDlg.addButton( wNextBtn );
// Create a back button
var wBackBtn = new DzPushButton( wDlg );
wBackBtn.getWidget().objectName = "BackBtn";
wBackBtn.text = "<<";
wBackBtn.enabled = false;
wBackBtn.setFixedWidth( nBtnHeight * 2 );
wBackBtn.toolTip = text("Click here to go back in the browser history.");
wBackBtn.whatsThis = sWhatsThis.arg( text("Go Back") ).arg( wBackBtn.toolTip );
wBrowser.backwardAvailable.connect( wBackBtn, updateButtonState );
wBackBtn.clicked.connect( wBrowser, backClicked );
// Add the button to the dialog
wDlg.addButton( wBackBtn );
// Set the browser source
wBrowser.searchPaths = [ sSearchPath ];
wBrowser.source = sFileName;
// Set the text on the accept button
wDlg.setAcceptButtonText( text("&Close") );
// Hide the cancel button
wDlg.showCancelButton( false );
// Display the dialog
wDlg.exec();
// Finalize the function and invoke
})( String("%1/DAZ Studio").arg( App.getDocumentationPath() ), "what_is_studio.htm" );