Make it possible to select multiple folders by using non-native QFileDialog

This commit is contained in:
Miguel Jacq 2017-05-21 16:14:32 +10:00
parent d3eeda887b
commit b35e3b76d5
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
3 changed files with 16 additions and 6 deletions

View File

@ -225,10 +225,20 @@ class FileSelection(QtWidgets.QVBoxLayout):
"""
Add folder button clicked.
"""
filename = QtWidgets.QFileDialog.getExistingDirectory(
caption=strings._('gui_choose_folder', True), options=QtWidgets.QFileDialog.ReadOnly)
if filename:
self.file_list.add_file(str(filename))
file_dialog = QtWidgets.QFileDialog(caption=strings._('gui_choose_folder', True))
file_dialog.setFileMode(QtWidgets.QFileDialog.Directory)
file_dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, True)
file_dialog.setOption(QtWidgets.QFileDialog.ReadOnly, True)
file_dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True)
tree_view = file_dialog.findChild(QtWidgets.QTreeView)
tree_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
list_view = file_dialog.findChild(QtWidgets.QListView, "listView")
list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
if file_dialog.exec_() == QtWidgets.QDialog.Accepted:
for filename in file_dialog.selectedFiles():
self.file_list.add_file(filename)
self.update()
def delete_file(self):

View File

@ -24,7 +24,7 @@
"help_filename": "List of files or folders to share",
"gui_drag_and_drop": "Drag and drop\nfiles here",
"gui_add_files": "Add Files",
"gui_add_folder": "Add Folder",
"gui_add_folder": "Add Folders",
"gui_delete": "Delete",
"gui_choose_files": "Choose files",
"gui_choose_folder": "Choose folder",

View File

@ -21,7 +21,7 @@
"help_filename": "Liste des fichiers ou dossiers à partager",
"gui_drag_and_drop": "Glissez déposez\nles fichiers ici",
"gui_add_files": "Ajouter des fichiers",
"gui_add_folder": "Ajouter un dossier",
"gui_add_folder": "Ajouter des dossiers",
"gui_delete": "Supprimer",
"gui_choose_files": "Sélectionnez des fichiers",
"gui_choose_folder": "Sélectionnez un dossier",