Convert file names from gtk.FileChooserDialog

On POSIX, it is encoded using the file system encoding.
On Windows, it is always UTF-8.
See http://www.pygtk.org/pygtk2reference/class-gtkfilechooser.html#FileNamesAndEncodings

issue5671
review21231002
This commit is contained in:
Cédric Krier committed 2016-08-31 22:55:03 +02:00
1 parent 0f98f48d8c
commit 36aab63dac
1 file changed
+8 -2
+8 -2
View File
@@ -423,13 +423,19 @@ def file_selection(title, filename='',
win.set_preview_widget(img_preview)
win.connect('update-preview', update_preview_cb, img_preview)
if os.name == 'nt':
encoding = 'utf-8'
else:
encoding = sys.getfilesystemencoding()
button = win.run()
if button != gtk.RESPONSE_OK:
result = False
result = None
elif not multi:
result = win.get_filename()
if result:
result = unicode(result, encoding)
else:
result = win.get_filenames()
result = [unicode(path, encoding) for path in win.get_filenames()]
parent.present()
win.destroy()
return result