UI/Layout.py

UI/Layout.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 a tool with an empty layout (with border) and shows how to register clalback (idle, input, paint, resize, show)
8 #
9 # Topic: FBLayout
10 #
11 
12 from pyfbsdk import *
13 from pyfbsdk_additions import *
14 
15 def OnInputCb(control,event):
16  print "OnInput ", control, event.Key, event.X, event.Y
17 
18 def OnResizeCb(control,event):
19  print "OnResize ", control, event.Width, event.Height
20 
21 def OnShowCb(control,event):
22  print "OnShow ", control, event.Shown
23 
24 def OnPaintCb(control,event):
25  print "OnPaint ", control, event
26 
27 def OnIdleCb(control,event):
28  print "OnIdle ", control, event
29 
30 def PopulateLayout(mainLyt):
31  lyt = FBLayout()
32  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
33  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
34  w = FBAddRegionParam(400,FBAttachType.kFBAttachNone,"")
35  h = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
36  lyt.AddRegion("Border1","Border2", x, y, w, h)
37  lyt.SetBorder("Border1",FBBorderStyle.kFBStandardBorder,True, True,1,0,90,0)
38 
39  lyt.OnInput.Add(OnInputCb)
40  lyt.OnResize.Add(OnResizeCb)
41  lyt.OnShow.Add(OnShowCb)
42  # This is commented out because these callbacks run all the time
43  # lyt.OnPaint.Add(OnPaintCb)
44  # lyt.OnIdle.Add(OnIdleCb)
45 
46  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
47  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
48  w = FBAddRegionParam(-10,FBAttachType.kFBAttachRight,"")
49  h = FBAddRegionParam(-10,FBAttachType.kFBAttachBottom,"")
50  mainLyt.AddRegion("Reg","Reg", x, y, w, h)
51  mainLyt.SetControl("Reg",lyt)
52 
53 def CreateTool():
54  # Tool creation will serve as the hub for all other controls
55  t = FBCreateUniqueTool("Tool Layout")
56 
57  PopulateLayout(t)
58  ShowTool(t)
59 
60 CreateTool()
61