From 13dfe589b96784c3321614cbe2b0ab6e913a9810 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Wed, 29 May 2024 14:14:26 +0200 Subject: [PATCH] Replace class MultiDirsSelectDialog with new FileDialog.getMultipleDirectories() --- picard/ui/mainwindow/__init__.py | 6 +----- picard/ui/util.py | 35 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/picard/ui/mainwindow/__init__.py b/picard/ui/mainwindow/__init__.py index b6899c69ed..91b88c39bb 100644 --- a/picard/ui/mainwindow/__init__.py +++ b/picard/ui/mainwindow/__init__.py @@ -147,7 +147,6 @@ from picard.ui.tagsfromfilenames import TagsFromFileNamesDialog from picard.ui.util import ( FileDialog, - MultiDirsSelectDialog, find_starting_directory, menu_builder, ) @@ -872,13 +871,10 @@ def add_directory(self): if directory: dir_list.append(directory) else: - file_dialog = MultiDirsSelectDialog( + dir_list = FileDialog.getMultipleDirectories( parent=self, - caption=_("Select one or more directories"), directory=current_directory, ) - if file_dialog.exec() == QtWidgets.QDialog.DialogCode.Accepted: - dir_list = file_dialog.selectedFiles() dir_count = len(dir_list) if dir_count: diff --git a/picard/ui/util.py b/picard/ui/util.py index f19d0fff81..b7f1da59b2 100644 --- a/picard/ui/util.py +++ b/picard/ui/util.py @@ -136,26 +136,23 @@ def getExistingDirectory(**kwargs): convert_filedialog_params(kwargs, _("Select a directory")) return QtWidgets.QFileDialog.getExistingDirectory(**kwargs) - -class MultiDirsSelectDialog(FileDialog): - - """Custom file selection dialog which allows the selection - of multiple directories. - Depending on the platform, dialog may fallback on non-native. - """ - - def __init__(self, parent=None, caption="", directory="", filter=""): - super().__init__(parent=parent, caption=caption, directory=directory, filter=filter) - self.setFileMode(QtWidgets.QFileDialog.FileMode.Directory) - self.setOption(QtWidgets.QFileDialog.Option.ShowDirsOnly) + @staticmethod + def getMultipleDirectories(parent=None, caption="", directory="", filter=""): + """Custom file selection dialog which allows the selection + of multiple directories. + Depending on the platform, dialog may fallback on non-native. + """ + if not caption: + caption = _("Select one or more directories") + file_dialog = FileDialog(parent=parent, caption=caption, directory=directory, filter=filter) + file_dialog.setFileMode(QtWidgets.QFileDialog.FileMode.Directory) + file_dialog.setOption(QtWidgets.QFileDialog.Option.ShowDirsOnly) # The native dialog doesn't allow selecting >1 directory - self.setOption(QtWidgets.QFileDialog.Option.DontUseNativeDialog) - for view in self.findChildren((QtWidgets.QListView, QtWidgets.QTreeView)): + file_dialog.setOption(QtWidgets.QFileDialog.Option.DontUseNativeDialog) + for view in file_dialog.findChildren((QtWidgets.QListView, QtWidgets.QTreeView)): if isinstance(view.model(), QtGui.QFileSystemModel): view.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection) - self.set_sidebar_locations() - def set_sidebar_locations(self): # Allow access to all mounted drives in the sidebar root_volume = "/" volume_paths = [] @@ -172,7 +169,11 @@ def set_sidebar_locations(self): QtCore.QDir.homePath(), QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.StandardLocation.MusicLocation), ] - self.setSidebarUrls(QtCore.QUrl.fromLocalFile(p) for p in paths + sorted(volume_paths) if p) + file_dialog.setSidebarUrls(QtCore.QUrl.fromLocalFile(p) for p in paths + sorted(volume_paths) if p) + dirs = () + if file_dialog.exec() == QtWidgets.QDialog.DialogCode.Accepted: + dirs = file_dialog.selectedFiles() + return tuple(dirs) def qlistwidget_items(qlistwidget):