-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtriangle_qt.py
42 lines (33 loc) · 1.23 KB
/
triangle_qt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Import the viz from triangle.py and run it in a Qt window.
Works with either PySide6, PyQt6, PyQt5 or PySide2.
"""
# For the sake of making this example Just Work, we try multiple QT libs
try:
from PySide6 import QtWidgets
except ModuleNotFoundError:
try:
from PyQt6 import QtWidgets
except ModuleNotFoundError:
try:
from PySide2 import QtWidgets
except ModuleNotFoundError:
from PyQt5 import QtWidgets
from wgpu.gui.qt import WgpuCanvas # WgpuCanvas is a QWidget subclass
import wgpu.backends.rs # noqa: F401, Select Rust backend
from triangle import main # The function to call to run the visualization
app = QtWidgets.QApplication([])
canvas = WgpuCanvas(title="wgpu triangle with Qt")
device = main(canvas)
# Enter Qt event loop (compatible with qt5/qt6)
app.exec() if hasattr(app, "exec") else app.exec_()
# For those interested, this is a simple way to integrate Qt's event
# loop with asyncio, but for real apps you probably want to use
# something like the qasync library.
# async def mainloop():
# await main_async(canvas)
# while not canvas.is_closed():
# await asyncio.sleep(0.001)
# app.flush()
# app.processEvents()
# loop.stop()