From 2451889e3b54e89ca618c6687d7468e24dd08654 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sun, 28 Nov 2021 15:04:44 +0100 Subject: [PATCH] Implement basic search --- shipments_gtk/ui/shipments.glade | 2 ++ shipments_gtk/window.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/shipments_gtk/ui/shipments.glade b/shipments_gtk/ui/shipments.glade index b651326..e1f2dcd 100644 --- a/shipments_gtk/ui/shipments.glade +++ b/shipments_gtk/ui/shipments.glade @@ -338,6 +338,8 @@ edit-find-symbolic False False + + False diff --git a/shipments_gtk/window.py b/shipments_gtk/window.py index d68bcde..2382e3e 100644 --- a/shipments_gtk/window.py +++ b/shipments_gtk/window.py @@ -173,6 +173,7 @@ class ShipmentsWindow: self.db_path = os.path.join(xdg_data_home, 'shipments/shipments.json') self.packages = [] self.current_package = None + self.query = None self.db_load() if len(self.packages) > 0: @@ -248,6 +249,11 @@ class ShipmentsWindow: grouped = {} for package in self.packages: + + if self.query is not None: + if self.query not in package['label'] and self.query not in package['code']: + continue + if package['status_category'] not in grouped: grouped[package['status_category']] = [] grouped[package['status_category']].append(package) @@ -535,3 +541,15 @@ class ShipmentsWindow: url = self.packages[i]['url'] Gio.AppInfo.launch_default_for_uri(url) + + def on_searchbox_search_changed(self, widget, *args): + query = widget.get_text() + if query == '': + self.query = None + else: + self.query = query + self.rebuild_list() + + def on_searchbox_stop_search(self, widget, *args): + widget.set_text('') + self.searchrevealer.set_reveal_child(False) -- 2.45.2