I'm new to GTK. I've been looking for an answer to my question but I haven't found anything. The thing is that I want to use GTK FileChooser to select a file. I've been looking at the example available here:
http://pygtk.org/pygtk2tutorial/examples/filechooser.py
Then I used the knowledge that I've learned in the example to add this feature to my program. However, I noticed that when I choose a file, the window hangs. By this I mean that the window to select a file never disappears until I close the whole program.
So I went back to the example, and just waited some time to see if the window was destroyed. And in fact, it didn't. The window to select a file disappears only when the program finishes. Here is the code:
#!/usr/bin/env python
# example filechooser.py
import pygtk
pygtk.require('2.0')
import gtk
import time
# Check for new pygtk: this is new class in PyGtk 2.4
if gtk.pygtk_version < (2,3,90):
print "PyGtk 2.3.90 or later required for this example"
raise SystemExit
dialog = gtk.FileChooserDialog("Open..",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)
filter = gtk.FileFilter()
filter.set_name("Images")
filter.add_mime_type("image/png")
filter.add_mime_type("image/jpeg")
filter.add_mime_type("image/gif")
filter.add_pattern("*.png")
filter.add_pattern("*.jpg")
filter.add_pattern("*.gif")
filter.add_pattern("*.tif")
filter.add_pattern("*.xpm")
dialog.add_filter(filter)
response = dialog.run()
if response == gtk.RESPONSE_OK:
print dialog.get_filename(), 'selected'
elif response == gtk.RESPONSE_CANCEL:
print 'Closed, no files selected'
dialog.destroy()
time.sleep(3)
And in those 3 seconds the window is there, so I guess it is never destroyed and I wonder why. Even if I wait 10 seconds, the window never disappears until the program finishes. I need to know if there's something wrong in the example or what I'm doing wrong since this is not something I would like to happen in my program.
Just in case, I'm using Python 2.7.3 and Debian 7.
Thanks in advance!