mirror of
https://github.com/aclist/dztui.git
synced 2026-10-25 12:12:31 +01:00
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
import textwrap
|
|
import sys
|
|
|
|
from typing import Self
|
|
from dzgui.util.strings import dialog_error, dialog_header
|
|
from dzgui.views.mixins.colorscheme import ColorAwareApp
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gtk # noqa E402
|
|
|
|
|
|
class AbortDialog(ColorAwareApp, Gtk.MessageDialog): # type: ignore
|
|
def __init__(self, string: str, buttons: Gtk.ButtonsType) -> None:
|
|
super().__init__(
|
|
title=dialog_header,
|
|
text=dialog_error,
|
|
transient_for=None,
|
|
buttons=buttons,
|
|
)
|
|
|
|
msg = textwrap.fill(string, 50)
|
|
self.format_secondary_text(msg)
|
|
|
|
ma = self.get_message_area()
|
|
label = ma.get_children()[1] # type: ignore
|
|
label.set_justify(Gtk.Justification.CENTER)
|
|
|
|
aa = self.get_action_area()
|
|
aa.set_margin_bottom(20)
|
|
aa.set_layout(Gtk.ButtonBoxStyle.CENTER) # type: ignore
|
|
|
|
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)
|
|
ignore = self.get_widget_for_response(Gtk.ResponseType.CANCEL)
|
|
if abort is not None and hasattr(abort, "set_label"):
|
|
abort.set_label("Exit")
|
|
if ignore is not None and hasattr(ignore, "set_label"):
|
|
ignore.set_label("Ignore")
|
|
|
|
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 | Gtk.ResponseType.DELETE_EVENT:
|
|
sys.exit(1)
|
|
case Gtk.ResponseType.CANCEL:
|
|
return
|
|
|
|
|
|
class EarlyAlertDialog(AbortDialog):
|
|
def __init__(self, string: str) -> None:
|
|
super().__init__(string=string, buttons=Gtk.ButtonsType.OK)
|
|
|
|
|
|
class EarlyIgnoreDialog(AbortDialog):
|
|
def __init__(self, string: str) -> None:
|
|
super().__init__(string=string, buttons=Gtk.ButtonsType.OK_CANCEL)
|