[MouseFox logo]
The MouseFox Project
Join The Community Discord Server
[Discord logo]
Edit on GitHub

kvex.widgets.slider

Home of XSlider and XSliderText.

 1"""Home of `XSlider` and `XSliderText`."""
 2
 3from typing import Optional, Any
 4from .. import kivy as kv
 5from .widget import XWidget
 6from .label import XLabel
 7from .layouts import XBox
 8
 9
10class XSlider(XWidget, kv.Slider):
11    """Slider."""
12
13    pass
14
15
16class XSliderText(XBox):
17    """Slider with Label."""
18
19    def __init__(
20        self,
21        prefix: str = "",
22        rounding: int = 3,
23        box_kwargs: Optional[dict[str, Any]] = None,
24        label_kwargs: Optional[dict[str, Any]] = None,
25        **kwargs,
26    ):
27        """Initialize the class.
28
29        Args:
30            prefix: Text to prefix the value presented in the label.
31            rounding: How many decimal places to show.
32            box_kwargs: Keyword arguments for XBox.
33            label_kwargs: Keyword arguments for XLabel.
34            kwargs: Keyword arguments for XSlider.
35        """
36        box_kwargs = {} if box_kwargs is None else box_kwargs
37        label_kwargs = {} if label_kwargs is None else label_kwargs
38        label_kwargs = {"halign": "left"} | label_kwargs
39        slider_kwargs = {"cursor_size": (25, 25)} | kwargs
40        super().__init__(**box_kwargs)
41        self.rounding = rounding
42        self.prefix = prefix
43        self.label = XLabel(**label_kwargs)
44        self.label.set_size(hx=0.2)
45        self.slider = XSlider(**slider_kwargs)
46        self.add_widgets(self.label, self.slider)
47        self.slider.bind(value=self._set_text)
48        self._set_text(self, self.slider.value)
49
50    def _set_text(self, w, value):
51        if isinstance(value, float):
52            value = round(value, self.rounding)
53        if value == round(value):
54            value = int(value)
55        self.label.text = str(f"{self.prefix}{value}")
56
57
58__all__ = (
59    "XSlider",
60    "XSliderText",
61)
class XSlider(kvex.widgets.widget.XWidget, kivy.uix.slider.Slider):
11class XSlider(XWidget, kv.Slider):
12    """Slider."""
13
14    pass

Slider.

Inherited Members
kivy.uix.widget.Widget
Widget
proxy_ref
apply_class_lang_rules
collide_point
collide_widget
on_motion
on_kv_post
add_widget
remove_widget
clear_widgets
register_for_motion_event
unregister_for_motion_event
export_to_png
export_as_image
get_root_window
get_parent_window
walk
walk_reverse
to_widget
to_window
to_parent
to_local
get_window_matrix
x
y
width
height
pos
size
get_right
set_right
right
get_top
set_top
top
get_center_x
set_center_x
center_x
get_center_y
set_center_y
center_y
center
cls
children
parent
size_hint_x
size_hint_y
size_hint
pos_hint
size_hint_min_x
size_hint_min_y
size_hint_min
size_hint_max_x
size_hint_max_y
size_hint_max
ids
opacity
on_opacity
canvas
get_disabled
set_disabled
inc_disabled
dec_disabled
disabled
motion_filter
kivy.uix.slider.Slider
value
min
max
padding
orientation
range
step
background_horizontal
background_disabled_horizontal
background_vertical
background_disabled_vertical
background_width
cursor_image
cursor_disabled_image
cursor_width
cursor_height
cursor_size
border_horizontal
border_vertical
value_track
value_track_color
value_track_width
sensitivity
on_min
on_max
get_norm_value
set_norm_value
value_normalized
get_value_pos
set_value_pos
value_pos
on_touch_down
on_touch_move
on_touch_up
kivy._event.EventDispatcher
register_event_type
unregister_event_types
unregister_event_type
is_event_type
bind
unbind
fbind
funbind
unbind_uid
get_property_observers
events
dispatch
dispatch_generic
dispatch_children
setter
getter
property
properties
create_property
apply_property
class XSliderText(kvex.widgets.layouts.XBox):
17class XSliderText(XBox):
18    """Slider with Label."""
19
20    def __init__(
21        self,
22        prefix: str = "",
23        rounding: int = 3,
24        box_kwargs: Optional[dict[str, Any]] = None,
25        label_kwargs: Optional[dict[str, Any]] = None,
26        **kwargs,
27    ):
28        """Initialize the class.
29
30        Args:
31            prefix: Text to prefix the value presented in the label.
32            rounding: How many decimal places to show.
33            box_kwargs: Keyword arguments for XBox.
34            label_kwargs: Keyword arguments for XLabel.
35            kwargs: Keyword arguments for XSlider.
36        """
37        box_kwargs = {} if box_kwargs is None else box_kwargs
38        label_kwargs = {} if label_kwargs is None else label_kwargs
39        label_kwargs = {"halign": "left"} | label_kwargs
40        slider_kwargs = {"cursor_size": (25, 25)} | kwargs
41        super().__init__(**box_kwargs)
42        self.rounding = rounding
43        self.prefix = prefix
44        self.label = XLabel(**label_kwargs)
45        self.label.set_size(hx=0.2)
46        self.slider = XSlider(**slider_kwargs)
47        self.add_widgets(self.label, self.slider)
48        self.slider.bind(value=self._set_text)
49        self._set_text(self, self.slider.value)
50
51    def _set_text(self, w, value):
52        if isinstance(value, float):
53            value = round(value, self.rounding)
54        if value == round(value):
55            value = int(value)
56        self.label.text = str(f"{self.prefix}{value}")

