Exact search

This commit is contained in:
Jesper 2024-06-12 11:42:47 +02:00
parent 90ad278098
commit 3feda3af08

View File

@ -9,6 +9,7 @@ import subprocess
import threading
import urllib.request, urllib.parse, urllib.error
from fuzzywuzzy import process
import unidecode
import gi
gi.require_version("Gtk", "3.0")
@ -753,16 +754,15 @@ class pluginclass(object):
except Exception as e:
print(e)
def fuzzy_application_search(self, search_text):
for item in self.applicationList:
self.applicationsBox.remove(item["button"])
def strip_case_and_accents(self, string):
if isinstance(string, str):
try:
value = unidecode.unidecode(string.lower())
except:
pass
return value
if search_text == "": # Reset application list
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
def fuzzy_application_search(self, search_text):
labels = [app["button"].appName for app in self.applicationList]
results = process.extract(search_text, labels, limit=len(labels))
@ -776,6 +776,25 @@ class pluginclass(object):
if first_button is True:
app["button"].grab_focus()
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):
self.filterTimer = None
@ -792,32 +811,20 @@ class pluginclass(object):
if self.lastActiveTab != 1:
self.changeTab(1, clear = False)
text = widget.get_text()
# showns = False # Are any app shown?
# shownList = []
# for i in self.applicationsBox.get_children():
# shown = i.filterText(text)
# if shown:
# dupe = False
# for item in shownList:
# if i.desktopFile == item.desktopFile:
# dupe = True
# if dupe:
# i.hide()
# else:
# shownList.append(i)
# #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 item in self.applicationList:
self.applicationsBox.remove(item["button"])
if text == "": # Reset application list
for item in self.applicationList:
self.applicationsBox.remove(item["button"])
for item in self.sortedApplicationList:
self.applicationsBox.pack_start(item[1], False, False, 0)
if self.enableFuzzySearch:
self.fuzzy_application_search(text)
else:
self.exact_application_search(text)
for i in self.categoriesBox.get_children():
i.released()
i.set_relief(Gtk.ReliefStyle.NONE)
@ -1728,4 +1735,4 @@ class pluginclass(object):
# print "=======>>> " + item.get_name() + " = top level"
# newApplicationsList.append({"entry": item, "category": ""})
return newApplicationsList
return newApplicationsList