mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Added focusable_children property
This commit is contained in:
@@ -215,7 +215,7 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
widgets: list[Widget] = []
|
widgets: list[Widget] = []
|
||||||
add_widget = widgets.append
|
add_widget = widgets.append
|
||||||
root = self.screen
|
root = self.screen
|
||||||
stack: list[Iterator[Widget]] = [iter(root.displayed_children)]
|
stack: list[Iterator[Widget]] = [iter(root.focusable_children)]
|
||||||
pop = stack.pop
|
pop = stack.pop
|
||||||
push = stack.append
|
push = stack.append
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
pop()
|
pop()
|
||||||
else:
|
else:
|
||||||
if node.is_container and node.can_focus:
|
if node.is_container and node.can_focus:
|
||||||
push(iter(node.displayed_children))
|
push(iter(node.focusable_children))
|
||||||
else:
|
else:
|
||||||
if node.can_focus:
|
if node.can_focus:
|
||||||
add_widget(node)
|
add_widget(node)
|
||||||
|
|||||||
@@ -313,8 +313,15 @@ class DOMNode(MessagePump):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def displayed_children(self) -> list[DOMNode]:
|
def displayed_children(self) -> list[DOMNode]:
|
||||||
|
"""The children which don't have display: none set."""
|
||||||
return [child for child in self.children if child.display]
|
return [child for child in self.children if child.display]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def focusable_children(self) -> list[DOMNode]:
|
||||||
|
"""Get the children which may be focused."""
|
||||||
|
# TODO: This may be the place to define order, other focus related rules
|
||||||
|
return [child for child in self.children if child.display and child.visible]
|
||||||
|
|
||||||
def get_pseudo_classes(self) -> Iterable[str]:
|
def get_pseudo_classes(self) -> Iterable[str]:
|
||||||
"""Get any pseudo classes applicable to this Node, e.g. hover, focus.
|
"""Get any pseudo classes applicable to this Node, e.g. hover, focus.
|
||||||
|
|
||||||
|
|||||||
17
tests/renderables/test_tint.py
Normal file
17
tests/renderables/test_tint.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import io
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.text import Text
|
||||||
|
|
||||||
|
from textual.color import Color
|
||||||
|
from textual.renderables.tint import Tint
|
||||||
|
|
||||||
|
|
||||||
|
def test_tint():
|
||||||
|
console = Console(file=io.StringIO(), force_terminal=True, color_system="truecolor")
|
||||||
|
renderable = Text.from_markup("[#aabbcc on #112233]foo")
|
||||||
|
console.print(Tint(renderable, Color(0, 100, 0, 0.5)))
|
||||||
|
output = console.file.getvalue()
|
||||||
|
print(repr(output))
|
||||||
|
expected = "\x1b[38;2;85;143;102;48;2;8;67;25mfoo\x1b[0m\n"
|
||||||
|
assert output == expected
|
||||||
Reference in New Issue
Block a user