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

kvex.widgets.container

Home of XContainer and XPlaceholder.

 1"""Home of `XContainer` and `XPlaceholder`."""
 2
 3from typing import Callable, Optional
 4from .. import kivy as kv
 5from .layouts import XAnchor, XBox
 6from .label import XLabel
 7from .button import XButton
 8
 9
10class XPlaceholder(XBox):
11    """A simple label and button widget for `XContainer`."""
12
13    def __init__(
14        self,
15        label_text: str = "",
16        button_text: str = "Return",
17        callback: Optional[Callable] = None,
18    ):
19        """Initialize the class.
20
21        Args:
22            label_text: Label text.
23            button_text: Button text.
24            callback: Function to call when button is pressed. Required to show button.
25        """
26        super().__init__(orientation="vertical")
27        if label_text:
28            label = XLabel(text=label_text)
29            label.set_size(hy=4)
30            self.add_widget(label)
31        if callback:
32            button = XButton(text=button_text, on_release=lambda *a: callback())
33            button.set_size(x="300dp", y="70dp")
34            self.add_widget(XAnchor.wrap(button))
35
36
37class XContainer(XAnchor):
38    """A frame with an optional `content` widget and an XPlaceholder fallback."""
39
40    content = kv.ObjectProperty(None, allownone=True)
41    """Content widget. Setting None will show the placeholder fallback."""
42
43    def __init__(self, placeholder: Optional[XPlaceholder] = None):
44        """Initialize the class with an `XPlaceholder`."""
45        super().__init__()
46        self._placeholder = placeholder or XPlaceholder()
47        self.bind(content=self._on_content)
48        self._on_content(self, self.content)
49
50    def _on_content(self, w, content):
51        self.clear_widgets()
52        if content:
53            self.add_widget(content)
54        else:
55            self.add_widget(self._placeholder)
56
57
58__all__ = (
59    "XContainer",
60    "XPlaceholder",
61)
class XContainer(kvex.widgets.layouts.XAnchor):
38class XContainer(XAnchor):
39    """A frame with an optional `content` widget and an XPlaceholder fallback."""
40
41    content = kv.ObjectProperty(None, allownone=True)
42    """Content widget. Setting None will show the placeholder fallback."""
43
44    def __init__(self, placeholder: Optional[XPlaceholder] = None):
45        """Initialize the class with an `XPlaceholder`."""
46        super().__init__()
47        self._placeholder = placeholder or XPlaceholder()
48        self.bind(content=self._on_content)
49        self._on_content(self, self.content)
50
51    def _on_content(self, w, content):
52        self.clear_widgets()
53        if content:
54            self.add_widget(content)
55        else:
56            self.add_widget(self._placeholder)

A frame with an optional content widget and an XPlaceholder fallback.

XContainer(placeholder: Optional[kvex.widgets.container.XPlaceholder] = None)
44    def __init__(self, placeholder: Optional[XPlaceholder] = None):
45        """Initialize the class with an `XPlaceholder`."""
46        super().__init__()
47        self._placeholder = placeholder or XPlaceholder()
48        self.bind(content=self._on_content)
49        self._on_content(self, self.content)

Initialize the class with an XPlaceholder.

content

Content widget. Setting None will show the placeholder fallback.

Inherited Members
kivy.uix.anchorlayout.AnchorLayout
padding
anchor_x
anchor_y
do_layout
kivy.uix.layout.Layout
add_widget
remove_widget
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
class XPlaceholder(kvex.widgets.layouts.XBox):
11class XPlaceholder(XBox):
12    """A simple label and button widget for `XContainer`."""
13
14    def __init__(
15        self,
16        label_text: str = "",
17        button_text: str = "Return",
18        callback: Optional[Callable] = None,
19    ):
20        """Initialize the class.
21
22        Args:
23            label_text: Label text.
24            button_text: Button text.
25            callback: Function to call when button is pressed. Required to show button.
26        """
27        super().__init__(orientation="vertical")
28        if label_text:
29            label = XLabel(text=label_text)
30            label.set_size(hy=4)
31            self.add_widget(label)
32        if callback:
33            button = XButton(text=button_text, on_release=lambda *a: callback())
34            button.set_size(x="300dp", y="70dp")
35            self.add_widget(XAnchor.wrap(button))

A simple label and button widget for XContainer.

XPlaceholder( label_text: str = '', button_text: str = 'Return', callback: Optional[Callable] = None)
14    def __init__(
15        self,
16        label_text: str = "",
17        button_text: str = "Return",
18        callback: Optional[Callable] = None,
19    ):
20        """Initialize the class.
21
22        Args:
23            label_text: Label text.
24            button_text: Button text.
25            callback: Function to call when button is pressed. Required to show button.
26        """
27        super().__init__(orientation="vertical")
28        if label_text:
29            label = XLabel(text=label_text)
30            label.set_size(hy=4)
31            self.add_widget(label)
32        if callback:
33            button = XButton(text=button_text, on_release=lambda *a: callback())
34            button.set_size(x="300dp", y="70dp")
35            self.add_widget(XAnchor.wrap(button))

Initialize the class.

Arguments:
  • label_text: Label text.
  • button_text: Button text.
  • callback: Function to call when button is pressed. Required to show button.
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