Fix file chooser dialog on Windows
Dropped decode_filechooser_file_paths() as with Python 3 it raised AttributeError: 'str' object has no attribute 'decode' on Windows, and silently handled exceptions effectively doing nothing on *nix systems.
This commit is contained in:
parent
453fd46427
commit
060aa01857
|
@ -4712,9 +4712,6 @@ class ClientCertChooserDialog(FileChooserDialog):
|
||||||
check if file exists and call callback
|
check if file exists and call callback
|
||||||
'''
|
'''
|
||||||
path_to_clientcert_file = self.get_filename()
|
path_to_clientcert_file = self.get_filename()
|
||||||
path_to_clientcert_file = \
|
|
||||||
gtkgui_helpers.decode_filechooser_file_paths(
|
|
||||||
(path_to_clientcert_file,))[0]
|
|
||||||
if os.path.exists(path_to_clientcert_file):
|
if os.path.exists(path_to_clientcert_file):
|
||||||
callback(widget, path_to_clientcert_file)
|
callback(widget, path_to_clientcert_file)
|
||||||
|
|
||||||
|
@ -4757,8 +4754,6 @@ class SoundChooserDialog(FileChooserDialog):
|
||||||
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()
|
||||||
path_to_snd_file = gtkgui_helpers.decode_filechooser_file_paths(
|
|
||||||
(path_to_snd_file,))[0]
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -4799,8 +4794,6 @@ class ImageChooserDialog(FileChooserDialog):
|
||||||
path_to_file = self.get_filename()
|
path_to_file = self.get_filename()
|
||||||
if not path_to_file:
|
if not path_to_file:
|
||||||
return
|
return
|
||||||
path_to_file = gtkgui_helpers.decode_filechooser_file_paths(
|
|
||||||
(path_to_file,))[0]
|
|
||||||
if os.path.exists(path_to_file):
|
if os.path.exists(path_to_file):
|
||||||
if isinstance(callback, tuple):
|
if isinstance(callback, tuple):
|
||||||
callback[0](widget, path_to_file, *callback[1:])
|
callback[0](widget, path_to_file, *callback[1:])
|
||||||
|
@ -4892,8 +4885,6 @@ class ArchiveChooserDialog(FileChooserDialog):
|
||||||
path_to_file = self.get_filename()
|
path_to_file = self.get_filename()
|
||||||
if not path_to_file:
|
if not path_to_file:
|
||||||
return
|
return
|
||||||
path_to_file = gtkgui_helpers.decode_filechooser_file_paths(
|
|
||||||
(path_to_file,))[0]
|
|
||||||
if os.path.exists(path_to_file):
|
if os.path.exists(path_to_file):
|
||||||
if isinstance(callback, tuple):
|
if isinstance(callback, tuple):
|
||||||
callback[0](path_to_file, *callback[1:])
|
callback[0](path_to_file, *callback[1:])
|
||||||
|
|
|
@ -297,8 +297,6 @@ class FileTransfersWindow:
|
||||||
def on_ok(widget):
|
def on_ok(widget):
|
||||||
file_dir = None
|
file_dir = None
|
||||||
files_path_list = dialog.get_filenames()
|
files_path_list = dialog.get_filenames()
|
||||||
files_path_list = gtkgui_helpers.decode_filechooser_file_paths(
|
|
||||||
files_path_list)
|
|
||||||
text_buffer = desc_entry.get_buffer()
|
text_buffer = desc_entry.get_buffer()
|
||||||
desc = text_buffer.get_text(text_buffer.get_start_iter(),
|
desc = text_buffer.get_text(text_buffer.get_start_iter(),
|
||||||
text_buffer.get_end_iter(), True)
|
text_buffer.get_end_iter(), True)
|
||||||
|
@ -379,8 +377,6 @@ class FileTransfersWindow:
|
||||||
def on_file_request_accepted(self, account, contact, file_props):
|
def on_file_request_accepted(self, account, contact, file_props):
|
||||||
def on_ok(widget, account, contact, file_props):
|
def on_ok(widget, account, contact, file_props):
|
||||||
file_path = dialog2.get_filename()
|
file_path = dialog2.get_filename()
|
||||||
file_path = gtkgui_helpers.decode_filechooser_file_paths(
|
|
||||||
(file_path,))[0]
|
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
# check if we have write permissions
|
# check if we have write permissions
|
||||||
if not os.access(file_path, os.W_OK):
|
if not os.access(file_path, os.W_OK):
|
||||||
|
|
|
@ -679,30 +679,6 @@ def make_pixbuf_grayscale(pixbuf):
|
||||||
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
|
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
|
||||||
return pixbuf2
|
return pixbuf2
|
||||||
|
|
||||||
def decode_filechooser_file_paths(file_paths):
|
|
||||||
"""
|
|
||||||
Decode as UTF-8 under Windows and ask sys.getfilesystemencoding() in POSIX
|
|
||||||
file_paths MUST be LIST
|
|
||||||
"""
|
|
||||||
file_paths_list = list()
|
|
||||||
|
|
||||||
if os.name == 'nt': # decode as UTF-8 under Windows
|
|
||||||
for file_path in file_paths:
|
|
||||||
file_path = file_path.decode('utf8')
|
|
||||||
file_paths_list.append(file_path)
|
|
||||||
else:
|
|
||||||
for file_path in file_paths:
|
|
||||||
try:
|
|
||||||
file_path = file_path.decode(sys.getfilesystemencoding())
|
|
||||||
except Exception:
|
|
||||||
try:
|
|
||||||
file_path = file_path
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
file_paths_list.append(file_path)
|
|
||||||
|
|
||||||
return file_paths_list
|
|
||||||
|
|
||||||
def escape_underscore(s):
|
def escape_underscore(s):
|
||||||
"""
|
"""
|
||||||
Escape underlines to prevent them from being interpreted as keyboard
|
Escape underlines to prevent them from being interpreted as keyboard
|
||||||
|
@ -771,7 +747,6 @@ def on_avatar_save_as_menuitem_activate(widget, jid, default_name=''):
|
||||||
|
|
||||||
def on_ok(widget):
|
def on_ok(widget):
|
||||||
file_path = dialog.get_filename()
|
file_path = dialog.get_filename()
|
||||||
file_path = decode_filechooser_file_paths((file_path,))[0]
|
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
# check if we have write permissions
|
# check if we have write permissions
|
||||||
if not os.access(file_path, os.W_OK):
|
if not os.access(file_path, os.W_OK):
|
||||||
|
|
Loading…
Reference in New Issue