Skip to content

Commit

Permalink
If the path is changed to an invalid directory, dispplay a warning an…
Browse files Browse the repository at this point in the history
…d revert back to last valid path
  • Loading branch information
zas committed Apr 24, 2024
1 parent 2a986cd commit f26a74f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion picard/ui/options/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,41 @@ def __init__(self, parent=None):
self.ui.save_backup_button.clicked.connect(self.save_backup)
self.ui.load_backup_button.clicked.connect(self.load_backup)
self.ui.browse_autobackup_dir.clicked.connect(self._dialog_autobackup_dir_browse)
self.ui.autobackup_dir.editingFinished.connect(self._check_autobackup_dir)

# Set the palette of the config file QLineEdit widget to inactive.
palette_normal = self.ui.config_file.palette()
palette_readonly = QtGui.QPalette(palette_normal)
disabled_color = palette_normal.color(QtGui.QPalette.ColorGroup.Inactive, QtGui.QPalette.ColorRole.Window)
palette_readonly.setColor(QtGui.QPalette.ColorRole.Base, disabled_color)
self.ui.config_file.setPalette(palette_readonly)
self.last_valid_path = _safe_autobackup_dir('')

def get_current_autobackup_dir(self):
return _safe_autobackup_dir(self.ui.autobackup_dir.text())

def set_current_autobackup_dir(self, path):
self.ui.autobackup_dir.setText(_safe_autobackup_dir(path))
self.last_valid_path = _safe_autobackup_dir(path)
self.ui.autobackup_dir.setText(self.last_valid_path)

def _check_autobackup_dir(self):
path = self.ui.autobackup_dir.text()
if not path or not os.path.isdir(path):
self._dialog_invalid_backup_dir(path)
else:
self.last_valid_path = _safe_autobackup_dir(path)
self.ui.autobackup_dir.setText(self.last_valid_path)

def _dialog_invalid_backup_dir(self, path):
dialog = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Icon.Critical,
_("Configuration File Backup Directory Error"),
_("The path provided isn't a valid directory, reverting to:\n"
"%s\n") % self.last_valid_path,
QtWidgets.QMessageBox.StandardButton.Ok,
self,
)
dialog.exec()

def _dialog_autobackup_dir_browse(self):
path = QtWidgets.QFileDialog.getExistingDirectory(self, "", self.get_current_autobackup_dir())
Expand Down

0 comments on commit f26a74f

Please sign in to comment.