2021-05-01 16:48:32 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk, GLib
|
|
|
|
|
|
|
|
class PromptWindow(Gtk.Window):
|
|
|
|
|
2021-05-02 16:58:52 +00:00
|
|
|
def __init__(self, prompt=None, task=None):
|
2021-05-01 16:48:32 +00:00
|
|
|
|
|
|
|
if task is None:
|
|
|
|
task = ""
|
2021-05-02 15:32:18 +00:00
|
|
|
self.orig_task = task
|
2021-05-01 16:48:32 +00:00
|
|
|
|
|
|
|
Gtk.Window.__init__(self, title="Pomodoro Prompt")
|
2021-05-01 17:13:12 +00:00
|
|
|
self.set_size_request(500, 100)
|
|
|
|
self.set_border_width(10)
|
2021-05-01 16:48:32 +00:00
|
|
|
|
2021-05-02 15:19:36 +00:00
|
|
|
# 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)
|
2021-05-01 18:44:20 +00:00
|
|
|
self.add(vbox)
|
|
|
|
|
2021-05-01 16:48:32 +00:00
|
|
|
self.entry = Gtk.Entry()
|
2021-05-02 15:32:18 +00:00
|
|
|
self.entry.set_text(self.orig_task)
|
2021-05-01 17:13:12 +00:00
|
|
|
self.entry.connect("activate", self.save)
|
2021-05-01 16:48:32 +00:00
|
|
|
|
2021-05-01 18:44:20 +00:00
|
|
|
vbox.pack_start(self.entry, True, True, 0)
|
|
|
|
|
|
|
|
hbox = Gtk.Box(spacing=6)
|
|
|
|
|
|
|
|
self.button_ok = Gtk.Button.new_with_label("OK")
|
|
|
|
self.button_ok.connect("clicked", self.save)
|
|
|
|
hbox.pack_start(self.button_ok, True, True, 0)
|
|
|
|
|
2021-05-02 15:32:18 +00:00
|
|
|
if task:
|
|
|
|
self.button_reset = Gtk.Button.new_with_label("Reset")
|
|
|
|
self.button_reset.connect("clicked", self.reset)
|
|
|
|
hbox.pack_start(self.button_reset, True, True, 0)
|
|
|
|
|
2021-05-01 18:44:20 +00:00
|
|
|
vbox.pack_start(hbox, True, True, 0)
|
2021-05-01 16:48:32 +00:00
|
|
|
|
2021-05-02 16:58:52 +00:00
|
|
|
if prompt:
|
|
|
|
self.set_title(prompt)
|
2021-05-01 16:48:32 +00:00
|
|
|
|
2021-05-02 16:11:53 +00:00
|
|
|
self.show_all()
|
|
|
|
Gtk.main()
|
|
|
|
|
2021-05-01 18:44:20 +00:00
|
|
|
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.
|
2021-05-02 15:19:36 +00:00
|
|
|
self.task = self.entry.get_text()
|
2021-05-01 17:13:12 +00:00
|
|
|
# A little concerned this might be sort of the nuclear option here.
|
|
|
|
Gtk.main_quit()
|
2021-05-01 16:48:32 +00:00
|
|
|
|
2021-05-02 15:32:18 +00:00
|
|
|
def reset(self, item):
|
|
|
|
self.entry.set_text(self.orig_task)
|
|
|
|
|
2021-05-02 15:19:36 +00:00
|
|
|
def retrieve(self):
|
2021-05-02 16:04:02 +00:00
|
|
|
if self.task:
|
|
|
|
return self.task
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
# started to do conditional like this but maybe main program handles.
|
|
|
|
# else if self.orig_task:
|
|
|
|
# return "Pomodoro cancelled, original goal was:"
|
|
|
|
|
2021-05-02 16:59:26 +00:00
|
|
|
def prompt(prompt=None, task=None):
|
|
|
|
win = PromptWindow(prompt=prompt, task=task)
|
|
|
|
return win.retrieve()
|
|
|
|
|
2021-05-02 16:04:02 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-05-02 16:59:26 +00:00
|
|
|
task = prompt(prompt="What'll you do next?", task="Something, probably!")
|
|
|
|
print(task)
|