Module textual.scroll_view
Expand source code
from __future__ import annotations
from rich.console import RenderableType
from .geometry import Size
from .widget import Widget
class ScrollView(Widget):
"""
A base class for a Widget that handles it's own scrolling (i.e. doesn't rely
on the compositor to render children).
"""
DEFAULT_CSS = """
ScrollView {
overflow-y: auto;
overflow-x: auto;
}
"""
@property
def is_scrollable(self) -> bool:
"""Always scrollable."""
return True
@property
def is_transparent(self) -> bool:
"""Not transparent, i.e. renders something."""
return False
def on_mount(self):
self._refresh_scrollbars()
def get_content_width(self, container: Size, viewport: Size) -> int:
"""Gets the width of the content area.
Args:
container (Size): Size of the container (immediate parent) widget.
viewport (Size): Size of the viewport.
Returns:
int: The optimal width of the content.
"""
return self.virtual_size.width
def get_content_height(self, container: Size, viewport: Size, width: int) -> int:
"""Gets the height (number of lines) in the content area.
Args:
container (Size): Size of the container (immediate parent) widget.
viewport (Size): Size of the viewport.
width (int): Width of renderable.
Returns:
int: The height of the content.
"""
return self.virtual_size.height
def _size_updated(
self, size: Size, virtual_size: Size, container_size: Size
) -> None:
"""Called when size is updated.
Args:
size (Size): New size.
virtual_size (Size): New virtual size.
container_size (Size): New container size.
"""
if (
self._size != size
or virtual_size != self.virtual_size
or container_size != self.container_size
):
self._size = size
virtual_size = self.virtual_size
self._scroll_update(virtual_size)
self._container_size = size - self.styles.gutter.totals
self.scroll_to(self.scroll_x, self.scroll_y, animate=False)
self.refresh()
def render(self) -> RenderableType:
"""Render the scrollable region (if `render_lines` is not implemented).
Returns:
RenderableType: Renderable object.
"""
from rich.panel import Panel
return Panel(f"{self.scroll_offset} {self.show_vertical_scrollbar}")
Classes
class ScrollView (*children: Widget, name: str | None = None, id: str | None = None, classes: str | None = None)-
A base class for a Widget that handles it's own scrolling (i.e. doesn't rely on the compositor to render children).
Expand source code
class ScrollView(Widget): """ A base class for a Widget that handles it's own scrolling (i.e. doesn't rely on the compositor to render children). """ DEFAULT_CSS = """ ScrollView { overflow-y: auto; overflow-x: auto; } """ @property def is_scrollable(self) -> bool: """Always scrollable.""" return True @property def is_transparent(self) -> bool: """Not transparent, i.e. renders something.""" return False def on_mount(self): self._refresh_scrollbars() def get_content_width(self, container: Size, viewport: Size) -> int: """Gets the width of the content area. Args: container (Size): Size of the container (immediate parent) widget. viewport (Size): Size of the viewport. Returns: int: The optimal width of the content. """ return self.virtual_size.width def get_content_height(self, container: Size, viewport: Size, width: int) -> int: """Gets the height (number of lines) in the content area. Args: container (Size): Size of the container (immediate parent) widget. viewport (Size): Size of the viewport. width (int): Width of renderable. Returns: int: The height of the content. """ return self.virtual_size.height def _size_updated( self, size: Size, virtual_size: Size, container_size: Size ) -> None: """Called when size is updated. Args: size (Size): New size. virtual_size (Size): New virtual size. container_size (Size): New container size. """ if ( self._size != size or virtual_size != self.virtual_size or container_size != self.container_size ): self._size = size virtual_size = self.virtual_size self._scroll_update(virtual_size) self._container_size = size - self.styles.gutter.totals self.scroll_to(self.scroll_x, self.scroll_y, animate=False) self.refresh() def render(self) -> RenderableType: """Render the scrollable region (if `render_lines` is not implemented). Returns: RenderableType: Renderable object. """ from rich.panel import Panel return Panel(f"{self.scroll_offset} {self.show_vertical_scrollbar}")Ancestors
Subclasses
- textual.widgets._data_table.DataTable
- textual.widgets._text_log.TextLog
Class variables
var COMPONENT_CLASSES : ClassVar[set[str]]var DEFAULT_CSS
Instance variables
var is_scrollable : bool-
Always scrollable.
Expand source code
@property def is_scrollable(self) -> bool: """Always scrollable.""" return True var is_transparent : bool-
Not transparent, i.e. renders something.
Expand source code
@property def is_transparent(self) -> bool: """Not transparent, i.e. renders something.""" return False
Methods
def get_content_height(self, container: Size, viewport: Size, width: int) ‑> int-
Gets the height (number of lines) in the content area.
Args
container:Size- Size of the container (immediate parent) widget.
viewport:Size- Size of the viewport.
width:int- Width of renderable.
Returns
int- The height of the content.
Expand source code
def get_content_height(self, container: Size, viewport: Size, width: int) -> int: """Gets the height (number of lines) in the content area. Args: container (Size): Size of the container (immediate parent) widget. viewport (Size): Size of the viewport. width (int): Width of renderable. Returns: int: The height of the content. """ return self.virtual_size.height def get_content_width(self, container: Size, viewport: Size) ‑> int-
Gets the width of the content area.
Args
container:Size- Size of the container (immediate parent) widget.
viewport:Size- Size of the viewport.
Returns
int- The optimal width of the content.
Expand source code
def get_content_width(self, container: Size, viewport: Size) -> int: """Gets the width of the content area. Args: container (Size): Size of the container (immediate parent) widget. viewport (Size): Size of the viewport. Returns: int: The optimal width of the content. """ return self.virtual_size.width def on_mount(self)-
Expand source code
def on_mount(self): self._refresh_scrollbars() def render(self) ‑> Union[rich.console.ConsoleRenderable, rich.console.RichCast, str]-
Render the scrollable region (if
render_linesis not implemented).Returns
RenderableType- Renderable object.
Expand source code
def render(self) -> RenderableType: """Render the scrollable region (if `render_lines` is not implemented). Returns: RenderableType: Renderable object. """ from rich.panel import Panel return Panel(f"{self.scroll_offset} {self.show_vertical_scrollbar}")
Inherited members
Widget:actionadd_classallow_horizontal_scrollallow_vertical_scrollancestorsanimateappauto_heightauto_linksauto_widthbackground_colorscall_latercan_focuscan_focus_childrencapture_mousecheck_idleclassescolorscomposecontainer_sizecontainer_viewportcontent_offsetcontent_regioncontent_sizecss_identifiercss_identifier_styledcss_path_nodesdisable_messagesdispatch_keydisplaydisplayed_childrenemitemit_no_waitenable_messagesexpandfocusfocusable_childrenget_childget_component_rich_styleget_component_stylesget_default_cssget_pseudo_classesget_style_atgutterhas_classhas_focushas_pseudo_classhighlight_link_idhorizontal_scrollbarhover_styleidis_containerlayerlayerslink_hover_stylelink_stylelogmax_scroll_xmax_scroll_ymountmouse_overoffseton_eventouter_sizeparentpost_messagepost_message_no_waitpost_renderpseudo_classesqueryquery_onerefreshregionrelease_mouseremoveremove_classrender_linerender_linesreset_focusreset_stylesrich_stylescreenscroll_downscroll_endscroll_homescroll_leftscroll_offsetscroll_page_downscroll_page_leftscroll_page_rightscroll_page_upscroll_relativescroll_rightscroll_target_xscroll_target_yscroll_toscroll_to_regionscroll_to_widgetscroll_upscroll_visiblescroll_xscroll_yscrollbar_cornerscrollbar_gutterscrollbar_size_horizontalscrollbar_size_verticalscrollbars_enabledset_classset_intervalset_stylesset_timershow_horizontal_scrollbarshow_vertical_scrollbarshrinksiblingssizetext_styletoggle_classtreevertical_scrollbarvirtual_regionvirtual_region_with_marginvirtual_sizevisiblevisible_siblingswalk_childrenwatch_has_focuswatch_mouse_overwindow_region