Skip to content

Commit

Permalink
Change tab name to be callable for normalizeFlat (#456)
Browse files Browse the repository at this point in the history
* Change tab name to be callable for normalizeFlat

* nitpick - dangling whitespace in string before eol
  • Loading branch information
teald committed May 9, 2024
1 parent 819f72f commit 3811c70
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion geminidr/core/primitives_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3486,7 +3486,7 @@ def reconstruct_points(ui_params):

visualizer = fit1d.Fit1DVisualizer(reconstruct_points,
all_fp_init,
tab_name_fmt="Array {}",
tab_name_fmt=lambda i: f"Array {i}",
xlabel=xaxis_label, ylabel='counts',
domains=all_domains,
title="Normalize Flat",
Expand Down
20 changes: 20 additions & 0 deletions geminidr/interactive/fit/fit1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,26 @@ def kickoff_modal(attr, old, new):
extra_masks=extra_masks,
)

# tab_name_fmt is expected to be a callable, which traditionally is
# just an anonymous function passed to the relevant visualizer as
# an argument.
if not callable(tab_name_fmt):
msg = (
f"tab_name_fmt must be callable, but got "
f"{type(tab_name_fmt)} ({tab_name_fmt})."
)

if isinstance(tab_name_fmt, str):
msg += (
" If you want to use a string, you should use "
"a lambda function like:\n"
" tab_name_fmt = lambda i: f'Extension {i}'\n"
"or, if you want to ignore the argument, use:\n"
" tab_name_fmt = lambda _: 'Extension'"
)

raise ValueError(msg)

if turbo_tabs:
self.turbo.add_tab(tui.component, title=str(tab_name_fmt(i)))

Expand Down

0 comments on commit 3811c70

Please sign in to comment.