Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable MDListItem raise an exception #1651

Closed
ikus060 opened this issue Mar 14, 2024 · 1 comment
Closed

Enable/Disable MDListItem raise an exception #1651

ikus060 opened this issue Mar 14, 2024 · 1 comment

Comments

@ikus060
Copy link
Contributor

ikus060 commented Mar 14, 2024

Description of the Bug

When trying to disable an MDListItem, an exception is raised.

Code and Logs

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp

KV = '''
<MyView>:

    MDBoxLayout:
        orientation: 'vertical'

        Button:
            text: "Toggle"
            on_release: root.toggle()

        MDListItem:
            id: item

            MDListItemHeadlineText:
                text: "Headline"

            MDListItemSupportingText:
                text: "Supporting text"

MDScreen:

    MDBoxLayout:
        id: content

        MyView:
'''

class MyView(BoxLayout):
    _trailing_icon = None

    def toggle(self):
        self.ids.item.disabled = not self.ids.item.disabled

class Example(MDApp):

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

"""


class MainApp(App):
    def build(self):
        self.root = Builder.load_string(kv)


if __name__ == '__main__':
    MainApp().run()

The exception getting raised:

   File "/home/ikus060/Downloads/test_listitem.py", line 36, in toggle
     self.ids.item.disabled = not self.ids.item.disabled
   File "kivy/weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
   File "kivy/properties.pyx", line 520, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 1662, in kivy.properties.AliasProperty.set
   File "/home/ikus060/workspace/PDSL/minarca.git/.venv/lib/python3.10/site-packages/kivy/uix/widget.py", line 1573, in set_disabled
     self.inc_disabled()
   File "/home/ikus060/workspace/PDSL/minarca.git/.venv/lib/python3.10/site-packages/kivy/uix/widget.py", line 1581, in inc_disabled
     self.property('disabled').dispatch(self)
   File "kivy/properties.pyx", line 608, in kivy.properties.Property.dispatch
   File "kivy/properties.pyx", line 625, in kivy.properties.Property.dispatch
   File "kivy/properties.pyx", line 1672, in kivy.properties.AliasProperty._dispatch
   File "kivy/_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1189, in kivy._event.EventObservers._dispatch
   File "/home/ikus060/workspace/PDSL/minarca.git/.venv/lib/python3.10/site-packages/kivy/lang/builder.py", line 60, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "<string>", line 52, in <module>
 IndexError: list index out of range

Screenshots

N/A

Versions

  • OS: Linux
  • Python: 3.10.12
  • Kivy: 2.3.0
  • KivyMD: 2.0.1.dev0
@cdavidson-project-canary
Copy link

cdavidson-project-canary commented Apr 10, 2024

My temporary workaround for this issue:
myMDListItem.ids.leading_container.add_widget(MDWidget())

Explanation: This prevents the index of out of range error by ensuring the leading_container layout has at least one child. This doesn't impact the appearance of the MDListItem in any noticeable way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants