diff --git a/pupgui2/pupgui2customiddialog.py b/pupgui2/pupgui2customiddialog.py index 6b7c125b..27183da3 100644 --- a/pupgui2/pupgui2customiddialog.py +++ b/pupgui2/pupgui2customiddialog.py @@ -45,7 +45,10 @@ def setup_ui(self): self.txtIdBrowseAction = self.ui.txtInstallDirectory.addAction(QIcon.fromTheme('document-open'), QLineEdit.TrailingPosition) self.txtIdBrowseAction.triggered.connect(self.txt_id_browse_action_triggered) - self.ui.txtInstallDirectory.setText(config_custom_install_location().get('install_dir', '')) + custom_install_directory = config_custom_install_location().get('install_dir', '') + + self.ui.txtInstallDirectory.setText(custom_install_directory) + self.ui.btnDefault.setEnabled(self.has_custom_install_directory(custom_install_directory)) # Don't enable btnDefault if there is no Custom Install Directory set self.ui.comboLauncher.addItems([ display_name for display_name in self.install_locations_dict.values() @@ -73,7 +76,9 @@ def btn_save_clicked(self): def btn_default_clicked(self): self.ui.txtInstallDirectory.setText('') - config_custom_install_location(remove=True) + + custom_install_directory = config_custom_install_location(remove=True).get('install_dir', '') + self.ui.btnDefault.setEnabled(self.has_custom_install_directory(custom_install_directory)) self.custom_id_set.emit('') @@ -100,3 +105,17 @@ def set_selected_launcher(self, ctool_name: str): def is_valid_custom_install_path(self, path: str) -> bool: expand_path = os.path.expanduser(path) return len(path.strip()) > 0 and os.path.isdir(expand_path) and os.access(expand_path, os.W_OK) + + def has_custom_install_directory(self, custom_install_directory: str = '') -> bool: + + """ + Returns whether a Custom Install Directory is set to a Truthy value. + If `custom_install_directory` is not passed, it will be retrieved. + + Return Type: bool + """ + + if not custom_install_directory: + return bool(config_custom_install_location().get('install_dir', '')) + + return bool(custom_install_directory)