From 06ae1c568add6495889d54f9618a64a40ff37c62 Mon Sep 17 00:00:00 2001 From: Xen0Xys Date: Wed, 31 Jul 2024 12:09:56 +0200 Subject: [PATCH] :goal_net: Add error when exporting the WCS while the widget is reduced when hidden --- js/models/event_handler.js | 6 +++++- src/ipyaladin/utils/exceptions.py | 8 ++++++++ src/ipyaladin/widget.py | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/js/models/event_handler.js b/js/models/event_handler.js index d5d6fc68..5bac5d24 100644 --- a/js/models/event_handler.js +++ b/js/models/event_handler.js @@ -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); diff --git a/src/ipyaladin/utils/exceptions.py b/src/ipyaladin/utils/exceptions.py index a77b3e73..0de125af 100644 --- a/src/ipyaladin/utils/exceptions.py +++ b/src/ipyaladin/utils/exceptions.py @@ -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) diff --git a/src/ipyaladin/widget.py b/src/ipyaladin/widget.py index af4f54a1..0af4a944 100644 --- a/src/ipyaladin/widget.py +++ b/src/ipyaladin/widget.py @@ -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: @@ -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") @@ -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. "