Skip to content

Commit

Permalink
🥅 Add error when exporting the WCS while the widget is reduced when h…
Browse files Browse the repository at this point in the history
…idden
  • Loading branch information
Xen0Xys authored and ManonMarchand committed Aug 1, 2024
1 parent efc8e31 commit 06ae1c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion js/models/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ export default class EventHandler {

this.aladin.on("resizeChanged", (width, height) => {
// Skip resize event when the div is hidden
if (width === 1 && height === 1) return;
if (width === 1 && height === 1) {
this.model.set("_is_reduced", true);
this.model.save_changes();
return;
} else this.model.set("_is_reduced", false);
this.updateWCS();
this.update2AxisFoV();
this.model.set("_height", height);
Expand Down
8 changes: 8 additions & 0 deletions src/ipyaladin/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ class WidgetCommunicationError(OSError):
def __init__(self, message: str) -> None:
self.message = message
super(WidgetCommunicationError, self).__init__(message)


class WidgetReducedError(ValueError):
"""Error raised when a widget is reduced to a point when hidden."""

def __init__(self, message: str) -> None:
self.message = message
super(WidgetReducedError, self).__init__(message)
13 changes: 12 additions & 1 deletion src/ipyaladin/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import numpy as np
import traitlets

from .utils.exceptions import WidgetCommunicationError
from .utils.exceptions import WidgetCommunicationError, WidgetReducedError
from .utils._coordinate_parser import parse_coordinate_string

try:
Expand Down Expand Up @@ -212,6 +212,13 @@ class Aladin(anywidget.AnyWidget):
"to convert the view to an astropy.HDUList",
).tag(sync=True)

# Temporary traitlets for widget size problem
_is_reduced = Bool(
False,
help="A private trait that stores if the widget "
"is reduced in size when hidden.",
).tag(sync=True)

init_options = traitlets.List(trait=Any()).tag(sync=True)

@default("init_options")
Expand Down Expand Up @@ -289,6 +296,10 @@ def wcs(self) -> WCS:
An astropy WCS object representing the world coordinate system.
"""
if self._is_reduced:
raise WidgetReducedError(
"WCS might be wrong if the Aladin Lite widget is not visible"
)
if self._wcs == {}:
raise WidgetCommunicationError(
"The world coordinate system is not available. "
Expand Down

0 comments on commit 06ae1c5

Please sign in to comment.