Skip to content

Handle Tab key in readonly TextInput and NumberInput on GTK - #4779

Open
100jinwoo001 wants to merge 5 commits into
beeware:mainfrom
100jinwoo001:bugfix/2554-gtk-readonly-beep
Open

100jinwoo001 wants to merge 5 commits into
beeware:mainfrom
100jinwoo001:bugfix/2554-gtk-readonly-beep

Conversation

@100jinwoo001

Copy link
Copy Markdown
Contributor

This PR fixes #2554 by intercepting the Tab and Shift+Tab keys when a TextInput or NumberInput is in readonly mode on GTK:

  • In GTK, Gtk.Entry (and Gtk.SpinButton) emits gtk_widget_error_bell (system beep) when a key that would insert a character (like \t) is received while editable is False.
  • In gtk/src/toga_gtk/widgets/textinput.py and gtk/src/toga_gtk/widgets/numberinput.py, when the widget is readonly and Key.TAB is pressed:
    • We navigate focus to the next (Gtk.DirectionType.TAB_FORWARD) or previous (Gtk.DirectionType.TAB_BACKWARD) widget via toplevel.child_focus (GTK3) / root.child_focus (GTK4).
    • We return True so the event is marked handled, preventing Gtk.Entry's default text insertion handler from triggering the error bell.
  • Added towncrier note changes/2554.bugfix.md.

Under GTK, if a readonly text input loses focus as a result of keyboard input (pressing Tab), a system beep was emitted because GtkEntry treated Tab as an unhandled edit attempt before propagating focus.

Fixes #2554

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool
    Assisted-by: ChatGPT

@freakboy3742

Copy link
Copy Markdown
Member

Is this intentionally still in draft status? It seems to be passing CI, so it's unclear if you're planning to do more work here.

@100jinwoo001
100jinwoo001 marked this pull request as ready for review November 3, 2026 12:24

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a relatively straightforward fix; the problem with the PR is that it is untested.

This won't show up as a coverage gap because there's no "branch" involved here - we need to add a testbed case for giving focus to a readonly widget (gated on whether each platform allows a readonly widget to accept focus).

Comment thread changes/2554.bugfix.md Resolved
Comment thread gtk/src/toga_gtk/widgets/numberinput.py Resolved
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.

Readonly Textinput beeps on focus loss with keyboard on GTK

2 participants