Skip to content

Commit

Permalink
Implement popout location in show() (#1503)
Browse files Browse the repository at this point in the history
* Implement popout args in show

* Codestyle

* Wording suggestions from Code Review

Co-authored-by: P. L. Lim <[email protected]>

* Mention new args in changelog

* Fix noteblock rst rendering

* Grammar and Wording

Co-authored-by: P. L. Lim <[email protected]>

Co-authored-by: Duy Nguyen <[email protected]>
Co-authored-by: P. L. Lim <[email protected]>
  • Loading branch information
3 people authored Jul 22, 2022
1 parent af25340 commit 9e20b50
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
New Features
------------

- New popout locations display Jdaviz in a detached popup window (``popout:window``)
or browser tab (``popout:tab``). [#1503]

Cubeviz
^^^^^^^

Expand Down
19 changes: 19 additions & 0 deletions docs/display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ For example, ``inline`` can be specified manually with::

imviz.show(loc='inline')

Detached Popout
---------------
Jdaviz can also be displayed in a detached window, separate from your working Jupyter interface.

.. note:: Popups must be allowed in your browser to display properly.

The following shows ``jdaviz`` in a new popout window::

imviz.show(loc='popout')

To manually specify the anchor location, append the anchor to popout, separated by a colon::
imviz.show(loc='popout:window')

You can also popout to a new browser tab by specifying a ``tab`` anchor::

imviz.show(loc='popout:tab')


Sidecar (Jupyter Lab)
---------------------

Expand Down
21 changes: 17 additions & 4 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ def show(self, loc="inline", title=None):
See `jupyterlab-sidecar <https://github.com/jupyter-widgets/jupyterlab-sidecar>`_
for the most up-to-date options.
"popout": Display the Jdaviz application in a detached display. By default, a new
window will open. Browser popup permissions required.
Other anchors:
* ``popout:window`` (The default, opens Jdaviz in a new, detached popout)
* ``popout:tab`` (Opens Jdaviz in a new, detached tab in your browser)
title : str, optional
The title of the sidecar tab. Defaults to the name of the
application; e.g., "specviz".
Expand Down Expand Up @@ -342,11 +350,16 @@ def show(self, loc="inline", title=None):
with scar:
display(self.app)

elif loc == "new browser tab":
raise NotImplementedError
elif loc.startswith('popout'):
anchor = None if loc == 'popout' else loc.split(':')[1]

elif loc == "popout":
raise NotImplementedError
# Default behavior (no anchor specified): display popout in new window
if anchor in (None, 'window'):
self.app.popout_button.open_window()
elif anchor == "tab":
self.app.popout_button.open_tab()
else:
raise ValueError("Unrecognized popout anchor")

else:
raise ValueError(f"Unrecognized display location: {loc}")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ install_requires =
regions>=0.6
scikit-image
sidecar>=0.5.1
ipypopout>=0.0.8
ipypopout>=0.0.10

[options.extras_require]
test =
Expand Down

0 comments on commit 9e20b50

Please sign in to comment.