mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add sandbox code for testing work on #939
This commit is contained in:
2
sandbox/davep/Makefile
Normal file
2
sandbox/davep/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
all:
|
||||
poetry run textual run --dev focus_removal_tester.py
|
||||
37
sandbox/davep/focus_removal_tester.py
Normal file
37
sandbox/davep/focus_removal_tester.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""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 NonFocusParent(Static):
|
||||
def compose(self):
|
||||
yield Button("Do Not Press")
|
||||
yield Static("Test")
|
||||
yield Button("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()
|
||||
Reference in New Issue
Block a user