Fix situation in which module prices are fetched individually (which the price column). Instead, have them wait in a queue that is processed when the entire fit is called and calculated (with the price pane). Also adds a little refresh icon to know that prices are updating and it's not just blank (might change)
This commit is contained in:
@@ -50,12 +50,15 @@ class Price(ViewColumn):
|
||||
return formatAmount(price, 3, 3, 9, currency=True)
|
||||
|
||||
def delayedText(self, mod, display, colItem):
|
||||
def callback(requests):
|
||||
price = requests[0].price
|
||||
sMkt = service.Market.getInstance()
|
||||
def callback(item):
|
||||
price = sMkt.getPriceNow(item.ID).price
|
||||
colItem.SetText(formatAmount(price, 3, 3, 9, currency=True) if price else "")
|
||||
colItem.SetImage(-1)
|
||||
display.SetItem(colItem)
|
||||
|
||||
service.Market.getInstance().getPrices([mod.item.ID], callback)
|
||||
sMkt.waitForPrice(mod.item, callback)
|
||||
return self.fittingView.imageList.GetImageIndex("refresh_small", "icons")
|
||||
|
||||
def getImageId(self, mod):
|
||||
return -1
|
||||
|
||||
@@ -249,10 +249,10 @@ class Display(wx.ListCtrl):
|
||||
oldImageId = colItem.GetImage()
|
||||
newText = col.getText(st)
|
||||
if newText is False:
|
||||
col.delayedText(st, self, colItem)
|
||||
newImageId = col.delayedText(st, self, colItem)
|
||||
newText = ""
|
||||
|
||||
newImageId = col.getImageId(st)
|
||||
else:
|
||||
newImageId = col.getImageId(st)
|
||||
|
||||
colItem.SetText(newText)
|
||||
colItem.SetImage(newImageId)
|
||||
|
||||
BIN
icons/refresh_small.png
Normal file
BIN
icons/refresh_small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 506 B |
@@ -71,6 +71,7 @@ class ShipBrowserWorkerThread(threading.Thread):
|
||||
class PriceWorkerThread(threading.Thread):
|
||||
def run(self):
|
||||
self.queue = Queue.Queue()
|
||||
self.wait = {}
|
||||
self.processUpdates()
|
||||
|
||||
def processUpdates(self):
|
||||
@@ -86,9 +87,21 @@ class PriceWorkerThread(threading.Thread):
|
||||
wx.CallAfter(callback)
|
||||
queue.task_done()
|
||||
|
||||
# After we fetch prices, go through the list of waiting items and call their callbacks
|
||||
for price in requests:
|
||||
callbacks = self.wait.pop(price.typeID, None)
|
||||
if callbacks:
|
||||
for callback in callbacks:
|
||||
wx.CallAfter(callback)
|
||||
|
||||
def trigger(self, prices, callbacks):
|
||||
self.queue.put((callbacks, prices))
|
||||
|
||||
def setToWait(self, itemID, callback):
|
||||
if itemID not in self.wait:
|
||||
self.wait[itemID] = []
|
||||
self.wait[itemID].append(callback)
|
||||
|
||||
class SearchWorkerThread(threading.Thread):
|
||||
def run(self):
|
||||
self.cv = threading.Condition()
|
||||
@@ -719,6 +732,21 @@ class Market():
|
||||
|
||||
self.priceWorkerThread.trigger(requests, cb)
|
||||
|
||||
def waitForPrice(self, item, callback):
|
||||
"""
|
||||
Wait for prices to be fetched and callback when finished. This is used with the column prices for modules.
|
||||
Instead of calling them individually, we set them to wait until the entire fit price is called and calculated
|
||||
(see GH #290)
|
||||
"""
|
||||
|
||||
def cb():
|
||||
try:
|
||||
callback(item)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.priceWorkerThread.setToWait(item.ID, cb)
|
||||
|
||||
def clearPriceCache(self):
|
||||
self.priceCache.clear()
|
||||
deleted_rows = eos.db.clearPrices()
|
||||
|
||||
Reference in New Issue
Block a user