1 from wxPython
.wx
import *
8 wxPopupWindow
= wxPopupTransientWindow
= wxWindow
10 #---------------------------------------------------------------------------
12 class TestPopup(wxPopupWindow
):
13 """Adds a bit of text and mouse movement to the wxPopupWindow"""
14 def __init__(self
, parent
, style
):
15 wxPopupWindow
.__init
__(self
, parent
, style
)
16 self
.SetBackgroundColour("CADET BLUE")
17 st
= wxStaticText(self
, -1,
18 "This is a special kind of top level\n"
19 "window that can be used for\n"
20 "popup menus, combobox popups\n"
22 "Try positioning the demo near\n"
23 "the bottom of the screen and \n"
24 "hit the button again.\n\n"
25 "In this demo this window can\n"
26 "be dragged with the left button\n"
27 "and closed with the right."
31 self
.SetSize( (sz
.width
+20, sz
.height
+20) )
33 EVT_LEFT_DOWN(self
, self
.OnMouseLeftDown
)
34 EVT_MOTION(self
, self
.OnMouseMotion
)
35 EVT_LEFT_UP(self
, self
.OnMouseLeftUp
)
36 EVT_RIGHT_UP(self
, self
.OnRightUp
)
37 EVT_LEFT_DOWN(st
, self
.OnMouseLeftDown
)
38 EVT_MOTION(st
, self
.OnMouseMotion
)
39 EVT_LEFT_UP(st
, self
.OnMouseLeftUp
)
40 EVT_RIGHT_UP(st
, self
.OnRightUp
)
42 def OnMouseLeftDown(self
, evt
):
43 self
.ldPos
= evt
.GetEventObject().ClientToScreen(evt
.GetPosition())
44 self
.wPos
= self
.GetPosition()
47 def OnMouseMotion(self
, evt
):
48 if evt
.Dragging() and evt
.LeftIsDown():
49 dPos
= evt
.GetEventObject().ClientToScreen(evt
.GetPosition())
50 nPos
= (self
.wPos
.x
+ (dPos
.x
- self
.ldPos
.x
),
51 self
.wPos
.y
+ (dPos
.y
- self
.ldPos
.y
))
54 def OnMouseLeftUp(self
, evt
):
57 def OnRightUp(self
, evt
):
62 class TestTransientPopup(wxPopupTransientWindow
):
63 """Adds a bit of text and mouse movement to the wxPopupWindow"""
64 def __init__(self
, parent
, style
, log
):
65 wxPopupTransientWindow
.__init
__(self
, parent
, style
)
67 panel
= wxPanel(self
, -1)
68 panel
.SetBackgroundColour("#FFB6C1")
69 st
= wxStaticText(panel
, -1,
70 "wxPopupTransientWindow is a\n"
71 "wxPopupWindow which disappears\n"
72 "automatically when the user\n"
73 "clicks the mouse outside it or if it\n"
74 "loses focus in any other way."
78 panel
.SetSize( (sz
.width
+20, sz
.height
+20) )
79 self
.SetSize(panel
.GetSize())
81 def ProcessLeftDown(self
, evt
):
82 self
.log
.write("ProcessLeftDown\n")
86 self
.log
.write("OnDismiss\n")
90 class TestPanel(wxPanel
):
91 def __init__(self
, parent
, log
):
92 wxPanel
.__init
__(self
, parent
, -1)
95 b
= wxButton(self
, -1, "Show wxPopupWindow", (25, 50))
96 EVT_BUTTON(self
, b
.GetId(), self
.OnShowPopup
)
98 b
= wxButton(self
, -1, "Show wxPopupTransientWindow", (25, 95))
99 EVT_BUTTON(self
, b
.GetId(), self
.OnShowPopupTransient
)
102 b
= wxButton(self
, -1, "Show wxPopupWindow with listbox", (25, 140))
103 EVT_BUTTON(self
, b
.GetId(), self
.OnShowPopupListbox
)
106 def OnShowPopup(self
, evt
):
107 win
= TestPopup(self
, wxSIMPLE_BORDER
)
109 # Show the popup right below or above the button
110 # depending on available screen space...
111 btn
= evt
.GetEventObject()
112 pos
= btn
.ClientToScreen( (0,0) )
114 win
.Position(pos
, (0, sz
.height
))
119 def OnShowPopupTransient(self
, evt
):
120 win
= TestTransientPopup(self
, wxSIMPLE_BORDER
, self
.log
)
122 # Show the popup right below or above the button
123 # depending on available screen space...
124 btn
= evt
.GetEventObject()
125 pos
= btn
.ClientToScreen( (0,0) )
127 win
.Position(pos
, (0, sz
.height
))
132 def OnShowPopupListbox(self
, evt
):
133 win
= TestPopupWithListbox(self
, wxNO_BORDER
, self
.log
)
135 # Show the popup right below or above the button
136 # depending on available screen space...
137 btn
= evt
.GetEventObject()
138 pos
= btn
.ClientToScreen( (0,0) )
140 win
.Position(pos
, (0, sz
.height
))
144 class TestPopupWithListbox(wxPopupWindow
):
145 def __init__(self
, parent
, style
, log
):
146 wxPopupWindow
.__init
__(self
, parent
, style
)
148 self
.lb
= wxListBox(self
, -1, choices
= keyword
.kwlist
)
149 #sz = self.lb.GetBestSize()
150 self
.SetSize((150, 75)) #sz)
151 self
.lb
.SetSize(self
.GetClientSize())
153 EVT_LEFT_DOWN(self
.lb
, self
.OnLeft
)
154 EVT_LISTBOX(self
, -1, self
.OnListBox
)
156 def OnLeft(self
, evt
):
157 print "OnLeft", evt
.GetEventObject()
159 def OnListBox(self
, evt
):
160 print "OnListBox", evt
.GetEventObject()
165 #---------------------------------------------------------------------------
167 def runTest(frame
, nb
, log
):
169 win
= TestPanel(nb
, log
)
172 dlg
= wxMessageDialog(frame
, 'wxPopupWindow is not available on this platform.',
173 'Sorry', wxOK | wxICON_INFORMATION
)
177 #---------------------------------------------------------------------------
188 if __name__
== '__main__':
191 run
.main(['', os
.path
.basename(sys
.argv
[0])])