mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Port use of QFileDialog since the return type of the static methods has changed in PyQt5
This commit is contained in:
parent
43aaa3f0d0
commit
fc2842108c
@ -666,28 +666,29 @@ class FileDialog(QObject):
|
|||||||
if not use_native_dialog:
|
if not use_native_dialog:
|
||||||
opts |= QFileDialog.DontUseNativeDialog
|
opts |= QFileDialog.DontUseNativeDialog
|
||||||
if mode == QFileDialog.AnyFile:
|
if mode == QFileDialog.AnyFile:
|
||||||
f = unicode(QFileDialog.getSaveFileName(parent, title,
|
f = QFileDialog.getSaveFileName(parent, title,
|
||||||
initial_dir, ftext, "", opts))
|
initial_dir, ftext, "", opts)
|
||||||
if f:
|
if f and f[0]:
|
||||||
self.selected_files.append(f)
|
self.selected_files.append(f[0])
|
||||||
elif mode == QFileDialog.ExistingFile:
|
elif mode == QFileDialog.ExistingFile:
|
||||||
f = unicode(QFileDialog.getOpenFileName(parent, title,
|
f = QFileDialog.getOpenFileName(parent, title,
|
||||||
initial_dir, ftext, "", opts))
|
initial_dir, ftext, "", opts)
|
||||||
if f and os.path.exists(f):
|
if f and f[0] and os.path.exists(f[0]):
|
||||||
self.selected_files.append(f)
|
self.selected_files.append(f[0])
|
||||||
elif mode == QFileDialog.ExistingFiles:
|
elif mode == QFileDialog.ExistingFiles:
|
||||||
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
|
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
|
||||||
ftext, "", opts)
|
ftext, "", opts)
|
||||||
for f in fs:
|
if fs and fs[0]:
|
||||||
f = unicode(f)
|
for f in fs[0]:
|
||||||
if not f:
|
f = unicode(f)
|
||||||
continue
|
if not f:
|
||||||
if not os.path.exists(f):
|
continue
|
||||||
# QFileDialog for some reason quotes spaces
|
if not os.path.exists(f):
|
||||||
# on linux if there is more than one space in a row
|
# QFileDialog for some reason quotes spaces
|
||||||
f = unquote(f)
|
# on linux if there is more than one space in a row
|
||||||
if f and os.path.exists(f):
|
f = unquote(f)
|
||||||
self.selected_files.append(f)
|
if f and os.path.exists(f):
|
||||||
|
self.selected_files.append(f)
|
||||||
else:
|
else:
|
||||||
if mode == QFileDialog.Directory:
|
if mode == QFileDialog.Directory:
|
||||||
opts |= QFileDialog.ShowDirsOnly
|
opts |= QFileDialog.ShowDirsOnly
|
||||||
|
@ -9,11 +9,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
from PyQt5.Qt import QNetworkCookieJar, QFileDialog, QNetworkProxy
|
from PyQt5.Qt import QNetworkCookieJar, QNetworkProxy
|
||||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||||
|
|
||||||
from calibre import USER_AGENT, get_proxies, get_download_filename
|
from calibre import USER_AGENT, get_proxies, get_download_filename
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
|
from calibre.gui2 import choose_save_file
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
|
|
||||||
@ -85,13 +86,8 @@ class NPWebView(QWebView):
|
|||||||
'the ADE library folder.'),
|
'the ADE library folder.'),
|
||||||
'acsm_download', self):
|
'acsm_download', self):
|
||||||
return
|
return
|
||||||
home = os.path.expanduser('~')
|
name = choose_save_file(self, 'web-store-download-unknown', _('File is not a supported ebook type. Save to disk?'), initial_filename=filename)
|
||||||
name = QFileDialog.getSaveFileName(self,
|
|
||||||
_('File is not a supported ebook type. Save to disk?'),
|
|
||||||
os.path.join(home, filename),
|
|
||||||
'*.*')
|
|
||||||
if name:
|
if name:
|
||||||
name = unicode(name)
|
|
||||||
self.gui.download_ebook(url, cf, name, name, False)
|
self.gui.download_ebook(url, cf, name, name, False)
|
||||||
else:
|
else:
|
||||||
self.gui.download_ebook(url, cf, filename, tags=self.tags)
|
self.gui.download_ebook(url, cf, filename, tags=self.tags)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user