简体   繁体   中英

Gtk.main() blocking in Gtk3 interface

I am designing a small GUI to interface with a piece of code I have written.

My problem is that the Gtk.main() command seem to be blocking, and even though my window closes when I click the destroy button, my terminal is still hanged.

I also do not see any interaction with signals.

Here is my sample:

#!/usr/bin/env python

from gi.repository import Gtk, Gdk, GObject

GObject.threads_init()

class Ivolution():       

    def __init__(self):

        print "in"
        self.builder = Gtk.Builder()
        self.builder.add_from_file("data/ui/IvolutionWindow.glade")
        #builder.connect_signals({ "on_window_destroy" : gtk.main_quit })
        self.window = self.builder.get_object("ivolution_window")
        print "in fin"

    def on_stopbutton_clicked(self, widget):
        """
        Asks the Facemovie thread to terminate
        """
        print "Stop"    

    def on_ivolutionwindow_destroy(self, widget, data=None):
        """Called when the IvolutionWindow is closed."""

        # Clean up code for saving application state should be added here.
        print "Exiting"
        Gtk.main_quit()
        print "Exited"

if __name__ == "__main__":
    app = Ivolution()
    print "deb"
    app.window.show()
    Gdk.threads_init()
    Gdk.threads_enter()
    print "but"
    Gtk.main()
    print "end"
    Gdk.thread_leave()
    print "ding"

I removed all the non essential parts.

The Gobject and gdk.threads things are tests I have made looking at different source codes over the internet.

I couldn't come up with a successful combination of them.

If I run the program into a console, here is what I get:

in

(Ivolution.py:4635): Gtk-CRITICAL **: gtk_radio_button_set_group: assertion `!g_slist_find (group, radio_button)' failed

(Ivolution.py:4635): Gtk-CRITICAL **: gtk_radio_button_set_group: assertion `!g_slist_find (group, radio_button)' failed
in fin
deb
but

Even though I hit the stop button and closes the window.

Once I close my window, the console stays the same, and even a ctrl+c won't stop the application.

I am sure I miss something basic, but as a complete GUI noob I don't see what. This sample code seem really close to mine. Any idea?

Ok, I feel both angry and a fool at the same time here.

I try to reuse code from an attempt I made with Quickly

I had no signals defined in my glade file. For some reason I don't exactly get, Quickly lets you call events without defining them in the glade files.

sure it couldn't work.

Th Python code above works fine, provided that you have the correct signals defined in your glade file

EDIT :

As a complement of information, here is how a signal would look like in the glade file

<signal name="delete-event" handler="on_destroy" swapped="no"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM