diff --git a/glue_ar/common/scatter.py b/glue_ar/common/scatter.py index ded9baf..5c330a7 100644 --- a/glue_ar/common/scatter.py +++ b/glue_ar/common/scatter.py @@ -1,23 +1,19 @@ from functools import partial from numpy import clip, isfinite, isnan, ndarray, ones, sqrt -try: - from types import NoneType -except ImportError: - NoneType = type(None) from typing import Callable, Dict, List, Optional, Tuple, Union - from glue.utils import ensure_numerical from glue_vispy_viewers.scatter.layer_state import ScatterLayerState + +from glue_ar.common.shapes import rectangular_prism_points, rectangular_prism_triangulation, \ + sphere_points, sphere_triangles +from glue_ar.utils import Bounds, NoneType, Viewer3DState, mask_for_bounds + try: from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState except ImportError: Scatter3DLayerState = NoneType -from glue_ar.common.shapes import rectangular_prism_points, rectangular_prism_triangulation, \ - sphere_points, sphere_triangles -from glue_ar.utils import Bounds, Viewer3DState, mask_for_bounds - ScatterLayerState3D = Union[ScatterLayerState, Scatter3DLayerState] Point = Tuple[float, float, float] diff --git a/glue_ar/common/scatter_gltf.py b/glue_ar/common/scatter_gltf.py index 333bef6..7206598 100644 --- a/glue_ar/common/scatter_gltf.py +++ b/glue_ar/common/scatter_gltf.py @@ -1,5 +1,4 @@ from gltflib import AccessorType, BufferTarget, ComponentType, PrimitiveMode -from glue_jupyter.common.state3d import ViewerState3D from glue_vispy_viewers.scatter.layer_state import ScatterLayerState from glue_vispy_viewers.volume.viewer_state import Vispy3DViewerState from numpy import array, isfinite, ndarray @@ -19,7 +18,12 @@ from glue_ar.common.scatter import Scatter3DLayerState, ScatterLayerState3D, \ PointsGetter, box_points_getter, IPYVOLUME_POINTS_GETTERS, \ IPYVOLUME_TRIANGLE_GETTERS, VECTOR_OFFSETS, radius_for_scatter_layer, \ - scatter_layer_mask, sizes_for_scatter_layer, sphere_points_getter + scatter_layer_mask, sizes_for_scatter_layer, sphere_points_getter, NoneType + +try: + from glue_jupyter.common.state3d import ViewerState3D +except ImportError: + ViewerState3D = NoneType def add_vectors_gltf(builder: GLTFBuilder, diff --git a/glue_ar/common/scatter_usd.py b/glue_ar/common/scatter_usd.py index abcc581..307488f 100644 --- a/glue_ar/common/scatter_usd.py +++ b/glue_ar/common/scatter_usd.py @@ -1,7 +1,5 @@ from typing import List, Optional, Tuple -from glue_jupyter.common.state3d import ViewerState3D -from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState from glue_vispy_viewers.scatter.layer_state import ScatterLayerState from glue_vispy_viewers.scatter.viewer_state import Vispy3DViewerState from numpy import array, ndarray @@ -16,9 +14,16 @@ from glue_ar.common.shapes import cone_triangles, cone_points, cylinder_points, cylinder_triangles, \ normalize, rectangular_prism_triangulation, sphere_triangles from glue_ar.utils import Viewer3DState, export_label_for_layer, iterable_has_nan, hex_to_components, \ - layer_color, xyz_for_layer, Bounds + layer_color, xyz_for_layer, Bounds, NoneType from glue_ar.usd_utils import material_for_color +try: + from glue_jupyter.common.state3d import ViewerState3D + from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState +except ImportError: + ViewerState3D = NoneType + Scatter3DLayerState = NoneType + def add_vectors_usd(builder: USDBuilder, viewer_state: Viewer3DState, diff --git a/glue_ar/utils.py b/glue_ar/utils.py index 8174cc3..6c21c36 100644 --- a/glue_ar/utils.py +++ b/glue_ar/utils.py @@ -19,6 +19,11 @@ except ImportError: ViewerState3D = Vispy3DViewerState +# Backwards compatibility for Python < 3.10 +try: + from types import NoneType # noqa +except ImportError: + NoneType = type(None) PACKAGE_DIR = dirname(abspath(__file__)) AR_ICON = abspath(join(dirname(__file__), "ar.png"))