Dragging tabs in an AuiNotebook does not change their index.

If you have an AuiNotebook with the AUI_NB_TAB_MOVE style set,
allowing the user to rearrange the tab order, the index of a moved tab
is not updated! I think this behaviour is unexpected. This is a
problem for me, because I need to iterate through the tabs in the
order that they're displayed so that I can save and load a session
with the same user-specified tab order.

Here's a test case:

import wx
from wx import aui

app = wx.PySimpleApp()
frame = wx.Frame(None)

nbstyle = aui.AUI_NB_TOP | aui.AUI_NB_TAB_MOVE |
aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
notebook = aui.AuiNotebook(frame, style=nbstyle)
notebook.AddPage(wx.TextCtrl(notebook), "tab 1")
notebook.AddPage(wx.TextCtrl(notebook), "tab 2")
notebook.AddPage(wx.TextCtrl(notebook), "tab 3")

def OnClose(evt):
    for i in xrange(notebook.GetPageCount()):
        print notebook.GetPageText(i)
    frame.Destroy()

frame.Bind(wx.EVT_CLOSE, OnClose)
frame.Show()
app.MainLoop()

No matter how you move the tabs, this will always print out the tabs
in the same order.

Is it possible to iterate the tabs in visible order, or force
AuiNotebook to keep insertion indices and visible indices in sync?

Hi,

If you have an AuiNotebook with the AUI_NB_TAB_MOVE style set,
allowing the user to rearrange the tab order, the index of a moved tab
is not updated! I think this behaviour is unexpected. This is a
problem for me, because I need to iterate through the tabs in the
order that they're displayed so that I can save and load a session
with the same user-specified tab order.

Here's a test case:

import wx
from wx import aui

app = wx.PySimpleApp()
frame = wx.Frame(None)

nbstyle = aui.AUI_NB_TOP | aui.AUI_NB_TAB_MOVE |
aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
notebook = aui.AuiNotebook(frame, style=nbstyle)
notebook.AddPage(wx.TextCtrl(notebook), "tab 1")
notebook.AddPage(wx.TextCtrl(notebook), "tab 2")
notebook.AddPage(wx.TextCtrl(notebook), "tab 3")

def OnClose(evt):
for i in xrange(notebook.GetPageCount()):
print notebook.GetPageText(i)
frame.Destroy()

frame.Bind(wx.EVT_CLOSE, OnClose)
frame.Show()
app.MainLoop()

No matter how you move the tabs, this will always print out the tabs
in the same order.

Is it possible to iterate the tabs in visible order, or force
AuiNotebook to keep insertion indices and visible indices in sync?

No, at least not as far as I know. But you could use wx.lib.agw.aui,
which is a port of wxAUI to Python I made and supports loading/saving
of AuiNotebook perspectives.

Andrea.

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

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever. <==

···

On 16 March 2010 12:24, Luke McCarthy wrote:

Thanks for the tip. However, don't you think this is a bug (or at
least, a flaw in the interface)? RemovePage doesn't leave a hole in
the "index space", it changes the indices of the tabs as it should. So
why shouldn't dragging keep the tabs indices in order? What if the
user has rearranged the tab order and then you want to use InsertPage
with GetSelection()+1 to insert a tab after the current selection, it
will totally mess up!

I have come up with a "solution", not very nice but it works:

        ...
        self.notebook.Bind(aui.EVT_AUINOTEBOOK_END_DRAG,
self.OnNotebookEndDrag)

    def OnNotebookEndDrag(self, evt):
        sel = self.notebook.GetSelection()
        caption = self.notebook.GetPageText(sel)
        bitmap = self.notebook.GetPageBitmap(sel)
        page = self.notebook.GetPage(sel)
        self.notebook.Freeze()
        self.notebook.RemovePage(sel)
        self.notebook.InsertPage(evt.GetInt(), page, caption, True,
bitmap)
        self.notebook.Thaw()

···

On Mar 16, 2:05 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:

Hi,

