diff --git a/README.md b/README.md index 5f4f68f0..2d31416b 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ To render to the screen you can use a variety of GUI toolkits: ```py # The auto backend selects either the glfw, qt or jupyter backend -from wgpu.gui.auto import WgpuCanvas, run, call_later +from wgpu.gui.auto import WgpuCanvas, loop # Visualizations can be embedded as a widget in a Qt application. # Import PySide6, PyQt6, PySide2 or PyQt5 before running the line below. diff --git a/docs/gui.rst b/docs/gui.rst index 7ce65207..0159eaae 100644 --- a/docs/gui.rst +++ b/docs/gui.rst @@ -20,19 +20,18 @@ The Canvas base classes ~WgpuCanvasInterface ~WgpuCanvasBase - ~WgpuAutoGui For each supported GUI toolkit there is a module that implements a ``WgpuCanvas`` class, which inherits from :class:`WgpuCanvasBase`, providing a common API. -The GLFW, Qt, and Jupyter backends also inherit from :class:`WgpuAutoGui` to include -support for events (interactivity). In the next sections we demonstrates the different -canvas classes that you can use. Events ------ +To implement interaction with a ``WgpuCanvas``, use the :func:`WgpuCanvasBase.add_event_handler()` method. +Events come in the following flavours: + .. autoclass:: WgpuEventType :members: @@ -46,22 +45,16 @@ across different machines and environments. Using ``wgpu.gui.auto`` selects a suitable backend depending on the environment and more. See :ref:`interactive_use` for details. -To implement interaction, the ``canvas`` has a :func:`WgpuAutoGui.handle_event()` method -that can be overloaded. Alternatively you can use it's :func:`WgpuAutoGui.add_event_handler()` -method. See the `event spec `_ -for details about the event objects. - -Also see the `triangle auto `_ -and `cube `_ examples that demonstrate the auto gui. +Also see the e.g. the `gui_auto.py `_ example. .. code-block:: py - from wgpu.gui.auto import WgpuCanvas, run, call_later + from wgpu.gui.auto import WgpuCanvas, loop canvas = WgpuCanvas(title="Example") canvas.request_draw(your_draw_function) - run() + loop.run() Support for GLFW @@ -73,12 +66,12 @@ but you can replace ``from wgpu.gui.auto`` with ``from wgpu.gui.glfw`` to force .. code-block:: py - from wgpu.gui.glfw import WgpuCanvas, run, call_later + from wgpu.gui.glfw import WgpuCanvas, loop canvas = WgpuCanvas(title="Example") canvas.request_draw(your_draw_function) - run() + loop() Support for Qt diff --git a/docs/guide.rst b/docs/guide.rst index 5f03221b..f3585e3b 100644 --- a/docs/guide.rst +++ b/docs/guide.rst @@ -19,7 +19,7 @@ GUI toolkits are supported, see the :doc:`gui`. In general, it's easiest to let .. code-block:: py - from wgpu.gui.auto import WgpuCanvas, run + from wgpu.gui.auto import WgpuCanvas canvas = WgpuCanvas(title="a wgpu example") diff --git a/tests/test_gui_auto_offscreen.py b/tests/test_gui_auto_offscreen.py index e01ef8a4..e34c02d0 100644 --- a/tests/test_gui_auto_offscreen.py +++ b/tests/test_gui_auto_offscreen.py @@ -32,14 +32,13 @@ def test_canvas_class(): assert WgpuCanvas is WgpuManualOffscreenCanvas assert issubclass(WgpuCanvas, wgpu.gui.WgpuCanvasBase) - assert issubclass(WgpuCanvas, wgpu.gui.WgpuAutoGui) def test_event_loop(): """Check that the event loop handles queued tasks and then returns.""" # Note: if this test fails, it may run forever, so it's a good idea to have a timeout on the CI job or something - from wgpu.gui.auto import run, call_later + from wgpu.gui.auto import loop ran = False @@ -47,8 +46,8 @@ def check(): nonlocal ran ran = True - call_later(0, check) - run() + loop.call_later(0, check) + loop.run() assert ran diff --git a/tests/test_gui_base.py b/tests/test_gui_base.py index 7174ebac..862cba39 100644 --- a/tests/test_gui_base.py +++ b/tests/test_gui_base.py @@ -117,11 +117,11 @@ def test_run_bare_canvas(): # This is (more or less) the equivalent of: # - # from wgpu.gui.auto import WgpuCanvas, run + # from wgpu.gui.auto import WgpuCanvas, loop # canvas = WgpuCanvas() - # run() + # loop.run() # - # Note: run() calls _draw_frame_and_present() in event loop. + # Note: loop.run() calls _draw_frame_and_present() in event loop. canvas = MyOffscreenCanvas() canvas._draw_frame_and_present() @@ -208,8 +208,8 @@ def draw_frame(): assert canvas.frame_count == 4 -def test_autogui_mixin(): - c = wgpu.gui.WgpuAutoGui() +def test_canvas_base_events(): + c = wgpu.gui.WgpuCanvasBase() # It's a mixin assert not isinstance(c, wgpu.gui.WgpuCanvasBase) diff --git a/tests/test_gui_glfw.py b/tests/test_gui_glfw.py index d894b197..01c3939e 100644 --- a/tests/test_gui_glfw.py +++ b/tests/test_gui_glfw.py @@ -32,11 +32,10 @@ def teardown_module(): pass # Do not glfw.terminate() because other tests may still need glfw -def test_is_autogui(): +def test_is_canvas_base(): from wgpu.gui.glfw import WgpuCanvas assert issubclass(WgpuCanvas, wgpu.gui.WgpuCanvasBase) - assert issubclass(WgpuCanvas, wgpu.gui.WgpuAutoGui) def test_glfw_canvas_basics(): diff --git a/wgpu/gui/auto.py b/wgpu/gui/auto.py index af2de762..a53db5a7 100644 --- a/wgpu/gui/auto.py +++ b/wgpu/gui/auto.py @@ -13,7 +13,7 @@ from ._gui_utils import logger, QT_MODULE_NAMES, get_imported_qt_lib, asyncio_is_running -# Note that wx is not in here, because it does not (yet) implement base.WgpuAutoGui +# Note that wx is not in here, because it does not (yet) fully implement base.WgpuCanvasBase WGPU_GUI_BACKEND_NAMES = ["glfw", "qt", "jupyter", "offscreen"]