2024-09-15 12:12:16 +00:00
|
|
|
"""
|
|
|
|
Components/Dialog
|
|
|
|
=================
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
`Material Design spec, Dialogs <https://m3.material.io/components/dialogs/overview>`_
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. rubric:: Dialogs provide important prompts in a user flow.
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-preview.png
|
2024-09-15 12:12:16 +00:00
|
|
|
:align: center
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
- Use dialogs to make sure users act on information
|
|
|
|
- Two types: basic and full-screen (full-screen not provided in KivyMD)
|
|
|
|
- Should be dedicated to completing a single task
|
|
|
|
- Can also display information relevant to the task
|
|
|
|
- Commonly used to confirm high-risk actions like deleting progress
|
|
|
|
|
|
|
|
Anatomy
|
|
|
|
=======
|
|
|
|
|
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-anatomy.png
|
|
|
|
:align: center
|
|
|
|
|
|
|
|
Example
|
|
|
|
=======
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
from kivy.lang import Builder
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
from kivymd.app import MDApp
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd.uix.button import MDButton, MDButtonText
|
|
|
|
from kivymd.uix.dialog import (
|
|
|
|
MDDialog,
|
|
|
|
MDDialogIcon,
|
|
|
|
MDDialogHeadlineText,
|
|
|
|
MDDialogSupportingText,
|
|
|
|
MDDialogButtonContainer,
|
|
|
|
MDDialogContentContainer,
|
|
|
|
)
|
|
|
|
from kivymd.uix.divider import MDDivider
|
|
|
|
from kivymd.uix.list import (
|
|
|
|
MDListItem,
|
|
|
|
MDListItemLeadingIcon,
|
|
|
|
MDListItemSupportingText,
|
|
|
|
)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
KV = '''
|
2024-09-15 17:57:02 +00:00
|
|
|
MDScreen:
|
|
|
|
md_bg_color: self.theme_cls.backgroundColor
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
MDButton:
|
2024-09-15 12:12:16 +00:00
|
|
|
pos_hint: {'center_x': .5, 'center_y': .5}
|
|
|
|
on_release: app.show_alert_dialog()
|
2024-09-15 17:57:02 +00:00
|
|
|
|
|
|
|
MDButtonText:
|
|
|
|
text: "Show dialog"
|
2024-09-15 12:12:16 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
return Builder.load_string(KV)
|
|
|
|
|
|
|
|
def show_alert_dialog(self):
|
2024-09-15 17:57:02 +00:00
|
|
|
MDDialog(
|
|
|
|
# ----------------------------Icon-----------------------------
|
|
|
|
MDDialogIcon(
|
|
|
|
icon="refresh",
|
|
|
|
),
|
|
|
|
# -----------------------Headline text-------------------------
|
|
|
|
MDDialogHeadlineText(
|
|
|
|
text="Reset settings?",
|
|
|
|
),
|
|
|
|
# -----------------------Supporting text-----------------------
|
|
|
|
MDDialogSupportingText(
|
|
|
|
text="This will reset your app preferences back to their "
|
|
|
|
"default settings. The following accounts will also "
|
|
|
|
"be signed out:",
|
|
|
|
),
|
|
|
|
# -----------------------Custom content------------------------
|
|
|
|
MDDialogContentContainer(
|
|
|
|
MDDivider(),
|
|
|
|
MDListItem(
|
|
|
|
MDListItemLeadingIcon(
|
|
|
|
icon="gmail",
|
|
|
|
),
|
|
|
|
MDListItemSupportingText(
|
|
|
|
text="KivyMD-library@yandex.com",
|
|
|
|
),
|
|
|
|
theme_bg_color="Custom",
|
|
|
|
md_bg_color=self.theme_cls.transparentColor,
|
|
|
|
),
|
|
|
|
MDListItem(
|
|
|
|
MDListItemLeadingIcon(
|
|
|
|
icon="gmail",
|
2024-09-15 12:12:16 +00:00
|
|
|
),
|
2024-09-15 17:57:02 +00:00
|
|
|
MDListItemSupportingText(
|
|
|
|
text="kivydevelopment@gmail.com",
|
2024-09-15 12:12:16 +00:00
|
|
|
),
|
2024-09-15 17:57:02 +00:00
|
|
|
theme_bg_color="Custom",
|
|
|
|
md_bg_color=self.theme_cls.transparentColor,
|
|
|
|
),
|
|
|
|
MDDivider(),
|
|
|
|
orientation="vertical",
|
|
|
|
),
|
|
|
|
# ---------------------Button container------------------------
|
|
|
|
MDDialogButtonContainer(
|
|
|
|
Widget(),
|
|
|
|
MDButton(
|
|
|
|
MDButtonText(text="Cancel"),
|
|
|
|
style="text",
|
|
|
|
),
|
|
|
|
MDButton(
|
|
|
|
MDButtonText(text="Accept"),
|
|
|
|
style="text",
|
|
|
|
),
|
|
|
|
spacing="8dp",
|
|
|
|
),
|
|
|
|
# -------------------------------------------------------------
|
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
Example().run()
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-example.gif
|
2024-09-15 12:12:16 +00:00
|
|
|
:align: center
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. warning:: Do not try to use the MDDialog widget in KV files.
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
API break
|
|
|
|
=========
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
1.2.0 version
|
|
|
|
-------------
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. code-block:: python
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd.app import MDApp
|
|
|
|
from kivymd.uix.button import MDFlatButton
|
|
|
|
from kivymd.uix.dialog import MDDialog
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
return Widget()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_start(self):
|
|
|
|
MDDialog(
|
|
|
|
title="Discard draft?",
|
2024-09-15 12:12:16 +00:00
|
|
|
buttons=[
|
|
|
|
MDFlatButton(
|
|
|
|
text="CANCEL",
|
|
|
|
theme_text_color="Custom",
|
|
|
|
text_color=self.theme_cls.primary_color,
|
|
|
|
),
|
|
|
|
MDFlatButton(
|
2024-09-15 17:57:02 +00:00
|
|
|
text="DISCARD",
|
2024-09-15 12:12:16 +00:00
|
|
|
theme_text_color="Custom",
|
|
|
|
text_color=self.theme_cls.primary_color,
|
|
|
|
),
|
|
|
|
],
|
2024-09-15 17:57:02 +00:00
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
Example().run()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-api-break-1-2-0.png
|
|
|
|
:align: center
|
|
|
|
|
|
|
|
.. code-block:: python
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd.app import MDApp
|
|
|
|
from kivymd.uix.button import MDFlatButton
|
|
|
|
from kivymd.uix.dialog import MDDialog
|
|
|
|
|
|
|
|
|
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
return Widget()
|
|
|
|
|
|
|
|
def on_start(self):
|
|
|
|
MDDialog(
|
|
|
|
title="Discard draft?",
|
2024-09-15 12:12:16 +00:00
|
|
|
text="This will reset your device to its default factory settings.",
|
|
|
|
buttons=[
|
|
|
|
MDFlatButton(
|
|
|
|
text="CANCEL",
|
|
|
|
theme_text_color="Custom",
|
|
|
|
text_color=self.theme_cls.primary_color,
|
|
|
|
),
|
|
|
|
MDFlatButton(
|
2024-09-15 17:57:02 +00:00
|
|
|
text="DISCARD",
|
2024-09-15 12:12:16 +00:00
|
|
|
theme_text_color="Custom",
|
|
|
|
text_color=self.theme_cls.primary_color,
|
|
|
|
),
|
|
|
|
],
|
2024-09-15 17:57:02 +00:00
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
Example().run()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/2-dialog-api-break-1-2-0.png
|
|
|
|
:align: center
|
|
|
|
|
|
|
|
.. code-block:: python
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.lang import Builder
|
|
|
|
from kivy.properties import StringProperty
|
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd import images_path
|
|
|
|
from kivymd.app import MDApp
|
|
|
|
from kivymd.uix.dialog import MDDialog
|
|
|
|
from kivymd.uix.list import OneLineAvatarListItem
|
|
|
|
|
|
|
|
KV = '''
|
|
|
|
<Item>
|
|
|
|
|
|
|
|
ImageLeftWidget:
|
|
|
|
source: root.source
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class Item(OneLineAvatarListItem):
|
|
|
|
divider = None
|
|
|
|
source = StringProperty()
|
|
|
|
|
|
|
|
|
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
Builder.load_string(KV)
|
|
|
|
return Widget()
|
|
|
|
|
|
|
|
def on_start(self):
|
|
|
|
MDDialog(
|
|
|
|
title="Set backup account",
|
|
|
|
type="simple",
|
|
|
|
items=[
|
|
|
|
Item(text="user01@gmail.com", source=f"{images_path}/logo/kivymd-icon-128.png"),
|
|
|
|
Item(text="user02@gmail.com", source="data/logo/kivy-icon-128.png"),
|
2024-09-15 12:12:16 +00:00
|
|
|
],
|
2024-09-15 17:57:02 +00:00
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
Example().run()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/3-dialog-api-break-1-2-0.png
|
|
|
|
:align: center
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
2.2.0 version
|
|
|
|
-------------
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. code-block:: python
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd.uix.widget import MDWidget
|
|
|
|
from kivymd.app import MDApp
|
|
|
|
from kivymd.uix.button import MDButton, MDButtonText
|
|
|
|
from kivymd.uix.dialog import MDDialog, MDDialogHeadlineText, MDDialogButtonContainer
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
return MDWidget(md_bg_color=self.theme_cls.backgroundColor)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_start(self):
|
|
|
|
MDDialog(
|
|
|
|
MDDialogHeadlineText(
|
|
|
|
text="Discard draft?",
|
|
|
|
halign="left",
|
|
|
|
),
|
|
|
|
MDDialogButtonContainer(
|
|
|
|
Widget(),
|
|
|
|
MDButton(
|
|
|
|
MDButtonText(text="Cancel"),
|
|
|
|
style="text",
|
|
|
|
),
|
|
|
|
MDButton(
|
|
|
|
MDButtonText(text="Discard"),
|
|
|
|
style="text",
|
|
|
|
),
|
|
|
|
spacing="8dp",
|
|
|
|
),
|
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
Example().run()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-api-break-2-2-0.png
|
|
|
|
:align: center
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. code-block:: python
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd.uix.widget import MDWidget
|
|
|
|
from kivymd.app import MDApp
|
|
|
|
from kivymd.uix.button import MDButton, MDButtonText
|
|
|
|
from kivymd.uix.dialog import MDDialog, MDDialogHeadlineText, MDDialogButtonContainer
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
return MDWidget(md_bg_color=self.theme_cls.backgroundColor)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_start(self):
|
|
|
|
MDDialog(
|
|
|
|
MDDialogHeadlineText(
|
|
|
|
text="Discard draft?",
|
|
|
|
halign="left",
|
|
|
|
),
|
|
|
|
MDDialogSupportingText(
|
|
|
|
text="This will reset your device to its default factory settings.",
|
|
|
|
halign="left",
|
|
|
|
),
|
|
|
|
MDDialogButtonContainer(
|
|
|
|
Widget(),
|
|
|
|
MDButton(
|
|
|
|
MDButtonText(text="Cancel"),
|
|
|
|
style="text",
|
|
|
|
),
|
|
|
|
MDButton(
|
|
|
|
MDButtonText(text="Discard"),
|
|
|
|
style="text",
|
|
|
|
),
|
|
|
|
spacing="8dp",
|
|
|
|
),
|
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
Example().run()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/2-dialog-api-break-2-2-0.png
|
|
|
|
:align: center
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
from kivymd import images_path
|
|
|
|
from kivymd.uix.widget import MDWidget
|
|
|
|
from kivymd.app import MDApp
|
|
|
|
from kivymd.uix.dialog import (
|
|
|
|
MDDialog,
|
|
|
|
MDDialogHeadlineText,
|
|
|
|
MDDialogContentContainer,
|
|
|
|
)
|
|
|
|
from kivymd.uix.list import (
|
|
|
|
MDListItem,
|
|
|
|
MDListItemLeadingAvatar,
|
|
|
|
MDListItemSupportingText,
|
|
|
|
)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
class Example(MDApp):
|
|
|
|
def build(self):
|
|
|
|
return MDWidget(md_bg_color=self.theme_cls.backgroundColor)
|
|
|
|
|
|
|
|
def on_start(self):
|
|
|
|
MDDialog(
|
|
|
|
MDDialogHeadlineText(
|
|
|
|
text="Set backup account",
|
|
|
|
halign="left",
|
|
|
|
),
|
|
|
|
MDDialogContentContainer(
|
|
|
|
MDListItem(
|
|
|
|
MDListItemLeadingAvatar(
|
|
|
|
source=f"{images_path}/logo/kivymd-icon-128.png",
|
|
|
|
),
|
|
|
|
MDListItemSupportingText(
|
|
|
|
text="user01@gmail.com",
|
|
|
|
),
|
|
|
|
theme_bg_color="Custom",
|
|
|
|
md_bg_color=self.theme_cls.transparentColor,
|
|
|
|
),
|
|
|
|
MDListItem(
|
|
|
|
MDListItemLeadingAvatar(
|
|
|
|
source="data/logo/kivy-icon-128.png",
|
|
|
|
),
|
|
|
|
MDListItemSupportingText(
|
|
|
|
text="user01@gmail.com",
|
|
|
|
),
|
|
|
|
theme_bg_color="Custom",
|
|
|
|
md_bg_color=self.theme_cls.transparentColor,
|
|
|
|
),
|
|
|
|
orientation="vertical",
|
|
|
|
),
|
|
|
|
).open()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
Example().run()
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/3-dialog-api-break-2-2-0.png
|
|
|
|
:align: center
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
"""
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
__all__ = [
|
|
|
|
"MDDialog",
|
|
|
|
"MDDialogIcon",
|
|
|
|
"MDDialogHeadlineText",
|
|
|
|
"MDDialogSupportingText",
|
|
|
|
"MDDialogContentContainer",
|
|
|
|
"MDDialogButtonContainer",
|
|
|
|
]
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
import os
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivy.core.window import Window
|
|
|
|
from kivy.lang import Builder
|
|
|
|
from kivy.metrics import dp
|
|
|
|
from kivy.properties import (
|
|
|
|
VariableListProperty,
|
|
|
|
NumericProperty,
|
|
|
|
ColorProperty,
|
|
|
|
ObjectProperty,
|
|
|
|
BooleanProperty,
|
|
|
|
)
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.widget import Widget
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
from kivymd.uix.card import MDCard
|
|
|
|
from kivymd.uix.label import MDIcon, MDLabel
|
|
|
|
from kivymd import uix_path
|
|
|
|
from kivymd.material_resources import DEVICE_TYPE
|
|
|
|
from kivymd.uix.behaviors import MotionDialogBehavior, DeclarativeBehavior
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(uix_path, "dialog", "dialog.kv"), encoding="utf-8"
|
|
|
|
) as kv_file:
|
|
|
|
Builder.load_string(kv_file.read())
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
class MDDialog(MDCard, MotionDialogBehavior):
|
|
|
|
"""
|
|
|
|
Dialog class.
|
|
|
|
|
|
|
|
For more information, see in the
|
|
|
|
:class:`~kivymd.uix.card.card.MDCard` and
|
|
|
|
:class:`~kivymd.uix.behaviors.motion_behavior.MotionDialogBehavior`
|
|
|
|
classes documentation.
|
|
|
|
|
|
|
|
:Events:
|
|
|
|
`on_pre_open`:
|
|
|
|
Fired before the MDDialog is opened. When this event is fired
|
|
|
|
MDDialog is not yet added to window.
|
|
|
|
`on_open`:
|
|
|
|
Fired when the MDDialog is opened.
|
|
|
|
`on_pre_dismiss`:
|
|
|
|
Fired before the MDDialog is closed.
|
|
|
|
`on_dismiss`:
|
|
|
|
Fired when the MDDialog is closed. If the callback returns True,
|
|
|
|
the dismiss will be canceled.
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
width_offset = NumericProperty(dp(48))
|
|
|
|
"""
|
|
|
|
Dialog offset from device width.
|
|
|
|
|
|
|
|
:attr:`width_offset` is an :class:`~kivy.properties.NumericProperty`
|
|
|
|
and defaults to `dp(48)`.
|
|
|
|
"""
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
radius = VariableListProperty(dp(28), lenght=4)
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
2024-09-15 17:57:02 +00:00
|
|
|
Dialog corners rounding value.
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
:attr:`radius` is an :class:`~kivy.properties.VariableListProperty`
|
|
|
|
and defaults to `[dp(28), dp(28), dp(28), dp(28)]`.
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
scrim_color = ColorProperty([0, 0, 0, 0.5])
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
2024-09-15 17:57:02 +00:00
|
|
|
Color for scrim in (r, g, b, a) or string format.
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
:attr:`scrim_color` is a :class:`~kivy.properties.ColorProperty`
|
|
|
|
and defaults to `[0, 0, 0, 0.5]`.
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
auto_dismiss = BooleanProperty(True)
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
2024-09-15 17:57:02 +00:00
|
|
|
This property determines if the dialog is automatically
|
|
|
|
dismissed when the user clicks outside it.
|
|
|
|
|
|
|
|
..versionadded:: 2.0.0
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
:attr:`auto_dismiss` is a :class:`~kivy.properties.BooleanProperty` and
|
|
|
|
defaults to True.
|
2024-09-15 12:12:16 +00:00
|
|
|
"""
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
_scrim = ObjectProperty() # kivymd.uix.dialog.dialog.MDDialogScrim object
|
|
|
|
_is_open = False # is the dialog currently open or closed.
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.register_event_type("on_open")
|
|
|
|
self.register_event_type("on_pre_open")
|
|
|
|
self.register_event_type("on_dismiss")
|
|
|
|
self.register_event_type("on_pre_dismiss")
|
|
|
|
self.opacity = 0
|
2024-09-15 12:12:16 +00:00
|
|
|
Window.bind(on_resize=self.update_width)
|
|
|
|
|
|
|
|
def update_width(self, *args) -> None:
|
2024-09-15 17:57:02 +00:00
|
|
|
self.size_hint_max_x = max(
|
|
|
|
self.width_offset,
|
2024-09-15 12:12:16 +00:00
|
|
|
min(
|
|
|
|
dp(560) if DEVICE_TYPE != "mobile" else dp(280),
|
|
|
|
Window.width - self.width_offset,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def add_widget(self, widget, *args, **kwargs):
|
|
|
|
if isinstance(widget, MDDialogIcon):
|
|
|
|
self.ids.icon_container.add_widget(widget)
|
|
|
|
elif isinstance(widget, MDDialogHeadlineText):
|
|
|
|
self.ids.headline_container.add_widget(widget)
|
|
|
|
elif isinstance(widget, MDDialogSupportingText):
|
|
|
|
self.ids.supporting_text_container.add_widget(widget)
|
|
|
|
elif isinstance(widget, MDDialogContentContainer):
|
|
|
|
self.ids.content_container.add_widget(widget)
|
|
|
|
elif isinstance(widget, MDDialogButtonContainer):
|
|
|
|
self.ids.button_container.add_widget(widget)
|
|
|
|
else:
|
|
|
|
return super().add_widget(widget)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def open(self) -> None:
|
|
|
|
"""Show the dialog."""
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
if self._is_open:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.dispatch("on_pre_open")
|
|
|
|
self._is_open = True
|
|
|
|
|
|
|
|
if not self._scrim:
|
|
|
|
self._scrim = MDDialogScrim(color=self.scrim_color)
|
|
|
|
|
|
|
|
Window.add_widget(self._scrim)
|
|
|
|
Window.add_widget(self)
|
2024-09-15 12:12:16 +00:00
|
|
|
super().on_open()
|
2024-09-15 17:57:02 +00:00
|
|
|
self.dispatch("on_open")
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_pre_open(self, *args) -> None:
|
|
|
|
"""Fired when a dialog pre opened."""
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_open(self, *args) -> None:
|
|
|
|
"""Fired when a dialog opened."""
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_dismiss(self, *args) -> None:
|
|
|
|
"""Fired when a dialog dismiss."""
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
def on_pre_dismiss(self, *args) -> None:
|
|
|
|
"""Fired when a dialog pre-dismiss."""
|
|
|
|
|
|
|
|
def on_touch_down(self, touch):
|
|
|
|
if not self.collide_point(*touch.pos) and self.auto_dismiss:
|
|
|
|
self.dismiss()
|
|
|
|
return True
|
|
|
|
super().on_touch_down(touch)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def dismiss(self, *args) -> None:
|
|
|
|
"""Closes the dialog."""
|
|
|
|
|
|
|
|
self.dispatch("on_pre_dismiss")
|
|
|
|
super().on_dismiss()
|
|
|
|
self._is_open = False
|
|
|
|
self.dispatch("on_dismiss")
|
|
|
|
|
|
|
|
|
|
|
|
class MDDialogIcon(MDIcon):
|
|
|
|
"""
|
|
|
|
The class implements an icon.
|
|
|
|
|
|
|
|
For more information, see in the
|
|
|
|
:class:`~kivymd.uix.label.label.MDIcon` class documentation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class MDDialogHeadlineText(MDLabel):
|
|
|
|
"""
|
|
|
|
The class implements the headline text.
|
|
|
|
|
|
|
|
For more information, see in the
|
|
|
|
:class:`~kivymd.uix.label.label.MDLabel` class documentation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class MDDialogSupportingText(MDLabel):
|
|
|
|
"""
|
|
|
|
The class implements the supporting text.
|
|
|
|
|
|
|
|
For more information, see in the
|
|
|
|
:class:`~kivymd.uix.label.label.MDLabel` class documentation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class MDDialogContentContainer(DeclarativeBehavior, BoxLayout):
|
|
|
|
"""
|
|
|
|
The class implements the container for custom widgets.
|
|
|
|
|
|
|
|
For more information, see in the
|
|
|
|
:class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
|
|
|
|
:class:`~kivy.uix.boxlayout.BoxLayout` classes documentation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class MDDialogButtonContainer(DeclarativeBehavior, BoxLayout):
|
|
|
|
"""
|
|
|
|
The class implements a container for placing dialog buttons.
|
|
|
|
|
|
|
|
For more information, see in the
|
|
|
|
:class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
|
|
|
|
:class:`~kivy.uix.boxlayout.BoxLayout` classes documentation.
|
|
|
|
"""
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
class MDDialogScrim(Widget):
|
|
|
|
color = ColorProperty(None)
|
|
|
|
alpha = NumericProperty(0)
|