One canvas API, multiple backends
Project description
rendercanvas
One canvas API, multiple backends 🚀
This project is part of pygfx.org
Introduction
See how the two windows above look the same? That's the idea; they also look the same to the code that renders to them. Yet, the GUI systems are very different (Qt vs glfw in this case). Now that's a powerful abstraction!
Purpose
- Provide a generic canvas API to render to.
- Provide an event loop for scheduling events and draws.
- Provide a simple but powerful event system with standardized event objects.
- Provide various canvas implementations:
- One that is light and easily installed (glfw).
- For various GUI libraries (e.g. qt and wx), so visuzalizations can be embedded in a GUI.
- For specific platforms (e.g. Jupyter, browser).
The main use-case is rendering with wgpu,
but rendercanvas
can be used by anything that can render based on a window-id or
by producing bitmap images.
Installation
pip install rendercanvas
To have at least one backend, we recommend:
pip install rendercanvas glfw
Usage
Also see the online documentation and the examples.
A minimal example that renders noise:
import numpy as np
from rendercanvas.auto import RenderCanvas, loop
canvas = RenderCanvas(update_mode="continuous")
context = canvas.get_context("bitmap")
@canvas.request_draw
def animate():
w, h = canvas.get_logical_size()
bitmap = np.random.uniform(0, 255, (h, w)).astype(np.uint8)
context.set_bitmap(bitmap)
loop.run()
Run wgpu visualizations:
from rendercanvas.auto import RenderCanvas, loop
from rendercanvas.utils.cube import setup_drawing_sync
canvas = RenderCanvas(
title="The wgpu cube example on $backend", update_mode="continuous"
)
draw_frame = setup_drawing_sync(canvas)
canvas.request_draw(draw_frame)
loop.run()
Embed in a Qt application:
from PySide6 import QtWidgets
from rendercanvas.qt import QRenderWidget
class Main(QtWidgets.QWidget):
def __init__(self):
super().__init__()
splitter = QtWidgets.QSplitter()
self.canvas = QRenderWidget(splitter)
...
app = QtWidgets.QApplication([])
main = Main()
app.exec()
License
This code is distributed under the 2-clause BSD license.
Developers
- Clone the repo.
- Install
rendercanvas
and developer deps usingpip install -e .[dev]
. - Use
ruff format
to apply autoformatting. - Use
ruff check
to check for linting errors. - Optionally, if you install pre-commit hooks with
pre-commit install
, lint fixes and formatting will be automatically applied ongit commit
. - Use
pytest tests
to run the tests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rendercanvas-1.0.0.tar.gz
.
File metadata
- Download URL: rendercanvas-1.0.0.tar.gz
- Upload date:
- Size: 51.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c87fe1d91c8fdcd346c2b62ec49415177a3469b7ef57d986e31a9a5dee893a |
|
MD5 | feaf29c624845e2ace01e6520e249193 |
|
BLAKE2b-256 | 72dc15c5b1a4100f97c881d0af62cb48a2becad9a06f44aca9be3232ab34ee13 |
File details
Details for the file rendercanvas-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: rendercanvas-1.0.0-py3-none-any.whl
- Upload date:
- Size: 61.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be1e313ae3ba4fedfe2f3e8e1d21d86e5d721be0fd6d99ef83114c01cfeb0164 |
|
MD5 | 54ffc1d498dc0785d0606429a6d439bb |
|
BLAKE2b-256 | a6c1514c69938c32a5c255edb6959d0f3866d385b4d1ae0d7d873a97e0dc027e |