~martijnbraam/shipments

05f69560213697c90eb4cf85127d7d0128d4ee57 — Martijn Braam 2 years ago ba281db
Group packages by status category in the sidebar
1 files changed, 44 insertions(+), 15 deletions(-)

M shipments_gtk/window.py
M shipments_gtk/window.py => shipments_gtk/window.py +44 -15
@@ 246,24 246,53 @@ class ShipmentsWindow:
        self.action_refresh.set_enabled(len(self.packages) > 0)
        self.action_opensite.set_enabled(len(self.packages) > 0)

        grouped = {}
        for package in self.packages:
            box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
            label = Gtk.Label(label=package['label'], xalign=0.0)
            label.set_line_wrap(True)
            box.add(label)
            code = Gtk.Label(label=package['status'], xalign=0.0)
            code.set_line_wrap(True)
            code.get_style_context().add_class('dim-label')
            box.add(code)
            box.set_margin_top(8)
            box.set_margin_bottom(8)
            box.set_margin_start(10)
            box.set_margin_end(10)
            if package['status_category'] not in grouped:
                grouped[package['status_category']] = []
            grouped[package['status_category']].append(package)

        headings = {
            StatusCategory.ERROR.value: "Error",
            StatusCategory.LABEL_CREATED.value: "Label created",
            StatusCategory.IN_TRANSIT.value: "In transit",
            StatusCategory.DELIVERED.value: "Delivered",
        }

        for h in headings:
            if h not in grouped:
                continue
            row = Gtk.ListBoxRow()
            row.set_selectable(False)
            row.set_activatable(False)
            label = Gtk.Label(label=headings[h])
            label.get_style_context().add_class('heading')
            label.set_margin_top(8)
            row.add(label)
            self.packagelist.add(row)
            row = Gtk.ListBoxRow()
            row.add(box)
            row.label = package['label']
            row.code = package['code']
            row.set_selectable(False)
            row.set_activatable(False)
            row.add(Gtk.Separator())
            self.packagelist.add(row)
            for package in grouped[h]:
                box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
                label = Gtk.Label(label=package['label'], xalign=0.0)
                label.set_line_wrap(True)
                box.add(label)
                code = Gtk.Label(label=package['status'], xalign=0.0)
                code.set_line_wrap(True)
                code.get_style_context().add_class('dim-label')
                box.add(code)
                box.set_margin_top(8)
                box.set_margin_bottom(8)
                box.set_margin_start(10)
                box.set_margin_end(10)
                row = Gtk.ListBoxRow()
                row.add(box)
                row.label = package['label']
                row.code = package['code']
                self.packagelist.add(row)
        self.packagelist.show_all()

    def show_package(self, code):