UI/GridLayout.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 how to use a FBGridLayout to dynamically place controls on screen.
#
# Topic: FBGridLayout
#

from pyfbsdk import *
from pyfbsdk_additions import *

def PopulateLayout(mainLyt):
    # Create Main region frame:
    x = FBAddRegionParam(5,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(5,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(-5,FBAttachType.kFBAttachRight,"")
    h = FBAddRegionParam(-5,FBAttachType.kFBAttachBottom,"")
    mainLyt.AddRegion("main","main", x, y, w, h)

    grid = FBGridLayout()

    grid.SetRowRatio(0, 3.0)

    # Add buttons in the first row
    for i in range(7):
        b = FBButton()
        b.Caption = "0," + str(i)
        grid.Add(b,0,i)
        
    # add buttons in the first column
    for i in range(7):
        b = FBButton()
        b.Caption = str(i) + ",0"
        grid.Add(b,i,0)
    
    b = FBButton()
    b.Caption = "0,1"
    grid.Add(b,0,1)    
        
    b = FBButton()
    b.Caption = "1,3"
    # specify button width: this will make the rows and columns grow to accomodate this big button
    grid.Add(b,1,3, width = 200)
        
    # set the height of the row 2
    grid.SetRowHeight(2, 50)
    
    b = FBButton()
    b.Caption = "2,2"
    # specify the width and height of a button
    grid.Add(b,2,2,width = 45, height = 25)
    
    # set the spacing between col3 and col4
    grid.SetColSpacing(3, 50)
    
    b = FBButton()
    b.Caption = "2,3"
    # specify that the button will be "right justified" in the column (attachX relates to horizontal position)
    grid.Add(b,2,3,attachX = FBAttachType.kFBAttachRight, width = 25, height = 20, attachY = FBAttachType.kFBAttachBottom)

    b = FBButton()
    b.Caption = "3,1"
    # specify the height of the button
    grid.Add(b,3,1, height = 200)


    b = FBButton()
    b.Caption = "3,2"
    # specify that the button will be attach to the bottom of the row (attachY relates to vertical position)
    grid.Add(b,3,2,attachY = FBAttachType.kFBAttachBottom, height = 25)
    
    b = FBButton()
    b.Caption = "3,6,3,6"
    # this button will span from row 3 to row 6 and from col 3 to col 6.
    grid.AddRange(b,3,6, 3, 6)

    mainLyt.SetControl("main",grid)

def CreateTool():    
    # Tool creation will serve as the hub for all other controls
    t = FBCreateUniqueTool("Grid Example")
    PopulateLayout(t)
    # Button creation
    t.StartSizeX = 800
    t.StartSizeY = 800
    ShowTool(t)
   
 
CreateTool()