added clear all/ended buttons

This commit is contained in:
Lynne Megido 2020-08-23 19:53:47 +10:00
parent d50cd17f9d
commit f0cfa46f28
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
2 changed files with 26 additions and 5 deletions

View File

@ -37,6 +37,9 @@ else:
settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot
class BuypeebApp: class BuypeebApp:
# SETUP
def __init__(self): def __init__(self):
self.app = Gtk.Application.new('com.lynnearsoftware.buypeeb', 0) self.app = Gtk.Application.new('com.lynnearsoftware.buypeeb', 0)
self.app.connect('startup', self.startup) self.app.connect('startup', self.startup)
@ -71,12 +74,14 @@ class BuypeebApp:
self.settings.save() self.settings.save()
self.app.quit() self.app.quit()
def msgBox(self, title, text, form = Gtk.MessageType.WARNING): # CONVENIENCE FUNCTIONS
def msgBox(self, title, text, form = Gtk.MessageType.WARNING, buttons = Gtk.ButtonsType.OK):
msgbox = Gtk.MessageDialog( msgbox = Gtk.MessageDialog(
parent = self.window, parent = self.window,
flags = 0, flags = 0,
message_type = form, message_type = form,
buttons = Gtk.ButtonsType.OK, buttons = buttons,
text = title text = title
) )
@ -122,9 +127,10 @@ class BuypeebApp:
self.items.clear() self.items.clear()
print(self.settings.watchlist) print(self.settings.watchlist)
for id, item in self.settings.watchlist.items(): for id, item in self.settings.watchlist.items():
print("heeh hoo")
self.items.append([item.name, item.price_aud(self.rate), "heenlo", id]) self.items.append([item.name, item.price_aud(self.rate), "heenlo", id])
# BUTTON CLICKS
def btnAddClicked(self, widget): def btnAddClicked(self, widget):
url = self.entryBox("Add URL", "Enter the URL of the item you want to add.") url = self.entryBox("Add URL", "Enter the URL of the item you want to add.")
if url: if url:
@ -136,6 +142,19 @@ class BuypeebApp:
self.renderList() self.renderList()
def btnClearEndedClicked(self, widget):
if self.msgBox("Clear ended?", "Are you sure you want to clear all ended items from the watchlist?", buttons = Gtk.ButtonsType.OK_CANCEL):
for id, item in self.settings.watchlist.items():
if not item.available:
del self.settings.watchlist[key]
self.renderList()
def btnClearAllClicked(self, widget):
if self.msgBox("Clear all?", "Are you sure you want to clear all watched items?", buttons = Gtk.ButtonsType.OK_CANCEL):
self.settings.watchlist = {}
self.items.clear()
def btnQuitClicked(self, widget): def btnQuitClicked(self, widget):
prompt = Gtk.MessageDialog( prompt = Gtk.MessageDialog(
parent = self.window, parent = self.window,

View File

@ -126,13 +126,14 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkToolButton" id="btnClearEnded">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Clear ended</property> <property name="tooltip_text" translatable="yes">Clear ended</property>
<property name="label" translatable="yes">Clear ended</property> <property name="label" translatable="yes">Clear ended</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-clear</property> <property name="stock_id">gtk-clear</property>
<signal name="clicked" handler="btnClearEndedClicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -140,13 +141,14 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkToolButton" id="btnClearAll">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Clear all</property> <property name="tooltip_text" translatable="yes">Clear all</property>
<property name="label" translatable="yes">Clear all</property> <property name="label" translatable="yes">Clear all</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-delete</property> <property name="stock_id">gtk-delete</property>
<signal name="clicked" handler="btnClearAllClicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>