Exact search
This commit is contained in:
parent
90ad278098
commit
3feda3af08
@ -9,6 +9,7 @@ import subprocess
|
|||||||
import threading
|
import threading
|
||||||
import urllib.request, urllib.parse, urllib.error
|
import urllib.request, urllib.parse, urllib.error
|
||||||
from fuzzywuzzy import process
|
from fuzzywuzzy import process
|
||||||
|
import unidecode
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
@ -753,16 +754,15 @@ class pluginclass(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def fuzzy_application_search(self, search_text):
|
def strip_case_and_accents(self, string):
|
||||||
for item in self.applicationList:
|
if isinstance(string, str):
|
||||||
self.applicationsBox.remove(item["button"])
|
try:
|
||||||
|
value = unidecode.unidecode(string.lower())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return value
|
||||||
|
|
||||||
if search_text == "": # Reset application list
|
def fuzzy_application_search(self, search_text):
|
||||||
for item in self.applicationList:
|
|
||||||
self.applicationsBox.remove(item["button"])
|
|
||||||
for item in self.sortedApplicationList:
|
|
||||||
self.applicationsBox.pack_start(item[1], False, False, 0)
|
|
||||||
else: # Perform fuzzy search
|
|
||||||
labels = [app["button"].appName for app in self.applicationList]
|
labels = [app["button"].appName for app in self.applicationList]
|
||||||
results = process.extract(search_text, labels, limit=len(labels))
|
results = process.extract(search_text, labels, limit=len(labels))
|
||||||
|
|
||||||
@ -776,6 +776,25 @@ class pluginclass(object):
|
|||||||
if first_button is True:
|
if first_button is True:
|
||||||
app["button"].grab_focus()
|
app["button"].grab_focus()
|
||||||
first_button = False
|
first_button = False
|
||||||
|
# TODO: Add appGenericName, appComment and appExec
|
||||||
|
|
||||||
|
def exact_application_search(self, search_text):
|
||||||
|
shownList = []
|
||||||
|
first_button = True
|
||||||
|
# TODO: Strip case and accents
|
||||||
|
keywords = self.strip_case_and_accents(search_text).split()
|
||||||
|
for app in self.applicationList:
|
||||||
|
for item in shownList:
|
||||||
|
if app["button"].desktopFile == item.desktopFile:
|
||||||
|
continue
|
||||||
|
for keyword in keywords:
|
||||||
|
if keyword != "" and (self.strip_case_and_accents(app["button"].appName).find(keyword) != -1):
|
||||||
|
self.applicationsBox.pack_start(app["button"], False, False, 0)
|
||||||
|
if first_button is True:
|
||||||
|
app["button"].grab_focus()
|
||||||
|
first_button = False
|
||||||
|
shownList.append(app["button"])
|
||||||
|
print("b")
|
||||||
|
|
||||||
def Filter(self, widget, category = None):
|
def Filter(self, widget, category = None):
|
||||||
self.filterTimer = None
|
self.filterTimer = None
|
||||||
@ -792,32 +811,20 @@ class pluginclass(object):
|
|||||||
if self.lastActiveTab != 1:
|
if self.lastActiveTab != 1:
|
||||||
self.changeTab(1, clear = False)
|
self.changeTab(1, clear = False)
|
||||||
text = widget.get_text()
|
text = widget.get_text()
|
||||||
# showns = False # Are any app shown?
|
|
||||||
# shownList = []
|
for item in self.applicationList:
|
||||||
# for i in self.applicationsBox.get_children():
|
self.applicationsBox.remove(item["button"])
|
||||||
# shown = i.filterText(text)
|
|
||||||
# if shown:
|
if text == "": # Reset application list
|
||||||
# dupe = False
|
for item in self.applicationList:
|
||||||
# for item in shownList:
|
self.applicationsBox.remove(item["button"])
|
||||||
# if i.desktopFile == item.desktopFile:
|
for item in self.sortedApplicationList:
|
||||||
# dupe = True
|
self.applicationsBox.pack_start(item[1], False, False, 0)
|
||||||
# if dupe:
|
if self.enableFuzzySearch:
|
||||||
# i.hide()
|
self.fuzzy_application_search(text)
|
||||||
# else:
|
else:
|
||||||
# shownList.append(i)
|
self.exact_application_search(text)
|
||||||
# #if this is the first matching item
|
|
||||||
# #focus it
|
|
||||||
# if(not showns):
|
|
||||||
# i.grab_focus()
|
|
||||||
# showns = True
|
|
||||||
self.fuzzy_application_search(text)
|
|
||||||
# TODO Toggle self.enableFuzzySearch
|
|
||||||
|
|
||||||
# if not showns:
|
|
||||||
# if len(text) >= 3:
|
|
||||||
# self.add_search_suggestions(text)
|
|
||||||
# if self.useAPT:
|
|
||||||
# GLib.timeout_add(300, self.add_apt_filter_results, text)
|
|
||||||
for i in self.categoriesBox.get_children():
|
for i in self.categoriesBox.get_children():
|
||||||
i.released()
|
i.released()
|
||||||
i.set_relief(Gtk.ReliefStyle.NONE)
|
i.set_relief(Gtk.ReliefStyle.NONE)
|
||||||
@ -1728,4 +1735,4 @@ class pluginclass(object):
|
|||||||
# print "=======>>> " + item.get_name() + " = top level"
|
# print "=======>>> " + item.get_name() + " = top level"
|
||||||
# newApplicationsList.append({"entry": item, "category": ""})
|
# newApplicationsList.append({"entry": item, "category": ""})
|
||||||
|
|
||||||
return newApplicationsList
|
return newApplicationsList
|
Loading…
Reference in New Issue
Block a user