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.21k stars 665 forks source link

Support remove_widget() on MDListItem #1646

Closed ikus060 closed 6 months ago

ikus060 commented 6 months ago

Description of the problem

When trying to remove the MDListItemTrailingIcon from a MDListItem an exception is raised. See #1644.

Describe the algorithm of actions that leads to the problem

See #1644.

Description of Changes

Add extra condition to avoid raising KeyError.

I did not write unit test since I did not see any testing done for MDList in general.

Screenshots of the solution to the problem

N/A

Code for testing new changes

N/A

HeaTTheatR commented 6 months ago

Thanks. Also note that the bug is in two places:

https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/list/list.kv#L69 https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/list/list.kv#L78

ikus060 commented 6 months ago

@HeaTTheatR I don't see any problem on line 69. The condition is working fine with or without children.

HeaTTheatR commented 6 months ago

@HeaTTheatR I don't see any problem on line 69. The condition is working fine with or without children.

<MDListItem>
    ...

    BoxLayout:
        ...

    AnchorLayout:
        ...

        BoxLayout:
            ...

            on_children:
                if leading_container.children: \
                leading_container.children[0].pos_hint = {"top": 1} \
                if len(args[1]) == 3 else {"center_y": .5}

    BoxLayout:
        ...

        on_children:
            if text_container.children: \
            self.children[0].pos_hint = {"top": 1} \
            if len(text_container.children) == 3 else {"center_y": .5}
ikus060 commented 6 months ago

@HeaTTheatR Sorry, but you will need to be more explicit if you think there is an issue with line 69.

According to me the current condition on line 69 if leading_container.children will not lead to an exception if the container has or has no children.

On the contrary, the trailing_container boxlayout has an issue, because the on_children rule make reference to self.children[0] which is not checked upon.