From 081bbe9f425a8c375c1d9873224cc0a7a7d25ea4 Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 21 Aug 2020 21:51:17 +1000 Subject: [PATCH] a working entrybox in python hooray, goodbye glade entrybox :'( --- buypeeb.py | 40 ++++++++++++++++++---- ui/main.glade | 95 --------------------------------------------------- 2 files changed, 33 insertions(+), 102 deletions(-) diff --git a/buypeeb.py b/buypeeb.py index 1b2d3df..65e918f 100755 --- a/buypeeb.py +++ b/buypeeb.py @@ -34,12 +34,6 @@ if isWindows: else: settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot -# print("Getting JPY/AUD exchange rate...") -rate = functions.get_exchange_rate() - -x = YahooAuctionsItem("My cool product", "peeb.us") -print(f"Bidding for item \"{x.name}\" started at {x.start_date} and will end at {x.end_date}. Current price is {x.price_jpy()}, or {x.price_aud()}.") - class BuypeebApp: def __init__(self): self.app = Gtk.Application.new('com.lynnearsoftware.buypeeb', 0) @@ -48,6 +42,7 @@ class BuypeebApp: self.app.connect('shutdown', self.shutdown) self.window = None self.settings = BuypeebSettings(settingsLocation) + self.builder = None def run(self, argv): self.app.run(argv) @@ -58,6 +53,7 @@ class BuypeebApp: builder.connect_signals(self) wndMain = builder.get_object('wndMain') self.window = wndMain + self.builder = builder app.add_window(self.window) self.settings.load() @@ -76,8 +72,38 @@ class BuypeebApp: msgbox.destroy() return response + def entryBox(self, title, text, allow_cancel = True): + # thanks to https://ardoris.wordpress.com/2008/07/05/pygtk-text-entry-dialog/ + entrybox = Gtk.MessageDialog( + parent = self.window, + modal = True, + destroy_with_parent = True, + message_type = Gtk.MessageType.QUESTION, + buttons = Gtk.ButtonsType.OK_CANCEL if allow_cancel else Gtk.ButtonsType.OK, + title = title + ) + + entrybox.set_markup(text) + entry = Gtk.Entry() + entry.connect("activate", self.entryBoxResponse, entrybox, Gtk.ResponseType.OK) # allow for pressing enter instead of clicking OK + + entrybox.vbox.pack_end(entry, True, True, 0) + entrybox.show_all() + + response = entrybox.run() + text = entry.get_text() + entrybox.destroy() + if response: + return text + else: + # user clicked cancel + return False + + def entryBoxResponse(self, widget, entrybox, response): + entrybox.response(response) + def btnAddClicked(self, widget): - self.msgBox("good job", "succkeess") + print(self.entryBox("Add URL", "Enter the URL of the item you want to add.")) def btnQuitClicked(self, widget): prompt = Gtk.MessageDialog(self.window, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL, "Really quit?") diff --git a/ui/main.glade b/ui/main.glade index 465e78d..81842a0 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -2,101 +2,6 @@ - - True - False - dialog-cancel - - - True - False - dialog-ok - - - False - Add new item - True - dialog - center - - - False - vertical - 2 - - - False - end - - - Cancel - True - True - True - image1 - - - True - True - 0 - - - - - Add - True - True - True - image2 - - - True - True - 1 - - - - - False - False - 0 - - - - - True - False - 10 - 10 - Enter the URL of the item you want to add. - True - - - False - True - 0 - - - - - True - True - https://buyee.jp/item/yahoo/auction/k3fl1n9 - url - GTK_INPUT_HINT_NO_SPELLCHECK | GTK_INPUT_HINT_NONE - - - False - True - 2 - - - - - - - -