Skip to content

Motion Behaviors

morphui.uix.behaviors.motion

MorphMotionBaseBehavior(**kwargs)

Bases: MorphScaleBehavior

Base class for motion-related behaviors.

This class serves as a common base for behaviors that involve motion or animation, such as menu motion. It can be extended to provide shared functionality or properties related to motion.

is_open = AliasProperty(lambda self: bool(self.parent), bind=['parent']) class-attribute instance-attribute

Flag indicating whether the menu is currently open.

This property is True when the menu is visible and False when it is closed.

:attr:is_open is a :class:~kivy.properties.AliasProperty and is read-only.

window_margin = NumericProperty(dp(8)) class-attribute instance-attribute

Margin from the window edges in pixels.

This property defines the minimum distance (in pixels) that the widget should maintain from the edges of the window. This ensures this widget remains fully visible and doesn't extend beyond the window bounds.

:attr:window_margin is a :class:~kivy.properties.NumericProperty and defaults to 8.

opening_duration = NumericProperty(0.15) class-attribute instance-attribute

Duration of the opening animation in seconds.

This property defines how long the animation takes when the is opened. It is specified in seconds.

:attr:opening_duration is a :class:~kivy.properties.NumericProperty and defaults to 0.15.

opening_transition = StringProperty('out_sine') class-attribute instance-attribute

Transition type for the opening animation.

This property defines the type of transition used during the opening animation. It should be a valid Kivy transition name.

:attr:opening_transition is a :class:~kivy.properties.StringProperty and defaults to 'out_sine'.

dismissing_duration = NumericProperty(0.15) class-attribute instance-attribute

Duration of the dismiss animation in seconds.

This property defines how long the animation takes when the is dismissed. It is specified in seconds.

:attr:dismissing_duration is a :class:~kivy.properties.NumericProperty and defaults to 0.1.

dismissing_transition = StringProperty('in_sine') class-attribute instance-attribute

Transition type for the dismiss animation.

This property defines the type of transition used during the dismiss animation. It should be a valid Kivy transition name.

:attr:dismissing_transition is a :class:~kivy.properties.StringProperty and defaults to 'in_sine'.

backdrop_dismiss = BooleanProperty(True) class-attribute instance-attribute

Whether to dismiss the widget when the backdrop is touched.

If set to True, touching the backdrop (the area outside the widget) will dismiss the widget. If set to False, the widget will not be dismissed when the backdrop is touched.

:attr:backdrop_dismiss is a :class:~kivy.properties.BooleanProperty and defaults to True.

open(*args)

Open the widget with animation.

This method opens the widget with an animation. If the widget is already open, it does nothing. The widget position is adjusted to fit within the window bounds before opening.

dismiss(*args)

Dismiss the menu with animation.

toggle(*args)

Toggle the menu open/closed state with animation.

on_pre_open(*args)

Event fired before the widget is opened.

on_pre_dismiss(*args)

Event fired before the widget is dismissed.

on_open(*args)

Event fired when the widget is opened.

on_dismiss(*args)

Event fired when the widget is dismissed.

on_touch_up(touch)

Handle touch up events to dismiss the widget when touching outside.

This method handles touch up events and dismisses the widget if :meth:_should_dismiss returns True. Otherwise, it allows the event to propagate to the parent class.

PARAMETER DESCRIPTION
touch

The touch event that occurred.

TYPE: MotionEvent

RETURNS DESCRIPTION
Literal[True] | None

Returns result from parent class if dismissal is not needed, or None if the widget was dismissed.

MorphMenuMotionBehavior(**kwargs)

Bases: MorphMotionBaseBehavior

Behavior class that adds menu motion functionality to a widget.

This behavior provides properties and methods to manage a menu associated with a widget, including tools, open/close state, and animation settings.

Notes

If the widget also inherits from :class:MorphSizeBoundsBehavior, this behavior will automatically set the size_upper_bound property to constrain the menu size within the window bounds when opened.

caller = ObjectProperty(None) class-attribute instance-attribute

Caller button that opened this menu.

