[wxPython-users] Capturing a mouse click on the tab of an already
selected notebook page
Robin Dunn
robin at alldunn.com
Wed Sep 26 09:53:10 PDT 2007
Bob Klahn wrote:
> At 08:03 PM 9/25/2007, you wrote:
>> At 07:52 PM 9/25/2007, you wrote:
>>> Hi Bob,
>>>
>>> On 9/26/07, Bob Klahn wrote:
>>> > Still no luck, Robin. My main-frame initialization code now looks
>>> like this:
>>> >
>>> > self.nb1.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown1)
>>> > self.nb2.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown2)
>>> >
>>> > def OnLeftDown1(self, evt):
>>> > wx.CallAfter(self.SetDiagramFocus())
>>> > evt.Skip()
>>> >
>>> > def OnLeftDown2(self, evt):
>>> > wx.CallAfter(self.SetDiagramFocus())
>>> > evt.Skip()
>>>
>>> You shouldn't use brackets in the argument method of wx.CallAfter,
>>> this is what the traceback is saying. Try to use the following:
>>>
>>> def OnLeftDown1(self, evt):
>>> wx.CallAfter(self.SetDiagramFocus)
>>> evt.Skip()
>>>
>>> def OnLeftDown2(self, evt):
>>> wx.CallAfter(self.SetDiagramFocus)
>>> evt.Skip()
>>>
>>> Notice the missing parenthesis () in the wx.CallAfter arguments :-D :-D
>>>
>>> Andrea.
>>
>> Aha! Wunderbar! It works! Bless you.
>>
>> Bob
>
> One more comment. A code snippet:
>
> self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged1)
> # if self.nb1.GetRowCount() > 0:
> # self.nb1.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
> self.OnPageChanged1)
> # self.nb2.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
> self.OnPageChanged2)
>
> The above binding to the main frame rather than to either notebook
> works. But when I used the notebook-specific bindings instead, the old
> problem returns, i.e., focus remains on the notebook tab.
It's possible that the PAGE_CHANGED event is not being sent to the
notebooks themselves, only to the parent. (Although that should
probably be considered a bug.) Try this instead:
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged1,
self.nb1)
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged2,
self.nb2)
For an explanation of the differences please read:
http://wiki.wxpython.org/self.Bind_vs._self.button.Bind
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list