UI/Container.py

UI/Container.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Create tool with a container and shows how to set icon in it.
8 # Shows how to register callback (double click, onChange, DragAndDrop) in the container.
9 #
10 # Topic: FBVisualContainer, FBOrientation
11 #
12 
13 from pyfbsdk import *
14 from pyfbsdk_additions import *
15 
16 
17 def OnChangeCallback(control, event):
18  print control.GetSelection()
19 
20 def OnDoubleClickCallback(control, event):
21  print control.GetSelection()
22 
23 def OnDragAndDropCallback(control, event):
24  print event.State, event.PosX, event.PosY, event.Data[0], event.Data[1], event.Components
25 
26 
27 def PopulateLayout(mainLyt):
28  x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
29  y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
30  w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
31  h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
32  mainLyt.AddRegion("main","main", x, y, w, h)
33 
34  lyt = FBHBoxLayout()
35  mainLyt.SetControl("main",lyt)
36 
37  icons = ["devices_body.png", "devices_generalpurp.png", "devices_gloves.png", "devices_joystick.png", "devices_keyboard.png", "devices_mouse.png"]
38 
39  containers = [FBVisualContainer(), FBVisualContainer()]
40  for containerIndex, c in enumerate(containers):
41  for i, icon in enumerate(icons):
42  itemIndex = ((containerIndex * 7) + i);
43  c.Items.append(("Item %d" % itemIndex, itemIndex ) )
44  c.ItemIconSet(itemIndex, icon)
45 
46  c.ItemHeight = 70
47  c.ItemWidth = 70
48  c.OnDblClick.Add(OnDoubleClickCallback)
49  c.OnChange.Add(OnChangeCallback)
50  c.OnDragAndDrop.Add(OnDragAndDropCallback)
51 
52  lyt.AddRelative(c)
53 
54  containers[0].Orientation = FBOrientation.kFBHorizontal
55  containers[1].Orientation = FBOrientation.kFBVertical
56 
57 def CreateTool():
58  # Tool creation will serve as the hub for all other controls
59  t = FBCreateUniqueTool("Container Tool Example")
60  t.StartSizeX = 400
61  t.StartSizeY = 400
62  PopulateLayout(t)
63 
64  ShowTool(t)
65 
66 CreateTool()