Fix bug where clicking Cancel in the Preferences dialog does not reset widgets #138
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.
This pull request fixes a bug in the Preferences window where Preferences changes are not 'cancelled' when the Cancel button is clicked.
How to reproduce the bug:
For example, change the default layout manager to something else
This puts the Preferences window into an asynchronous state, meaning that the setting was technically not saved (if you close and re-open Pygubu Designer, you'll notice that the setting was not actually saved, which is good). But the preferences window now reflects an incorrect state until you restart Pygubu Designer.
Similarly, when a custom widget .py file gets added to the list (or removed from the list), clicking on 'Cancel' and re-opening the Preferences window will not show the original custom widget list.
Why this bug occurs:
The widgets in the Preferences window are tied to Tk variables. So when the user interacts with any of the widgets, the Tk variables are immediately changed, so even when the user clicks Cancel, the Tk variables have already been changed at that point.
What this pull request does:
Change # 1)
Now when the Cancel button gets clicked (or if the user closes the window from the window manager), it will restore the Tk variables back to what they were before the changes that were made by the user. Similarly, it will now restore the custom widgets list to what it was before the user made any changes to it.
Change # 2)
In the Preferences dialog: when the Preferences dialog closes (Cancel or OK), any combo boxes that had focus will no longer have their text selected/highlighted the next time the preferences window opens. This is primarily a cosmetic/design change.
For example, right now if you the Preferences window and change the default layout manager, click OK.
When you re-open the Preferences window, that combo box will have its text highlighted/selected. This pull request will prevent the combo box from having its text selected when the Preferences dialog opens.