Skip to content

robabram/textual-thin-slider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tests Completion Status Coverage Status Supported Python Versions is support

Textual Thin Slider

A thin slider widget for the Textual UI platform. The thin slider widget is only 1 character tall and allows fine control to choose a value within a range. Options include, no value display, percentage or value. Value may displayed on left or right of slider bar.

Slider w/Percent

Installation

pip install thin-textual-slider
uv add thin-textual-slider

Usage

Display Option Enum and Widget Control Arguments

class ThinSliderDisplayOptions(IntEnum):
    """ How should we show values with the slider bar, use bitwise and/or to set/read values. """
    none = 0  # Do not display the percentage or value (default)
    display_left = 1  # Display percentage/value to the left of the slider bar
    display_right = 2  # Display percentage/value to the right of the slider bar 
    show_value = 4  # Show current slider value instead of percentage

class ThinSlider(
    range_min: int,
    range_max: int,
    value: int,
    step: int,
    display_type: ThinSliderDisplayOptions
)

# Programmatically change slider value
slider.value = {new integer value}

Example: Textual App Usage With Event Message

from textual import on
from textual.app import ComposeResult, App
from textual_thin_slider import ThinSlider, ThinSliderDisplayOptions

class SimpleSliderApp(App):
    slider_value: int = 0
    slider_percentage: float = 0.0

    def compose(self) -> ComposeResult:
        yield ThinSlider(
            id="test-slider",
            range_min=0,
            range_max=250,
            display_type=ThinSliderDisplayOptions.display_right | ThinSliderDisplayOptions.show_value
        )

    @on(ThinSlider.Changed, "#test-slider")
    def on_thin_slider_changed(self, event: ThinSlider.Changed) -> None:
        self.slider_value = event.value
        self.slider_percentage = event.control.percent

if __name__ == "__main__":
    app = SimpleSliderApp()
    app.run()

About

A thin slider widgit for Textual

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages