a working entrybox in python hooray, goodbye glade entrybox :'(

This commit is contained in:
Lynne Megido 2020-08-21 21:51:17 +10:00
parent 03376ffd7f
commit 081bbe9f42
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
2 changed files with 33 additions and 102 deletions

View File

@ -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?")

View File

@ -2,101 +2,6 @@
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">dialog-cancel</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">dialog-ok</property>
</object>
<object class="GtkDialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Add new item</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="gravity">center</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">image1</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">image2</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="label" translatable="yes">Enter the URL of the item you want to add.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">https://buyee.jp/item/yahoo/auction/k3fl1n9</property>
<property name="input_purpose">url</property>
<property name="input_hints">GTK_INPUT_HINT_NO_SPELLCHECK | GTK_INPUT_HINT_NONE</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkListStore" id="lstItems">
<columns>
<!-- column-name Name -->