简体   繁体   中英

Python/wxPython: auinotebook get all pages

I have an auinotebook, is there anyway to get a list of all pages in the notebook? When the user selects an action from a list, a new page is added to the notebook. If they select that action again, then the page should not be added again (instead, that page will be selected for them). I can't see to figure out how to do this?? Thanks!

Assuming you are using wx.lib.agw.aui.AuiNotebook:

import wx.lib.agw.aui as aui

class MyNotebook(aui.AuiNotebook):
    def __getitem__(self, index):
        ''' More pythonic way to get a specific page, also useful for iterating
            over all pages, e.g: for page in notebook: ... '''
        if index < self.GetPageCount():
            return self.GetPage(index)
        else:
            raise IndexError

Now you can iterate over the pages of the notebook:

notebook = MyNotebook(parent)
notebook.AddPage(someWindow, "page 1")
notebook.AddPage(someOtherWindow, "page 2")
for page in notebook:
    ...

You don't mention which AuiNotebook you're using. Is it the one that comes with wx.aui or wx.lib.agw.aui? Either way, I would think you could use GetChildren() to get a list of the notebook's panels and iterate through those as necessary. There's also a GetPageCount that you might be able to use in conjunction with GetPageInfo and GetPageText (these last three methods are in the agw version...not sure if they're included in the other). See the documentation for more information: http://xoomer.virgilio.it/infinity77/AGW_Docs/aui.auibook.AuiNotebook.html#aui-auibook-auinotebook

Or you could cross-post to the wxPython user's list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM