Is that a conscious design decision or did to just turn out that way? I ask
because the way it is described in the demo (I couldn't find it in the docs)
makes it sound like it was designed for implementing popup menus and the
like, which is currently impossible.
Anyhow, On to the "use wxPopupWindow and handle the transient part myself"
idea. I've been playing around with ways of doing this and I've not got
anywhere. In my experiments with using KILL_FOCUS and SET_FOCUS it seems
that the children of the wx.PopupWindow are refusing to take the focus (See
sample code below). Am I missing something or do I need to go up another
level and use a undecorated wx.Frame instead?
Any advice on how to implement this would be gratefully received. As
background, I am trying to match the behaviour of a PopupMenu but with menu
items I can place and size myself (I'm writing a touch-screen application so
big targets are important). Sudden thought: Would something using
CaptureMouse work. I'd want the captured mouse click to dismiss the window
and then be passed onto whatever would have received the click had the mouse
not been captured.
Cheers,
Rich
import wx
class MyPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
moreButton = wx.Button(self,-1,"Open", size = (120,20))
wx.EVT_BUTTON(self,moreButton.GetId(),self.OnOpen)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(moreButton,1,wx.EXPAND)
self.SetSizerAndFit(sizer)
def OnOpen(self, event):
otherPanel = wx.PopupWindow(self,wx.RAISED_BORDER)
otherPanel.SetSize(self.GetSize())
btn = event.GetEventObject()
sz = btn.GetSize()
otherPanel.Position(self.ClientToScreen((0,0)),(0, sz.height))
buttonA = wx.Button(otherPanel,-1,"A")
buttonB = wx.Button(otherPanel,-1,"B")
buttonC = wx.Button(otherPanel,-1,"C")
wx.EVT_BUTTON(self,buttonA.GetId(),self.OnButton)
wx.EVT_BUTTON(self,buttonB.GetId(),self.OnButton)
wx.EVT_BUTTON(self,buttonC.GetId(),self.OnButton)
wx.EVT_KILL_FOCUS(otherPanel,self.OnKillFocus)
wx.EVT_KILL_FOCUS(buttonA,self.OnKillFocus)
wx.EVT_KILL_FOCUS(buttonB,self.OnKillFocus)
wx.EVT_KILL_FOCUS(buttonC,self.OnKillFocus)
wx.EVT_SET_FOCUS(otherPanel,self.OnSetFocus)
wx.EVT_SET_FOCUS(buttonA,self.OnSetFocus)
wx.EVT_SET_FOCUS(buttonB,self.OnSetFocus)
wx.EVT_SET_FOCUS(buttonC,self.OnSetFocus)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(buttonA,1,wx.EXPAND)
sizer.Add(buttonB,1,wx.EXPAND)
sizer.Add(buttonC,1,wx.EXPAND)
otherPanel.SetSizer(sizer)
otherPanel.Layout()
otherPanel.Show()
otherPanel.SetFocus()
buttonA.SetFocus()
print "Focused is:",wx.Window_FindFocus().GetLabel()
def OnButton(self, event):
print event.GetEventObject().GetLabel()
def OnKillFocus(self, event):
print 'Kill', event.GetEventObject().GetLabel()
def OnSetFocus(self, event):
print 'Set', event.GetEventObject().GetLabel()
def test():
app = wx.PySimpleApp()
frame = wx.Frame(None,-1,"PopupWindow Bug")
basket = MyPanel(frame,-1)
frame.Fit()
frame.Show(True)
app.MainLoop()
if __name__ == "__main__":
test()
------- Important Disclaimer follows -------
The information in this email and any attachments is confidential and is
solely for the attention of the addressee. It must not be disclosed to any
third party without our prior authority. Any figures or financial data are
for informational purposes only and are not intended as an offer for
purchase or sale of any security. If you are not the intended recipient,
please telephone +44 (20) 7594 4000 immediately.
···
-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]Richard Cooper wrote:
> Hi all,
>
> I'm having a problem with wxPopupTransientWindow closing
prematurely. In the
> example I've provided below clicking on the open button opens a
> wxPopupTransientWindow with 3 buttons in it. If I try to
click buttons B or
> C then the wxPopupTransientWindow disappears without the
EVT_BUTTON handler
> being run.wxPopupTransientWindow will be dismissed if the window, or it's first
child if it has one, loses the focus. If you need more than
one child
you're probably better off usign a wxPopupWindow directly and doing
something else about the focus and/or clicking the mouse
outside the window.