Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ 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!

Coming from `wgpu.gui`? Check [from_wgpu_canvas.md](from_wgpu_canvas.md).


## 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).
Providing a generic API for:

* managing a canvas window ([`BaseRenderCanvas`](https://rendercanvas.readthedocs.io/stable/api.html)).
* presenting rendered results with `wgpu` ([`WgpuContext`](https://rendercanvas.readthedocs.io/stable/contexts.html#rendercanvas.contexts.WgpuContext)).
* presenting rendered results as a bitmap ([`BitmapContext`](https://rendercanvas.readthedocs.io/stable/contexts.html#rendercanvas.contexts.BitmapContext)).
* working with events that have standardized behavior.

The main use-case is rendering with [wgpu](https://github.com/pygfx/wgpu-py),
but ``rendercanvas``can be used by anything that can render based on a window-id or
by producing bitmap images.
Implement that on top of a variety of backends:

* Running on desktop with a light backend (glfw).
* Running in the browser (with Pyodide or PyScript).
* Running from a (Jupyter) notebook.
* Embedding as a widget in a GUI library.
* Qt
* wx
* In addition to the GUI libraries mentioned above, the following event loops are supported:
* asyncio
* trio
* raw


## Installation
Expand Down Expand Up @@ -109,8 +115,8 @@ app.exec()

## Async or not async

We support both; a render canvas can be used in a fully async setting using e.g. Asyncio or Trio, or in an event-drived framework like Qt.
If you like callbacks, ``loop.call_later()`` always works. If you like async, use ``loop.add_task()``. Event handlers can always be async.
We support both; a render canvas can be used in a fully async setting using e.g. Asyncio or Trio, or in an event-driven framework like Qt.
If you like callbacks, ``loop.call_later()`` always works. If you like async, use ``loop.add_task()``.
See the [docs on async](https://rendercanvas.readthedocs.io/stable/start.html#async) for details.


Expand Down
2 changes: 1 addition & 1 deletion docs/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ An example using Pyodide directly:
from rendercanvas.auto import RenderCanvas, loop

canvas = RenderCanvas()
context = canvas.get_context("bitmap")
context = canvas.get_bitmap_context()
data = np.random.uniform(127, 255, size=(24, 32, 4)).astype(np.uint8)

@canvas.request_draw
Expand Down
4 changes: 2 additions & 2 deletions examples/pyodide.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
canvas2_el = document.getElementById("canvas2")
canvas_green = RenderCanvas(canvas_element=canvas2_el, size=(320, 240), update_mode="continuous")

context_red = canvas_red.get_context("bitmap")
context_green = canvas_green.get_context("bitmap")
context_red = canvas_red.get_bitmap_context()
context_green = canvas_green.get_bitmap_context()

red_data = np.random.uniform(127, 255, size=(24, 32, 4)).astype(np.uint8)
red_data[..., 0] = 255
Expand Down
4 changes: 2 additions & 2 deletions from_wgpu_canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ This document lists all the changes w.r.t. the last version of the canvas in wgp
* `run` -> `loop.run()`.
* `call_later` -> `loop.call_later`.
* `canvas.is_closed()` -> `canvas.get_closed()`.
* The `canvas.get_context()` must be called with an arg: `canvas.get_context("wgpu")`.
* Instead of `canvas.get_context()`, use `canvas.get_wgpu_context()` (or `canvas.get_context('bitmap')`).


## Improvements

* Overall cleaner code, more tests, better docs.
* Support for contexts other than wgpu.
* Bitmap rendering via builtin`canvas.get_context("bitmap")`.
* Bitmap rendering via builtin`canvas.get_bitmap_context()`.
* Handling of sigint (ctrl+c).
* Support for Trio.
* Support for async event handlers.
Expand Down