UI/Edit.py

UI/Edit.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 different FBEdit controls and possible customizations
8 #
9 # Topic: FBEdit, FBEditColor, FBEditNumber, FBEditVector, FBEditTimeCode
10 #
11 
12 from pyfbsdk import *
13 from pyfbsdk_additions import *
14 
15 editStyles = ["FBEdit","FBEditColor","FBEditNumber","FBEditVector","FBEditTimeCode"]
16 edits = {}
17 
18 # Normal Edit
19 def OnChange(control,event):
20  print control.Text
21 
22 def PopulateLayout(mainLyt):
23  anchor = ""
24  attachType = FBAttachType.kFBAttachTop
25 
26  # Generically create different types of edit
27  for style in editStyles:
28  # Create label
29  labId = "Label" + style
30  l = FBLabel()
31  l.Caption = style
32  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
33  y = FBAddRegionParam(10,attachType,anchor)
34  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
35  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
36 
37  mainLyt.AddRegion(labId,labId, x, y, w, h)
38  mainLyt.SetControl(labId,l)
39 
40  # Create edit
41  editId = "Edit" + style
42  initCall = "%s()" % (style)
43  e = eval( initCall )
44  edits[style] = e
45 
46  x = FBAddRegionParam(10,FBAttachType.kFBAttachRight,labId)
47  y = FBAddRegionParam(10,attachType,anchor)
48  w = FBAddRegionParam(200,FBAttachType.kFBAttachNone,"")
49  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
50 
51  mainLyt.AddRegion(editId,editId, x, y, w, h)
52 
53  mainLyt.SetControl(editId,e)
54 
55  attachType = FBAttachType.kFBAttachBottom
56  anchor = labId
57 
58  # Do specific edit initialization according to its type
59 
60  e = edits['FBEdit']
61  e.Text = "initial text"
62  #e.PasswordMode = True
63  e.OnChange.Add(OnChange)
64 
65 
66  # Color Edit
67  e = edits['FBEditColor']
68  e.Value = FBColor(1.0, 0.0,0.0)
69  # e.ColorMode = 2
70  # e.ColorMode = 3
71 
72  # Number edit
73  e = edits['FBEditNumber']
74  e.Max = 100
75  e.Min = 34
76  e.Value = 62
77 
78  # Vector Edit
79  e = edits['FBEditVector']
80  e.Value = FBVector3d(42.0, 23.0,666.666)
81 
82  e = edits['FBEditTimeCode']
83  e.Value = FBTime(11,22,33,11)
84 
85 def CreateTool():
86  # Tool creation will serve as the hub for all other controls
87  t = FBCreateUniqueTool("Edit Example")
88  PopulateLayout(t)
89  ShowTool(t)
90 
91 CreateTool()