Skip to content

Commit

Permalink
Update timer configuration and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Nov 5, 2024
1 parent 9843f23 commit 5023841
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 11 additions & 5 deletions glue_wwt/viewer/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
__all__ = ['WWTDataViewerBase']


class RepeatTimer(Timer):
def run(self):
while not self.finished.wait(self.interval):
self.function(*self.args, **self.kwargs)


class WWTDataViewerBase(object):
LABEL = 'Earth/Planet/Sky Viewer (WWT)'
_wwt = None
Expand Down Expand Up @@ -59,7 +65,7 @@ def __init__(self):
# which contains information about WWT's internal time. But we only get those messages when something
# changes with the WWT view, so we can't rely on that here.
# This just kicks off the first timer; the method repeatedly time-calls itself
self._current_time_timer = Timer(1.0, self._update_time)
self._current_time_timer = RepeatTimer(1.0, self._update_time)
self._current_time_timer.start()

self.state.add_global_callback(self._update_wwt)
Expand All @@ -69,7 +75,10 @@ def __init__(self):
# NB: Specific frontend implementations need to call this
# We just consolidate the logic here
def _cleanup(self):
self._current_time_timer.cancel()
try:
self._current_time_timer.cancel()
except RuntimeError:
pass

def _initialize_wwt(self):
raise NotImplementedError('subclasses should set _wwt here')
Expand Down Expand Up @@ -173,6 +182,3 @@ def _update_time(self):
self.state.current_time = datetime64(self._wwt.get_current_time().to_string())
except ViewerNotAvailableError:
pass

self._current_time_timer = Timer(1.0, self._update_time)
self._current_time_timer.start()
3 changes: 3 additions & 0 deletions glue_wwt/viewer/jupyter_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def __init__(self, session, state=None):
self._layout_tab.set_title(1, "Layers")
self._layout = HBox([self.figure_widget, self._layout_tab], layout=Layout(height="400px"))

def __del__(self):
self._cleanup()

def _initialize_wwt(self):
self._wwt = WWTJupyterWidget()

Expand Down
5 changes: 4 additions & 1 deletion glue_wwt/viewer/qt_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ def __init__(self, session, parent=None, state=None):

self.set_status('NOTE ON ZOOMING: use the z/x keys to zoom in/out if scrolling does not work')

def __del__(self):
self._cleanup()

def _initialize_wwt(self):
from pywwt.qt import WWTQtClient
self._wwt = WWTQtClient()

def closeEvent(self, event):
self._wwt.widget.close()
self._cleanup()
self._wwt.widget.close()
return super(WWTQtViewer, self).closeEvent(event)

def _on_wwt_ready(self):
Expand Down

0 comments on commit 5023841

Please sign in to comment.