|
| 1 | +from itertools import chain |
| 2 | +from glue.config import session_patch |
| 3 | +from glue_jupyter.app import JupyterApplication |
| 4 | + |
| 5 | +TRANSLATION = { |
| 6 | + "glue_qt.viewers.histogram.data_viewer.HistogramViewer": "glue_jupyter.bqplot.histogram.BqplotHistogramView", |
| 7 | + "glue_qt.viewers.image.data_viewer.ImageViewer": "glue_jupyter.bqplot.image.BqplotImageView", |
| 8 | + "glue_qt.viewers.profile.data_viewer.ProfileViewer": "glue_jupyter.bqplot.profile.BqplotProfileView", |
| 9 | + "glue_qt.viewers.scatter.data_viewer.ScatterViewer": "glue_jupyter.bqplot.scatter.BqplotScatterView", |
| 10 | + "glue.viewers.image.layer_artist.ImageLayerArtist": "glue_jupyter.bqplot.image.BqplotImageLayerArtist", |
| 11 | + "glue.viewers.image.layer_artist.ImageSubsetLayerArtist": "glue_jupyter.bqplot.image.BqplotImageSubsetLayerArtist", |
| 12 | + "glue_qt.viewers.profile.layer_artist.QThreadedProfileLayerArtist": "glue_jupyter.bqplot.profile.BqplotProfileLayerArtist", |
| 13 | + "glue_qt.viewers.histogram.layer_artist.QThreadedHistogramLayerArtist": "glue_jupyter.bqplot.histogram.BqplotHistogramLayerArtist", |
| 14 | + "glue.viewers.scatter.layer_artist.ScatterLayerArtist": "glue_jupyter.bqplot.scatter.BqplotScatterLayerArtist", |
| 15 | + "glue.viewers.image.state.ImageLayerState": "glue_jupyter.bqplot.image.state.BqplotImageLayerState", |
| 16 | + "glue.viewers.image.state.ImageViewerState": "glue_jupyter.bqplot.image.state.BqplotImageViewerState", |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +@session_patch() |
| 21 | +def translate_qt_to_jupyter_session(session): |
| 22 | + |
| 23 | + session["__main__"]["_type"] = "glue_jupyter.app.JupyterApplication" |
| 24 | + session["__main__"]["viewers"] = list(chain(*session["__main__"]["viewers"])) |
| 25 | + |
| 26 | + for key in session: |
| 27 | + original_type = session[key]["_type"] |
| 28 | + if original_type in TRANSLATION: |
| 29 | + session[key]["_type"] = TRANSLATION[original_type] |
| 30 | + |
| 31 | + if "layers" in session[key]: |
| 32 | + layers = session[key]["layers"] |
| 33 | + for layer in layers: |
| 34 | + if layer["_type"] in TRANSLATION: |
| 35 | + layer["_type"] = TRANSLATION[layer["_type"]] |
0 commit comments