Skip to content

Commit

Permalink
feat: Added Search bar for extension center (#439 by @Kabiirk)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 authored Oct 26, 2024
2 parents 1526672 + cb02ae9 commit 6684264
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/biscuit/extensions/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,39 @@ def run_fetch_extensions(self, *_) -> None:
with self.extensions_lock:
threading.Thread(target=self.fetch_extensions, daemon=True).start()

def fetch_searched_extensions(self, search_string) -> None:
"""Fetch extensions whose name matches the search_string from Extensions repository."""

response = None
try:
response = requests.get(self.list_url)
except Exception:
pass

# FAIL - network error
if not response or response.status_code != 200:
try:
self.base.extensions_view.results.show_placeholder()
except:
...
return

self.fetched = json.loads(response.text)
# SUCCESS
if self.fetched:
try:
self.base.extensions_view.results.show_content()
except:
...

if not search_string:
for name, data in self.fetched.items():
self.fetch_queue.put((name, data))
else:
for name, data in self.fetched.items():
if search_string.lower() in name.lower():
self.fetch_queue.put((name, data))

def fetch_extensions(self) -> None:
"""Fetch extensions from Extensions repository."""

Expand Down
5 changes: 5 additions & 0 deletions src/biscuit/views/extensions/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def __init__(self, master, *args, **kwargs) -> None:
self.add_item(self.results)
self.add_action(Icons.FILTER, self.results.toggle_installed)
self.add_action(Icons.REFRESH, self.results.refresh)
self.add_action(Icons.SEARCH, self.results.search)
self.searchbox.bind('<Return>', lambda e:self.results.search()) # Bind ENTER KEY PRESS TO Search Function
# Error faced & Reason for using Lambda:
# # https://stackoverflow.com/questions/23842770/python-function-takes-1-positional-argument-but-2-were-given-how

# self.add_action(Icons.CLEAR_ALL, self.results.clear)

def initialize(self) -> None:
Expand Down
9 changes: 9 additions & 0 deletions src/biscuit/views/extensions/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, master, *args, **kwargs) -> None:
self.placeholder = ExtensionsPlaceholder(self)
self.extension_list = ExtensionsList(self.content)
self.extension_list.pack(fill=tk.BOTH, expand=True)
self.master = master

self.filter_installed = False

Expand Down Expand Up @@ -105,3 +106,11 @@ def set_selected(self, extension: ExtensionGUI) -> None:
def toggle_installed(self) -> None:
self.filter_installed = not self.filter_installed
self.refresh()

def search(self) -> None:
if self.base.testing:
return

self.clear()
self.update_idletasks()
self.manager.fetch_searched_extensions(self.master.searchbox.get())

0 comments on commit 6684264

Please sign in to comment.