Search code examples
pythongtkgtk3

Python Gtk+3 Window.present not work with GNOME Builder


environment:

  • Ubuntu Gnome 16.04.3
  • GNOME Builder 3.26.3

The GNOME Builder generated project use GtkTemplate to interpret ui, But I change it to use Gtk.Builder to interpret. After modifying, it does not work. And I can not see any error message.

class Application(Gtk.Application):
    def __init__(self):
        super().__init__(application_id='org.gnome.Ee',
                         flags = Gio.ApplicationFlags.FLAGS_NONE)
    def do_startup(self):
        print('do_startup')
        Gtk.Application.do_startup(self)
        builder = Gtk.Builder()
        builder.add_from_resource("/org/gnome/Ee/window.ui")
        print(builder)
        self.builder = builder
    def do_activate(self):
        print("do_activate")
        win = self.props.active_window
        if not win:
            win = self.builder.get_object("EeWindow")
            print(win)
        win.present() # not work, can not see the window

I have upload the demo code to Github: https://github.com/Honghe/gnome_builder_demo

Any help will be appreciated!


Solution

  • The application does not know about the window so it exits immediately. You need to call win.set_application(self) after you created an instance of the window.