Middle Click To Close Notebook Tab

Hello List!

Okay, this one should be simple.

I'd like to close the tabs of a notebook by middle (or alternately) right clicking.

So far:

···

*****************************************
class MyNotebook(wx.Notebook):
    def __init__(self, *args, **kwds):
        wx.Notebook.__init__(self,*args,**kwds)

        self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMClick)

    def OnMClick(self,evt):
        print "Clicked!!"
        x,y = wx.GetMousePosition()
        page = self.HitTestXY(x,y)
        self.DeletePage(page) *****************************************

The problematic part is getting the correct tab! On Windows (at least), self.HitTestXY doesn't seem to yield expected results. Am I using it correctly?

Also, is what response should I get if I'm not over *any* tab. Is there an easy way to capture this.

Thanks!

Gregg Lind

Departments of Epidemiology and Biostatistics
University of Minnesota, Unites States

I tried this in demo, and yes, this seems to be a bug for me (or not
implemented).

I modified the notebook demo, and HitTestXY always delivered 10 or 9
(there were 9 tabs).

wxMSW, 2.6.0.0.

I also tried: fr, page = self.HitTest((x,y))
print x,y, fr, page
fr is always -1 and page always 1 (?)

···

On Mon, 20 Jun 2005 16:39:55 -0500, Gregg Lind -- Biostatistics <lind1199@umn.edu> wrote:

Hello List!

Okay, this one should be simple.

I'd like to close the tabs of a notebook by middle (or alternately)
right clicking.

So far:

*****************************************
class MyNotebook(wx.Notebook):
   def __init__(self, *args, **kwds):
       wx.Notebook.__init__(self,*args,**kwds)

       self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMClick)

   def OnMClick(self,evt):
       print "Clicked!!"
       x,y = wx.GetMousePosition()
       page = self.HitTestXY(x,y)
       self.DeletePage(page)
*****************************************

The problematic part is getting the correct tab!
On Windows (at least), self.HitTestXY doesn't seem to yield expected
results. Am I using it correctly?
[...]

--
Franz Steinhaeusler

This works for me:

# part of a wx.Notebook class...
def onRightClick(self, event):
"""right-click event handler"""
    mousePos = event.GetPosition()
    pageIdx, other = self.HitTest(mousePos)
    self.DeletePage(pageIdx)

Rad

···

----- Original Message ----- From: "Franz Steinhäusler" <franz.steinhaeusler@gmx.at>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Tuesday, June 21, 2005 9:06 AM
Subject: [wxPython-users] Re: Middle Click To Close Notebook Tab

On Mon, 20 Jun 2005 16:39:55 -0500, Gregg Lind -- Biostatistics > <lind1199@umn.edu> wrote:

Hello List!

Okay, this one should be simple.

I'd like to close the tabs of a notebook by middle (or alternately)
right clicking.

So far:

*****************************************
class MyNotebook(wx.Notebook):
   def __init__(self, *args, **kwds):
       wx.Notebook.__init__(self,*args,**kwds)

       self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMClick)

   def OnMClick(self,evt):
       print "Clicked!!"
       x,y = wx.GetMousePosition()
       page = self.HitTestXY(x,y)
       self.DeletePage(page)
*****************************************

The problematic part is getting the correct tab!
On Windows (at least), self.HitTestXY doesn't seem to yield expected
results. Am I using it correctly?
[...]

I tried this in demo, and yes, this seems to be a bug for me (or not
implemented).

I modified the notebook demo, and HitTestXY always delivered 10 or 9
(there were 9 tabs).

wxMSW, 2.6.0.0.

I also tried: fr, page = self.HitTest((x,y))
print x,y, fr, page
fr is always -1 and page always 1 (?)

--
Franz Steinhaeusler

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org