]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupWindow.py
swigged code update for wxMac
[wxWidgets.git] / wxPython / demo / wxPopupWindow.py
1 from wxPython.wx import *
2
3 #---------------------------------------------------------------------------
4
5 class TestPopup(wxPopupWindow):
6 """Adds a bit of text and mouse movement to the wxPopupWindow"""
7 def __init__(self, parent, style):
8 wxPopupWindow.__init__(self, parent, style)
9 self.SetBackgroundColour("CADET BLUE")
10 st = wxStaticText(self, -1,
11 "This is a special kind of top level\n"
12 "window that can be used for\n"
13 "popup menus, combobox popups\n"
14 "and such.\n\n"
15 "Try positioning the demo near\n"
16 "the bottom of the screen and \n"
17 "hit the button again.\n\n"
18 "In this demo this window can\n"
19 "be dragged with the left button\n"
20 "and closed with the right."
21 ,
22 pos=(10,10))
23 sz = st.GetBestSize()
24 self.SetSize( (sz.width+20, sz.height+20) )
25
26 EVT_LEFT_DOWN(self, self.OnMouseLeftDown)
27 EVT_MOTION(self, self.OnMouseMotion)
28 EVT_LEFT_UP(self, self.OnMouseLeftUp)
29 EVT_RIGHT_UP(self, self.OnRightUp)
30 EVT_LEFT_DOWN(st, self.OnMouseLeftDown)
31 EVT_MOTION(st, self.OnMouseMotion)
32 EVT_LEFT_UP(st, self.OnMouseLeftUp)
33 EVT_RIGHT_UP(st, self.OnRightUp)
34
35 def OnMouseLeftDown(self, evt):
36 self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
37 self.wPos = self.GetPosition()
38 self.CaptureMouse()
39
40 def OnMouseMotion(self, evt):
41 if evt.Dragging() and evt.LeftIsDown():
42 dPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
43 nPos = (self.wPos.x + (dPos.x - self.ldPos.x),
44 self.wPos.y + (dPos.y - self.ldPos.y))
45 self.Move(nPos)
46
47 def OnMouseLeftUp(self, evt):
48 self.ReleaseMouse()
49
50 def OnRightUp(self, evt):
51 self.Show(false)
52 self.Destroy()
53
54
55 class TestPopupWithListbox(wxPopupWindow):
56 def __init__(self, parent, style, log):
57 wxPopupWindow.__init__(self, parent, style)
58 import keyword
59 self.lb = wxListBox(self, -1, choices = keyword.kwlist)
60
61 #sz = self.lb.GetBestSize()
62 self.SetSize((150, 75)) #sz)
63 self.lb.SetSize(self.GetClientSize())
64 self.lb.SetFocus()
65
66 EVT_LEFT_DOWN(self.lb, self.OnLeft)
67 EVT_LISTBOX(self, -1, self.OnListBox)
68
69
70 def OnLeft(self, evt):
71 print "OnLeft", evt.GetEventObject()
72 evt.Skip()
73 def OnListBox(self, evt):
74 print "OnListBox", evt.GetEventObject()
75 evt.Skip()
76
77
78
79 class TestTransientPopup(wxPopupTransientWindow):
80 """Adds a bit of text and mouse movement to the wxPopupWindow"""
81 def __init__(self, parent, style, log):
82 wxPopupTransientWindow.__init__(self, parent, style)
83 self.log = log
84 panel = wxPanel(self, -1)
85 panel.SetBackgroundColour("#FFB6C1")
86 st = wxStaticText(panel, -1,
87 "wxPopupTransientWindow is a\n"
88 "wxPopupWindow which disappears\n"
89 "automatically when the user\n"
90 "clicks the mouse outside it or if it\n"
91 "loses focus in any other way."
92 ,
93 pos=(10,10))
94 sz = st.GetBestSize()
95 panel.SetSize( (sz.width+20, sz.height+20) )
96 self.SetSize(panel.GetSize())
97
98 def ProcessLeftDown(self, evt):
99 self.log.write("ProcessLeftDown\n")
100 return false
101
102 def OnDismiss(self):
103 self.log.write("OnDismiss\n")
104
105
106
107 class TestPanel(wxPanel):
108 def __init__(self, parent, log):
109 wxPanel.__init__(self, parent, -1)
110 self.log = log
111
112 b = wxButton(self, -1, "Show wxPopupWindow", (25, 50))
113 EVT_BUTTON(self, b.GetId(), self.OnShowPopup)
114
115 b = wxButton(self, -1, "Show wxPopupTransientWindow", (25, 95))
116 EVT_BUTTON(self, b.GetId(), self.OnShowPopupTransient)
117
118 b = wxButton(self, -1, "Show wxPopupWindow with listbox", (25, 140))
119 EVT_BUTTON(self, b.GetId(), self.OnShowPopupListbox)
120
121
122 def OnShowPopup(self, evt):
123 win = TestPopup(self, wxSIMPLE_BORDER)
124
125 # Show the popup right below or above the button
126 # depending on available screen space...
127 btn = evt.GetEventObject()
128 pos = btn.ClientToScreen( (0,0) )
129 sz = btn.GetSize()
130 win.Position(pos, (0, sz.height))
131
132 win.Show(true)
133
134
135 def OnShowPopupTransient(self, evt):
136 win = TestTransientPopup(self, wxSIMPLE_BORDER, self.log)
137
138 # Show the popup right below or above the button
139 # depending on available screen space...
140 btn = evt.GetEventObject()
141 pos = btn.ClientToScreen( (0,0) )
142 sz = btn.GetSize()
143 win.Position(pos, (0, sz.height))
144
145 win.Popup()
146
147
148 def OnShowPopupListbox(self, evt):
149 win = TestPopupWithListbox(self, wxNO_BORDER, self.log)
150
151 # Show the popup right below or above the button
152 # depending on available screen space...
153 btn = evt.GetEventObject()
154 pos = btn.ClientToScreen( (0,0) )
155 sz = btn.GetSize()
156 win.Position(pos, (0, sz.height))
157
158 win.Show(true)
159
160 #---------------------------------------------------------------------------
161
162 def runTest(frame, nb, log):
163 win = TestPanel(nb, log)
164 return win
165
166 #---------------------------------------------------------------------------
167
168
169
170
171 overview = """\
172 """