Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend overview to docs #43

Merged
merged 1 commit into from
Dec 9, 2024
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
64 changes: 64 additions & 0 deletions docs/backends.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
Backends
========

Overview
--------

The table below gives an overview of the names in the different ``rendercanvas`` backend modules.

.. list-table::

* - **backend module**
- **names**
- **purpose**
* - ``auto``
- | ``RenderCanvas``
| ``loop``
- | Select a backend automatically.
* - ``glfw``
- | ``GlfwRenderCanvas``
| ``RenderCanvas`` (alias)
| ``loop`` (an ``AsyncioLoop``)
- | A lightweight backend.
* - ``jupyter``
- | ``JupyterRenderCanvas``
| ``RenderCanvas`` (alias)
| ``loop`` (an ``AsyncioLoop``)
- | Integrate in Jupyter notebook / lab.
* - ``offscreen``
- | ``OffscreenRenderCanvas``
| ``RenderCanvas`` (alias)
| ``loop`` (a ``StubLoop``)
- | For offscreen rendering.
* - ``qt``
- | ``QRenderCanvas`` (toplevel)
| ``RenderCanvas`` (alias)
| ``QRenderWidget`` (subwidget)
| ``QtLoop``
| ``loop``
- | Create a standalone canvas using Qt, or
| integrate a render canvas in a Qt application.
* - ``wx``
- | ``WxRenderCanvas`` (toplevel)
| ``RenderCanvas`` (alias)
| ``WxRenderWidget`` (subwidget)
| ``WxLoop``
| ``loop``
- | Create a standalone canvas using wx, or
| integrate a render canvas in a wx application.


There are also two loop-backends. These are mainly intended for use with the glfw backend:

.. list-table::

* - **backend module**
- **names**
- **purpose**
* - ``asyncio``
- | ``AsyncoLoop``
| ``loop``
- | Provide a generic loop based on Asyncio.
* - ``trio``
- | ``TrioLoop``
| ``loop``
- | Provide a loop based on Trio.


The auto backend
-----------------

Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
or ``sudo apt install libglfw3-wayland`` when using Wayland.
"""

__all__ = ["RenderCanvas", "loop"]
__all__ = ["GlfwRenderCanvas", "RenderCanvas", "loop"]

import sys
import time
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
can be used as cell output, or embedded in an ipywidgets gui.
"""

__all__ = ["RenderCanvas", "loop"]
__all__ = ["JupyterRenderCanvas", "RenderCanvas", "loop"]

import time

Expand Down
6 changes: 3 additions & 3 deletions rendercanvas/offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Offscreen canvas. No scheduling.
"""

__all__ = ["RenderCanvas", "loop"]
__all__ = ["OffscreenRenderCanvas", "RenderCanvas", "loop"]

import time

Expand All @@ -13,7 +13,7 @@ class OffscreenCanvasGroup(BaseCanvasGroup):
pass


class ManualOffscreenRenderCanvas(BaseRenderCanvas):
class OffscreenRenderCanvas(BaseRenderCanvas):
"""An offscreen canvas intended for manual use.

Call the ``.draw()`` method to perform a draw and get the result.
Expand Down Expand Up @@ -90,7 +90,7 @@ def draw(self):
return self._last_image


RenderCanvas = ManualOffscreenRenderCanvas
RenderCanvas = OffscreenRenderCanvas


class StubLoop(BaseLoop):
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
can be used as a standalone window or in a larger GUI.
"""

__all__ = ["QRenderWidget", "RenderCanvas", "RenderWidget", "loop"]
__all__ = ["QRenderCanvas", "QRenderWidget", "QtLoop", "RenderCanvas", "loop"]

import sys
import ctypes
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A stub backend for documentation purposes.
"""

__all__ = ["RenderCanvas", "loop"]
__all__ = ["RenderCanvas", "StubLoop", "StubRenderCanvas", "loop"]

from .base import BaseCanvasGroup, WrapperRenderCanvas, BaseRenderCanvas, BaseLoop

Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
can be used as a standalone window or in a larger GUI.
"""

__all__ = ["RenderCanvas", "RenderWidget", "WxRenderWidget", "loop"]
__all__ = ["RenderCanvas", "WxLoop", "WxRenderCanvas", "WxRenderWidget", "loop"]

import sys
import time
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_offscreen_module():

canvas_class = m.get_canvas_class()
m.check_canvas(canvas_class)
assert canvas_class.name == "ManualOffscreenRenderCanvas"
assert canvas_class.name == "OffscreenRenderCanvas"


def test_qt_module():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_context.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from rendercanvas.utils.bitmappresentadapter import BitmapPresentAdapter
from rendercanvas.utils.bitmaprenderingcontext import BitmapRenderingContext
from rendercanvas.offscreen import ManualOffscreenRenderCanvas
from rendercanvas.offscreen import OffscreenRenderCanvas as ManualOffscreenRenderCanvas

from testutils import can_use_wgpu_lib, run_tests
import pytest
Expand Down
12 changes: 6 additions & 6 deletions tests/test_offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def test_offscreen_selection_using_env_var():
from rendercanvas.offscreen import ManualOffscreenRenderCanvas
from rendercanvas.offscreen import OffscreenRenderCanvas

ori = os.getenv("RENDERCANVAS_FORCE_OFFSCREEN")
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = "1"
Expand All @@ -24,20 +24,20 @@ def test_offscreen_selection_using_env_var():
for value in ["", "0", "false", "False", "wut"]:
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = value
module = select_backend()
assert module.RenderCanvas is not ManualOffscreenRenderCanvas
assert module.RenderCanvas is not OffscreenRenderCanvas

for value in ["1", "true", "True"]:
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = value
module = select_backend()
assert module.RenderCanvas is ManualOffscreenRenderCanvas
assert module.RenderCanvas is OffscreenRenderCanvas

finally:
if ori is not None:
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = ori


def test_offscreen_selection_using_legacyt_env_var():
from rendercanvas.offscreen import ManualOffscreenRenderCanvas
from rendercanvas.offscreen import OffscreenRenderCanvas

ori1 = os.getenv("RENDERCANVAS_FORCE_OFFSCREEN")
ori2 = os.getenv("WGPU_FORCE_OFFSCREEN")
Expand All @@ -53,12 +53,12 @@ def test_offscreen_selection_using_legacyt_env_var():
for value in ["", "0", "false", "False", "wut"]:
os.environ["WGPU_FORCE_OFFSCREEN"] = value
module = select_backend()
assert module.RenderCanvas is not ManualOffscreenRenderCanvas
assert module.RenderCanvas is not OffscreenRenderCanvas

for value in ["1", "true", "True"]:
os.environ["WGPU_FORCE_OFFSCREEN"] = value
module = select_backend()
assert module.RenderCanvas is ManualOffscreenRenderCanvas
assert module.RenderCanvas is OffscreenRenderCanvas

finally:
if ori1 is not None:
Expand Down
Loading