diff --git a/efck/emoji.py b/efck/emoji.py index 4881283..8a93f6e 100644 --- a/efck/emoji.py +++ b/efck/emoji.py @@ -66,6 +66,9 @@ def clean_desc(text): text = re.sub(r'\W{2,}', ' ', text) return text + emojis = [] + known_man_names = set() + official_emoji = set() with open(EMOJI_ORDERING_FILE, encoding='utf-8') as fd: for line in fd: @@ -88,6 +91,8 @@ def clean_desc(text): emoji_normed = ''.join(ch for ch in emoji if ch not in MODIFIER_CHARS) shortcode = shortcodes.pop(emoji_normed, '') + if name.startswith('man'): + known_man_names.add(name.split(':')[0]) if should_skip_emoji(name): continue @@ -96,11 +101,18 @@ def clean_desc(text): shortcode = clean_desc(shortcode) custom_str = ' '.join(filter(None, (custom_strings.get(ch, '') for ch in emoji))) - yield emoji, name, alt_name, shortcode, custom_str + emojis.append((emoji, name, alt_name, shortcode, custom_str)) # All shortcodes were consumed assert not shortcodes, shortcodes # Trail with custom emoji sequences from the file for custom_emoji in custom_strings.keys() - official_emoji: - yield custom_emoji, '', '', '', custom_strings[custom_emoji] + emojis.append((custom_emoji, '', '', '', custom_strings[custom_emoji])) + + # Skip person in case of emojis for which either man or woman + # versions also exist ("health worker", "astronout" ...) + is_person_disabled = not config_state[EmojiTab.__name__]['Gender']['person'] + if is_person_disabled: + emojis[:] = [i for i in emojis if f'man {i[1]}' not in known_man_names] + return emojis diff --git a/efck/tabs/emoji.py b/efck/tabs/emoji.py index d2a858c..4b83231 100644 --- a/efck/tabs/emoji.py +++ b/efck/tabs/emoji.py @@ -42,7 +42,7 @@ def __init__(self, *args, **kwargs): def init(self): logger.info('Reloading emoji ...') - self.emoji_data = list(enum_emojis()) + self.emoji_data = enum_emojis() def rowCount(self, index): return len(self.emoji_data) diff --git a/efck/tests.py b/efck/tests.py index 4a84d43..e4715de 100644 --- a/efck/tests.py +++ b/efck/tests.py @@ -179,10 +179,21 @@ class TestEmoji(TestCase): def test_enum_emoji(self): from .emoji import enum_emojis - emojis = list(enum_emojis()) + emojis = enum_emojis() self.assertGreater(len(emojis), 1000) self.assertGreater(len(emojis[0]), 3) + def test_no_judge(self): + from .emoji import enum_emojis + from .config import _gender + + # Test disabled neuter professions are not present + _gender.update({'person': 0, 'man': 0, 'woman': 1}) + emojis = enum_emojis() + judge = [i[1] for i in emojis if 'judge' in i[1]] + self.assertEqual(len(judge), 1) + self.assertIn('woman', judge[0]) + class TestOutput(TestCase): def test_copy_to_clipboard(self):