Introduce new error toast widget

This commit is contained in:
heliguy
2024-07-05 03:13:34 -04:00
parent fb308aa35a
commit 4882b31761
2 changed files with 25 additions and 0 deletions

View File

@@ -51,6 +51,7 @@ warehouse_sources = [
'main.py',
'host_info.py',
'widgets/app_row.py',
'widgets/error_toast.py',
'main_window/window.py',
'packages_page/packages_page.py',
'../data/style.css',

View File

@@ -0,0 +1,24 @@
from gi.repository import Adw, Gtk, Gdk, GLib, Pango
clipboard = Gdk.Display.get_default().get_clipboard()
class ErrorToast:
def __init__(self, display_msg, error_msg, parent_window, format=True):
def on_response(dialog, response_id):
if response_id == "copy":
clipboard.set(error_msg)
popup = Adw.AlertDialog.new(display_msg, None if format else error_msg)
popup.add_response("copy", _("Copy"))
popup.add_response("ok", _("OK"))
popup.connect("response", on_response)
if format:
lb = Gtk.Label(selectable=True, wrap=True)#, natural_wrap_mode=Gtk.NaturalWrapMode.WORD)
lb.set_markup(f"<tt>{GLib.markup_escape_text(error_msg)}</tt>")
# lb.set_label(error_msg)
# lb.set_selectable(True)
popup.set_extra_child(lb)
self.toast = Adw.Toast(title=display_msg, button_label=_("Details"))
self.toast.connect("button-clicked", lambda *_: popup.present(parent_window))