コード例 #1
0
def find_glob_icon(*names, category="categories"):
    if not LOAD_GLOB:
        return None
    icondirs = getattr(IconTheme, "icondirs", [])
    if not icondirs:
        return None
    dirnames = (category, )
    pathnames = []
    for name in names:
        for dn in dirnames:
            for d in icondirs:
                for ext in EXTENSIONS:
                    pathnames += [
                        os.path.join(d, "*", "*", dn, "%s.%s" % (name, ext)),
                        os.path.join(d, "*", dn, "*", "%s.%s" % (name, ext)),
                    ]
    for pathname in pathnames:
        filenames = glob.glob(pathname)
        log("glob(%s) matches %i filenames", pathname, len(filenames))
        if filenames:
            for f in filenames:
                v = icon_util.load_icon_from_file(f)
                if v:
                    log("found icon for %s with glob '%s': %s", names,
                        pathname, f)
                    return v
    return None
コード例 #2
0
def load_entry_icon(props):
    #load icon binary data
    names = []
    for x in ("Icon", "Name", "GenericName"):
        name = props.get(x)
        if name and name not in names:
            names.append(name)
            continue
    for x in ("Exec", "TryExec"):
        cmd = props.get(x)
        if cmd and not cmd.endswith(os.path.sep):
            cmd = os.path.basename(cmd)
            if cmd not in names:
                names.append(cmd)
    filename = find_icon(*names)
    icondata = None
    if filename:
        icondata = icon_util.load_icon_from_file(filename)
        if icondata:
            bdata, ext = icondata
            props["IconData"] = bdata
            props["IconType"] = ext
    if not icondata:
        log("no icon found for %s from %s", names, props)
    return props
コード例 #3
0
ファイル: xdg_helper.py プロジェクト: frostbane/xpra
def main():
    from xpra.platform import program_context  #pylint: disable=import-outside-toplevel
    with program_context("XDG-Menu-Helper", "XDG Menu Helper"):
        for x in list(sys.argv):
            if x in ("-v", "--verbose"):
                sys.argv.remove(x)
                add_debug_category("menu")
                log.enable_debug()

        def icon_fmt(icondata):
            return "%i bytes" % len(icondata)

        if len(sys.argv) > 1:
            for x in sys.argv[1:]:
                if os.path.isabs(x):
                    v = icon_util.load_icon_from_file(x)
                    print("load_icon_from_file(%s)=%s" % (x, v))
        else:
            menu = load_xdg_menu_data()
            if menu:
                print()
                print("application menu:")
                print_nested_dict(menu, vformat={"IconData": icon_fmt})
            else:
                print("no application menu data found")
            #try desktop sessions:
            sessions = load_desktop_sessions()
            if sessions:
                print()
                print("session menu:")
                print_nested_dict(sessions, vformat={"IconData": icon_fmt})
            else:
                print("no session menu data found")
    return 0
コード例 #4
0
def load_desktop_sessions():
    xsessions_dir = "%s/share/xsessions" % sys.prefix
    if not os.path.exists(xsessions_dir) or not os.path.isdir(xsessions_dir):
        return {}
    xsessions = {}
    with IconLoadingContext():
        from xdg.DesktopEntry import DesktopEntry
        for f in os.listdir(xsessions_dir):
            filename = os.path.join(xsessions_dir, f)
            de = DesktopEntry(filename)
            try:
                entry = load_xdg_entry(de)
                if not entry:
                    continue
                name = de.getName()
                if not entry.get("IconData"):
                    names = get_icon_names_for_session(name.lower())
                    icon_filename = find_icon(*names)
                    if icon_filename:
                        icondata = icon_util.load_icon_from_file(icon_filename)
                        if icondata:
                            entry["IconData"] = icondata[0]
                            entry["IconType"] = icondata[1]
                xsessions[name] = entry
            except Exception as e:
                log("load_desktop_sessions(%s)", remove_icons, exc_info=True)
                log.error("Error loading desktop entry '%s':", filename)
                log.error(" %s", e)
    return xsessions
コード例 #5
0
ファイル: xdg_helper.py プロジェクト: frostbane/xpra
def load_icon_from_theme(icon_name, theme=None):
    if not EXPORT_ICONS or not icon_name:
        return None
    from xdg import IconTheme
    filename = IconTheme.getIconPath(icon_name, theme=theme)
    if not filename:
        return None
    return icon_util.load_icon_from_file(filename)
コード例 #6
0
ファイル: xdg_helper.py プロジェクト: frostbane/xpra
def find_icon(dirnames, icondirs, name):
    extensions = ("png", "svg", "xpm")
    pathnames = []
    noext = os.path.splitext(name)[0]
    for dn in dirnames:
        for d in icondirs:
            for ext in extensions:
                pathnames += [
                    os.path.join(d, "*", "*", dn, "%s.%s" % (noext, ext)),
                    os.path.join(d, "*", dn, "*", "%s.%s" % (noext, ext)),
                ]
    for pathname in pathnames:
        filenames = glob.glob(pathname)
        log("glob(%s) matches %i filenames", pathname, len(filenames))
        if filenames:
            for f in filenames:
                v = icon_util.load_icon_from_file(f)
                if v:
                    log("found icon for '%s' with glob '%s': %s", name,
                        pathname, f)
                    return v
    return None