UI/Layout.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 with an empty layout (with border) and shows how to register clalback (idle, input, paint, resize, show)
# 
# Topic: FBLayout
# 

from pyfbsdk import *
from pyfbsdk_additions import *

def OnInputCb(control,event):
    print "OnInput ", control, event.Key, event.X, event.Y

def OnResizeCb(control,event):
    print "OnResize ", control, event.Width, event.Height

def OnShowCb(control,event):
    print "OnShow ", control, event.Shown
    
def OnPaintCb(control,event):
    print "OnPaint ", control, event

def OnIdleCb(control,event):
    print "OnIdle ", control, event
    
def PopulateLayout(mainLyt):
    lyt = FBLayout()
    x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(400,FBAttachType.kFBAttachNone,"")
    h = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
    lyt.AddRegion("Border1","Border2", x, y, w, h)
    lyt.SetBorder("Border1",FBBorderStyle.kFBStandardBorder,True, True,1,0,90,0)
    
    lyt.OnInput.Add(OnInputCb)
    lyt.OnResize.Add(OnResizeCb)
    lyt.OnShow.Add(OnShowCb)
    # This is commented out because these callbacks run all the time
    # lyt.OnPaint.Add(OnPaintCb)
    # lyt.OnIdle.Add(OnIdleCb)    
    
    x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(-10,FBAttachType.kFBAttachRight,"")
    h = FBAddRegionParam(-10,FBAttachType.kFBAttachBottom,"")
    mainLyt.AddRegion("Reg","Reg", x, y, w, h)
    mainLyt.SetControl("Reg",lyt)

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

    PopulateLayout(t)    
    ShowTool(t)

CreateTool()