]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupWindow.py
fixed crashes in GtkText when it was refreshed from inside wxYield
[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 ## #sz = self.lb.GetBestSize()
61 ## self.SetSize((150, 75)) #sz)
62 ## self.lb.SetSize(self.GetClientSize())
63 ## self.lb.SetFocus()
64 ## EVT_LEFT_DOWN(self.lb, self.OnLeft)
65 ## EVT_LISTBOX(self, -1, self.OnListBox)
66
67 ## def OnLeft(self, evt):
68 ## print "OnLeft", evt.GetEventObject()
69 ## evt.Skip()
70 ## def OnListBox(self, evt):
71 ## print "OnListBox", evt.GetEventObject()
72 ## evt.Skip()
73
74
75
76 class TestTransientPopup(wxPopupTransientWindow):
77 """Adds a bit of text and mouse movement to the wxPopupWindow"""
78 def __init__(self, parent, style, log):
79 wxPopupTransientWindow.__init__(self, parent, style)
80 self.log = log
81 panel = wxPanel(self, -1)
82 panel.SetBackgroundColour("#FFB6C1")
83 st = wxStaticText(panel, -1,
84 "wxPopupTransientWindow is a\n"
85 "wxPopupWindow which disappears\n"
86 "automatically when the user\n"
87 "clicks the mouse outside it or if it\n"
88 "loses focus in any other way."
89 ,
90 pos=(10,10))
91 sz = st.GetBestSize()
92 panel.SetSize( (sz.width+20, sz.height+20) )
93 self.SetSize(panel.GetSize())
94
95 def ProcessLeftDown(self, evt):
96 self.log.write("ProcessLeftDown\n")
97 return false
98
99 def OnDismiss(self):
100 self.log.write("OnDismiss\n")
101
102
103
104 class TestPanel(wxPanel):
105 def __init__(self, parent, log):
106 wxPanel.__init__(self, parent, -1)
107 self.log = log
108
109 b = wxButton(self, -1, "Show wxPopupWindow", (25, 50))
110 EVT_BUTTON(self, b.GetId(), self.OnShowPopup)
111
112 b = wxButton(self, -1, "Show wxPopupTransientWindow", (25, 95))
113 EVT_BUTTON(self, b.GetId(), self.OnShowPopupTransient)
114
115 b = wxButton(self, -1, "Show wxPopupWindow with listbox", (25, 140))
116 EVT_BUTTON(self, b.GetId(), self.OnShowPopupListbox)
117
118
119 def OnShowPopup(self, evt):
120 win = TestPopup(self, wxSIMPLE_BORDER)
121
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) )
126 sz = btn.GetSize()
127 win.Position(pos, (0, sz.height))
128
129 win.Show(true)
130
131
132 def OnShowPopupTransient(self, evt):
133 win = TestTransientPopup(self, wxSIMPLE_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.Popup()
143
144
145 ## def OnShowPopupListbox(self, evt):
146 ## win = TestPopupWithListbox(self, wxNO_BORDER, self.log)
147
148 ## # Show the popup right below or above the button
149 ## # depending on available screen space...
150 ## btn = evt.GetEventObject()
151 ## pos = btn.ClientToScreen( (0,0) )
152 ## sz = btn.GetSize()
153 ## win.Position(pos, (0, sz.height))
154
155 ## win.Show(true)
156
157 #---------------------------------------------------------------------------
158
159 def runTest(frame, nb, log):
160 win = TestPanel(nb, log)
161 return win
162
163 #---------------------------------------------------------------------------
164
165
166
167
168 overview = """\
169 """