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