Ah I think I get it. I'm onto a different problem right now, but I'll try these out and see what happens when I get a chance. Many thanks!
···
----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: wxPython-users@lists.wxwidgets.org
Sent: Thursday, November 8, 2007 9:32:44 AM (GMT-0800) America/Tijuana
Subject: Re: [wxPython-users] Key events and wx.AUI?
Simone wrote:
Patrick Van Pelt ha scritto:
Okay, here's a sample of this problem. When you right-click in the
empty space below the text field, you get a response in the
textfield. But when you just left click, or press a key, nothing
happens, even though they are bound to functions. Oddly, in my app,
it does register left clicks, but not in this sample, and I don't see
anything different. But the keydown doesn't work in either version.
I'm sure its something simple and obvious, but I can't see it.You can solve the problem with the left click by binding the event in
this way:self.window.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
Why? The answer is on the wiki:
self.Bind vs. self.button.Bind - wxPyWiki
For the key down event, I don't know how to solve.
It's a very similar problem, with an additional twist. First you need
to use self.window.Bind(...) in order to catch the key events sent to
self.window. (Just using self.Bind(...) means you want to catch the key
events sent to self.) The twist is that since you are also catching
self.window's EVT_LEFT_DOWN then you also need to explicitly set the
focus in that handler, because you are overriding the default handler
which normally does it. Otherwise the focus stays in the textctrl.
Here is the modified sample:
import wx
import wx.aui
#---------------------------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(400, 400))
self._mgr = wx.aui.AuiManager(self)
self.panel1 = TestPanel(self)
self._mgr.AddPane(self.panel1, wx.CENTER, 'Pane Number One')
self._mgr.Update()
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.text = wx.TextCtrl(self)
self.window = wx.ScrolledWindow(self)
self.window.SetBackgroundColour('light blue')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.text, 0, wx.EXPAND)
sizer.Add(self.window, 1, wx.EXPAND)
self.SetSizer(sizer)
self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu, self.window)
self.window.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
self.window.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def OnContextMenu(self, evt):
self.text.SetValue("I just right-clicked")
def OnLeftClick(self, evt):
self.text.SetValue("I just left-clicked")
self.window.SetFocus()
def OnKeyDown(self, evt):
self.text.SetValue("I pressed a key")
#---------------------------------------------------------------------------
import wx.lib.mixins.inspection
app = wx.lib.mixins.inspection.InspectableApp(False)
frame = MyFrame()
frame.Show(True)
app.MainLoop()
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
_____________________________________________________________________
The information contained in this message and its attachments is
confidential and proprietary to LAIKA, Inc. By opening this email
or any of its attachments, you agree to keep all such information
confidential and not to use, distribute, disclose or copy any part
of such information without the prior written consent of LAIKA,
Inc. If you are not the intended recipient of this message, any use,
distribution, disclosure or copying of such information is prohibited.
If received in error, please contact the sender.