Skip to content

Commit

Permalink
Add helper function to browse for root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavol committed Dec 4, 2024
1 parent ca3e446 commit 5d883c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions spinetoolbox/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions spinetoolbox/widgets/settings_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5d883c2

Please sign in to comment.