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

MDDropdownMenu Acts Incorrectly When show_duration<0.3 (With Solution) #1745

Open
Chitaoji opened this issue Oct 24, 2024 · 0 comments
Open

Comments

@Chitaoji
Copy link

MDDropdownMenu Acts Incorrectly When show_duration<0.3

I tried to create a MDDropdownMenu object with show_duration=0.0, but the result seemed funny to me (see the screenshot below).

I think i've already found the reason why this happened, which was in the class MotionDropDownMenuBehavior:

class MotionDropDownMenuBehavior(MotionBase):
    def on_open(self, *args):
        anim = Animation(
            _scale_y=1,
            duration=self.show_duration,
            transition=self.show_transition,
        )
        anim &= Animation(
            _scale_x=1,
            duration=self.show_duration - 0.3, # HERE!!
            transition="out_quad",
        )
        anim.start(self)

It seems that when duration=self.show_duration - 0.3 is less than 0, the animation will become strange and never-ending, so a single change may fix the problem:

class MotionDropDownMenuBehavior(MotionBase):
    def on_open(self, *args):
        anim = Animation(
            _scale_y=1,
            duration=self.show_duration,
            transition=self.show_transition,
        )
        anim &= Animation(
            _scale_x=1,
            duration=max(self.show_duration - 0.3, 0.0), # HERE!!
            transition="out_quad",
        )
        anim.start(self)

It works good with me, and will cause no other problems as far as I can see. But I'm not sure whether the program was meant to be like before.

Code and Logs

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu

KV = """
MDScreen:

    MDIconButton:
        id: button
        icon: "dots-vertical"
        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: app.menu_open()
"""


class Test(MDApp):
    def menu_open(self):
        menu_items = [{"text": f"Item {i}"} for i in range(5)]
        MDDropdownMenu(
            caller=self.root.ids.button, items=menu_items, show_duration=0.0
        ).open()

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


Test().run()

"""


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


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

Screenshots

c34a73a1147836b8d6d0ba78062f042

Versions

  • OS: Windows
  • Python: 3.12.7
  • Kivy: 2.3.0
  • KivyMD: 2.0.1
@Chitaoji Chitaoji changed the title MDDropdownMenu Acts Incorrectly When show_duration<0.3 MDDropdownMenu Acts Incorrectly When show_duration<0.3 (With Solution) Oct 24, 2024
chillibasket added a commit to chillibasket/KivyMD that referenced this issue Oct 26, 2024
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

1 participant