-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathui_list_family_font.py
139 lines (99 loc) · 4.38 KB
/
ui_list_family_font.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import bpy
from .addon_prefs import get_addon_preferences
# Font selection UI List
class FONTSELECTOR_family_uilist(bpy.types.UIList):
obj = None
strip = False
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, flt_flag) :
obj_props = self.obj.fontselector_object_properties
# Name
row = layout.row(align=True)
row.label(text = item.name)
# Multi Component
if not self.strip and obj_props.show_multi_component and item.multi_component:
row.operator(
"fontselector.load_font_family",
text="",
icon="FONTPREVIEW",
).font_family_name = item.name
# row.label(text="", icon="FONTPREVIEW")
# Favorites
if obj_props.show_favorite:
if item.favorite:
icon = 'SOLO_ON'
else:
icon = 'SOLO_OFF'
row.prop(item, "favorite", text = "", icon = icon, emboss = True)
def draw_filter(self, context, layout):
obj_props = self.obj.fontselector_object_properties
row = layout.row(align=True)
row.label(text = "", icon = "FILTER")
row.separator()
row.prop(obj_props, "favorite_filter", text="", icon="SOLO_ON")
row.prop(obj_props, "invert_filter", text="", icon="ARROW_LEFTRIGHT")
row.separator()
sub = row.row(align=True)
sub.alignment = "RIGHT"
sub.label(text = "", icon = "HIDE_OFF")
sub.separator()
if not self.strip:
sub.prop(obj_props, "show_multi_component", text="", icon="FONTPREVIEW")
sub.prop(obj_props, "show_favorite", text="", icon="SOLO_ON")
def filter_items(self, context, data, propname):
obj_props = self.obj.fontselector_object_properties
families = context.window_manager.fontselector_properties.font_families
family = families[obj_props.family_index]
# Default return values.
flt_flags = []
flt_neworder = []
helper_funcs = bpy.types.UI_UL_list
col = getattr(data, propname)
# Filter/Order
if obj_props.font_search\
or obj_props.favorite_filter\
or obj_props.invert_filter:
flt_flags = [self.bitflag_filter_item] * len(col)
# Name search
if obj_props.font_search :
search = obj_props.font_search.lower()
for idx, family in enumerate(col) :
if flt_flags[idx] != 0 :
chk_visible = search in family.name.lower()
if not chk_visible:
for f in family.fonts:
if obj_props.search_font_names and search in f.font_name.lower():
chk_visible = True
if obj_props.search_filepath and search in f.filepath.lower():
chk_visible = True
if not chk_visible:
flt_flags[idx] = 0
# Favorites
if obj_props.favorite_filter :
for idx, family in enumerate(col) :
if flt_flags[idx] != 0 :
if family.favorite == False :
flt_flags[idx] = 0
# invert filtering
if obj_props.invert_filter :
for idx, family in enumerate(col) :
if flt_flags[idx] != 0 :
flt_flags[idx] = 0
else :
flt_flags[idx] = self.bitflag_filter_item
return flt_flags, flt_neworder
# Font selection Object UI List
class FONTSELECTOR_UL_family_uilist_object(FONTSELECTOR_family_uilist):
def __init__(self):
self.obj = bpy.context.active_object.data
# Font selection Strip UI List
class FONTSELECTOR_UL_family_uilist_strip(FONTSELECTOR_family_uilist):
def __init__(self):
self.obj = bpy.context.active_sequence_strip
self.strip = True
### REGISTER ---
def register():
bpy.utils.register_class(FONTSELECTOR_UL_family_uilist_object)
bpy.utils.register_class(FONTSELECTOR_UL_family_uilist_strip)
def unregister():
bpy.utils.unregister_class(FONTSELECTOR_UL_family_uilist_object)
bpy.utils.unregister_class(FONTSELECTOR_UL_family_uilist_strip)