|
16 | 16 | import time |
17 | 17 | import subprocess |
18 | 18 |
|
19 | | -from wgpu.gui import WgpuCanvasBase |
| 19 | +from rendercanvas.asyncio import loop |
| 20 | +from rendercanvas.base import BaseRenderCanvas, BaseCanvasGroup |
20 | 21 |
|
21 | 22 | # Import the function that we must call to run the visualization |
22 | | -from triangle import setup_drawing_sync |
23 | | -# from cube import setup_drawing_sync |
| 23 | +# from triangle import setup_drawing_sync |
| 24 | +from cube import setup_drawing_sync |
24 | 25 |
|
25 | 26 |
|
26 | 27 | code = """ |
27 | 28 | import sys |
28 | 29 | import json |
29 | | -from PySide6 import QtWidgets # Use either PySide6 or PyQt6 |
30 | | -from wgpu.gui.qt import WgpuCanvas |
| 30 | +from PyQt6 import QtWidgets # Use either PySide6 or PyQt6 |
| 31 | +from rendercanvas.qt import RenderCanvas |
31 | 32 |
|
32 | 33 | app = QtWidgets.QApplication([]) |
33 | | -canvas = WgpuCanvas(title="wgpu triangle in Qt subprocess") |
| 34 | +canvas = RenderCanvas(title="wgpu cube in Qt subprocess", update_mode="ondemand") |
34 | 35 |
|
35 | | -print(json.dumps(canvas.get_present_methods())) |
| 36 | +print(json.dumps(canvas._subwidget._rc_get_present_methods())) |
36 | 37 | print(canvas.get_physical_size()) |
37 | 38 | sys.stdout.flush() |
38 | 39 |
|
39 | | -app.exec_() |
| 40 | +app.exec() |
40 | 41 | """ |
41 | 42 |
|
42 | 43 |
|
43 | | -class ProxyCanvas(WgpuCanvasBase): |
| 44 | +class ProxyCanvasGroup(BaseCanvasGroup): |
| 45 | + pass |
| 46 | + |
| 47 | + |
| 48 | +class ProxyCanvas(BaseRenderCanvas): |
| 49 | + _rc_canvas_group = ProxyCanvasGroup(loop) |
| 50 | + |
44 | 51 | def __init__(self): |
45 | 52 | super().__init__() |
46 | 53 | self._present_methods = json.loads(p.stdout.readline().decode()) |
| 54 | + print(self._present_methods) |
47 | 55 | self._psize = tuple( |
48 | 56 | int(x) for x in p.stdout.readline().decode().strip().strip("()").split(",") |
49 | 57 | ) |
50 | 58 | print(self._psize) |
51 | 59 | time.sleep(0.2) |
52 | 60 |
|
53 | | - def get_present_methods(self): |
| 61 | + def _rc_get_present_methods(self): |
54 | 62 | return self._present_methods |
55 | 63 |
|
56 | | - def get_physical_size(self): |
| 64 | + def _rc_request_draw(self): |
| 65 | + loop = self._rc_canvas_group.get_loop() |
| 66 | + loop.call_soon(self._draw_frame_and_present) |
| 67 | + |
| 68 | + def _rc_get_physical_size(self): |
57 | 69 | return self._psize |
58 | 70 |
|
59 | | - def get_pixel_ratio(self): |
| 71 | + def _rc_get_pixel_ratio(self): |
60 | 72 | return 1 |
61 | 73 |
|
62 | | - def get_logical_size(self): |
| 74 | + def _rc_get_logical_size(self): |
63 | 75 | return self._psize |
64 | 76 |
|
65 | | - def set_logical_size(self, width, height): |
| 77 | + def _rc_set_logical_size(self, width, height): |
66 | 78 | pass |
67 | 79 |
|
68 | | - def close(self): |
| 80 | + def _rc_close(self): |
69 | 81 | p.kill() |
70 | 82 |
|
71 | | - def is_closed(self): |
72 | | - raise NotImplementedError() |
73 | | - |
74 | | - def _request_draw(self): |
75 | | - self.draw_frame() |
| 83 | + def _rc_get_closed(self): |
| 84 | + return_code = p.poll() |
| 85 | + return return_code is not None |
76 | 86 |
|
77 | 87 |
|
78 | 88 | # Create subprocess |
79 | 89 | p = subprocess.Popen([sys.executable, "-c", code], stdout=subprocess.PIPE) |
80 | 90 |
|
81 | 91 | # Create a canvas that maps to the window of that subprocess |
82 | 92 | canvas = ProxyCanvas() |
| 93 | +canvas.set_update_mode("continuous") |
83 | 94 |
|
84 | | -# Go! |
| 95 | +# Register our draw function |
85 | 96 | draw_frame = setup_drawing_sync(canvas) |
86 | 97 | canvas.request_draw(draw_frame) |
87 | | -time.sleep(3) |
| 98 | + |
| 99 | +# Start the event loop |
| 100 | +loop.run() |
0 commit comments