Description : |
Below is the source for a simple DAZ Script that tests various aspects of the widget types. |
Concepts Covered : |
|
Source : ./samples/ |
00001 /********************************************************************** 00002 File: widgetTest.ds 00003 00004 Copyright © 2002-2006 DAZ Productions. All Rights Reserved. 00005 00006 This file is part of the DAZ Script Documentation. 00007 00008 This file may be used only in accordance with the DAZ Script 00009 license provided with the DAZ Script Documentation. 00010 00011 The contents of this file may not be disclosed to third parties, 00012 copied or duplicated in any form, in whole or in part, without the 00013 prior written permission of DAZ Productions, except as explicitly 00014 allowed in the DAZ Script license. 00015 00016 See http://www.daz3d.com to contact DAZ Productions or for more 00017 information about DAZ Script. 00018 **********************************************************************/ 00019 const nMARGIN = 5; 00020 const nSPACING = 5; 00021 const nMIN_BTN_WIDTH = 80; 00022 const nMAX_BTN_HEIGHT = 20; 00023 00024 const clrBLACK = new Color( 0, 0, 0 ); 00025 const clrWHITE = new Color( 255, 255, 255 ); 00026 const clrRED = new Color( 255, 0, 0 ); 00027 const clrGREEN = new Color( 0, 255, 0 ); 00028 const clrBLUE = new Color( 0, 0, 255 ); 00029 00030 // Get the Help Manager for "What's This?" and tool tips 00031 var oHelpMgr = App.getHelpMgr(); 00032 00033 // find the "What's This?" action; for the help button 00034 var oActionMgr = MainWindow.getActionMgr(); 00035 var oHelpAction = oActionMgr ? oActionMgr.findAction( "DzWhatsThisAction" ) : undefined; 00036 00037 /***************************** 00038 Dialog 00039 *****************************/ 00040 var wDlg = new DzDialog; 00041 wDlg.caption = "DAZ Script Widget Test"; 00042 00043 // Main Layout 00044 var wDlgLyt = new DzVBoxLayout( wDlg ); 00045 wDlgLyt.autoAdd = true; 00046 wDlgLyt.margin = nMARGIN; 00047 wDlgLyt.spacing = nSPACING; 00048 00049 // Create a check box 00050 var wBtn = new DzCheckBox( wDlg ); 00051 wBtn.text = "DzCheckBox 0"; 00052 00053 // Create a combo box 00054 var wComboBox = new DzComboBox( wDlg ); 00055 wComboBox.insertItem( "DzComboBox Item 0" ); 00056 wComboBox.insertItem( "DzComboBox Item 1" ); 00057 wComboBox.insertItem( "DzComboBox Item 2" ); 00058 wComboBox.currentItem = 1; 00059 00060 // Create a date edit 00061 var wDateEdit = new DzDateEdit( wDlg ); 00062 wDateEdit.date = new Date; 00063 00064 // Create a time edit 00065 var wTimeEdit = new DzTimeEdit( wDlg ); 00066 wTimeEdit.date = new Date; 00067 00068 // Create a date time edit 00069 var wDateTimeEdit = new DzDateTimeEdit( wDlg ); 00070 wDateTimeEdit.date = wDateEdit.date; 00071 00072 // Create a group box 00073 var wHBox = new DzHGroupBox( wDlg ); 00074 00075 // Create a dial 00076 var wDial = new DzDial( wHBox ); 00077 wDial.minWidth = 100; 00078 wDial.minHeight = 100; 00079 wDial.min = 0; 00080 wDial.max = 255; 00081 wDial.notchesVisible = true; 00082 wDial.notchTarget = nSPACING; 00083 wDial.wrapping = false; 00084 00085 // Create a LCD number 00086 var wLCD = new DzLCDNumber( wHBox ); 00087 wLCD.value = wDial.value; 00088 wLCD.segmentStyle = wLCD.Flat; 00089 setLCDValue( wDial.value ); 00090 00091 function setLCDValue( nValue ){ 00092 wLCD.value = nValue; 00093 if( nValue < 85 ) 00094 wLCD.paletteForegroundColor = clrRED; 00095 else if( nValue < 170 ) 00096 wLCD.paletteForegroundColor = clrGREEN; 00097 else 00098 wLCD.paletteForegroundColor = clrBLUE; 00099 } 00100 connect( wDial, "valueChanged(int)", setLCDValue ); 00101 00102 // Create a color widget 00103 var wColor = new DzColorWgt( wDlg ); 00104 wColor.value = clrRED; 00105 00106 // Create a int slider 00107 var wSlider = new DzIntSlider( wDlg ); 00108 wSlider.min = 0; 00109 wSlider.max = 9; 00110 wSlider.clamped = true; 00111 wSlider.sensitivity = 1; 00112 wSlider.value = 2; 00113 wSlider.textEditable = true; 00114 wSlider.textVisible = true; 00115 00116 // Create a enum slider 00117 wSlider = new DzEnumSlider( wDlg ); 00118 wSlider.addItem( "Zero" ); 00119 wSlider.addItem( "One" ); 00120 wSlider.addItem( "Two" ); 00121 wSlider.addItem( "Three" ); 00122 wSlider.addItem( "Four" ); 00123 wSlider.addItem( "Five" ); 00124 wSlider.addItem( "Six" ); 00125 wSlider.addItem( "Seven" ); 00126 wSlider.addItem( "Eight" ); 00127 wSlider.addItem( "Nine" ); 00128 wSlider.value = 2; 00129 00130 // Create a float slider 00131 wSlider = new DzFloatSlider( wDlg ); 00132 wSlider.min = 0; 00133 wSlider.max = 9; 00134 wSlider.clamped = true; 00135 wSlider.sensitivity = 0.5; 00136 wSlider.value = 2; 00137 wSlider.textEditable = true; 00138 wSlider.textVisible = true; 00139 00140 // Create a button group 00141 var wBtnGrp = new DzVButtonGroup( wDlg ); 00142 wBtnGrp.title = "DzVButtonGroup"; 00143 wBtnGrp.columns = 2; 00144 wBtnGrp.title += String( " (columns = %1)" ).arg( wBtnGrp.columns ); 00145 wBtnGrp.checkable = true; 00146 00147 // Create some radio buttons 00148 wBtn = new DzRadioButton( wBtnGrp ); 00149 wBtn.text = "DzRadioButton 0"; 00150 wBtn = new DzRadioButton( wBtnGrp ); 00151 wBtn.text = "DzRadioButton 1"; 00152 wBtn = new DzRadioButton( wBtnGrp ); 00153 wBtn.text = "DzRadioButton 2"; 00154 wBtn = new DzRadioButton( wBtnGrp ); 00155 wBtn.text = "DzRadioButton 3"; 00156 wBtn = new DzRadioButton( wBtnGrp ); 00157 wBtn.text = "DzRadioButton 4"; 00158 wBtn = new DzRadioButton( wBtnGrp ); 00159 wBtn.text = "DzRadioButton 5"; 00160 00161 wBtnGrp.selected = 3; 00162 00163 // Create a label 00164 var wLbl = new DzLabel( wDlg ); 00165 wLbl.text = "This is a DzLabel."; 00166 00167 // Create a line edit 00168 var wLineEdit = new DzLineEdit( wDlg ); 00169 wLineEdit.text = "DzLineEdit Highlighted"; 00170 wLineEdit.setSelection( 11, wLineEdit.text.length - 1 ); 00171 00172 // Create a listbox 00173 var wListBox = new DzListBox( wDlg ); 00174 wListBox.insertItem( "DzListBox Item 0" ); 00175 wListBox.insertItem( "DzListBox Item 1" ); 00176 wListBox.insertItem( "DzListBox Item 2" ); 00177 wListBox.setSelected( 1, true ); 00178 00179 // Create a listview 00180 var wListView = new DzListView( wDlg ); 00181 wListView.rootIsDecorated = true; 00182 wListView.allColumnsShowFocus = true; 00183 wListView.addColumn( "Column 0" ); 00184 wListView.addColumn( "Column 1" ); 00185 var wListviewItem; 00186 for( var i = 0; i < 3; i++ ){ 00187 ListViewItem = new DzListViewItem( wListView ); 00188 ListViewItem.setText( 0, String( "DzListViewItem %1" ).arg( i ) ); 00189 var ListViewItemChild; 00190 for( var j = 0; j < 3; j++ ){ 00191 ListViewItemChild = new DzListViewItem( ListViewItem ); 00192 ListViewItemChild.setText( 0, String( "DzListViewItem %1 Child %2" ).arg( i ).arg( j ) ); 00193 } 00194 } 00195 00196 // Create a group box for the dialog buttons 00197 var wDlgBtnsGB = new DzGroupBox( wDlg ); 00198 wDlgBtnsGB.flat = true; 00199 00200 // Create a layout for the dialog buttons 00201 var wDlgBtnsLyt = new DzGridLayout( wDlgBtnsGB ); 00202 wDlgBtnsLyt.margin = nMARGIN; 00203 wDlgBtnsLyt.spacing = nSPACING; 00204 00205 // Create the interactive help ("What's This?") push button 00206 var wHelpBtn = new DzPushButton( wDlgBtnsGB ); 00207 wHelpBtn.pixmap = new Pixmap( String( "%1/images/icons/whatsthissmallicon.png" ).arg( App.getResourcesPath() ) ); 00208 wHelpBtn.maxHeight = nMAX_BTN_HEIGHT; 00209 if( oHelpAction ) 00210 connect( wHelpBtn, "clicked()", oHelpAction, "activate()" ); 00211 wHelpBtn.toolTip = oHelpMgr.getToolTip( "WhatsThis" ); 00212 wHelpBtn.whatsThis = oHelpMgr.getHelpString( "WhatsThis" ); 00213 wDlgBtnsLyt.addWidget( wHelpBtn, 0, 0 ); 00214 00215 // Stretch the column between the left and right sides 00216 wDlgBtnsLyt.setColStretch( 1, 1 ); 00217 00218 // Create the accept push button 00219 var wAcceptBtn = new DzPushButton( wDlgBtnsGB ); 00220 wAcceptBtn.text = "&Accept"; 00221 wAcceptBtn.minWidth = nMIN_BTN_WIDTH; 00222 wAcceptBtn.maxHeight = nMAX_BTN_HEIGHT; 00223 wDlg.setAcceptButton( wAcceptBtn ); 00224 wAcceptBtn.toolTip = oHelpMgr.getToolTip( "AcceptDialog" ); 00225 wAcceptBtn.whatsThis = oHelpMgr.getHelpString( "AcceptDialog" ); 00226 wDlgBtnsLyt.addWidget( wAcceptBtn, 0, 2 ); 00227 00228 // Create the cancel push button 00229 var wCancelBtn = new DzPushButton( wDlgBtnsGB ); 00230 wCancelBtn.text = "&Cancel"; 00231 wCancelBtn.minWidth = nMIN_BTN_WIDTH; 00232 wCancelBtn.maxHeight = nMAX_BTN_HEIGHT; 00233 wDlg.setRejectButton( wCancelBtn ); 00234 wCancelBtn.toolTip = oHelpMgr.getToolTip( "CancelDialog" ); 00235 wCancelBtn.whatsThis = oHelpMgr.getHelpString( "CancelDialog" ); 00236 wDlgBtnsLyt.addWidget( wCancelBtn, 0, 3 ); 00237 00238 // Polish 00239 wDlg.width = wDlg.minWidth > 400 ? wDlg.minWidth : 400; 00240 wDlg.height = wDlg.minHeight; 00241 00242 // Launch 00243 wDlg.exec(); |