pomodoroprompt/prompt_window.py

50 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
class PromptWindow(Gtk.Window):
def __init__(self, task=None):
if task is None:
task = ""
Gtk.Window.__init__(self, title="Pomodoro Prompt")
self.set_size_request(500, 100)
self.set_border_width(10)
2021-05-01 18:44:20 +00:00
vbox = Gtk.Box(spacing=10)
self.add(vbox)
self.entry = Gtk.Entry()
self.entry.set_text(task)
self.entry.connect("activate", self.save)
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)
vbox.pack_start(hbox, True, True, 0)
# self.set_title("Entry")
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.
task = self.entry.get_text()
print(task)
# A little concerned this might be sort of the nuclear option here.
Gtk.main_quit()
win = PromptWindow(task="Making money")
win.show_all()
Gtk.main()