]>
Commit | Line | Data |
---|---|---|
0122b7e3 RD |
1 | from wxPython.wx import * |
2 | ||
3 | #--------------------------------------------------------------------------- | |
4 | ||
5 | class TestPopup(wxPopupWindow): | |
c0c84fa0 | 6 | """Adds a bit of text and mouse movement to the wxPopupWindow""" |
0122b7e3 RD |
7 | def __init__(self, parent, style): |
8 | wxPopupWindow.__init__(self, parent, style) | |
c0c84fa0 RD |
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) ) | |
0122b7e3 RD |
25 | |
26 | EVT_LEFT_DOWN(self, self.OnMouseLeftDown) | |
27 | EVT_MOTION(self, self.OnMouseMotion) | |
28 | EVT_LEFT_UP(self, self.OnMouseLeftUp) | |
c0c84fa0 RD |
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) | |
0122b7e3 RD |
34 | |
35 | def OnMouseLeftDown(self, evt): | |
c0c84fa0 | 36 | self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition()) |
f0db4f38 | 37 | self.wPos = self.GetPosition() |
0122b7e3 RD |
38 | self.CaptureMouse() |
39 | ||
40 | def OnMouseMotion(self, evt): | |
c0c84fa0 RD |
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) | |
0122b7e3 RD |
46 | |
47 | def OnMouseLeftUp(self, evt): | |
48 | self.ReleaseMouse() | |
c0c84fa0 | 49 | |
c0c84fa0 RD |
50 | def OnRightUp(self, evt): |
51 | self.Show(false) | |
52 | self.Destroy() | |
53 | ||
54 | ||
55 | class TestTransientPopup(wxPopupTransientWindow): | |
56 | """Adds a bit of text and mouse movement to the wxPopupWindow""" | |
a57d56d6 | 57 | def __init__(self, parent, style, log): |
c0c84fa0 | 58 | wxPopupTransientWindow.__init__(self, parent, style) |
a57d56d6 RD |
59 | self.log = log |
60 | panel = wxPanel(self, -1) | |
61 | panel.SetBackgroundColour("#FFB6C1") | |
62 | st = wxStaticText(panel, -1, | |
c0c84fa0 RD |
63 | "wxPopupTransientWindow is a\n" |
64 | "wxPopupWindow which disappears\n" | |
65 | "automatically when the user\n" | |
66 | "clicks the mouse outside it or if it\n" | |
67 | "loses focus in any other way." | |
68 | , | |
69 | pos=(10,10)) | |
70 | sz = st.GetBestSize() | |
a57d56d6 RD |
71 | panel.SetSize( (sz.width+20, sz.height+20) ) |
72 | self.SetSize(panel.GetSize()) | |
0122b7e3 | 73 | |
a57d56d6 RD |
74 | def ProcessLeftDown(self, evt): |
75 | self.log.write("ProcessLeftDown\n") | |
76 | return false | |
77 | ||
78 | def OnDismiss(self): | |
79 | self.log.write("OnDismiss\n") | |
80 | ||
0122b7e3 | 81 | |
2d3a90ce | 82 | |
0122b7e3 RD |
83 | class TestPanel(wxPanel): |
84 | def __init__(self, parent, log): | |
85 | wxPanel.__init__(self, parent, -1) | |
86 | self.log = log | |
87 | ||
c0c84fa0 | 88 | b = wxButton(self, -1, "Show wxPopupWindow", (25, 50)) |
0122b7e3 RD |
89 | EVT_BUTTON(self, b.GetId(), self.OnShowPopup) |
90 | ||
c0c84fa0 RD |
91 | b = wxButton(self, -1, "Show wxPopupTransientWindow", (25, 95)) |
92 | EVT_BUTTON(self, b.GetId(), self.OnShowPopupTransient) | |
93 | ||
25e92d2d RD |
94 | if 0: |
95 | b = wxButton(self, -1, "Show wxPopupWindow with listbox", (25, 140)) | |
96 | EVT_BUTTON(self, b.GetId(), self.OnShowPopupListbox) | |
2d3a90ce | 97 | |
0122b7e3 RD |
98 | |
99 | def OnShowPopup(self, evt): | |
100 | win = TestPopup(self, wxSIMPLE_BORDER) | |
c0c84fa0 RD |
101 | |
102 | # Show the popup right below or above the button | |
103 | # depending on available screen space... | |
104 | btn = evt.GetEventObject() | |
105 | pos = btn.ClientToScreen( (0,0) ) | |
106 | sz = btn.GetSize() | |
107 | win.Position(pos, (0, sz.height)) | |
108 | ||
0122b7e3 RD |
109 | win.Show(true) |
110 | ||
111 | ||
c0c84fa0 | 112 | def OnShowPopupTransient(self, evt): |
a57d56d6 | 113 | win = TestTransientPopup(self, wxSIMPLE_BORDER, self.log) |
c0c84fa0 | 114 | |
a57d56d6 RD |
115 | # Show the popup right below or above the button |
116 | # depending on available screen space... | |
c0c84fa0 RD |
117 | btn = evt.GetEventObject() |
118 | pos = btn.ClientToScreen( (0,0) ) | |
119 | sz = btn.GetSize() | |
120 | win.Position(pos, (0, sz.height)) | |
121 | ||
a57d56d6 | 122 | win.Popup() |
c0c84fa0 RD |
123 | |
124 | ||
25e92d2d RD |
125 | def OnShowPopupListbox(self, evt): |
126 | win = TestPopupWithListbox(self, wxNO_BORDER, self.log) | |
127 | ||
128 | # Show the popup right below or above the button | |
129 | # depending on available screen space... | |
130 | btn = evt.GetEventObject() | |
131 | pos = btn.ClientToScreen( (0,0) ) | |
132 | sz = btn.GetSize() | |
133 | win.Position(pos, (0, sz.height)) | |
134 | ||
135 | win.Show(true) | |
136 | ||
137 | class TestPopupWithListbox(wxPopupWindow): | |
138 | def __init__(self, parent, style, log): | |
139 | wxPopupWindow.__init__(self, parent, style) | |
140 | import keyword | |
141 | self.lb = wxListBox(self, -1, choices = keyword.kwlist) | |
142 | #sz = self.lb.GetBestSize() | |
143 | self.SetSize((150, 75)) #sz) | |
144 | self.lb.SetSize(self.GetClientSize()) | |
145 | self.lb.SetFocus() | |
146 | EVT_LEFT_DOWN(self.lb, self.OnLeft) | |
147 | EVT_LISTBOX(self, -1, self.OnListBox) | |
148 | ||
149 | def OnLeft(self, evt): | |
150 | print "OnLeft", evt.GetEventObject() | |
151 | evt.Skip() | |
152 | def OnListBox(self, evt): | |
153 | print "OnListBox", evt.GetEventObject() | |
154 | evt.Skip() | |
2d3a90ce | 155 | |
2d3a90ce | 156 | |
0122b7e3 RD |
157 | |
158 | #--------------------------------------------------------------------------- | |
159 | ||
160 | def runTest(frame, nb, log): | |
161 | win = TestPanel(nb, log) | |
162 | return win | |
163 | ||
164 | #--------------------------------------------------------------------------- | |
165 | ||
166 | ||
167 | ||
168 | ||
169 | overview = """\ | |
170 | """ |