mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
9c540f557a
commit
96656a1f2d
@ -95,28 +95,22 @@ class FileDialog(QObject):
|
|||||||
initial_dir = select_initial_dir(initial_dir)
|
initial_dir = select_initial_dir(initial_dir)
|
||||||
self.selected_files = []
|
self.selected_files = []
|
||||||
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
|
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
|
||||||
with sanitize_env_vars():
|
with sanitize_env_vars(), adapt_menubar:
|
||||||
opts = QFileDialog.Option(0)
|
opts = QFileDialog.Option(0)
|
||||||
if not use_native_dialog:
|
if not use_native_dialog:
|
||||||
opts |= QFileDialog.Option.DontUseNativeDialog
|
opts |= QFileDialog.Option.DontUseNativeDialog
|
||||||
if has_long_filter:
|
if has_long_filter:
|
||||||
opts |= QFileDialog.Option.HideNameFilterDetails
|
opts |= QFileDialog.Option.HideNameFilterDetails
|
||||||
if mode == QFileDialog.FileMode.AnyFile:
|
if mode == QFileDialog.FileMode.AnyFile:
|
||||||
with adapt_menubar:
|
f = QFileDialog.getSaveFileName(parent, title, initial_dir, ftext, "", opts)
|
||||||
f = QFileDialog.getSaveFileName(parent, title,
|
|
||||||
initial_dir, ftext, "", opts)
|
|
||||||
if f and f[0]:
|
if f and f[0]:
|
||||||
self.selected_files.append(f[0])
|
self.selected_files.append(f[0])
|
||||||
elif mode == QFileDialog.FileMode.ExistingFile:
|
elif mode == QFileDialog.FileMode.ExistingFile:
|
||||||
with adapt_menubar:
|
f = QFileDialog.getOpenFileName(parent, title, initial_dir, ftext, "", opts)
|
||||||
f = QFileDialog.getOpenFileName(parent, title,
|
|
||||||
initial_dir, ftext, "", opts)
|
|
||||||
if f and f[0] and os.path.exists(f[0]):
|
if f and f[0] and os.path.exists(f[0]):
|
||||||
self.selected_files.append(f[0])
|
self.selected_files.append(f[0])
|
||||||
elif mode == QFileDialog.FileMode.ExistingFiles:
|
elif mode == QFileDialog.FileMode.ExistingFiles:
|
||||||
with adapt_menubar:
|
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, ftext, "", opts)
|
||||||
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
|
|
||||||
ftext, "", opts)
|
|
||||||
if fs and fs[0]:
|
if fs and fs[0]:
|
||||||
for f in fs[0]:
|
for f in fs[0]:
|
||||||
f = str(f)
|
f = str(f)
|
||||||
@ -131,8 +125,7 @@ class FileDialog(QObject):
|
|||||||
else:
|
else:
|
||||||
if mode == QFileDialog.FileMode.Directory:
|
if mode == QFileDialog.FileMode.Directory:
|
||||||
opts |= QFileDialog.Option.ShowDirsOnly
|
opts |= QFileDialog.Option.ShowDirsOnly
|
||||||
with adapt_menubar:
|
f = str(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
|
||||||
f = str(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
|
|
||||||
if os.path.exists(f):
|
if os.path.exists(f):
|
||||||
self.selected_files.append(f)
|
self.selected_files.append(f)
|
||||||
if self.selected_files:
|
if self.selected_files:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user