# 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 tool with a container and shows how to set icon in it.
# Shows how to register callback (double click, onChange, DragAndDrop) in the container.
#
# Topic: FBContainer, FBOrientation
#

from pyfbsdk import *
from pyfbsdk_additions import *


def OnChangeCallback(control, event):
    print control.GetSelection()

def OnDoubleClickCallback(control, event):
    print control.GetSelection()

def OnDragAndDropCallback(control, event):
    print event.State, event.PosX, event.PosY, event.Data0, event.Data1, event.Components


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)

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

    icons = ["devices_body.tif", "devices_generalpurp.tif", "devices_gloves.tif", "devices_joystick.tif", "devices_keyboard.tif", "devices_mouse.tif"]

    containers = [FBContainer(), FBContainer()]
    for containerIndex, c in enumerate(containers):
        for i, icon in enumerate(icons):
            itemIndex = ((containerIndex * 7) + i);
            c.Items.append(("Item %d" % itemIndex, itemIndex ) )
            c.ItemIconSet(itemIndex, icon)

        c.ItemHeight = 70
        c.ItemWidth = 70
        c.OnDblClick.Add(OnDoubleClickCallback)
        c.OnChange.Add(OnChangeCallback)
        c.OnDragAndDrop.Add(OnDragAndDropCallback)

        lyt.AddRelative(c)

    containers[0].Orientation = FBOrientation.kFBHorizontal
    containers[1].Orientation = FBOrientation.kFBVertical

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

    ShowTool(t)

CreateTool()