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()
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'.
animation_type
is anOptionProperty
and defaults to 'pulse'.
-
font_style_title
¶ Dialog title style.
SweetAlert( window_control_buttons="mac-style", font_style_title="H4", ).fire("Title", "Message!")
font_style_title
is anOptionProperty
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!")
font_style_text
is anOptionProperty
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")
font_style_footer
is anOptionProperty
and defaults to attr:~kivymd.font_definitions.theme_font_styles
Button font size.
SweetAlert( window_control_buttons="mac-style", font_size_button="24sp", ).fire("Message!")
font_size_button
is anNumericProperty
and defaults to '16sp'.
Button color.
SweetAlert( window_control_buttons="mac-style", color_button=(1, 0, 1, 1), ).fire("Message!")
color_button
is anListProperty
and defaults to [].
Button text color.
SweetAlert( window_control_buttons="mac-style", text_color_button=(1, 0, 0, 1), ).fire("Message!")
text_color_button
is anListProperty
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!")
position
is anOptionProperty
and defaults to 'center'.
Type of buttons of window header.
SweetAlert(window_control_buttons="mac-style").fire("Message!")
SweetAlert(window_control_buttons="close").fire("Message!")
window_control_buttons
is anOptionProperty
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 anObjectProperty
and defaults to None.
-
timer
¶ Dialog closes automatically by timer.
timer
is anNumericProperty
and defaults to 0.
-
request
¶
-
fire
(self, title='', text='', footer='', image='', height_image='200dp', input='', buttons=None, type='')¶ title
SweetAlert().fire("Title")
text
SweetAlert().fire("Title", "Text)
Or without title:
SweetAlert().fire(text="Text)
footer
SweetAlert().fire(text="Message", footer="Footer text")
image
SweetAlert().fire(text="Message", image="https://picsum.photos/600/400/?blur")
input
SweetAlert().fire(text="Message", input="Input Email")
Or combine parameters:
SweetAlert().fire( text="Message", image="https://picsum.photos/600/400/?blur", input="Input Email", )
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()
type:
success
SweetAlert().fire('That thing is still around?', type='question')
failure
SweetAlert().fire('That thing is still around?', type='failure')
warning
SweetAlert().fire('That thing is still around?', type='warning')
info
SweetAlert().fire('That thing is still around?', type='info')
question
SweetAlert().fire('That thing is still around?', type='question')
-
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_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.