Search: Fix searching for accentuated strings

This commit is contained in:
Clement Lefebvre 2020-06-10 11:49:10 +01:00
parent 9d56931ce0
commit 3169e80707
2 changed files with 20 additions and 23 deletions

View File

@ -12,7 +12,8 @@ import urllib.request, urllib.parse, urllib.error
import gi import gi
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
gi.require_version("MateMenu", "2.0") gi.require_version("MateMenu", "2.0")
from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib, MateMenu gi.require_version("XApp", "1.0")
from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib, MateMenu, XApp
import plugins.recentHelper as RecentHelper import plugins.recentHelper as RecentHelper
from plugins.easybuttons import (ApplicationLauncher, CategoryButton, from plugins.easybuttons import (ApplicationLauncher, CategoryButton,

View File

@ -2,6 +2,7 @@
import os.path import os.path
import shutil import shutil
import unidecode
import xdg.DesktopEntry import xdg.DesktopEntry
import xdg.Menu import xdg.Menu
@ -258,10 +259,10 @@ class ApplicationLauncher(easyButton):
def loadDesktopEntry(self, desktopItem): def loadDesktopEntry(self, desktopItem):
try: try:
self.appName = self.strip_accents(desktopItem.getName()) self.appName = desktopItem.getName()
self.appGenericName = self.strip_accents(desktopItem.getGenericName()) self.appGenericName = desktopItem.getGenericName()
self.appComment = self.strip_accents(desktopItem.getComment()) self.appComment = desktopItem.getComment()
self.appExec = self.strip_accents(desktopItem.getExec().replace('\\\\', '\\')) self.appExec = desktopItem.getExec().replace('\\\\', '\\')
self.appIconName = desktopItem.getIcon() self.appIconName = desktopItem.getIcon()
self.appCategories = desktopItem.getCategories() self.appCategories = desktopItem.getCategories()
self.appMateDocPath = desktopItem.get("X-MATE-DocPath") or "" self.appMateDocPath = desktopItem.get("X-MATE-DocPath") or ""
@ -303,30 +304,25 @@ class ApplicationLauncher(easyButton):
self.addLabel(self.appName) self.addLabel(self.appName)
def filterText(self, text): def filterText(self, text):
keywords = text.lower().split() keywords = self.strip_case_and_accents(text).split()
appName = self.appName.lower() appName = self.strip_case_and_accents(self.appName)
appGenericName = self.appGenericName.lower() appGenericName = self.strip_case_and_accents(self.appGenericName)
appComment = self.appComment.lower() appComment = self.strip_case_and_accents(self.appComment)
appExec = self.appExec.lower() appExec = self.strip_case_and_accents(self.appExec)
for keyword in keywords: for keyword in keywords:
keyw = self.strip_accents(keyword) if keyword != "" and appName.find(keyword) == -1 and appGenericName.find(keyword) == -1 and appComment.find(keyword) == -1 and appExec.find(keyword) == -1:
if keyw != "" and appName.find(keyw) == -1 and appGenericName.find(keyw) == -1 and appComment.find(keyw) == -1 and appExec.find(keyw) == -1:
self.hide() self.hide()
return False return False
self.show() self.show()
return True return True
def strip_accents(self, string): def strip_case_and_accents(self, string):
# FIXME: Is this right?? if isinstance(string, str):
return string try:
# value = string value = unidecode.unidecode(string.lower())
# print(value, "...") except:
# if isinstance(string, str): pass
# try: return value
# value = string.encode('UTF8', 'ignore')
# except:
# pass
# return value
def getTooltip(self): def getTooltip(self):
tooltip = self.appName tooltip = self.appName