~martijnbraam/shipments

2451889e3b54e89ca618c6687d7468e24dd08654 — Martijn Braam 2 years ago 05f6956
Implement basic search
2 files changed, 20 insertions(+), 0 deletions(-)

M shipments_gtk/ui/shipments.glade
M shipments_gtk/window.py
M shipments_gtk/ui/shipments.glade => shipments_gtk/ui/shipments.glade +2 -0
@@ 338,6 338,8 @@
                            <property name="primary-icon-name">edit-find-symbolic</property>
                            <property name="primary-icon-activatable">False</property>
                            <property name="primary-icon-sensitive">False</property>
                            <signal name="search-changed" handler="on_searchbox_search_changed" swapped="no"/>
                            <signal name="stop-search" handler="on_searchbox_stop_search" swapped="no"/>
                          </object>
                          <packing>
                            <property name="expand">False</property>

M shipments_gtk/window.py => shipments_gtk/window.py +18 -0
@@ 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)