object-tree 3.1.0__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {object_tree-3.1.0 → object_tree-3.2.0}/PKG-INFO +4 -1
- {object_tree-3.1.0 → object_tree-3.2.0}/README.md +3 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/core/__init__.py +6 -1
- {object_tree-3.1.0 → object_tree-3.2.0}/core/adapter.py +28 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/core/node.py +64 -3
- {object_tree-3.1.0 → object_tree-3.2.0}/core/selection.py +1 -1
- {object_tree-3.1.0 → object_tree-3.2.0}/core/viewport.py +21 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/object_tree.egg-info/PKG-INFO +4 -1
- {object_tree-3.1.0 → object_tree-3.2.0}/pyproject.toml +1 -1
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_adapter.py +34 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_node.py +126 -3
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_viewport.py +39 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/core/hittest.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/core/inspector.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/core/interaction.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/core/viewport_system.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/demo/__init__.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/demo/app.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/demo/scene.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/demo/tests/__init__.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/demo/tests/test_scene.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/object_tree.egg-info/SOURCES.txt +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/object_tree.egg-info/dependency_links.txt +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/object_tree.egg-info/requires.txt +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/object_tree.egg-info/top_level.txt +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/rules/__init__.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/rules/boolean_flags.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/rules/function.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/setup.cfg +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_hittest.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_inspector.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_interaction.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_rules.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_selection.py +0 -0
- {object_tree-3.1.0 → object_tree-3.2.0}/tests/test_viewport_system.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: object-tree
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: A zero-dependency, general-purpose nested selection and inspection framework
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/GrayJou/object_tree
|
|
@@ -132,6 +132,9 @@ flags.apply(element) # Sets element.visible_rules
|
|
|
132
132
|
- [x] Dict adapter
|
|
133
133
|
- [x] DearPyGui demo
|
|
134
134
|
- [x] Ancestor selection rule
|
|
135
|
+
- [x] Adapter back-reference, kind/ID, traversal utilities
|
|
136
|
+
- [x] Multi-selection aware rules
|
|
137
|
+
- [x] Auto-register property types
|
|
135
138
|
|
|
136
139
|
### v4.0 — Events & Observability
|
|
137
140
|
|
|
@@ -111,6 +111,9 @@ flags.apply(element) # Sets element.visible_rules
|
|
|
111
111
|
- [x] Dict adapter
|
|
112
112
|
- [x] DearPyGui demo
|
|
113
113
|
- [x] Ancestor selection rule
|
|
114
|
+
- [x] Adapter back-reference, kind/ID, traversal utilities
|
|
115
|
+
- [x] Multi-selection aware rules
|
|
116
|
+
- [x] Auto-register property types
|
|
114
117
|
|
|
115
118
|
### v4.0 — Events & Observability
|
|
116
119
|
|
|
@@ -17,7 +17,7 @@ from .hittest import (
|
|
|
17
17
|
)
|
|
18
18
|
from .inspector import BoxSpec, InspectorSystem
|
|
19
19
|
from .interaction import InteractionController
|
|
20
|
-
from .node import PROPERTY_TYPES, InspectableObject, Property
|
|
20
|
+
from .node import PROPERTY_TYPES, InspectableObject, Property, walk_tree
|
|
21
21
|
from .selection import SelectionState
|
|
22
22
|
from .viewport import (
|
|
23
23
|
AncestorSelectedRule,
|
|
@@ -28,6 +28,8 @@ from .viewport import (
|
|
|
28
28
|
ParentSelectedRule,
|
|
29
29
|
Rule,
|
|
30
30
|
SameGroupRule,
|
|
31
|
+
SelfInMultiRule,
|
|
32
|
+
SelfOrAncestorInMultiRule,
|
|
31
33
|
SelfOrAncestorSelectedRule,
|
|
32
34
|
SiblingSelectedRule,
|
|
33
35
|
ViewportElement,
|
|
@@ -38,6 +40,7 @@ __all__ = [
|
|
|
38
40
|
"InspectableObject",
|
|
39
41
|
"Property",
|
|
40
42
|
"PROPERTY_TYPES",
|
|
43
|
+
"walk_tree",
|
|
41
44
|
"SelectionState",
|
|
42
45
|
"InspectorSystem",
|
|
43
46
|
"BoxSpec",
|
|
@@ -54,6 +57,8 @@ __all__ = [
|
|
|
54
57
|
"SiblingSelectedRule",
|
|
55
58
|
"AncestorSelectedRule",
|
|
56
59
|
"SameGroupRule",
|
|
60
|
+
"SelfInMultiRule",
|
|
61
|
+
"SelfOrAncestorInMultiRule",
|
|
57
62
|
"AndRule",
|
|
58
63
|
"OrRule",
|
|
59
64
|
"NotRule",
|
|
@@ -10,6 +10,12 @@ class InspectableAdapter(Protocol):
|
|
|
10
10
|
|
|
11
11
|
Implement this protocol on any wrapper type to convert it into the
|
|
12
12
|
object-tree representation via :func:`adapt`.
|
|
13
|
+
|
|
14
|
+
.. note::
|
|
15
|
+
``get_parent()`` is **not** called by :func:`adapt` — the tree is
|
|
16
|
+
built purely from ``get_children()``. ``get_parent()`` exists for
|
|
17
|
+
external use (e.g. manual parent lookups from an adapted node's
|
|
18
|
+
``.adapter`` back-reference).
|
|
13
19
|
"""
|
|
14
20
|
def get_name(self) -> str: ...
|
|
15
21
|
def get_parent(self) -> Optional[Any]: ...
|
|
@@ -17,19 +23,33 @@ class InspectableAdapter(Protocol):
|
|
|
17
23
|
def get_properties(self) -> Dict[str, Tuple[str, Any]]: ...
|
|
18
24
|
def get_show_parent_box(self) -> bool: ...
|
|
19
25
|
|
|
26
|
+
def get_kind(self) -> str:
|
|
27
|
+
"""Discriminator string for the node type (e.g. ``"point"``, ``"group"``). Defaults to ``""``."""
|
|
28
|
+
return ""
|
|
29
|
+
|
|
30
|
+
def get_id(self) -> str:
|
|
31
|
+
"""Stable unique identifier within the parent context. Defaults to ``get_name()``."""
|
|
32
|
+
return self.get_name()
|
|
33
|
+
|
|
20
34
|
|
|
21
35
|
def adapt(adapter: InspectableAdapter) -> InspectableObject:
|
|
22
36
|
"""Recursively convert an :class:`InspectableAdapter` into an :class:`InspectableObject` tree.
|
|
23
37
|
|
|
24
38
|
The resulting tree mirrors the structure returned by the adapter's
|
|
25
39
|
``get_children()`` method.
|
|
40
|
+
|
|
41
|
+
The original adapter is stored on each node's ``.adapter`` field for
|
|
42
|
+
reverse-lookup (see R1/R2 in the Chromatica2 integration spec).
|
|
26
43
|
"""
|
|
27
44
|
name = adapter.get_name()
|
|
28
45
|
props = adapter.get_properties()
|
|
29
46
|
|
|
30
47
|
node = InspectableObject(
|
|
31
48
|
name=name,
|
|
49
|
+
kind=adapter.get_kind(),
|
|
50
|
+
uid=adapter.get_id(),
|
|
32
51
|
show_parent_box=adapter.get_show_parent_box(),
|
|
52
|
+
adapter=adapter,
|
|
33
53
|
)
|
|
34
54
|
for prop_name, (prop_type, prop_value) in props.items():
|
|
35
55
|
node.add_property(Property(name=prop_name, type=prop_type, value=prop_value))
|
|
@@ -48,6 +68,8 @@ class DictAdapter:
|
|
|
48
68
|
|
|
49
69
|
{
|
|
50
70
|
"name": str,
|
|
71
|
+
"kind": str,
|
|
72
|
+
"uid": str,
|
|
51
73
|
"show_parent_box": bool,
|
|
52
74
|
"properties": {"key": (type_str, value), ...},
|
|
53
75
|
"children": [<recursive dict>, ...],
|
|
@@ -60,6 +82,12 @@ class DictAdapter:
|
|
|
60
82
|
def get_name(self) -> str:
|
|
61
83
|
return self._data.get("name", "Unnamed")
|
|
62
84
|
|
|
85
|
+
def get_kind(self) -> str:
|
|
86
|
+
return self._data.get("kind", "")
|
|
87
|
+
|
|
88
|
+
def get_id(self) -> str:
|
|
89
|
+
return self._data.get("uid", self.get_name())
|
|
90
|
+
|
|
63
91
|
def get_parent(self) -> Optional[Any]:
|
|
64
92
|
parent = self._data.get("parent")
|
|
65
93
|
if parent is not None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
|
-
from typing import Any, Optional
|
|
3
|
+
from typing import Any, Generator, Optional
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
PROPERTY_TYPES = {"Literal", "Float", "Int", "Bool", "Color", "Vector2", "Vector3"}
|
|
@@ -12,7 +12,7 @@ class Property:
|
|
|
12
12
|
|
|
13
13
|
Attributes:
|
|
14
14
|
name: Display name for the property.
|
|
15
|
-
type: One of PROPERTY_TYPES
|
|
15
|
+
type: One of PROPERTY_TYPES, or a custom type registered at runtime.
|
|
16
16
|
value: Current runtime value.
|
|
17
17
|
default: Optional default value.
|
|
18
18
|
"""
|
|
@@ -23,7 +23,7 @@ class Property:
|
|
|
23
23
|
|
|
24
24
|
def __post_init__(self):
|
|
25
25
|
if self.type not in PROPERTY_TYPES:
|
|
26
|
-
|
|
26
|
+
PROPERTY_TYPES.add(self.type)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
@dataclass
|
|
@@ -37,17 +37,23 @@ class InspectableObject:
|
|
|
37
37
|
|
|
38
38
|
Attributes:
|
|
39
39
|
name: Human-readable label.
|
|
40
|
+
kind: Discriminator string for the node type (e.g. ``"point"``, ``"group"``).
|
|
41
|
+
uid: Stable unique identifier within its context.
|
|
40
42
|
parent: Parent node (set automatically by ``add_child``).
|
|
41
43
|
children: Direct child nodes.
|
|
42
44
|
properties: Keyed by property name.
|
|
43
45
|
show_parent_box: If True, the inspector includes this object's
|
|
44
46
|
parent when computing the inspection stack.
|
|
47
|
+
adapter: Back-reference to the source adapter that created this node.
|
|
45
48
|
"""
|
|
46
49
|
name: str
|
|
50
|
+
kind: str = ""
|
|
51
|
+
uid: str = ""
|
|
47
52
|
parent: Optional[InspectableObject] = None
|
|
48
53
|
children: list[InspectableObject] = field(default_factory=list)
|
|
49
54
|
properties: dict[str, Property] = field(default_factory=dict)
|
|
50
55
|
show_parent_box: bool = True
|
|
56
|
+
adapter: Any = field(default=None, repr=False)
|
|
51
57
|
|
|
52
58
|
def __hash__(self):
|
|
53
59
|
return id(self)
|
|
@@ -117,3 +123,58 @@ class InspectableObject:
|
|
|
117
123
|
def path_names(self) -> list[str]:
|
|
118
124
|
"""``.name`` of each node in ``.path()``."""
|
|
119
125
|
return [obj.name for obj in self.path()]
|
|
126
|
+
|
|
127
|
+
def walk(self) -> Generator[InspectableObject, None, None]:
|
|
128
|
+
"""DFS pre-order traversal yielding ``self`` and all descendants."""
|
|
129
|
+
yield self
|
|
130
|
+
for child in self.children:
|
|
131
|
+
yield from child.walk()
|
|
132
|
+
|
|
133
|
+
def walk_up(self) -> Generator[InspectableObject, None, None]:
|
|
134
|
+
"""Walk from ``self`` to root (yields self, parent, grandparent, ...)."""
|
|
135
|
+
cursor: Optional[InspectableObject] = self
|
|
136
|
+
while cursor is not None:
|
|
137
|
+
yield cursor
|
|
138
|
+
cursor = cursor.parent
|
|
139
|
+
|
|
140
|
+
def find(
|
|
141
|
+
self,
|
|
142
|
+
*,
|
|
143
|
+
kind: str | None = None,
|
|
144
|
+
name: str | None = None,
|
|
145
|
+
uid: str | None = None,
|
|
146
|
+
) -> Optional[InspectableObject]:
|
|
147
|
+
"""DFS search for the first node matching all specified criteria."""
|
|
148
|
+
for node in self.walk():
|
|
149
|
+
if kind is not None and node.kind != kind:
|
|
150
|
+
continue
|
|
151
|
+
if name is not None and node.name != name:
|
|
152
|
+
continue
|
|
153
|
+
if uid is not None and node.uid != uid:
|
|
154
|
+
continue
|
|
155
|
+
return node
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
def find_all(
|
|
159
|
+
self,
|
|
160
|
+
*,
|
|
161
|
+
kind: str | None = None,
|
|
162
|
+
name: str | None = None,
|
|
163
|
+
uid: str | None = None,
|
|
164
|
+
) -> list[InspectableObject]:
|
|
165
|
+
"""DFS search returning all nodes matching all specified criteria."""
|
|
166
|
+
results: list[InspectableObject] = []
|
|
167
|
+
for node in self.walk():
|
|
168
|
+
if kind is not None and node.kind != kind:
|
|
169
|
+
continue
|
|
170
|
+
if name is not None and node.name != name:
|
|
171
|
+
continue
|
|
172
|
+
if uid is not None and node.uid != uid:
|
|
173
|
+
continue
|
|
174
|
+
results.append(node)
|
|
175
|
+
return results
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def walk_tree(root: InspectableObject) -> Generator[InspectableObject, None, None]:
|
|
179
|
+
"""DFS pre-order traversal of the entire tree from *root*."""
|
|
180
|
+
yield from root.walk()
|
|
@@ -46,7 +46,7 @@ class SelectionState:
|
|
|
46
46
|
def toggle_multi(self, obj: InspectableObject) -> None:
|
|
47
47
|
"""Add or remove *obj* from the multi-selection set."""
|
|
48
48
|
if self._multi is None:
|
|
49
|
-
self._multi =
|
|
49
|
+
self._multi = set()
|
|
50
50
|
if obj in self._multi:
|
|
51
51
|
self._multi.discard(obj)
|
|
52
52
|
if not self._multi:
|
|
@@ -103,6 +103,27 @@ class SameGroupRule:
|
|
|
103
103
|
return selection.is_within_same_group(obj)
|
|
104
104
|
|
|
105
105
|
|
|
106
|
+
@dataclass
|
|
107
|
+
class SelfInMultiRule:
|
|
108
|
+
"""True when the object is in the multi-selection set."""
|
|
109
|
+
def __call__(self, selection: SelectionState, obj: InspectableObject) -> bool:
|
|
110
|
+
return selection.multi is not None and obj in selection.multi
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@dataclass
|
|
114
|
+
class SelfOrAncestorInMultiRule:
|
|
115
|
+
"""True when the object or any ancestor is in the multi-selection set."""
|
|
116
|
+
def __call__(self, selection: SelectionState, obj: InspectableObject) -> bool:
|
|
117
|
+
if selection.multi is None:
|
|
118
|
+
return False
|
|
119
|
+
cursor: Optional[InspectableObject] = obj
|
|
120
|
+
while cursor is not None:
|
|
121
|
+
if cursor in selection.multi:
|
|
122
|
+
return True
|
|
123
|
+
cursor = cursor.parent
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
|
|
106
127
|
@dataclass
|
|
107
128
|
class AndRule:
|
|
108
129
|
"""True only when **all** sub-rules return True."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: object-tree
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: A zero-dependency, general-purpose nested selection and inspection framework
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/GrayJou/object_tree
|
|
@@ -132,6 +132,9 @@ flags.apply(element) # Sets element.visible_rules
|
|
|
132
132
|
- [x] Dict adapter
|
|
133
133
|
- [x] DearPyGui demo
|
|
134
134
|
- [x] Ancestor selection rule
|
|
135
|
+
- [x] Adapter back-reference, kind/ID, traversal utilities
|
|
136
|
+
- [x] Multi-selection aware rules
|
|
137
|
+
- [x] Auto-register property types
|
|
135
138
|
|
|
136
139
|
### v4.0 — Events & Observability
|
|
137
140
|
|
|
@@ -39,3 +39,37 @@ class TestDictAdapter:
|
|
|
39
39
|
props = adapter.get_properties()
|
|
40
40
|
assert props["Count"] == ("int", 42)
|
|
41
41
|
assert props["Name"] == ("str", "hello")
|
|
42
|
+
|
|
43
|
+
def test_dict_adapter_kind_uid(self):
|
|
44
|
+
data = {"name": "P0", "kind": "point", "uid": "P0"}
|
|
45
|
+
adapter = DictAdapter(data)
|
|
46
|
+
assert adapter.get_kind() == "point"
|
|
47
|
+
assert adapter.get_id() == "P0"
|
|
48
|
+
|
|
49
|
+
def test_dict_adapter_default_uid(self):
|
|
50
|
+
data = {"name": "Unnamed"}
|
|
51
|
+
adapter = DictAdapter(data)
|
|
52
|
+
assert adapter.get_kind() == ""
|
|
53
|
+
assert adapter.get_id() == "Unnamed" # falls back to get_name()
|
|
54
|
+
|
|
55
|
+
def test_adapt_stores_adapter_backref(self):
|
|
56
|
+
data = {"name": "Root", "children": [{"name": "Child"}]}
|
|
57
|
+
node = adapt(DictAdapter(data))
|
|
58
|
+
assert isinstance(node.adapter, DictAdapter)
|
|
59
|
+
assert node.adapter.get_name() == "Root"
|
|
60
|
+
assert node.children[0].adapter.get_name() == "Child"
|
|
61
|
+
|
|
62
|
+
def test_adapt_stores_kind_and_uid(self):
|
|
63
|
+
data = {
|
|
64
|
+
"name": "P0",
|
|
65
|
+
"kind": "point",
|
|
66
|
+
"uid": "P0",
|
|
67
|
+
"children": [
|
|
68
|
+
{"name": "Sub", "kind": "subpoint", "uid": "S0"},
|
|
69
|
+
],
|
|
70
|
+
}
|
|
71
|
+
node = adapt(DictAdapter(data))
|
|
72
|
+
assert node.kind == "point"
|
|
73
|
+
assert node.uid == "P0"
|
|
74
|
+
assert node.children[0].kind == "subpoint"
|
|
75
|
+
assert node.children[0].uid == "S0"
|
|
@@ -9,9 +9,11 @@ class TestProperty:
|
|
|
9
9
|
assert p.type == "Float"
|
|
10
10
|
assert p.value == 1.5
|
|
11
11
|
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
def test_create_unknown_type_auto_registers(self):
|
|
13
|
+
p = Property("Foo", "UnknownType")
|
|
14
|
+
assert p.type == "UnknownType"
|
|
15
|
+
assert "UnknownType" in PROPERTY_TYPES
|
|
16
|
+
PROPERTY_TYPES.discard("UnknownType")
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
class TestInspectableObject:
|
|
@@ -150,3 +152,124 @@ class TestInspectableObject:
|
|
|
150
152
|
assert seg1.get_property("Start").value == 0.0
|
|
151
153
|
assert line.root() is line
|
|
152
154
|
assert seg2.root() is line
|
|
155
|
+
|
|
156
|
+
def test_kind_and_uid(self):
|
|
157
|
+
obj = InspectableObject(name="P0", kind="point", uid="P0")
|
|
158
|
+
assert obj.kind == "point"
|
|
159
|
+
assert obj.uid == "P0"
|
|
160
|
+
|
|
161
|
+
def test_adapter_backref(self):
|
|
162
|
+
adapter = {"hello": "world"}
|
|
163
|
+
obj = InspectableObject(name="Test", adapter=adapter)
|
|
164
|
+
assert obj.adapter is adapter
|
|
165
|
+
|
|
166
|
+
def test_walk(self):
|
|
167
|
+
root = InspectableObject(name="Root")
|
|
168
|
+
a = InspectableObject(name="A")
|
|
169
|
+
b = InspectableObject(name="B")
|
|
170
|
+
root.add_child(a)
|
|
171
|
+
root.add_child(b)
|
|
172
|
+
names = [n.name for n in root.walk()]
|
|
173
|
+
assert names == ["Root", "A", "B"]
|
|
174
|
+
|
|
175
|
+
def test_walk_nested(self):
|
|
176
|
+
root = InspectableObject(name="Root")
|
|
177
|
+
a = InspectableObject(name="A")
|
|
178
|
+
a1 = InspectableObject(name="A1")
|
|
179
|
+
a2 = InspectableObject(name="A2")
|
|
180
|
+
b = InspectableObject(name="B")
|
|
181
|
+
root.add_child(a)
|
|
182
|
+
a.add_child(a1)
|
|
183
|
+
a.add_child(a2)
|
|
184
|
+
root.add_child(b)
|
|
185
|
+
names = [n.name for n in root.walk()]
|
|
186
|
+
assert names == ["Root", "A", "A1", "A2", "B"]
|
|
187
|
+
|
|
188
|
+
def test_walk_up(self):
|
|
189
|
+
child = InspectableObject(name="Child")
|
|
190
|
+
parent = InspectableObject(name="Parent")
|
|
191
|
+
grandparent = InspectableObject(name="Root")
|
|
192
|
+
grandparent.add_child(parent)
|
|
193
|
+
parent.add_child(child)
|
|
194
|
+
names = [n.name for n in child.walk_up()]
|
|
195
|
+
assert names == ["Child", "Parent", "Root"]
|
|
196
|
+
|
|
197
|
+
def test_find_by_kind(self):
|
|
198
|
+
root = InspectableObject(name="Root", kind="group")
|
|
199
|
+
a = InspectableObject(name="A", kind="point")
|
|
200
|
+
b = InspectableObject(name="B", kind="point")
|
|
201
|
+
root.add_child(a)
|
|
202
|
+
root.add_child(b)
|
|
203
|
+
assert root.find(kind="point") is a
|
|
204
|
+
assert root.find(kind="group") is root
|
|
205
|
+
assert root.find(kind="curve") is None
|
|
206
|
+
|
|
207
|
+
def test_find_by_name(self):
|
|
208
|
+
root = InspectableObject(name="Root")
|
|
209
|
+
a = InspectableObject(name="Alpha")
|
|
210
|
+
b = InspectableObject(name="Beta")
|
|
211
|
+
root.add_child(a)
|
|
212
|
+
root.add_child(b)
|
|
213
|
+
assert root.find(name="Beta") is b
|
|
214
|
+
assert root.find(name="Gamma") is None
|
|
215
|
+
|
|
216
|
+
def test_find_by_uid(self):
|
|
217
|
+
root = InspectableObject(name="Root", uid="R0")
|
|
218
|
+
a = InspectableObject(name="A", uid="A0")
|
|
219
|
+
b = InspectableObject(name="B", uid="B0")
|
|
220
|
+
root.add_child(a)
|
|
221
|
+
root.add_child(b)
|
|
222
|
+
assert root.find(uid="B0") is b
|
|
223
|
+
assert root.find(uid="X") is None
|
|
224
|
+
|
|
225
|
+
def test_find_composite(self):
|
|
226
|
+
root = InspectableObject(name="Root", kind="group")
|
|
227
|
+
a = InspectableObject(name="Point", kind="point", uid="P1")
|
|
228
|
+
b = InspectableObject(name="Point", kind="point", uid="P2")
|
|
229
|
+
root.add_child(a)
|
|
230
|
+
root.add_child(b)
|
|
231
|
+
assert root.find(kind="point", uid="P2") is b
|
|
232
|
+
assert root.find(kind="point", name="Point", uid="P1") is a
|
|
233
|
+
|
|
234
|
+
def test_find_all(self):
|
|
235
|
+
root = InspectableObject(name="Root")
|
|
236
|
+
a = InspectableObject(name="A", kind="point")
|
|
237
|
+
b = InspectableObject(name="B", kind="point")
|
|
238
|
+
c = InspectableObject(name="C", kind="curve")
|
|
239
|
+
root.add_child(a)
|
|
240
|
+
root.add_child(b)
|
|
241
|
+
root.add_child(c)
|
|
242
|
+
results = root.find_all(kind="point")
|
|
243
|
+
assert len(results) == 2
|
|
244
|
+
assert a in results
|
|
245
|
+
assert b in results
|
|
246
|
+
assert c not in results
|
|
247
|
+
|
|
248
|
+
def test_find_all_empty(self):
|
|
249
|
+
root = InspectableObject(name="Root")
|
|
250
|
+
assert root.find_all(kind="point") == []
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class TestPropertyAutoRegister:
|
|
254
|
+
def test_unknown_type_auto_registered(self):
|
|
255
|
+
p = Property("Mode", "Enum", "auto")
|
|
256
|
+
assert p.type == "Enum"
|
|
257
|
+
assert "Enum" in PROPERTY_TYPES
|
|
258
|
+
# cleanup so other tests aren't affected
|
|
259
|
+
PROPERTY_TYPES.discard("Enum")
|
|
260
|
+
|
|
261
|
+
def test_string_type_auto_registered(self):
|
|
262
|
+
p = Property("Label", "String", "hello")
|
|
263
|
+
assert p.type == "String"
|
|
264
|
+
assert "String" in PROPERTY_TYPES
|
|
265
|
+
PROPERTY_TYPES.discard("String")
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class TestWalkTree:
|
|
269
|
+
def test_walk_tree(self):
|
|
270
|
+
from core.node import walk_tree
|
|
271
|
+
root = InspectableObject(name="Root")
|
|
272
|
+
a = InspectableObject(name="A")
|
|
273
|
+
root.add_child(a)
|
|
274
|
+
names = [n.name for n in walk_tree(root)]
|
|
275
|
+
assert names == ["Root", "A"]
|
|
@@ -12,6 +12,8 @@ from core.viewport import (
|
|
|
12
12
|
PolygonRegion,
|
|
13
13
|
RectRegion,
|
|
14
14
|
SameGroupRule,
|
|
15
|
+
SelfInMultiRule,
|
|
16
|
+
SelfOrAncestorInMultiRule,
|
|
15
17
|
SelfOrAncestorSelectedRule,
|
|
16
18
|
SiblingSelectedRule,
|
|
17
19
|
ViewportElement,
|
|
@@ -236,3 +238,40 @@ class TestRules:
|
|
|
236
238
|
|
|
237
239
|
rule = NotRule(BooleanRule(False))
|
|
238
240
|
assert rule(sel, obj) is True
|
|
241
|
+
|
|
242
|
+
def test_self_in_multi_rule(self):
|
|
243
|
+
rule = SelfInMultiRule()
|
|
244
|
+
a = InspectableObject(name="A")
|
|
245
|
+
b = InspectableObject(name="B")
|
|
246
|
+
sel = SelectionState()
|
|
247
|
+
assert rule(sel, a) is False
|
|
248
|
+
|
|
249
|
+
sel.select(a)
|
|
250
|
+
sel.toggle_multi(b)
|
|
251
|
+
assert rule(sel, a) is False # a is current, not in multi
|
|
252
|
+
assert rule(sel, b) is True # b is in multi
|
|
253
|
+
|
|
254
|
+
sel.toggle_multi(b)
|
|
255
|
+
assert rule(sel, b) is False # b removed from multi
|
|
256
|
+
|
|
257
|
+
def test_self_or_ancestor_in_multi_rule(self):
|
|
258
|
+
rule = SelfOrAncestorInMultiRule()
|
|
259
|
+
gp = InspectableObject(name="GP")
|
|
260
|
+
p = InspectableObject(name="P")
|
|
261
|
+
c = InspectableObject(name="C")
|
|
262
|
+
gp.add_child(p)
|
|
263
|
+
p.add_child(c)
|
|
264
|
+
|
|
265
|
+
sel = SelectionState()
|
|
266
|
+
assert rule(sel, c) is False
|
|
267
|
+
|
|
268
|
+
# add gp to multi
|
|
269
|
+
sel.select(gp)
|
|
270
|
+
sel.toggle_multi(gp)
|
|
271
|
+
assert rule(sel, c) is True
|
|
272
|
+
assert rule(sel, p) is True
|
|
273
|
+
assert rule(sel, gp) is True
|
|
274
|
+
|
|
275
|
+
# clear multi
|
|
276
|
+
sel.clear_multi()
|
|
277
|
+
assert rule(sel, c) is False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|