Reputation: 31
I have a very weird problem at the moment and I hope you'll be able to reproduce it. Please try the following Python code:
import gtk
print '=== 1 ==='
def _createFileDialog():
dialog = gtk.FileChooserDialog()
print dialog.get_current_folder(), '***'
dialog.set_current_folder('/home/')
print dialog.get_current_folder(), '###'
dialog = _createFileDialog()
print '=== 2 ==='
dialog = gtk.FileChooserDialog()
print dialog.get_current_folder(), '***'
dialog.set_current_folder('/home/')
print dialog.get_current_folder(), '###'
As you can see, the code sections are basically the same, so you might expect the same results. However, during the first section, the line ending with '###' prints 'None ###', while the second section correctly prints '/home ###'. I re-tried this on two different computers of my colleagues, and on one computer this was reproducable. Does anybody know what the problem might be?
Nice greetings and thanks in advance Chris
Upvotes: 3
Views: 191
Reputation: 29886
It can also print "None ###" in both cases.
The call to set_current_folder
seems to be asynchronous, it works as expected if you let GTK handle pending events before calling get_current_folder
:
dialog = gtk.FileChooserDialog()
print dialog.get_current_folder(), '***'
dialog.set_current_folder('/home/')
while gtk.events_pending():
gtk.main_iteration()
print dialog.get_current_folder(), '###'
Upvotes: 2