prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Determine if container or window is focusable
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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