]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxPopupWindow.py
1 from wxPython
.wx
import *
3 #---------------------------------------------------------------------------
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"
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."
24 self
.SetSize( (sz
.width
+20, sz
.height
+20) )
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
)
35 def OnMouseLeftDown(self
, evt
):
36 self
.ldPos
= evt
.GetEventObject().ClientToScreen(evt
.GetPosition())
37 if wxPlatform
== "__WXMSW__": # this is weird...
38 self
.wPos
= self
.GetParent().ClientToScreen(self
.GetPosition())
40 self
.wPos
= self
.GetPosition()
43 def OnMouseMotion(self
, evt
):
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
))
50 def OnMouseLeftUp(self
, evt
):
53 def OnRightUp(self
, evt
):
58 class TestTransientPopup(wxPopupTransientWindow
):
59 """Adds a bit of text and mouse movement to the wxPopupWindow"""
60 def __init__(self
, parent
, style
, log
):
61 wxPopupTransientWindow
.__init
__(self
, parent
, style
)
63 panel
= wxPanel(self
, -1)
64 panel
.SetBackgroundColour("#FFB6C1")
65 st
= wxStaticText(panel
, -1,
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."
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) )
82 def ProcessLeftDown(self
, evt
):
83 self
.log
.write("ProcessLeftDown\n")
87 self
.log
.write("OnDismiss\n")
90 class TestPanel(wxPanel
):
91 def __init__(self
, parent
, log
):
92 wxPanel
.__init
__(self
, parent
, -1)
95 b
= wxButton(self
, -1, "Show wxPopupWindow", (25, 50))
96 EVT_BUTTON(self
, b
.GetId(), self
.OnShowPopup
)
98 b
= wxButton(self
, -1, "Show wxPopupTransientWindow", (25, 95))
99 EVT_BUTTON(self
, b
.GetId(), self
.OnShowPopupTransient
)
102 def OnShowPopup(self
, evt
):
103 win
= TestPopup(self
, wxSIMPLE_BORDER
)
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) )
110 win
.Position(pos
, (0, sz
.height
))
115 def OnShowPopupTransient(self
, evt
):
116 win
= TestTransientPopup(self
, wxSIMPLE_BORDER
, self
.log
)
118 # Show the popup right below or above the button
119 # depending on available screen space...
120 btn
= evt
.GetEventObject()
121 pos
= btn
.ClientToScreen( (0,0) )
123 win
.Position(pos
, (0, sz
.height
))
129 #---------------------------------------------------------------------------
131 def runTest(frame
, nb
, log
):
132 win
= TestPanel(nb
, log
)
135 #---------------------------------------------------------------------------