Skip to content
Snippets Groups Projects
ui.py 34.7 KiB
Newer Older
  • Learn to ignore specific revisions
  •     colored_icon = []
    
        for offset in range(len(icon.icon_pixels)):
            idx = offset * 4
    
            r = icon.icon_pixels_float[idx]
            g = icon.icon_pixels_float[idx+1]
            b = icon.icon_pixels_float[idx+2]
            a = icon.icon_pixels_float[idx+3]
    
            # add back some brightness and opacity blender takes away from the custom icon
            r = min(r+r*0.2,1)
            g = min(g+g*0.2,1)
            b = min(b+b*0.2,1)
            a = min(a+a*0.2,1)
    
            # make the icon follow the theme color (assuming the icon is white)
            r *= theme_color.r
            g *= theme_color.g
            b *= theme_color.b
    
            colored_icon.append(r)
            colored_icon.append(g)
            colored_icon.append(b)
            colored_icon.append(a)
    
        icon.icon_pixels_float = colored_icon
    
    
    def filter_items_by_name_insensitive(pattern, bitflag, items, propname="name", flags=None, reverse=False):
            """
            Set FILTER_ITEM for items which name matches filter_name one (case-insensitive).
            pattern is the filtering pattern.
            propname is the name of the string property to use for filtering.
            flags must be a list of integers the same length as items, or None!
            return a list of flags (based on given flags if not None),
            or an empty list if no flags were given and no filtering has been done.
            """
            import fnmatch
    
            if not pattern or not items:  # Empty pattern or list = no filtering!
                return flags or []
    
            if flags is None:
                flags = [0] * len(items)
    
            # Make pattern case-insensitive
            pattern = pattern.lower()
    
            # Implicitly add heading/trailing wildcards.
            pattern = "*" + pattern + "*"
    
            for i, item in enumerate(items):
                name = getattr(item, propname, None)
    
                # Make name case-insensitive
                name = name.lower()
    
                # This is similar to a logical xor
                if bool(name and fnmatch.fnmatch(name, pattern)) is not bool(reverse):
                    flags[i] |= bitflag
    
            return flags