]>
Commit | Line | Data |
---|---|---|
0122b7e3 RD |
1 | from wxPython.wx import * |
2 | ||
eb0f373c RD |
3 | havePopupWindow = 1 |
4 | try: | |
5 | wxPopupWindow | |
6 | except NameError: | |
7 | havePopupWindow = 0 | |
8 | wxPopupWindow = wxPopupTransientWindow = wxWindow | |
9 | ||
0122b7e3 RD |
10 | #--------------------------------------------------------------------------- |
11 | ||
12 | class TestPopup(wxPopupWindow): | |
c0c84fa0 | 13 | """Adds a bit of text and mouse movement to the wxPopupWindow""" |
0122b7e3 RD |
14 | def __init__(self, parent, style): |
15 | wxPopupWindow.__init__(self, parent, style) | |
c0c84fa0 RD |
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" | |
21 | "and such.\n\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." | |
28 | , | |
29 | pos=(10,10)) | |
30 | sz = st.GetBestSize() | |
31 | self.SetSize( (sz.width+20, sz.height+20) ) | |
0122b7e3 RD |
32 | |
33 | EVT_LEFT_DOWN(self, self.OnMouseLeftDown) | |
34 | EVT_MOTION(self, self.OnMouseMotion) | |
35 | EVT_LEFT_UP(self, self.OnMouseLeftUp) | |
c0c84fa0 RD |
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) | |
0122b7e3 RD |
41 | |
42 | def OnMouseLeftDown(self, evt): | |
c0c84fa0 | 43 | self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition()) |
f0db4f38 | 44 | self.wPos = self.GetPosition() |
0122b7e3 RD |
45 | self.CaptureMouse() |
46 | ||
47 | def OnMouseMotion(self, evt): | |
c0c84fa0 RD |
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)) | |
52 | self.Move(nPos) | |
0122b7e3 RD |
53 | |
54 | def OnMouseLeftUp(self, evt): | |
55 | self.ReleaseMouse() | |
c0c84fa0 | 56 | |
c0c84fa0 RD |
57 | def OnRightUp(self, evt): |
58 | self.Show(false) | |
59 | self.Destroy() | |
60 | ||
61 | ||
62 | class TestTransientPopup(wxPopupTransientWindow): | |
63 | """Adds a bit of text and mouse movement to the wxPopupWindow""" | |
a57d56d6 | 64 | def __init__(self, parent, style, log): |
c0c84fa0 | 65 | wxPopupTransientWindow.__init__(self, parent, style) |
a57d56d6 RD |
66 | self.log = log |
67 | panel = wxPanel(self, -1) | |
68 | panel.SetBackgroundColour("#FFB6C1") | |
69 | st = wxStaticText(panel, -1, | |
c0c84fa0 RD |
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." | |
75 | , | |
76 | pos=(10,10)) | |
77 | sz = st.GetBestSize() | |
a57d56d6 RD |
78 | panel.SetSize( (sz.width+20, sz.height+20) ) |
79 | self.SetSize(panel.GetSize()) | |
0122b7e3 | 80 | |
a57d56d6 RD |
81 | def ProcessLeftDown(self, evt): |
82 | self.log.write("ProcessLeftDown\n") | |
83 | return false | |
84 | ||
85 | def OnDismiss(self): | |
86 | self.log.write("OnDismiss\n") | |
87 | ||
0122b7e3 | 88 | |
2d3a90ce | 89 | |
0122b7e3 RD |
90 | class TestPanel(wxPanel): |
91 | def __init__(self, parent, log): | |
92 | wxPanel.__init__(self, parent, -1) | |
93 | self.log = log | |
94 | ||
c0c84fa0 | 95 | b = wxButton(self, -1, "Show wxPopupWindow", (25, 50)) |
0122b7e3 RD |
96 | EVT_BUTTON(self, b.GetId(), self.OnShowPopup) |
97 | ||
c0c84fa0 RD |
98 | b = wxButton(self, -1, "Show wxPopupTransientWindow", (25, 95)) |
99 | EVT_BUTTON(self, b.GetId(), self.OnShowPopupTransient) | |
100 | ||
25e92d2d RD |
101 | if 0: |
102 | b = wxButton(self, -1, "Show wxPopupWindow with listbox", (25, 140)) | |
103 | EVT_BUTTON(self, b.GetId(), self.OnShowPopupListbox) | |
2d3a90ce | 104 | |
0122b7e3 RD |
105 | |
106 | def OnShowPopup(self, evt): | |
107 | win = TestPopup(self, wxSIMPLE_BORDER) | |
c0c84fa0 RD |
108 | |
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) ) | |
113 | sz = btn.GetSize() | |
114 | win.Position(pos, (0, sz.height)) | |
115 | ||
0122b7e3 RD |
116 | win.Show(true) |
117 | ||
118 | ||
c0c84fa0 | 119 | def OnShowPopupTransient(self, evt): |
a57d56d6 | 120 | win = TestTransientPopup(self, wxSIMPLE_BORDER, self.log) |
c0c84fa0 | 121 | |
a57d56d6 RD |
122 | # Show the popup right below or above the button |
123 | # depending on available screen space... | |
c0c84fa0 RD |
124 | btn = evt.GetEventObject() |
125 | pos = btn.ClientToScreen( (0,0) ) | |
126 | sz = btn.GetSize() | |
127 | win.Position(pos, (0, sz.height)) | |
128 | ||
a57d56d6 | 129 | win.Popup() |
c0c84fa0 RD |
130 | |
131 | ||
25e92d2d RD |
132 | def OnShowPopupListbox(self, evt): |
133 | win = TestPopupWithListbox(self, wxNO_BORDER, self.log) | |
134 | ||
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) ) | |
139 | sz = btn.GetSize() | |
140 | win.Position(pos, (0, sz.height)) | |
141 | ||
142 | win.Show(true) | |
143 | ||
144 | class TestPopupWithListbox(wxPopupWindow): | |
145 | def __init__(self, parent, style, log): | |
146 | wxPopupWindow.__init__(self, parent, style) | |
147 | import keyword | |
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()) | |
152 | self.lb.SetFocus() | |
153 | EVT_LEFT_DOWN(self.lb, self.OnLeft) | |
154 | EVT_LISTBOX(self, -1, self.OnListBox) | |
155 | ||
156 | def OnLeft(self, evt): | |
157 | print "OnLeft", evt.GetEventObject() | |
158 | evt.Skip() | |
159 | def OnListBox(self, evt): | |
160 | print "OnListBox", evt.GetEventObject() | |
161 | evt.Skip() | |
2d3a90ce | 162 | |
2d3a90ce | 163 | |
0122b7e3 RD |
164 | |
165 | #--------------------------------------------------------------------------- | |
166 | ||
167 | def runTest(frame, nb, log): | |
eb0f373c RD |
168 | if havePopupWindow: |
169 | win = TestPanel(nb, log) | |
170 | return win | |
171 | else: | |
172 | dlg = wxMessageDialog(frame, 'wxPopupWindow is not available on this platform.', | |
173 | 'Sorry', wxOK | wxICON_INFORMATION) | |
174 | dlg.ShowModal() | |
175 | dlg.Destroy() | |
0122b7e3 RD |
176 | |
177 | #--------------------------------------------------------------------------- | |
178 | ||
179 | ||
180 | ||
181 | ||
182 | overview = """\ | |
183 | """ |