# 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 FBTree and modify its properties
#
# Topic: FBTree
#

from pyfbsdk import *
from pyfbsdk_additions import *

# Callback
def TreeSelectCallback(control, event):
    print "Node : ",event.TreeNode.Name, " selected."

def PopulateLayout(mainLyt):
    x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
    h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
    mainLyt.AddRegion("main","main", x, y, w, h)


    t = FBTree()
    t.CheckBoxes = True
    t.AutoExpandOnDblClick = True
    t.AutoExpandOnDragOver = True
    t.AutoScroll = True
    t.AutoScrollOnExpand = True
    t.ItemHeight = 40
    t.DeselectOnCollapse = True
    t.EditNodeOn2Select = True
    t.HighlightOnRightClick = True
    t.MultiDrag = True
    t.MultiSelect = True
    t.NoSelectOnDrag = True
    t.NoSelectOnRightClick = False
    t.ShowLines = True

    mainLyt.SetControl("main",t)

    r = t.GetRoot()
    n = t.InsertLast(r, "1")
    n = t.InsertLast(n, "2")
    n = t.InsertLast(n, "3")
    n = t.InsertLast(n, "4")
    n = t.InsertLast(r, "5")
    n = t.InsertLast(n, "6")
    t.InsertLast(n, "7")

    t.OnSelect.Add(TreeSelectCallback)

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

CreateTool()