# 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 2 different kinds of list and shows how to register callbacks.
# 
# Topic: VBoxLayout, FBListStyle, FBList
#

from pyfbsdk import *
from pyfbsdk_additions import *

def ListCallback(control, event):
    print control.Items[control.ItemIndex], "has been selected!"


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

    lyt = VBoxLayout()
    mainLyt.SetControl("main",lyt)


    # List creation
    global controls
    controls = [FBList(), FBList()]
    for l in controls:
        l.OnChange.Add(ListCallback)
        # fill the list with dummy data
        for i in range(10):
            name = "list element %d" % (i + 1)
            l.Items.append(name)


    #FBListStyle.kFBDropDownList
    #FBListStyle.kFBVerticalList
    controls[0].Style = FBListStyle.kFBDropDownList
    lyt.Add(controls[0], 25)
    controls[0].Selected(4, True)

    controls[1].Style = FBListStyle.kFBVerticalList
    lyt.Add(controls[1], 200)
    controls[1].Selected(7, True)
    controls[1].MultiSelect = True


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


CreateTool()