2020-08-10 09:34:24 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# <one line to give the program's name and a brief idea of what it does.>
|
|
|
|
# Copyright (C) 2020 lynnesbian
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
import requests, gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk, Gio, Gdk
|
2020-08-10 09:34:24 +00:00
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
import functions
|
|
|
|
from listing import YahooAuctionsItem
|
|
|
|
from settings import BuypeebSettings
|
2020-08-10 09:34:24 +00:00
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
import json, sys
|
|
|
|
from os import path
|
2020-08-10 09:34:24 +00:00
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
isWindows = sys.platform.startswith('win')
|
2020-08-10 09:34:24 +00:00
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
if isWindows:
|
|
|
|
settingsLocation = path.join(os.getenv("APPDATA"), "Lynnear Software", "bypeeb")
|
|
|
|
else:
|
|
|
|
settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot
|
2020-08-10 09:34:24 +00:00
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
class BuypeebApp:
|
|
|
|
def __init__(self):
|
|
|
|
self.app = Gtk.Application.new('com.lynnearsoftware.buypeeb', 0)
|
|
|
|
self.app.connect('startup', self.startup)
|
|
|
|
self.app.connect('activate', self.activate)
|
|
|
|
self.app.connect('shutdown', self.shutdown)
|
|
|
|
self.window = None
|
|
|
|
self.settings = BuypeebSettings(settingsLocation)
|
2020-08-21 11:51:17 +00:00
|
|
|
self.builder = None
|
2020-08-21 10:32:43 +00:00
|
|
|
|
|
|
|
def run(self, argv):
|
|
|
|
self.app.run(argv)
|
|
|
|
|
|
|
|
def startup(self, app):
|
|
|
|
builder = Gtk.Builder()
|
|
|
|
builder.add_from_string(open(path.join(path.dirname(__file__), "ui/main.glade"), 'r').read())
|
|
|
|
builder.connect_signals(self)
|
|
|
|
wndMain = builder.get_object('wndMain')
|
2020-08-22 08:55:15 +00:00
|
|
|
self.items = builder.get_object('lstItems')
|
|
|
|
self.items.clear() # ensure list is empty
|
2020-08-21 10:32:43 +00:00
|
|
|
self.window = wndMain
|
2020-08-21 11:51:17 +00:00
|
|
|
self.builder = builder
|
2020-08-21 10:32:43 +00:00
|
|
|
app.add_window(self.window)
|
2020-08-22 08:55:15 +00:00
|
|
|
self.setExchangeRate()
|
2020-08-21 10:32:43 +00:00
|
|
|
|
|
|
|
self.settings.load()
|
2020-08-22 08:55:15 +00:00
|
|
|
self.renderList()
|
2020-08-21 10:32:43 +00:00
|
|
|
|
|
|
|
def activate(self, app):
|
|
|
|
self.window.show_all()
|
|
|
|
|
|
|
|
def shutdown(self, app):
|
|
|
|
self.settings.save()
|
|
|
|
self.app.quit()
|
|
|
|
|
2020-08-21 11:08:18 +00:00
|
|
|
def msgBox(self, title, text, form = Gtk.MessageType.WARNING):
|
2020-08-22 08:55:15 +00:00
|
|
|
msgbox = Gtk.MessageDialog(
|
|
|
|
parent = self.window,
|
|
|
|
flags = 0,
|
|
|
|
message_type = form,
|
|
|
|
buttons = Gtk.ButtonsType.OK,
|
|
|
|
message_format = title
|
|
|
|
)
|
|
|
|
|
2020-08-21 11:08:18 +00:00
|
|
|
msgbox.format_secondary_text(text)
|
|
|
|
response = msgbox.run()
|
|
|
|
msgbox.destroy()
|
|
|
|
return response
|
|
|
|
|
2020-08-21 11:51:17 +00:00
|
|
|
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)
|
|
|
|
|
2020-08-22 08:55:15 +00:00
|
|
|
def setExchangeRate(self):
|
|
|
|
self.rate = functions.get_exchange_rate()
|
|
|
|
|
|
|
|
def renderList(self):
|
|
|
|
self.items.clear()
|
|
|
|
print(self.settings.watchlist)
|
|
|
|
for item in self.settings.watchlist:
|
|
|
|
print("heeh hoo")
|
|
|
|
self.items.append([item.name, item.price_aud(self.rate), "heenlo", item.id])
|
|
|
|
|
2020-08-21 10:59:35 +00:00
|
|
|
def btnAddClicked(self, widget):
|
2020-08-22 08:55:15 +00:00
|
|
|
url = self.entryBox("Add URL", "Enter the URL of the item you want to add.")
|
|
|
|
if url:
|
|
|
|
if functions.rmatch("", url):
|
|
|
|
self.settings.watch(url)
|
|
|
|
|
|
|
|
self.renderList()
|
2020-08-21 11:08:18 +00:00
|
|
|
|
|
|
|
def btnQuitClicked(self, widget):
|
2020-08-22 08:55:15 +00:00
|
|
|
prompt = Gtk.MessageDialog(
|
|
|
|
parent = self.window,
|
|
|
|
flags = 0,
|
|
|
|
message_type = Gtk.MessageType.QUESTION,
|
|
|
|
buttons = Gtk.ButtonsType.OK_CANCEL,
|
|
|
|
message_format = "Really quit?"
|
|
|
|
)
|
|
|
|
|
2020-08-21 11:08:18 +00:00
|
|
|
prompt.format_secondary_text("Are you sure you want to quit buypeeb?")
|
|
|
|
response = prompt.run()
|
|
|
|
if response:
|
|
|
|
self.shutdown(self)
|
2020-08-21 10:59:35 +00:00
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app = BuypeebApp()
|
|
|
|
app.run(sys.argv)
|