mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 15:12:48 +01:00
feat: catch cancel and shutdown events
This commit is contained in:
1 parent
319966f8e1
commit
2e5860650f
9 files changed
+94
-40
No files matched your search
@@ -87,7 +87,13 @@ class NotifyDialog(GenericDialog):
|
||||
|
||||
|
||||
class WaitDialog(GenericDialog):
|
||||
def __init__(self, controller: "Controller", secondary: str, jobs: int = 1):
|
||||
def __init__(
|
||||
self,
|
||||
controller: "Controller",
|
||||
secondary: str,
|
||||
jobs: int = 1,
|
||||
show_cancel: bool = False,
|
||||
):
|
||||
super().__init__(
|
||||
controller=controller,
|
||||
text=strings.wait,
|
||||
@@ -96,19 +102,29 @@ class WaitDialog(GenericDialog):
|
||||
secondary=secondary,
|
||||
)
|
||||
|
||||
self.controller = controller
|
||||
self.jobs = jobs
|
||||
self.cur_job = 1
|
||||
|
||||
self.cancel = Gtk.Button(label="Cancel", halign=Gtk.Align.CENTER)
|
||||
self.cancel.connect("clicked", lambda _: self.controller.set_cancel_event())
|
||||
|
||||
self.connect("delete-event", lambda widget, event: True)
|
||||
content = self.get_content_area()
|
||||
spinner = Gtk.Spinner()
|
||||
self.prog = Gtk.ProgressBar()
|
||||
|
||||
content.pack_end(self.cancel, NO_EXPAND, NO_FILL, 0)
|
||||
content.pack_end(spinner, NO_EXPAND, NO_FILL, 0)
|
||||
|
||||
if self.jobs > 1:
|
||||
content.pack_end(self.prog, NO_EXPAND, NO_FILL, 0)
|
||||
else:
|
||||
spinner.start()
|
||||
|
||||
if show_cancel is False:
|
||||
self.connect("realize", lambda _: self.cancel.set_visible(False))
|
||||
|
||||
def update_text(self, msg: str) -> None:
|
||||
self.format_secondary_text(msg)
|
||||
|
||||
@@ -119,6 +135,9 @@ class WaitDialog(GenericDialog):
|
||||
self.prog.set_fraction(fraction)
|
||||
self.cur_job += 1
|
||||
|
||||
def show_cancel(self, state: bool) -> None:
|
||||
self.cancel.set_visible(state)
|
||||
|
||||
|
||||
class QuitDialog(GenericDialog):
|
||||
def __init__(self, controller: "Controller", secondary: str):
|
||||
|
||||
Reference in new issue
Block a user