Skip to content

Generic canvas events (WIP)#61

Draft
gselzer wants to merge 7 commits intopyapp-kit:mainfrom
gselzer:canvas-events
Draft

Generic canvas events (WIP)#61
gselzer wants to merge 7 commits intopyapp-kit:mainfrom
gselzer:canvas-events

Conversation

@gselzer
Copy link
Copy Markdown
Collaborator

@gselzer gselzer commented Mar 30, 2026

Adds KeyPressEvent and KeyReleaseEvent with the goal of enabling keyboard shortcuts in downstream tools such as ndv.

Key events are modeled using app-model's KeyBinding type. Longer-term, we should consider upstreaming pieces of the events system to app-model.

This PR also makes some minor refactors to the events model (e.g. renaming canvas_pospos, world_ray removed from MouseEvent base) in the pursuit of more general events that can be used by Canvas event filters now and maybe upstream in app-model later.

What's included

  • KeyPressEvent and KeyReleaseEvent event types
  • Qt backend support for keyboard events
  • Example: keyboard_pan_zoom.py

TODO

  • Consider adding keyboard shortcuts directly into CameraControllers
  • Jupyter backend keyboard events
  • Wx backend keyboard events

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 82.48588% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.04%. Comparing base (fb0957f) to head (798bbf5).

Files with missing lines Patch % Lines
src/scenex/model/_canvas.py 53.57% 13 Missing ⚠️
src/scenex/app/_jupyter_keymap.py 80.00% 5 Missing ⚠️
src/scenex/app/_wx_keymap.py 79.16% 5 Missing ⚠️
src/scenex/model/_nodes/camera.py 87.87% 4 Missing ⚠️
src/scenex/app/_wx.py 89.65% 3 Missing ⚠️
src/scenex/imgui/_controls.py 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (82.48%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
- Coverage   88.33%   88.04%   -0.29%     
==========================================
  Files          62       64       +2     
  Lines        3060     3162     +102     
==========================================
+ Hits         2703     2784      +81     
- Misses        357      378      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

gselzer added 3 commits March 30, 2026 14:47
As these events become more general we should use broader language
Comment on lines 72 to +76
def _on_view_event(event: Event) -> bool:
if isinstance(event, MouseMoveEvent):
intersections = event.world_ray.intersections(view.scene)
if (ray := view.to_ray(event.pos)) is None:
return False
intersections = ray.intersections(view.scene)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really left wanting for something better than this. We need a way to go from "here's an event" to "here are all of the nodes that pertain to this event"

Will keep thinking on it. Suggestions appreciated too by any passers-by!

gselzer added 2 commits April 10, 2026 13:59
Want to be able to play with these things. Likely will try moving to
app-model at some point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant