Comment 11 for bug 717162

Revision history for this message
John S. Gruber (jsjgruber) wrote :

import gtk

""" Either commenting out the following threads call, or disabling the global
appmenu, allows the program to run after using the First Menu's About and then
closing the resulting About dialog box.

The Second Menu's About dialog box, with its different call back routine, works irregardless.

Including gtk.gdk.threads_leave() in the problematic call back routine also
works. The problem seems to be an unbalanced thread lock enter..leave """

gtk.gdk.threads_init() # Without this line program works ok

window=gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Our Window")
window.connect("delete-event", lambda x,y: gtk.main_quit() )
window.show()

def menuitem_response(string):
    about = gtk.AboutDialog()
    about.set_name("My About Dialog")
    response = about.run()
    gtk.gdk.threads_leave() # <---------------------------------------------------------------------
    about.destroy()

def menuitem2_response(string):
    about = gtk.AboutDialog()
    about.set_name("My About Dialog")
    about.connect("response", lambda x,y: x.destroy() )
    about.show()

about_item = gtk.MenuItem("About")
about_item.connect_object("activate", menuitem_response, "about")
about_item.show()

about_item2 = gtk.MenuItem("About")
about_item2.connect_object("activate", menuitem2_response, "about")
about_item2.show()

menu = gtk.Menu()
menu.append(about_item)

menu2 = gtk.Menu()
menu2.append(about_item2)

root_menu = gtk.MenuItem("First Top Menu")
root_menu.show()
root_menu.set_submenu(menu)

second_menu = gtk.MenuItem("Second Top Menu")
second_menu.show()
second_menu.set_submenu(menu2)

vbox = gtk.VBox(False, 0)
window.add(vbox)
vbox.show()

menubar=gtk.MenuBar()
vbox.pack_start(menubar, False, False, 0)
menubar.append(root_menu)
menubar.append(second_menu)
menubar.show()

gtk.main()