Skip to content

Commit

Permalink
More renames, removing inappropriate refs to wgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Nov 6, 2024
1 parent f817810 commit 2ea2598
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable", None),
"wgpu": ("https://wgpu-py.readthedocs.io/en/latest", None),
"wgpu": ("https://wgpu-py.readthedocs.io/en/stable", None),
}

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ GUI libraries
Multiple GUI backends are supported, see :doc:`the GUI API <gui>` for details:

* `glfw <https://github.com/FlorianRhiem/pyGLFW>`_: a lightweight GUI for the desktop
* `jupyter_rfb <https://jupyter-rfb.readthedocs.io>`_: only needed if you plan on using wgpu in Jupyter
* `jupyter_rfb <https://jupyter-rfb.readthedocs.io>`_: only needed if you plan on using Jupyter
* qt (PySide6, PyQt6, PySide2, PyQt5)
* wx
2 changes: 1 addition & 1 deletion examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rendercanvas.auto import RenderCanvas, run


canvas = RenderCanvas(size=(640, 480), title="wgpu events")
canvas = RenderCanvas(size=(640, 480), title="RenderCanvas events")


@canvas.add_event_handler("*")
Expand Down
4 changes: 2 additions & 2 deletions rendercanvas/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EventType(BaseEnum):
This includes the events from the jupyter_rfb event spec (see
https://jupyter-rfb.readthedocs.io/en/stable/events.html) plus some
wgpu-specific events.
rendercanvas-specific events.
"""

# Jupter_rfb spec
Expand Down Expand Up @@ -207,7 +207,7 @@ def emit(self, event):
with log_exception(f"Error during handling {event_type} event"):
callback(event)

def _wgpu_close(self):
def _rc_close(self):
"""Wrap up when the scheduler detects the canvas is closed/dead."""
# This is a little feature because detecting a widget from closing can be tricky.
if not self._closed:
Expand Down
8 changes: 4 additions & 4 deletions rendercanvas/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self):
# loop usually stops when the last window is closed, so the close event may
# not be fired.
# * Keep the GUI going even when the canvas loop is on pause e.g. because its
# minimized (applies to backends that implement _wgpu_gui_poll).
# minimized (applies to backends that implement _rc_gui_poll).
self._gui_timer = self._TimerClass(self, self._tick, one_shot=False)

def _register_scheduler(self, scheduler):
Expand All @@ -145,7 +145,7 @@ def _register_scheduler(self, scheduler):

def _tick(self):
# Keep the GUI alive on every tick
self._wgpu_gui_poll()
self._rc_gui_poll()

# Check all schedulers
schedulers_to_close = []
Expand Down Expand Up @@ -235,7 +235,7 @@ def _call_soon(self, callback, *args):
"""
self.call_later(0, callback, *args)

def _wgpu_gui_poll(self):
def _rc_gui_poll(self):
"""For the subclass to implement:
Some event loops (e.g. asyncio) are just that and dont have a GUI to update.
Expand Down Expand Up @@ -343,7 +343,7 @@ def _get_canvas(self):
canvas = self._canvas_ref()
if canvas is None or canvas.is_closed():
# Pretty nice, we can send a close event, even if the canvas no longer exists
self._events._wgpu_close()
self._events._rc_close()
return None
else:
return canvas
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class AsyncioTimer(BaseTimer):
"""Wgpu timer based on asyncio."""
"""Timer based on asyncio."""

_handle = None

Expand Down
14 changes: 7 additions & 7 deletions rendercanvas/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


# Note that wx is not in here, because it does not (yet) fully implement base.BaseRenderCanvas
WGPU_GUI_BACKEND_NAMES = ["glfw", "qt", "jupyter", "offscreen"]
BACKEND_NAMES = ["glfw", "qt", "jupyter", "offscreen"]


def _load_backend(backend_name):
Expand All @@ -30,7 +30,7 @@ def _load_backend(backend_name):
elif backend_name == "offscreen":
from . import offscreen as module
else: # no-cover
raise ImportError("Unknown wgpu gui backend: '{backend_name}'")
raise ImportError("Unknown rendercanvas backend: '{backend_name}'")
return module


Expand All @@ -53,18 +53,18 @@ def select_backend():

# Always report failed backends, because we only try them when it looks like we can.
if failed_backends:
msg = "WGPU could not load some backends:"
msg = "rendercanvas could not load some backends:"
for key, val in failed_backends.items():
msg += f"\n{key}: {val}"
logger.warning(msg)

# Return or raise
if module is not None:
log = logger.warning if failed_backends else logger.info
log(f"WGPU selected {backend_name} gui because {reason}.")
log(f"Rendercanvas selected {backend_name} backend because {reason}.")
return module
else:
msg = "WGPU Could not load any of the supported GUI backends."
msg = "Rendercanvas could not load any of the supported backends."
if "jupyter" in failed_backends:
msg += "\n You may need to ``pip install -U jupyter_rfb``."
else:
Expand Down Expand Up @@ -94,9 +94,9 @@ def backends_by_env_vars():
# Env var to force a backend for general use
backend_name = os.getenv("WGPU_GUI_BACKEND", "").lower().strip() or None
if backend_name:
if backend_name not in WGPU_GUI_BACKEND_NAMES:
if backend_name not in BACKEND_NAMES:
logger.warning(
f"Ignoring invalid WGPU_GUI_BACKEND '{backend_name}', must be one of {WGPU_GUI_BACKEND_NAMES}"
f"Ignoring invalid WGPU_GUI_BACKEND '{backend_name}', must be one of {BACKEND_NAMES}"
)
backend_name = None
if backend_name:
Expand Down
4 changes: 2 additions & 2 deletions rendercanvas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _process_events(self):
# Get events from the GUI into our event mechanism.
loop = self._get_loop()
if loop:
loop._wgpu_gui_poll()
loop._rc_gui_poll()

# Flush our events, so downstream code can update stuff.
# Maybe that downstream code request a new draw.
Expand Down Expand Up @@ -245,7 +245,7 @@ def force_draw(self):
def _draw_frame_and_present(self):
"""Draw the frame and present the result.
Errors are logged to the "wgpu" logger. Should be called by the
Errors are logged to the "rendercanvas" logger. Should be called by the
subclass at its draw event.
"""

Expand Down
10 changes: 5 additions & 5 deletions rendercanvas/glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
# Make sure that glfw is new enough
glfw_version_info = tuple(int(i) for i in glfw.__version__.split(".")[:2])
if glfw_version_info < (1, 9):
raise ImportError("wgpu-py requires glfw 1.9 or higher.")
raise ImportError("rendercanvas requires glfw 1.9 or higher.")

# Do checks to prevent pitfalls on hybrid Xorg/Wayland systems
is_wayland = False
if sys.platform.startswith("linux") and SYSTEM_IS_WAYLAND:
if not hasattr(glfw, "get_x11_window"):
# Probably glfw was imported before we wgpu was, so we missed our chance
# Probably glfw was imported before this module, so we missed our chance
# to set the env var to make glfw use x11.
is_wayland = True
logger.warning("Using GLFW with Wayland, which is experimental.")
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_physical_size(window):


class GlfwRenderCanvas(BaseRenderCanvas):
"""A glfw window providing a wgpu canvas."""
"""A glfw window providing a render canvas."""

# See https://www.glfw.org/docs/latest/group__window.html

Expand Down Expand Up @@ -201,7 +201,7 @@ def __init__(self, *, size=None, title=None, **kwargs):
self.set_logical_size(*size)
self.set_title(title)

# Callbacks to provide a minimal working canvas for wgpu
# Callbacks to provide a minimal working canvas

def _on_pixelratio_change(self, *args):
if self._changing_pixel_ratio:
Expand Down Expand Up @@ -539,7 +539,7 @@ def init_glfw(self):
self._glfw_initialized = True
atexit.register(glfw.terminate)

def _wgpu_gui_poll(self):
def _rc_gui_poll(self):
glfw.post_empty_event() # Awake the event loop, if it's in wait-mode
glfw.poll_events()
if self.stop_if_no_more_canvases and not tuple(self.all_glfw_canvases):
Expand Down
4 changes: 2 additions & 2 deletions rendercanvas/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class JupyterRenderCanvas(BaseRenderCanvas, RemoteFrameBuffer):
"""An ipywidgets widget providing a wgpu canvas. Needs the jupyter_rfb library."""
"""An ipywidgets widget providing a render canvas. Needs the jupyter_rfb library."""

def __init__(self, *, size=None, title=None, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self):
super().__init__()
self._pending_jupyter_canvases = []

def _wgpu_gui_poll(self):
def _rc_gui_poll(self):
pass # Jupyter is running in a separate process :)

def run(self):
Expand Down
4 changes: 2 additions & 2 deletions rendercanvas/offscreen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .base import BaseRenderCanvas, BaseLoop, BaseTimer


class WgpuManualOffscreenCanvas(BaseRenderCanvas):
class ManualOffscreenRenderCanvas(BaseRenderCanvas):
"""An offscreen canvas intended for manual use.
Call the ``.draw()`` method to perform a draw and get the result.
Expand Down Expand Up @@ -69,7 +69,7 @@ def draw(self):
return self._last_image


RenderCanvas = WgpuManualOffscreenCanvas
RenderCanvas = ManualOffscreenRenderCanvas


class StubTimer(BaseTimer):
Expand Down
16 changes: 8 additions & 8 deletions rendercanvas/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def enable_hidpi():
pass # fail on older Qt's


# If you import this module, you want to use wgpu in a way that does not suck
# If you import this module, you want to render in a way that does not suck
# on high-res monitors. So we apply the minimal configuration to make this so.
# Most apps probably should also set AA_UseHighDpiPixmaps, but it's not
# needed for wgpu, so not our responsibility (some users may NOT want it set).
# needed, so not our responsibility (some users may NOT want it set).
enable_hidpi()

_show_image_method_warning = (
Expand All @@ -140,7 +140,7 @@ def enable_hidpi():


class QRenderWidget(BaseRenderCanvas, QtWidgets.QWidget):
"""A QWidget representing a wgpu canvas that can be embedded in a Qt application."""
"""A QWidget representing a render canvas that can be embedded in a Qt application."""

def __init__(self, *args, present_method=None, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -182,7 +182,7 @@ def paintEngine(self): # noqa: N802 - this is a Qt method
def paintEvent(self, event): # noqa: N802 - this is a Qt method
self._draw_frame_and_present()

# Methods that we add from wgpu (snake_case)
# Methods that we add for BaseRenderCanvas (snake_case)

def _request_draw(self):
# Ask Qt to do a paint event
Expand Down Expand Up @@ -447,7 +447,7 @@ def present_image(self, image_data, **kwargs):


class QRenderCanvas(BaseRenderCanvas, QtWidgets.QWidget):
"""A toplevel Qt widget providing a wgpu canvas."""
"""A toplevel Qt widget providing a render canvas."""

# Most of this is proxying stuff to the inner widget.
# We cannot use a toplevel widget directly, otherwise the window
Expand Down Expand Up @@ -494,7 +494,7 @@ def closeEvent(self, event): # noqa: N802
self._subwidget._is_closed = True
self.submit_event({"event_type": "close"})

# Methods that we add from wgpu (snake_case)
# Methods that we add from BaseRenderCanvas (snake_case)

def _request_draw(self):
self._subwidget._request_draw()
Expand Down Expand Up @@ -549,7 +549,7 @@ def present_image(self, image, **kwargs):


class QtTimer(BaseTimer):
"""Wgpu timer basef on Qt."""
"""Timer basef on Qt."""

def _init(self):
self._qt_timer = QtCore.QTimer()
Expand Down Expand Up @@ -603,7 +603,7 @@ def _stop(self):
if not already_had_app_on_import:
self._app.quit()

def _wgpu_gui_poll(self):
def _rc_gui_poll(self):
pass # we assume the Qt event loop is running. Calling processEvents() will cause recursive repaints.


Expand Down
12 changes: 6 additions & 6 deletions rendercanvas/wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def enable_hidpi():


class WxRenderWidget(BaseRenderCanvas, wx.Window):
"""A wx Window representing a wgpu canvas that can be embedded in a wx application."""
"""A wx Window representing a render canvas that can be embedded in a wx application."""

def __init__(self, *args, present_method=None, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -310,7 +310,7 @@ def _on_mouse_events(self, event: wx.MouseEvent):
def _on_mouse_move(self, event: wx.MouseEvent):
self._mouse_event("pointer_move", event)

# Methods that we add from wgpu
# Methods that we add from BaseRenderCanvas

def _get_surface_ids(self):
if sys.platform.startswith("win") or sys.platform.startswith("darwin"):
Expand Down Expand Up @@ -418,7 +418,7 @@ def present_image(self, image_data, **kwargs):


class WxRenderCanvas(BaseRenderCanvas, wx.Frame):
"""A toplevel wx Frame providing a wgpu canvas."""
"""A toplevel wx Frame providing a render canvas."""

# Most of this is proxying stuff to the inner widget.

Expand All @@ -440,7 +440,7 @@ def __init__(
if not size:
size = 640, 480

self._subwidget = WxWgpuWindow(parent=self, **sub_kwargs)
self._subwidget = WxRenderWidget(parent=self, **sub_kwargs)
self._events = self._subwidget._events
self.Bind(wx.EVT_CLOSE, lambda e: self.Destroy())

Expand Down Expand Up @@ -524,7 +524,7 @@ def Notify(self, *args): # noqa: N802
try:
self._callback()
except RuntimeError:
pass # wrapped C/C++ object of type WxWgpuWindow has been deleted
pass # wrapped C/C++ object of type WxRenderWidget has been deleted


class WxTimer(BaseTimer):
Expand Down Expand Up @@ -565,7 +565,7 @@ def _stop(self):
self._frame_to_keep_loop_alive.Destroy()
_frame_to_keep_loop_alive = None

def _wgpu_gui_poll(self):
def _rc_gui_poll(self):
pass # We can assume the wx loop is running.

def process_wx_events(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


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

ori = os.environ.get("WGPU_FORCE_OFFSCREEN", "")
os.environ["WGPU_FORCE_OFFSCREEN"] = "1"
Expand All @@ -23,12 +23,12 @@ def test_offscreen_selection_using_env_var():
for value in ["", "0", "false", "False", "wut"]:
os.environ["WGPU_FORCE_OFFSCREEN"] = value
module = select_backend()
assert module.RenderCanvas is not WgpuManualOffscreenCanvas
assert module.RenderCanvas is not ManualOffscreenRenderCanvas

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

finally:
os.environ["WGPU_FORCE_OFFSCREEN"] = ori
Expand Down

0 comments on commit 2ea2598

Please sign in to comment.