From 02cf152ecbbc043386eb45907a8239b8e3bd08c6 Mon Sep 17 00:00:00 2001 From: mlncn Date: Sun, 2 May 2021 15:09:19 -0400 Subject: [PATCH] Add crucial destroy() otherwise window stays there, nonresponsive, until script killed i just hadn't noticed in the standalone script because the script did in fact end, but when called from pomodoroprompt.py itself, which keeps running, the window hung, froze, freezed, broke, was a problem. And i thought it was somehow because it was called from another file or program but really it was just this missing destroy that is somehow not in many examples. --- prompt_window.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/prompt_window.py b/prompt_window.py index c277b26..bc0cae4 100644 --- a/prompt_window.py +++ b/prompt_window.py @@ -16,9 +16,6 @@ class PromptWindow(Gtk.Window): self.set_size_request(500, 100) self.set_border_width(10) - # This is needed to end the thread if the dialog is closed with the X. - self.connect("destroy", Gtk.main_quit) - vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10) self.add(vbox) @@ -45,22 +42,20 @@ class PromptWindow(Gtk.Window): self.set_title(prompt) self.show_all() - Gtk.main() def save(self, item): # Note: item is the entry directly if enter is pressed, but the button # (i guess) if the button is pressed, so we do not use it. self.task = self.entry.get_text() - # A little concerned this might be sort of the nuclear option here. - Gtk.main_quit() + self.destroy() def reset(self, item): self.entry.set_text(self.orig_task) def retrieve(self): - if self.task: + try: return self.task - else: + except AttributeError: return None # started to do conditional like this but maybe main program handles. # else if self.orig_task: @@ -68,6 +63,10 @@ class PromptWindow(Gtk.Window): def prompt(prompt=None, task=None): win = PromptWindow(prompt=prompt, task=task) + # This is needed to end the thread if the dialog is closed with the X. + win.connect("destroy", Gtk.main_quit) + win.show_all() + Gtk.main() return win.retrieve()