Python Reference Guide
 
Loading...
Searching...
No Matches
UI\BoxLayout.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 that shows how to use a FBVBoxLayout/FBHBoxLayout to place controls dynamically on screen.
8#
9# Topic: FBHBoxLayout, FBVBoxLayout, FBAttachType
10#
11
12from pyfbsdk import *
13from pyfbsdk_additions import *
14
15
16def PopulateLayout(mainLyt):
17 # Create Main region frame:
18 x = FBAddRegionParam(5,FBAttachType.kFBAttachLeft,"")
19 y = FBAddRegionParam(5,FBAttachType.kFBAttachTop,"")
20 w = FBAddRegionParam(-5,FBAttachType.kFBAttachRight,"")
21 h = FBAddRegionParam(-5,FBAttachType.kFBAttachBottom,"")
22
23 main = FBVBoxLayout()
24 mainLyt.AddRegion("main","main", x, y, w, h)
25 mainLyt.SetControl("main",main)
26
27
28 # create horizontal boxes packed in a vbox
29 hstripes = FBVBoxLayout()
30
31 # Shows how to create a FBHBoxLayout that grows from left to right
32 box = FBHBoxLayout(FBAttachType.kFBAttachLeft)
33 names = ["from ->", "left ->", "to ->", "right ->"]
34 for name in names:
35 b = FBButton()
36 b.Caption = name
37 box.Add(b, 50)
38 hstripes.Add(box, 35)
39
40 # Shows how to create a FBHBoxLayout that grows from right to left
41 box = FBHBoxLayout(FBAttachType.kFBAttachRight)
42 names = ["<- from", "<- right", "<- to", "<- left"]
43 for name in names:
44 b = FBButton()
45 b.Caption = name
46 box.Add(b, 50)
47 hstripes.Add(box, 35)
48
49 # Add a button that is center in its row using "dummy" addRelative
50 row = FBHBoxLayout(FBAttachType.kFBAttachLeft)
51 row.AddRelative(None)
52 b = FBButton()
53 b.Caption = "center"
54 row.Add(b, 50)
55 row.AddRelative(None)
56 hstripes.Add(row,35)
57
58 # Shows how to add buttons that resize to take all spaces available according to ratio
59 names = [("1/4 of width", 0.25), ("1/2 of width", 0.5), ("1/4 of width", 0.25)]
60 box = FBHBoxLayout(FBAttachType.kFBAttachLeft)
61 for name, ratio in names:
62 b = FBButton()
63 b.Caption = name
64 box.AddRelative(b, ratio)
65 hstripes.Add(box, 35)
66
67
68 # add all vbox into the main layout
69 main.AddRelative(hstripes,1.0)
70
71 vstripes = FBHBoxLayout()
72
73 # Shows how to create a FBVBoxLayout that grows from Top to bottom
74 box = FBVBoxLayout(FBAttachType.kFBAttachTop)
75 names = ["from ", "top", "to", "bottom"]
76 for name in names:
77 b = FBButton()
78 b.Caption = name
79 box.Add(b, 50)
80 vstripes.Add(box, 70)
81
82 # Shows how to create a FBVBoxLayout that grows Bottom to Top
83 box = FBVBoxLayout(FBAttachType.kFBAttachBottom)
84 names = ["from", "bottom", "to", "top"]
85 for name in names:
86 b = FBButton()
87 b.Caption = name
88 box.Add(b, 50)
89 vstripes.Add(box, 70)
90
91 # Add a button that is center in its column using "dummy" addRelative
92 row = FBVBoxLayout()
93 row.AddRelative(None)
94 b = FBButton()
95 b.Caption = "center"
96 row.Add(b, 35)
97 row.AddRelative(None)
98 vstripes.Add(row,70)
99
100 # Shows how to add buttons that resize to take all spaces available according to ratio
101 names = [("1/4 of width", 0.25), ("1/2 of width", 0.5), ("1/4 of width", 0.25)]
102 box = FBVBoxLayout()
103 for name, ratio in names:
104 b = FBButton()
105 b.Caption = name
106 box.AddRelative(b, ratio)
107 vstripes.Add(box, 70)
108
109 main.AddRelative(vstripes,1.0)
110
111def CreateTool():
112 # Tool creation will serve as the hub for all other controls
113 t = FBCreateUniqueTool("Box Example")
114 PopulateLayout(t)
115 t.StartSizeX = 800
116 t.StartSizeY = 800
117 ShowTool(t)
118
119
120CreateTool()
Used to create and manage buttons in a user interface.
Definition: pyfbsdk_generated.h:2442