wxdiagram 0.1.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.
- wxdiagram-0.1.0/LICENSE.md +21 -0
- wxdiagram-0.1.0/NOTICE.md +25 -0
- wxdiagram-0.1.0/PKG-INFO +147 -0
- wxdiagram-0.1.0/README.md +124 -0
- wxdiagram-0.1.0/pyproject.toml +59 -0
- wxdiagram-0.1.0/setup.cfg +4 -0
- wxdiagram-0.1.0/tests/test_api_contract.py +64 -0
- wxdiagram-0.1.0/tests/test_core_api.py +126 -0
- wxdiagram-0.1.0/tests/test_geometry.py +63 -0
- wxdiagram-0.1.0/tests/test_interaction.py +463 -0
- wxdiagram-0.1.0/tests/test_persistence.py +178 -0
- wxdiagram-0.1.0/tests/test_zoom.py +228 -0
- wxdiagram-0.1.0/wxdiagram/__init__.py +238 -0
- wxdiagram-0.1.0/wxdiagram/basic.py +416 -0
- wxdiagram-0.1.0/wxdiagram/bmpshape.py +97 -0
- wxdiagram-0.1.0/wxdiagram/composite.py +534 -0
- wxdiagram-0.1.0/wxdiagram/core.py +2684 -0
- wxdiagram-0.1.0/wxdiagram/demo.py +402 -0
- wxdiagram-0.1.0/wxdiagram/divided.py +410 -0
- wxdiagram-0.1.0/wxdiagram/geometry.py +737 -0
- wxdiagram-0.1.0/wxdiagram/lines.py +1218 -0
- wxdiagram-0.1.0/wxdiagram/persistence.py +463 -0
- wxdiagram-0.1.0/wxdiagram/polygon.py +38 -0
- wxdiagram-0.1.0/wxdiagram.egg-info/PKG-INFO +147 -0
- wxdiagram-0.1.0/wxdiagram.egg-info/SOURCES.txt +26 -0
- wxdiagram-0.1.0/wxdiagram.egg-info/dependency_links.txt +1 -0
- wxdiagram-0.1.0/wxdiagram.egg-info/requires.txt +1 -0
- wxdiagram-0.1.0/wxdiagram.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2026 Andy Bulka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Notices
|
|
2
|
+
|
|
3
|
+
wxdiagram is a fork of and contains code derived from the following projects.
|
|
4
|
+
All rights in that code remain with their respective authors.
|
|
5
|
+
|
|
6
|
+
## wx.lib.ogl (wxPython)
|
|
7
|
+
|
|
8
|
+
- Files: `wxdiagram/basic.py`, `wxdiagram/geometry.py`, `wxdiagram/lines.py`, `wxdiagram/divided.py`, `wxdiagram/bmpshape.py`, and `wxdiagram/core.py` (adapted)
|
|
9
|
+
- Authors: Pierre Hjälm (2004), from a C++ original by Julian Smart (1998)
|
|
10
|
+
- License: wxWindows / wxWidgets license
|
|
11
|
+
- Copyright notices retained in the file headers
|
|
12
|
+
|
|
13
|
+
## OGLlike
|
|
14
|
+
|
|
15
|
+
- Files: `wxdiagram/core.py` (adapted)
|
|
16
|
+
- Author: Erik R. Lechak (2003-2004)
|
|
17
|
+
- No formal license was stated by the author in the original header, which
|
|
18
|
+
asked that improvements be sent to the author and that credit be kept.
|
|
19
|
+
These credits are retained here. Modifications since 2017 are copyright
|
|
20
|
+
Andy Bulka.
|
|
21
|
+
|
|
22
|
+
## wxdiagram
|
|
23
|
+
|
|
24
|
+
- Author: Andy Bulka (2017-2026)
|
|
25
|
+
- License: MIT, see LICENSE.md
|
wxdiagram-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wxdiagram
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A zoomable shape-and-connector canvas for wxPython
|
|
5
|
+
Author-email: Andy Bulka <abulka@gmail.com>
|
|
6
|
+
Maintainer-email: Andy Bulka <abulka@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/abulka/wxdiagram
|
|
9
|
+
Project-URL: Repository, https://github.com/abulka/wxdiagram
|
|
10
|
+
Project-URL: Issues, https://github.com/abulka/wxdiagram/issues
|
|
11
|
+
Keywords: wxpython,diagram,diagramming,canvas,editor
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Software Development
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.md
|
|
20
|
+
License-File: NOTICE.md
|
|
21
|
+
Requires-Dist: wxpython>=4.2
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# wxdiagram
|
|
25
|
+
|
|
26
|
+
**A zoomable shape-and-connector canvas for wxPython.**
|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/wxdiagram/)
|
|
29
|
+
|
|
30
|
+
`wxdiagram` gives a wxPython application a modern diagram canvas without the
|
|
31
|
+
ceremony of `wx.lib.ogl`: shapes, edges, selection, zoom/pan, and JSON
|
|
32
|
+
persistence in a small MIT-licensed package.
|
|
33
|
+
|
|
34
|
+
It began life as `ogl2`, an internal canvas for
|
|
35
|
+
[pynsource](https://github.com/abulka/pynsource). The name is now retired; this
|
|
36
|
+
repository is the standalone library. See `NOTICE.md` for the `wx.lib.ogl` and
|
|
37
|
+
OGLlike attribution.
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Canvas with real zoom/pan**: `ZoomIn`, `ZoomOut`, `ZoomTo`, `ZoomReset`,
|
|
44
|
+
`ZoomToFit`, `CenterOn`; Ctrl+wheel and macOS pinch zoom anchored at the
|
|
45
|
+
pointer; drag empty canvas to pan; mouse-wheel scrolling; virtual size tracks
|
|
46
|
+
the diagram so panning cannot wander into empty space.
|
|
47
|
+
- **Selection and handles**: shift-click multi-select, resize handles, hover
|
|
48
|
+
ports, drag port-to-shape to connect.
|
|
49
|
+
- **Connectors**: attached lines whose endpoints are clipped to the shapes'
|
|
50
|
+
perimeters, so edges always meet the facing sides and re-route when shapes
|
|
51
|
+
move. Explicit lines support arrowheads (start/middle/end), splines, dashed
|
|
52
|
+
pens, and bend control points.
|
|
53
|
+
- **Shapes**: rectangles, ellipses, polygons, points, lines, bitmaps, divided
|
|
54
|
+
(UML-style) shapes, labelled blocks, composite shapes with layout
|
|
55
|
+
constraints, and non-interactive text labels.
|
|
56
|
+
- **JSON persistence**: `Diagram.Save(path)` / `Diagram.Load(path)` or
|
|
57
|
+
`wxdiagram.persistence`; versioned, portable, no pickle.
|
|
58
|
+
- **Keyboard**: Delete, Tab cycle, Ctrl+A, Ctrl+C/V.
|
|
59
|
+
- **Headless-friendly**: shapes and the diagram model work without showing a
|
|
60
|
+
window.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
Requires Python 3.10+ and wxPython 4.2+.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install wxdiagram
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
or from source with [uv](https://docs.astral.sh/uv/):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git clone https://github.com/abulka/wxdiagram.git
|
|
74
|
+
cd wxdiagram
|
|
75
|
+
uv sync
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quickstart
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import wx
|
|
82
|
+
import wxdiagram
|
|
83
|
+
|
|
84
|
+
app = wx.App(redirect=False)
|
|
85
|
+
frame = wx.Frame(None, title="wxdiagram minimal", size=(600, 400))
|
|
86
|
+
|
|
87
|
+
canvas = wxdiagram.ShapeCanvas(frame)
|
|
88
|
+
canvas.SetDiagram(wxdiagram.Diagram())
|
|
89
|
+
|
|
90
|
+
shape = wxdiagram.RectangleShape(100, 100, 300, 200)
|
|
91
|
+
shape.AddText("hello world")
|
|
92
|
+
canvas.InsertShape(shape, 999)
|
|
93
|
+
|
|
94
|
+
frame.Show()
|
|
95
|
+
canvas.update_virtual_size()
|
|
96
|
+
app.MainLoop()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Connect two blocks with an attached line:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
canvas.join_shapes(left_block, right_block)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The edge routes through the box perimeters, so it stays correct from any
|
|
106
|
+
direction and follows the shapes when they move.
|
|
107
|
+
|
|
108
|
+
## Demo and examples
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
uv run python -m wxdiagram.demo
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The demo shows UML-style class boxes, a composite, a basic-shape gallery, a
|
|
115
|
+
bitmap, a polyline and an arrowed line. It has Add, View and File menus,
|
|
116
|
+
including JSON save/load.
|
|
117
|
+
|
|
118
|
+
Small runnable scripts live in `examples/`:
|
|
119
|
+
|
|
120
|
+
- `minimal_canvas.py` — the 30-line hello world
|
|
121
|
+
- `connect_two_blocks.py` — attached-line connections
|
|
122
|
+
- `zoom_to_fit.py` — zoom and pan
|
|
123
|
+
- `save_load.py` — save and load with JSON
|
|
124
|
+
|
|
125
|
+
## Scope
|
|
126
|
+
|
|
127
|
+
`wxdiagram` is a **canvas library**, not a UML framework or a full layout
|
|
128
|
+
engine. It deliberately does not include:
|
|
129
|
+
|
|
130
|
+
- a UML parser or graph model
|
|
131
|
+
- application menus, licensing, or PlantUML integration
|
|
132
|
+
- a Sugiyama/A* layout engine
|
|
133
|
+
- complete `wx.lib.ogl` API parity
|
|
134
|
+
|
|
135
|
+
Layout is pluggable; an application can run its own layout and hand positions
|
|
136
|
+
to the canvas. See `docs/migration-from-wx-lib-ogl.md` for a detailed
|
|
137
|
+
comparison with `wx.lib.ogl`.
|
|
138
|
+
|
|
139
|
+
## Status
|
|
140
|
+
|
|
141
|
+
Beta (`0.1.0`). The public API is still settling, so pin a version if you
|
|
142
|
+
depend on it. pynsource is the main downstream consumer.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT, see `LICENSE.md`. The `wx.lib.ogl` and OGLlike attribution is in
|
|
147
|
+
`NOTICE.md`.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# wxdiagram
|
|
2
|
+
|
|
3
|
+
**A zoomable shape-and-connector canvas for wxPython.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/wxdiagram/)
|
|
6
|
+
|
|
7
|
+
`wxdiagram` gives a wxPython application a modern diagram canvas without the
|
|
8
|
+
ceremony of `wx.lib.ogl`: shapes, edges, selection, zoom/pan, and JSON
|
|
9
|
+
persistence in a small MIT-licensed package.
|
|
10
|
+
|
|
11
|
+
It began life as `ogl2`, an internal canvas for
|
|
12
|
+
[pynsource](https://github.com/abulka/pynsource). The name is now retired; this
|
|
13
|
+
repository is the standalone library. See `NOTICE.md` for the `wx.lib.ogl` and
|
|
14
|
+
OGLlike attribution.
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **Canvas with real zoom/pan**: `ZoomIn`, `ZoomOut`, `ZoomTo`, `ZoomReset`,
|
|
21
|
+
`ZoomToFit`, `CenterOn`; Ctrl+wheel and macOS pinch zoom anchored at the
|
|
22
|
+
pointer; drag empty canvas to pan; mouse-wheel scrolling; virtual size tracks
|
|
23
|
+
the diagram so panning cannot wander into empty space.
|
|
24
|
+
- **Selection and handles**: shift-click multi-select, resize handles, hover
|
|
25
|
+
ports, drag port-to-shape to connect.
|
|
26
|
+
- **Connectors**: attached lines whose endpoints are clipped to the shapes'
|
|
27
|
+
perimeters, so edges always meet the facing sides and re-route when shapes
|
|
28
|
+
move. Explicit lines support arrowheads (start/middle/end), splines, dashed
|
|
29
|
+
pens, and bend control points.
|
|
30
|
+
- **Shapes**: rectangles, ellipses, polygons, points, lines, bitmaps, divided
|
|
31
|
+
(UML-style) shapes, labelled blocks, composite shapes with layout
|
|
32
|
+
constraints, and non-interactive text labels.
|
|
33
|
+
- **JSON persistence**: `Diagram.Save(path)` / `Diagram.Load(path)` or
|
|
34
|
+
`wxdiagram.persistence`; versioned, portable, no pickle.
|
|
35
|
+
- **Keyboard**: Delete, Tab cycle, Ctrl+A, Ctrl+C/V.
|
|
36
|
+
- **Headless-friendly**: shapes and the diagram model work without showing a
|
|
37
|
+
window.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
Requires Python 3.10+ and wxPython 4.2+.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install wxdiagram
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
or from source with [uv](https://docs.astral.sh/uv/):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/abulka/wxdiagram.git
|
|
51
|
+
cd wxdiagram
|
|
52
|
+
uv sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quickstart
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import wx
|
|
59
|
+
import wxdiagram
|
|
60
|
+
|
|
61
|
+
app = wx.App(redirect=False)
|
|
62
|
+
frame = wx.Frame(None, title="wxdiagram minimal", size=(600, 400))
|
|
63
|
+
|
|
64
|
+
canvas = wxdiagram.ShapeCanvas(frame)
|
|
65
|
+
canvas.SetDiagram(wxdiagram.Diagram())
|
|
66
|
+
|
|
67
|
+
shape = wxdiagram.RectangleShape(100, 100, 300, 200)
|
|
68
|
+
shape.AddText("hello world")
|
|
69
|
+
canvas.InsertShape(shape, 999)
|
|
70
|
+
|
|
71
|
+
frame.Show()
|
|
72
|
+
canvas.update_virtual_size()
|
|
73
|
+
app.MainLoop()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Connect two blocks with an attached line:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
canvas.join_shapes(left_block, right_block)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The edge routes through the box perimeters, so it stays correct from any
|
|
83
|
+
direction and follows the shapes when they move.
|
|
84
|
+
|
|
85
|
+
## Demo and examples
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uv run python -m wxdiagram.demo
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The demo shows UML-style class boxes, a composite, a basic-shape gallery, a
|
|
92
|
+
bitmap, a polyline and an arrowed line. It has Add, View and File menus,
|
|
93
|
+
including JSON save/load.
|
|
94
|
+
|
|
95
|
+
Small runnable scripts live in `examples/`:
|
|
96
|
+
|
|
97
|
+
- `minimal_canvas.py` — the 30-line hello world
|
|
98
|
+
- `connect_two_blocks.py` — attached-line connections
|
|
99
|
+
- `zoom_to_fit.py` — zoom and pan
|
|
100
|
+
- `save_load.py` — save and load with JSON
|
|
101
|
+
|
|
102
|
+
## Scope
|
|
103
|
+
|
|
104
|
+
`wxdiagram` is a **canvas library**, not a UML framework or a full layout
|
|
105
|
+
engine. It deliberately does not include:
|
|
106
|
+
|
|
107
|
+
- a UML parser or graph model
|
|
108
|
+
- application menus, licensing, or PlantUML integration
|
|
109
|
+
- a Sugiyama/A* layout engine
|
|
110
|
+
- complete `wx.lib.ogl` API parity
|
|
111
|
+
|
|
112
|
+
Layout is pluggable; an application can run its own layout and hand positions
|
|
113
|
+
to the canvas. See `docs/migration-from-wx-lib-ogl.md` for a detailed
|
|
114
|
+
comparison with `wx.lib.ogl`.
|
|
115
|
+
|
|
116
|
+
## Status
|
|
117
|
+
|
|
118
|
+
Beta (`0.1.0`). The public API is still settling, so pin a version if you
|
|
119
|
+
depend on it. pynsource is the main downstream consumer.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT, see `LICENSE.md`. The `wx.lib.ogl` and OGLlike attribution is in
|
|
124
|
+
`NOTICE.md`.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wxdiagram"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A zoomable shape-and-connector canvas for wxPython"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE.md", "NOTICE.md"]
|
|
13
|
+
authors = [{ name = "Andy Bulka", email = "abulka@gmail.com" }]
|
|
14
|
+
maintainers = [{ name = "Andy Bulka", email = "abulka@gmail.com" }]
|
|
15
|
+
keywords = ["wxpython", "diagram", "diagramming", "canvas", "editor"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Software Development",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"wxpython>=4.2",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/abulka/wxdiagram"
|
|
29
|
+
Repository = "https://github.com/abulka/wxdiagram"
|
|
30
|
+
Issues = "https://github.com/abulka/wxdiagram/issues"
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=8",
|
|
35
|
+
"pytest-cov>=5",
|
|
36
|
+
"ruff>=0.6",
|
|
37
|
+
"mkdocs-material>=9",
|
|
38
|
+
"mkdocstrings[python]>=0.26",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
include = ["wxdiagram*"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
46
|
+
addopts = "-q"
|
|
47
|
+
|
|
48
|
+
[tool.ruff]
|
|
49
|
+
target-version = "py310"
|
|
50
|
+
line-length = 100
|
|
51
|
+
extend-exclude = ["bin", "docs", "pro"]
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint]
|
|
54
|
+
# Pyflakes + pycodestyle errors, migrated gradually. Keep the rule set small.
|
|
55
|
+
select = ["E4", "E7", "E9", "F"]
|
|
56
|
+
ignore = ["E501"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff.format]
|
|
59
|
+
quote-style = "double"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Public API contract test.
|
|
3
|
+
|
|
4
|
+
These names are the documented library surface. Keep them importable unless a
|
|
5
|
+
breaking release is planned; pynsource is the main downstream consumer.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import wxdiagram
|
|
9
|
+
|
|
10
|
+
PUBLIC_NAMES = [
|
|
11
|
+
# from wxdiagram import ARROW_*
|
|
12
|
+
"ARROW_ARROW",
|
|
13
|
+
"ARROW_DOUBLE_OBLIQUE",
|
|
14
|
+
"ARROW_FILLED_CIRCLE",
|
|
15
|
+
"ARROW_HOLLOW_CIRCLE",
|
|
16
|
+
"ARROW_METAFILE",
|
|
17
|
+
"ARROW_POSITION_END",
|
|
18
|
+
"ARROW_POSITION_MIDDLE",
|
|
19
|
+
"ARROW_POSITION_START",
|
|
20
|
+
"ARROW_SINGLE_OBLIQUE",
|
|
21
|
+
# from wxdiagram import Connectable, Resizeable, Selectable, Attributable
|
|
22
|
+
"Connectable",
|
|
23
|
+
"Resizeable",
|
|
24
|
+
"Selectable",
|
|
25
|
+
"Attributable",
|
|
26
|
+
# from wxdiagram import ...
|
|
27
|
+
"GetArrowPoints",
|
|
28
|
+
"GetPointOnLine",
|
|
29
|
+
"line_control_points_to_xy_points",
|
|
30
|
+
"LineShape",
|
|
31
|
+
"initialize",
|
|
32
|
+
"Shape",
|
|
33
|
+
"RectangleShape",
|
|
34
|
+
"LinesShape",
|
|
35
|
+
"ShapeRegion",
|
|
36
|
+
"FORMAT_NONE",
|
|
37
|
+
"FORMAT_CENTRE_HORIZ",
|
|
38
|
+
"FORMAT_CENTRE_VERT",
|
|
39
|
+
# package-level names
|
|
40
|
+
"ShapeCanvas",
|
|
41
|
+
"Diagram",
|
|
42
|
+
"Shape",
|
|
43
|
+
"Block",
|
|
44
|
+
"DividedShape",
|
|
45
|
+
"BitmapShape",
|
|
46
|
+
"PolygonShape",
|
|
47
|
+
"ShapeEvtHandler",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_public_names_exist():
|
|
52
|
+
missing = [name for name in PUBLIC_NAMES if getattr(wxdiagram, name, None) is None]
|
|
53
|
+
assert not missing, f"wxdiagram is missing public names: {missing}"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_all_exported_names_are_importable():
|
|
57
|
+
for name in wxdiagram.__all__:
|
|
58
|
+
assert getattr(wxdiagram, name, None) is not None, (
|
|
59
|
+
f"wxdiagram.{name} is declared in __all__ but not importable"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_version_is_set():
|
|
64
|
+
assert isinstance(wxdiagram.__version__, str) and wxdiagram.__version__
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Regression tests for the public canvas/diagram contract."""
|
|
2
|
+
|
|
3
|
+
import wx
|
|
4
|
+
|
|
5
|
+
import wxdiagram
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _canvas(wx_app):
|
|
9
|
+
frame = wx.Frame(None)
|
|
10
|
+
canvas = wxdiagram.ShapeCanvas(frame)
|
|
11
|
+
diagram = wxdiagram.Diagram()
|
|
12
|
+
canvas.SetDiagram(diagram)
|
|
13
|
+
return frame, canvas, diagram
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_set_diagram_connects_canvas_and_shapes(wx_app):
|
|
17
|
+
frame, canvas, diagram = _canvas(wx_app)
|
|
18
|
+
assert diagram.GetCanvas() is canvas
|
|
19
|
+
|
|
20
|
+
shape = wxdiagram.RectangleShape(0, 0, 100, 50)
|
|
21
|
+
canvas.AddShape(shape)
|
|
22
|
+
assert shape.GetCanvas() is canvas
|
|
23
|
+
|
|
24
|
+
frame.Destroy()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_add_shape_after_inserts_after_not_before(wx_app):
|
|
28
|
+
frame, canvas, diagram = _canvas(wx_app)
|
|
29
|
+
a = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
30
|
+
b = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
31
|
+
c = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
32
|
+
diagram.AddShape(a)
|
|
33
|
+
diagram.AddShape(c)
|
|
34
|
+
diagram.AddShape(b, addAfter=a)
|
|
35
|
+
assert diagram.shapes.index(b) == diagram.shapes.index(a) + 1
|
|
36
|
+
frame.Destroy()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_diagram_clear_clears_dc_but_keeps_shapes(wx_app):
|
|
40
|
+
frame, canvas, diagram = _canvas(wx_app)
|
|
41
|
+
shape = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
42
|
+
canvas.AddShape(shape)
|
|
43
|
+
|
|
44
|
+
bitmap = wx.Bitmap(20, 20)
|
|
45
|
+
dc = wx.MemoryDC(bitmap)
|
|
46
|
+
diagram.Clear(dc)
|
|
47
|
+
dc.SelectObject(wx.NullBitmap)
|
|
48
|
+
|
|
49
|
+
assert diagram.shapes == [shape]
|
|
50
|
+
frame.Destroy()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_show_all_toggles_visibility(wx_app):
|
|
54
|
+
frame, canvas, diagram = _canvas(wx_app)
|
|
55
|
+
shape = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
56
|
+
canvas.AddShape(shape)
|
|
57
|
+
assert shape.IsShown()
|
|
58
|
+
|
|
59
|
+
diagram.ShowAll(False)
|
|
60
|
+
assert not shape.IsShown()
|
|
61
|
+
|
|
62
|
+
diagram.ShowAll(True)
|
|
63
|
+
assert shape.IsShown()
|
|
64
|
+
frame.Destroy()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_shape_ids_are_stable_and_findable(wx_app):
|
|
68
|
+
frame, canvas, diagram = _canvas(wx_app)
|
|
69
|
+
a = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
70
|
+
b = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
71
|
+
canvas.AddShape(a)
|
|
72
|
+
canvas.AddShape(b)
|
|
73
|
+
|
|
74
|
+
assert a.GetId() > 0
|
|
75
|
+
assert b.GetId() > 0
|
|
76
|
+
assert a.GetId() != b.GetId()
|
|
77
|
+
assert diagram.FindShape(a.GetId()) is a
|
|
78
|
+
assert diagram.FindShape(b.GetId()) is b
|
|
79
|
+
assert diagram.FindShape(999999) is None
|
|
80
|
+
frame.Destroy()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_line_spline_and_arrow_accessors(wx_app):
|
|
84
|
+
line = wxdiagram.LineShape()
|
|
85
|
+
line.MakeLineControlPoints(2)
|
|
86
|
+
line.SetEnds(0, 0, 100, 0)
|
|
87
|
+
|
|
88
|
+
assert not line.IsSpline()
|
|
89
|
+
line.SetSpline(True)
|
|
90
|
+
assert line.IsSpline()
|
|
91
|
+
|
|
92
|
+
arrow = line.AddArrow(wxdiagram.ARROW_ARROW)
|
|
93
|
+
assert line.GetArrows() == [arrow]
|
|
94
|
+
assert line.FindArrowHead(-1, "") is arrow
|
|
95
|
+
assert line.FindArrowHeadId(arrow.GetId()) is arrow
|
|
96
|
+
assert line.DeleteArrowHeadId(arrow.GetId())
|
|
97
|
+
assert line.GetArrows() == []
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_composite_constraints_can_be_inspected_and_cleaned(wx_app):
|
|
101
|
+
parent = wxdiagram.CompositeShape()
|
|
102
|
+
a = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
103
|
+
b = wxdiagram.RectangleShape(0, 0, 10, 10)
|
|
104
|
+
parent.AddChild(a)
|
|
105
|
+
parent.AddChild(b)
|
|
106
|
+
|
|
107
|
+
constraint = parent.AddSimpleConstraint(wxdiagram.CONSTRAINT_ALIGNED_TOP, a, b)
|
|
108
|
+
assert parent.GetConstraints() == [constraint]
|
|
109
|
+
|
|
110
|
+
parent.RemoveChildFromConstraints(b)
|
|
111
|
+
assert parent.GetConstraints() == []
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_persistence_preserves_shape_ids(wx_app, tmp_path):
|
|
115
|
+
frame, canvas, diagram = _canvas(wx_app)
|
|
116
|
+
shape = wxdiagram.RectangleShape(0, 0, 100, 50)
|
|
117
|
+
canvas.AddShape(shape)
|
|
118
|
+
shape_id = shape.GetId()
|
|
119
|
+
|
|
120
|
+
path = tmp_path / "ids.json"
|
|
121
|
+
diagram.Save(path)
|
|
122
|
+
loaded = wxdiagram.Diagram.Load(path)
|
|
123
|
+
|
|
124
|
+
assert loaded.shapes[0].GetId() == shape_id
|
|
125
|
+
assert loaded.FindShape(shape_id) is loaded.shapes[0]
|
|
126
|
+
frame.Destroy()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Tests for the pure-math helpers in wxdiagram.geometry."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
from wxdiagram import (
|
|
6
|
+
GetPointOnLine,
|
|
7
|
+
GetArrowPoints,
|
|
8
|
+
CheckLineIntersection,
|
|
9
|
+
FindEndForBox,
|
|
10
|
+
FindEndForCircle,
|
|
11
|
+
FindEndForPolyline,
|
|
12
|
+
line_control_points_to_xy_points,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_get_point_on_line():
|
|
17
|
+
x, y = GetPointOnLine(0, 0, 100, 0, 10)
|
|
18
|
+
assert math.isclose(x, 90)
|
|
19
|
+
assert math.isclose(y, 0)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_find_end_for_circle():
|
|
23
|
+
# circle centre at origin radius 50; line from origin going right; intersection at x=50
|
|
24
|
+
found = FindEndForCircle(50, 100, 0, 0, 0)
|
|
25
|
+
assert found is not None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_get_arrow_points():
|
|
29
|
+
pts = GetArrowPoints(0, 0, 100, 0, 20, 10)
|
|
30
|
+
assert len(pts) == 6
|
|
31
|
+
# the tip of the arrow is at the end of the line
|
|
32
|
+
assert math.isclose(pts[0], 100)
|
|
33
|
+
assert math.isclose(pts[1], 0)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_check_line_intersection_cross():
|
|
37
|
+
ratio, k_line = CheckLineIntersection(0, 0, 100, 100, 0, 100, 100, 0)
|
|
38
|
+
assert not (ratio == 1.0 and k_line == 1.0) # (1.0, 1.0) means "no intersection"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_check_line_intersection_parallel_is_false():
|
|
42
|
+
ratio, k_line = CheckLineIntersection(0, 0, 100, 0, 0, 10, 100, 10)
|
|
43
|
+
assert ratio == 1.0 and k_line == 1.0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_find_end_for_box():
|
|
47
|
+
pt = FindEndForBox(100, 50, 50, 25, 500, 25)
|
|
48
|
+
assert pt is not None
|
|
49
|
+
# ends at the right edge of the box: 100/2 = 50 from centre
|
|
50
|
+
assert math.isclose(pt[0], 50 + 50, abs_tol=1)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_find_end_for_polyline():
|
|
54
|
+
xvec = [0, 50, 100]
|
|
55
|
+
yvec = [0, 50, 0]
|
|
56
|
+
result = FindEndForPolyline(xvec, yvec, 150, 0, 50, 25)
|
|
57
|
+
assert result is not None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_line_control_points_to_xy_points():
|
|
61
|
+
xs, ys = line_control_points_to_xy_points([(0, 1), (20, 30), (40, 10)])
|
|
62
|
+
assert xs == [0, 20, 40]
|
|
63
|
+
assert ys == [1, 30, 10]
|