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
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from pebble import ProcessPool
import json, sys
from os import path
from threading import Thread
from datetime import datetime
from concurrent.futures import TimeoutError
import functions
from listing import YahooAuctionsItem, JST
@ -69,6 +71,7 @@ class BuypeebApp:
self.window = None
self.settings = BuypeebSettings(settingsLocation)
self.builder = None
self.selected = None
def run(self, argv):
self.app.run(argv)
@ -86,6 +89,7 @@ class BuypeebApp:
self.setExchangeRate()
self.settings.load()
self.resetSidePane()
self.renderList()
def activate(self, app):
@ -151,12 +155,15 @@ class BuypeebApp:
def renderList(self):
self.items.clear()
print(self.settings.watchlist)
# print(self.settings.watchlist)
for id, item in self.settings.watchlist.items():
if item.ready:
self.items.append([item.name, item.price_aud(self.rate), "...", id])
else:
self.items.append([item.name, "...", "...", id])
name = item.name
if name == None:
name = "Loading..."
self.items.append([name, "...", "...", id])
self.updateListTimes()
@ -173,13 +180,34 @@ class BuypeebApp:
else:
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
def btnAddClicked(self, widget):
url = self.entryBox("Add URL", "Enter the URL of the item you want to add.")
if url:
# 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)
else:
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?")
response = prompt.run()
if response:
if response == Gtk.ResponseType.OK:
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__':
app = BuypeebApp()
app.run(sys.argv)

View file

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

View file

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

View file

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