Slider with Label.

XSliderText( prefix: str = '', rounding: int = 3, box_kwargs: Optional[dict[str, Any]] = None, label_kwargs: Optional[dict[str, Any]] = None, **kwargs)
20    def __init__(
21        self,
22        prefix: str = "",
23        rounding: int = 3,
24        box_kwargs: Optional[dict[str, Any]] = None,
25        label_kwargs: Optional[dict[str, Any]] = None,
26        **kwargs,
27    ):
28        """Initialize the class.
29
30        Args:
31            prefix: Text to prefix the value presented in the label.
32            rounding: How many decimal places to show.
33            box_kwargs: Keyword arguments for XBox.
34            label_kwargs: Keyword arguments for XLabel.
35            kwargs: Keyword arguments for XSlider.
36        """
37        box_kwargs = {} if box_kwargs is None else box_kwargs
38        label_kwargs = {} if label_kwargs is None else label_kwargs
39        label_kwargs = {"halign": "left"} | label_kwargs
40        slider_kwargs = {"cursor_size": (25, 25)} | kwargs
41        super().__init__(**box_kwargs)
42        self.rounding = rounding
43        self.prefix = prefix
44        self.label = XLabel(**label_kwargs)
45        self.label.set_size(hx=0.2)
46        self.slider = XSlider(**slider_kwargs)
47        self.add_widgets(self.label, self.slider)
48        self.slider.bind(value=self._set_text)
49        self._set_text(self, self.slider.value)

Initialize the class.

Arguments:
  • prefix: Text to prefix the value presented in the label.
  • rounding: How many decimal places to show.
  • box_kwargs: Keyword arguments for XBox.
  • label_kwargs: Keyword arguments for XLabel.
  • kwargs: Keyword arguments for XSlider.
Inherited Members
kivy.uix.boxlayout.BoxLayout
spacing
padding
orientation
minimum_width
minimum_height
minimum_size
do_layout
add_widget
remove_widget
kivy.uix.layout.Layout
layout_hint_with_bounds
kivy.uix.widget.Widget
proxy_ref
apply_class_lang_rules
collide_point
collide_widget
on_motion
on_touch_down
on_touch_move
on_touch_up
on_kv_post
clear_widgets
register_for_motion_event
unregister_for_motion_event
export_to_png
export_as_image
get_root_window
get_parent_window
walk
walk_reverse
to_widget
to_window
to_parent
to_local
get_window_matrix
x
y
width
height
pos
size
get_right
set_right
right
get_top
set_top
top
get_center_x
set_center_x
center_x
get_center_y
set_center_y
center_y
center
cls
children
parent
size_hint_x
size_hint_y
size_hint
pos_hint
size_hint_min_x
size_hint_min_y
size_hint_min
size_hint_max_x
size_hint_max_y
size_hint_max
ids
opacity
on_opacity
canvas
get_disabled
set_disabled
inc_disabled
dec_disabled
disabled
motion_filter
kivy._event.EventDispatcher
register_event_type
unregister_event_types
unregister_event_type
is_event_type
bind
unbind
fbind
funbind
unbind_uid
get_property_observers
events
dispatch
dispatch_generic
dispatch_children
setter
getter
property
properties
create_property
apply_property