views:

404

answers:

3

I'm experimenting with wxPython,

I have a tabbed interface (notebook) and each tab is basically a file list view (yes, I'm trying to make a file manager)

The file list inherits from wx.ListCtrl, and the tabbed interface inherits from wx.Notebook

I'm just starting .. and I had it so double clicking on a folder will cd into that folder, but I want to also change the title of the tab.

How do I do that?

I have the object that represents the file list and the title I want to set it to,

[ EDIT Notebook.SetPageText() takes a number, so I can't pass the tab object directly to it ]

my current approach is to cycle through the tabs until one of them matches my tab:

    for tab_id in range(self.GetPageCount()):
        if self.GetPage(tab_id) == tab:
            self.SetPageText(tab_id, title)
            break

This seems rather naive though, isn't there a smarter approach?

A: 

As .GetPage returns a wx.Window, I think tab.Label = title should work.

Venti
just tried it, didn't work
hasen j
A: 

I think doing something like this helps :


notebook.get_tab_label(notebook.get_nth_page(your_page_number)).set_text("Your text")

If you want to have a reference to the current tab always, you must connect the "switch-page" signal, and save the page in a variable.

Geo
How is that better than notebook.SetPageText(page_number, "title")? Plus you still need to find the "number" first.
hasen j
+1  A: 

I don't know wxPython, but I assume it wraps all the methods of the C++ classes.

There is wxNotebook::GetSelection() which returns wxNOT_FOUND or the index of the selected page, which can then be used to call wxNotebook::SetPageText().

Or use wxNotebook::GetPage() with this index to check whether it is equal to tab.

mghie
I don't want to make an assumption that only the selected page can change directory.
hasen j
I'm not sure how you would double click on a file list without that page being active in the notebook? But if you need it to work with all pages, just stick with the code in your question, it's not bad or naive IMO.
mghie