mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
capture mouse issue
This commit is contained in:
@@ -680,7 +680,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
finally:
|
||||
self.mouse_over = widget
|
||||
|
||||
async def capture_mouse(self, widget: Widget | None) -> None:
|
||||
def capture_mouse(self, widget: Widget | None) -> None:
|
||||
"""Send all mouse events to the given widget, disable mouse capture.
|
||||
|
||||
Args:
|
||||
@@ -689,12 +689,12 @@ class App(Generic[ReturnType], DOMNode):
|
||||
if widget == self.mouse_captured:
|
||||
return
|
||||
if self.mouse_captured is not None:
|
||||
await self.mouse_captured.post_message(
|
||||
self.mouse_captured.post_message_no_wait(
|
||||
events.MouseRelease(self, self.mouse_position)
|
||||
)
|
||||
self.mouse_captured = widget
|
||||
if widget is not None:
|
||||
await widget.post_message(events.MouseCapture(self, self.mouse_position))
|
||||
widget.post_message_no_wait(events.MouseCapture(self, self.mouse_position))
|
||||
|
||||
def panic(self, *renderables: RenderableType) -> None:
|
||||
"""Exits the app then displays a message.
|
||||
|
||||
@@ -231,10 +231,14 @@ class ScrollBar(Widget):
|
||||
style=scrollbar_style,
|
||||
)
|
||||
|
||||
async def on_enter(self, event: events.Enter) -> None:
|
||||
def on_hide(self, event: events.Hide) -> None:
|
||||
if self.grabbed:
|
||||
self.release_mouse()
|
||||
|
||||
def on_enter(self, event: events.Enter) -> None:
|
||||
self.mouse_over = True
|
||||
|
||||
async def on_leave(self, event: events.Leave) -> None:
|
||||
def on_leave(self, event: events.Leave) -> None:
|
||||
self.mouse_over = False
|
||||
|
||||
async def action_scroll_down(self) -> None:
|
||||
@@ -243,15 +247,15 @@ class ScrollBar(Widget):
|
||||
async def action_scroll_up(self) -> None:
|
||||
await self.emit(ScrollUp(self) if self.vertical else ScrollLeft(self))
|
||||
|
||||
async def action_grab(self) -> None:
|
||||
await self.capture_mouse()
|
||||
def action_grab(self) -> None:
|
||||
self.capture_mouse()
|
||||
|
||||
async def action_released(self) -> None:
|
||||
await self.capture_mouse(False)
|
||||
def action_released(self) -> None:
|
||||
self.capture_mouse(False)
|
||||
|
||||
async def on_mouse_up(self, event: events.MouseUp) -> None:
|
||||
def on_mouse_up(self, event: events.MouseUp) -> None:
|
||||
if self.grabbed:
|
||||
await self.release_mouse()
|
||||
self.release_mouse()
|
||||
|
||||
async def on_mouse_capture(self, event: events.MouseCapture) -> None:
|
||||
self.grabbed = event.mouse_position
|
||||
|
||||
@@ -1090,7 +1090,7 @@ class Widget(DOMNode):
|
||||
"""Give input focus to this widget."""
|
||||
self.app.set_focus(self)
|
||||
|
||||
async def capture_mouse(self, capture: bool = True) -> None:
|
||||
def capture_mouse(self, capture: bool = True) -> None:
|
||||
"""Capture (or release) the mouse.
|
||||
|
||||
When captured, all mouse coordinates will go to this widget even when the pointer is not directly over the widget.
|
||||
@@ -1098,14 +1098,14 @@ class Widget(DOMNode):
|
||||
Args:
|
||||
capture (bool, optional): True to capture or False to release. Defaults to True.
|
||||
"""
|
||||
await self.app.capture_mouse(self if capture else None)
|
||||
self.app.capture_mouse(self if capture else None)
|
||||
|
||||
async def release_mouse(self) -> None:
|
||||
def release_mouse(self) -> None:
|
||||
"""Release the mouse.
|
||||
|
||||
Mouse events will only be sent when the mouse is over the widget.
|
||||
"""
|
||||
await self.app.capture_mouse(None)
|
||||
self.app.capture_mouse(None)
|
||||
|
||||
async def broker_event(self, event_name: str, event: events.Event) -> bool:
|
||||
return await self.app.broker_event(event_name, event, default_namespace=self)
|
||||
|
||||
Reference in New Issue
Block a user