generated from kivy-garden/flower
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels