UI/GridLayout.py

UI/GridLayout.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 showing how to use a FBGridLayout to dynamically place controls on screen.
8 #
9 # Topic: FBGridLayout
10 #
11 
12 from pyfbsdk import *
13 from pyfbsdk_additions import *
14 
15 def PopulateLayout(mainLyt):
16  # Create Main region frame:
17  x = FBAddRegionParam(5,FBAttachType.kFBAttachLeft,"")
18  y = FBAddRegionParam(5,FBAttachType.kFBAttachTop,"")
19  w = FBAddRegionParam(-5,FBAttachType.kFBAttachRight,"")
20  h = FBAddRegionParam(-5,FBAttachType.kFBAttachBottom,"")
21  mainLyt.AddRegion("main","main", x, y, w, h)
22 
23  grid = FBGridLayout()
24 
25  grid.SetRowRatio(0, 3.0)
26 
27  # Add buttons in the first row
28  for i in range(7):
29  b = FBButton()
30  b.Caption = "0," + str(i)
31  grid.Add(b,0,i)
32 
33  # add buttons in the first column
34  for i in range(7):
35  b = FBButton()
36  b.Caption = str(i) + ",0"
37  grid.Add(b,i,0)
38 
39  b = FBButton()
40  b.Caption = "0,1"
41  grid.Add(b,0,1)
42 
43  b = FBButton()
44  b.Caption = "1,3"
45  # specify button width: this will make the rows and columns grow to accomodate this big button
46  grid.Add(b,1,3, width = 200)
47 
48  # set the height of the row 2
49  grid.SetRowHeight(2, 50)
50 
51  b = FBButton()
52  b.Caption = "2,2"
53  # specify the width and height of a button
54  grid.Add(b,2,2,width = 45, height = 25)
55 
56  # set the spacing between col3 and col4
57  grid.SetColSpacing(3, 50)
58 
59  b = FBButton()
60  b.Caption = "2,3"
61  # specify that the button will be "right justified" in the column (attachX relates to horizontal position)
62  grid.Add(b,2,3,attachX = FBAttachType.kFBAttachRight, width = 25, height = 20, attachY = FBAttachType.kFBAttachBottom)
63 
64  b = FBButton()
65  b.Caption = "3,1"
66  # specify the height of the button
67  grid.Add(b,3,1, height = 200)
68 
69 
70  b = FBButton()
71  b.Caption = "3,2"
72  # specify that the button will be attach to the bottom of the row (attachY relates to vertical position)
73  grid.Add(b,3,2,attachY = FBAttachType.kFBAttachBottom, height = 25)
74 
75  b = FBButton()
76  b.Caption = "3,6,3,6"
77  # this button will span from row 3 to row 6 and from col 3 to col 6.
78  grid.AddRange(b,3,6, 3, 6)
79 
80  mainLyt.SetControl("main",grid)
81 
82 def CreateTool():
83  # Tool creation will serve as the hub for all other controls
84  t = FBCreateUniqueTool("Grid Example")
85  PopulateLayout(t)
86  # Button creation
87  t.StartSizeX = 800
88  t.StartSizeY = 800
89  ShowTool(t)
90 
91 
92 CreateTool()
93