pygtk FileChooserDialog slows down interpreter
I'm trying to use FileChooserDialog to get a native gnome dialog box in a python script. After the script executes, my ipython -pylab
prompt experiences a significant slow down. This problem also exists from a plain python prompt. I've isolated the problem to the dialog box. The following example (which has been posted elsewhere as a pygtk example) illustrates the issue:
import pygtk
pygtk.require('2.0')
import gtk
class FileChooserDialog:
def __init__(self):
filechooserdialog = gtk.FileChooserDialog("FileChooserDialog Example", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
response = filechooserdialog.run()
if response == gtk.RESPONSE_OK:
print "Selected filepath: %s" % filechooserdialog.get_filename()
filechooserdialog.destroy()
if __name__ == "__main__":
FileChooserDialog()
After running the script, my hard drive light seems to flash after any key is typed in from the keyboard - very strange behavior! I do not have the problem with deprecated gtk.FileSelection
or any other gtk window objects.
I'm currently running, python 2.6.5, gtk 2.21.1, pygtk 2.17.0 in ubuntu 10.04. In general this dialog seems to be 开发者_如何学Pythonflaky; I've also had some issues with the window not destroying itself when executed certain ways within scripts. Any help would be greatly appreciated!
From running this in the IDLE, here's the steps I can see going on for me -
- The script starts and the file chooser loads
- The interpreter locks as it waits for
FileChooserDialog.run()
- The interpreter resumes when I click to remove it
Which is nothing what like you describe, so I can only assume it is some esoteric, weird error.
I'm on a little older system (and a totally different distro), so I run:
- Python 2.6.4
- PyGTK 2.16.0
- GTK 2.18.7
Just for correctness (not necessairly dealing with the problem, though who knows...) remember to call .destroy()
for the dialog after you call .run()
on it.P
精彩评论