KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

MDButton disable=False of disabled button fails in MDDialog

Open RobertFlatt opened this issue 4 months ago • 0 comments

Description of the Bug

In an MDDialog setting an MDButton disable=False does not enable the button.

Code and Logs

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"
'''


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

    def show_alert_dialog(self):
        self.accept_button = MDButton(
            MDButtonText(text="Accept"),

            disabled=True,
            on_release=self.is_enabled)
        
        MDDialog(
            # -----------------------Headline text-------------------------
            MDDialogHeadlineText(
                text="Button Enable Test",
            ),
            # -----------------------Supporting text-----------------------
            MDDialogSupportingText(
                text="Click left button to enable right button.\n\n"
                "Issue: Right button background gets lighter, text color does "
                "not change, right button does not respond to on_release. "
                "See print messages in terminal."
            ),
            # -----------------------Custom content------------------------
            MDDialogContentContainer(
            ),
            # ---------------------Button container------------------------
            MDDialogButtonContainer(
                Widget(),
                MDButton(
                    MDButtonText(text="Enable Other"),
                    style="elevated",
                    on_release=self.enable_other
                ),
                self.accept_button,
                spacing="8dp",
            ),
            # -------------------------------------------------------------
        ).open()

    def enable_other(self, button):
        print('old disabled state =',self.accept_button.disabled)
        self.accept_button.disabled = False
        print('new disabled state =',self.accept_button.disabled)

    def is_enabled(self, button):
        print('Is enabled =', not self.accept_button.disabled)

Example().run()

Screenshots

issue 1 before issue 1 after

Versions

  • OS: Windows 11
  • Python: 3.11.1
  • Kivy: 2.3.0
  • KivyMD: 2.0.1.dev0

RobertFlatt avatar Apr 01 '24 03:04 RobertFlatt