Ejemplo n.º 1
0
    def __filter(self, model, iter_, data):
        """Filter a single row"""
        plugin = model.get_value(iter_)
        if not plugin:
            return False

        entry, state_combo, type_combo = data

        plugin_type = type_combo.get_active_type()
        if not issubclass(plugin.cls, plugin_type):
            return False

        tag_row = state_combo.get_active_row()
        if tag_row:
            plugin_tags = plugin.tags
            tag, flag = tag_row
            enabled = plugin_enabled(plugin)
            if (flag == EnabledType.NO and plugin_tags or
                    flag == EnabledType.TAG and tag not in plugin_tags or
                    flag == EnabledType.EN and not enabled or
                    flag == EnabledType.DIS and enabled):
                return False

        def matches(text, filter_):
            return all(p in remove_diacritics(text.lower())
                       for p in filter_.lower().split())

        filter_ = remove_diacritics(entry.get_text())
        return (matches(plugin.name, filter_) or
                matches(plugin.id, filter_) or
                matches((plugin.description or ""), filter_))
Ejemplo n.º 2
0
 def get_key(cls, song):
     key = song(cls.get_key_expression())
     if cls.config_get_bool(cls._CFG_REMOVE_DIACRITICS):
         key = remove_diacritics(key)
     if cls.config_get_bool(cls._CFG_CASE_INSENSITIVE):
         key = key.lower()
     if cls.config_get_bool(cls._CFG_REMOVE_PUNCTUATION):
         key = remove_punctuation(key)
     if cls.config_get_bool(cls._CFG_REMOVE_WHITESPACE):
         key = "_".join(key.split())
     return key
Ejemplo n.º 3
0
 def matches(text, filter_):
     return all(p in remove_diacritics(text.lower())
                for p in filter_.lower().split())
Ejemplo n.º 4
0
 def test_harder(self):
     assert remove_diacritics("abc '123' ?!") == "abc '123' ?!"
     assert remove_diacritics(SOME_FRENCH) == "gout d'œufs a Noel"
Ejemplo n.º 5
0
 def test_empty(self):
     assert remove_diacritics("") == ""
     assert remove_diacritics(" \t\n") == " \t\n"