-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better handle disabling widgets when displaying #308
Merged
mwcraig
merged 2 commits into
feder-observatory:main
from
mwcraig:fix-autoui-disabled-state
May 1, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import ipywidgets as ipw | ||
import pytest | ||
from ipyautoui.custom.iterable import ItemBox, ItemControl | ||
|
||
from stellarphot.settings import Camera, Observatory, PassbandMap, SavedSettings | ||
from stellarphot.settings.custom_widgets import ChooseOrMakeNew, Confirm | ||
|
@@ -187,6 +188,36 @@ def test_choosing_different_item_updates_display(self, tmp_path): | |
# The item widget should now have the values of the second observatory | ||
assert Observatory(**choose_or_make_new._item_widget.value) == observatory2 | ||
|
||
def test_passband_map_buttons_are_disabled_or_enabled(self, tmp_path): | ||
# When an existing PassbandMap is selected the add/remove buttons | ||
# for individual rows should not be displayed. | ||
saved = SavedSettings(_testing_path=tmp_path) | ||
passband_map = PassbandMap(**DEFAULT_PASSBAND_MAP) | ||
saved.add_item(passband_map) | ||
|
||
choose_or_make_new = ChooseOrMakeNew("passband_map", _testing_path=tmp_path) | ||
|
||
# There is no great way to get to the ItemBox widget that contains and controls | ||
# the add/remove buttons, so we keep going down through widget children until we | ||
# get to an ItemBox and then check that the buttons are disabled. | ||
# Recursion is the easiest way to do that, so recurse we will.. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, an actual use for recursion that isn't factorials or the Fibonacci sequence or binary search... |
||
def find_item_box(top_widget): | ||
for kid in top_widget.children: | ||
if isinstance(kid, ItemBox): | ||
return kid | ||
if hasattr(kid, "children"): | ||
result = find_item_box(kid) | ||
if result: | ||
return result | ||
|
||
item_box = find_item_box(choose_or_make_new) | ||
assert item_box.add_remove_controls == ItemControl.none | ||
|
||
# Next, we will click the "Edit" button and check that the buttons are enabled. | ||
choose_or_make_new._edit_button.click() | ||
item_box = find_item_box(choose_or_make_new) | ||
assert item_box.add_remove_controls == ItemControl.add_remove | ||
|
||
def test_make_passband_map(self, tmp_path): | ||
# Make a passband map and save it, then check that it is in the dropdown | ||
saved = SavedSettings(_testing_path=tmp_path) | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll admit I am trusting your tests because I don't know
pyautoui
well.