# 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 a tabpanel that automatically manages all clicking on tabs to display the relevant content.
#
# Topic: FBTabPanel, FBBorderStyle, TabControl
#

from pyfbsdk import *
from pyfbsdk_additions import *


def PopulateLayout(mainLyt):
    tab = TabControl()

    # insert tab control
    x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(-10,FBAttachType.kFBAttachRight,"")
    h = FBAddRegionParam(-10,FBAttachType.kFBAttachBottom,"")

    mainLyt.AddRegion("tab", "tab",x,y,w,h)
    mainLyt.SetControl("tab", tab)


    # Create dummy layout that will be "tabbable"
    for i in range(3):
        name = "%s %d" % ("Tab ", i + 1)

        l = FBLayout()

        x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
        y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
        w = FBAddRegionParam(-10,FBAttachType.kFBAttachRight,"")
        h = FBAddRegionParam(-10,FBAttachType.kFBAttachBottom,"")
        l.AddRegion(name,name, x, y, w, h)
        # each layout will have a visible border
        l.SetBorder(name,FBBorderStyle.kFBStandardBorder,True, True,1,0,90,0)

        tab.Add(name,l)


    tab.SetContent(0)
    tab.TabPanel.TabStyle = 0 # normal tabs
    #tab.TabPanel.TabStyle = 1 # tabs are activated with buttons

def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = CreateUniqueTool("TabPanel Example")
    t.StartSizeX = 400
    t.StartSizeY = 400
    PopulateLayout(t)
    ShowTool(t)

CreateTool()