Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension Search bar implementation #439

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Loading