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

kvex.widgets.label

Home of XLabel and XLabelClick.

 1"""Home of `XLabel` and `XLabelClick`."""
 2
 3from .. import kivy as kv
 4from ..behaviors import XThemed
 5from .widget import XWidget
 6
 7
 8class XLabel(XThemed, XWidget, kv.Label):
 9    """Label."""
10
11    def __init__(self, fixed_width: bool = False, fixed_height: bool = False, **kwargs):
12        """Initialize the class.
13
14        Args:
15            fixed_width: Adjust the height of the label while maintaining width.
16            fixed_height: Adjust the width of the label while maintaining height.
17        """
18        kwargs = {
19            "markup": True,
20            "halign": "center",
21            "valign": "center",
22        } | kwargs
23        if fixed_width and fixed_height:
24            raise RuntimeError("Must set either fixed_width or fixed_height.")
25        super().__init__(**kwargs)
26        self._trigger_fix_height = kv.Clock.create_trigger(self._fix_height)
27        self._trigger_fix_width = kv.Clock.create_trigger(self._fix_width)
28        if fixed_width:
29            self.bind(
30                size=self._trigger_fix_height,
31                text=self._trigger_fix_height,
32            )
33        elif fixed_height:
34            self.bind(
35                size=self._trigger_fix_width,
36                text=self._trigger_fix_width,
37            )
38        else:
39            self.bind(size=self._on_size)
40
41    def _fix_height(self, *a):
42        x = self.size[0]
43        hx = self.size_hint[0]
44        self.text_size = x, None
45        self.texture_update()
46        if hx is None:
47            self.set_size(x=x, y=self.texture_size[1])
48        else:
49            self.set_size(hx=hx, y=self.texture_size[1])
50
51    def _fix_width(self, *a):
52        y = self.size[1]
53        hy = self.size_hint[1]
54        self.text_size = None, y
55        self.texture_update()
56        if hy is None:
57            self.set_size(x=self.texture_size[0], y=y)
58        else:
59            self.set_size(x=self.texture_size[0], hy=hy)
60
61    def _on_size(self, *a):
62        self.text_size = self.size
63
64    def on_subtheme(self, subtheme):
65        """Apply colors."""
66        self.color = subtheme.fg.rgba
67
68
69class XLabelClick(kv.ButtonBehavior, XLabel):
70    """Label with ButtonBehavior."""
71
72    pass
73
74
75__all__ = (
76    "XLabel",
77    "XLabelClick",
78)
class XLabel(kvex.behaviors.XThemed, kvex.widgets.widget.XWidget, kivy.uix.label.Label):
 9class XLabel(XThemed, XWidget, kv.Label):
10    """Label."""
11
12    def __init__(self, fixed_width: bool = False, fixed_height: bool = False, **kwargs):
13        """Initialize the class.
14
15        Args:
16            fixed_width: Adjust the height of the label while maintaining width.
17            fixed_height: Adjust the width of the label while maintaining height.
18        """
19        kwargs = {
20            "markup": True,
21            "halign": "center",
22            "valign": "center",
23        } | kwargs
24        if fixed_width and fixed_height:
25            raise RuntimeError("Must set either fixed_width or fixed_height.")
26        super().__init__(**kwargs)
27        self._trigger_fix_height = kv.Clock.create_trigger(self._fix_height)
28        self._trigger_fix_width = kv.Clock.create_trigger(self._fix_width)
29        if fixed_width:
30            self.bind(
31                size=self._trigger_fix_height,
32                text=self._trigger_fix_height,
33            )
34        elif fixed_height:
35            self.bind(
36                size=self._trigger_fix_width,
37                text=self._trigger_fix_width,
38            )
39        else:
40            self.bind(size=self._on_size)
41
42    def _fix_height(self, *a):
43        x = self.size[0]
44        hx = self.size_hint[0]
45        self.text_size = x, None
46        self.texture_update()
47        if hx is None:
48            self.set_size(x=x, y=self.texture_size[1])
49        else:
50            self.set_size(hx=hx, y=self.texture_size[1])
51
52    def _fix_width(self, *a):
53        y = self.size[1]
54        hy = self.size_hint[1]
55        self.text_size = None, y
56        self.texture_update()
57        if hy is None:
58            self.set_size(x=self.texture_size[0], y=y)
59        else:
60            self.set_size(x=self.texture_size[0], hy=hy)
61
62    def _on_size(self, *a):
63        self.text_size = self.size
64
65    def on_subtheme(self, subtheme):
66        """Apply colors."""
67        self.color = subtheme.fg.rgba

