-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #954 from davep/bug/939/loss-of-focus-take-2
Try and better settle focus after a focused widget is removed (redux)
- Loading branch information
Showing
5 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
poetry run textual run --dev focus_removal_tester.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Focus removal tester. | ||
https://github.com/Textualize/textual/issues/939 | ||
""" | ||
|
||
from textual.app import App | ||
from textual.containers import Container | ||
from textual.widgets import Static, Header, Footer, Button | ||
|
||
|
||
class LeftButton(Button): | ||
pass | ||
|
||
|
||
class RightButton(Button): | ||
pass | ||
|
||
|
||
class NonFocusParent(Static): | ||
def compose(self): | ||
yield LeftButton("Do Not Press") | ||
yield Static("Test") | ||
yield RightButton("Really Do Not Press") | ||
|
||
|
||
class FocusRemovalTester(App[None]): | ||
|
||
BINDINGS = [("a", "add_widget", "Add Widget"), ("d", "del_widget", "Delete Widget")] | ||
|
||
def compose(self): | ||
yield Header() | ||
yield Container() | ||
yield Footer() | ||
|
||
def action_add_widget(self): | ||
self.query_one(Container).mount(NonFocusParent()) | ||
|
||
def action_del_widget(self): | ||
candidates = self.query(NonFocusParent) | ||
if candidates: | ||
candidates.last().remove() | ||
|
||
|
||
if __name__ == "__main__": | ||
FocusRemovalTester().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters