Skip to content

Commit

Permalink
Merge pull request #355 from mwcraig/fix-ugly-checkbox
Browse files Browse the repository at this point in the history
Move "show details" checkbox next to dropdown
  • Loading branch information
mwcraig authored May 22, 2024
2 parents 62d39e7 + b165d93 commit 6a3ad24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 18 additions & 3 deletions stellarphot/settings/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,30 @@ def __init__(
value=(f"<h2>Choose a {self._display_name} " "or make a new one</h2>")
)

self._choose_detail_container = ipw.HBox(layout={"width": DEFAULT_BUTTON_WIDTH})

# Selector for existing items or to make a new one
self._choose_existing = ipw.Dropdown(description="")
choose_width = 75 # percent, the details checkbox takes up the rest
self._choose_existing.layout.width = (
f"{choose_width}%" if details_hideable else "100%"
)

# Option to show/hide details, only displayed if user wants it.
self._show_details_ui = ipw.Checkbox(description="Show details", value=True)
self._show_details_ui = ipw.Checkbox(description="Details", value=True)
self._show_details_ui.layout.display = "flex" if details_hideable else "none"
# Removes unused whitespace before the checkbox
self._show_details_ui.style.description_width = "0px"

if details_hideable:
self._show_details_ui.layout.width = f"{100 - choose_width}%"
self._show_details_cached_value = self._show_details_ui.value

self._choose_detail_container.children = [
self._choose_existing,
self._show_details_ui,
]

self._edit_delete_container = ipw.HBox(
# width below was chosen to match the dropdown...would prefer to
# determine this programmatically but don't know how.
Expand Down Expand Up @@ -117,8 +133,7 @@ def __init__(
# Build the main widget
self.children = [
self._title,
self._choose_existing,
self._show_details_ui,
self._choose_detail_container,
self._details_box,
]

Expand Down
5 changes: 4 additions & 1 deletion stellarphot/settings/tests/test_custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ def test_details_hideable_or_not(self, tmp_path, hideable):
)

# New UI element should be in the big box
assert choose_or_make_new._show_details_ui in choose_or_make_new.children
assert (
choose_or_make_new._show_details_ui
in choose_or_make_new._choose_detail_container.children
)

if hideable:
# The "show/hide details" widget should be visible
Expand Down

0 comments on commit 6a3ad24

Please sign in to comment.