UI/Edit.py

# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.

# Script description:
# Create a tool showing different FBEdit controls and possible customizations
#
# Topic: FBEdit, FBEditColor, FBEditNumber, FBEditVector, FBTimeCode
#

from pyfbsdk import *
from pyfbsdk_additions import *

editStyles = ["FBEdit","FBEditColor","FBEditNumber","FBEditVector","FBTimeCode"]
edits = {}

# Normal Edit
def OnChange(control,event):
    print control.Text

def PopulateLayout(mainLyt):
    anchor = ""
    attachType = FBAttachType.kFBAttachTop

    # Generically create different types of edit
    for style in editStyles:
        # Create label
        labId = "Label" + style
        l = FBLabel()
        l.Caption = style
        x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
        y = FBAddRegionParam(10,attachType,anchor)
        w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
        h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
        
        mainLyt.AddRegion(labId,labId, x, y, w, h)
        mainLyt.SetControl(labId,l)
            
        # Create edit
        editId = "Edit" + style
        initCall = "%s()" % (style)
        e = eval( initCall )
        edits[style] = e
        
        x = FBAddRegionParam(10,FBAttachType.kFBAttachRight,labId)
        y = FBAddRegionParam(10,attachType,anchor)
        w = FBAddRegionParam(200,FBAttachType.kFBAttachNone,"")
        h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
    
        mainLyt.AddRegion(editId,editId, x, y, w, h)
    
        mainLyt.SetControl(editId,e)
      
        attachType = FBAttachType.kFBAttachBottom
        anchor = labId
        
    # Do specific edit initialization according to its type

    e = edits['FBEdit']
    e.Text = "initial text"
    #e.PasswordMode = True
    e.OnChange.Add(OnChange)
    
    
    # Color Edit
    e = edits['FBEditColor']
    e.Value = FBColor(1.0, 0.0,0.0)
    # e.ColorMode = 2
    # e.ColorMode = 3
    
    # Number edit
    e = edits['FBEditNumber']
    e.Max = 100
    e.Min = 34
    e.Value = 62
    
    # Vector Edit
    e = edits['FBEditVector']
    e.Value = FBVector3d(42.0, 23.0,666.666)
    
    e = edits['FBTimeCode']
    e.Value = FBTime(11,22,33,11)

def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = FBCreateUniqueTool("Edit Example")
    PopulateLayout(t)
    ShowTool(t)
    
CreateTool()