-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
edf5706
commit b1096ef
Showing
9 changed files
with
155 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
An example that uses events to trigger some canvas functionality. | ||
A nice demo, and very convenient to test the different backends. | ||
* Can be closed with Escape or by pressing the window close button. | ||
* In both cases, it should print "Close detected" exactly once. | ||
* Hit space to spend 2 seconds doing direct draws. | ||
""" | ||
|
||
import time | ||
|
||
from wgpu.gui.auto import WgpuCanvas, loop | ||
|
||
from cube import setup_drawing_sync | ||
|
||
|
||
canvas = WgpuCanvas( | ||
size=(640, 480), | ||
title="Canvas events on $backend - $fps fps", | ||
max_fps=10, | ||
update_mode="continuous", | ||
present_method="", | ||
) | ||
|
||
|
||
draw_frame = setup_drawing_sync(canvas) | ||
canvas.request_draw(lambda: (draw_frame(), canvas.request_draw())) | ||
|
||
|
||
@canvas.add_event_handler("*") | ||
def process_event(event): | ||
if event["event_type"] not in ["pointer_move", "before_draw", "animate"]: | ||
print(event) | ||
|
||
if event["event_type"] == "key_down": | ||
if event["key"] == "Escape": | ||
canvas.close() | ||
elif event["key"] == " ": | ||
etime = time.time() + 2 | ||
i = 0 | ||
while time.time() < etime: | ||
i += 1 | ||
canvas.force_draw() | ||
print(f"force-drawed {i} frames in 2s.") | ||
elif event["event_type"] == "close": | ||
# Should see this exactly once, either when pressing escape, or | ||
# when pressing the window close button. | ||
print("Close detected!") | ||
assert canvas.is_closed() | ||
|
||
|
||
if __name__ == "__main__": | ||
loop.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,26 @@ | ||
""" | ||
A simple example to demonstrate events. | ||
Also serves as a test-app for the canvas backends. | ||
""" | ||
|
||
import time | ||
|
||
from wgpu.gui.auto import WgpuCanvas, loop | ||
|
||
from cube import setup_drawing_sync | ||
|
||
|
||
canvas = WgpuCanvas( | ||
size=(640, 480), | ||
title="wgpu events", | ||
max_fps=10, | ||
update_mode="continuous", | ||
present_method="", | ||
size=(640, 480), title="Canvas events on $backend", update_mode="continuous" | ||
) | ||
|
||
|
||
draw_frame = setup_drawing_sync(canvas) | ||
canvas.request_draw(lambda: (draw_frame(), canvas.request_draw())) | ||
canvas.request_draw(draw_frame) | ||
|
||
|
||
@canvas.add_event_handler("*") | ||
def process_event(event): | ||
if event["event_type"] not in ["pointer_move", "before_draw", "animate"]: | ||
print(event) | ||
|
||
if event["event_type"] == "key_down": | ||
if event["key"] == "Escape": | ||
canvas.close() | ||
elif event["key"] == " ": | ||
etime = time.time() + 2 | ||
i = 0 | ||
while time.time() < etime: | ||
i += 1 | ||
canvas.force_draw() | ||
print(f"force-drawed {i} frames in 2s.") | ||
elif event["event_type"] == "close": | ||
# Should see this exactly once, either when pressing escape, or | ||
# when pressing the window close button. | ||
print("Close detected!") | ||
assert canvas.is_closed() | ||
|
||
|
||
if __name__ == "__main__": | ||
loop.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
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
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
Oops, something went wrong.