From 3ff4708ee99825ac8d83ae0a872a723cc7f1f2e9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 14 Jul 2012 13:48:06 +0530 Subject: [PATCH] Add env var to not use native file dialogs --- manual/customize.rst | 1 + src/calibre/gui2/__init__.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/manual/customize.rst b/manual/customize.rst index e2e2825de6..ceee4ece62 100644 --- a/manual/customize.rst +++ b/manual/customize.rst @@ -30,6 +30,7 @@ Environment variables * ``CALIBRE_OVERRIDE_DATABASE_PATH`` - allows you to specify the full path to metadata.db. Using this variable you can have metadata.db be in a location other than the library folder. Useful if your library folder is on a networked drive that does not support file locking. * ``CALIBRE_DEVELOP_FROM`` - Used to run from a calibre development environment. See :ref:`develop`. * ``CALIBRE_OVERRIDE_LANG`` - Used to force the language used by the interface (ISO 639 language code) + * ``CALIBRE_NO_NATIVE_FILEDIALOGS`` - Causes calibre to not use native file dialogs for selecting files/directories. * ``SYSFS_PATH`` - Use if sysfs is mounted somewhere other than /sys * ``http_proxy`` - Used on linux to specify an HTTP proxy diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 370e2dc993..00f5bef03d 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -573,17 +573,24 @@ class FileDialog(QObject): if not isinstance(initial_dir, basestring): initial_dir = os.path.expanduser(default_dir) self.selected_files = [] + use_native_dialog = not os.environ.has_key('CALIBRE_NO_NATIVE_FILEDIALOGS') with SanitizeLibraryPath(): + opts = QFileDialog.Option() + if not use_native_dialog: + opts |= QFileDialog.DontUseNativeDialog if mode == QFileDialog.AnyFile: - f = unicode(QFileDialog.getSaveFileName(parent, title, initial_dir, ftext, "")) + f = unicode(QFileDialog.getSaveFileName(parent, title, + initial_dir, ftext, "", opts)) if f: self.selected_files.append(f) elif mode == QFileDialog.ExistingFile: - f = unicode(QFileDialog.getOpenFileName(parent, title, initial_dir, ftext, "")) + f = unicode(QFileDialog.getOpenFileName(parent, title, + initial_dir, ftext, "", opts)) if f and os.path.exists(f): self.selected_files.append(f) elif mode == QFileDialog.ExistingFiles: - fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, ftext, "") + fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, + ftext, "", opts) for f in fs: f = unicode(f) if not f: continue @@ -594,7 +601,8 @@ class FileDialog(QObject): if f and os.path.exists(f): self.selected_files.append(f) else: - opts = QFileDialog.ShowDirsOnly if mode == QFileDialog.Directory else QFileDialog.Option() + if mode == QFileDialog.Directory: + opts |= QFileDialog.ShowDirsOnly f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts)) if os.path.exists(f): self.selected_files.append(f)