kvex.widgets.button
Home of XButton
and XToggleButton
.
1"""Home of `XButton` and `XToggleButton`.""" 2 3from .. import kivy as kv 4from .. import assets 5from ..behaviors import XThemed 6from .widget import XWidget 7 8 9BG_NORMAL = str(assets.get_image("button")) 10BG_DOWN = str(assets.get_image("button_down")) 11 12 13class XButton(XThemed, XWidget, kv.Button): 14 """Button.""" 15 16 def __init__(self, **kwargs): 17 """Initialize the class.""" 18 kwargs = dict( 19 markup=True, 20 halign="center", 21 valign="center", 22 background_normal=BG_NORMAL, 23 background_down=BG_DOWN, 24 border=(2, 1, 2, 1), 25 ) | kwargs 26 super().__init__(**kwargs) 27 28 def on_touch_down(self, m): 29 """Overrides base class method to only react to left clicks.""" 30 if m.button != "left": 31 return False 32 return super().on_touch_down(m) 33 34 def on_subtheme(self, subtheme): 35 """Apply colors.""" 36 self.background_color = subtheme.bg.rgba 37 self.color = subtheme.fg.rgba 38 39 40class XToggleButton(kv.ToggleButtonBehavior, XButton): 41 """ToggleButton.""" 42 43 active = kv.BooleanProperty(False) 44 """Behaves like an alias for the `state` property being "down".""" 45 46 def __init__(self, **kwargs): 47 """Same arguments as kivy Button.""" 48 super().__init__(**kwargs) 49 self.bind(state=self._set_active) 50 self.bind(active=self._set_state) 51 52 def toggle(self, *args): 53 """Toggles the active state of the button.""" 54 self.active = not self.active 55 56 def _set_state(self, *args): 57 self.state = "down" if self.active else "normal" 58 59 def _set_active(self, *args): 60 self.active = self.state == "down" 61 62 63__all__ = ( 64 "XButton", 65 "XToggleButton", 66)
14class XButton(XThemed, XWidget, kv.Button): 15 """Button.""" 16 17 def __init__(self, **kwargs): 18 """Initialize the class.""" 19 kwargs = dict( 20 markup=True, 21 halign="center", 22 valign="center", 23 background_normal=BG_NORMAL, 24 background_down=BG_DOWN, 25 border=(2, 1, 2, 1), 26 ) | kwargs 27 super().__init__(**kwargs) 28 29 def on_touch_down(self, m): 30 """Overrides base class method to only react to left clicks.""" 31 if m.button != "left": 32 return False 33 return super().on_touch_down(m) 34 35 def on_subtheme(self, subtheme): 36 """Apply colors.""" 37 self.background_color = subtheme.bg.rgba 38 self.color = subtheme.fg.rgba
Button.
XButton(**kwargs)
17 def __init__(self, **kwargs): 18 """Initialize the class.""" 19 kwargs = dict( 20 markup=True, 21 halign="center", 22 valign="center", 23 background_normal=BG_NORMAL, 24 background_down=BG_DOWN, 25 border=(2, 1, 2, 1), 26 ) | kwargs 27 super().__init__(**kwargs)
Initialize the class.
def
on_touch_down(self, m):
29 def on_touch_down(self, m): 30 """Overrides base class method to only react to left clicks.""" 31 if m.button != "left": 32 return False 33 return super().on_touch_down(m)
Overrides base class method to only react to left clicks.
def
on_subtheme(self, subtheme):
35 def on_subtheme(self, subtheme): 36 """Apply colors.""" 37 self.background_color = subtheme.bg.rgba 38 self.color = subtheme.fg.rgba
Apply colors.
Inherited Members
- kivy.uix.button.Button
- background_color
- background_normal
- background_down
- background_disabled_normal
- background_disabled_down
- border
- kivy.uix.behaviors.button.ButtonBehavior
- state
- last_touch
- min_state_time
- always_release
- cancel_event
- 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
41class XToggleButton(kv.ToggleButtonBehavior, XButton): 42 """ToggleButton.""" 43 44 active = kv.BooleanProperty(False) 45 """Behaves like an alias for the `state` property being "down".""" 46 47 def __init__(self, **kwargs): 48 """Same arguments as kivy Button.""" 49 super().__init__(**kwargs) 50 self.bind(state=self._set_active) 51 self.bind(active=self._set_state) 52 53 def toggle(self, *args): 54 """Toggles the active state of the button.""" 55 self.active = not self.active 56 57 def _set_state(self, *args): 58 self.state = "down" if self.active else "normal" 59 60 def _set_active(self, *args): 61 self.active = self.state == "down"
ToggleButton.
XToggleButton(**kwargs)
47 def __init__(self, **kwargs): 48 """Same arguments as kivy Button.""" 49 super().__init__(**kwargs) 50 self.bind(state=self._set_active) 51 self.bind(active=self._set_state)
Same arguments as kivy Button.
def
toggle(self, *args):
53 def toggle(self, *args): 54 """Toggles the active state of the button.""" 55 self.active = not self.active
Toggles the active state of the button.
Inherited Members
- kivy.uix.behaviors.togglebutton.ToggleButtonBehavior
- group
- allow_no_selection
- on_group
- get_widgets
- kivy.uix.button.Button
- background_color
- background_normal
- background_down
- background_disabled_normal
- background_disabled_down
- border
- kivy.uix.behaviors.button.ButtonBehavior
- state
- last_touch
- min_state_time
- always_release
- cancel_event
- 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