Skip to content

Commit

Permalink
QFileDialog: use keyword arguments
Browse files Browse the repository at this point in the history
Note: I dropped caption="" in most places, because that's the default, though I think we should set one in most cases, this will need further work.
  • Loading branch information
zas committed May 29, 2024
1 parent b67b606 commit c796280
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 18 deletions.
14 changes: 12 additions & 2 deletions picard/script/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ def export_script(self, parent=None):

dialog_title = _("Export Script File")
dialog_file_types = self._get_dialog_filetypes()
filename, file_type = QtWidgets.QFileDialog.getSaveFileName(parent, dialog_title, default_path, dialog_file_types)
filename, file_type = QtWidgets.QFileDialog.getSaveFileName(
parent=parent,
caption=dialog_title,
directory=default_path,
filter=dialog_file_types,
)
if not filename:
return False
# Fix issue where Qt may set the extension twice
Expand Down Expand Up @@ -259,7 +264,12 @@ def import_script(cls, parent=None):
dialog_title = _("Import Script File")
dialog_file_types = cls._get_dialog_filetypes()
default_script_directory = os.path.normpath(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.StandardLocation.DocumentsLocation))
filename, file_type = QtWidgets.QFileDialog.getOpenFileName(parent, dialog_title, default_script_directory, dialog_file_types)
filename, file_type = QtWidgets.QFileDialog.getOpenFileName(
parent=parent,
caption=dialog_title,
directory=default_script_directory,
filter=dialog_file_types,
)
if not filename:
return None
log.debug("Importing script file: %s", filename)
Expand Down
2 changes: 1 addition & 1 deletion picard/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ def lookup_cd(self, action):
traceback=self._debug)

def lookup_discid_from_logfile(self):
file_chooser = QtWidgets.QFileDialog(self.window)
file_chooser = QtWidgets.QFileDialog(parent=self.window)
file_chooser.setNameFilters([
_("All supported log files") + " (*.log *.txt)",
_("EAC / XLD / Whipper / fre:ac log files") + " (*.log)",
Expand Down
2 changes: 1 addition & 1 deletion picard/ui/coverartbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def _try_load_remote_image(self, url, data):
return coverartimage

def choose_local_file(self):
file_chooser = QtWidgets.QFileDialog(self)
file_chooser = QtWidgets.QFileDialog(parent=self)
extensions = ['*' + ext for ext in imageinfo.get_supported_extensions()]
extensions.sort()
file_chooser.setNameFilters([
Expand Down
4 changes: 2 additions & 2 deletions picard/ui/logview.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ def _format(self, level):

def _save_log_as_do(self):
path, ok = QtWidgets.QFileDialog.getSaveFileName(
self,
parent=self,
caption=_("Save Log View to File"),
options=QtWidgets.QFileDialog.Option.DontConfirmOverwrite
options=QtWidgets.QFileDialog.Option.DontConfirmOverwrite,
)
if ok and path:
if os.path.isfile(path):
Expand Down
16 changes: 13 additions & 3 deletions picard/ui/mainwindow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ def add_files(self):
extensions.sort()
formats.insert(0, _("All supported formats") + " (%s)" % " ".join(extensions))
formats.insert(1, _("All files") + " (*)")
files, _filter = QtWidgets.QFileDialog.getOpenFileNames(self, "", current_directory, ";;".join(formats))
files, _filter = QtWidgets.QFileDialog.getOpenFileNames(
parent=self,
directory=current_directory,
filter=";;".join(formats),
)
if files:
config = get_config()
config.persist['current_directory'] = os.path.dirname(files[0])
Expand All @@ -860,11 +864,17 @@ def add_directory(self):
dir_list = []
config = get_config()
if not config.setting['allow_multi_dirs_selection']:
directory = QtWidgets.QFileDialog.getExistingDirectory(self, "", current_directory)
directory = QtWidgets.QFileDialog.getExistingDirectory(
parent=self,
directory=current_directory,
)
if directory:
dir_list.append(directory)
else:
file_dialog = MultiDirsSelectDialog(parent=self, caption="", directory=current_directory)
file_dialog = MultiDirsSelectDialog(
parent=self,
directory=current_directory,
)
if file_dialog.exec() == QtWidgets.QDialog.DialogCode.Accepted:
dir_list = file_dialog.selectedFiles()

Expand Down
5 changes: 4 additions & 1 deletion picard/ui/options/fingerprinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ def update_groupboxes(self):
self._acoustid_fpcalc_check()

def acoustid_fpcalc_browse(self):
path, _filter = QtWidgets.QFileDialog.getOpenFileName(self, "", self.ui.acoustid_fpcalc.text())
path, _filter = QtWidgets.QFileDialog.getOpenFileName(
parent=self,
directory=self.ui.acoustid_fpcalc.text(),
)
if path:
path = os.path.normpath(path)
self.ui.acoustid_fpcalc.setText(path)
Expand Down
5 changes: 4 additions & 1 deletion picard/ui/options/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ def save(self):

def starting_directory_browse(self):
item = self.ui.starting_directory_path
path = QtWidgets.QFileDialog.getExistingDirectory(self, "", item.text())
path = QtWidgets.QFileDialog.getExistingDirectory(
parent=self,
directory=item.text(),
)
if path:
path = os.path.normpath(path)
item.setText(path)
Expand Down
5 changes: 4 additions & 1 deletion picard/ui/options/interface_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ def restore_defaults(self):

def starting_directory_browse(self):
item = self.ui.starting_directory_path
path = QtWidgets.QFileDialog.getExistingDirectory(self, "", item.text())
path = QtWidgets.QFileDialog.getExistingDirectory(
parent=self,
directory=item.text(),
)
if path:
path = os.path.normpath(path)
item.setText(path)
Expand Down
5 changes: 4 additions & 1 deletion picard/ui/options/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def _dialog_invalid_backup_dir(self, path):
dialog.exec()

def _dialog_autobackup_dir_browse(self):
path = QtWidgets.QFileDialog.getExistingDirectory(self, "", self.get_current_autobackup_dir())
path = QtWidgets.QFileDialog.getExistingDirectory(
parent=self,
directory=self.get_current_autobackup_dir(),
)
if path:
self.set_current_autobackup_dir(path)

Expand Down
7 changes: 3 additions & 4 deletions picard/ui/options/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,9 @@ def change_details(self):

def open_plugins(self):
files, _filter = QtWidgets.QFileDialog.getOpenFileNames(
self,
"",
QtCore.QDir.homePath(),
"Picard plugin (*.py *.pyc *.zip)"
parent=self,
directory=QtCore.QDir.homePath(),
filter="Picard plugin (*.py *.pyc *.zip)",
)
if files:
for path in files:
Expand Down
5 changes: 4 additions & 1 deletion picard/ui/options/renaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ def display_error(self, error):
super().display_error(error)

def move_files_to_browse(self):
path = QtWidgets.QFileDialog.getExistingDirectory(self, "", self.ui.move_files_to.text())
path = QtWidgets.QFileDialog.getExistingDirectory(
parent=self,
directory=self.ui.move_files_to.text(),
)
if path:
path = os.path.normpath(path)
self.ui.move_files_to.setText(path)
Expand Down

0 comments on commit c796280

Please sign in to comment.