mirror of
https://github.com/aclist/dztui.git
synced 2026-08-25 17:32:36 +02:00
feat: dedicated ignore dialog
This commit is contained in:
parent
9d8d37e110
commit
2413dd1f14
@ -1,5 +1,6 @@
|
||||
import textwrap
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from typing import Self
|
||||
from dzgui.util.strings import dialog_error, dialog_header
|
||||
@ -9,14 +10,17 @@ import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk # noqa E402
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from gi.repository import Gdk
|
||||
|
||||
class EarlyAlertDialog(Gtk.MessageDialog):
|
||||
def __init__(self, string: str) -> None:
|
||||
|
||||
class AbortDialog(Gtk.MessageDialog):
|
||||
def __init__(self, string: str, buttons: Gtk.ButtonsType) -> None:
|
||||
super().__init__(
|
||||
title=dialog_header,
|
||||
text=dialog_error,
|
||||
transient_for=None,
|
||||
buttons=Gtk.ButtonsType.OK,
|
||||
buttons=buttons,
|
||||
)
|
||||
|
||||
msg = textwrap.fill(string, 50)
|
||||
@ -24,7 +28,8 @@ class EarlyAlertDialog(Gtk.MessageDialog):
|
||||
|
||||
aa = self.get_action_area()
|
||||
aa.set_margin_bottom(20)
|
||||
# self.action_area.set_margin_bottom(20)
|
||||
aa.set_layout(Gtk.ButtonBoxStyle.CENTER)
|
||||
|
||||
self.outer = self.get_content_area()
|
||||
self.outer.set_margin_start(30)
|
||||
self.outer.set_margin_end(30)
|
||||
@ -32,26 +37,30 @@ class EarlyAlertDialog(Gtk.MessageDialog):
|
||||
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:
|
||||
case Gtk.ResponseType.OK | Gtk.ResponseType.DELETE_EVENT:
|
||||
sys.exit(1)
|
||||
case Gtk.ResponseType.CANCEL:
|
||||
print("response was cancel")
|
||||
return
|
||||
|
||||
class EarlyAlertDialog(AbortDialog):
|
||||
def __init__(self, string: str, buttons: Gtk.ButtonsType) -> None:
|
||||
super().__init__(string=string, buttons=Gtk.ButtonsType.OK)
|
||||
|
||||
class EarlyIgnoreDialog(EarlyAlertDialog):
|
||||
class EarlyIgnoreDialog(AbortDialog):
|
||||
def __init__(self, string: str) -> None:
|
||||
super().__init__(string=string)
|
||||
super().__init__(string=string, buttons=Gtk.ButtonsType.OK_CANCEL)
|
||||
|
||||
# TODO: reverse order
|
||||
self.add_button("Ignore", Gtk.ResponseType.CANCEL)
|
||||
|
||||
# TODO: if exit, sys.exit(1), else pass
|
||||
|
||||
@ -161,6 +161,7 @@ class QuitDialog(GenericDialog):
|
||||
self.add_button(strings.exit_app, Gtk.ResponseType.OK)
|
||||
|
||||
self.connect("response", self._on_response)
|
||||
# TODO: superfluous with the above
|
||||
self.connect("delete-event", self._on_response)
|
||||
|
||||
def _on_response(self, dialog: Self, response: Gtk.ResponseType) -> None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user