2003-12-08 20:23:28 -05:00
|
|
|
#
|
|
|
|
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Some issues with the listbox example; I tried correcting
|
|
|
|
# it but it's still not working the way it should. Commented
|
2004-01-12 22:17:17 -05:00
|
|
|
# out for now, as I found it.
|
2003-12-08 20:23:28 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
import wx
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2002-08-13 19:59:08 -04:00
|
|
|
havePopupWindow = 1
|
2004-02-23 16:23:26 -05:00
|
|
|
if wx.Platform == '__WXMAC__':
|
2002-08-13 19:59:08 -04:00
|
|
|
havePopupWindow = 0
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.PopupWindow = wx.PopupTransientWindow = wx.Window
|
2002-08-13 19:59:08 -04:00
|
|
|
|
2001-10-12 19:26:38 -04:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPopup(wx.PopupWindow):
|
2004-01-12 22:17:17 -05:00
|
|
|
"""Adds a bit of text and mouse movement to the wx.PopupWindow"""
|
2001-10-12 19:26:38 -04:00
|
|
|
def __init__(self, parent, style):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.PopupWindow.__init__(self, parent, style)
|
2001-11-12 22:16:03 -05:00
|
|
|
self.SetBackgroundColour("CADET BLUE")
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
st = wx.StaticText(self, -1,
|
2001-11-12 22:16:03 -05:00
|
|
|
"This is a special kind of top level\n"
|
|
|
|
"window that can be used for\n"
|
|
|
|
"popup menus, combobox popups\n"
|
|
|
|
"and such.\n\n"
|
|
|
|
"Try positioning the demo near\n"
|
|
|
|
"the bottom of the screen and \n"
|
|
|
|
"hit the button again.\n\n"
|
|
|
|
"In this demo this window can\n"
|
|
|
|
"be dragged with the left button\n"
|
|
|
|
"and closed with the right."
|
|
|
|
,
|
|
|
|
pos=(10,10))
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2001-11-12 22:16:03 -05:00
|
|
|
sz = st.GetBestSize()
|
|
|
|
self.SetSize( (sz.width+20, sz.height+20) )
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
|
|
|
|
self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
|
|
|
|
self.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
|
|
|
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
|
|
|
|
|
|
|
st.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
|
|
|
|
st.Bind(wx.EVT_MOTION, self.OnMouseMotion)
|
|
|
|
st.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
|
|
|
|
st.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2004-06-28 22:05:36 -04:00
|
|
|
wx.CallAfter(self.Refresh)
|
|
|
|
|
2001-10-12 19:26:38 -04:00
|
|
|
def OnMouseLeftDown(self, evt):
|
2004-06-28 22:05:36 -04:00
|
|
|
self.Refresh()
|
2001-11-12 22:16:03 -05:00
|
|
|
self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
|
2003-12-29 18:21:38 -05:00
|
|
|
self.wPos = self.ClientToScreen((0,0))
|
2001-10-12 19:26:38 -04:00
|
|
|
self.CaptureMouse()
|
|
|
|
|
|
|
|
def OnMouseMotion(self, evt):
|
2001-11-12 22:16:03 -05:00
|
|
|
if evt.Dragging() and evt.LeftIsDown():
|
|
|
|
dPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
|
|
|
|
nPos = (self.wPos.x + (dPos.x - self.ldPos.x),
|
|
|
|
self.wPos.y + (dPos.y - self.ldPos.y))
|
|
|
|
self.Move(nPos)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
def OnMouseLeftUp(self, evt):
|
|
|
|
self.ReleaseMouse()
|
2001-11-12 22:16:03 -05:00
|
|
|
|
|
|
|
def OnRightUp(self, evt):
|
2003-03-25 01:35:27 -05:00
|
|
|
self.Show(False)
|
2001-11-12 22:16:03 -05:00
|
|
|
self.Destroy()
|
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestTransientPopup(wx.PopupTransientWindow):
|
2004-01-12 22:17:17 -05:00
|
|
|
"""Adds a bit of text and mouse movement to the wx.PopupWindow"""
|
2001-11-13 01:43:26 -05:00
|
|
|
def __init__(self, parent, style, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.PopupTransientWindow.__init__(self, parent, style)
|
2001-11-13 01:43:26 -05:00
|
|
|
self.log = log
|
2005-04-13 21:17:00 -04:00
|
|
|
self.SetBackgroundColour("#FFB6C1")
|
|
|
|
st = wx.StaticText(self, -1,
|
2004-01-12 22:17:17 -05:00
|
|
|
"wx.PopupTransientWindow is a\n"
|
|
|
|
"wx.PopupWindow which disappears\n"
|
2001-11-12 22:16:03 -05:00
|
|
|
"automatically when the user\n"
|
|
|
|
"clicks the mouse outside it or if it\n"
|
2003-12-11 12:43:05 -05:00
|
|
|
"(or its first child) loses focus in \n"
|
|
|
|
"any other way."
|
2001-11-12 22:16:03 -05:00
|
|
|
,
|
|
|
|
pos=(10,10))
|
|
|
|
sz = st.GetBestSize()
|
2005-04-13 21:17:00 -04:00
|
|
|
self.SetSize( (sz.width+20, sz.height+20) )
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2001-11-13 01:43:26 -05:00
|
|
|
def ProcessLeftDown(self, evt):
|
|
|
|
self.log.write("ProcessLeftDown\n")
|
2003-03-25 01:35:27 -05:00
|
|
|
return False
|
2001-11-13 01:43:26 -05:00
|
|
|
|
|
|
|
def OnDismiss(self):
|
|
|
|
self.log.write("OnDismiss\n")
|
|
|
|
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2002-05-03 19:31:35 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2001-10-12 19:26:38 -04:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2001-10-12 19:26:38 -04:00
|
|
|
self.log = log
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
b = wx.Button(self, -1, "Show wx.PopupWindow", (25, 50))
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowPopup, b)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
b = wx.Button(self, -1, "Show wx.PopupTransientWindow", (25, 95))
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowPopupTransient, b)
|
2001-11-12 22:16:03 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# This isn't working so well, not sure why. Commented out for
|
|
|
|
# now.
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
# b = wx.Button(self, -1, "Show wx.PopupWindow with listbox", (25, 140))
|
2003-12-08 20:23:28 -05:00
|
|
|
# self.Bind(wx.EVT_BUTTON, self.OnShowPopupListbox, b)
|
2002-05-03 19:31:35 -04:00
|
|
|
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
def OnShowPopup(self, evt):
|
2003-12-08 20:23:28 -05:00
|
|
|
win = TestPopup(self, wx.SIMPLE_BORDER)
|
2005-06-11 15:31:44 -04:00
|
|
|
#win = TestPopupWithListbox(self, wx.SIMPLE_BORDER, self.log)
|
2001-11-12 22:16:03 -05:00
|
|
|
|
|
|
|
# Show the popup right below or above the button
|
|
|
|
# depending on available screen space...
|
|
|
|
btn = evt.GetEventObject()
|
|
|
|
pos = btn.ClientToScreen( (0,0) )
|
|
|
|
sz = btn.GetSize()
|
2003-12-08 20:23:28 -05:00
|
|
|
win.Position(pos, (0, sz[1]))
|
2001-11-12 22:16:03 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
win.Show(True)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
|
2001-11-12 22:16:03 -05:00
|
|
|
def OnShowPopupTransient(self, evt):
|
2005-04-13 21:17:00 -04:00
|
|
|
win = TestTransientPopup(self,
|
|
|
|
wx.SIMPLE_BORDER,
|
|
|
|
self.log)
|
2001-11-12 22:16:03 -05:00
|
|
|
|
2001-11-13 01:43:26 -05:00
|
|
|
# Show the popup right below or above the button
|
|
|
|
# depending on available screen space...
|
2001-11-12 22:16:03 -05:00
|
|
|
btn = evt.GetEventObject()
|
|
|
|
pos = btn.ClientToScreen( (0,0) )
|
|
|
|
sz = btn.GetSize()
|
2003-12-08 20:23:28 -05:00
|
|
|
win.Position(pos, (0, sz[1]))
|
2001-11-12 22:16:03 -05:00
|
|
|
|
2001-11-13 01:43:26 -05:00
|
|
|
win.Popup()
|
2001-11-12 22:16:03 -05:00
|
|
|
|
|
|
|
|
2002-05-13 20:06:37 -04:00
|
|
|
def OnShowPopupListbox(self, evt):
|
2003-12-08 20:23:28 -05:00
|
|
|
win = TestPopupWithListbox(self, wx.NO_BORDER, self.log)
|
2002-05-13 20:06:37 -04:00
|
|
|
|
|
|
|
# Show the popup right below or above the button
|
|
|
|
# depending on available screen space...
|
|
|
|
btn = evt.GetEventObject()
|
|
|
|
pos = btn.ClientToScreen( (0,0) )
|
|
|
|
sz = btn.GetSize()
|
2003-12-08 20:23:28 -05:00
|
|
|
win.Position(pos, (0, sz[1]))
|
2002-05-13 20:06:37 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
win.Show(True)
|
2002-05-13 20:06:37 -04:00
|
|
|
|
2005-06-11 15:31:44 -04:00
|
|
|
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
# This class is currently not implemented in the demo. It does not
|
|
|
|
# behave the way it should, so for the time being it's only here
|
|
|
|
# for show. If you figure out how to make it work, please send
|
|
|
|
# a corrected file to Robin!
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPopupWithListbox(wx.PopupWindow):
|
2002-05-13 20:06:37 -04:00
|
|
|
def __init__(self, parent, style, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.PopupWindow.__init__(self, parent, style)
|
2005-06-11 15:31:44 -04:00
|
|
|
self.log = log
|
2002-05-13 20:06:37 -04:00
|
|
|
import keyword
|
2003-12-08 20:23:28 -05:00
|
|
|
self.lb = wx.ListBox(self, -1, choices = keyword.kwlist)
|
2002-05-13 20:06:37 -04:00
|
|
|
#sz = self.lb.GetBestSize()
|
|
|
|
self.SetSize((150, 75)) #sz)
|
|
|
|
self.lb.SetSize(self.GetClientSize())
|
|
|
|
self.lb.SetFocus()
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_LISTBOX, self.OnListBox)
|
2005-06-11 15:31:44 -04:00
|
|
|
self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListBoxDClick)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2002-05-13 20:06:37 -04:00
|
|
|
def OnListBox(self, evt):
|
2003-12-08 20:23:28 -05:00
|
|
|
obj = evt.GetEventObject()
|
2005-06-11 15:31:44 -04:00
|
|
|
self.log.write("OnListBox: %s\n" % obj)
|
|
|
|
self.log.write('Selected: %s\n' % obj.GetString(evt.GetInt()))
|
2002-05-13 20:06:37 -04:00
|
|
|
evt.Skip()
|
2002-05-03 19:31:35 -04:00
|
|
|
|
2005-06-11 15:31:44 -04:00
|
|
|
def OnListBoxDClick(self, evt):
|
|
|
|
self.Hide()
|
|
|
|
self.Destroy()
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2002-08-13 19:59:08 -04:00
|
|
|
if havePopupWindow:
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
else:
|
2004-11-01 14:39:09 -05:00
|
|
|
from Main import MessagePanel
|
|
|
|
win = MessagePanel(nb, 'wx.PopupWindow is not available on this platform.',
|
|
|
|
'Sorry', wx.ICON_WARNING)
|
|
|
|
return win
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
|
|
|
"""
|
2002-08-26 20:57:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2002-08-26 20:57:19 -04:00
|
|
|
|