-
-
Notifications
You must be signed in to change notification settings - Fork 16
Description
This was brought up by @astrofrog in relation to #93, #126, #131, and spacetelescope/jdaviz#445 .
Need inputs from @mwcraig and @eteq .
Idea (from Tom R)
I think for the single viewer, Imviz, we might want astrowidgets to actually wrap the whole Imviz/JupyterApplication, rather than the viewer instance, where we can get a reference to the viewer to use in the rest of the wrapper.
Imviz here is from spacetelescope/jdaviz#429 :
from astrowidgets import AstroWidgetsWrapper
from jdaviz import Imviz
imviz = Imviz()
imviz_aw = AstroWidgetsWrapper(imviz) # Exposes astrowidgets API
So basically you don’t need to worry about the ipywidgets.VBox stuff. We show the GUI using regular jdaviz and the wrapper just exposes the astrowidgets API and translates it on-the-fly to what is needed for jdaviz but doesn’t deal with any UI aspect (so no mouseover, no VBox, etc).
Pros
UI is now completely handled by the chosen backend, thus freeing astrowidgets of the burden and might make #122 implementation less complicated.
Cons
In the idea above, we won't be able to do the cursor positioning like this anymore:
astrowidgets/astrowidgets/core.py
Lines 857 to 873 in 8fed923
| @cursor.setter | |
| def cursor(self, val): | |
| if val is None: | |
| self._jup_coord.layout.visibility = 'hidden' | |
| self._jup_coord.layout.display = 'none' | |
| elif val == 'top' or val == 'bottom': | |
| self._jup_coord.layout.visibility = 'visible' | |
| self._jup_coord.layout.display = 'flex' | |
| if val == 'top': | |
| self.layout.flex_flow = 'column-reverse' | |
| else: | |
| self.layout.flex_flow = 'column' | |
| else: | |
| raise ValueError('Invalid value {} for cursor.' | |
| 'Valid values are: ' | |
| '{}'.format(val, ALLOWED_CURSOR_LOCATIONS)) | |
| self._cursor = val |
Things like this is also no longer possible:
astrowidgets/astrowidgets/core.py
Lines 169 to 177 in 8fed923
| @property | |
| def image_height(self): | |
| return int(self._jup_img.height) | |
| @image_height.setter | |
| def image_height(self, value): | |
| # widgets expect width/height as strings, but most users will not, so | |
| # do the conversion. | |
| self._jup_img.height = str(value) |
By farming out all GUI controls to backends, while #122 implementation here might be less complicated, it might also not be entirely possible to simply "switch backend" transparently. For instance, Ginga implementation might still rely on VBox and will implement the cursor positioning in its own subclass, which is not available in other backends.