如何在wx.aui.AuiNotebook中更改页面标题?

时间:2012-05-17 22:24:37

标签: user-interface wxpython

所以我正在编写一个文本编辑器来更好地学习wxPython(并创建一个我真正喜欢的文本编辑器:P)。我一直无法在wx.aui.AuiNotebook类上找到很多信息。我想知道的一件事是如何与其页面进行交互。例如,我真的想知道如何更改页面的标题(以便我可以在用户保存时更新页面标题,或者在未保存的更改时标记它)。对此事的任何帮助都将非常感谢!

2 个答案:

答案 0 :(得分:2)

该方法称为SetPageText,因此您可以执行以下操作:

    current_page = notebook.GetCurrentPage()
    current_page_index = notebook.GetPageIndex(current_page)
    current_label = notebook.GetPageText(current_page_index)
    if not current_label.endswith(' (*)':
        notebook.SetPageText(current_page_index, current_label + ' (*)')

答案 1 :(得分:1)

显然,在wxPython版本2.8中不包括wx.aui.AuiNotebook.GetCurrentPage()。我显然没有意识到wx.aui.AuiNotebook中的“页面”等同于添加到它的面板。因此,以下代码将起作用,

    self.panelBox = []
    newPanel = wx.Panel(self, wx.ID_ANY)

    #YADA YADA STUFF!        

    self.nb.AddPage(newPanel, "Untitled Document "+str(self.untitledDocCount))
    currPageIndex = self.nb.GetPageIndex(newPanel)
    currLabel = self.nb.GetPageText(currPageIndex)
    if not currLabel.endswith(' (*)'):
        self.nb.SetPageText(currPageIndex, currLabel+' (*)')
    self.panelBox.append(newPanel)

由程序员决定是否可以访问页面(面板)。我这样做是通过将面板参考存储在“面板框”中,然后在诸如“更改标签”事件之类的条件下相应地切换它们。我不知道这是否是最好的方法,但它似乎工作到目前为止。