KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

'ThemeManager' object has no attribute 'primary_dark'

Open akoslaczko opened this issue 5 months ago • 1 comments

Description of the Bug

When you try to use the MDToggleButton mixin class the code breaks with the titular AttributeError. The example code in the documentation breaks as well:

Code and Logs

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDButton

KV = '''
MDScreen:

    MDBoxLayout:
        adaptive_size: True
        spacing: "12dp"
        pos_hint: {"center_x": .5, "center_y": .5}

        MyToggleButton:
            text: "Show ads"
            group: "x"

        MyToggleButton:
            text: "Do not show ads"
            group: "x"

        MyToggleButton:
            text: "Does not matter"
            group: "x"
'''


class MyToggleButton(MDButton, MDToggleButton):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.background_down = self.theme_cls.primary_color


class Test(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"
        return Builder.load_string(KV)


Test().run()

 Traceback (most recent call last):
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivy/lang/builder.py", line 412, in load_string
     self._apply_rule(
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivy/lang/builder.py", line 667, in _apply_rule
     self._apply_rule(
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivy/lang/builder.py", line 663, in _apply_rule
     child = cls(__no_builder=True)
   File "/home/akkus/DEV/Projects/material-chess-clock/test.py", line 31, in __init__
     super().__init__(*args, **kwargs)
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivymd/uix/button/button.py", line 949, in __init__
     super().__init__(*args, **kwargs)
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivymd/uix/behaviors/declarative_behavior.py", line 312, in __init__
     super().__init__(**kwargs)
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivymd/uix/behaviors/backgroundcolor_behavior.py", line 164, in __init__
     super().__init__(**kwarg)
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivymd/uix/behaviors/toggle_behavior.py", line 248, in __init__
     super().__init__(**kwargs)
   File "/home/akkus/DEV/Projects/material-chess-clock/venv/lib/python3.10/site-packages/kivymd/uix/behaviors/toggle_behavior.py", line 205, in __init__
     self.theme_cls.primary_dark
 AttributeError: 'ThemeManager' object has no attribute 'primary_dark'

Versions

  • OS: Kubuntu 22.04
  • Python: 3.10
  • Kivy: 2.3.0
  • KivyMD: 2.0.1.dev0

akoslaczko avatar Feb 12 '24 16:02 akoslaczko