Skip to content

Commit

Permalink
More work in isolating Qt functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Aug 30, 2018
1 parent f587353 commit 025abf9
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 70 deletions.
14 changes: 13 additions & 1 deletion glue/_deps.py
Expand Up @@ -130,6 +130,18 @@ def version(self):
return 'unknown version'


class QtPy(Dependency):

@property
def installed(self):
try:
importlib.import_module(self.module)
return True
except Exception:
# QtPy raises a PythonQtError in some cases, so we can't use
# ImportError.
return False

# Add any dependencies here
# Make sure to add new categories to the categories tuple

Expand All @@ -143,7 +155,7 @@ def version(self):
)

required = (
Dependency('qtpy', 'Required', min_version='1.2'),
QtPy('qtpy', 'Required', min_version='1.2'),
Dependency('setuptools', 'Required', min_version='1.0'),
Dependency('numpy', 'Required', min_version='1.9'),
Dependency('bottleneck', 'Required', min_version='1.2'),
Expand Down
8 changes: 6 additions & 2 deletions glue/conftest.py
Expand Up @@ -42,7 +42,9 @@ def pytest_configure(config):
# Start up QApplication, if the Qt code is present
try:
from glue.utils.qt import get_qapp
except ImportError:
except Exception:
# Note that we catch any exception, not just ImportError, because
# QtPy can raise a PythonQtError.
pass
else:
get_qapp()
Expand Down Expand Up @@ -71,7 +73,9 @@ def pytest_unconfigure(config):
try:
from glue.utils.qt import app
app.qapp = None
except ImportError: # for when we run the tests without the qt directories
except Exception: # for when we run the tests without the qt directories
# Note that we catch any exception, not just ImportError, because
# QtPy can raise a PythonQtError.
pass

if OBJGRAPH_INSTALLED and not ON_APPVEYOR:
Expand Down
3 changes: 0 additions & 3 deletions glue/plugins/dendro_viewer/__init__.py
@@ -1,5 +1,2 @@
def setup():
from glue.config import qt_client
from .qt.data_viewer import DendrogramViewer
from .data_factory import load_dendro # noqa
qt_client.add(DendrogramViewer)
5 changes: 5 additions & 0 deletions glue/plugins/dendro_viewer/qt/__init__.py
@@ -1 +1,6 @@
from .data_viewer import DendrogramViewer # noqa


def setup():
from glue.config import qt_client
qt_client.add(DendrogramViewer)
36 changes: 1 addition & 35 deletions glue/plugins/exporters/plotly/export_plotly.py
Expand Up @@ -260,7 +260,7 @@ def can_save_plotly(application):
if hasattr(viewer, '__plotly__'):
continue

if not isinstance(viewer, (ScatterViewer, HistogramViewer)):
if not isinstance(viewer, tuple(DISPATCH)):
raise ValueError("Plotly Export cannot handle viewer: %s"
% type(viewer))

Expand All @@ -276,38 +276,4 @@ def can_save_plotly(application):
raise ValueError("Plotly Export supports at most 4 plots")


def save_plotly(application):
"""
Save a Glue session to a plotly plot
This is currently restricted to 1-4 scatterplots or histograms
Parameters
----------
application : `~glue.core.application_base.Application`
Glue application to save
label : str
Label for the exported plot
"""

args, kwargs = build_plotly_call(application)

logging.getLogger(__name__).debug(args, kwargs)

# TODO: check what current GUI framework is

from glue.plugins.exporters.plotly.qt import QtPlotlyExporter
exporter = QtPlotlyExporter(plotly_args=args, plotly_kwargs=kwargs)
exporter.exec_()


DISPATCH = {}

try:
from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.histogram.qt import HistogramViewer
except ImportError:
pass
else:
DISPATCH[ScatterViewer] = export_scatter
DISPATCH[HistogramViewer] = export_histogram
15 changes: 14 additions & 1 deletion glue/plugins/exporters/plotly/qt/__init__.py
@@ -1 +1,14 @@
from .exporter import QtPlotlyExporter # noqa
def setup():

from glue.config import exporters
from glue.plugins.exporters.plotly.export_plotly import (can_save_plotly, DISPATCH,
export_scatter, export_histogram)
from glue.plugins.exporters.plotly.qt.exporter import save_plotly

from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.histogram.qt import HistogramViewer

DISPATCH[ScatterViewer] = export_scatter
DISPATCH[HistogramViewer] = export_histogram

exporters.add('Plotly', save_plotly, can_save_plotly)
26 changes: 26 additions & 0 deletions glue/plugins/exporters/plotly/qt/exporter.py
Expand Up @@ -2,13 +2,39 @@

import os
import sys
import logging
import traceback
import webbrowser

from qtpy import QtWidgets
from glue.utils import nonpartial
from glue.utils.qt import load_ui
from glue.utils.qt.widget_properties import TextProperty, ButtonProperty
from glue.plugins.exporters.plotly.export_plotly import build_plotly_call


def save_plotly(application):
"""
Save a Glue session to a plotly plot
This is currently restricted to 1-4 scatterplots or histograms
Parameters
----------
application : `~glue.core.application_base.Application`
Glue application to save
label : str
Label for the exported plot
"""

args, kwargs = build_plotly_call(application)

logging.getLogger(__name__).debug(args, kwargs)

# TODO: check what current GUI framework is

exporter = QtPlotlyExporter(plotly_args=args, plotly_kwargs=kwargs)
exporter.exec_()


class QtPlotlyExporter(QtWidgets.QDialog):
Expand Down
Expand Up @@ -12,7 +12,7 @@
from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.histogram.qt import HistogramViewer

from ..export_plotly import build_plotly_call
from ...export_plotly import build_plotly_call


class TestPlotly(object):
Expand Down
4 changes: 0 additions & 4 deletions glue/viewers/histogram/__init__.py
@@ -1,4 +0,0 @@
def setup():
from glue.config import qt_client
from .qt.data_viewer import HistogramViewer
qt_client.add(HistogramViewer)
5 changes: 5 additions & 0 deletions glue/viewers/histogram/qt/__init__.py
@@ -1 +1,6 @@
from .data_viewer import HistogramViewer # noqa


def setup():
from glue.config import qt_client
qt_client.add(HistogramViewer)
4 changes: 0 additions & 4 deletions glue/viewers/image/__init__.py
@@ -1,4 +0,0 @@
def setup():
from glue.config import qt_client
from .qt.data_viewer import ImageViewer
qt_client.add(ImageViewer)
5 changes: 5 additions & 0 deletions glue/viewers/image/qt/__init__.py
@@ -1,2 +1,7 @@
from .data_viewer import ImageViewer # noqa
from .standalone_image_viewer import StandaloneImageViewer # noqa


def setup():
from glue.config import qt_client
qt_client.add(ImageViewer)
4 changes: 0 additions & 4 deletions glue/viewers/profile/__init__.py
@@ -1,4 +0,0 @@
def setup():
from glue.config import qt_client
from .qt.data_viewer import ProfileViewer
qt_client.add(ProfileViewer)
5 changes: 5 additions & 0 deletions glue/viewers/profile/qt/__init__.py
@@ -1 +1,6 @@
from .data_viewer import ProfileViewer # noqa


def setup():
from glue.config import qt_client
qt_client.add(ProfileViewer)
4 changes: 0 additions & 4 deletions glue/viewers/scatter/__init__.py
@@ -1,4 +0,0 @@
def setup():
from glue.config import qt_client
from .qt.data_viewer import ScatterViewer
qt_client.add(ScatterViewer)
4 changes: 4 additions & 0 deletions glue/viewers/scatter/qt/__init__.py
@@ -1 +1,5 @@
from .data_viewer import ScatterViewer # noqa

def setup():
from glue.config import qt_client
qt_client.add(ScatterViewer)
4 changes: 0 additions & 4 deletions glue/viewers/table/__init__.py
@@ -1,4 +0,0 @@
def setup():
from glue.config import qt_client
from .qt import TableViewer
qt_client.add(TableViewer)
5 changes: 5 additions & 0 deletions glue/viewers/table/qt/__init__.py
@@ -1 +1,6 @@
from .data_viewer import TableViewer, TableLayerArtist # noqa


def setup():
from glue.config import qt_client
qt_client.add(TableViewer)
15 changes: 8 additions & 7 deletions setup.py
Expand Up @@ -51,16 +51,17 @@
entry_points = """
[glue.plugins]
export_d3po = glue.plugins.export_d3po:setup
export_plotly = glue.plugins.exporters.plotly:setup
export_plotly = glue.plugins.exporters.plotly.qt:setup
pv_slicer = glue.plugins.tools.pv_slicer:setup
coordinate_helpers = glue.plugins.coordinate_helpers:setup
spectral_cube = glue.plugins.data_factories.spectral_cube:setup
dendro_viewer = glue.plugins.dendro_viewer:setup
image_viewer = glue.viewers.image:setup
scatter_viewer = glue.viewers.scatter:setup
histogram_viewer = glue.viewers.histogram:setup
profile_viewer = glue.viewers.profile:setup
table_viewer = glue.viewers.table:setup
dendro_factory = glue.plugins.dendro_viewer:setup
dendro_viewer = glue.plugins.dendro_viewer.qt:setup
image_viewer = glue.viewers.image.qt:setup
scatter_viewer = glue.viewers.scatter.qt:setup
histogram_viewer = glue.viewers.histogram.qt:setup
profile_viewer = glue.viewers.profile.qt:setup
table_viewer = glue.viewers.table.qt:setup
data_exporters = glue.core.data_exporters:setup
fits_format = glue.io.formats.fits:setup
export_python = glue.plugins.tools:setup
Expand Down

0 comments on commit 025abf9

Please sign in to comment.