UI/MoveResizeToolExample.py

UI/MoveResizeToolExample.py
1 # Copyright 2014 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 # Shows how to move & resize a tool already opened.
8 #
9 # Topic: FBTool
10 #
11 
12 from pyfbsdk import *
13 import pyfbsdk_additions
14 
15 # Buttons creation
16 def BtnUpdateCallback(control, event):
17  (posX, posY) = GetToolPositionByName( toolname )
18  nPositionX.Value = posX
19  nPositionY.Value = posY
20 
21  (sizeW, sizeH) = GetToolSizeByName( toolname )
22  nSizeW.Value = sizeW
23  nSizeH.Value = sizeH
24 
25  nSizeMinW.Value = toolObj.MinSizeX
26  nSizeMinH.Value = toolObj.MinSizeY
27  nSizeMaxW.Value = toolObj.MaxSizeX
28  nSizeMaxH.Value = toolObj.MaxSizeY
29 
30 
31 def BtnApplyCallback(control, event):
32  SetToolPositionByName( toolname, (int)(nPositionX.Value), (int)(nPositionY.Value) )
33  SetToolSizeByName( toolname, (int)(nSizeW.Value), (int)(nSizeH.Value) )
34 
35  toolObj.MinSizeX = (int)(nSizeMinW.Value)
36  toolObj.MinSizeY = (int)(nSizeMinH.Value)
37  toolObj.MaxSizeX = (int)(nSizeMaxW.Value)
38  toolObj.MaxSizeY = (int)(nSizeMaxH.Value)
39 
40 
41 def PopulateLayout(mainLyt):
42 
43  #-------------------------------
44  # Tool Position
45  #-------------------------------
46  l = FBLabel()
47  l.Caption = "Tool Position:"
48  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
49  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
50  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
51  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
52 
53  mainLyt.AddRegion("LabelPosition","LabelPosition", x, y, w, h)
54  mainLyt.SetControl("LabelPosition",l)
55 
56 
57  l = FBLabel()
58  l.Caption = "X:"
59  x = FBAddRegionParam(90,FBAttachType.kFBAttachLeft,"")
60  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
61  w = FBAddRegionParam(10,FBAttachType.kFBAttachNone,"")
62  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
63 
64  mainLyt.AddRegion("LabelPositionX","LabelPositionX", x, y, w, h)
65  mainLyt.SetControl("LabelPositionX",l)
66 
67 
68  global nPositionX
69  nPositionX = FBEditNumber()
70  nPositionX.Precision = 0
71  x = FBAddRegionParam(100,FBAttachType.kFBAttachLeft,"")
72  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
73  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
74  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
75 
76  mainLyt.AddRegion("EditPositionX","EditPositionX", x, y, w, h)
77  mainLyt.SetControl("EditPositionX",nPositionX)
78 
79 
80 
81  l = FBLabel()
82  l.Caption = "Y:"
83  x = FBAddRegionParam(160,FBAttachType.kFBAttachLeft,"")
84  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
85  w = FBAddRegionParam(10,FBAttachType.kFBAttachNone,"")
86  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
87 
88  mainLyt.AddRegion("LabelPositionY","LabelPositionY", x, y, w, h)
89  mainLyt.SetControl("LabelPositionY",l)
90 
91 
92  global nPositionY
93  nPositionY = FBEditNumber()
94  nPositionY.Precision = 0
95  x = FBAddRegionParam(170,FBAttachType.kFBAttachLeft,"")
96  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
97  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
98  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
99 
100  mainLyt.AddRegion("EditPositionY","EditPositionY", x, y, w, h)
101  mainLyt.SetControl("EditPositionY",nPositionY)
102 
103 
104 
105  #-------------------------------
106  # Tool Size
107  #-------------------------------
108  l = FBLabel()
109  l.Caption = "Tool Size:"
110  x = FBAddRegionParam(250,FBAttachType.kFBAttachLeft,"")
111  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
112  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
113  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
114 
115  mainLyt.AddRegion("LabelSize","LabelSize", x, y, w, h)
116  mainLyt.SetControl("LabelSize",l)
117 
118 
119  l = FBLabel()
120  l.Caption = "W:"
121  x = FBAddRegionParam(350,FBAttachType.kFBAttachLeft,"")
122  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
123  w = FBAddRegionParam(15,FBAttachType.kFBAttachNone,"")
124  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
125 
126  mainLyt.AddRegion("LabelSizeW","LabelSizeW", x, y, w, h)
127  mainLyt.SetControl("LabelSizeW",l)
128 
129 
130  global nSizeW
131  nSizeW = FBEditNumber()
132  nSizeW.Precision = 0
133  x = FBAddRegionParam(365,FBAttachType.kFBAttachLeft,"")
134  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
135  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
136  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
137 
138  mainLyt.AddRegion("EditSizeW","EditSizeW", x, y, w, h)
139  mainLyt.SetControl("EditSizeW",nSizeW)
140 
141 
142 
143  l = FBLabel()
144  l.Caption = "H:"
145  x = FBAddRegionParam(440,FBAttachType.kFBAttachLeft,"")
146  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
147  w = FBAddRegionParam(10,FBAttachType.kFBAttachNone,"")
148  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
149 
150  mainLyt.AddRegion("LabelSizeH","LabelSizeH", x, y, w, h)
151  mainLyt.SetControl("LabelSizeH",l)
152 
153 
154  global nSizeH
155  nSizeH = FBEditNumber()
156  nSizeH.Precision = 0
157  x = FBAddRegionParam(450,FBAttachType.kFBAttachLeft,"")
158  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
159  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
160  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
161 
162  mainLyt.AddRegion("EditSizeH","EditSizeH", x, y, w, h)
163  mainLyt.SetControl("EditSizeH",nSizeH)
164 
165 
166 
167  #-------------------------------
168  # Tool Size Width
169  #-------------------------------
170  l = FBLabel()
171  l.Caption = "Tool Size Width:"
172  x = FBAddRegionParam(250,FBAttachType.kFBAttachLeft,"")
173  y = FBAddRegionParam(50,FBAttachType.kFBAttachTop,"")
174  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
175  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
176 
177  mainLyt.AddRegion("LabelSizeWidth","LabelSizeWidth", x, y, w, h)
178  mainLyt.SetControl("LabelSizeWidth",l)
179 
180 
181  l = FBLabel()
182  l.Caption = "Min:"
183  x = FBAddRegionParam(345,FBAttachType.kFBAttachLeft,"")
184  y = FBAddRegionParam(50,FBAttachType.kFBAttachTop,"")
185  w = FBAddRegionParam(20,FBAttachType.kFBAttachNone,"")
186  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
187 
188  mainLyt.AddRegion("LabelSizeMinW","LabelSizeMinW", x, y, w, h)
189  mainLyt.SetControl("LabelSizeMinW",l)
190 
191 
192  global nSizeMinW
193  nSizeMinW = FBEditNumber()
194  nSizeMinW.Precision = 0
195  x = FBAddRegionParam(365,FBAttachType.kFBAttachLeft,"")
196  y = FBAddRegionParam(50,FBAttachType.kFBAttachTop,"")
197  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
198  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
199 
200  mainLyt.AddRegion("EditSizeMinW","EditSizeMinW", x, y, w, h)
201  mainLyt.SetControl("EditSizeMinW",nSizeMinW)
202 
203 
204 
205  l = FBLabel()
206  l.Caption = "Max:"
207  x = FBAddRegionParam(425,FBAttachType.kFBAttachLeft,"")
208  y = FBAddRegionParam(50,FBAttachType.kFBAttachTop,"")
209  w = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
210  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
211 
212  mainLyt.AddRegion("LabelSizeMaxW","LabelSizeMaxW", x, y, w, h)
213  mainLyt.SetControl("LabelSizeMaxW",l)
214 
215 
216  global nSizeMaxW
217  nSizeMaxW = FBEditNumber()
218  nSizeMaxW.Precision = 0
219  x = FBAddRegionParam(450,FBAttachType.kFBAttachLeft,"")
220  y = FBAddRegionParam(50,FBAttachType.kFBAttachTop,"")
221  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
222  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
223 
224  mainLyt.AddRegion("EditSizeMaxW","EditSizeMaxW", x, y, w, h)
225  mainLyt.SetControl("EditSizeMaxW",nSizeMaxW)
226 
227 
228 
229  #-------------------------------
230  # Tool Size Height
231  #-------------------------------
232  l = FBLabel()
233  l.Caption = "Tool Size Height:"
234  x = FBAddRegionParam(250,FBAttachType.kFBAttachLeft,"")
235  y = FBAddRegionParam(90,FBAttachType.kFBAttachTop,"")
236  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
237  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
238 
239  mainLyt.AddRegion("LabelSizeHeight","LabelSizeHeight", x, y, w, h)
240  mainLyt.SetControl("LabelSizeHeight",l)
241 
242 
243  l = FBLabel()
244  l.Caption = "Min:"
245  x = FBAddRegionParam(345,FBAttachType.kFBAttachLeft,"")
246  y = FBAddRegionParam(90,FBAttachType.kFBAttachTop,"")
247  w = FBAddRegionParam(20,FBAttachType.kFBAttachNone,"")
248  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
249 
250  mainLyt.AddRegion("LabelSizeMinH","LabelSizeMinH", x, y, w, h)
251  mainLyt.SetControl("LabelSizeMinH",l)
252 
253 
254  global nSizeMinH
255  nSizeMinH = FBEditNumber()
256  nSizeMinH.Precision = 0
257  x = FBAddRegionParam(365,FBAttachType.kFBAttachLeft,"")
258  y = FBAddRegionParam(90,FBAttachType.kFBAttachTop,"")
259  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
260  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
261 
262  mainLyt.AddRegion("EditSizeMinH","EditSizeMinH", x, y, w, h)
263  mainLyt.SetControl("EditSizeMinH",nSizeMinH)
264 
265 
266 
267  l = FBLabel()
268  l.Caption = "Max:"
269  x = FBAddRegionParam(425,FBAttachType.kFBAttachLeft,"")
270  y = FBAddRegionParam(90,FBAttachType.kFBAttachTop,"")
271  w = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
272  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
273 
274  mainLyt.AddRegion("LabelSizeMaxH","LabelSizeMaxH", x, y, w, h)
275  mainLyt.SetControl("LabelSizeMaxH",l)
276 
277 
278  global nSizeMaxH
279  nSizeMaxH = FBEditNumber()
280  nSizeMaxH.Precision = 0
281  x = FBAddRegionParam(450,FBAttachType.kFBAttachLeft,"")
282  y = FBAddRegionParam(90,FBAttachType.kFBAttachTop,"")
283  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
284  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
285 
286  mainLyt.AddRegion("EditSizeMaxH","EditSizeMaxH", x, y, w, h)
287  mainLyt.SetControl("EditSizeMaxH",nSizeMaxH)
288 
289 
290  #-------------------------------
291  # Buttons
292  #-------------------------------
293  b = FBButton()
294  b.Caption = "Update Values!"
295  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
296  y = FBAddRegionParam(130,FBAttachType.kFBAttachTop,"")
297  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
298  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
299 
300  mainLyt.AddRegion("BtnUpdate","BtnUpdate", x, y, w, h)
301  mainLyt.SetControl("BtnUpdate",b)
302 
303  b.OnClick.Add(BtnUpdateCallback)
304 
305 
306  b = FBButton()
307  b.Caption = "Apply Changes!"
308  x = FBAddRegionParam(120,FBAttachType.kFBAttachLeft,"")
309  y = FBAddRegionParam(130,FBAttachType.kFBAttachTop,"")
310  w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
311  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
312 
313  mainLyt.AddRegion("BtnApply","BtnApply", x, y, w, h)
314  mainLyt.SetControl("BtnApply",b)
315 
316  b.OnClick.Add(BtnApplyCallback)
317 
318 
319 
320  #-------------------------------
321  # Known issue
322  #-------------------------------
323  l = FBLabel()
324  l.Caption = "Known issue:\nWhen the Tool width/height values are near its related min/max limit values,\nthe width/height values returned are different than the values get."
325  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
326  y = FBAddRegionParam(170,FBAttachType.kFBAttachTop,"")
327  w = FBAddRegionParam(500,FBAttachType.kFBAttachNone,"")
328  h = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
329 
330  mainLyt.AddRegion("LabelSizeKnownIssue","LabelSizeKnownIssue", x, y, w, h)
331  mainLyt.SetControl("LabelSizeKnownIssue",l)
332 
333 
334 
335 toolname = "Move & Resize Tool Example"
336 
337 
338 def CreateTool():
339  t = pyfbsdk_additions.FBCreateUniqueTool(toolname)
340  t.StartSizeX = 550
341  t.StartSizeY = 250
342  PopulateLayout(t)
343  return t
344 
345 global toolObj
346 if toolname in pyfbsdk_additions.FBToolList:
347  toolObj = ShowToolByName(toolname)
348 else:
349  toolObj = CreateTool()
350 
351  # Comment this line if you want to put this script in PythonStartup folder.
352  ShowTool(toolObj)
353