Hello again,
I'm still just a wxpython novice, but I've been playing around with
PopupWindows, and I've run into something I could use some help with.
When I put a TextCtrl inside a PopupWindow of any type, it seems
incapable of receiving its own events. I cannot even seem to put focus
on the TextCtrl, and normal Char events don't seem to trigger.
Additionally, Selections do not show up, but they do get processed (you
can select text, then right click and select Copy/Paste and it works
just fine). So I'm wondering, where are the events being diverted to,
and what (if anything) can I do to restore 'Normal' event possessing
within the popup window?
I've included a little example App that shows this (I threw in the
WxPython Popup Demo's dragging code just to see that some event
possessing is still going on). Any Advice?
···
#-----------------------------------------------------------------------
--------
import wx
class TestPopup(wx.PopupWindow):
def __init__(self, parent, style):
wx.PopupWindow.__init__(self, parent, style)
tc = wx.TextCtrl(self, -1,
"It shone, pale as bone \n"
"As I stood there alone\n"
"And I thought to myself how the moon,\n"
"That night, cast its light\n"
"On my heart's true delight,\n"
"And the reef where her body was strewn. \n"
,
pos=(10,10), size=(250, 100),
style=wx.TE_MULTILINE)
self.SetSize( (280, 130) )
self.wPos = self.ClientToScreen((0,0))
self.ldPos = self.ClientToScreen((0,0))
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)
def OnMouseLeftDown(self, evt):
self.Refresh()
self.ldPos =
evt.GetEventObject().ClientToScreen(evt.GetPosition())
self.wPos = self.ClientToScreen((0,0))
self.CaptureMouse()
def OnMouseMotion(self, evt):
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)
def OnMouseLeftUp(self, evt):
try:
self.ReleaseMouse()
except Exception:
pass
def OnRightUp(self, evt):
self.Show(False)
self.Destroy()
class TestPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "POP!", (25, 50))
self.Bind(wx.EVT_BUTTON, self.OnShowPopup, b)
def OnShowPopup(self, evt):
win = TestPopup(self, wx.SIMPLE_BORDER)
btn = evt.GetEventObject()
pos = btn.ClientToScreen( (0,0) )
sz = btn.GetSize()
win.Position(pos, (0, sz[1]))
win.Show(True)
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Test Popup")
self.pane = TestPanel(self)
class App(wx.App):
def OnInit(self):
self.frame = Frame(parent = None)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()
#-----------------------------------------------------------------------
--------
-Greg