Skip to content

Dialog

Dialogs display content in a modal overlay and block interaction with the rest of the UI. A MorphScrimLayer is rendered behind the dialog to focus user attention.

Usage

from morphui.uix.dialog import MorphDialog
from morphui.uix.label import MorphLabel
from morphui.uix.button import MorphButton
from morphui.uix.boxlayout import MorphBoxLayout
from kivy.core.window import Window

dialog = MorphDialog(
    MorphLabel(text="Discard changes?"),
    MorphBoxLayout(
        MorphButton(text="Cancel", on_release=lambda b: dialog.dismiss()),
        MorphButton(text="Discard", on_release=self.discard),
        orientation='horizontal',
        spacing=8,
    ),
    orientation='vertical',
    padding=24,
    spacing=16,
)

Window.add_widget(dialog)
dialog.open()

Open / Dismiss

dialog.open()    # animate in
dialog.dismiss() # animate out and remove from window

morphui.uix.dialog

Dialog widget for MorphUI.

This module provides a modal dialog component with an animated entry/exit and a semi-transparent scrim layer that appears behind the dialog to draw focus away from the underlying UI.

CLASS DESCRIPTION
MorphScrimLayer

Semi-transparent overlay rendered behind the dialog.

MorphDialog

Modal dialog container with open/dismiss animation.

MorphScrimLayer

Bases: Widget

A semi-transparent overlay that appears behind a dialog to focus the user's attention on the dialog content.

The scrim layer is typically used in conjunction with a dialog to create a visual separation between the dialog and the rest of the application interface. It helps to emphasize the dialog and reduce distractions from the background content.

color = ColorProperty([0, 0, 0, 0.5]) class-attribute instance-attribute

The color of the scrim layer, specified as a list of four float values representing the red, green, blue, and alpha (opacity) components of the color.

:attr:color is a :class:~kivy.properties.ColorProperty and defaults to [0, 0, 0, 0.5], which means the scrim will be black with 50 % opacity.

MorphDialog(*widgets, **kwargs)

Bases: MorphDialogMotionBehavior, MorphSizeBoundsBehavior, MorphElevationBoxLayout

A dialog widget that displays content in a modal overlay with a scrim layer behind it.

The :class:MorphDialog class provides a customizable dialog component that can be used to display information, prompt the user for input, or present other interactive content in a modal overlay.

The dialog includes a scrim layer that appears behind it to focus the user's attention on the dialog content and reduce distractions from the background interface.

The dialog supports animated entry and exit, and can be used in a with statement to ensure proper opening and closing.

scrim_color = AliasProperty(_get_scrim_color, _set_scrim_color, bind=['_scrim_widget']) class-attribute instance-attribute

The color of the scrim layer behind the dialog, specified as a list of four float values representing the red, green, blue, and alpha (opacity) components of the color.

:attr:scrim_color is an :class:~kivy.properties.AliasProperty that provides a convenient way to get and set the color of the scrim layer without directly accessing the internal _scrim_widget. It is bound to changes in the :attr:_scrim_widget property to ensure that updates to the scrim color are reflected in the scrim widget when it is created or updated.