From fedfd56c7cbbc227c6bea9a5050995df9f0d60e6 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 16 Aug 2024 12:19:36 +0100 Subject: [PATCH 1/3] Added full implementation of __gluestate__ and __setgluestate__ for application --- glue_qt/app/application.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/glue_qt/app/application.py b/glue_qt/app/application.py index 5fe26d93..936f2368 100644 --- a/glue_qt/app/application.py +++ b/glue_qt/app/application.py @@ -1445,13 +1445,26 @@ def add_datasets(self, *args, **kwargs): return result def __gluestate__(self, context): - state = super(GlueApplication, self).__gluestate__(context) + viewers = [list(map(context.id, tab)) for tab in self.viewers] + data = self.session.data_collection + from glue.main import _loaded_plugins + state = dict(session=context.id(self.session), viewers=viewers, + data=context.id(data), plugins=_loaded_plugins) state['tab_names'] = self.tab_names return state @classmethod def __setgluestate__(cls, rec, context): + self = cls(data_collection=context.object(rec['data'])) + # manually register the newly-created session, which the viewers need + context.register_object(rec['session'], self.session) self = super(GlueApplication, cls).__setgluestate__(rec, context) + for i, tab in enumerate(rec['viewers']): + if self.tab(i) is None: + self.new_tab() + for v in tab: + viewer = context.object(v) + self.add_widget(viewer, tab=i, hold_position=True) if 'tab_names' in rec: self.tab_names = rec['tab_names'] return self From 95c077507cc29f2fb9557313ca4a8955344e8d90 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 16 Aug 2024 12:35:02 +0100 Subject: [PATCH 2/3] Change back to use common code from glue-core --- glue_qt/app/application.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/glue_qt/app/application.py b/glue_qt/app/application.py index 936f2368..bcf335bf 100644 --- a/glue_qt/app/application.py +++ b/glue_qt/app/application.py @@ -1445,20 +1445,14 @@ def add_datasets(self, *args, **kwargs): return result def __gluestate__(self, context): - viewers = [list(map(context.id, tab)) for tab in self.viewers] - data = self.session.data_collection - from glue.main import _loaded_plugins - state = dict(session=context.id(self.session), viewers=viewers, - data=context.id(data), plugins=_loaded_plugins) + state = super().__gluestate__(context) + state['viewers'] = [list(map(context.id, tab)) for tab in self.viewers] state['tab_names'] = self.tab_names return state @classmethod def __setgluestate__(cls, rec, context): - self = cls(data_collection=context.object(rec['data'])) - # manually register the newly-created session, which the viewers need - context.register_object(rec['session'], self.session) - self = super(GlueApplication, cls).__setgluestate__(rec, context) + self = super().__setgluestate__(rec, context) for i, tab in enumerate(rec['viewers']): if self.tab(i) is None: self.new_tab() From 0236a604d126b9adf779aafe6c5a7e341e623b7f Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 16 Aug 2024 13:50:55 +0100 Subject: [PATCH 3/3] Make __setgluestate__ compatible with older glue-core versions --- glue_qt/app/application.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/glue_qt/app/application.py b/glue_qt/app/application.py index bcf335bf..50d2ca22 100644 --- a/glue_qt/app/application.py +++ b/glue_qt/app/application.py @@ -1453,6 +1453,12 @@ def __gluestate__(self, context): @classmethod def __setgluestate__(cls, rec, context): self = super().__setgluestate__(rec, context) + + # COMPAT: removing the following if statement once we require# + # glue-core v1.22.0 or later + if sum(len(tab) for tab in self.viewers) > 0: + return self + for i, tab in enumerate(rec['viewers']): if self.tab(i) is None: self.new_tab()