fixes encoding problems when choosing a file in FileChooserDialog on non-utf-8 systems

This commit is contained in:
Yann Leboulanger 2006-04-12 13:56:30 +00:00
parent 2a5e41e06a
commit af424d5bb9
2 changed files with 11 additions and 11 deletions

View File

@ -1537,11 +1537,8 @@ class SoundChooserDialog(FileChooserDialog):
def on_ok(widget, callback): def on_ok(widget, callback):
'''check if file exists and call callback''' '''check if file exists and call callback'''
path_to_snd_file = self.get_filename() path_to_snd_file = self.get_filename()
try: path_to_snd_file = gtkgui_helpers.decode_filechooser_file_paths(
path_to_snd_file = path_to_snd_file.decode( (path_to_snd_file,))[0]
sys.getfilesystemencoding())
except:
pass
if os.path.exists(path_to_snd_file): if os.path.exists(path_to_snd_file):
callback(widget, path_to_snd_file) callback(widget, path_to_snd_file)
@ -1576,11 +1573,8 @@ class ImageChooserDialog(FileChooserDialog):
def on_ok(widget, callback): def on_ok(widget, callback):
'''check if file exists and call callback''' '''check if file exists and call callback'''
path_to_file = self.get_filename() path_to_file = self.get_filename()
try: path_to_file = gtkgui_helpers.decode_filechooser_file_paths(
path_to_file = path_to_file.decode( (path_to_file,))[0]
sys.getfilesystemencoding())
except:
pass
if os.path.exists(path_to_file): if os.path.exists(path_to_file):
callback(widget, path_to_file) callback(widget, path_to_file)

View File

@ -506,7 +506,13 @@ def decode_filechooser_file_paths(file_paths):
file_paths_list.append(file_path) file_paths_list.append(file_path)
else: else:
for file_path in file_paths: for file_path in file_paths:
file_path = file_path.decode(sys.getfilesystemencoding()) try:
file_path = file_path.decode(sys.getfilesystemencoding())
except:
try:
file_path = file_path.decode('utf-8')
except:
pass
file_paths_list.append(file_path) file_paths_list.append(file_path)
return file_paths_list return file_paths_list