Skip to content

Conversation

@bruno-rino
Copy link
Contributor

Pressing the Return key on a table or tree should be semantically identical to double clicking. This PR aims to do that, by invoking on_activate, just like double clicking does.

On GTK, this is the default behaviour, so nothing to do there.

There's a small snag when multiple_select is enabled.
Currently, on_activate has an argument: the row/node that was double clicked.
When pressing Return when multiple rows are selected, there isn't a single row that should be activated. I chose to not invoke the event in this case.

I placed the code that helps handling this on the core widgets: the _selection_single method. This way it can be shared across implementations.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@johnzhou721
Copy link
Contributor

Winforms failure is unrelated. c.f. the latest run on #3769

@mhsmith
Copy link
Member

mhsmith commented Sep 29, 2025

I've restarted CI; if it passes and you think the PR is ready for review, please post a comment.

@bruno-rino bruno-rino marked this pull request as ready for review October 2, 2025 10:57
@bruno-rino
Copy link
Contributor Author

I think this PR is ready for review.

@freakboy3742 freakboy3742 requested a review from mhsmith October 5, 2025 23:22
@mhsmith mhsmith changed the title Enable keyboard activate Enable keyboard on_activate in Table and Tree Oct 6, 2025
@mhsmith
Copy link
Member

mhsmith commented Oct 6, 2025

I'm currently preparing a demo for Wednesday, so I may not get a chance to look at this until Thursday.

Copy link
Member

Choose a reason for hiding this comment

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

We recently switched the documentation from RST to Markdown, so please rename this file to .md.

on_select_handler.assert_called_once_with(widget)
on_select_handler.reset_mock()
await probe.type_character("a")
await probe.redraw("Letter pressed - forth row selected")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await probe.redraw("Letter pressed - forth row selected")
await probe.redraw("Letter pressed - fourth row selected")

# Activate row
assert widget.selection == source[3]
await probe.type_character("\n")
await probe.redraw("Return key pressed - forth row activated")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await probe.redraw("Return key pressed - forth row activated")
await probe.redraw("Return key pressed - fourth row activated")


async def test_activate_keyboard(
widget,
probe,
Copy link
Member

Choose a reason for hiding this comment

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

This partly duplicates test_keyboard_navigation, so I think it would be better to merge them all into a single test, which covers activation of at least two different items.

Copy link
Member

Choose a reason for hiding this comment

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

My comments on test_table also apply to test_tree.

Also, there are several places in this file where "table" and "row" should be replaced by "tree" and "node".

Copy link
Member

Choose a reason for hiding this comment

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

Duplicate code between Tree and Table should be merged.

Copy link
Member

Choose a reason for hiding this comment

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

The Tree and Table implementations are duplicated, so please merge them into one. Don't worry about the type annotations, because we only use them for documentation of the public API.

Copy link
Contributor Author

@bruno-rino bruno-rino Oct 14, 2025

Choose a reason for hiding this comment

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

Where should this code shared between table and tree live?
Is it OK to add an from toga.widgets.table import ... in tree.py?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if there isn't any more obvious place, then it's fine to put it in one file and import it from the other.

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.

3 participants