Skip to content
Merged
19 changes: 19 additions & 0 deletions examples/gui_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# run_example = false

import sys
import time
import atexit

Expand Down Expand Up @@ -36,6 +37,15 @@
context.set_physical_size(*glfw.get_framebuffer_size(window))


# Setup async callbacks. This is optional, but it enables code using promise.then().
# The asyncgen hook is a stub for the system to detect the call_soon_threadsafe function.
# This works if both are defined on the same class or in the same module.
to_call_soon = []
call_soon_threadsafe = to_call_soon.append
stub_asynchen_hook = lambda agen: None
sys.set_asyncgen_hooks(stub_asynchen_hook)


def main():
draw_frame = setup_drawing_sync(context)

Expand All @@ -50,6 +60,15 @@ def main():
# resize handling
context.set_physical_size(*glfw.get_framebuffer_size(window))

# Call async callbacks (optional, see above)
callbacks = to_call_soon.copy()
to_call_soon.clear()
for cb in callbacks:
try:
cb()
Comment thread
almarklein marked this conversation as resolved.
Outdated
except Exception as err:
print(err)

# draw a frame
draw_frame()
# present the frame to the screen
Expand Down
5 changes: 3 additions & 2 deletions examples/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def test_examples_screenshots(
def unload_module():
del sys.modules[module_name]

request.addfinalizer(unload_module)
if request:
request.addfinalizer(unload_module)

if not hasattr(example, "canvas"):
# some examples we screenshot test don't have a canvas as a global variable when imported,
Expand Down Expand Up @@ -188,4 +189,4 @@ def test_examples_run(module, force_offscreen):
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = "true"
pytest.getoption = lambda x: False
is_lavapipe = True
test_examples_screenshots("validate_volume", pytest, None, None)
test_examples_screenshots("cube", pytest, mock_time, None, None)
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ requires-python = ">= 3.10"
dependencies = [
"cffi>=1.15.0",
"rubicon-objc>=0.4.1; sys_platform == 'darwin'",
"sniffio",
"rendercanvas >=2.4", # Temporarily depend on rendercanvas because we re-aligned apis. Remove in a few months
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_enums_and_flags_and_structs():

def test_base_wgpu_api():
# Fake a device and an adapter
adapter = wgpu.GPUAdapter(None, set(), {}, wgpu.GPUAdapterInfo({}), None)
adapter = wgpu.GPUAdapter(None, set(), {}, wgpu.GPUAdapterInfo({}))
queue = wgpu.GPUQueue("", None, None)
device = wgpu.GPUDevice("device08", -1, adapter, {42, 43}, {}, queue)

Expand Down
Loading
Loading