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

need to call _on_visible(False) when dynamically creating menus #2

Open
goffi-contrib opened this issue Dec 24, 2016 · 1 comment
Open

Comments

@goffi-contrib
Copy link
Collaborator

Hello,

first of all thanks for your work, it's really useful :).

I use contextmenu to create dynamic menus in my application. While it's working alright when building it in kv, the ContextMenu was displayed and in a bad position with a dynamically created menu.

After some debugging, I realised that I need to call context_menu._on_visible(False) just after ContextMenu parent is set to fix it.

below is a code that reproduce the problem/workaround:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.garden.contextmenu import AppMenu, AppMenuTextItem, ContextMenu, ContextMenuTextItem


class MyApp(App):
    def build(self):
        self.title = 'Simple app menu example'
        main = BoxLayout(orientation='vertical')
        app_menu = AppMenu(size_hint=(1, None), height=30)
        for name in ['test1', 'test2', 'test3']:
            app_menu_text_item = AppMenuTextItem(text=name)
            app_menu.add_widget(app_menu_text_item)
            context_menu = ContextMenu()
            for item in ['menu1', 'menu2', 'menu3']:
                wid = ContextMenuTextItem(text=item)
                context_menu.add_widget(wid)
            app_menu_text_item.add_widget(context_menu)
            # if I don't put the next line, context_menu appear in the bottom
            # on first launch, then disappear when the app_menu is used
            context_menu._on_visible(False)
        main.add_widget(app_menu)
        main.add_widget(Label(text='test'))
        return main

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

This should be done somewhere in the code, when the parent is set for the first time.

Thanks

@martinsik
Copy link
Member

martinsik commented Jan 10, 2017

I think I understand where the problem is. The visibility is in the examples set directly in .kv. This isn't necessary for app menus but for context menus it's required which isn't ideal.
I'll have a look at it.

@AndreMiras AndreMiras transferred this issue from kivy-garden/garden.contextmenu Dec 10, 2019
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

2 participants