Plugin search now works on author names, description

This commit is contained in:
Rikko 2022-12-03 21:04:51 +05:30
parent b9c82567b8
commit 0b499f92fe
2 changed files with 25 additions and 14 deletions

View file

@ -1,6 +1,7 @@
{ {
"plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py", "plugin_manager_url": "https://github.com/bombsquad-community/plugin-manager/{content_type}/{tag}/plugin_manager.py",
"versions": { "versions": {
"0.1.9": null,
"0.1.8": { "0.1.8": {
"api_version": 7, "api_version": 7,
"commit_sha": "bbce3bd", "commit_sha": "bbce3bd",

View file

@ -20,7 +20,7 @@ _env = _ba.env()
_uiscale = ba.app.ui.uiscale _uiscale = ba.app.ui.uiscale
PLUGIN_MANAGER_VERSION = "0.1.8" PLUGIN_MANAGER_VERSION = "0.1.9"
REPOSITORY_URL = "https://github.com/bombsquad-community/plugin-manager" REPOSITORY_URL = "https://github.com/bombsquad-community/plugin-manager"
CURRENT_TAG = "main" CURRENT_TAG = "main"
INDEX_META = "{repository_url}/{content_type}/{tag}/index.json" INDEX_META = "{repository_url}/{content_type}/{tag}/index.json"
@ -1441,9 +1441,9 @@ class PluginManagerWindow(ba.Window):
self._last_filter_text = None self._last_filter_text = None
self._last_filter_plugins = [] self._last_filter_plugins = []
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.create_task(self.process_search_filter()) loop.create_task(self.process_search_term())
async def process_search_filter(self): async def process_search_term(self):
while True: while True:
await asyncio.sleep(0.2) await asyncio.sleep(0.2)
try: try:
@ -1454,7 +1454,7 @@ class PluginManagerWindow(ba.Window):
if self.selected_category is None: if self.selected_category is None:
continue continue
try: try:
await self.draw_plugin_names(self.selected_category, search_filter=filter_text) await self.draw_plugin_names(self.selected_category, search_term=filter_text)
except CategoryDoesNotExistError: except CategoryDoesNotExistError:
pass pass
# XXX: This may be more efficient, but we need a way to get a plugin's textwidget # XXX: This may be more efficient, but we need a way to get a plugin's textwidget
@ -1515,6 +1515,16 @@ class PluginManagerWindow(ba.Window):
texture=ba.gettexture("replayIcon"), texture=ba.gettexture("replayIcon"),
draw_controller=controller_button) draw_controller=controller_button)
def search_term_filterer(self, plugin, search_term):
if search_term in plugin.name:
return True
if search_term in plugin.info["description"].lower():
return True
for author in plugin.info["authors"]:
if search_term in author["name"].lower():
return True
return False
# async def draw_plugin_names(self, category): # async def draw_plugin_names(self, category):
# for plugin in self._columnwidget.get_children(): # for plugin in self._columnwidget.get_children():
# plugin.delete() # plugin.delete()
@ -1524,8 +1534,9 @@ class PluginManagerWindow(ba.Window):
# await asyncio.gather(*plugin_names_to_draw) # await asyncio.gather(*plugin_names_to_draw)
# XXX: Not sure if this is the best way to handle search filters. # XXX: Not sure if this is the best way to handle search filters.
async def draw_plugin_names(self, category, search_filter=""): async def draw_plugin_names(self, category, search_term=""):
to_draw_plugin_names = (search_filter, category) != (self._last_filter_text, # Re-draw plugin list UI if either search term or category was switched.
to_draw_plugin_names = (search_term, category) != (self._last_filter_text,
self.selected_category) self.selected_category)
if not to_draw_plugin_names: if not to_draw_plugin_names:
return return
@ -1535,18 +1546,17 @@ class PluginManagerWindow(ba.Window):
except (KeyError, AttributeError): except (KeyError, AttributeError):
raise CategoryDoesNotExistError(f"{category} does not exist.") raise CategoryDoesNotExistError(f"{category} does not exist.")
if search_filter: if search_term:
plugins = [] search_term_filterer = lambda plugin: self.search_term_filterer(plugin, search_term)
for plugin in category_plugins: plugins = filter(search_term_filterer, category_plugins)
if search_filter in plugin.name:
plugins.append(plugin)
else: else:
plugins = category_plugins plugins = category_plugins
if plugins == self._last_filter_plugins: if plugins == self._last_filter_plugins:
# Plugins names to draw on UI are already drawn.
return return
self._last_filter_text = search_filter self._last_filter_text = search_term
self._last_filter_plugins = plugins self._last_filter_plugins = plugins
plugin_names_to_draw = tuple(self.draw_plugin_name(plugin) for plugin in plugins) plugin_names_to_draw = tuple(self.draw_plugin_name(plugin) for plugin in plugins)
@ -1613,7 +1623,7 @@ class PluginManagerWindow(ba.Window):
async def select_category(self, category): async def select_category(self, category):
self.plugins_in_current_view.clear() self.plugins_in_current_view.clear()
self.draw_category_selection_button(post_label=category) self.draw_category_selection_button(post_label=category)
await self.draw_plugin_names(category, search_filter=self._last_filter_text) await self.draw_plugin_names(category, search_term=self._last_filter_text)
self.selected_category = category self.selected_category = category
def cleanup(self): def cleanup(self):