Python GTK (Glade) Notebook
Asked Answered
F

2

6

I'm currently developing a small application in Python with the use of GTK+ (and Glade). Everything has been fairly simple to integrate so far, until I came up with the idea to add tabs instead of pop-ups. Note: Still using Python 2.7+

Is there any easy way to implement already existing pages inside a new tab(notebook) like structure? I'm having difficulties to find how to add content per separate tab created in glade. Perhabs a more 'clear' question: What Notebook function will be required to call a specific V/HBox with every different tab? The current structure looks like (minus Menu / statusbar):

[ mainWindow ] --> (1) mainOverview (gtkVbox) --> (2A) mainContent (gtkHbox) ... other non-related content

The structure I was hoping for would look like:

[ mainWindow ] --> (1) mainOverview --> (2) noteBook --> (3) Tab1 --> (4) mainContent (gtkHbox) -- (3) Tab2 --> (4) secondaryContent (gtkHbox)

The application itself works fine (multithreaded, fully functioning) without the tabs, the mainContent(gtkHbox) contains a file/recursive directory analyzer, a few checkboxes and a general overview. I was hoping for an easy way to display this main window (the gtkHbox) ONLY when having Tab1 selected.

Having difficulties to find good reference pages that display a proper way to call content pages per notebook tab. Any reference-pages or useful links are very much appreciated! Thanks so far! My apologies if this is a rather newbish question, I'm not new to Python coding, but interfaces on the other hand... ;)

Fertility answered 24/5, 2013 at 22:57 Comment(2)
Umm are you having difficulty adding contents in glade to each page? If you double click on the tab, then that page is selected for adding content in glade. You can go ahead and add content for that page. As for switching you can use set_current_page to switch to page whose content you want to display. Register for "switch-page" signal to find out which page has been switched to.Aver
@Aver : I never realized it would be this simple. I was hoping for a simple solution located inside the code itself, but never came up with the idea you can simply 'drag' H/VBoxes to each Tab in Glade itself! Thank you so much! :)Fertility
B
1

Not an answer, but it looks like "another.anon.coward" already answered this in a comment...

If you double click on the tab, then that page is selected for adding content in glade. You can go ahead and add content for that page. As for switching you can use set_current_page to switch to page whose content you want to display. Register for "switch-page" signal to find out which page has been switched to.

Brunel answered 26/2, 2014 at 18:15 Comment(0)
A
0

click on the notebook widget on the widget explorer(object inspector) on the left of glade. Then use your left and right keyboard arrow keys to move from tab to tab. You can also double click on the label of the tab as pyrotherm has said in his answer. But if you want to do it programatically get the notebook object from the ui using the get_object method of Gtk.builder class. Then do this to add a page

builder = Gtk.Builder()
builder.add_from_file("example.glade")

self.notebook = builder.get_object("notebook1") # set the id of the notebook in glade
self.page1 = Gtk.Box()
self.page1.add(Gtk.Label(label="Default Page!"))
self.notebook.append_page(self.page1, Gtk.Label(label="Plain Title"))

Now add the content you want to it. Now on to signals. Pyrotherm has already answered it. though there is no signal named switch-page. its named switch_page. You can look at the list of signals of notebook here

Appel answered 5/1, 2022 at 5:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.