On 16 March 2010 12:24, Luke McCarthy wrote:

> If you have an AuiNotebook with the AUI_NB_TAB_MOVE style set,
> allowing the user to rearrange the tab order, the index of a moved tab
> is not updated! I think this behaviour is unexpected. This is a
> problem for me, because I need to iterate through the tabs in the
> order that they're displayed so that I can save and load a session
> with the same user-specified tab order.

> Here's a test case:

> import wx
> from wx import aui

> app = wx.PySimpleApp()
> frame = wx.Frame(None)

> nbstyle = aui.AUI_NB_TOP | aui.AUI_NB_TAB_MOVE |
> aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
> notebook = aui.AuiNotebook(frame, style=nbstyle)
> notebook.AddPage(wx.TextCtrl(notebook), "tab 1")
> notebook.AddPage(wx.TextCtrl(notebook), "tab 2")
> notebook.AddPage(wx.TextCtrl(notebook), "tab 3")

> def OnClose(evt):
> for i in xrange(notebook.GetPageCount()):
> print notebook.GetPageText(i)
> frame.Destroy()

> frame.Bind(wx.EVT_CLOSE, OnClose)
> frame.Show()
> app.MainLoop()

> No matter how you move the tabs, this will always print out the tabs
> in the same order.

> Is it possible to iterate the tabs in visible order, or force
> AuiNotebook to keep insertion indices and visible indices in sync?

No, at least not as far as I know. But you could use wx.lib.agw.aui,
which is a port of wxAUI to Python I made and supports loading/saving
of AuiNotebook perspectives.

Andrea.

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

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever. <==

It probably is a bug. There are several with the default AUI. Go ahead
and check if this one has been reported on Trac and if not, submit a
bug report. Andrea wrote his version of AUI because the default AUI
had bugs or missing features that he didn't want to wait several years
for.

···

On Mar 16, 9:59 am, Luke McCarthy <luke.mccar...@gmail.com> wrote:

Thanks for the tip. However, don't you think this is a bug (or at
least, a flaw in the interface)? RemovePage doesn't leave a hole in
the "index space", it changes the indices of the tabs as it should. So
why shouldn't dragging keep the tabs indices in order? What if the
user has rearranged the tab order and then you want to use InsertPage
with GetSelection()+1 to insert a tab after the current selection, it
will totally mess up!

I have come up with a "solution", not very nice but it works:

    \.\.\.
    self\.notebook\.Bind\(aui\.EVT\_AUINOTEBOOK\_END\_DRAG,

self.OnNotebookEndDrag)

def OnNotebookEndDrag\(self, evt\):
    sel = self\.notebook\.GetSelection\(\)
    caption = self\.notebook\.GetPageText\(sel\)
    bitmap = self\.notebook\.GetPageBitmap\(sel\)
    page = self\.notebook\.GetPage\(sel\)
    self\.notebook\.Freeze\(\)
    self\.notebook\.RemovePage\(sel\)
    self\.notebook\.InsertPage\(evt\.GetInt\(\), page, caption, True,

bitmap)
self.notebook.Thaw()

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

It seems like AGW AUI has the same behaviour. I'll have a look on
Trac.

···

On Mar 16, 3:03 pm, Mike Driscoll <kyoso...@gmail.com> wrote:

It probably is a bug. There are several with the default AUI. Go ahead
and check if this one has been reported on Trac and if not, submit a
bug report. Andrea wrote his version of AUI because the default AUI
had bugs or missing features that he didn't want to wait several years
for.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

I've found the bug reported here:

http://trac.wxwidgets.org/ticket/10848

Hi,

It seems like AGW AUI has the same behaviour. I'll have a look on
Trac.

It is very likely, but agw.aui.AuiNotebook supports perspective
saving/restoring out of the box, so you shouldn't worry (and shouldn't
care) anymore about the page indexes and ordering. Just call
SavePerspective and it will do everything for you.

Andrea.

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

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever. <==

···

On 16 March 2010 15:15, Luke McCarthy wrote: