[wxPython-users] Capturing a mouse click on the tab of an already selected notebook page

Bob Klahn bobstones at comcast.net
Wed Sep 26 10:29:55 PDT 2007


At 12:53 PM 9/26/2007, Robin Dunn wrote:
>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!

Ah, that's much better.  Thank you.  Having to leave off the notebook 
specification to make my code work bothered me.

Re "that should probably be considered a bug," yes, it certainly 
seems so to me.  Worthy of a SourceForge bug report, imo.

Bob






More information about the wxpython-users mailing list