Skip to content

Commit cf4d583

Browse files
authored
Remove wgpu.gui canvases (#735)
* Replace wgpu.gui with a shim for rendercanvas * Remove / update reference to canvas * Update tests_mem * Remove old gui tests and add new ones to test compat with rendecanvas * tweak dependencies * Bring back WgpuCanvasInterface * Adjust for new Ruff
1 parent 7c7b0e8 commit cf4d583

38 files changed

+399
-3586
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ jobs:
7373
python -m pip install --upgrade pip
7474
pip install -e .
7575
- name: Test imports
76-
env:
77-
WGPU_FORCE_OFFSCREEN: true
7876
run: |
7977
python -c "print('wgpu'); import wgpu; print(wgpu)"
8078
python -c "print('wgpu.backends.wgpu_native'); import wgpu.backends.wgpu_native"
81-
python -c "print('wgpu.gui.offscreen'); import wgpu.gui.offscreen"
8279
python -c "print('wgpu.utils'); import wgpu.utils"
8380
8481
docs-build:
@@ -144,7 +141,7 @@ jobs:
144141
run: |
145142
python -m pip install --upgrade pip
146143
pip install -U .
147-
pip install -U pytest numpy psutil pyinstaller glfw
144+
pip install -U pytest numpy psutil pyinstaller
148145
- name: Test PyInstaller
149146
run: |
150147
pushd $HOME

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ API closely resembling the [WebGPU spec](https://gpuweb.github.io/gpuweb/).
6060
## Installation
6161

6262
```
63-
pip install wgpu glfw
63+
# Just wgpu
64+
pip install wgpu
65+
66+
# If you want to render to screen
67+
pip install wgpu rendercanvas glfw
6468
```
6569

6670
Linux users should make sure that **pip >= 20.3**. That should do the
@@ -80,16 +84,13 @@ import wgpu
8084
To render to the screen you can use a variety of GUI toolkits:
8185

8286
```py
83-
# The auto backend selects either the glfw, qt or jupyter backend
84-
from wgpu.gui.auto import WgpuCanvas, run, call_later
87+
# The rendercanvas auto backend selects either the glfw, qt, wx, or jupyter backend
88+
from rendercanvas.auto import RenderCanvas, loop
8589

8690
# Visualizations can be embedded as a widget in a Qt application.
8791
# Import PySide6, PyQt6, PySide2 or PyQt5 before running the line below.
8892
# The code will detect and use the library that is imported.
89-
from wgpu.gui.qt import WgpuCanvas
90-
91-
# Visualizations can be embedded as a widget in a wx application.
92-
from wgpu.gui.wx import WgpuCanvas
93+
from rendercanvas.qt import RenderCanvas
9394
```
9495

9596
Some functions in the original `wgpu-native` API are async. In the Python API,
@@ -159,7 +160,7 @@ call it to see if an image is produced.
159160

160161
To support this type of testing, ensure the following requirements are met:
161162

162-
* The `WgpuCanvas` class is imported from the `wgpu.gui.auto` module.
163+
* The `RenderCanvas` class is imported from the `rendercanvas.auto` module.
163164
* The `canvas` instance is exposed as a global in the module.
164165
* A rendering callback has been registered with `canvas.request_draw(fn)`.
165166

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ROOT_DIR = os.path.abspath(os.path.join(__file__, "..", ".."))
2020
sys.path.insert(0, ROOT_DIR)
2121

22-
os.environ["WGPU_FORCE_OFFSCREEN"] = "true"
22+
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = "true"
2323

2424

2525
# Load wgpu so autodoc can query docstrings
@@ -99,7 +99,7 @@ def resolve_crossrefs(text):
9999

100100

101101
# Tweak docstrings of classes and their methods
102-
for module, hide_class_signature in [(wgpu.classes, True), (wgpu.gui, False)]:
102+
for module, hide_class_signature in [(wgpu.classes, True)]:
103103
for cls_name in module.__all__:
104104
cls = getattr(module, cls_name)
105105
# Class docstring

docs/gui.rst

Lines changed: 0 additions & 212 deletions
This file was deleted.

docs/guide.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Creating a canvas
1515
+++++++++++++++++
1616

1717
If you want to render to the screen, you need a canvas. Multiple
18-
GUI toolkits are supported, see the :doc:`gui`. In general, it's easiest to let ``wgpu`` select a GUI automatically:
18+
GUI toolkits are supported, see https://rendercanvas.readthedocs.io/stable/backends.htm. In general, it's easiest to let ``rendercanvas`` select a GUI automatically:
1919

2020
.. code-block:: py
2121
22-
from wgpu.gui.auto import WgpuCanvas, run
22+
from rendercanvas.auto import RenderCanvas, loop
2323
24-
canvas = WgpuCanvas(title="a wgpu example")
24+
canvas = RenderCanvas(title="a wgpu example")
2525
2626
2727
Next, we can setup the render context, which we will need later on.
@@ -94,21 +94,24 @@ the previous step.
9494
render_pass.end()
9595
device.queue.submit([command_encoder.finish()])
9696
97-
# If you want to draw continuously, request a new draw right now
97+
# You can request a new draw when you know something has changed.
9898
canvas.request_draw()
9999
100+
# Alternatively you can tell the canvas to draw continuously with
101+
# canvas = RenderCanvas(update_mode='continuous')
102+
100103
101104
Starting the event loop
102105
+++++++++++++++++++++++
103106

104107

105108
We can now pass the above render function to the canvas. The canvas will then
106-
call the function whenever it (re)draws the window. And finally, we call ``run()`` to enter the mainloop.
109+
call the function whenever it (re)draws the window. And finally, we call ``loop.run()`` to enter the mainloop.
107110

108111
.. code-block:: py
109112
110113
canvas.request_draw(draw_frame)
111-
run()
114+
loop.run()
112115
113116
114117
Offscreen
@@ -247,8 +250,5 @@ In wgpu a PyInstaller-hook is provided to help simplify the freezing process
247250
(it e.g. ensures that the wgpu-native DLL is included). This hook requires
248251
PyInstaller version 4+.
249252

250-
Our hook also includes ``glfw`` when it is available, so code using ``wgpu.gui.auto``
251-
should Just Work.
252-
253253
Note that PyInstaller needs ``wgpu`` to be installed in `site-packages` for
254254
the hook to work (i.e. it seems not to work with a ``pip -e .`` dev install).

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Welcome to the wgpu-py docs!
1111
guide
1212
wgpu
1313
backends
14-
gui
1514
utils
1615

1716

docs/start.rst

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,11 @@ Python 3.9 or higher is required. Pypy is supported.
1414
pip install wgpu
1515
1616
17-
Since most users will want to render something to screen, we recommend installing GLFW as well:
17+
Since most users will want to render something to screen, we recommend installing `rendercanvas <https://github.com/pygfx/rendercanvas>`_ and `glfw <https://github.com/FlorianRhiem/pyGLFW>`_ as well:
1818

1919
.. code-block:: bash
2020
21-
pip install wgpu glfw
22-
23-
24-
GUI libraries
25-
-------------
26-
27-
Multiple GUI backends are supported, see :doc:`the GUI API <gui>` for details:
28-
29-
* `glfw <https://github.com/FlorianRhiem/pyGLFW>`_: a lightweight GUI for the desktop
30-
* `jupyter_rfb <https://jupyter-rfb.readthedocs.io>`_: only needed if you plan on using wgpu in Jupyter
31-
* qt (PySide6, PyQt6, PySide2, PyQt5)
32-
* wx
21+
pip install wgpu rendercanvas glfw
3322
3423
3524
The wgpu-native library

0 commit comments

Comments
 (0)