Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
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