diff --git a/src/biscuit/extensions/extensions.py b/src/biscuit/extensions/extensions.py index dfb9e482..d640dc16 100644 --- a/src/biscuit/extensions/extensions.py +++ b/src/biscuit/extensions/extensions.py @@ -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.""" diff --git a/src/biscuit/views/extensions/extensions.py b/src/biscuit/views/extensions/extensions.py index 85f4ac87..7197ff26 100644 --- a/src/biscuit/views/extensions/extensions.py +++ b/src/biscuit/views/extensions/extensions.py @@ -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('', 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: 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())