Label.

XLabel(fixed_width: bool = False, fixed_height: bool = False, **kwargs)
12    def __init__(self, fixed_width: bool = False, fixed_height: bool = False, **kwargs):
13        """Initialize the class.
14
15        Args:
16            fixed_width: Adjust the height of the label while maintaining width.
17            fixed_height: Adjust the width of the label while maintaining height.
18        """
19        kwargs = {
20            "markup": True,
21            "halign": "center",
22            "valign": "center",
23        } | kwargs
24        if fixed_width and fixed_height:
25            raise RuntimeError("Must set either fixed_width or fixed_height.")
26        super().__init__(**kwargs)
27        self._trigger_fix_height = kv.Clock.create_trigger(self._fix_height)
28        self._trigger_fix_width = kv.Clock.create_trigger(self._fix_width)
29        if fixed_width:
30            self.bind(
31                size=self._trigger_fix_height,
32                text=self._trigger_fix_height,
33            )
34        elif fixed_height:
35            self.bind(
36                size=self._trigger_fix_width,
37                text=self._trigger_fix_width,
38            )
39        else:
40            self.bind(size=self._on_size)

Initialize the class.

Arguments:
  • fixed_width: Adjust the height of the label while maintaining width.
  • fixed_height: Adjust the width of the label while maintaining height.
def on_subtheme(self, subtheme):
65    def on_subtheme(self, subtheme):
66        """Apply colors."""
67        self.color = subtheme.fg.rgba

Apply colors.

Inherited Members
kivy.uix.label.Label
texture_update
on_touch_down
on_ref_press
disabled_color
text
text_size
base_direction
text_language
font_context
font_family
font_name
font_size
font_features
line_height
bold
italic
underline
strikethrough
padding_x
padding_y
padding
halign
valign
color
outline_width
outline_color
disabled_outline_color
texture
texture_size
mipmap
shorten
shorten_from
is_shortened
split_str
ellipsis_options
unicode_errors
markup
refs
anchors
max_lines
strip
font_hinting
font_kerning
font_blended
kivy.uix.widget.Widget
proxy_ref
apply_class_lang_rules
collide_point
collide_widget
on_motion
on_touch_move
on_touch_up
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._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 XLabelClick(kivy.uix.behaviors.button.ButtonBehavior, XLabel):
70class XLabelClick(kv.ButtonBehavior, XLabel):
71    """Label with ButtonBehavior."""
72
73    pass

Label with ButtonBehavior.

Inherited Members
kivy.uix.behaviors.button.ButtonBehavior
ButtonBehavior
state
last_touch
min_state_time
always_release
cancel_event
on_touch_down
on_touch_move
on_touch_up
on_press
on_release
trigger_action
kivy.uix.label.Label
texture_update
on_ref_press
disabled_color
text
text_size
base_direction
text_language
font_context
font_family
font_name
font_size
font_features
line_height
bold
italic
underline
strikethrough
padding_x
padding_y
padding
halign
valign
color
outline_width
outline_color
disabled_outline_color
texture
texture_size
mipmap
shorten
shorten_from
is_shortened
split_str
ellipsis_options
unicode_errors
markup
refs
anchors
max_lines
strip
font_hinting
font_kerning
font_blended
kivy.uix.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._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