xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #2174: menu-context.patch

File menu-context.patch, 3.0 KB (added by Antoine Martin, 2 years ago)

try without the XDG_MENU_PREFIX first

  • xpra/platform/xposix/xdg_helper.py

     
    1111import os
    1212
    1313from xpra.util import envbool
    14 from xpra.os_util import load_binary_file, BytesIOClass, PYTHON3
     14from xpra.os_util import load_binary_file, BytesIOClass, OSEnvContext, PYTHON3
    1515from xpra.log import Logger
    1616
    1717log = Logger("exec", "menu")
     
    207207def load_xdg_menu_data():
    208208    global xdg_menu_data
    209209    if not xdg_menu_data:
     210        xdg_menu_data = do_load_xdg_menu_data()
     211    return xdg_menu_data
     212
     213def do_load_xdg_menu_data():
     214    try:
     215        from xdg.Menu import parse, Menu, ParsingError
     216    except ImportError:
     217        log("load_xdg_menu_data()", exc_info=True)
     218        log.warn("Warning: no xdg module, cannot use application menu data")
     219        return None
     220    menu = None
     221    if "XDG_MENU_PREFIX" in os.environ:
     222        #try without the menu prefix first:
     223        with OSEnvContext():
     224            del os.environ["XDG_MENU_PREFIX"]
     225            try:
     226                menu = parse()
     227            except ParsingError:
     228                menu = None
     229    if menu is None:
    210230        try:
    211             from xdg.Menu import parse, Menu
    212         except ImportError:
     231            menu = parse()
     232        except Exception as e:
    213233            log("load_xdg_menu_data()", exc_info=True)
    214             log.warn("Warning: no xdg module, cannot use application menu data")
    215         else:
    216             xdg_menu_data = {}
     234            log.error("Error parsing xdg menu data:")
     235            log.error(" %s", e)
     236            log.error(" this is either a bug in python-xdg,")
     237            log.error(" or an invalid system menu configuration")
     238            return None
     239    menu_data = {}
     240    for submenu in menu.getEntries():
     241        if isinstance(submenu, Menu) and submenu.Visible:
     242            name = submenu.getName()
    217243            try:
    218                 menu = parse()
     244                menu_data[name] = load_xdg_menu(submenu)
    219245            except Exception as e:
    220246                log("load_xdg_menu_data()", exc_info=True)
    221                 log.error("Error parsing xdg menu data:")
     247                log.error("Error loading submenu '%s':", name)
    222248                log.error(" %s", e)
    223                 log.error(" this is either a bug in python-xdg,")
    224                 log.error(" or an invalid system menu configuration")
    225             else:
    226                 for submenu in menu.getEntries():
    227                     if isinstance(submenu, Menu) and submenu.Visible:
    228                         name = submenu.getName()
    229                         try:
    230                             xdg_menu_data[name] = load_xdg_menu(submenu)
    231                         except Exception as e:
    232                             log("load_xdg_menu_data()", exc_info=True)
    233                             log.error("Error loading submenu '%s':", name)
    234                             log.error(" %s", e)
    235     return xdg_menu_data
     249    return menu_data