CID: Disable btnDefault
if no Custom Install Directory path is set
#457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on suggestion in #454 (comment).
This PR disables the "Default" button (
btnDefault
) if no Custom Install Directory has been configured. It also disables the button on click, if it successfully clears the value from the INI (i.e. if after clicking, the Custom Install Directory is successfully removed, togglebtnDefault
enabled/disabled based on thebool
cast of the value in the INI file).The Custom Install Directory path is saved to the ProtonUp-Qt config file, and we can retrieve it using
config_custom_install_location
. I believe this is also responsible for writing out the path as well to the INI file. We can toggle whetherbtnDefault
is enable on dialog load based on ifcustom_install_directory
is defined.custom_install_directory: str = config_custom_install_location().get('install_dir', '')
will retrieve the value ofinstall_dir
based on the value in the INI. If this is not set, trying to fetchinstall_dir
will actually returnNone
. I am not entirely sure why this is, I would've thought calling.get('install_dir', '')
would return''
forFalse
y values, but I guess not. Theconfig_custom_install_location
function can take aninstall_dir
keyword argument and this defaults toinstall_dir=None
, so that's where theNone
comes from. If no Custom Install Directory is set,config_custom_install_location
returnsNone
.Instead of refactoring behaviour in
config_custom_install_location
for this PR and potentially breaking things (i.e. changing the default argument toinstall_dir=''
), I rolled with it and calledsetEnabled
with abool
cast ofcustom_install_directory
. Ifcustom_install_directory
returnsNone
(which it should if there is no Custom Install Directory is set) then we callbool(None)
to toggle the enabled state ofbtnDefault
, which will disable it (bool(None)
isFalse
). Also, ifcustom_install_directory
contained otherFalse
y values like an empty string (''
) (which shouldn't be possible normally, but could happen if a user manually edited their INI file), we would also disablebtnDefault
. I think this is desirable;False
y values should be considered equal to having no Custom Install Directory set, and so should disablebtnDefault
Since this functionality is also used on
btnDefault
click, I broke it out into a method that handles checking if acustom_install_directory
is set to aTruth
y value. This makes the code a bit cleaner, as instead of doing thebool
cast ourselves, we just tellbtnDefault.setEnabled
to toggle based onself.has_custom_install_directory
return value, and that method handles the implementation detail. This also means if we wanted to change this implementation in future it would be more straightforward (e.g. if we ever wanted to validate the path in any way).I have attached some screenshots to show this change.
Before (
main
)After (This PR)
It is also enabled again when a Custom Install Directory is saved and the dialog is re-opened.
Thanks!