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.
This commit is contained in:
mlncn 2021-05-02 15:09:19 -04:00
parent f856241c80
commit 02cf152ecb

View file

@ -16,9 +16,6 @@ class PromptWindow(Gtk.Window):
self.set_size_request(500, 100) self.set_size_request(500, 100)
self.set_border_width(10) 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) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.add(vbox) self.add(vbox)
@ -45,22 +42,20 @@ class PromptWindow(Gtk.Window):
self.set_title(prompt) self.set_title(prompt)
self.show_all() self.show_all()
Gtk.main()
def save(self, item): def save(self, item):
# Note: item is the entry directly if enter is pressed, but the button # 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. # (i guess) if the button is pressed, so we do not use it.
self.task = self.entry.get_text() self.task = self.entry.get_text()
# A little concerned this might be sort of the nuclear option here. self.destroy()
Gtk.main_quit()
def reset(self, item): def reset(self, item):
self.entry.set_text(self.orig_task) self.entry.set_text(self.orig_task)
def retrieve(self): def retrieve(self):
if self.task: try:
return self.task return self.task
else: except AttributeError:
return None return None
# started to do conditional like this but maybe main program handles. # started to do conditional like this but maybe main program handles.
# else if self.orig_task: # else if self.orig_task:
@ -68,6 +63,10 @@ class PromptWindow(Gtk.Window):
def prompt(prompt=None, task=None): def prompt(prompt=None, task=None):
win = PromptWindow(prompt=prompt, task=task) 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() return win.retrieve()