Files
dzgui/dzgui/views/dialogs/early_alert.py
T
2026-05-26 03:54:30 +09:00

58 lines
1.6 KiB
Python

import textwrap
import sys
from typing import Self
from dzgui.util.strings import dialog_error, dialog_header
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk # noqa E402
class EarlyAlertDialog(Gtk.MessageDialog):
def __init__(self, string: str) -> None:
super().__init__(
title=dialog_header,
text=dialog_error,
transient_for=None,
buttons=Gtk.ButtonsType.OK,
)
msg = textwrap.fill(string, 50)
self.format_secondary_text(msg)
aa = self.get_action_area()
aa.set_margin_bottom(20)
# self.action_area.set_margin_bottom(20)
self.outer = self.get_content_area()
self.outer.set_margin_start(30)
self.outer.set_margin_end(30)
self.set_default_size(250, 100)
abort = self.get_widget_for_response(Gtk.ResponseType.OK)
if abort is not None and hasattr(abort, "set_label"):
abort.set_label("Exit")
self.connect("response", self._on_response)
self.run()
self.destroy()
def _on_response(self, dialog: Self, response: Gtk.ResponseType) -> None:
match response:
case Gtk.ResponseType.OK:
sys.exit(1)
case Gtk.ResponseType.CANCEL:
return
class EarlyIgnoreDialog(EarlyAlertDialog):
def __init__(self, string: str) -> None:
super().__init__(string=string)
# TODO: reverse order
self.add_button("Ignore", Gtk.ResponseType.CANCEL)
# TODO: if exit, sys.exit(1), else pass