Skip to content

Commit 7b138a6

Browse files
authored
Merge pull request #1237 from ZacZhangzhuo/feature/viewer-context-detection
Feature/viewer-context-detection
2 parents adfbee0 + 1de9b13 commit 7b138a6

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
### Added
11-
11+
* Added `viewerinstance` in `compas.scene.Scene` to support viewers context detection.
1212
* Added `compas_rhino8` as starting point for Rhino8 support.
1313
* Added `compas.scene.SceneObjectNode`.
1414
* Added `compas.scene.SceneTree`.

src/compas/scene/context.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from compas.plugins import pluggable
1+
import inspect
2+
from collections import defaultdict
3+
4+
import compas
25
from compas.plugins import PluginValidator
6+
from compas.plugins import pluggable
7+
38
from .exceptions import NoSceneObjectContextError
49
from .exceptions import SceneObjectNotRegisteredError
5-
import inspect
6-
import compas
7-
from collections import defaultdict
810

911
ITEM_SCENEOBJECT = defaultdict(dict)
1012

@@ -62,15 +64,9 @@ def is_viewer_open():
6264
bool
6365
6466
"""
65-
# TODO: implement [without introducing compas_view2 as a dependency..?]
66-
# make the viewer app a singleton
67-
# check for the exitence of an instance of the singleton
68-
# if the instance exists, return True
69-
# in this case, the viewer is the current context
70-
# to do this without introducing compas_view2 as a dependency,
71-
# creating the singleton instance should modify a class attribute of the SceneObject
72-
# (or potentially a module level attribute of compas itself)
73-
return False
67+
from compas.scene import Scene
68+
69+
return Scene.viewerinstance is not None
7470

7571

7672
def _detect_current_context():

src/compas/scene/scene.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from compas.data import Data
22
from compas.datastructures import Tree
33
from compas.datastructures import TreeNode
4-
from .sceneobject import SceneObject
5-
from .context import redraw
4+
65
from .context import clear
6+
from .context import redraw
7+
from .sceneobject import SceneObject
78

89

910
class SceneObjectNode(TreeNode):
@@ -201,6 +202,8 @@ class Scene(Data):
201202
202203
"""
203204

205+
viewerinstance = None
206+
204207
def __init__(self, name=None, context=None):
205208
super(Scene, self).__init__(name)
206209
self._tree = SceneTree("Scene")

0 commit comments

Comments
 (0)