]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxPopupWindow.py
wxComboBox does not derive from wxChoice in wxGTK so it can't in
[wxWidgets.git] / wxPython / demo / wxPopupWindow.py
CommitLineData
0122b7e3
RD
1from wxPython.wx import *
2
3#---------------------------------------------------------------------------
4
5class 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
RD
37## if wxPlatform == "__WXMSW__": # this is weird...
38## self.wPos = self.GetParent().ClientToScreen(self.GetPosition())
39## else:
40 self.wPos = self.GetPosition()
0122b7e3
RD
41 self.CaptureMouse()
42
43 def OnMouseMotion(self, evt):
c0c84fa0
RD
44 if evt.Dragging() and evt.LeftIsDown():
45 dPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
46 nPos = (self.wPos.x + (dPos.x - self.ldPos.x),
47 self.wPos.y + (dPos.y - self.ldPos.y))
48 self.Move(nPos)
0122b7e3
RD
49
50 def OnMouseLeftUp(self, evt):
51 self.ReleaseMouse()
c0c84fa0 52
c0c84fa0
RD
53 def OnRightUp(self, evt):
54 self.Show(false)
55 self.Destroy()
56
57
58class TestTransientPopup(wxPopupTransientWindow):
59 """Adds a bit of text and mouse movement to the wxPopupWindow"""
a57d56d6 60 def __init__(self, parent, style, log):
c0c84fa0 61 wxPopupTransientWindow.__init__(self, parent, style)
a57d56d6
RD
62 self.log = log
63 panel = wxPanel(self, -1)
64 panel.SetBackgroundColour("#FFB6C1")
65 st = wxStaticText(panel, -1,
c0c84fa0
RD
66 "wxPopupTransientWindow is a\n"
67 "wxPopupWindow which disappears\n"
68 "automatically when the user\n"
69 "clicks the mouse outside it or if it\n"
70 "loses focus in any other way."
71 ,
72 pos=(10,10))
73 sz = st.GetBestSize()
a57d56d6
RD
74 panel.SetSize( (sz.width+20, sz.height+20) )
75 self.SetSize(panel.GetSize())
76## self.SetBackgroundColour("#FFB6C1")
77## b = wxButton(self, -1, "this is a Button", (10,10))
78## sz = b.GetBestSize()
79## self.SetSize( (sz.width+20, sz.height+20) )
0122b7e3
RD
80
81
a57d56d6
RD
82 def ProcessLeftDown(self, evt):
83 self.log.write("ProcessLeftDown\n")
84 return false
85
86 def OnDismiss(self):
87 self.log.write("OnDismiss\n")
88
0122b7e3
RD
89
90class 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
0122b7e3
RD
101
102 def OnShowPopup(self, evt):
103 win = TestPopup(self, wxSIMPLE_BORDER)
c0c84fa0
RD
104
105 # Show the popup right below or above the button
106 # depending on available screen space...
107 btn = evt.GetEventObject()
108 pos = btn.ClientToScreen( (0,0) )
109 sz = btn.GetSize()
110 win.Position(pos, (0, sz.height))
111
0122b7e3
RD
112 win.Show(true)
113
114
c0c84fa0 115 def OnShowPopupTransient(self, evt):
a57d56d6 116 win = TestTransientPopup(self, wxSIMPLE_BORDER, self.log)
c0c84fa0 117
a57d56d6
RD
118 # Show the popup right below or above the button
119 # depending on available screen space...
c0c84fa0
RD
120 btn = evt.GetEventObject()
121 pos = btn.ClientToScreen( (0,0) )
122 sz = btn.GetSize()
123 win.Position(pos, (0, sz.height))
124
a57d56d6 125 win.Popup()
c0c84fa0
RD
126
127
0122b7e3
RD
128
129#---------------------------------------------------------------------------
130
131def runTest(frame, nb, log):
132 win = TestPanel(nb, log)
133 return win
134
135#---------------------------------------------------------------------------
136
137
138
139
140overview = """\
141"""