From 10c5c53fc3c64495950b34d327483afe242a067b Mon Sep 17 00:00:00 2001 From: AssassinTee Date: Thu, 6 Jun 2024 10:00:46 +0200 Subject: [PATCH] fix wrong lambda, use a handler factory instead for more clarity --- src/dialogs/dialog_config_settings.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/dialogs/dialog_config_settings.py b/src/dialogs/dialog_config_settings.py index e9bc634..04e0881 100644 --- a/src/dialogs/dialog_config_settings.py +++ b/src/dialogs/dialog_config_settings.py @@ -27,7 +27,8 @@ def __init__(self, *args): q_label = QLabel(label) self.layout.addWidget(q_label, index, 0) self.layout.addWidget(config_button, index, 1) - config_button.clicked.connect(lambda: self.browseSetting(config, q_label, config_button, filemode)) + handler = self.createBrowseSettingHandler(config, q_label.text(), config_button, filemode) + config_button.clicked.connect(handler) q_btn = QDialogButtonBox.StandardButton.Ok @@ -38,7 +39,13 @@ def __init__(self, *args): self.setModal(True) - def browseSetting(self, setting: str, q_label: QLabel, config_button: QPushButton, filemode: QFileDialog.FileMode): + def createBrowseSettingHandler(self, setting: str, text: str, config_button: QPushButton, + filemode: QFileDialog.FileMode): + def handler(): + self.browseSetting(setting, text, config_button, filemode) + return handler + + def browseSetting(self, setting: str, text: str, config_button: QPushButton, filemode: QFileDialog.FileMode): value = ConfigManager.config()[setting] if not value: directory = os.getcwd() @@ -46,9 +53,12 @@ def browseSetting(self, setting: str, q_label: QLabel, config_button: QPushButto directory = Path(value).parent if Path(value).is_file() else ( value if Path(value).is_dir() else os.getcwd()) - dialog = QFileDialog(self) + dialog = QFileDialog(self, caption=text) dialog.setFileMode(filemode) - path, _ = dialog.getOpenFileName(self, q_label.text(), str(directory)) - if path: - ConfigManager.setConfig(setting, path) - config_button.setText(path) + dialog.setDirectory(str(directory)) + if dialog.exec(): + paths = dialog.selectedFiles() + if paths: + path = paths[0] + ConfigManager.setConfig(setting, path) + config_button.setText(path)