-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55d3dfd
commit 48d878e
Showing
3 changed files
with
90 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
An example demonstrating a qt app with a wgpu viz inside. | ||
This is the same as the ``gui_qt_embed.py`` example, except this uses | ||
the asyncio compatible mode that was introduced in Pyside 6.6. | ||
""" | ||
|
||
# ruff: noqa: N802 | ||
# run_example = false | ||
|
||
import time | ||
import asyncio | ||
|
||
from PySide6 import QtWidgets, QtAsyncio | ||
from wgpu.gui.qt import WgpuWidget | ||
from triangle import setup_drawing_sync | ||
|
||
|
||
class ExampleWidget(QtWidgets.QWidget): | ||
def __init__(self): | ||
super().__init__() | ||
self.resize(640, 480) | ||
self.setWindowTitle("wgpu triangle embedded in a qt app") | ||
|
||
splitter = QtWidgets.QSplitter() | ||
|
||
self.button = QtWidgets.QPushButton("Hello world", self) | ||
self.canvas = WgpuWidget(splitter) | ||
self.output = QtWidgets.QTextEdit(splitter) | ||
|
||
# self.button.clicked.connect(self.whenButtonClicked) | ||
self.button.clicked.connect( | ||
lambda: asyncio.ensure_future(self.whenButtonClicked()) | ||
) | ||
|
||
splitter.addWidget( | ||
self.canvas, | ||
) | ||
splitter.addWidget(self.output) | ||
splitter.setSizes([400, 300]) | ||
|
||
layout = QtWidgets.QHBoxLayout() | ||
layout.addWidget(self.button, 0) | ||
layout.addWidget(splitter, 1) | ||
self.setLayout(layout) | ||
|
||
self.show() | ||
|
||
def addLine(self, line): | ||
t = self.output.toPlainText() | ||
t += "\n" + line | ||
self.output.setPlainText(t) | ||
|
||
async def whenButtonClicked(self): | ||
self.addLine("Waiting 1 sec ...") | ||
await asyncio.sleep(1) | ||
self.addLine(f"Clicked at {time.time():0.1f}") | ||
|
||
|
||
app = QtWidgets.QApplication([]) | ||
example = ExampleWidget() | ||
|
||
draw_frame = setup_drawing_sync(example.canvas) | ||
example.canvas.request_draw(draw_frame) | ||
|
||
# Enter Qt event loop the asyncio-compatible way | ||
QtAsyncio.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters