UI/TutorialGrid.py

UI/TutorialGrid.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 # Tutorial for the FBGridLayout. This is the code used in the Python Scripting Help Dev Guide.
8 #
9 # Topic: FBGridLayout, FBMemo
10 #
11 
12 from pyfbsdk import *
13 import pyfbsdk_additions
14 from pyfbsdk_additions import *
15 
16 t = FBCreateUniqueTool("Simple Grid Example")
17 t.StartSizeX = 400
18 t.StartSizeY = 400
19 
20 x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
21 y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
22 w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
23 h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
24 t.AddRegion("main","main", x, y, w, h)
25 
26 # create our gridLayout
27 grid = FBGridLayout()
28 t.SetControl("main", grid)
29 
30 #Create our Label
31 
32 label = FBLabel()
33 label.Caption = "Enter your suggestions:"
34 
35 # add the label to the top left corner of the grid
36 grid.Add(label, 0, 0)
37 
38 # create the Memo
39 memo = FBMemo()
40 
41 # we want the memo to span from row 1 to row1 and from column 0 to column 2
42 grid.AddRange(memo, 1, 1, 0, 2)
43 
44 # create buttons
45 ok = FBButton()
46 ok.Caption = "Ok"
47 cancel = FBButton()
48 cancel.Caption = "Cancel"
49 
50 # place the buttons in their respective columns and in row2
51 grid.Add(ok, 2, 1)
52 grid.Add(cancel, 2, 2)
53 
54 # now assign the rows and columns attributes
55 
56 # Fixed the height of row 0 and row 2 so the label and the buttons
57 # have a normal height
58 grid.SetRowHeight(0, 30)
59 grid.SetRowHeight(2, 30)
60 
61 # want to fix the width of column 1 and 2 so the buttons are
62 # of a normal size
63 grid.SetColWidth( 1, 45 )
64 grid.SetColWidth( 2, 45 )
65 
66 # To ensure our memo can be stretched, ensure row 1 and column 0 have a ratio
67 grid.SetColRatio( 0, 1.0 )
68 grid.SetRowRatio( 1, 1.0 )
69 
70 
71 ShowTool(t)