UI/Container.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 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 = FBHBoxLayout()
    mainLyt.SetControl("main",lyt)
    
    icons = ["devices_body.png", "devices_generalpurp.png", "devices_gloves.png", "devices_joystick.png", "devices_keyboard.png", "devices_mouse.png"]
    
    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 = FBCreateUniqueTool("Container Tool Example")
    t.StartSizeX = 400
    t.StartSizeY = 400
    PopulateLayout(t)

    ShowTool(t)

CreateTool()