-
Notifications
You must be signed in to change notification settings - Fork 8
Support for Pyodide and PyScript #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
c81ab50
393b590
f0f533d
d62dc39
93e3639
bd9b3ab
9017288
a10970d
e62274a
d79656c
8d51188
1044d0f
d393c52
8b71ed7
f197d7d
529c3ec
7025f87
58bc775
51459d3
6cf0ba5
d9f8fc0
fcd2d1c
3e13446
75e3ddc
879399e
7544b77
2dd4824
053f2db
ef8d9d3
475943c
c2b3aa7
485088a
2584ecb
dd8545f
740993a
05d5b6e
69d2381
c2a313f
a338395
041082a
21da505
da6ea72
d8140a5
643263a
6edf5ec
11c6e68
1687744
28bf576
0c881a2
aa0f4cf
24b353b
cba8479
34e4a35
0af1ad0
702a0a4
b4f6d00
2f85d5c
27f45aa
03ca0c0
fc5d5da
9826904
677db3c
bd01cd9
f3bfaf0
464d314
551cc50
8d39bc0
eddaf54
baf518f
4504f7c
b06a8a1
3bcbdde
8f5f72b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| # packages available inside pyodide | ||
| from pyodide.ffi import run_sync, create_proxy | ||
| from js import document, ImageData, Uint8ClampedArray, window, HTMLCanvasElement, ResizeObserver | ||
|
|
||
|
|
||
| # needed for completeness? somehow is required for other examples - hmm? | ||
|
|
@@ -84,7 +84,7 @@ | |
| res += (mouse_button_map.get(i, i),) | ||
| return res | ||
|
|
||
|
|
||
| self._pointer_inside = False # keep track for the pointer_move event | ||
| # resize ? maybe composition? | ||
| # perhaps: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver | ||
|
|
||
|
|
@@ -93,7 +93,7 @@ | |
| # print(entry) | ||
| new_size = () | ||
| ratio = self.get_pixel_ratio() | ||
| if entry.devicePixelContentBoxSize: # safari doesn't | ||
| new_size = (entry.devicePixelContentBoxSize[0].inlineSize, entry.devicePixelContentBoxSize[0].blockSize) | ||
| else: | ||
| lsize = () | ||
|
|
@@ -160,9 +160,9 @@ | |
| self.canvas_element.addEventListener("pointerup", self._pointer_up_proxy) | ||
|
|
||
| # pointer_move | ||
| # TODO: track pointer_inside and pointer_down to only trigger this when relevant? | ||
| # also figure out why it doesn't work in the first place... | ||
| def _html_pointer_move(proxy_args): | ||
| if (not self._pointer_inside) and (not proxy_args.buttons): # only when inside or a button is pressed | ||
| return | ||
| modifiers = tuple( | ||
| [v for k, v in key_mod_map.items() if getattr(proxy_args, k)] | ||
| ) | ||
|
|
@@ -199,6 +199,7 @@ | |
| "time_stamp": proxy_args.timeStamp, | ||
| } | ||
| self.submit_event(event) | ||
| self._pointer_inside = True | ||
|
|
||
| self._pointer_enter_proxy = create_proxy(_html_pointer_enter) | ||
| self.canvas_element.addEventListener("pointerenter", self._pointer_enter_proxy) | ||
|
|
@@ -220,6 +221,7 @@ | |
| "time_stamp": proxy_args.timeStamp, | ||
| } | ||
| self.submit_event(event) | ||
| self._pointer_inside = False | ||
|
|
||
| self._pointer_leave_proxy = create_proxy(_html_pointer_leave) | ||
| self.canvas_element.addEventListener("pointerleave", self._pointer_leave_proxy) | ||
|
|
@@ -299,24 +301,24 @@ | |
| self._key_up_proxy = create_proxy(_html_key_up) | ||
| document.addEventListener("keyup", self._key_up_proxy) | ||
|
|
||
| # char | ||
| def _html_char(proxy_args): | ||
| print(dir(proxy_args)) | ||
| modifiers = tuple( | ||
| [v for k, v in key_mod_map.items() if getattr(proxy_args, k)] | ||
| ) | ||
| event = { | ||
| "event_type": "char", | ||
| "modifiers": modifiers, | ||
| "char_str": proxy_args.key, # unsure if this works, it's experimental anyway: https://github.com/pygfx/rendercanvas/issues/28 | ||
| "time_stamp": proxy_args.timeStamp, | ||
| } | ||
| self.submit_event(event) | ||
|
|
||
| self._char_proxy = create_proxy(_html_char) | ||
| document.addEventListener( | ||
| "input", self._char_proxy | ||
| ) # maybe just another keydown? (seems to include unicode chars) | ||
| # char ... it's not this | ||
| # def _html_char(proxy_args): | ||
|
||
| # print(dir(proxy_args)) | ||
| # modifiers = tuple( | ||
| # [v for k, v in key_mod_map.items() if getattr(proxy_args, k)] | ||
| # ) | ||
| # event = { | ||
| # "event_type": "char", | ||
| # "modifiers": modifiers, | ||
| # "char_str": proxy_args.key, # unsure if this works, it's experimental anyway: https://github.com/pygfx/rendercanvas/issues/28 | ||
| # "time_stamp": proxy_args.timeStamp, | ||
| # } | ||
| # self.submit_event(event) | ||
|
|
||
| # self._char_proxy = create_proxy(_html_char) | ||
| # document.addEventListener( | ||
| # "input", self._char_proxy | ||
| # ) # maybe just another keydown? (seems to include unicode chars) | ||
|
|
||
| # animate event doesn't seem to be actually implemented, and it's by the loop not the gui. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to look into:
Maybe you already have and this comment is entirely moot