From 5d883c2569058c75a2d3727b9b2a5697419394d0 Mon Sep 17 00:00:00 2001 From: Pekka T Savolainen Date: Wed, 4 Dec 2024 16:15:16 +0200 Subject: [PATCH] Add helper function to browse for root directory Re #3020 --- spinetoolbox/helpers.py | 16 ++++++++++++++++ spinetoolbox/widgets/settings_widget.py | 10 +++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/spinetoolbox/helpers.py b/spinetoolbox/helpers.py index 36a421f46..bb5a9edff 100644 --- a/spinetoolbox/helpers.py +++ b/spinetoolbox/helpers.py @@ -954,6 +954,22 @@ def select_certificate_directory(parent, line_edit): line_edit.setText(answer) +def select_root_directory(parent, line_edit): + """Shows file browser and inserts selected root directory to given line edit. + Used in Tool Properties. + + Args: + parent (QWidget, optional): Parent of QFileDialog + line_edit (QLineEdit): Line edit where the selected path will be inserted + """ + current_path = get_current_path(line_edit) + initial_path = current_path if current_path is not None else home_dir() + answer = QFileDialog.getExistingDirectory(parent, "Select root directory", initial_path) + if not answer: + return + line_edit.setText(answer) + + def get_current_path(le): """Returns the text in the given line edit. If no text, returns the placeholder text if it is a valid path. If it's not a valid path, diff --git a/spinetoolbox/widgets/settings_widget.py b/spinetoolbox/widgets/settings_widget.py index 5b9a6e429..cc4545188 100644 --- a/spinetoolbox/widgets/settings_widget.py +++ b/spinetoolbox/widgets/settings_widget.py @@ -168,14 +168,14 @@ def read_settings(self): snap_entities = self._qsettings.value("appSettings/snapEntities", defaultValue="false") merge_dbs = self._qsettings.value("appSettings/mergeDBs", defaultValue="true") db_editor_show_undo = int(self._qsettings.value("appSettings/dbEditorShowUndo", defaultValue="2")) - max_ent_dim_count = int(self.qsettings.value("appSettings/maxEntityDimensionCount", defaultValue="5")) - build_iters = int(self.qsettings.value("appSettings/layoutAlgoBuildIterations", defaultValue="12")) - spread_factor = int(self.qsettings.value("appSettings/layoutAlgoSpreadFactor", defaultValue="100")) - neg_weight_exp = int(self.qsettings.value("appSettings/layoutAlgoNegWeightExp", defaultValue="2")) + max_ent_dim_count = int(self._qsettings.value("appSettings/maxEntityDimensionCount", defaultValue="5")) + build_iters = int(self._qsettings.value("appSettings/layoutAlgoBuildIterations", defaultValue="12")) + spread_factor = int(self._qsettings.value("appSettings/layoutAlgoSpreadFactor", defaultValue="100")) + neg_weight_exp = int(self._qsettings.value("appSettings/layoutAlgoNegWeightExp", defaultValue="2")) if commit_at_exit == 0: # Not needed but makes the code more readable. self.ui.checkBox_commit_at_exit.setCheckState(Qt.CheckState.Unchecked) elif commit_at_exit == 1: - self.ui.checkBox_commit_at_exit.setCheckState(Qt.PartiallyChecked) + self.ui.checkBox_commit_at_exit.setCheckState(Qt.CheckState.PartiallyChecked) else: # commit_at_exit == "2": self.ui.checkBox_commit_at_exit.setCheckState(Qt.CheckState.Checked) self.ui.checkBox_entity_tree_sticky_selection.setChecked(sticky_selection == "true")