From 760f101024b7759f59b28d3dc42db0187ee2435e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 28 Mar 2024 21:14:28 +0100 Subject: [PATCH] add reload ticket functionallity will automatically overwrite the file on disk with the updated data if unsuccessful, nothing will be done --- choochoo/ticketview.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/choochoo/ticketview.py b/choochoo/ticketview.py index 7811e1d..24f6fd1 100644 --- a/choochoo/ticketview.py +++ b/choochoo/ticketview.py @@ -56,6 +56,27 @@ class TicketScreen(Adw.NavigationPage): if action == "remove": self.ticket.delete() self.activate_action("win.home", None) + def show_toast(self, title): + toast = Adw.Toast() + toast.set_title(title) + toast.set_timeout(2) + self.overlay.add_toast(toast) + + def fetch(self): + GLib.idle_add(self.show_toast, _("Fetching ticket information")) + self.task_fetch() + + def task_fetch(self): + tnumber = self.ticket.ticket_number + tsurname = self.ticket.last_name + ticket = Ticket.from_network(tnumber, tsurname) + if ticket is None: + GLib.idle_add(self.show_toast, _("Couldn't refresh ticket. Try again later")) + else: + self.ticket = ticket + self.ticket.save() + GLib.idle_add(self.show_toast, _("Done")) + GLib.idle_add(self.update) def generate_code(self): barcode = self.ticket.barcode -- 2.38.5