load HTML file in a script

mikey186mikey186 Posts: 84

I was looking in the example file for "Simple Text Browser Dialog", and I noticed at the end of the script, it's loading a HTML file from inside the DAZ Studio application folder. What if I want to open up a HTML within a script file. For instance, I have a DAZ script file and a simple HTML file in the same folder within my Library. 

at the very end, I found this script section where it's loading the file.

( String("%1/DAZ Studio").arg( App.getDocumentationPath() ), "what_is_studio.htm" );

What I am trying to do is to load the HTML file from the same folder where my DSA script file is. I tried this code to no avail.

( String("/Scripts").arg( App.getAbsoluteScriptPath() ), "MY_HTML_FILE.html" );

Any idea of a way to point the script to load the HTML file within my script folder?

Post edited by mikey186 on

Comments

  • mikey186mikey186 Posts: 84
    edited December 2020

    Richard Haseltine said:

    Have you looked at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/display_document_dynamic/start ?

    I did, but I wanted it to open in a typical browser in DAZ, not in a other browser. 

    I tried using this code and ended up a parse error

    // DAZ Studio version 4.12.1.118 filetype DAZ Script// 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 = "<b>%1</b><br/><br/>%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();		//TEST	var g_oFILE = new DzGZFile( getScriptFileName() );var g_sSCRIPT_NAME = String( "%1.%2" ).arg( g_oFILE.baseName() ).arg( g_oFILE.extension() );var g_sSCRIPT_LOCATION = g_oFILE.path(); // Finalize the function and invoke})App.showURL( String("%1/tes2t.htm").arg( g_sSCRIPT_LOCATION ) );

     

    Post edited by mikey186 on
  • OmnifluxOmniflux Posts: 377
    edited December 2020

    You have an error on the last line. It should be

    })(App.showURL( String("%1/tes2t.htm").arg( g_sSCRIPT_LOCATION ) ));

    to resolve the error, but that still won't do what you want.

    You don't want to call App.showURL here, and g_sSCRIPT_LOCATION is not accessable here either.

    Post edited by Omniflux on
  • OmnifluxOmniflux Posts: 377

    Here is a quick rework

    // DAZ Studio version 4.12.1.118 filetype DAZ Script// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function( 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 &amp;&amp; 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 &lt; 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("&amp;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 = "&gt;&gt;";	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 = "&lt;&lt;";	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 );  	// TEST	var g_oFILE = new DzFileInfo( getScriptFileName() );	var g_sSCRIPT_LOCATION = g_oFILE.path();	g_oFILE.deleteLater(); 	// Set the browser source	wBrowser.searchPaths = [ g_sSCRIPT_LOCATION ];	wBrowser.source = sFileName;  	// Set the text on the accept button	wDlg.setAcceptButtonText( text("&amp;Close") );	// Hide the cancel button	wDlg.showCancelButton( false ); 	// Display the dialog	wDlg.exec();	// Finalize the function and invoke})("tes2t.htm");

     

Sign In or Register to comment.