Skip to content

Commit

Permalink
helper method to programmatically toggle API hints
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 4, 2024
1 parent 2566a82 commit a9f3ba0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/plugin_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ For example:
plugin.open_in_tray()
plugin.show('popout')
When running in a notebook, some plugins provide API hints directly in the UI. To enable these, toggle the ``<>`` button in the top of the plugin.
When running in a notebook, some plugins provide API hints directly in the UI. To enable these, toggle the ``<>`` button on the top bar of the app or call:

.. code-block:: python
viz.toggle_api_hints()
14 changes: 14 additions & 0 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,20 @@ def show_in_new_tab(self, title=None): # pragma: no cover
DeprecationWarning)
return self.show(loc="sidecar:tab-after", title=title)

def toggle_api_hints(self, enabled=None):
"""
Toggle the visibility of API hints in the application.
Parameters
----------
enabled : bool, optional
If `True`, show API hints. If `False`, hide API hints.
If `None`, toggle the current state.
"""
if enabled is None:
enabled = not self.app.state.show_api_hints
self.app.state.show_api_hints = enabled

def _handle_display_units(self, data, use_display_units=True):
if use_display_units:
if isinstance(data, Spectrum1D):
Expand Down
10 changes: 10 additions & 0 deletions jdaviz/tests/test_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ def test_specviz_data_labels(specviz_helper, spectrum1d):
assert specviz_helper.data_labels == [label]
assert specviz_helper.viewers['spectrum-viewer'].data_labels_loaded == [label]
assert specviz_helper.viewers['spectrum-viewer'].data_labels_visible == [label]


def test_toggle_api_hints(specviz_helper):
assert specviz_helper.app.state.show_api_hints is False
specviz_helper.app.toggle_api_hints()
assert specviz_helper.app.state.show_api_hints is True
specviz_helper.app.toggle_api_hints(True)
assert specviz_helper.app.state.show_api_hints is True
specviz_helper.app.toggle_api_hints()
assert specviz_helper.app.state.show_api_hints is False

0 comments on commit a9f3ba0

Please sign in to comment.