@@ -59,6 +59,30 @@ def mimeData(self, indexes):
59
59
return data
60
60
61
61
62
+ class EmojiFilterProxyModel (QSortFilterProxyModel ):
63
+ """Proxy class used for sorting and filtering model data"""
64
+
65
+ def filterAcceptsRow (self , sourceRow , sourceParent ):
66
+ """Filter for emoji groups and text filter"""
67
+
68
+ if get_app ().window .emojiFilterGroup .currentData () and \
69
+ get_app ().window .emojiFilterGroup .currentData () != "Show All" :
70
+ # Fetch the group name
71
+ index = self .sourceModel ().index (sourceRow , 2 , sourceParent ) # group name column
72
+ group_name = self .sourceModel ().data (index ) # group name (i.e. common)
73
+
74
+ # Fetch the emoji name
75
+ index = self .sourceModel ().index (sourceRow , 0 , sourceParent ) # transition name column
76
+ emoji_name = self .sourceModel ().data (index ) # emoji name (i.e. Smiley Face)
77
+
78
+ # Return, if regExp match in displayed format.
79
+ return get_app ().window .emojiFilterGroup .currentData () == group_name and \
80
+ self .filterRegExp ().indexIn (emoji_name ) >= 0
81
+
82
+ # Continue running built-in parent filter logic
83
+ return super (EmojiFilterProxyModel , self ).filterAcceptsRow (sourceRow , sourceParent )
84
+
85
+
62
86
class EmojisModel ():
63
87
def update_model (self , clear = True ):
64
88
log .info ("updating emoji model." )
@@ -88,13 +112,14 @@ def update_model(self, clear=True):
88
112
89
113
# get a list of files in the OpenShot /emojis directory
90
114
emojis_dir = os .path .join (info .PATH , "emojis" , "color" , "svg" )
91
- transition_groups = [{"type" : "common" , "dir" : emojis_dir , "files" : os .listdir (emojis_dir )}, ]
115
+ emoji_paths = [{"type" : "common" , "dir" : emojis_dir , "files" : os .listdir (emojis_dir )}, ]
116
+ emoji_groups = {}
92
117
93
118
# Add optional user-defined transitions folder
94
119
if os .path .exists (info .EMOJIS_PATH ) and os .listdir (info .EMOJIS_PATH ):
95
- transition_groups .append ({"type" : "user" , "dir" : info .EMOJIS_PATH , "files" : os .listdir (info .EMOJIS_PATH )})
120
+ emoji_paths .append ({"type" : "user" , "dir" : info .EMOJIS_PATH , "files" : os .listdir (info .EMOJIS_PATH )})
96
121
97
- for group in transition_groups :
122
+ for group in emoji_paths :
98
123
type = group ["type" ]
99
124
dir = group ["dir" ]
100
125
files = group ["files" ]
@@ -109,9 +134,13 @@ def update_model(self, clear=True):
109
134
110
135
# get name of transition
111
136
emoji = emoji_lookup .get (fileBaseName , {})
112
- emoji_name = emoji .get ("annotation" , fileBaseName )
137
+ emoji_name = _ ( emoji .get ("annotation" , fileBaseName ). capitalize () )
113
138
emoji_type = emoji .get ("group" , "user" )
114
139
140
+ # Track unique emoji groups
141
+ if emoji_type not in emoji_groups .keys ():
142
+ emoji_groups [emoji_type ] = emoji_type
143
+
115
144
# Check for thumbnail path (in build-in cache)
116
145
thumb_path = os .path .join (info .IMAGES_PATH , "cache" , "{}.png" .format (fileBaseName ))
117
146
@@ -152,6 +181,7 @@ def update_model(self, clear=True):
152
181
col .setIcon (QIcon (thumb_path ))
153
182
col .setText (emoji_name )
154
183
col .setToolTip (emoji_name )
184
+ col .setData (emoji_type )
155
185
col .setFlags (Qt .ItemIsSelectable | Qt .ItemIsEnabled | Qt .ItemIsUserCheckable | Qt .ItemIsDragEnabled )
156
186
row .append (col )
157
187
@@ -181,6 +211,12 @@ def update_model(self, clear=True):
181
211
self .model .appendRow (row )
182
212
self .model_paths [path ] = path
183
213
214
+ # Loop through emoji groups, and populate emoji filter drop-down
215
+ get_app ().window .emojiFilterGroup .clear ()
216
+ get_app ().window .emojiFilterGroup .addItem (_ ("Show All" ), "Show All" )
217
+ for emoji_type in sorted (emoji_groups .keys ()):
218
+ get_app ().window .emojiFilterGroup .addItem (_ (emoji_type .capitalize ()), emoji_type )
219
+
184
220
def __init__ (self , * args ):
185
221
186
222
# Create standard model
0 commit comments