Port use of QFileDialog since the return type of the static methods has changed in PyQt5

This commit is contained in:
Kovid Goyal 2014-04-23 12:15:02 +05:30
parent 43aaa3f0d0
commit fc2842108c
2 changed files with 22 additions and 25 deletions

View File

@ -666,19 +666,20 @@ class FileDialog(QObject):
if not use_native_dialog:
opts |= QFileDialog.DontUseNativeDialog
if mode == QFileDialog.AnyFile:
f = unicode(QFileDialog.getSaveFileName(parent, title,
initial_dir, ftext, "", opts))
if f:
self.selected_files.append(f)
f = QFileDialog.getSaveFileName(parent, title,
initial_dir, ftext, "", opts)
if f and f[0]:
self.selected_files.append(f[0])
elif mode == QFileDialog.ExistingFile:
f = unicode(QFileDialog.getOpenFileName(parent, title,
initial_dir, ftext, "", opts))
if f and os.path.exists(f):
self.selected_files.append(f)
f = QFileDialog.getOpenFileName(parent, title,
initial_dir, ftext, "", opts)
if f and f[0] and os.path.exists(f[0]):
self.selected_files.append(f[0])
elif mode == QFileDialog.ExistingFiles:
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
ftext, "", opts)
for f in fs:
if fs and fs[0]:
for f in fs[0]:
f = unicode(f)
if not f:
continue

View File

@ -9,11 +9,12 @@ __docformat__ = 'restructuredtext en'
import os
from urlparse import urlparse
from PyQt5.Qt import QNetworkCookieJar, QFileDialog, QNetworkProxy
from PyQt5.Qt import QNetworkCookieJar, QNetworkProxy
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from calibre import USER_AGENT, get_proxies, get_download_filename
from calibre.ebooks import BOOK_EXTENSIONS
from calibre.gui2 import choose_save_file
from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.filenames import ascii_filename
@ -85,13 +86,8 @@ class NPWebView(QWebView):
'the ADE library folder.'),
'acsm_download', self):
return
home = os.path.expanduser('~')
name = QFileDialog.getSaveFileName(self,
_('File is not a supported ebook type. Save to disk?'),
os.path.join(home, filename),
'*.*')
name = choose_save_file(self, 'web-store-download-unknown', _('File is not a supported ebook type. Save to disk?'), initial_filename=filename)
if name:
name = unicode(name)
self.gui.download_ebook(url, cf, name, name, False)
else:
self.gui.download_ebook(url, cf, filename, tags=self.tags)