screen position of Notebook tabs

I’m trying to obtain the
screen position of the actual index tab of a page in a
wx.NotebookCtrl. I’ve tried several methods but I haven’t succeeded
yet. Intuitively I was hoping that the Notebook class itself would
have a method returning the coordinates of the index tab for one of its
pages, but that doesn’t seem to be available. Everything I have tried seems to return the same position (the upper left corner of the entire wx.NotebookCtrl itself) even when asking the individual pages (wx.Panels) their position. In the docs I haven’t found a function that lets either the parent Notebook or the child Panels report the actual location of thier index tab.

I hope I don’t have to resort to brute-force methods such as
calculating the width of each notebook tab (as a result of the length
of its text label) and traversing/adding to figure out the position of
each.

Thanks in advance for any suggestions!

Andrea Gavana wrote:

Hi Eric,

> I don't think there is a way to do that, other than maybe switch to
> another notebook (i.e., FlatNotebook). But maybe I am wrong. BTW, if
> you tell us what you are trying to achieve, maybe there are
> alternative solutions someone might suggest.

Thank you, Andrea. Maybe I will experiment with FlatNotebook. Today I
still wish to see if I can make this work using the simple Notebook control.

This morning I added method GetTabExtent(self, page) to my Notebook
subclass, returning the coordinates occupied by the index tab for a given
page of the notebook. It loops a test coordinate through the page and uses
HitTest to determine whether it has hit the proper tab (just the tab, with
wx.NB_HITTEST_ONLABEL).

This works, but it's such a brute-force method and I'm surprised there isn't
an existing method for this already. I won't be surprised if I get this all
working and then find out there's already an existing provision for passing
a text box editor function to Notebook for this same purpose of editing tab
label text. But it's good practice for learning, in the meantime. I'm
still seeking any suggestions on how others have handled this situation.

There might be a way to do that, I am sure Robin will know the answer.

There isn't a method for that. I'm not sure if the native platforms provide anything for it either...

···

On 5/16/07, Eric Ongerth wrote:

On 5/16/07, Andrea Gavana <andrea.gavana@gmail.com> wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Eric Ongerth wrote:

Thank you, Robin.

I suspect that something in the C++ code holds data on the tab positions in some form; the Notebook control has to keep track of where the tabs are shown on the screen, where the labels are shown on the tabs, etc. And when the style is multiline, the control has to decide when it's holding enough tabs to start an additional line of tabs (or when to decrease by a line) -- upon which it has to resize all of its tabs. But even if it's keeping track of that stuff, that's not to say that any of this information is exposed.

Keep in mind that this is the native widget so we only have access to what the platform lets us have. In fact there is no guarantee that the native widget is even keeping track of the size/positions of the tabs, it could just as easily calculate it on the fly when it needs it.

So what is the typical or standard method for allowing an app's user (for example, upon choosing "rename" from a context sensitive popup menu) to edit tab labels in situ? Brute force is working great in my program but the thought makes me cringe. I suppose I could just give thanks for modern processing power.

I don't think I've ever seen it done like this. Usually renaming a tab/page is part of some other dialog that may also be collecting other information.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!