PPGLayout.AddButton operator

導入

v4.0

詳細

ボタンをレイアウトに追加します。その他のコントロールと異なり、ボタンはインスペクト対象オブジェクトの特定のParameterに関連付ける必要はありません。ボタンの用途は基本的に、押したときに何らかのスクリプトコードが実行されるというものです。

デフォルトでは、ボタンの幅はラベルのテキストに応じて自動的に決定されます。ただし、siUICX属性を使用してデフォルトの設定を変更できます(PPGItem.SetAttributeを参照)。

スクリプト 構文

oReturn = PPGLayout.AddButton( ScriptName, [Label] );

戻り値

PPGItem

パラメータ

パラメータ タイプ 詳細
ScriptName String ボタンの名前。ユニークな名前でなければならないほか、名前にスペースは使用できません。この名前は、ボタンを押したときに呼び出すロジックサブルーチンの決定に使用されます。
Label String ボタンのラベル。指定されない場合には、スクリプト名が表示されます。

1. JScript の例

/*
        This example creates a custom property with a single parameter called "Data" and a button.
        Each time you click the button the value is randomized
*/
var oPSet = ActiveSceneRoot.AddProperty( "CustomProperty", false, "ButtonExample" ) ;
oPSet.AddParameter3( "Data", siDouble, 0, 0, 1 ) ;
var oLayout = oPSet.PPGLayout
oLayout.AddRow() ;
oLayout.AddItem( "Data" ) ;
oLayout.AddButton( "Randomize" ) ;
oLayout.EndRow() ;
oLayout.Logic = Randomize_OnClicked.toString() ;
oLayout.Language = "JScript" ;
InspectObj( oPSet ) ;
function Randomize_OnClicked()
{
        PPG.Data.Value = Math.random() ;
}

2. VBScript の例

'
' This example creates a custom property with a single parameter called "Data" and a button.
' Each time you click the button the value is randomized
'
set oPSet = ActiveSceneRoot.AddProperty( "CustomProperty", false, "ButtonExample" )
oPSet.AddParameter3 "Data", siDouble, 0, 0, 1
set oLayout = oPSet.PPGLayout
oLayout.AddRow
oLayout.AddItem "Data"
oLayout.AddButton "Randomize"
oLayout.EndRow
'Store a little VBScript code to react to the button press.
'If this code was more sophisticated we could read it out
'of a file
oLayout.Logic = "sub Randomize_OnClicked"   & vbCrlf & "   PPG.Data.Value = Rnd" & vbCrlf & "end sub"
oLayout.Language = "VBScript" 'Optional because this is the default
InspectObj oPSet

3. JScript の例

/*
        Example showing how to disable a button
        Often certain buttons should be disabled if they don't apply in the current context.
        In this case a button is only enabled if there is text entered in a edit box.  The 
        button gets enabled and disabled by the SomeText_OnChanged() callback.  This callback
        is not called as characters are actually entered in the text box, but as soon as that 
        edit box loses focus (for example if the tab key is pressed )
*/
var oPSet = ActiveSceneRoot.AddProperty( "CustomProperty", false, "ButtonExample" ) ;
oPSet.AddParameter3( "SomeText", siString ) ;
var oLayout = oPSet.PPGLayout
oLayout.AddRow() ;
oLayout.AddItem( "SomeText" ) ;
var oItem = oLayout.AddButton( "ClickMe", "Click Me" ) ;
// Set a PPGItem attribute to disable the control
// (because initially there is no text inside SomeText)
oItem.SetAttribute( "buttondisable", true ) ;
oLayout.EndRow() ;
oLayout.Logic = SomeText_OnChanged.toString() + ClickMe_OnClicked.toString() ;
oLayout.Language = "JScript" ;
InspectObj( oPSet ) ;
// PPG Logic that is provided to the PPG
function SomeText_OnChanged()
{
        // Button will be disabled until some text is entered
        bDisableButton = ( PPG.SomeText.Value.length == 0 ) ;   
        // Get the layout
        oPPGLayout = PPG.PPGLayout ;
        // Lookup the PPGItem associated with the button
        oPPGItem = oPPGLayout.Item( "ClickMe" ) ;                       
        bAlreadyDisabled = oPPGItem.GetAttribute( "buttondisable" ) ;
        if ( bDisableButton != bAlreadyDisabled )
        {       
                oPPGItem.SetAttribute( "buttondisable", bDisableButton ) ;      
                // We only call refresh if we determine the state has
                // actually changed             
                PPG.Refresh() ;
        }
}
function ClickMe_OnClicked()
{
        // Will never be called if the SomeText is empty
        XSIUIToolkit.MsgBox( "Value of text is " +  PPG.SomeText.Value ) ;
}

関連項目

PPGLayout.AddItem PPGItem.Label PPGItem.Name PPG PPGLayout.Logic