How can I display images in a dialog box?

iwaveiwave Posts: 46
edited December 1969 in Daz Script Developer Discussion

Hello everyone.
I'm new to daz script.

I have spent a few days searching on the forum, reading the docs and examples.
The only useful class I found is DzListViewItem,which can be used to display pixmap in dialog box.
If this class is just what I need, then how should I convert an image to a pixmap?
Thanks.

Comments

  • rbtwhizrbtwhiz Posts: 2,470
    edited October 2015

    An image can be loaded into a Pixmap by passing the path of the image you want to display to the constructor [or to the Pixmap::load() method after the object has been constructed]. A DzLabel can have a Pixmap set on it, and display that instead of text.

    See the Simple Image Dialog sample.

    -Rob

    Post edited by rbtwhiz on
  • iwaveiwave Posts: 46
    edited December 1969

    It works great!
    Thank you so much for your clear and standardized coding!

  • Eustace ScrubbEustace Scrubb Posts: 2,719
    edited December 1969

    I may have to remember this one.

  • V3DigitimesV3Digitimes Posts: 3,365
    edited October 2015

    Well it works great!

    Yet I have a small issue.  While playing with this to go and look for an image in any mapped content folder (which works now), I managed, god knows how, to "break" the dimensions of my "Content Directory Manager" pop up window...

    Now the size of the Content  Directory Manager window is vertically bigger than my screen, and I can't resize it - well I can resize it only horizontally, which is not the dimension presenting an issue. 

    It may be due to everything I tested in term of interface screen, maybe to the "sKey" part which I have hidden for a while (I did not know why it was important).

    I'd like to repair this, but I don't know where to look for. In windows registry? In the " App data / roaming" of the application?

    Thanks for any tip about this !

     

    EDIT : FORGET ABOUT THAT, I leave it here for information, I managed to solve this in the windows registry, SOFTWARE/DAZ/Studio 4/content directory manager/ : change h value.. Well..  It is solved now!

    Post edited by V3Digitimes on
  • TotteTotte Posts: 14,676
    edited July 2016

    I wrote this little method for this, to load an image and get it back as a widget to place into the Dialog.

    // ==========================================

    // getDialogImage method

    // ==========================================

    BWCRollUp.prototype.getDialogImage = function(imagename) {

    var wLabel = new DzLabel( this.wDialog );

    var sScriptPath = g_oFILE.path();

    var sResourcePath = sScriptPath + "/REMResources/";

    var sImagePath = sResourcePath + imagename;

    var pixImage = new Pixmap(sImagePath);

    wLabel.pixmap = pixImage;

    return wLabel;

    }


    Post edited by Totte on
  • As an extention to this question, is there any chance someone knows whether it's possible to display images (or even change the color) for backgrounds of dialogs / group boxes?  

    So far all of my attempts have failed, and I was wondering if this could be due to Daz's UI theme overriding script behavior that tries to set this.

  • YudinEdYudinEd Posts: 90
    edited March 2017

     

     someone knows whether it's possible to display images (or even change the color) for backgrounds of dialogs 

    var Dlg = new DzDialog;var pixImage = new Pixmap("c:/img.jpg");Dlg.paletteBackgroundPixmap = pixImage;	Dlg.exec()

     

    var Dlg = new DzDialog;Dlg.paletteBackgroundColor = new Color( 66,99,99 );//or can use for colors - new Color("dark red")Dlg.exec()

     

    Post edited by YudinEd on
  • YudinEdYudinEd Posts: 90
    edited April 2017

    I add :)

    You can scale image content. Create label with dialog size as background and place here one image.  In next example I scale image content on label MyLabel. 

    MyLabel.scaledContents=pixImage

     

    Post edited by YudinEd on
  • Can someone please help me? I am trying to create a basic dialog that displays a static image when the user clicks the encrypted dse in my new DAZ product directory. I am obviously not adjusting the script correctly because it is not working. I can see the dialog and even title it OK. But my associated image refuses to show up. 

    Is there is video or specific workflow for making this happen for daz creators? I am an artist, not a programmer. But I really need to get this working so i can deliver my new product as professionally as possible. 

    Here is my script. What the heck am I missing here? 

    /********************************************************************** 	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: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/simple_image_dialog/start// 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;	};		/*********************************************************************/	// 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 = "HoneyClub - Daz Product Notes";		// 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 pixmap for the image	var pixImage = new Pixmap( sFileName );		// Create a label and assign a pixmap	var wLabel = new DzLabel( wDlg );	wLabel.pixmap = pixImage;	wLabel.toolTip = sFileName;	wLabel.whatsThis = sWhatsThis.arg( text( "Image Path" ) ).arg( wLabel.toolTip );		// Add the label to the dialog	wDlg.addWidget( wLabel, 0, DzWidget.AlignCenter );		// Get the minimum size of the dialog	var sizeHint = oDlgWgt.minimumSizeHint;		// Set the fixed size of the dialog	wDlg.setFixedSize( sizeHint.width, sizeHint.height );		// 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("product-notes.png").arg( App.getResourcesPath()) );

     

    Please help.

     

  • Update: I still cannot see my original post. It is being "approved", as I figure(hope) this one will be also.

    In any case, I can get both my image dialog scripts to work flawlessly IF I use absolute path syntax. Obviously, not everyone will use the default Daz My Library path. That means I really need the correct syntax for getting Daz to locate my image using relative path, instead. 

    This way works: 

    // Finalize the function and invoke
    })( String("C:/Users/Public/Documents/DAZ 3D/My Library/People/Genesis 8 Female/Characters/Vendor/Character for Genesis 8.1/product-notes-gen8.1.png").arg( App.getResourcesPath()) );

    How can i get this to work using a relative path from say the "People" directory

    // Finalize the function and invoke
    })( String("../People/Genesis 8 Female/Characters/Vendor/Character for Genesis 8.1/product-notes-gen8.1.png").arg( App.getResourcesPath()) );  

    Adding the ../ does NOT work for me. 

    In adding a %1, Daz considers the relative path is from its "resources" directory in Program Files. 

    // Finalize the function and invoke
    })( String("%1product-notes-gen8.1.png").arg( App.getResourcesPath()) );  

    Adding the %1 equals  C:/Program Files/DAZ 3D/DAZStudio4/resources/product-notes-gen8.1.png

    What is the correct syntax for the relative path "People"? 

    Thanks!

  • Richard HaseltineRichard Haseltine Posts: 107,857

    Is the file in the folder specified by the getResourcePath() method? Don't forget that this will proabably not work with a product installed through Connect

  • Richard HaseltineRichard Haseltine Posts: 107,857

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/file_find/start shows how to get an absolute path from a relative path, ncorporating that in the dialogue script would let you have a portable way to show the image.

  • Richard Haseltine said:

    Is the file in the folder specified by the getResourcePath() method? Don't forget that this will proabably not work with a product installed through Connect

    No, sir. This product is intended to be installed manually. As I said, I am not a programmer. I was hoping there was a sample script that would allow small changes in specific values to allow me to use for my own product read me popup. 

    I would like to have the dse and png file in the same directory, and the dse just find the file and display it. 

    How can I change the basic image dialog script FOUND HERE to allow such a simple configuration? 

    Thank you for your help!

  • Richard HaseltineRichard Haseltine Posts: 107,857

    It is potentially risky but you can also use http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/script_dz#a_1aa338a2077f9a344468248ed644fe31d6 to get the path to the script,  assuming it is being run from a file, then chop off the script's name to leave just the path and apend the image name for the dialogue script.

  • OmnifluxOmniflux Posts: 427
    edited June 12

    I have mashed these two sample scripts together for you

     

    /**********************************************************************
    
    	This script is adapted from parts 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: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/simple_image_dialog/start
    // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/display_document_dynamic/start
    
    // Define an anonymous function;
    // serves as our main loop,
    // limits the scope of variables
    (function( sTitle, sRelativePath ){
    
    	/*********************************************************************/
    	// 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;
    	};
    
    	/*********************************************************************/
    
    	// Get the content manager
    	var oContentMgr = App.getContentMgr();
    	// If we do not have a content manager
    	if( !oContentMgr ){
    		// We are done...
    		return;
    	}
    
    	// Declareworking variables
    	var sPreferredBasePath, sAbsolutePath;
    
    	// Get the path of this script
    	var sScriptPath = getScriptFileName();
    
    	// If the version is 4.8.1.51 or newer
    	if( App.version64 >= 0x0004000800010033 ){
    		// Define the directory type to look in
    		var nDirType = DzContentMgr.AllDirs;
    
    		// If the version is 4.9.0.51 or newer
    		if( App.version64 >= 0x0004000900000033 ){
    			// Also look in cloud directories
    			nDirType = DzContentMgr.AllDirsAndCloud;
    		}
    
    		//Define the preferred [mapped] base path; use the path of the current script
    		sPreferredBasePath = oContentMgr.getMappedPath( nDirType, sScriptPath, false );
    
    		// Get the absolute path of the file to be shown/opened
    		sAbsolutePath = oContentMgr.getAbsolutePath( nDirType, sRelativePath, sPreferredBasePath );
    	// If the version is older than 4.8.1.51
    	} else {
    		// Define the preferred [mapped] base path; use the path of the current script
    		sPreferredBasePath = oContentMgr.getMappedPath( sScriptPath, true, false );
     
    		// Get the absolute path of the file to be shown/opened
    		sAbsolutePath = oContentMgr.getAbsolutePath( sRelativePath, true, sPreferredBasePath );
    	}
    
    	// If the file was found
    	if( !sAbsolutePath.isEmpty() ){
    		// 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 = sTitle;
    		
    		// 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 pixmap for the image
    		var pixImage = new Pixmap( sAbsolutePath );
    		
    		// Create a label and assign a pixmap
    		var wLabel = new DzLabel( wDlg );
    		wLabel.pixmap = pixImage;
    		wLabel.toolTip = sAbsolutePath;
    		wLabel.whatsThis = sWhatsThis.arg( text( "Image Path" ) ).arg( wLabel.toolTip );
    		
    		// Add the label to the dialog
    		wDlg.addWidget( wLabel, 0, DzWidget.AlignCenter );
    		
    		// Get the minimum size of the dialog
    		var sizeHint = oDlgWgt.minimumSizeHint;
    		
    		// Set the fixed size of the dialog
    		wDlg.setFixedSize( sizeHint.width, sizeHint.height );
    		
    		// Set the text on the accept button
    		wDlg.setAcceptButtonText( text( "&Close" ) );
    		// Hide the cancel button
    		wDlg.showCancelButton( false );
    		
    		// Display the dialog
    		wDlg.exec();
    
    	// If the file was not found
    	} else {
    		// Inform the user
    		MessageBox.information(
    			text( "'%1' could not be found in a mapped content directory. " +
    				"Check the installation and try again.").arg( sRelativePath ),
    			text( "File Not Found" ), text( "&OK" ) );
    	}
    
    // Finalize the function and invoke
    })("HoneyClub - Daz Product Notes", "data/Vendor/Product/product-notes.png");

    Edited to note I did not see your most recent post about relative to the script, which Richard has supplied the answer for. This example is for a path relative to the content directory, as you requested initally.

    Post edited by Omniflux on
  • My goodness! Thank you for your gracious replies! :) 

Sign In or Register to comment.