-
Notifications
You must be signed in to change notification settings - Fork 8
[WIP] proof of concept: HTMLCanvas bitmap context in pyodide #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
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): | ||
|
Comment on lines
+304
to
+305
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have a look at the implementation of char events in jupyter_rfb vispy/jupyter_rfb#119 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at that initially, I tried to avoid actually changing the webpage, but maybe there is no way around it. Which also opens new questions like should the python code spawn new canvases? |
||
| # 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