kvex.widgets.layouts
Layout widgets.
1"""Layout widgets.""" 2 3from typing import Optional 4import functools 5from .. import kivy as kv 6from .. import assets 7from .. import util 8from ..behaviors import XThemed 9from .widget import XWidget 10 11 12class XBox(XWidget, kv.BoxLayout): 13 """BoyLayout.""" 14 15 pass 16 17 18class XZBox(XWidget, kv.GridLayout): 19 """Behaves like a Box where widgets are drawn in reverse order.""" 20 21 def __init__( 22 self, 23 *, 24 orientation: str = "horizontal", 25 **kwargs, 26 ): 27 """Initialize the class.""" 28 if orientation == "horizontal": 29 kwargs["orientation"] = "rl-tb" 30 kwargs["rows"] = 1 31 elif orientation == "vertical": 32 kwargs["orientation"] = "lr-bt" 33 kwargs["cols"] = 1 34 else: 35 raise ValueError('orientation must be "horizontal" or "vertical"') 36 super().__init__(**kwargs) 37 38 def add_widget(self, *args, **kwargs): 39 """Overrides base method to insert correctly.""" 40 kwargs["insert_last"] = True 41 super().add_widget(*args, **kwargs) 42 43 44class XDBox(XWidget, kv.GridLayout): 45 """Behaves like a Box that will dynamically resize based on children's height.""" 46 47 def __init__(self, cols: int = 1, **kwargs): 48 """Initialize the class.""" 49 super().__init__(cols=cols, **kwargs) 50 self.bind(children=self._resize) 51 trigger = util.create_trigger(self._resize) 52 self._snooze_trigger = lambda *a: util.snooze_trigger(trigger) 53 54 def add_widget(self, w, *args, **kwargs): 55 """Overrides base method in order to bind to size changes.""" 56 w.bind(size=self._resize) 57 super().add_widget(w, *args, **kwargs) 58 self._snooze_trigger() 59 60 def _resize(self, *a): 61 self.set_size(hx=1, y=sum([util.sp2pixels(c.height) for c in self.children])) 62 63 64class XGrid(XWidget, kv.GridLayout): 65 """GridLayout.""" 66 67 pass 68 69 70class XStack(XWidget, kv.StackLayout): 71 """StackLayout.""" 72 73 pass 74 75 76class XRelative(XWidget, kv.RelativeLayout): 77 """RelativeLayout.""" 78 79 pass 80 81 82class XAnchor(XWidget, kv.AnchorLayout): 83 """AnchorLayout.""" 84 85 @classmethod 86 def wrap(cls, widget: kv.Widget, /, **kwargs) -> "XAnchor": 87 """Create `XAnchor` with child widget. 88 89 Args: 90 widget: Widget to wrap. 91 kwargs: Keyword arguments for the XAnchor. 92 """ 93 anchor = cls(**kwargs) 94 anchor.add_widget(widget) 95 return anchor 96 97 98class XFrame(XThemed, XAnchor): 99 """Themed `XAnchor` with a background.""" 100 101 BG = str(assets.get_image("xframe_bg")) 102 103 def on_subtheme(self, subtheme): 104 """Apply background color.""" 105 self.make_bg(subtheme.bg, source=self.BG) 106 107 108wrap = XAnchor.wrap 109pwrap = functools.partial(XAnchor.wrap, padding="10sp") 110"""Like `wrap` but with '10sp' padding.""" 111fwrap = XFrame.wrap 112"""Like `wrap` but with `XFrame`.""" 113fpwrap = functools.partial(XFrame.wrap, padding="10sp") 114"""Like `fwrap` but with '10sp' padding.""" 115 116 117class XAnchorDelayed(XAnchor): 118 """An XAnchor that delays layout events. 119 120 Useful for preventing window drag-resize from creating too many events. 121 """ 122 123 layout_event_delay = kv.NumericProperty(0.1) 124 """Delay for layout events.""" 125 _delayed_layout_event = None 126 127 def do_layout(self, *args, **kwargs): 128 """Override base method to delay layout events.""" 129 if self._delayed_layout_event: 130 self._delayed_layout_event.cancel() 131 _real_do_layout = super().do_layout 132 self._delayed_layout_event = util.schedule_once( 133 lambda dt: _real_do_layout(*args, **kwargs), 134 self.layout_event_delay, 135 ) 136 137 138class XCurtain(XAnchor): 139 """AnchorLayout that can show or hide it's content.""" 140 141 content = kv.ObjectProperty(None, allownone=True) 142 """Widget to show and hide.""" 143 showing = kv.BooleanProperty(True) 144 """If the content widget is showing.""" 145 dynamic = kv.BooleanProperty(False) 146 """If the the curtain should resize based on content size and visibility.""" 147 148 def __init__(self, *args, **kwargs): 149 """Initialize the class.""" 150 super().__init__(*args, **kwargs) 151 self.bind( 152 content=self._on_properties, 153 showing=self._on_properties, 154 dynamic=self._on_properties, 155 ) 156 self._on_properties() 157 158 def _on_properties(self, *args): 159 if self.showing and self.content: 160 if self.content.parent: 161 self.clear_widgets() 162 if not self.content.parent: 163 self.add_widget(self.content) 164 if self.dynamic: 165 self.set_size(*self.content.size) 166 else: 167 self.clear_widgets() 168 if self.dynamic: 169 self.set_size(0, 0) 170 171 def show(self, *args, **kwargs): 172 """Show the content widget.""" 173 self.showing = True 174 175 def hide(self, *args, **kwargs): 176 """Hide the content widget.""" 177 self.showing = False 178 179 def toggle(self, *args, set_as: Optional[bool] = None, **kwargs): 180 """Toggle showing the content widget.""" 181 if set_as is None: 182 set_as = not self.showing 183 self.showing = set_as 184 185 186__all__ = ( 187 "XBox", 188 "XZBox", 189 "XDBox", 190 "XGrid", 191 "XRelative", 192 "XStack", 193 "XAnchor", 194 "XFrame", 195 "wrap", 196 "pwrap", 197 "fwrap", 198 "fpwrap", 199 "XAnchorDelayed", 200 "XCurtain", 201)
BoyLayout.
Inherited Members
- kivy.uix.boxlayout.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
19class XZBox(XWidget, kv.GridLayout): 20 """Behaves like a Box where widgets are drawn in reverse order.""" 21 22 def __init__( 23 self, 24 *, 25 orientation: str = "horizontal", 26 **kwargs, 27 ): 28 """Initialize the class.""" 29 if orientation == "horizontal": 30 kwargs["orientation"] = "rl-tb" 31 kwargs["rows"] = 1 32 elif orientation == "vertical": 33 kwargs["orientation"] = "lr-bt" 34 kwargs["cols"] = 1 35 else: 36 raise ValueError('orientation must be "horizontal" or "vertical"') 37 super().__init__(**kwargs) 38 39 def add_widget(self, *args, **kwargs): 40 """Overrides base method to insert correctly.""" 41 kwargs["insert_last"] = True 42 super().add_widget(*args, **kwargs)
Behaves like a Box where widgets are drawn in reverse order.
22 def __init__( 23 self, 24 *, 25 orientation: str = "horizontal", 26 **kwargs, 27 ): 28 """Initialize the class.""" 29 if orientation == "horizontal": 30 kwargs["orientation"] = "rl-tb" 31 kwargs["rows"] = 1 32 elif orientation == "vertical": 33 kwargs["orientation"] = "lr-bt" 34 kwargs["cols"] = 1 35 else: 36 raise ValueError('orientation must be "horizontal" or "vertical"') 37 super().__init__(**kwargs)
Initialize the class.
39 def add_widget(self, *args, **kwargs): 40 """Overrides base method to insert correctly.""" 41 kwargs["insert_last"] = True 42 super().add_widget(*args, **kwargs)
Overrides base method to insert correctly.
Inherited Members
- kivy.uix.gridlayout.GridLayout
- spacing
- padding
- cols
- rows
- col_default_width
- row_default_height
- col_force_default
- row_force_default
- cols_minimum
- rows_minimum
- minimum_width
- minimum_height
- minimum_size
- orientation
- get_max_widgets
- on_children
- do_layout
- kivy.uix.layout.Layout
- 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
45class XDBox(XWidget, kv.GridLayout): 46 """Behaves like a Box that will dynamically resize based on children's height.""" 47 48 def __init__(self, cols: int = 1, **kwargs): 49 """Initialize the class.""" 50 super().__init__(cols=cols, **kwargs) 51 self.bind(children=self._resize) 52 trigger = util.create_trigger(self._resize) 53 self._snooze_trigger = lambda *a: util.snooze_trigger(trigger) 54 55 def add_widget(self, w, *args, **kwargs): 56 """Overrides base method in order to bind to size changes.""" 57 w.bind(size=self._resize) 58 super().add_widget(w, *args, **kwargs) 59 self._snooze_trigger() 60 61 def _resize(self, *a): 62 self.set_size(hx=1, y=sum([util.sp2pixels(c.height) for c in self.children]))
Behaves like a Box that will dynamically resize based on children's height.
48 def __init__(self, cols: int = 1, **kwargs): 49 """Initialize the class.""" 50 super().__init__(cols=cols, **kwargs) 51 self.bind(children=self._resize) 52 trigger = util.create_trigger(self._resize) 53 self._snooze_trigger = lambda *a: util.snooze_trigger(trigger)
Initialize the class.
55 def add_widget(self, w, *args, **kwargs): 56 """Overrides base method in order to bind to size changes.""" 57 w.bind(size=self._resize) 58 super().add_widget(w, *args, **kwargs) 59 self._snooze_trigger()
Overrides base method in order to bind to size changes.
Inherited Members
- kivy.uix.gridlayout.GridLayout
- spacing
- padding
- cols
- rows
- col_default_width
- row_default_height
- col_force_default
- row_force_default
- cols_minimum
- rows_minimum
- minimum_width
- minimum_height
- minimum_size
- orientation
- get_max_widgets
- on_children
- do_layout
- kivy.uix.layout.Layout
- 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
GridLayout.
Inherited Members
- kivy.uix.gridlayout.GridLayout
- GridLayout
- spacing
- padding
- cols
- rows
- col_default_width
- row_default_height
- col_force_default
- row_force_default
- cols_minimum
- rows_minimum
- minimum_width
- minimum_height
- minimum_size
- orientation
- get_max_widgets
- on_children
- 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
RelativeLayout.
Inherited Members
- kivy.uix.relativelayout.RelativeLayout
- RelativeLayout
- do_layout
- to_parent
- to_local
- on_motion
- on_touch_down
- on_touch_move
- on_touch_up
- kivy.uix.floatlayout.FloatLayout
- 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_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
- 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
StackLayout.
Inherited Members
- kivy.uix.stacklayout.StackLayout
- StackLayout
- spacing
- padding
- orientation
- minimum_width
- minimum_height
- minimum_size
- 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
83class XAnchor(XWidget, kv.AnchorLayout): 84 """AnchorLayout.""" 85 86 @classmethod 87 def wrap(cls, widget: kv.Widget, /, **kwargs) -> "XAnchor": 88 """Create `XAnchor` with child widget. 89 90 Args: 91 widget: Widget to wrap. 92 kwargs: Keyword arguments for the XAnchor. 93 """ 94 anchor = cls(**kwargs) 95 anchor.add_widget(widget) 96 return anchor
AnchorLayout.
86 @classmethod 87 def wrap(cls, widget: kv.Widget, /, **kwargs) -> "XAnchor": 88 """Create `XAnchor` with child widget. 89 90 Args: 91 widget: Widget to wrap. 92 kwargs: Keyword arguments for the XAnchor. 93 """ 94 anchor = cls(**kwargs) 95 anchor.add_widget(widget) 96 return anchor
Create XAnchor
with child widget.
Arguments:
- widget: Widget to wrap.
- kwargs: Keyword arguments for the XAnchor.
Inherited Members
- kivy.uix.anchorlayout.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
99class XFrame(XThemed, XAnchor): 100 """Themed `XAnchor` with a background.""" 101 102 BG = str(assets.get_image("xframe_bg")) 103 104 def on_subtheme(self, subtheme): 105 """Apply background color.""" 106 self.make_bg(subtheme.bg, source=self.BG)
Themed XAnchor
with a background.
104 def on_subtheme(self, subtheme): 105 """Apply background color.""" 106 self.make_bg(subtheme.bg, source=self.BG)
Apply background color.
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
86 @classmethod 87 def wrap(cls, widget: kv.Widget, /, **kwargs) -> "XAnchor": 88 """Create `XAnchor` with child widget. 89 90 Args: 91 widget: Widget to wrap. 92 kwargs: Keyword arguments for the XAnchor. 93 """ 94 anchor = cls(**kwargs) 95 anchor.add_widget(widget) 96 return anchor
Create XAnchor
with child widget.
Arguments:
- widget: Widget to wrap.
- kwargs: Keyword arguments for the XAnchor.
Like wrap
but with '10sp' padding.
Like fwrap
but with '10sp' padding.
118class XAnchorDelayed(XAnchor): 119 """An XAnchor that delays layout events. 120 121 Useful for preventing window drag-resize from creating too many events. 122 """ 123 124 layout_event_delay = kv.NumericProperty(0.1) 125 """Delay for layout events.""" 126 _delayed_layout_event = None 127 128 def do_layout(self, *args, **kwargs): 129 """Override base method to delay layout events.""" 130 if self._delayed_layout_event: 131 self._delayed_layout_event.cancel() 132 _real_do_layout = super().do_layout 133 self._delayed_layout_event = util.schedule_once( 134 lambda dt: _real_do_layout(*args, **kwargs), 135 self.layout_event_delay, 136 )
An XAnchor that delays layout events.
Useful for preventing window drag-resize from creating too many events.
128 def do_layout(self, *args, **kwargs): 129 """Override base method to delay layout events.""" 130 if self._delayed_layout_event: 131 self._delayed_layout_event.cancel() 132 _real_do_layout = super().do_layout 133 self._delayed_layout_event = util.schedule_once( 134 lambda dt: _real_do_layout(*args, **kwargs), 135 self.layout_event_delay, 136 )
Override base method to delay layout events.
Inherited Members
- kivy.uix.anchorlayout.AnchorLayout
- AnchorLayout
- padding
- anchor_x
- anchor_y
- 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
139class XCurtain(XAnchor): 140 """AnchorLayout that can show or hide it's content.""" 141 142 content = kv.ObjectProperty(None, allownone=True) 143 """Widget to show and hide.""" 144 showing = kv.BooleanProperty(True) 145 """If the content widget is showing.""" 146 dynamic = kv.BooleanProperty(False) 147 """If the the curtain should resize based on content size and visibility.""" 148 149 def __init__(self, *args, **kwargs): 150 """Initialize the class.""" 151 super().__init__(*args, **kwargs) 152 self.bind( 153 content=self._on_properties, 154 showing=self._on_properties, 155 dynamic=self._on_properties, 156 ) 157 self._on_properties() 158 159 def _on_properties(self, *args): 160 if self.showing and self.content: 161 if self.content.parent: 162 self.clear_widgets() 163 if not self.content.parent: 164 self.add_widget(self.content) 165 if self.dynamic: 166 self.set_size(*self.content.size) 167 else: 168 self.clear_widgets() 169 if self.dynamic: 170 self.set_size(0, 0) 171 172 def show(self, *args, **kwargs): 173 """Show the content widget.""" 174 self.showing = True 175 176 def hide(self, *args, **kwargs): 177 """Hide the content widget.""" 178 self.showing = False 179 180 def toggle(self, *args, set_as: Optional[bool] = None, **kwargs): 181 """Toggle showing the content widget.""" 182 if set_as is None: 183 set_as = not self.showing 184 self.showing = set_as
AnchorLayout that can show or hide it's content.
149 def __init__(self, *args, **kwargs): 150 """Initialize the class.""" 151 super().__init__(*args, **kwargs) 152 self.bind( 153 content=self._on_properties, 154 showing=self._on_properties, 155 dynamic=self._on_properties, 156 ) 157 self._on_properties()
Initialize the class.
180 def toggle(self, *args, set_as: Optional[bool] = None, **kwargs): 181 """Toggle showing the content widget.""" 182 if set_as is None: 183 set_as = not self.showing 184 self.showing = set_as
Toggle showing the content widget.
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