build_tools.tui_common.controls.sliders ======================================= .. py:module:: build_tools.tui_common.controls.sliders .. autoapi-nested-parse:: Float slider control widget. This module provides the FloatSlider widget for float parameter control with keyboard and mouse support. **Features:** - Keyboard navigation: ``+``/``-`` or ``j``/``k`` or arrow keys to adjust - Configurable step size and decimal precision - Optional suffix text display - Posts ``Changed`` message when value updates - Focusable with visual feedback **Example Usage:** .. code-block:: python from build_tools.tui_common.controls import FloatSlider from textual import on class MyApp(App): def compose(self) -> ComposeResult: yield FloatSlider( label="Temperature", value=0.5, min_val=0.0, max_val=1.0, step=0.1, precision=2, suffix="bias", id="temperature-slider", ) @on(FloatSlider.Changed) def on_slider_changed(self, event: FloatSlider.Changed) -> None: print(f"Slider {event.widget_id} = {event.value}") Classes ------- .. autoapisummary:: build_tools.tui_common.controls.sliders.FloatSlider Module Contents --------------- .. py:class:: FloatSlider(label, value, min_val, max_val, step = 0.1, precision = 1, suffix = None, *args, **kwargs) Bases: :py:obj:`textual.widgets.Static` Float slider widget with keyboard and mouse support. A horizontal widget displaying a label, current value in brackets, and optional suffix. Users can adjust the value using keyboard shortcuts while the widget has focus. .. attribute:: label_text Display label shown before the value .. attribute:: value Current float value (clamped to min/max range) .. attribute:: min_val Minimum allowed value .. attribute:: max_val Maximum allowed value .. attribute:: step Amount to increment/decrement per keypress .. attribute:: precision Number of decimal places to display .. attribute:: suffix Optional text shown after the value Keybindings: - ``+`` or ``=`` or ``j`` or ``down``: Increment value by step - ``-`` or ``_`` or ``k`` or ``up``: Decrement value by step Messages: - :class:`Changed`: Posted when value changes, includes new value and widget ID CSS Classes: - ``.slider-label``: Label element (width: 15, right-aligned) - ``.slider-value``: Value display (width: 8, centered, highlighted on focus) - ``.slider-suffix``: Suffix text (auto width, muted color) Initialize float slider. :param label: Display label shown before the value :param value: Initial value (will be clamped to min/max range) :param min_val: Minimum allowed value :param max_val: Maximum allowed value :param step: Increment/decrement step size (default: 0.1) :param precision: Number of decimal places to display (default: 1) :param suffix: Optional static suffix text to display after value :param \*args: Additional positional arguments passed to Static :param \*\*kwargs: Additional keyword arguments passed to Static .. py:attribute:: BINDINGS :value: [('+', 'increment', 'Increment'), ('=', 'increment', 'Increment'), ('j', 'increment',... A list of key bindings. .. py:class:: Changed(value, widget_id) Bases: :py:obj:`textual.message.Message` Message posted when the slider value changes. .. attribute:: value The new float value after the change .. attribute:: widget_id The ID of the widget that posted this message, or None Initialize the Changed message. :param value: The new slider value :param widget_id: ID of the slider widget that changed .. py:attribute:: value .. py:attribute:: widget_id .. py:attribute:: DEFAULT_CSS :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ FloatSlider { layout: horizontal; height: 1; width: 100%; } FloatSlider .slider-label { width: 15; text-align: right; padding-right: 1; } FloatSlider .slider-value { width: 8; text-align: center; background: $boost; } FloatSlider:focus .slider-value { background: $accent; text-style: bold; } FloatSlider .slider-suffix { width: auto; padding-left: 1; color: $text-muted; } """ .. raw:: html
Default TCSS. .. py:attribute:: label_text .. py:attribute:: value .. py:attribute:: min_val .. py:attribute:: max_val .. py:attribute:: step :value: 0.1 .. py:attribute:: precision :value: 1 .. py:attribute:: suffix :value: '' .. py:method:: compose() Create the slider layout. Layout: [Label:] [value] [suffix] :Yields: Label widgets for label, value display, and suffix .. py:method:: on_mount() Configure widget after mounting. Makes the widget focusable for keyboard navigation. Focus state is used to highlight the value display. .. py:method:: action_increment() Increment value by step, clamped to max. Only posts Changed message if value actually changed. .. py:method:: action_decrement() Decrement value by step, clamped to min. Only posts Changed message if value actually changed. .. py:method:: set_value(value) Set value programmatically, clamped to range. Use this method to update the slider value from code. Posts Changed message if value actually changed. :param value: New value (will be clamped to min/max range)