object-tree 3.0.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.2.0/PKG-INFO +193 -0
- object_tree-3.2.0/README.md +172 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/core/__init__.py +6 -1
- {object_tree-3.0.0 → object_tree-3.2.0}/core/adapter.py +28 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/core/node.py +64 -3
- {object_tree-3.0.0 → object_tree-3.2.0}/core/selection.py +1 -1
- {object_tree-3.0.0 → object_tree-3.2.0}/core/viewport.py +21 -0
- object_tree-3.2.0/object_tree.egg-info/PKG-INFO +193 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/pyproject.toml +1 -1
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_adapter.py +34 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_node.py +126 -3
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_viewport.py +39 -0
- object_tree-3.0.0/PKG-INFO +0 -42
- object_tree-3.0.0/README.md +0 -21
- object_tree-3.0.0/object_tree.egg-info/PKG-INFO +0 -42
- {object_tree-3.0.0 → object_tree-3.2.0}/core/hittest.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/core/inspector.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/core/interaction.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/core/viewport_system.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/demo/__init__.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/demo/app.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/demo/scene.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/demo/tests/__init__.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/demo/tests/test_scene.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/object_tree.egg-info/SOURCES.txt +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/object_tree.egg-info/dependency_links.txt +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/object_tree.egg-info/requires.txt +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/object_tree.egg-info/top_level.txt +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/rules/__init__.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/rules/boolean_flags.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/rules/function.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/setup.cfg +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_hittest.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_inspector.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_interaction.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_rules.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_selection.py +0 -0
- {object_tree-3.0.0 → object_tree-3.2.0}/tests/test_viewport_system.py +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: object-tree
|
|
3
|
+
Version: 3.2.0
|
|
4
|
+
Summary: A zero-dependency, general-purpose nested selection and inspection framework
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/GrayJou/object_tree
|
|
7
|
+
Project-URL: Repository, https://github.com/GrayJou/object_tree
|
|
8
|
+
Keywords: selection,inspection,viewport,editor,framework
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Provides-Extra: demo
|
|
20
|
+
Requires-Dist: dearpygui>=1.10; extra == "demo"
|
|
21
|
+
|
|
22
|
+
# object-tree
|
|
23
|
+
|
|
24
|
+
A zero-dependency Python framework for nested selection and inspection of hierarchical object trees. Framework-agnostic — no UI toolkit coupling.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install object-tree
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Core has zero runtime dependencies (stdlib only). Optional demo requires DearPyGui:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install "object-tree[demo]"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from core.node import InspectableObject, Property
|
|
42
|
+
from core.selection import SelectionState
|
|
43
|
+
from core.viewport import RectRegion, ViewportElement
|
|
44
|
+
|
|
45
|
+
# Build an object tree
|
|
46
|
+
root = InspectableObject(name="Root")
|
|
47
|
+
child = InspectableObject(name="Child")
|
|
48
|
+
root.add_child(child)
|
|
49
|
+
|
|
50
|
+
# Add properties
|
|
51
|
+
child.add_property(Property("color", "Literal", "#FF5722"))
|
|
52
|
+
|
|
53
|
+
# Selection
|
|
54
|
+
sel = SelectionState()
|
|
55
|
+
sel.select(child)
|
|
56
|
+
print(sel.is_selected(child)) # True
|
|
57
|
+
|
|
58
|
+
# Viewport element with click region
|
|
59
|
+
elem = ViewportElement(target=child, click_region=RectRegion(x=0, y=0, width=100, height=100))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See the [demo app](demo/app.py) for a complete DearPyGui example.
|
|
63
|
+
|
|
64
|
+
## Architecture
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
object-tree/
|
|
68
|
+
core/ # Core framework (zero dependencies)
|
|
69
|
+
node.py InspectableObject tree, Property
|
|
70
|
+
selection.py SelectionState (single + multi)
|
|
71
|
+
inspector.py InspectorSystem, BoxSpec stack
|
|
72
|
+
viewport.py ViewportElement, click regions, Rule system
|
|
73
|
+
viewport_system.py ViewportSystem with hit-testing
|
|
74
|
+
hittest.py point-in-rect/circle/polygon
|
|
75
|
+
interaction.py InteractionController (click → select → refresh)
|
|
76
|
+
adapter.py DictAdapter, InspectableAdapter protocol
|
|
77
|
+
rules/ # Convenience rule builders
|
|
78
|
+
boolean_flags.py VisibilityFlags, SelectabilityFlags
|
|
79
|
+
function.py CustomRule, always_visible/hidden/selectable
|
|
80
|
+
demo/ # DearPyGui demo app (optional dep)
|
|
81
|
+
app.py DPG window with canvas + inspector panel
|
|
82
|
+
scene.py 4-level scene definition
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Key Concepts
|
|
86
|
+
|
|
87
|
+
### InspectableObject
|
|
88
|
+
|
|
89
|
+
Tree node with name, parent, children, properties, and `show_parent_box` flag (controls whether the inspector walks up to the parent).
|
|
90
|
+
|
|
91
|
+
### SelectionState
|
|
92
|
+
|
|
93
|
+
Tracks a primary selected object (with previous selection) and an optional multi-selection set.
|
|
94
|
+
|
|
95
|
+
### ViewportElement
|
|
96
|
+
|
|
97
|
+
Binds an `InspectableObject` to its on-screen representation. Controls visibility and selectability through composable rules:
|
|
98
|
+
|
|
99
|
+
| Rule | True when |
|
|
100
|
+
|------|-----------|
|
|
101
|
+
| `BooleanRule` | Always/never |
|
|
102
|
+
| `ParentSelectedRule` | The object's parent is selected |
|
|
103
|
+
| `SelfOrAncestorSelectedRule` | The object or an ancestor is the selection |
|
|
104
|
+
| `AncestorSelectedRule` | Any ancestor of the object is selected |
|
|
105
|
+
| `SiblingSelectedRule` | A sibling is selected |
|
|
106
|
+
| `SameGroupRule` | Same root tree as the selection |
|
|
107
|
+
|
|
108
|
+
Rules can be combined with `AndRule`, `OrRule`, `NotRule`.
|
|
109
|
+
|
|
110
|
+
### VisibilityFlags / SelectabilityFlags
|
|
111
|
+
|
|
112
|
+
High-level flag classes that translate boolean configuration into rule lists:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from rules.boolean_flags import VisibilityFlags, SelectabilityFlags
|
|
116
|
+
|
|
117
|
+
flags = VisibilityFlags(
|
|
118
|
+
visible_by_default=False,
|
|
119
|
+
reveal_when_parent_selected=True,
|
|
120
|
+
remain_visible_when_self_selected=True,
|
|
121
|
+
)
|
|
122
|
+
flags.apply(element) # Sets element.visible_rules
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Roadmap
|
|
126
|
+
|
|
127
|
+
### v3.x — Current (Stabilization)
|
|
128
|
+
|
|
129
|
+
- [x] Core object tree, selection, inspector, viewport rules
|
|
130
|
+
- [x] Hit-testing (rect, circle, polygon)
|
|
131
|
+
- [x] Interaction controller
|
|
132
|
+
- [x] Dict adapter
|
|
133
|
+
- [x] DearPyGui demo
|
|
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
|
|
138
|
+
|
|
139
|
+
### v4.0 — Events & Observability
|
|
140
|
+
|
|
141
|
+
- [ ] Selection change events (`on_selected`, `on_deselected` callbacks)
|
|
142
|
+
- [ ] Property change events / observable properties
|
|
143
|
+
- [ ] Tree mutation events (child added/removed)
|
|
144
|
+
- [ ] `InspectorSystem` change notification
|
|
145
|
+
|
|
146
|
+
### v4.1 — Undo / Redo
|
|
147
|
+
|
|
148
|
+
- [ ] Command pattern for selection changes
|
|
149
|
+
- [ ] Command pattern for property edits
|
|
150
|
+
- [ ] Undo/redo stack with configurable depth
|
|
151
|
+
- [ ] Keyboard shortcuts integration
|
|
152
|
+
|
|
153
|
+
### v5.0 — Multi-Select & Viewport
|
|
154
|
+
|
|
155
|
+
- [ ] Drag-select box for multi-selection
|
|
156
|
+
- [ ] Modifier-key based toggle selection (Ctrl+click, Shift+click)
|
|
157
|
+
- [ ] Viewport scrolling / panning
|
|
158
|
+
- [ ] Zoom support with coordinate transforms
|
|
159
|
+
|
|
160
|
+
### v5.1 — Adapters & Interop
|
|
161
|
+
|
|
162
|
+
- [ ] Qt adapter (`QStandardItemModel` ↔ `InspectableObject`)
|
|
163
|
+
- [ ] Serialization adapter (JSON / YAML import/export)
|
|
164
|
+
- [ ] Property introspection from dataclasses / attrs
|
|
165
|
+
- [ ] Tree diff/patch for incremental updates
|
|
166
|
+
|
|
167
|
+
### v6.0 — Performance & Tooling
|
|
168
|
+
|
|
169
|
+
- [ ] Virtual viewport (lazy element evaluation for large trees)
|
|
170
|
+
- [ ] Object tree search / filter by name or property
|
|
171
|
+
- [ ] Property validation framework (type, range, regex)
|
|
172
|
+
- [ ] Profiling hooks for rule evaluation
|
|
173
|
+
|
|
174
|
+
### Future Ideas
|
|
175
|
+
|
|
176
|
+
- **Drag and drop** — Reorder objects within and across trees
|
|
177
|
+
- **Templates** — Reusable sub-tree blueprints
|
|
178
|
+
- **Documentation site** — mkdocs or readthedocs
|
|
179
|
+
- **CLI tool** — Inspect and manipulate object trees from the command line
|
|
180
|
+
- **Remote inspection** — WebSocket-based remote tree browser
|
|
181
|
+
- **Game engine adapters** — Godot, Unity, Unreal editor model adapters
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
1. Fork the repository
|
|
186
|
+
2. Create a feature branch (`git checkout -b feature/my-feature`)
|
|
187
|
+
3. Make changes (zero-dependency core, please)
|
|
188
|
+
4. Run tests (`pytest tests/`)
|
|
189
|
+
5. Submit a pull request
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# object-tree
|
|
2
|
+
|
|
3
|
+
A zero-dependency Python framework for nested selection and inspection of hierarchical object trees. Framework-agnostic — no UI toolkit coupling.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install object-tree
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Core has zero runtime dependencies (stdlib only). Optional demo requires DearPyGui:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install "object-tree[demo]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from core.node import InspectableObject, Property
|
|
21
|
+
from core.selection import SelectionState
|
|
22
|
+
from core.viewport import RectRegion, ViewportElement
|
|
23
|
+
|
|
24
|
+
# Build an object tree
|
|
25
|
+
root = InspectableObject(name="Root")
|
|
26
|
+
child = InspectableObject(name="Child")
|
|
27
|
+
root.add_child(child)
|
|
28
|
+
|
|
29
|
+
# Add properties
|
|
30
|
+
child.add_property(Property("color", "Literal", "#FF5722"))
|
|
31
|
+
|
|
32
|
+
# Selection
|
|
33
|
+
sel = SelectionState()
|
|
34
|
+
sel.select(child)
|
|
35
|
+
print(sel.is_selected(child)) # True
|
|
36
|
+
|
|
37
|
+
# Viewport element with click region
|
|
38
|
+
elem = ViewportElement(target=child, click_region=RectRegion(x=0, y=0, width=100, height=100))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
See the [demo app](demo/app.py) for a complete DearPyGui example.
|
|
42
|
+
|
|
43
|
+
## Architecture
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
object-tree/
|
|
47
|
+
core/ # Core framework (zero dependencies)
|
|
48
|
+
node.py InspectableObject tree, Property
|
|
49
|
+
selection.py SelectionState (single + multi)
|
|
50
|
+
inspector.py InspectorSystem, BoxSpec stack
|
|
51
|
+
viewport.py ViewportElement, click regions, Rule system
|
|
52
|
+
viewport_system.py ViewportSystem with hit-testing
|
|
53
|
+
hittest.py point-in-rect/circle/polygon
|
|
54
|
+
interaction.py InteractionController (click → select → refresh)
|
|
55
|
+
adapter.py DictAdapter, InspectableAdapter protocol
|
|
56
|
+
rules/ # Convenience rule builders
|
|
57
|
+
boolean_flags.py VisibilityFlags, SelectabilityFlags
|
|
58
|
+
function.py CustomRule, always_visible/hidden/selectable
|
|
59
|
+
demo/ # DearPyGui demo app (optional dep)
|
|
60
|
+
app.py DPG window with canvas + inspector panel
|
|
61
|
+
scene.py 4-level scene definition
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Key Concepts
|
|
65
|
+
|
|
66
|
+
### InspectableObject
|
|
67
|
+
|
|
68
|
+
Tree node with name, parent, children, properties, and `show_parent_box` flag (controls whether the inspector walks up to the parent).
|
|
69
|
+
|
|
70
|
+
### SelectionState
|
|
71
|
+
|
|
72
|
+
Tracks a primary selected object (with previous selection) and an optional multi-selection set.
|
|
73
|
+
|
|
74
|
+
### ViewportElement
|
|
75
|
+
|
|
76
|
+
Binds an `InspectableObject` to its on-screen representation. Controls visibility and selectability through composable rules:
|
|
77
|
+
|
|
78
|
+
| Rule | True when |
|
|
79
|
+
|------|-----------|
|
|
80
|
+
| `BooleanRule` | Always/never |
|
|
81
|
+
| `ParentSelectedRule` | The object's parent is selected |
|
|
82
|
+
| `SelfOrAncestorSelectedRule` | The object or an ancestor is the selection |
|
|
83
|
+
| `AncestorSelectedRule` | Any ancestor of the object is selected |
|
|
84
|
+
| `SiblingSelectedRule` | A sibling is selected |
|
|
85
|
+
| `SameGroupRule` | Same root tree as the selection |
|
|
86
|
+
|
|
87
|
+
Rules can be combined with `AndRule`, `OrRule`, `NotRule`.
|
|
88
|
+
|
|
89
|
+
### VisibilityFlags / SelectabilityFlags
|
|
90
|
+
|
|
91
|
+
High-level flag classes that translate boolean configuration into rule lists:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from rules.boolean_flags import VisibilityFlags, SelectabilityFlags
|
|
95
|
+
|
|
96
|
+
flags = VisibilityFlags(
|
|
97
|
+
visible_by_default=False,
|
|
98
|
+
reveal_when_parent_selected=True,
|
|
99
|
+
remain_visible_when_self_selected=True,
|
|
100
|
+
)
|
|
101
|
+
flags.apply(element) # Sets element.visible_rules
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Roadmap
|
|
105
|
+
|
|
106
|
+
### v3.x — Current (Stabilization)
|
|
107
|
+
|
|
108
|
+
- [x] Core object tree, selection, inspector, viewport rules
|
|
109
|
+
- [x] Hit-testing (rect, circle, polygon)
|
|
110
|
+
- [x] Interaction controller
|
|
111
|
+
- [x] Dict adapter
|
|
112
|
+
- [x] DearPyGui demo
|
|
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
|
|
117
|
+
|
|
118
|
+
### v4.0 — Events & Observability
|
|
119
|
+
|
|
120
|
+
- [ ] Selection change events (`on_selected`, `on_deselected` callbacks)
|
|
121
|
+
- [ ] Property change events / observable properties
|
|
122
|
+
- [ ] Tree mutation events (child added/removed)
|
|
123
|
+
- [ ] `InspectorSystem` change notification
|
|
124
|
+
|
|
125
|
+
### v4.1 — Undo / Redo
|
|
126
|
+
|
|
127
|
+
- [ ] Command pattern for selection changes
|
|
128
|
+
- [ ] Command pattern for property edits
|
|
129
|
+
- [ ] Undo/redo stack with configurable depth
|
|
130
|
+
- [ ] Keyboard shortcuts integration
|
|
131
|
+
|
|
132
|
+
### v5.0 — Multi-Select & Viewport
|
|
133
|
+
|
|
134
|
+
- [ ] Drag-select box for multi-selection
|
|
135
|
+
- [ ] Modifier-key based toggle selection (Ctrl+click, Shift+click)
|
|
136
|
+
- [ ] Viewport scrolling / panning
|
|
137
|
+
- [ ] Zoom support with coordinate transforms
|
|
138
|
+
|
|
139
|
+
### v5.1 — Adapters & Interop
|
|
140
|
+
|
|
141
|
+
- [ ] Qt adapter (`QStandardItemModel` ↔ `InspectableObject`)
|
|
142
|
+
- [ ] Serialization adapter (JSON / YAML import/export)
|
|
143
|
+
- [ ] Property introspection from dataclasses / attrs
|
|
144
|
+
- [ ] Tree diff/patch for incremental updates
|
|
145
|
+
|
|
146
|
+
### v6.0 — Performance & Tooling
|
|
147
|
+
|
|
148
|
+
- [ ] Virtual viewport (lazy element evaluation for large trees)
|
|
149
|
+
- [ ] Object tree search / filter by name or property
|
|
150
|
+
- [ ] Property validation framework (type, range, regex)
|
|
151
|
+
- [ ] Profiling hooks for rule evaluation
|
|
152
|
+
|
|
153
|
+
### Future Ideas
|
|
154
|
+
|
|
155
|
+
- **Drag and drop** — Reorder objects within and across trees
|
|
156
|
+
- **Templates** — Reusable sub-tree blueprints
|
|
157
|
+
- **Documentation site** — mkdocs or readthedocs
|
|
158
|
+
- **CLI tool** — Inspect and manipulate object trees from the command line
|
|
159
|
+
- **Remote inspection** — WebSocket-based remote tree browser
|
|
160
|
+
- **Game engine adapters** — Godot, Unity, Unreal editor model adapters
|
|
161
|
+
|
|
162
|
+
## Contributing
|
|
163
|
+
|
|
164
|
+
1. Fork the repository
|
|
165
|
+
2. Create a feature branch (`git checkout -b feature/my-feature`)
|
|
166
|
+
3. Make changes (zero-dependency core, please)
|
|
167
|
+
4. Run tests (`pytest tests/`)
|
|
168
|
+
5. Submit a pull request
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|
|
@@ -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."""
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: object-tree
|
|
3
|
+
Version: 3.2.0
|
|
4
|
+
Summary: A zero-dependency, general-purpose nested selection and inspection framework
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/GrayJou/object_tree
|
|
7
|
+
Project-URL: Repository, https://github.com/GrayJou/object_tree
|
|
8
|
+
Keywords: selection,inspection,viewport,editor,framework
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Provides-Extra: demo
|
|
20
|
+
Requires-Dist: dearpygui>=1.10; extra == "demo"
|
|
21
|
+
|
|
22
|
+
# object-tree
|
|
23
|
+
|
|
24
|
+
A zero-dependency Python framework for nested selection and inspection of hierarchical object trees. Framework-agnostic — no UI toolkit coupling.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install object-tree
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Core has zero runtime dependencies (stdlib only). Optional demo requires DearPyGui:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install "object-tree[demo]"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from core.node import InspectableObject, Property
|
|
42
|
+
from core.selection import SelectionState
|
|
43
|
+
from core.viewport import RectRegion, ViewportElement
|
|
44
|
+
|
|
45
|
+
# Build an object tree
|
|
46
|
+
root = InspectableObject(name="Root")
|
|
47
|
+
child = InspectableObject(name="Child")
|
|
48
|
+
root.add_child(child)
|
|
49
|
+
|
|
50
|
+
# Add properties
|
|
51
|
+
child.add_property(Property("color", "Literal", "#FF5722"))
|
|
52
|
+
|
|
53
|
+
# Selection
|
|
54
|
+
sel = SelectionState()
|
|
55
|
+
sel.select(child)
|
|
56
|
+
print(sel.is_selected(child)) # True
|
|
57
|
+
|
|
58
|
+
# Viewport element with click region
|
|
59
|
+
elem = ViewportElement(target=child, click_region=RectRegion(x=0, y=0, width=100, height=100))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See the [demo app](demo/app.py) for a complete DearPyGui example.
|
|
63
|
+
|
|
64
|
+
## Architecture
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
object-tree/
|
|
68
|
+
core/ # Core framework (zero dependencies)
|
|
69
|
+
node.py InspectableObject tree, Property
|
|
70
|
+
selection.py SelectionState (single + multi)
|
|
71
|
+
inspector.py InspectorSystem, BoxSpec stack
|
|
72
|
+
viewport.py ViewportElement, click regions, Rule system
|
|
73
|
+
viewport_system.py ViewportSystem with hit-testing
|
|
74
|
+
hittest.py point-in-rect/circle/polygon
|
|
75
|
+
interaction.py InteractionController (click → select → refresh)
|
|
76
|
+
adapter.py DictAdapter, InspectableAdapter protocol
|
|
77
|
+
rules/ # Convenience rule builders
|
|
78
|
+
boolean_flags.py VisibilityFlags, SelectabilityFlags
|
|
79
|
+
function.py CustomRule, always_visible/hidden/selectable
|
|
80
|
+
demo/ # DearPyGui demo app (optional dep)
|
|
81
|
+
app.py DPG window with canvas + inspector panel
|
|
82
|
+
scene.py 4-level scene definition
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Key Concepts
|
|
86
|
+
|
|
87
|
+
### InspectableObject
|
|
88
|
+
|
|
89
|
+
Tree node with name, parent, children, properties, and `show_parent_box` flag (controls whether the inspector walks up to the parent).
|
|
90
|
+
|
|
91
|
+
### SelectionState
|
|
92
|
+
|
|
93
|
+
Tracks a primary selected object (with previous selection) and an optional multi-selection set.
|
|
94
|
+
|
|
95
|
+
### ViewportElement
|
|
96
|
+
|
|
97
|
+
Binds an `InspectableObject` to its on-screen representation. Controls visibility and selectability through composable rules:
|
|
98
|
+
|
|
99
|
+
| Rule | True when |
|
|
100
|
+
|------|-----------|
|
|
101
|
+
| `BooleanRule` | Always/never |
|
|
102
|
+
| `ParentSelectedRule` | The object's parent is selected |
|
|
103
|
+
| `SelfOrAncestorSelectedRule` | The object or an ancestor is the selection |
|
|
104
|
+
| `AncestorSelectedRule` | Any ancestor of the object is selected |
|
|
105
|
+
| `SiblingSelectedRule` | A sibling is selected |
|
|
106
|
+
| `SameGroupRule` | Same root tree as the selection |
|
|
107
|
+
|
|
108
|
+
Rules can be combined with `AndRule`, `OrRule`, `NotRule`.
|
|
109
|
+
|
|
110
|
+
### VisibilityFlags / SelectabilityFlags
|
|
111
|
+
|
|
112
|
+
High-level flag classes that translate boolean configuration into rule lists:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from rules.boolean_flags import VisibilityFlags, SelectabilityFlags
|
|
116
|
+
|
|
117
|
+
flags = VisibilityFlags(
|
|
118
|
+
visible_by_default=False,
|
|
119
|
+
reveal_when_parent_selected=True,
|
|
120
|
+
remain_visible_when_self_selected=True,
|
|
121
|
+
)
|
|
122
|
+
flags.apply(element) # Sets element.visible_rules
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Roadmap
|
|
126
|
+
|
|
127
|
+
### v3.x — Current (Stabilization)
|
|
128
|
+
|
|
129
|
+
- [x] Core object tree, selection, inspector, viewport rules
|
|
130
|
+
- [x] Hit-testing (rect, circle, polygon)
|
|
131
|
+
- [x] Interaction controller
|
|
132
|
+
- [x] Dict adapter
|
|
133
|
+
- [x] DearPyGui demo
|
|
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
|
|
138
|
+
|
|
139
|
+
### v4.0 — Events & Observability
|
|
140
|
+
|
|
141
|
+
- [ ] Selection change events (`on_selected`, `on_deselected` callbacks)
|
|
142
|
+
- [ ] Property change events / observable properties
|
|
143
|
+
- [ ] Tree mutation events (child added/removed)
|
|
144
|
+
- [ ] `InspectorSystem` change notification
|
|
145
|
+
|
|
146
|
+
### v4.1 — Undo / Redo
|
|
147
|
+
|
|
148
|
+
- [ ] Command pattern for selection changes
|
|
149
|
+
- [ ] Command pattern for property edits
|
|
150
|
+
- [ ] Undo/redo stack with configurable depth
|
|
151
|
+
- [ ] Keyboard shortcuts integration
|
|
152
|
+
|
|
153
|
+
### v5.0 — Multi-Select & Viewport
|
|
154
|
+
|
|
155
|
+
- [ ] Drag-select box for multi-selection
|
|
156
|
+
- [ ] Modifier-key based toggle selection (Ctrl+click, Shift+click)
|
|
157
|
+
- [ ] Viewport scrolling / panning
|
|
158
|
+
- [ ] Zoom support with coordinate transforms
|
|
159
|
+
|
|
160
|
+
### v5.1 — Adapters & Interop
|
|
161
|
+
|
|
162
|
+
- [ ] Qt adapter (`QStandardItemModel` ↔ `InspectableObject`)
|
|
163
|
+
- [ ] Serialization adapter (JSON / YAML import/export)
|
|
164
|
+
- [ ] Property introspection from dataclasses / attrs
|
|
165
|
+
- [ ] Tree diff/patch for incremental updates
|
|
166
|
+
|
|
167
|
+
### v6.0 — Performance & Tooling
|
|
168
|
+
|
|
169
|
+
- [ ] Virtual viewport (lazy element evaluation for large trees)
|
|
170
|
+
- [ ] Object tree search / filter by name or property
|
|
171
|
+
- [ ] Property validation framework (type, range, regex)
|
|
172
|
+
- [ ] Profiling hooks for rule evaluation
|
|
173
|
+
|
|
174
|
+
### Future Ideas
|
|
175
|
+
|
|
176
|
+
- **Drag and drop** — Reorder objects within and across trees
|
|
177
|
+
- **Templates** — Reusable sub-tree blueprints
|
|
178
|
+
- **Documentation site** — mkdocs or readthedocs
|
|
179
|
+
- **CLI tool** — Inspect and manipulate object trees from the command line
|
|
180
|
+
- **Remote inspection** — WebSocket-based remote tree browser
|
|
181
|
+
- **Game engine adapters** — Godot, Unity, Unreal editor model adapters
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
1. Fork the repository
|
|
186
|
+
2. Create a feature branch (`git checkout -b feature/my-feature`)
|
|
187
|
+
3. Make changes (zero-dependency core, please)
|
|
188
|
+
4. Run tests (`pytest tests/`)
|
|
189
|
+
5. Submit a pull request
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|
|
@@ -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
|
object_tree-3.0.0/PKG-INFO
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: object-tree
|
|
3
|
-
Version: 3.0.0
|
|
4
|
-
Summary: A zero-dependency, general-purpose nested selection and inspection framework
|
|
5
|
-
License-Expression: MIT
|
|
6
|
-
Project-URL: Homepage, https://github.com/GrayJou/object_tree
|
|
7
|
-
Project-URL: Repository, https://github.com/GrayJou/object_tree
|
|
8
|
-
Keywords: selection,inspection,viewport,editor,framework
|
|
9
|
-
Classifier: Development Status :: 4 - Beta
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
-
Requires-Python: >=3.10
|
|
18
|
-
Description-Content-Type: text/markdown
|
|
19
|
-
Provides-Extra: demo
|
|
20
|
-
Requires-Dist: dearpygui>=1.10; extra == "demo"
|
|
21
|
-
|
|
22
|
-
# object_tree
|
|
23
|
-
|
|
24
|
-
A zero-dependency, general-purpose nested selection and inspection framework.
|
|
25
|
-
|
|
26
|
-
**Status:** Design phase. The implementation starts from two documents in this repo:
|
|
27
|
-
|
|
28
|
-
- `NestedSelectionIdea.md` — the original concept: object tree, selection state, inspector box stacking, viewport visibility rules, editing groups.
|
|
29
|
-
- `Analysis_NestedSelectionIdea.md` — architecture analysis recommending Phase 1 core types (`InspectableObject`, `SelectionState`, `InspectorSystem`, `ViewportElement`), then adapter layers.
|
|
30
|
-
|
|
31
|
-
Both documents live at the repo root so an agent can read them and implement from the design.
|
|
32
|
-
|
|
33
|
-
## Goals
|
|
34
|
-
|
|
35
|
-
1. N-level recursive selection of objects in a tree hierarchy.
|
|
36
|
-
2. Lightweight, no-dependency core that can be imported by BezierManager, Chromatica2, HLV, or any other consumer.
|
|
37
|
-
3. Clean separation between the object model, selection state, and viewport/UI logic.
|
|
38
|
-
4. Adapter pattern for framework-specific rendering (DearPyGui, etc.) without coupling.
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
*Created 2026-07-02. See `NestedSelectionIdea.md` and `Analysis_NestedSelectionIdea.md` for the full design.*
|
object_tree-3.0.0/README.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# object_tree
|
|
2
|
-
|
|
3
|
-
A zero-dependency, general-purpose nested selection and inspection framework.
|
|
4
|
-
|
|
5
|
-
**Status:** Design phase. The implementation starts from two documents in this repo:
|
|
6
|
-
|
|
7
|
-
- `NestedSelectionIdea.md` — the original concept: object tree, selection state, inspector box stacking, viewport visibility rules, editing groups.
|
|
8
|
-
- `Analysis_NestedSelectionIdea.md` — architecture analysis recommending Phase 1 core types (`InspectableObject`, `SelectionState`, `InspectorSystem`, `ViewportElement`), then adapter layers.
|
|
9
|
-
|
|
10
|
-
Both documents live at the repo root so an agent can read them and implement from the design.
|
|
11
|
-
|
|
12
|
-
## Goals
|
|
13
|
-
|
|
14
|
-
1. N-level recursive selection of objects in a tree hierarchy.
|
|
15
|
-
2. Lightweight, no-dependency core that can be imported by BezierManager, Chromatica2, HLV, or any other consumer.
|
|
16
|
-
3. Clean separation between the object model, selection state, and viewport/UI logic.
|
|
17
|
-
4. Adapter pattern for framework-specific rendering (DearPyGui, etc.) without coupling.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
*Created 2026-07-02. See `NestedSelectionIdea.md` and `Analysis_NestedSelectionIdea.md` for the full design.*
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: object-tree
|
|
3
|
-
Version: 3.0.0
|
|
4
|
-
Summary: A zero-dependency, general-purpose nested selection and inspection framework
|
|
5
|
-
License-Expression: MIT
|
|
6
|
-
Project-URL: Homepage, https://github.com/GrayJou/object_tree
|
|
7
|
-
Project-URL: Repository, https://github.com/GrayJou/object_tree
|
|
8
|
-
Keywords: selection,inspection,viewport,editor,framework
|
|
9
|
-
Classifier: Development Status :: 4 - Beta
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
-
Requires-Python: >=3.10
|
|
18
|
-
Description-Content-Type: text/markdown
|
|
19
|
-
Provides-Extra: demo
|
|
20
|
-
Requires-Dist: dearpygui>=1.10; extra == "demo"
|
|
21
|
-
|
|
22
|
-
# object_tree
|
|
23
|
-
|
|
24
|
-
A zero-dependency, general-purpose nested selection and inspection framework.
|
|
25
|
-
|
|
26
|
-
**Status:** Design phase. The implementation starts from two documents in this repo:
|
|
27
|
-
|
|
28
|
-
- `NestedSelectionIdea.md` — the original concept: object tree, selection state, inspector box stacking, viewport visibility rules, editing groups.
|
|
29
|
-
- `Analysis_NestedSelectionIdea.md` — architecture analysis recommending Phase 1 core types (`InspectableObject`, `SelectionState`, `InspectorSystem`, `ViewportElement`), then adapter layers.
|
|
30
|
-
|
|
31
|
-
Both documents live at the repo root so an agent can read them and implement from the design.
|
|
32
|
-
|
|
33
|
-
## Goals
|
|
34
|
-
|
|
35
|
-
1. N-level recursive selection of objects in a tree hierarchy.
|
|
36
|
-
2. Lightweight, no-dependency core that can be imported by BezierManager, Chromatica2, HLV, or any other consumer.
|
|
37
|
-
3. Clean separation between the object model, selection state, and viewport/UI logic.
|
|
38
|
-
4. Adapter pattern for framework-specific rendering (DearPyGui, etc.) without coupling.
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
*Created 2026-07-02. See `NestedSelectionIdea.md` and `Analysis_NestedSelectionIdea.md` for the full design.*
|
|
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
|