Mejmo
Mejmo

Reputation: 2593

Python GTK window in Thread

I have a CLI application, which is digging some data, in case of need, fires up a thread which creates GTK window with some information. However the CLI (main thread) still analyzes the data in the background, so there could be numerous windows created. In case I close the window, the destroy event is actually fired up, I got a debug line in CLI, but the window locks up.

Some magical command that I have to use ?

I create window like this in the main thread:

    gtk.gdk.threads_init()
    notifyWindow = NotifyWindow()
    notifyWindow.start()

This is NotifyWindow(Thread).destroy

def destroy(self, widget, data=None):
    print "destroy signal occurred"
    gtk.main_quit()

This is NotifyWindow(Thread).run

def run(self):

    self.window = gtk.glade.XML( "hadinfo.glade" )

    self.window_main = self.window.get_widget("window_main")

    if (self.window_main):
        self.window_main.connect("destroy", self.destroy)
        self.window_main.connect("delete_event", self.delete_event)

    self.button_cancel = self.window.get_widget("button_cancel")
    self.button_cancel.connect("clicked", self.destroy)

    self.window.get_widget("window_main").show()

    gtk.main()

Upvotes: 3

Views: 1180

Answers (1)

Khertan
Khertan

Reputation: 93

using a gtk.threads_enter() and leave around your main call should help.

Take a look at the PyGtk Faq : PyGtk FAQ

Upvotes: 1

Related Questions