Merge branch 'main' into add-containers

This commit is contained in:
Rodrigo Girão Serrão
2023-03-14 14:35:23 +00:00
11 changed files with 169 additions and 168 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,19 +1,6 @@
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll, Horizontal
from textual.widgets import (
Header,
Footer,
Button,
DataTable,
Input,
ListView,
ListItem,
Label,
Markdown,
MarkdownViewer,
Tree,
TextLog,
)
from textual.containers import Horizontal
from textual.widgets import Button
class WidgetDisableTestApp(App[None]):
@@ -21,62 +8,26 @@ class WidgetDisableTestApp(App[None]):
Horizontal {
height: auto;
}
DataTable, ListView, Tree, TextLog {
height: 2;
}
Markdown, MarkdownViewer {
height: 1fr;
Button {
width: 1fr;
}
"""
@property
def data_table(self) -> DataTable:
data_table = DataTable[str]()
data_table.add_columns("Column 1", "Column 2", "Column 3", "Column 4")
data_table.add_rows(
[(str(n), str(n * 10), str(n * 100), str(n * 1000)) for n in range(100)]
)
return data_table
@property
def list_view(self) -> ListView:
return ListView(*[ListItem(Label(f"This is list item {n}")) for n in range(20)])
@property
def test_tree(self) -> Tree:
tree = Tree[None](label="This is a test tree")
for n in range(10):
tree.root.add_leaf(f"Leaf {n}")
tree.root.expand()
return tree
def compose(self) -> ComposeResult:
yield Header()
yield VerticalScroll(
Horizontal(
Button(),
Button(variant="primary"),
Button(variant="success"),
Button(variant="warning"),
Button(variant="error"),
),
self.data_table,
self.list_view,
self.test_tree,
TextLog(),
Input(),
Input(placeholder="This is an empty input with a placeholder"),
Input("This is some text in an input"),
Markdown("# Hello, World!"),
MarkdownViewer("# Hello, World!"),
id="test-container",
)
yield Footer()
def on_mount(self) -> None:
self.query_one(TextLog).write("Hello, World!")
self.query_one("#test-container", VerticalScroll).disabled = True
for _ in range(4):
with Horizontal():
yield Button()
yield Button(variant="primary")
yield Button(variant="success")
yield Button(variant="warning")
yield Button(variant="error")
with Horizontal(disabled=True):
yield Button()
yield Button(variant="primary")
yield Button(variant="success")
yield Button(variant="warning")
yield Button(variant="error")
if __name__ == "__main__":

View File

@@ -0,0 +1,45 @@
from textual.app import App, ComposeResult
from textual.message import Message
from textual.widget import Widget
async def test_message_inheritance_namespace():
"""Inherited messages get their correct namespaces.
Regression test for https://github.com/Textualize/textual/issues/1814.
"""
class BaseWidget(Widget):
class Fired(Message):
pass
def trigger(self) -> None:
self.post_message(self.Fired())
class Left(BaseWidget):
class Fired(BaseWidget.Fired):
pass
class Right(BaseWidget):
class Fired(BaseWidget.Fired):
pass
handlers_called = []
class MessageInheritanceApp(App[None]):
def compose(self) -> ComposeResult:
yield Left()
yield Right()
def on_left_fired(self):
handlers_called.append("left")
def on_right_fired(self):
handlers_called.append("right")
app = MessageInheritanceApp()
async with app.run_test():
app.query_one(Left).trigger()
app.query_one(Right).trigger()
assert handlers_called == ["left", "right"]