Open HackXIt opened 1 month ago
In regards to the other problems you mentioned about MDDialog, it works perfectly fine for the ExitDialog:
Have a look at modules/dialog/exitdialog.kv
.
PLEASE NOTE
loaddialog.kv
and savedialog.kv
are DEPRECATED.
I am using Filemanager of KivyMD directly in the application main_screen.py
to load/save from/to a file.
def __init__(self, title: str, **kwargs):
super(MainScreen, self).__init__(**kwargs)
# self.file_load_popup = loaddialog.LoadDialog(callback=self.load_textfile, title="Load file", size_hint=(0.9, 0.9))
# # self.file_load_popup.size = (400, 400)
# self.file_save_popup = savedialog.SaveDialog(callback=self.save_textfile, title="Save file", size_hint=(0.9, 0.9))
# # self.file_save_popup.size = (400, 400)
# self.settings_popup = app_settings.AppSettingsPopup()
self.title = title
self.last_path = None
self.opened_file = None
# FIXME This is used to keep track of the file manager state (open or closed) but is not currently used
self.manager_open = False
self.file_manager = MDFileManager(
exit_manager=self.exit_manager,
select_path=self.select_path,
icon_selection_button="folder-marker"
)
def on_load_file(self):
if self.last_path is not None:
path = self.last_path
else:
path = os.path.expanduser("~")
self.file_manager.show(path)
self.manager_open = True
Text is not a valid property for the MDDialog directly. MDDialog is just a class for handling everything around it.
Title is valid for MDDialog.
If you want to use text it must be on one of the children of the created MDDialog, as highlighted in the documentation:
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivymd.app import MDApp
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,
)
KV = '''
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
MDButton:
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.show_alert_dialog()
MDButtonText:
text: "Show dialog" # <--- text is VALID here
'''
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
def show_alert_dialog(self):
MDDialog( # <--- text is NOT VALID here
# ----------------------------Icon-----------------------------
MDDialogIcon(
icon="refresh",
),
# -----------------------Headline text-------------------------
MDDialogHeadlineText(
text="Reset settings?", # <--- text is VALID here
),
# -----------------------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", # <--- text is VALID here
),
theme_bg_color="Custom",
md_bg_color=self.theme_cls.transparentColor,
),
MDListItem(
MDListItemLeadingIcon(
icon="gmail",
),
MDListItemSupportingText(
text="kivydevelopment@gmail.com", # <--- text is VALID here
),
theme_bg_color="Custom",
md_bg_color=self.theme_cls.transparentColor,
),
MDDivider(),
orientation="vertical",
),
# ---------------------Button container------------------------
MDDialogButtonContainer(
Widget(),
MDButton(
MDButtonText(text="Cancel"), # <--- text is VALID here
style="text",
),
MDButton(
MDButtonText(text="Accept"), # <--- text is VALID here
style="text",
),
spacing="8dp",
),
# -------------------------------------------------------------
).open()
Example().run()
You need to think about the KivyMD components in terms of Lego pieces.
MDDialog is just one part of the building, if you want text, you need to put that into a button, label or something, and then put that widget INTO the dialog, which then displays the text.
The Dialog component only handles the "temporary window/screen" that is opened to display a seperate portion of UI elevated from the actual application. It's functionality comes from all the handlers it provides and the mechanisms such as open and dismiss. To use 'text' or any other property that correspond to specific widgets, you need to place those widgets into the dialog in a hierarchical manner.
To highlight it more clearly based on your example:
def select_voice(self, voice_name):
# Verwerk de geselecteerde stemnaam
log.info("%s: Selected voice: %s", self.__class__.__name__, voice_name)
# Je kunt hier verdere acties ondernemen, zoals het instellen van de geselecteerde stem in de API
# TODO: Popup: you have selected this voice
if not self.voice_dialog:
self.voice_dialog = MDDialog(
MDLabel(text="Hello World")
)
self.voice_dialog.open()
...
In regard to commit: a2902de