Skip to content

Commit

Permalink
CID: Disable btnDefault if no Custom Install Directory path is set (#…
Browse files Browse the repository at this point in the history
…457)

* CID: Disable `btnDefault` if no Custom Install Directory path is set

* CID: Refactor + disable btnDefault on click
  • Loading branch information
sonic2kk authored Sep 20, 2024
1 parent d848220 commit 01dd509
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pupgui2/pupgui2customiddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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('')

Expand All @@ -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)

0 comments on commit 01dd509

Please sign in to comment.