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_lines
is 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
:action
add_class
allow_horizontal_scroll
allow_vertical_scroll
ancestors
animate
app
auto_height
auto_links
auto_width
background_colors
call_later
can_focus
can_focus_children
capture_mouse
check_idle
classes
colors
compose
container_size
container_viewport
content_offset
content_region
content_size
css_identifier
css_identifier_styled
css_path_nodes
disable_messages
dispatch_key
display
displayed_children
emit
emit_no_wait
enable_messages
expand
focus
focusable_children
get_child
get_component_rich_style
get_component_styles
get_default_css
get_pseudo_classes
get_style_at
gutter
has_class
has_focus
has_pseudo_class
highlight_link_id
horizontal_scrollbar
hover_style
id
is_container
layer
layers
link_hover_style
link_style
log
max_scroll_x
max_scroll_y
mount
mouse_over
offset
on_event
outer_size
parent
post_message
post_message_no_wait
post_render
pseudo_classes
query
query_one
refresh
region
release_mouse
remove
remove_class
render_line
render_lines
reset_focus
reset_styles
rich_style
screen
scroll_down
scroll_end
scroll_home
scroll_left
scroll_offset
scroll_page_down
scroll_page_left
scroll_page_right
scroll_page_up
scroll_relative
scroll_right
scroll_target_x
scroll_target_y
scroll_to
scroll_to_region
scroll_to_widget
scroll_up
scroll_visible
scroll_x
scroll_y
scrollbar_corner
scrollbar_gutter
scrollbar_size_horizontal
scrollbar_size_vertical
scrollbars_enabled
set_class
set_interval
set_styles
set_timer
show_horizontal_scrollbar
show_vertical_scrollbar
shrink
siblings
size
text_style
toggle_class
tree
vertical_scrollbar
virtual_region
virtual_region_with_margin
virtual_size
visible
visible_siblings
walk_children
watch_has_focus
watch_mouse_over
window_region