PyAuiNotebook - Right click event

Hi,

Been fighting with this one on and off for the last couple weeks and
am at a bit of a loss. When an aui notebook has been split I was
running into issues where the right click event was returning the
wrong tab index. In the attached sample app have tracked it down an
anomaly where in depending upon where the event is bound wx is
delivering different coords to the event handler.

If the event handler for EVT_AUINOTEBOOK_TAB_RIGHT_UP is bound
directly to the notebook control it will return the wrong index in
some cases after the book has been split, however if the handler is
bound to the notebooks parent then it works correctly.

To reproduce in the attached sample: (Windows 7, wx2.9.2.4)

1) Run it
2) Drag Page 3 to the right to split the notebook in two
3) right click on Page 3
4) Observe the correct index / label printed to the console
5) Close it
6) Comment out the event binding to the WrapPanel class, and
un-comment the binding/handler in the MyBook class
7) Repeat step 1-3
8) Observe it now reports Page 0 as being clicked on.

Debugging into the auibook code shows that the mouse coords sent to
the control in its handler for the mouse event are different in these
two cases. In the case of being bound directly to the notebook it
appears the coords are in client coords for two separate windows where
as for when bound to the parent the coords appear as the "two"
notebooks are one window.

Any thoughts / ideas?

Thanks,

Cody

aui_nb_index.py (2.74 KB)

Hi Cody,

Hi,

Been fighting with this one on and off for the last couple weeks and

am at a bit of a loss. When an aui notebook has been split I was

running into issues where the right click event was returning the

wrong tab index. In the attached sample app have tracked it down an

anomaly where in depending upon where the event is bound wx is

delivering different coords to the event handler.

If the event handler for EVT_AUINOTEBOOK_TAB_RIGHT_UP is bound

directly to the notebook control it will return the wrong index in

some cases after the book has been split, however if the handler is

bound to the notebooks parent then it works correctly.

To reproduce in the attached sample: (Windows 7, wx2.9.2.4)

  1. Run it

  2. Drag Page 3 to the right to split the notebook in two

  3. right click on Page 3

  4. Observe the correct index / label printed to the console

  5. Close it

  6. Comment out the event binding to the WrapPanel class, and

un-comment the binding/handler in the MyBook class

  1. Repeat step 1-3

  2. Observe it now reports Page 0 as being clicked on.

Debugging into the auibook code shows that the mouse coords sent to

the control in its handler for the mouse event are different in these

two cases. In the case of being bound directly to the notebook it

appears the coords are in client coords for two separate windows where

as for when bound to the parent the coords appear as the “two”

notebooks are one window.

Any thoughts / ideas?

Not really at the moment, mainly because I don’t have the slightest idea on how to fix this issue. One way of “fixing” it would simply be to put a warning in the documentation recommending to bind the event to the notebook parent, although this is not exactly an ideal solution. I’ll try and dig into the code to see if I am mistakenly converting some coordinates somewhere or doing some stupid/unneeded steps before raising the event, although I am bit swamped with projects (some of them wxPython/Phoenix related) and a patch would be extremely welcome.

Thank you for the bug report.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 28 September 2011 00:50, Cody wrote:

import wx

Hi,

Hi Cody,

Not really at the moment, mainly because I don't have the slightest idea on
how to fix this issue. One way of "fixing" it would simply be to put a
warning in the documentation recommending to bind the event to the notebook
parent, although this is not exactly an ideal solution. I'll try and dig
into the code to see if I am mistakenly converting some coordinates
somewhere or doing some stupid/unneeded steps before raising the event,
although I am bit swamped with projects (some of them wxPython/Phoenix
related) and a patch would be extremely welcome.

Think I have manged to narrow it down some more.

AuiTabCtrl.OnRightUp
- gets the correct tab page
- Calls AuiTabContainer.GetPageFromIndex when setting the selection
in the event object

GetPageFromIndex returns the a value that is the index of the page
within the current TabFrame's AuiTabContainer.

Just to illustrate take the following split notebook below 3 pages on
left 2 on right TabFrame

0 | 1 | 2 ||| 0 | 1

Right clicking on the index 1 in the second TabFrame will set the
event selection to 1. Passing this 1 to the AuiNotebooks GetPageText
results in the page at the index relative to the toplevel TabContainer
being returned which happens to be index 1 from the TabFrame on the
left.

Cody

···

On Sep 28, 2:20 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:

Hi,

Hi,

Hi Cody,

Not really at the moment, mainly because I don't have the slightest idea on
how to fix this issue. One way of "fixing" it would simply be to put a
warning in the documentation recommending to bind the event to the notebook
parent, although this is not exactly an ideal solution. I'll try and dig
into the code to see if I am mistakenly converting some coordinates
somewhere or doing some stupid/unneeded steps before raising the event,
although I am bit swamped with projects (some of them wxPython/Phoenix
related) and a patch would be extremely welcome.

The attached patch doesn't fix the root problem (described in previous
message) but does make it possible to work around it. By also sending
the page window object with the event the AuiNotebook's GetPageIndex
method can be used to retrieve the correct index in the client code's
event handler.

Didn't have enough time to apply and test to other event handlers so
this patch only applies to OnRightUp right now, but this issue is
likely present in all of the AuiTabCtrl event handler methods that set
the event selection attribute when the notebook is split.

Cody

aui_rightclick.patch (1.2 KB)

···

On Wed, Sep 28, 2011 at 2:20 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

Hi Cody,

Hi,

Hi,

Hi Cody,

Not really at the moment, mainly because I don’t have the slightest idea on

how to fix this issue. One way of “fixing” it would simply be to put a

warning in the documentation recommending to bind the event to the notebook

parent, although this is not exactly an ideal solution. I’ll try and dig

into the code to see if I am mistakenly converting some coordinates

somewhere or doing some stupid/unneeded steps before raising the event,

although I am bit swamped with projects (some of them wxPython/Phoenix

related) and a patch would be extremely welcome.

The attached patch doesn’t fix the root problem (described in previous

message) but does make it possible to work around it. By also sending

the page window object with the event the AuiNotebook’s GetPageIndex

method can be used to retrieve the correct index in the client code’s

event handler.

Didn’t have enough time to apply and test to other event handlers so

this patch only applies to OnRightUp right now, but this issue is

likely present in all of the AuiTabCtrl event handler methods that set

the event selection attribute when the notebook is split.

Thank you, I have applied your patch. When I’ll get some more time I’ll dig into the code and try to fix it.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 1 October 2011 23:30, Cody wrote:

On Wed, Sep 28, 2011 at 2:20 PM, Andrea Gavana andrea.gavana@gmail.com wrote:

import wx

Hi,

mclick.patch (840 Bytes)

···

On Sun, Oct 2, 2011 at 3:23 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

Hi Cody,

Thank you, I have applied your patch. When I'll get some more time I'll dig
into the code and try to fix it.
Andrea.

Thanks, here is one more that adds it to the middle mouse click events
as well so that all the mouse events are now covered.

Cody