开发者

Callback function is not executed with ondestroy

I'm developing an application using python gtk+ and glade. My glade file format is gtk-builder. I've two windows in it - one main window and one login window. Inside __ init __ () I run the login dialog window, so that I can make sure the focus will not be switched to the main window until the user emits OK signal from the login window. When this is done using the following code, the user has to click twice on the [x] on the titlebar, to quit the application. When I use loginWindow.show() rather than the run(), it works perfect, but the focus issue arises there. How can I fix this issue?

import sys
try:
    import pygtk
    pygtk.require("2.8")
except:
    pass
try:
    import gtk
except:
    sys.exit(1)


class netChat:
    def __init__(self):
        self.builder = gtk.Builder()
        self.builder.add_from_file("netchat.glade")
        self.builder.connect_signals(self)
        self.loginWindow = self.builder.get_object('loginWindow')
        self.mainWindow = self.builder.get_object('mainWindow')
        self.message = self.builder.get_object('message')
        self.timeLine = self.builder.get_object('timeLine')
        self.loginWindo开发者_C百科w.run()
    def onSend(self, widget):
        text = self.message.get_text()
        myBuffer = self.timeLine.get_buffer()
        myBuffer.insert_at_cursor(' '+text+'\n')
        self.message.set_text('')
        print "on Send"
    def mainQuit(self, widget):
        print "Quiting, goodbye!"
        sys.exit(0)
    def loginQuit(self, widget):
        print "Login Quit, goodbye!"
        sys.exit(1)

if __name__ == "__main__":
    myChat = netChat()
    gtk.main()

I tried setting the same mainQuit() callback for both of the windows too. But that didn't make any difference. Thanks for any help.


It looks like you have a reentry issue. Probably you are running the main window from the onClick of the "ok" button in the login dialog.

Maybe you are calling gtk.main() several times?

It is difficult to guess, since your code is not complete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