API

Usage

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
#:import SweetAlert kivymd.components.sweetalert.SweetAlert


MDScreen:

    MDRaisedButton:
        text: "EXAMPLE"
        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: SweetAlert(window_control_buttons="mac-style").fire("Message!")
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/preview-sweet-alert-example.png

API - sweetalert.sweetalert

class sweetalert.sweetalert.SweetAlert(**kwargs)

ModalView class. See module documentation for more information.

Events
on_pre_open:

Fired before the ModalView is opened. When this event is fired ModalView is not yet added to window.

on_open:

Fired when the ModalView is opened.

on_pre_dismiss:

Fired before the ModalView is closed.

on_dismiss:

Fired when the ModalView is closed. If the callback returns True, the dismiss will be canceled.

Changed in version 1.11.0: Added events on_pre_open and on_pre_dismiss.

Changed in version 2.0.0: Added property 'overlay_color'.

animation_type

Dialog appearance animation type. Available options are: 'pulse'.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-anim-pulse.gif

animation_type is an OptionProperty and defaults to 'pulse'.

font_style_title

Dialog title style.

SweetAlert(
    window_control_buttons="mac-style",
    font_style_title="H4",
).fire("Title", "Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-title-style.png

font_style_title is an OptionProperty and defaults to attr:~kivymd.font_definitions.theme_font_styles

font_style_text

Dialog text style.

SweetAlert(
    window_control_buttons="mac-style",
    font_style_text="H4",
).fire("Title", "Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-text-style.png

font_style_text is an OptionProperty and defaults to attr:~kivymd.font_definitions.theme_font_styles

Dialog footer style.

SweetAlert(
    window_control_buttons="mac-style",
    font_style_footer="H4",
).fire("Title", "Message!", "Footer")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-text-footer.png

font_style_footer is an OptionProperty and defaults to attr:~kivymd.font_definitions.theme_font_styles

font_size_button

Button font size.

SweetAlert(
    window_control_buttons="mac-style",
    font_size_button="24sp",
).fire("Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-size-button.png

font_size_button is an NumericProperty and defaults to '16sp'.

color_button

Button color.

SweetAlert(
    window_control_buttons="mac-style",
    color_button=(1, 0, 1, 1),
).fire("Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-color-button.png

color_button is an ListProperty and defaults to [].

text_color_button

Button text color.

SweetAlert(
    window_control_buttons="mac-style",
    text_color_button=(1, 0, 0, 1),
).fire("Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-text-color-button.png

text_color_button is an ListProperty and defaults to [].

position

Dialog position. Available options are: 'center', 'top-left', 'top-right', 'bottom-left', 'bottom-right'.

SweetAlert(
    window_control_buttons="mac-style",
    position="top-right",
).fire("Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-top-right.png

position is an OptionProperty and defaults to 'center'.

window_control_buttons

Type of buttons of window header.

SweetAlert(window_control_buttons="mac-style").fire("Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-window-control-buttons.png
SweetAlert(window_control_buttons="close").fire("Message!")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-close.png

window_control_buttons is an OptionProperty and defaults to None.

window_control_callback

Callback for buttons of window header.

SweetAlert(
    window_control_buttons="close",
    window_control_callback=self.callback,
).fire("Message!")
def callback(self, instance_button):
    print(instance_button)

window_control_callback is an ObjectProperty and defaults to None.

timer

Dialog closes automatically by timer.

timer is an NumericProperty and defaults to 0.

request
fire(self, title='', text='', footer='', image='', height_image='200dp', input='', buttons=None, type='')

title

SweetAlert().fire("Title")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-title.png

text

SweetAlert().fire("Title", "Text)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-title-text.png

Or without title:

SweetAlert().fire(text="Text)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-text.png

footer

SweetAlert().fire(text="Message", footer="Footer text")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-footer.png

image

SweetAlert().fire(text="Message", image="https://picsum.photos/600/400/?blur")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-image.png

input

SweetAlert().fire(text="Message", input="Input Email")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-input.png

Or combine parameters:

SweetAlert().fire(
    text="Message",
    image="https://picsum.photos/600/400/?blur",
    input="Input Email",
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-combine.png

buttons

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.button import MDRaisedButton, MDFlatButton

from kivymd.components.sweetalert import SweetAlert

KV = '''
MDScreen:

    MDRaisedButton:
        text: "EXAMPLE"
        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: app.show_dialog()
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def show_dialog(self):
        button_ok = MDRaisedButton(
            text='OK',
            font_size=16,
            on_release=self.callback,
        )
        button_cancel = MDFlatButton(
            text='CANCEL',
            font_size=16,
            on_release=self.callback,
        )
        self.alert = SweetAlert()
        self.alert.fire(
            'Your public IP', buttons=[button_ok, button_cancel],
        )

    def callback(self, instance_button):
        print(self.alert, instance_button)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-buttons.png

type:

success

SweetAlert().fire('That thing is still around?', type='question')
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-success.png

failure

SweetAlert().fire('That thing is still around?', type='failure')
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-failure.png

warning

SweetAlert().fire('That thing is still around?', type='warning')
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-warning.png

info

SweetAlert().fire('That thing is still around?', type='info')
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-info.png

question

SweetAlert().fire('That thing is still around?', type='question')
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/sweet-alert-question.png
update_width(self, *args)

Updates window width.

on_request(self, instance, value)

Adds a MDSpinner to the dialog.

add_input(self, input)
check_timer(self, timer, interval=1)
add_image(self, image, height_image)
add_buttons(self, buttons)
add_text(self, text)
add_title(self, title)
add_icon(self, type, char='', color=())
anim_open_dialog_pulse(self, *args)
anim_close_dialog_pulse(self, *args)
class sweetalert.sweetalert.CustomLabel(**kwargs)

Base class for dialog labels.

class sweetalert.sweetalert.MacOSWindowHeaderButton(**kwargs)

The base class of buttons (close/collapse/expand) that will be placed in the window header.