From 961d9f70697f7795b8e88ef6901eb206c3bc4695 Mon Sep 17 00:00:00 2001 From: Kabiir Date: Sat, 26 Oct 2024 10:36:28 -0400 Subject: [PATCH 1/3] Added Search functionality --- src/biscuit/extensions/extensions.py | 30 ++++++++++++++++++++++ src/biscuit/views/extensions/extensions.py | 1 + src/biscuit/views/extensions/results.py | 9 +++++++ 3 files changed, 40 insertions(+) diff --git a/src/biscuit/extensions/extensions.py b/src/biscuit/extensions/extensions.py index dfb9e482..a83ea7dc 100644 --- a/src/biscuit/extensions/extensions.py +++ b/src/biscuit/extensions/extensions.py @@ -110,6 +110,36 @@ 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: + ... + + for name, data in self.fetched.items(): + # More complex logic can be used using RegEx + if search_string in name: + self.fetch_queue.put((name, data)) + def fetch_extensions(self) -> None: """Fetch extensions from Extensions repository.""" diff --git a/src/biscuit/views/extensions/extensions.py b/src/biscuit/views/extensions/extensions.py index 85f4ac87..32563ce4 100644 --- a/src/biscuit/views/extensions/extensions.py +++ b/src/biscuit/views/extensions/extensions.py @@ -28,6 +28,7 @@ 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.add_action(Icons.CLEAR_ALL, self.results.clear) def initialize(self) -> None: diff --git a/src/biscuit/views/extensions/results.py b/src/biscuit/views/extensions/results.py index dbb91168..6fa2892c 100644 --- a/src/biscuit/views/extensions/results.py +++ b/src/biscuit/views/extensions/results.py @@ -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 @@ -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()) From 3d8422485b3adff5967198fc30c9f43a5055afce Mon Sep 17 00:00:00 2001 From: Kabiir Date: Sat, 26 Oct 2024 10:40:14 -0400 Subject: [PATCH 2/3] Added Search trigger on keypress --- src/biscuit/views/extensions/extensions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/biscuit/views/extensions/extensions.py b/src/biscuit/views/extensions/extensions.py index 32563ce4..7197ff26 100644 --- a/src/biscuit/views/extensions/extensions.py +++ b/src/biscuit/views/extensions/extensions.py @@ -29,6 +29,10 @@ def __init__(self, master, *args, **kwargs) -> None: 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('', 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: From cb02ae9f4d6a3b3ea71a662b0e9a9ae34ce82f5b Mon Sep 17 00:00:00 2001 From: Billy Date: Sat, 26 Oct 2024 22:30:30 +0530 Subject: [PATCH 3/3] fix: Extensions searchbar - make non case-sensitive --- src/biscuit/extensions/extensions.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/biscuit/extensions/extensions.py b/src/biscuit/extensions/extensions.py index a83ea7dc..d640dc16 100644 --- a/src/biscuit/extensions/extensions.py +++ b/src/biscuit/extensions/extensions.py @@ -135,11 +135,14 @@ def fetch_searched_extensions(self, search_string) -> None: except: ... - for name, data in self.fetched.items(): - # More complex logic can be used using RegEx - if search_string in name: + 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."""