From 874ff7fba32934194f1546766220bd9a5bf2c20f Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Mon, 11 Nov 2024 10:29:43 +0100 Subject: [PATCH] Tweak examples --- examples/cube_auto.py | 9 ++------- examples/cube_glfw.py | 11 ++++------- examples/cube_qt.py | 10 ++-------- examples/cube_wx.py | 11 ++++------- examples/demo.py | 2 +- examples/events.py | 4 ++-- examples/multiple.py | 14 ++++++-------- examples/offsceen_threaded.py | 2 +- examples/qt_app_asyncio.py | 1 - 9 files changed, 22 insertions(+), 42 deletions(-) diff --git a/examples/cube_auto.py b/examples/cube_auto.py index cb6c156..2fe56e1 100644 --- a/examples/cube_auto.py +++ b/examples/cube_auto.py @@ -8,15 +8,10 @@ canvas = RenderCanvas( - size=(640, 480), title=f"The wgpu cube example on a {RenderCanvas.__name__}" + title="The wgpu cube example on $backend", update_mode="continuous" ) draw_frame = setup_drawing_sync(canvas) - - -@canvas.request_draw -def animate(): - draw_frame() - canvas.request_draw() +canvas.request_draw(draw_frame) if __name__ == "__main__": diff --git a/examples/cube_glfw.py b/examples/cube_glfw.py index e1a5529..b817d6c 100644 --- a/examples/cube_glfw.py +++ b/examples/cube_glfw.py @@ -7,14 +7,11 @@ from rendercanvas.utils.cube import setup_drawing_sync -canvas = RenderCanvas(size=(640, 480), title="The wgpu cube example on glfw") +canvas = RenderCanvas( + title="The wgpu cube example on $backend", update_mode="continuous" +) draw_frame = setup_drawing_sync(canvas) - - -@canvas.request_draw -def animate(): - draw_frame() - canvas.request_draw() +canvas.request_draw(draw_frame) if __name__ == "__main__": diff --git a/examples/cube_qt.py b/examples/cube_qt.py index 09be663..a781317 100644 --- a/examples/cube_qt.py +++ b/examples/cube_qt.py @@ -19,18 +19,12 @@ from rendercanvas.qt import RenderCanvas, run - from rendercanvas.utils.cube import setup_drawing_sync -canvas = RenderCanvas(size=(640, 480), title=f"The wgpu cube example on {lib}") +canvas = RenderCanvas(title=f"The wgpu cube example on {lib}", update_mode="continuous") draw_frame = setup_drawing_sync(canvas) - - -@canvas.request_draw -def animate(): - draw_frame() - canvas.request_draw() +canvas.request_draw(draw_frame) if __name__ == "__main__": diff --git a/examples/cube_wx.py b/examples/cube_wx.py index 22441b6..75768f0 100644 --- a/examples/cube_wx.py +++ b/examples/cube_wx.py @@ -7,14 +7,11 @@ from rendercanvas.utils.cube import setup_drawing_sync -canvas = RenderCanvas(size=(640, 480), title="The wgpu cube example on wx") +canvas = RenderCanvas( + title="The wgpu cube example on $backend", update_mode="continuous" +) draw_frame = setup_drawing_sync(canvas) - - -@canvas.request_draw -def animate(): - draw_frame() - canvas.request_draw() +canvas.request_draw(draw_frame) if __name__ == "__main__": diff --git a/examples/demo.py b/examples/demo.py index 37f68fd..04f1d0c 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -26,7 +26,7 @@ draw_frame = setup_drawing_sync(canvas) -canvas.request_draw(lambda: (draw_frame(), canvas.request_draw())) +canvas.request_draw(draw_frame) @canvas.add_event_handler("*") diff --git a/examples/events.py b/examples/events.py index 61f80b2..8161385 100644 --- a/examples/events.py +++ b/examples/events.py @@ -5,12 +5,12 @@ from rendercanvas.auto import RenderCanvas, run -canvas = RenderCanvas(size=(640, 480), title="RenderCanvas events") +canvas = RenderCanvas(title="RenderCanvas events") @canvas.add_event_handler("*") def process_event(event): - if event["event_type"] != "pointer_move": + if event["event_type"] not in ["pointer_move", "before_draw", "draw"]: print(event) diff --git a/examples/multiple.py b/examples/multiple.py index ad26338..c4f73a9 100644 --- a/examples/multiple.py +++ b/examples/multiple.py @@ -1,21 +1,19 @@ """ -Run triangle and cube examples two canvases. +Run cube example in two canvases. """ # test_example = true from rendercanvas.auto import RenderCanvas, loop -from triangle import setup_drawing_sync as setup_drawing_sync_triangle -from cube import setup_drawing_sync as setup_drawing_sync_cube +from rendercanvas.utils.cube import setup_drawing_sync - -canvas1 = RenderCanvas(title=f"Triangle example on {RenderCanvas.__name__}") -draw_frame1 = setup_drawing_sync_triangle(canvas1) +canvas1 = RenderCanvas(title="$backend 1", update_mode="continuous") +draw_frame1 = setup_drawing_sync(canvas1) canvas1.request_draw(draw_frame1) -canvas2 = RenderCanvas(title=f"Cube example on {RenderCanvas.__name__}") -draw_frame2 = setup_drawing_sync_cube(canvas2) +canvas2 = RenderCanvas(title="$backend 2", update_mode="continuous") +draw_frame2 = setup_drawing_sync(canvas2) canvas2.request_draw(draw_frame2) diff --git a/examples/offsceen_threaded.py b/examples/offsceen_threaded.py index 24954ef..bf8b5de 100644 --- a/examples/offsceen_threaded.py +++ b/examples/offsceen_threaded.py @@ -19,7 +19,7 @@ from rendercanvas.offscreen import RenderCanvas -from cube import setup_drawing_sync +from rendercanvas.utils.cube import setup_drawing_sync # create canvas diff --git a/examples/qt_app_asyncio.py b/examples/qt_app_asyncio.py index a9c5d38..fc00287 100644 --- a/examples/qt_app_asyncio.py +++ b/examples/qt_app_asyncio.py @@ -47,7 +47,6 @@ def __init__(self): splitter = QtWidgets.QSplitter() - # todo: use update_mode = 'continuous' when that feature has arrived self.button = QtWidgets.QPushButton("Hello world", self) self.canvas = QRenderWidget(splitter, update_mode="continuous") self.output = QtWidgets.QTextEdit(splitter)