UI/Popup.py

UI/Popup.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 will create and close a FBPopup
8 #
9 # Topic: FBButton, FBPopup
10 #
11 
12 from pyfbsdk import *
13 from pyfbsdk_additions import *
14 
15 # Button creation
16 def ShowPopupCallback(control, event):
17  global t
18  popup.Show(t)
19 
20 # a Popup is really a layout. It should be populated/initialized
21 def ClosePopupCallback(control, event):
22  popup.Close(True)
23 
24 
25 def PopulateLayout(mainLyt):
26  # create a button on the tool that will show the popup
27  b = FBButton()
28  b.Caption = "Pop up"
29 
30  x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
31  y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
32  w = FBAddRegionParam(50,FBAttachType.kFBAttachNone,"")
33  h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
34 
35  mainLyt.AddRegion("Btn","Btn", x, y, w, h)
36  mainLyt.SetControl("Btn",b)
37 
38  b.OnClick.Add(ShowPopupCallback)
39 
40  # create the popup
41  global popup
42  popup = FBPopup()
43  popup.Caption = "Popup"
44  popup.Modal = False
45 
46  popup.Left = 300
47  popup.Top = 300
48  popup.Width = 400
49  popup.Height = 500
50 
51  b = FBButton()
52  b.Caption = "Close"
53  b.OnClick.Add(ClosePopupCallback)
54 
55 
56  popup.AddRegion( "Close", "Close", x, y ,w,h )
57  popup.SetControl("Close", b)
58 
59 def CreateTool():
60  # Tool creation will serve as the hub for all other controls
61  global t
62  t = FBCreateUniqueTool("Popup Example")
63  PopulateLayout(t)
64  ShowTool(t)
65 
66 
67 CreateTool()
68