I am using gtk to create a file choose dialog:
from gi.repository import Gtk
import time
dialog = Gtk.FileChooserDialog("World to load:", None,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("load", dialog.get_filename())
else:
print("cancel")
dialog.destroy()
time.sleep(5)
The code works: I get either file name or 'cancel printed. But the chooser window does not close before the program exits 5s later. The window just hangs there the program runs further and is responsive. Replacing dialog.destroy()
with dialog.hide()
does not change anything as far as I can tell.
I get a warning:
Gtk-Message: 10:27:04.843: GtkDialog mapped without a transient parent. This is discouraged.
not sure if this is related.
I have tried various versions of Gtk.main()
, Gtk.main_quit()
and other ways to force the main loop, however, my (admittedly imperfect) reading is that file dialog implements the loops itself and does not need the main loop.
Anyone can help me to get this window to close?
I am using python 3.6.7, gi 3.26.1 on ubuntu 18.04