Skip to main content

wxdiagram

A zoomable shape-and-connector canvas for wxPython.

PyPI

wxdiagram gives a wxPython application a modern diagram canvas without the ceremony of wx.lib.ogl: shapes, edges, selection, zoom/pan, and JSON persistence in a small MIT-licensed package.

It began life as ogl2, an internal canvas for pynsource. The name is now retired; this repository is the standalone library. See NOTICE.md for the wx.lib.ogl and OGLlike attribution.

wxdiagram demo

Docs

Documentation

Features

  • Canvas with real zoom/pan: ZoomIn, ZoomOut, ZoomTo, ZoomReset, ZoomToFit, CenterOn; Ctrl+wheel and macOS pinch zoom anchored at the pointer; drag empty canvas to pan; mouse-wheel scrolling; virtual size tracks the diagram so panning cannot wander into empty space.
  • Selection and editing: marquee select (plain drag on empty canvas), Shift/Ctrl add, Esc clear, arrow-key nudge, duplicate, z-order, undo/redo, corner resize handles (proportional by default, Shift = free aspect, Alt = from centre), and drag from a side dot onto another shape to connect. Non-connectable shapes also get edge handles.
  • Grid and guides: optional background grid, snap-to-grid and magnetic alignment guides to other shapes' edges and centres.
  • Connectors: attached lines whose endpoints are clipped to the shapes' perimeters, so edges always meet the facing sides and re-route when shapes move. Explicit lines support arrowheads (start/middle/end), splines, dashed pens, bend control points, editable labels and per-edge routing modes (straight, auto, avoid, curved, orthogonal).
  • Shapes: resizable rectangles, ellipses, polygons (interior hit-testing), points, lines, resizable bitmaps, divided (UML-style) shapes, labelled blocks, composite shapes with layout constraints that scale their children, non-interactive text labels and movable text captions.
  • Layout and routing hooks: an optional spring layout (ShapeCanvas.ApplyLayout), crossing-aware refinement, and experimental injectable edge routers (LineShape.SetRouter, ShapeCanvas.SetDefaultRouter, batch route_many).
  • Export: render the diagram to PNG at any scale (ShapeCanvas.ExportPng).
  • JSON persistence: Diagram.Save(path) / Diagram.Load(path) or wxdiagram.persistence; versioned, portable, no pickle.
  • Keyboard: Delete, Tab cycle, Ctrl+A, Ctrl+C/V.
  • Headless-friendly: shapes and the diagram model work without showing a window.

Installation

Requires Python 3.10+ and wxPython 4.2+.

pip install wxdiagram

On PyPI: https://pypi.org/project/wxdiagram/

or from source with uv:

git clone https://github.com/abulka/wxdiagram.git
cd wxdiagram
uv sync

Quickstart

import wx
import wxdiagram

app = wx.App(redirect=False)
frame = wx.Frame(None, title="wxdiagram minimal", size=(600, 400))

canvas = wxdiagram.ShapeCanvas(frame)
canvas.SetDiagram(wxdiagram.Diagram())

shape = wxdiagram.RectangleShape(100, 100, 300, 200)
shape.AddText("hello world")
canvas.InsertShape(shape, 999)

frame.Show()
canvas.update_virtual_size()
app.MainLoop()

Connect two blocks with an attached line:

canvas.join_shapes(left_block, right_block)

The edge routes through the box perimeters, so it stays correct from any direction and follows the shapes when they move.

Demos and examples

There are three demos:

# 1. Kitchen sink: the full canvas API.
uv run python -m wxdiagram.demo

# 2. Shape editor: Shape Studio-style properties panel and tools.
uv run python -m wxdiagram.shapesdemo

# 3. Layout playground: spring layout, sizes and routing modes.
uv run python -m wxdiagram.layoutdemo

The same entry points are wrapped by ./bin/run, ./bin/run-shapes and ./bin/run-layout.

The kitchen-sink demo is a tour of UML-style class boxes, a composite, a basic-shape gallery, bitmaps, captions, a polyline and an arrowed line. The File/Edit/Add/Arrange/View menus expose JSON save/load, undo/redo, duplicate, delete, z-order, image import and zoom.

The shape editor adds rectangles, circles, ellipses, triangles and free lines; edit name, position, size, colours and border width in the resizable, wrapping properties panel on the right; connect shapes by dragging a round side dot onto another shape; group/ungroup, duplicate and reorder. File/Edit/Add/Arrange/View/Help menus and right-click menus match the main demo, and View > Theme switches between System, Light and Dark.

The layout playground builds a small graph, runs the spring layout, and lets you switch route modes, randomise sizes and reset the graph. (Router injection is experimental and is not exposed in the playground.)

See the layout tutorial for using ApplyLayout and RouteEdges in your own app.

Small runnable scripts live in examples/:

  • minimal_canvas.py — the 30-line hello world
  • connect_two_blocks.py — attached-line connections
  • zoom_to_fit.py — zoom and pan
  • save_load.py — save and load with JSON

Scope

wxdiagram is a canvas library, not a UML framework or a full layout engine. It deliberately does not include:

  • a UML parser or graph model
  • application menus, licensing, or PlantUML integration
  • a Sugiyama/A* layout engine
  • complete wx.lib.ogl API parity

Layout is pluggable; an application can run its own layout and hand positions to the canvas. See docs/migration-from-wx-lib-ogl.md for a detailed comparison with wx.lib.ogl.

Status

Beta (0.2.6). The public API is still settling, so pin a version if you depend on it. pynsource is the main downstream consumer.

License

MIT, see LICENSE.md. The wx.lib.ogl and OGLlike attribution is in NOTICE.md.

Metadata

Release files for wxdiagram 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wxdiagram 0.2.6
File Size Uploaded Provenance Actions
wxdiagram-0.2.6.tar.gz 161.4 kB With provenance Details for wxdiagram-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wxdiagram 0.2.6
File Interpreter ABI Platform Actions
wxdiagram-0.2.6-py3-none-any.whl Python 3 none any Details for wxdiagram-0.2.6-py3-none-any.whl

Total release size: 297.2 kB

Release files / wxdiagram-0.2.6.tar.gz

Download URL wxdiagram-0.2.6.tar.gz
Size 161.4 kB
Tags Source
SHA-256 checksum
How to use checksums
156cc36d3a7cf4b276861a9df01bd6e23e6bdd838feaf8b9ce12b69a0470de01
BLAKE2b-256 checksum
How to use checksums
d50b5d42652f8ecad362f99634b5d8aefa986ef4ce71b6335f26599854f0f3f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / wxdiagram-0.2.6-py3-none-any.whl

Download URL wxdiagram-0.2.6-py3-none-any.whl
Size 135.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d95e46fb119809fc16c8b873a9846ac10dc6433bf89ef0508a21c4890c253650
BLAKE2b-256 checksum
How to use checksums
0a9e872643127b2035ac36af6baa7c94e60451fc7b864250791d7663e1e75b33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for wxdiagram 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for wxdiagram-0.2.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page