Search code examples
gtkpygtkgladegtk3

How do I load a widget in an adjacent pane when a toolbutton is clicked?


I am trying to create a GTK python app for configuring settings and I have been looking at creating a GTK design for the app using Glade.

So far I have created a design with 5 notebooks and it looks somewhat like this:

glade-notebooks

However, I actually want to use a Gtktoolbar with primary-style toolbar buttons that open the settings in the adjacent pane when the Gtktoolbar buttons are clicked. The current Gtkprimarytoolbar implementation looks like this:

glade-toolbars

I am very new to Gtk designing and I tried setting the on_tool_unitysettings_clicked signal to handle nb_unitysettings. I'll admit I don't know what I am doing.

The idea is when I click on the toolbar button, the related notebook gets loaded in the pane below the toolbar buttons. How exactly do I do that? I would be very much happy with a Glade solution.


Solution

  • I ended up merging both the windows above and changing the notebook's page when each of the toolbar buttons are pressed. I also hid the tabs of the notebook so it doesn't look like there was a notebook there at all.

    Here's the python file that handles the signals when the buttons are pressed:

    #!/usr/bin/env python3
    from gi.repository import Gtk
    
    class Handler ():
        '''Clicking the toolbars'''
        def on_tool_startpage_toggled(self,nb_mechanig):
            nb_mechanig.set_current_page(0)
        def on_tool_unitysettings_toggled(self,nb_mechanig):
            nb_mechanig.set_current_page(1)
        def on_tool_compizsettings_toggled(self,nb_mechanig):
            nb_mechanig.set_current_page(2)
        def on_tool_themesettings_toggled(self,nb_mechanig):
            nb_mechanig.set_current_page(3)
        def on_tool_desktopsettings_toggled(self,nb_mechanig):
            nb_mechanig.set_current_page(4)
    
    
    # Basic builder setting up
    
    builder = Gtk.Builder()
    builder.add_from_file("mechanig.glade")
    builder.connect_signals(Handler())
    
    # The main Mechanig window that needs to be shown
    mechanig_main = builder.get_object('mechanig_main')
    
    # This signal is emitted when you close the window,
    # which triggers Gtk.main_quit, which tells the main Gtk loop to quit
    mechanig_main.connect("delete-event", Gtk.main_quit)
    
    # This is required, otherwise Gtk leaves the window hidden.
    # Useful, like with our dummy "windows" that get reparented
    mechanig_main.show_all()
    
    # Runs the main loop
    Gtk.main()
    

    And the window now looks like this and this is the closest I can get to what I wanted:

    Mechanig-glade-previewer