Mercurial > libervia-desktop-kivy
diff cagou/core/menu.py @ 373:5d994be1161b
core: removed root menus (i.e. global menu on top of window):
root menus were not really useful as most actions doable there are doable through others
widgets in Cagou. For actions without equivalent in widgets (like about screen), a new
menu, more discreet, will be added soon.
Kivy Garden's ContextMenu is not used anymore, so it has been removed from dependencies
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 27 Jan 2020 21:17:09 +0100 |
parents | 9c6fe392d623 |
children | 9ef01266e3fe |
line wrap: on
line diff
--- a/cagou/core/menu.py Mon Jan 27 21:17:08 2020 +0100 +++ b/cagou/core/menu.py Mon Jan 27 21:17:09 2020 +0100 @@ -27,8 +27,7 @@ from kivy.uix.popup import Popup from cagou.core.utils import FilterBehavior from kivy import properties -from kivy_garden import contextmenu, modernmenu -from sat_frontends.quick_frontend import quick_menus +from kivy_garden import modernmenu from kivy.core.window import Window from kivy.animation import Animation from kivy.metrics import dp @@ -70,115 +69,6 @@ return super(AboutPopup, self).on_touch_down(touch) -class MainMenu(contextmenu.AppMenu): - pass - - -class MenuItem(contextmenu.ContextMenuTextItem): - item = properties.ObjectProperty() - - def on_item(self, instance, item): - self.text = item.name - - def on_release(self): - super(MenuItem, self).on_release() - self.parent.hide() - selected = G.host.selected_widget - profile = None - if selected is not None: - try: - # FIXME: handle multi-profiles - profile = next(iter(selected.profiles)) - except AttributeError: - pass - - if profile is None: - try: - profile = list(selected.profiles)[0] - except (AttributeError, IndexError): - try: - profile = list(G.host.profiles)[0] - except IndexError: - log.warning("Can't find profile") - self.item.call(selected, profile) - - -class MenuSeparator(contextmenu.ContextMenuDivider): - pass - - -class RootMenuContainer(contextmenu.AppMenuTextItem): - pass - - -class MenuContainer(contextmenu.ContextMenuTextItem): - pass - - -class MenusWidget(BoxLayout): - - def update(self, type_, caller=None): - """Method to call when menus have changed - - @param type_(unicode): menu type like in sat.core.sat_main.importMenu - @param caller(Widget): instance linked to the menus - """ - self.menus_container = G.host.menus.getMainContainer(type_) - self.createMenus(caller) - - def _buildMenus(self, container, caller=None): - """Recursively build menus of the container - - @param container(quick_menus.MenuContainer): menu container - @param caller(Widget): instance linked to the menus - """ - if caller is None: - main_menu = MainMenu() - self.add_widget(main_menu) - caller = main_menu - else: - context_menu = contextmenu.ContextMenu() - caller.add_widget(context_menu) - # FIXME: next line is needed after parent is set to avoid - # a display bug in contextmenu - # TODO: fix this upstream - context_menu._on_visible(False) - - caller = context_menu - - for child in container.getActiveMenus(): - if isinstance(child, quick_menus.MenuContainer): - if isinstance(caller, MainMenu): - menu_container = RootMenuContainer() - else: - menu_container = MenuContainer() - menu_container.text = child.name - caller.add_widget(menu_container) - self._buildMenus(child, caller=menu_container) - elif isinstance(child, quick_menus.MenuSeparator): - wid = MenuSeparator() - caller.add_widget(wid) - elif isinstance(child, quick_menus.MenuItem): - wid = MenuItem(item=child) - caller.add_widget(wid) - else: - log.error("Unknown child type: {}".format(child)) - - def createMenus(self, caller): - self.clear_widgets() - self._buildMenus(self.menus_container, caller) - - def onAbout(self): - about = AboutPopup() - about.title = ABOUT_TITLE - about.content = AboutContent( - text=ABOUT_CONTENT.format( - backend_version = G.host.backend_version, - version=G.host.version), - markup=True) - about.open() - - class TransferItem(BoxLayout): plug_info = properties.DictProperty()