mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
optional actions
This commit is contained in:
@@ -29,7 +29,7 @@ Sidebar {
|
||||
}
|
||||
|
||||
Sidebar:focus-within {
|
||||
offset: 0 0 !important;
|
||||
offset: 0 0 !important;
|
||||
}
|
||||
|
||||
Sidebar.-hidden {
|
||||
|
||||
@@ -295,7 +295,6 @@ class Screen(Widget):
|
||||
# No focus, so blur currently focused widget if it exists
|
||||
if self.focused is not None:
|
||||
self.focused.post_message_no_wait(events.Blur(self))
|
||||
self.focused.emit_no_wait(events.DescendantBlur(self))
|
||||
self.focused = None
|
||||
self.log.debug("focus was removed")
|
||||
elif widget.can_focus:
|
||||
@@ -303,14 +302,12 @@ class Screen(Widget):
|
||||
if self.focused is not None:
|
||||
# Blur currently focused widget
|
||||
self.focused.post_message_no_wait(events.Blur(self))
|
||||
self.focused.emit_no_wait(events.DescendantBlur(self))
|
||||
# Change focus
|
||||
self.focused = widget
|
||||
# Send focus event
|
||||
if scroll_visible:
|
||||
self.screen.scroll_to_widget(widget)
|
||||
widget.post_message_no_wait(events.Focus(self))
|
||||
widget.emit_no_wait(events.DescendantFocus(self))
|
||||
self.log.debug(widget, "was focused")
|
||||
|
||||
async def _on_idle(self, event: events.Idle) -> None:
|
||||
|
||||
@@ -2344,17 +2344,22 @@ class Widget(DOMNode):
|
||||
self.mouse_over = True
|
||||
|
||||
def _on_focus(self, event: events.Focus) -> None:
|
||||
for node in self.ancestors_with_self:
|
||||
if node._has_focus_within:
|
||||
self.app.update_styles(node)
|
||||
self.has_focus = True
|
||||
self.refresh()
|
||||
self.emit_no_wait(events.DescendantFocus(self))
|
||||
|
||||
def _on_blur(self, event: events.Blur) -> None:
|
||||
if any(node._has_focus_within for node in self.ancestors_with_self):
|
||||
self.app.update_styles(self)
|
||||
self.has_focus = False
|
||||
self.refresh()
|
||||
self.emit_no_wait(events.DescendantBlur(self))
|
||||
|
||||
def _on_descendant_blur(self, event: events.DescendantBlur) -> None:
|
||||
if self._has_focus_within:
|
||||
self.app.update_styles(self)
|
||||
|
||||
def _on_descendant_focus(self, event: events.DescendantBlur) -> None:
|
||||
if self._has_focus_within:
|
||||
self.app.update_styles(self)
|
||||
|
||||
def _on_mouse_scroll_down(self, event) -> None:
|
||||
if self.allow_vertical_scroll:
|
||||
@@ -2398,34 +2403,42 @@ class Widget(DOMNode):
|
||||
def _on_scroll_to_region(self, message: messages.ScrollToRegion) -> None:
|
||||
self.scroll_to_region(message.region, animate=True)
|
||||
|
||||
def action_scroll_home(self) -> None:
|
||||
if self._allow_scroll:
|
||||
self.scroll_home()
|
||||
def action_scroll_home(self) -> bool | None:
|
||||
if not self._allow_scroll:
|
||||
return False
|
||||
self.scroll_home()
|
||||
|
||||
def action_scroll_end(self) -> None:
|
||||
if self._allow_scroll:
|
||||
self.scroll_end()
|
||||
def action_scroll_end(self) -> bool | None:
|
||||
if not self._allow_scroll:
|
||||
return False
|
||||
self.scroll_end()
|
||||
|
||||
def action_scroll_left(self) -> None:
|
||||
if self.allow_horizontal_scroll:
|
||||
self.scroll_left()
|
||||
def action_scroll_left(self) -> bool | None:
|
||||
if not self.allow_horizontal_scroll:
|
||||
return False
|
||||
self.scroll_left()
|
||||
|
||||
def action_scroll_right(self) -> None:
|
||||
if self.allow_horizontal_scroll:
|
||||
self.scroll_right()
|
||||
def action_scroll_right(self) -> bool | None:
|
||||
if not self.allow_horizontal_scroll:
|
||||
return False
|
||||
self.scroll_right()
|
||||
|
||||
def action_scroll_up(self) -> None:
|
||||
if self.allow_vertical_scroll:
|
||||
self.scroll_up()
|
||||
def action_scroll_up(self) -> bool | None:
|
||||
if not self.allow_vertical_scroll:
|
||||
return False
|
||||
self.scroll_up()
|
||||
|
||||
def action_scroll_down(self) -> None:
|
||||
if self.allow_vertical_scroll:
|
||||
self.scroll_down()
|
||||
def action_scroll_down(self) -> bool | None:
|
||||
if not self.allow_vertical_scroll:
|
||||
return False
|
||||
self.scroll_down()
|
||||
|
||||
def action_page_down(self) -> None:
|
||||
if self.allow_vertical_scroll:
|
||||
self.scroll_page_down()
|
||||
def action_page_down(self) -> bool | None:
|
||||
if not self.allow_vertical_scroll:
|
||||
return False
|
||||
self.scroll_page_down()
|
||||
|
||||
def action_page_up(self) -> None:
|
||||
if self.allow_vertical_scroll:
|
||||
self.scroll_page_up()
|
||||
def action_page_up(self) -> bool | None:
|
||||
if not self.allow_vertical_scroll:
|
||||
return False
|
||||
self.scroll_page_up()
|
||||
|
||||
Reference in New Issue
Block a user