Add Keyboard Support to Canvas
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 829
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 40
Description
### What is the problem or limitation you are having?
The Canvas widget is has no keyboard handling. It would be useful to be able to do things like scroll a plot using arrow keys or capture simple keyboard input for games.
### Describe the solution you'd like
Add a callback for keyboard events on the Canvas widget. The callback should be given the key pressed as a Toga Key expression, along with any modifiers, and ideally the text that results from that key combination with the current keyboard layout, if any.
### Describe alternatives you've considered
Leaving it as is, and implementing a more robust input handling system at a higher level that is independent of the Canvas widget. For example the proposal doesn't handle composed keys or entering text in Chinese/Japanese/Korean. These require additional special handling which should be its own subsystem (see eg. hoe Gtk handles composing characters).
### Additional context
This is related to #3994 in so far as the Canvas element can have `keypress` handlers. Looking at how HTML/Javascript handles key presses may give a guide to the information that is passed to the callback.
Contributor guide
Research direction
Start by reviewing the Canvas widget and the related #3994 discussion, then compare the requested callback data with HTML/JavaScript keypress behavior and Toga Key expressions. Clarify how modifiers, resulting text, composed keys, and CJK input are scoped; done means the supported keyboard behavior and its limitations are implemented and documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100