[wxPython-users] Capturing a mouse click on the tab of an
already selected notebook page
Bob Klahn
bobstones at comcast.net
Tue Sep 25 16:41:47 PDT 2007
At 12:59 PM 9/25/2007, you wrote:
>Bob Klahn wrote:
>>At 04:01 AM 9/25/2007, Andrea wrote:
>>>Hi Bob,
>>>
>>>On 9/25/07, Bob Klahn wrote:
>>> > How do I do that? It's probably very simple, but the solution
>>> > continues to escape me. I suspect I'll slap my forehead when you all
>>> > clue me in ...
>>> >
>>> > I have a splitter with two notebooks, one notebook on each side
>>> of the sash.
>>> >
>>> > For =one= type of right-notebook page (not for other right-notebook
>>> > page types), the code that responds to a click there should perform
>>> > its particular task =and= set the focus to a panel on the
>>> > corresponding left-notebook page.
>>> >
>>> > I have no trouble making this happen in response to a click anywhere
>>> > =within= the right-notebook page. THE PROBLEM occurs when the =tab=
>>> > of the right-notebook page is clicked.
>>> >
>>> > MY QUESTION: How do I capture a click on the =tab= of an already
>>> > selected notebook page?
>>> >
>>> > (wx.EVT_NOTEBOOK_PAGE_CHANGED (or wx.EVT_NOTEBOOK_PAGE_CHANGING)
>>> > events are of course not triggered.)
>>>
>>>I haven't tried it so I am not sure it will work, but what about
>>>something like:
>>>
>>>yourNotebook.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
>>>
>>>def OnLeftDown(self, event):
>>>
>>> # Do something to the other notebook
>>> event.Skip()
>>>
>>>When the 2 notebook events (wx.EVT_NOTEBOOK_PAGE_CHANGED or
>>>wx.EVT_NOTEBOOK_PAGE_CHANGING) are not triggered, probably the
>>>wx.EVT_LEFT_DOWN is sent.
>>>
>>>Andrea.
>>Thanks! Yes, wx.EVT_LEFT_DOWN is sent. I had already tried this,
>>and =assumed= (we know about that word) it didn't work because of
>>the problem I still have. I must never have put a log statement in
>>the left-down event-triggered code. Shame on me.
>>Regardless, as I just said, I still have a problem ...
>>My main-frame code now looks like this:
>>self.nb2.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown2)
>>def OnLeftDown2(self,event):
>> code-to-set-focus-to-notebook1-panel
>> event.Skip()
>>If I comment out the event-skip line, focus is set to the
>>notebook-1 panel. But when I comment the event.Skip() line back
>>in, that focus is lost.
>>So something further up the event chain is interfering. How can I
>>find out what that is?
>
>Do your focus setting code in method called via wx.CallAfter. The
>default handler will change the active notebook tab and set focus to
>the page window, so you want to do your thing after the default is done.
>
>Also, I'm not sure if you've seen this or not, but wx.Notebook has a
>HitTest method so you can find out which tab was clicked on from the
>position passed in the event object.
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()
def SetDiagramFocus(self):
print 'SetDiagramFocus entered'
< Code to set the focus >
print 'SetDiagramFocus complete'
Now, when I click on the notebook tab, I get this:
SetDiagramFocus entered
SetDiagramFocus complete
Traceback (most recent call last):
File
"C:\Python25\Lib\site-packages\wx2.8-msw-unicode\wx\_core.py", line
14099, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
TypeError: 'NoneType' object is not callable
If I comment out the two bind events, no traceback occurs.
But in all cases, i.e., (a) with the event bindings and with
evt.Skip(), (b) with the the event bindings but without evt.Skip(),
or (c) without the event bindings, the dotted rectangle around the
tab label is still there, focus has not been transferred to the
notebook page's diagram.
What's happening now? I have no idea. :-( I'd sure like to
understand all this.
I'm ready for your next suggestion. :-)
Bob
P.S. Yes, I've noticed the HitTest method, but I have yet to try it out.
More information about the wxpython-users
mailing list