Compare commits

...

2 commits

5 changed files with 76 additions and 10 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
// "python.pythonPath": "/home/lynne/Projects/code/python/buypeeb/venv/bin/python3.8"
}

View file

@ -21,11 +21,13 @@
import requests, gi import requests, gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
from pebble import ProcessPool
import json, sys import json, sys
from os import path from os import path
from threading import Thread from threading import Thread
from datetime import datetime from datetime import datetime
from concurrent.futures import TimeoutError
import functions import functions
from listing import YahooAuctionsItem, JST from listing import YahooAuctionsItem, JST
@ -69,6 +71,7 @@ class BuypeebApp:
self.window = None self.window = None
self.settings = BuypeebSettings(settingsLocation) self.settings = BuypeebSettings(settingsLocation)
self.builder = None self.builder = None
self.selected = None
def run(self, argv): def run(self, argv):
self.app.run(argv) self.app.run(argv)
@ -86,6 +89,7 @@ class BuypeebApp:
self.setExchangeRate() self.setExchangeRate()
self.settings.load() self.settings.load()
self.resetSidePane()
self.renderList() self.renderList()
def activate(self, app): def activate(self, app):
@ -151,12 +155,15 @@ class BuypeebApp:
def renderList(self): def renderList(self):
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():
if item.ready: if item.ready:
self.items.append([item.name, item.price_aud(self.rate), "...", id]) self.items.append([item.name, item.price_aud(self.rate), "...", id])
else: else:
self.items.append([item.name, "...", "...", id]) name = item.name
if name == None:
name = "Loading..."
self.items.append([name, "...", "...", id])
self.updateListTimes() self.updateListTimes()
@ -173,13 +180,34 @@ class BuypeebApp:
else: else:
listing[2] = f"{idate} {itime}" listing[2] = f"{idate} {itime}"
def updateSidePane(self, id: str):
item = self.settings.watchlist[id]
info = {
"Name": item.name,
"YahooName": item.original_name,
"Price": item.price_jpy(),
"PriceAUD": item.price_aud(),
"Ending": item.ending_in(),
"Bids": item.bids
}
for label, contents in info.items():
self.builder.get_object(f"lblSelected{label}").set_label(contents)
def resetSidePane(self):
for label in ["YahooName", "Price", "PriceAUD", "Ending", "Bids"]:
self.builder.get_object(f"lblSelected{label}").set_label("")
self.builder.get_object("lblSelectedName").set_label("buypeeb")
# BUTTON CLICKS # 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:
# vry simpl url validation for simpol creachers # vry simpl url validation for simpol creachers
if functions.rmatch(r"https?.+yahoo.+", url): if functions.rmatch(r"http.+yahoo.+", url):
self.settings.watch(url) self.settings.watch(url)
else: else:
self.msgBox("Invalid URL", "The provided URL was invalid.", Gtk.MessageType.ERROR) self.msgBox("Invalid URL", "The provided URL was invalid.", Gtk.MessageType.ERROR)
@ -211,9 +239,34 @@ class BuypeebApp:
prompt.format_secondary_text("Are you sure you want to quit buypeeb?") prompt.format_secondary_text("Are you sure you want to quit buypeeb?")
response = prompt.run() response = prompt.run()
if response: if response == Gtk.ResponseType.OK:
self.shutdown(self) self.shutdown(self)
def btnSelectedRenameClicked(self, widget):
item = self.settings.watchlist[self.selected]
name = self.entryBox("Rename", f"Enter a new name for \"{item.name}\".")
if name:
item.name = name
self.renderList() # TODO: only update the changed item
def btnSelectedRemoveClicked(self, widget):
del self.settings.watchlist[self.selected]
self.selected = None
self.renderList()
self.resetSidePane()
# OTHER UI INTERACTIONS
def tveItemsSelectionChanged(self, selection):
items, treeIter = selection.get_selected()
if treeIter == None:
return
row = items[treeIter]
id = row[3]
self.selected = id
self.updateSidePane(id)
if __name__ == '__main__': if __name__ == '__main__':
app = BuypeebApp() app = BuypeebApp()
app.run(sys.argv) app.run(sys.argv)

View file

@ -110,3 +110,6 @@ class YahooAuctionsItem:
def price_aud(self, rate = 75.0): def price_aud(self, rate = 75.0):
return f"${self.price / rate:.2f}" return f"${self.price / rate:.2f}"
def ending_in(self):
return "heenlo"

View file

@ -1,2 +1,3 @@
requests==2.24 requests==2.24
PyGObject==3.36 PyGObject==3.36
pebble==4.5

View file

@ -275,7 +275,9 @@
<property name="search_column">1</property> <property name="search_column">1</property>
<property name="activate_on_single_click">True</property> <property name="activate_on_single_click">True</property>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection"/> <object class="GtkTreeSelection">
<signal name="changed" handler="tveItemsSelectionChanged" swapped="no"/>
</object>
</child> </child>
<child> <child>
<object class="GtkTreeViewColumn"> <object class="GtkTreeViewColumn">
@ -346,7 +348,9 @@
<property name="label" translatable="yes">precious peebus polytonal player</property> <property name="label" translatable="yes">precious peebus polytonal player</property>
<property name="justify">center</property> <property name="justify">center</property>
<property name="wrap">True</property> <property name="wrap">True</property>
<property name="ellipsize">end</property>
<property name="max_width_chars">40</property> <property name="max_width_chars">40</property>
<property name="lines">3</property>
<attributes> <attributes>
<attribute name="weight" value="bold"/> <attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/> <attribute name="scale" value="2"/>
@ -598,11 +602,12 @@
<property name="homogeneous">True</property> <property name="homogeneous">True</property>
<property name="layout_style">expand</property> <property name="layout_style">expand</property>
<child> <child>
<object class="GtkButton"> <object class="GtkButton" id="btnSelectedRemove">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Delete</property> <property name="tooltip_text" translatable="yes">Remove</property>
<signal name="clicked" handler="btnSelectedRemoveClicked" swapped="no"/>
<child> <child>
<object class="GtkImage" id="image4"> <object class="GtkImage" id="image4">
<property name="visible">True</property> <property name="visible">True</property>
@ -619,11 +624,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton" id="btnSelectedRename">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Rename</property> <property name="tooltip_text" translatable="yes">Rename</property>
<signal name="clicked" handler="btnSelectedRenameClicked" swapped="no"/>
<child> <child>
<object class="GtkImage" id="image1"> <object class="GtkImage" id="image1">
<property name="visible">True</property> <property name="visible">True</property>
@ -639,7 +645,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton" id="btnSelectedUpdate">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -659,7 +665,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkToggleButton"> <object class="GtkToggleButton" id="btnSelectedFavourite">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>