kivy / kivy

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS
https://kivy.org
MIT License
17k stars 3.04k forks source link

Label widget draw using the 'color' instead of 'disabled_color' #8660

Closed ikus060 closed 1 month ago

ikus060 commented 1 month ago

Software Versions

Describe the bug The color of label are not properly manage in regard to disable_color vs color.

If the "color" get updated when the widget is disabled, then the label is draw using the "color" value instead of using the "disabled_color" value.

Expected behavior When a label is disabled, it should always be draw using the disabled_color.

To Reproduce

from kivy.lang import Builder
from kivy.properties import ColorProperty
from kivymd.uix.screen import MDScreen
from kivymd.app import MDApp
from kivy.clock import Clock

Builder.load_string(
    '''
<MyScreen>
    BoxLayout:

        Label:
            text: "This is my enabled Text"
            color: root.text_color
            disabled_color: root.disabled_color

        Label:
            text: "This is my disabled Text should be Red"
            color: root.text_color
            disabled_color: root.disabled_color
            disabled: True

'''
)

class MyScreen(MDScreen):
    text_color = ColorProperty()
    disabled_color = ColorProperty()

    def __init__(self, *args, **kwargs):
        self.text_color = [1,1,1,1] # White
        self.disabled_color = [1,0,0,1] # Red
        super().__init__(*args, **kwargs)
        Clock.schedule_once(lambda dt: self._update_text_color(), 0.2)

    def _update_text_color(self):
        self.text_color = [1,1,0,1] # Yellow

class MainApp(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = MyScreen()

    def build(self):
        return self.screen

MainApp().run()

image

Additional context Add any other context about the problem here.

Problem seams located in label.py. A special condition should be added to avoid replacing the 'color' if the widget is disabled.

I suspect a similar issue with Button too.

ikus060 commented 1 month ago

@ElliotGarbus Did write a response to this ticket and then deleted it ? I got an email, but then your response is not here anymore.

ElliotGarbus commented 1 month ago

Yes, I wrote a response - then realized I misunderstood the issue, and deleted it.

ikus060 commented 1 month ago

Ok.

Could I propose a fix for 2.3.0 branch ?

ElliotGarbus commented 1 month ago

You don't need my permission, just issue a PR.