prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Determine if container or window is focusable

Open
#1,270 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

I want to find out if a container contains any focusable objects. I couldn't find a property or function that provides that information.

The following code I copied from Layout.focus() works for me:

from prompt_toolkit.layout.layout import walk
from prompt_toolkit.layout.containers import Window, to_container

def is_focusable(container):
    for c in walk(to_container(container), skip_hidden=True):
        if isinstance(c, Window) and c.content.is_focusable():
            return True
    return False

Would this be a good addition for the Container class?

@property
def is_focusable(self):
    for c in walk(self, skip_hidden=True):
        if isinstance(c, Window) and c.content.is_focusable():
            return True
    return False

I can live with my solution, but I think this should be provided out of the box.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Layout.focus() and the existing walk(), Window, and to_container() references in prompt_toolkit.layout.layout and prompt_toolkit.layout.containers. Determine whether the proposed Container-level property fits the existing API, then verify that it reports whether any visible Window content is focusable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.