`Enter` and `Leave` can reach a parent in either order when the mouse moves between its children
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Start with App._set_mouse_over to see where the Leave and Enter events are posted for the old and new widgets, then trace how each bubbles through message pumps to the shared parent. The repro script shows the ordering problem with a delayed on_leave; the calculator example is the case where it shows up in traces. Done means Leave reaches every shared ancestor before Enter, while event.stop() still works for ListItem.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi! When the mouse moves from one widget to a sibling, the parent sometimes gets the new widget's Enter before the old widget's Leave.
App._set_mouse_over posts Leave to the old widget and Enter to the new one at the same time. Both events bubble, and each climbs from its own widget's message pump, so which of the two reaches a shared ancestor first depends on which pump gets there first. If the old widget is still busy, for example because its own on_leave awaits something, the Enter wins.
import asyncio
import collections
import sys
import textual
from textual import events
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Static
class Cell(Static):
"""A widget whose own Leave handler takes `delay` seconds (0: a plain handler)."""
def __init__(self, label: str, delay: float) -> None:
super().__init__(label, id=label)
self.delay = delay
async def on_leave(self, event: events.Leave) -> None:
if self.delay:
await asyncio.sleep(self.delay)
class Row(Horizontal):
"""Records the Enter and Leave events that bubble up to it, in the order it gets them."""
seen: list[str] = []
def on_enter(self, event: events.Enter) -> None:
Row.seen.append(f"Enter({event.node.id})")
def on_leave(self, event: events.Leave) -> None:
Row.seen.append(f"Leave({event.node.id})")
class EnterLeaveApp(App):
CSS = "Cell { width: 10; height: 3; }"
def __init__(self, delay: float) -> None:
super().__init__()
self.delay = delay
def compose(self) -> ComposeResult:
with Row():
yield Cell("a", self.delay)
yield Cell("b", 0)
async def once(delay: float) -> str:
app = EnterLeaveApp(delay)
async with app.run_test() as pilot:
await pilot.hover("#a")
await pilot.pause(0.1)
Row.seen = []
await pilot.hover("#b")
await pilot.pause(0.1)
return " ".join(Row.seen)
async def main() -> None:
runs = int(sys.argv[1]) if len(sys.argv) > 1 else 20
print(f"Textual {textual.__version__}, {runs} runs each")
for delay in (0, 0.01):
tally = collections.Counter()
for _ in range(runs):
tally[await once(delay)] += 1
print(f"a's on_leave takes {delay} s; what Row gets moving from a to b -> runs: {dict(tally)}")
asyncio.run(main())
Output on main (5e5b7ef), Python 3.13, macOS (8.2.7 is the same):
Textual 8.2.8, 30 runs each
a's on_leave takes 0 s; what Row gets moving from a to b -> runs: {'Leave(a) Enter(b)': 30}
a's on_leave takes 0.01 s; what Row gets moving from a to b -> runs: {'Enter(b) Leave(a)': 30}
With plain handlers the order is usually right, but it still depends on scheduling: in a test harness that compares message traces run against run, the calculator example's clicks from one button to the next got the screen's Enter and Leave in the other order about one run in ten, and scrolling content under a still pointer does the same. I expected Leave(a) before Enter(b) at every shared ancestor, every time. I have a fix that keeps both events bubbling (so event.stop() still works, which ListItem relies on) and posts the Enter once the Leave has bubbled as far as it goes. I'm happy to open a PR if that approach sounds right.
- Lenguaje dominante
- Python
- Estrellas
- 37.7k
- Forks
- 1.5k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Textualize/textual
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6790 · 2 comentarios ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Textualize/textual#6789 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6787 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6782 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Textualize/textual#6778 · 1 comentario ·
Todos los issues de Textualize/textual
Issues similares
-
Internal ErrorAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
frappe/frappe_docker#2071 ·
Los mantenedores suelen responder en 1 día
-
bug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Abiertocomp/desktop P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NousResearch/hermes-agent#157702 ·
Los mantenedores suelen responder en 1 día
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPosiblemente ocupada @BahaaMattar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Los mantenedores suelen responder en 1 día