kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.24k stars 674 forks source link

Improvement Dialog_Box #1174

Closed Gacheur closed 2 years ago

Gacheur commented 2 years ago

Description of the Feature

Hi, I'm new user to github, I don't know if I'm in the right channel. But I'have an idea to improve the KivyMD lib. It concern The file dilog.py This function allows you to modify all item in a dialog box removing older items. The user cant just modify the list instead to re create another object. On the surface, it does not change anything, but when the app running on smartphone this can save a amount resources.

Funcion added to kivymd/uix/dialog/dialog.py

def update_items(self, ls_new_item):

    for item in self.items:
        self.ids.box_items.remove_widget(item)

    self.items = ls_new_item

    self.create_items()

App Full Code


from kivymd.app import MDApp
from kivymd.uix.button import MDFlatButton, MDRaisedButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.list import OneLineAvatarIconListItem

KV = '''

MDFloatLayout:

    MDRaisedButton:
        text: "ALERT DIALOG"
        pos_hint: {'center_x': .5, 'center_y': .5}
        on_release: app.show_confirmation_dialog()

    MDRaisedButton:
        text: "CHANGE ITEM"
        pos_hint: {'center_x': .5, 'center_y': .4}
        on_release: app.change_item_list()
'''

class Example(MDApp):
    dialog = None

    def build(self):
        return Builder.load_string(KV)

    def show_confirmation_dialog(self):

        ls_item = [
        OneLineAvatarIconListItem(text="Callisto"),
        OneLineAvatarIconListItem(text="Luna")
        ]

        if not self.dialog:
            self.dialog = MDDialog(
                title="Phone ringtone",
                type="confirmation",
                items=ls_item,
                buttons=[
                    MDFlatButton(
                        text="CANCEL",
                        theme_text_color="Custom",
                        text_color=self.theme_cls.primary_color,
                    ),
                    MDFlatButton(
                        text="OK",
                        theme_text_color="Custom",
                        text_color=self.theme_cls.primary_color,
                    ),
                ],
            )

        self.dialog.open()

    def change_item_list(self):

        ls_new_item = [
            OneLineAvatarIconListItem(text="New"),
            OneLineAvatarIconListItem(text="List")
        ]

        self.dialog.update_items(ls_new_item)

        self.dialog.open()

Example().run()

Screenshots

screen-gif

Versions

sollarp commented 2 years ago

Hi,

If you think you can add to the project and have an idea. Issue a PR (pull request ) and @HeaTTheatR will decides if your commit improves the project. Please see PR documentation for further info. https://github.com/kivymd/KivyMD#contributing