diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2631778816..020e1f216d78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Added - +* Added `viewerinstance` in `compas.scene.Scene` to support viewers context detection. * Added `compas_rhino8` as starting point for Rhino8 support. * Added `compas.scene.SceneObjectNode`. * Added `compas.scene.SceneTree`. diff --git a/src/compas/scene/context.py b/src/compas/scene/context.py index 564f588b476d..0a2265ffc5a7 100644 --- a/src/compas/scene/context.py +++ b/src/compas/scene/context.py @@ -1,10 +1,12 @@ -from compas.plugins import pluggable +import inspect +from collections import defaultdict + +import compas from compas.plugins import PluginValidator +from compas.plugins import pluggable + from .exceptions import NoSceneObjectContextError from .exceptions import SceneObjectNotRegisteredError -import inspect -import compas -from collections import defaultdict ITEM_SCENEOBJECT = defaultdict(dict) @@ -62,15 +64,9 @@ def is_viewer_open(): bool """ - # TODO: implement [without introducing compas_view2 as a dependency..?] - # make the viewer app a singleton - # check for the exitence of an instance of the singleton - # if the instance exists, return True - # in this case, the viewer is the current context - # to do this without introducing compas_view2 as a dependency, - # creating the singleton instance should modify a class attribute of the SceneObject - # (or potentially a module level attribute of compas itself) - return False + from compas.scene import Scene + + return Scene.viewerinstance is not None def _detect_current_context(): diff --git a/src/compas/scene/scene.py b/src/compas/scene/scene.py index 17e599be3b7a..ec351213a9ab 100644 --- a/src/compas/scene/scene.py +++ b/src/compas/scene/scene.py @@ -1,9 +1,10 @@ from compas.data import Data from compas.datastructures import Tree from compas.datastructures import TreeNode -from .sceneobject import SceneObject -from .context import redraw + from .context import clear +from .context import redraw +from .sceneobject import SceneObject class SceneObjectNode(TreeNode): @@ -178,6 +179,8 @@ class Scene(Data): """ + viewerinstance = None + def __init__(self, name=None, context=None): super(Scene, self).__init__(name) self._tree = SceneTree("Scene")