This property holds a reference to the widget that triggered the opening of this toolbar menu. It can be used to manage the position and behavior of the menu in relation to the caller button.

:attr:caller is a :class:~kivy.properties.ObjectProperty and defaults to None.

same_width_as_caller = BooleanProperty(False) class-attribute instance-attribute

Whether the menu should match the caller button's width.

If set to True, the menu will automatically adjust its width to match the width of the caller button when opened.

:attr:same_width_as_caller is a :class:~kivy.properties.BoolProperty and defaults to False.

menu_anchor_position = OptionProperty('center', options=['left', 'center', 'right']) class-attribute instance-attribute

Position of the menu relative to the caller widget.

This property defines the horizontal alignment of the menu relative to the caller button. Options are: - 'left': Align the menu's right edge with the caller's left edge - 'center': Center the menu horizontally with the caller - 'right': Align the menu's left edge with the caller's right edge

:attr:menu_anchor_position is a :class:~kivy.properties.OptionProperty and defaults to 'center'.

menu_opening_direction = OptionProperty('down', options=['up', 'center', 'down']) class-attribute instance-attribute

Direction in which the menu opens.

This property defines the direction in which the menu will open relative to the caller button. It can be either 'up', 'center' or 'down'.

:attr:menu_opening_direction is a :class:~kivy.properties.OptionProperty and defaults to 'down'.

menu_caller_spacing = NumericProperty(dp(2)) class-attribute instance-attribute

Spacing between the menu and the caller button in pixels.

This property defines the vertical spacing (in pixels) between the menu and the caller button when the menu is opened.

:attr:menu_caller_spacing is a :class:~kivy.properties.NumericProperty and defaults to 2.

auto_adjust_position = BooleanProperty(True) class-attribute instance-attribute

Whether to automatically adjust menu position to fit within window bounds.

This property determines if the menu should automatically adjust its position and opening direction when there is insufficient space in the window to fully display the menu. If set to True, the menu will switch its anchor position and/or opening direction to fit within the window bounds.

:attr:auto_adjust_position is a :class:~kivy.properties.BoolProperty and defaults to True.

min_space_required = NumericProperty(dp(100)) class-attribute instance-attribute

Minimum space required (in pixels) before adjusting menu position.

This property defines the minimum amount of space (in pixels) required in the desired direction for the menu to open. If there is insufficient space, the menu may switch its position or opening direction based on the :attr:auto_adjust_position setting.

:attr:min_space_required is a :class:~kivy.properties.NumericProperty and defaults to 100.

set_scale_origin(*args)

Set the scale origin based on the caller button position and anchor.

This method calculates the scale origin point for the menu based on the position and size of the caller button, ensuring that the menu scales from the appropriate point when opened or closed.

caller_collide_point(x, y)

Check if the given point collides with the caller button.

This method checks if the specified (x, y) coordinates collide with the caller button's area. It is used to determine if a touch event occurred within the caller button. This method is a workaround for the fact that the native collide_point method does not work correctly for the caller button when the menu is open.

PARAMETER DESCRIPTION
x

The x-coordinate of the point to check.

TYPE: float

y

The y-coordinate of the point to check.

TYPE: float

RETURNS DESCRIPTION
bool

True if the point collides with the caller button, False otherwise.

MorphDialogMotionBehavior(**kwargs)

Bases: MorphMotionBaseBehavior

Behavior class that adds dialog motion functionality to a widget.

This behavior extends :class:MorphMotionBaseBehavior to provide motion functionality specific to dialogs. It can be used to create dialogs that open and close with animations, while ensuring they fit within the window bounds.

Notes

This behavior is designed for dialog widgets and may include additional properties or methods specific to dialog behavior in the future.

window_margin = NumericProperty(dp(48)) class-attribute instance-attribute

Margin from the window edges in pixels.

This property defines the minimum distance (in pixels) that the widget should maintain from the edges of the window. This ensures this widget remains fully visible and doesn't extend beyond the window bounds.

:attr:window_margin is a :class:~kivy.properties.NumericProperty and defaults to 48.

set_scale_origin(*args)

Set the scale origin to the center of the dialog.