]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupWindow.py
Various other tweaks and updates
[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.GetParent().ClientToScreen(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
51 def OnRightUp(self, evt):
52 self.Show(false)
53 self.Destroy()
54
55
56 class TestTransientPopup(wxPopupTransientWindow):
57 """Adds a bit of text and mouse movement to the wxPopupWindow"""
58 def __init__(self, parent, style):
59 wxPopupTransientWindow.__init__(self, parent, style)
60 self.SetBackgroundColour("#FFB6C1")
61 st = wxStaticText(self, -1,
62 "wxPopupTransientWindow is a\n"
63 "wxPopupWindow which disappears\n"
64 "automatically when the user\n"
65 "clicks the mouse outside it or if it\n"
66 "loses focus in any other way."
67 ,
68 pos=(10,10))
69 sz = st.GetBestSize()
70 self.SetSize( (sz.width+20, sz.height+20) )
71
72
73
74 class TestPanel(wxPanel):
75 def __init__(self, parent, log):
76 wxPanel.__init__(self, parent, -1)
77 self.log = log
78
79 b = wxButton(self, -1, "Show wxPopupWindow", (25, 50))
80 EVT_BUTTON(self, b.GetId(), self.OnShowPopup)
81
82 b = wxButton(self, -1, "Show wxPopupTransientWindow", (25, 95))
83 EVT_BUTTON(self, b.GetId(), self.OnShowPopupTransient)
84
85
86 def OnShowPopup(self, evt):
87 win = TestPopup(self, wxSIMPLE_BORDER)
88
89 # Show the popup right below or above the button
90 # depending on available screen space...
91 btn = evt.GetEventObject()
92 pos = btn.ClientToScreen( (0,0) )
93 sz = btn.GetSize()
94 win.Position(pos, (0, sz.height))
95
96 win.Show(true)
97
98
99 def OnShowPopupTransient(self, evt):
100 win = TestTransientPopup(self, wxSIMPLE_BORDER)
101
102 # show the popup right below or above the button
103 btn = evt.GetEventObject()
104 pos = btn.ClientToScreen( (0,0) )
105 sz = btn.GetSize()
106 win.Position(pos, (0, sz.height))
107
108 win.Popup(btn)
109
110
111
112 #---------------------------------------------------------------------------
113
114 def runTest(frame, nb, log):
115 win = TestPanel(nb, log)
116 return win
117
118 #---------------------------------------------------------------------------
119
120
121
122
123 overview = """\
124 """