mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Drop explicit sender attribute from messages (#1940)
* remove sender * removed priority post * timer fix * test fixes * drop async version of post_message * extended docs * fix no app * Added control properties * changelog * changelog * changelog * fix for stopping timers * changelog * added aliases to radio and checkbox * Drop sender from Message init * drop time * drop cast * Added aliases
This commit is contained in:
@@ -10,7 +10,6 @@ from textual.app import App
|
||||
from textual.coordinate import Coordinate
|
||||
from textual.events import Click, MouseMove
|
||||
from textual.message import Message
|
||||
from textual.message_pump import MessagePump
|
||||
from textual.widgets import DataTable
|
||||
from textual.widgets.data_table import (
|
||||
CellDoesNotExist,
|
||||
@@ -556,9 +555,8 @@ async def test_coordinate_to_cell_key_invalid_coordinate():
|
||||
table.coordinate_to_cell_key(Coordinate(9999, 9999))
|
||||
|
||||
|
||||
def make_click_event(sender: MessagePump):
|
||||
def make_click_event():
|
||||
return Click(
|
||||
sender=sender,
|
||||
x=1,
|
||||
y=2,
|
||||
delta_x=0,
|
||||
@@ -577,7 +575,7 @@ async def test_datatable_on_click_cell_cursor():
|
||||
app = DataTableApp()
|
||||
async with app.run_test() as pilot:
|
||||
table = app.query_one(DataTable)
|
||||
click = make_click_event(app)
|
||||
click = make_click_event()
|
||||
column_key = table.add_column("ABC")
|
||||
table.add_row("123")
|
||||
row_key = table.add_row("456")
|
||||
@@ -591,13 +589,11 @@ async def test_datatable_on_click_cell_cursor():
|
||||
"CellSelected",
|
||||
]
|
||||
cell_highlighted_event: DataTable.CellHighlighted = app.messages[1]
|
||||
assert cell_highlighted_event.sender is table
|
||||
assert cell_highlighted_event.value == "456"
|
||||
assert cell_highlighted_event.cell_key == CellKey(row_key, column_key)
|
||||
assert cell_highlighted_event.coordinate == Coordinate(1, 0)
|
||||
|
||||
cell_selected_event: DataTable.CellSelected = app.messages[2]
|
||||
assert cell_selected_event.sender is table
|
||||
assert cell_selected_event.value == "456"
|
||||
assert cell_selected_event.cell_key == CellKey(row_key, column_key)
|
||||
assert cell_selected_event.coordinate == Coordinate(1, 0)
|
||||
@@ -610,7 +606,7 @@ async def test_on_click_row_cursor():
|
||||
async with app.run_test():
|
||||
table = app.query_one(DataTable)
|
||||
table.cursor_type = "row"
|
||||
click = make_click_event(app)
|
||||
click = make_click_event()
|
||||
table.add_column("ABC")
|
||||
table.add_row("123")
|
||||
row_key = table.add_row("456")
|
||||
@@ -619,12 +615,11 @@ async def test_on_click_row_cursor():
|
||||
assert app.message_names == ["RowHighlighted", "RowHighlighted", "RowSelected"]
|
||||
|
||||
row_highlighted: DataTable.RowHighlighted = app.messages[1]
|
||||
assert row_highlighted.sender is table
|
||||
|
||||
assert row_highlighted.row_key == row_key
|
||||
assert row_highlighted.cursor_row == 1
|
||||
|
||||
row_selected: DataTable.RowSelected = app.messages[2]
|
||||
assert row_selected.sender is table
|
||||
assert row_selected.row_key == row_key
|
||||
assert row_highlighted.cursor_row == 1
|
||||
|
||||
@@ -639,7 +634,7 @@ async def test_on_click_column_cursor():
|
||||
column_key = table.add_column("ABC")
|
||||
table.add_row("123")
|
||||
table.add_row("456")
|
||||
click = make_click_event(app)
|
||||
click = make_click_event()
|
||||
table.on_click(event=click)
|
||||
await wait_for_idle(0)
|
||||
assert app.message_names == [
|
||||
@@ -648,12 +643,10 @@ async def test_on_click_column_cursor():
|
||||
"ColumnSelected",
|
||||
]
|
||||
column_highlighted: DataTable.ColumnHighlighted = app.messages[1]
|
||||
assert column_highlighted.sender is table
|
||||
assert column_highlighted.column_key == column_key
|
||||
assert column_highlighted.cursor_column == 0
|
||||
|
||||
column_selected: DataTable.ColumnSelected = app.messages[2]
|
||||
assert column_selected.sender is table
|
||||
assert column_selected.column_key == column_key
|
||||
assert column_highlighted.cursor_column == 0
|
||||
|
||||
@@ -669,7 +662,6 @@ async def test_hover_coordinate():
|
||||
assert table.hover_coordinate == Coordinate(0, 0)
|
||||
|
||||
mouse_move = MouseMove(
|
||||
sender=app,
|
||||
x=1,
|
||||
y=2,
|
||||
delta_x=0,
|
||||
@@ -694,7 +686,6 @@ async def test_header_selected():
|
||||
column_key = table.add_column("number")
|
||||
table.add_row(3)
|
||||
click_event = Click(
|
||||
sender=table,
|
||||
x=3,
|
||||
y=0,
|
||||
delta_x=0,
|
||||
@@ -708,7 +699,6 @@ async def test_header_selected():
|
||||
table.on_click(click_event)
|
||||
await pilot.pause()
|
||||
message: DataTable.HeaderSelected = app.messages[-1]
|
||||
assert message.sender is table
|
||||
assert message.label == Text("number")
|
||||
assert message.column_index == 0
|
||||
assert message.column_key == column_key
|
||||
@@ -729,7 +719,6 @@ async def test_row_label_selected():
|
||||
table.add_column("number")
|
||||
row_key = table.add_row(3, label="A")
|
||||
click_event = Click(
|
||||
sender=table,
|
||||
x=1,
|
||||
y=1,
|
||||
delta_x=0,
|
||||
@@ -743,7 +732,6 @@ async def test_row_label_selected():
|
||||
table.on_click(click_event)
|
||||
await pilot.pause()
|
||||
message: DataTable.RowLabelSelected = app.messages[-1]
|
||||
assert message.sender is table
|
||||
assert message.label == Text("A")
|
||||
assert message.row_index == 0
|
||||
assert message.row_key == row_key
|
||||
|
||||
@@ -19,7 +19,7 @@ class ValidWidget(Widget):
|
||||
|
||||
async def test_dispatch_key_valid_key():
|
||||
widget = ValidWidget()
|
||||
result = await widget.dispatch_key(Key(widget, key="x", character="x"))
|
||||
result = await widget.dispatch_key(Key(key="x", character="x"))
|
||||
assert result is True
|
||||
assert widget.called_by == widget.key_x
|
||||
|
||||
@@ -28,7 +28,7 @@ async def test_dispatch_key_valid_key_alias():
|
||||
"""When you press tab or ctrl+i, it comes through as a tab key event, but handlers for
|
||||
tab and ctrl+i are both considered valid."""
|
||||
widget = ValidWidget()
|
||||
result = await widget.dispatch_key(Key(widget, key="tab", character="\t"))
|
||||
result = await widget.dispatch_key(Key(key="tab", character="\t"))
|
||||
assert result is True
|
||||
assert widget.called_by == widget.key_ctrl_i
|
||||
|
||||
@@ -54,7 +54,7 @@ async def test_dispatch_key_raises_when_conflicting_handler_aliases():
|
||||
In the terminal, they're the same thing, so we fail fast via exception here."""
|
||||
widget = DuplicateHandlersWidget()
|
||||
with pytest.raises(DuplicateKeyHandlers):
|
||||
await widget.dispatch_key(Key(widget, key="tab", character="\t"))
|
||||
await widget.dispatch_key(Key(key="tab", character="\t"))
|
||||
assert widget.called_by == widget.key_tab
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ async def test_paste_app():
|
||||
|
||||
app = PasteApp()
|
||||
async with app.run_test() as pilot:
|
||||
await app.post_message(events.Paste(sender=app, text="Hello"))
|
||||
app.post_message(events.Paste(text="Hello"))
|
||||
await pilot.pause(0)
|
||||
|
||||
assert len(paste_events) == 1
|
||||
|
||||
@@ -34,7 +34,7 @@ def chunks(data, size):
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return XTermParser(sender=mock.sentinel, more_data=lambda: False)
|
||||
return XTermParser(more_data=lambda: False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("chunk_size", [2, 3, 4, 5, 6])
|
||||
@@ -65,7 +65,6 @@ def test_bracketed_paste(parser):
|
||||
assert len(events) == 1
|
||||
assert isinstance(events[0], Paste)
|
||||
assert events[0].text == pasted_text
|
||||
assert events[0].sender == mock.sentinel
|
||||
|
||||
|
||||
def test_bracketed_paste_content_contains_escape_codes(parser):
|
||||
@@ -302,7 +301,6 @@ def test_terminal_mode_reporting_synchronized_output_supported(parser):
|
||||
events = list(parser.feed(sequence))
|
||||
assert len(events) == 1
|
||||
assert isinstance(events[0], TerminalSupportsSynchronizedOutput)
|
||||
assert events[0].sender == mock.sentinel
|
||||
|
||||
|
||||
def test_terminal_mode_reporting_synchronized_output_not_supported(parser):
|
||||
|
||||
@@ -15,7 +15,7 @@ class CheckboxApp(App[None]):
|
||||
yield Checkbox(value=True, id="cb3")
|
||||
|
||||
def on_checkbox_changed(self, event: Checkbox.Changed) -> None:
|
||||
self.events_received.append((event.input.id, event.input.value))
|
||||
self.events_received.append((event.checkbox.id, event.checkbox.value))
|
||||
|
||||
|
||||
async def test_checkbox_initial_state() -> None:
|
||||
|
||||
@@ -15,7 +15,7 @@ class RadioButtonApp(App[None]):
|
||||
yield RadioButton(value=True, id="rb3")
|
||||
|
||||
def on_radio_button_changed(self, event: RadioButton.Changed) -> None:
|
||||
self.events_received.append((event.input.id, event.input.value))
|
||||
self.events_received.append((event.radio_button.id, event.radio_button.value))
|
||||
|
||||
|
||||
async def test_radio_button_initial_state() -> None:
|
||||
|
||||
@@ -19,9 +19,9 @@ class RadioSetApp(App[None]):
|
||||
def on_radio_set_changed(self, event: RadioSet.Changed) -> None:
|
||||
self.events_received.append(
|
||||
(
|
||||
event.input.id,
|
||||
event.radio_set.id,
|
||||
event.index,
|
||||
[button.value for button in event.input.query(RadioButton)],
|
||||
[button.value for button in event.radio_set.query(RadioButton)],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user