From 9e96aac04d437030bcbea40f6d52c50f264ac01c Mon Sep 17 00:00:00 2001 From: blitzmann Date: Thu, 4 Jun 2015 14:10:27 -0500 Subject: [PATCH] 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) --- gui/builtinViewColumns/price.py | 9 ++++++--- gui/display.py | 6 +++--- icons/refresh_small.png | Bin 0 -> 506 bytes service/market.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 icons/refresh_small.png diff --git a/gui/builtinViewColumns/price.py b/gui/builtinViewColumns/price.py index 5fe6ef954..be387c8d5 100644 --- a/gui/builtinViewColumns/price.py +++ b/gui/builtinViewColumns/price.py @@ -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 diff --git a/gui/display.py b/gui/display.py index 0cfc28854..cd08a8d1e 100644 --- a/gui/display.py +++ b/gui/display.py @@ -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) diff --git a/icons/refresh_small.png b/icons/refresh_small.png new file mode 100644 index 0000000000000000000000000000000000000000..d3087dfc920b1705cdebc5beeba8a62047c99b68 GIT binary patch literal 506 zcmV-LrYk6ae86R!cq$1)rW52v1)b7{)|O}AG6Uw?DO|Ft)k{$F)%(f{RF=l?I+ zlJnnhy4xL`1{54hojLt{-~Wv_SN(53T=hS3efa;Fl|lb2w&(vZ*_{2~XR7ONye`Pu zoA?0e-~T}W{*PZ9b_gaOFw5hT_Y~(tZoT$Qj_p>QLT-Dpnng!_d8sIiCa_~9WpM}{jZm=`Cltb^#NWN0R6i=Yh}{^)FrY1 zts6}Ln^hV9kC-0#zxPDb|Kx?y|5Z~IXW}#f=--za%M<=jKim6%%IU8E6Hm4O?>pJ@ zzvo2be~`FJvceg~cv%O$F0gC1*cmrB?0?kE;Q#uCTK~1P)&8reDgReaQaGRxhpHK8 wAOih+0O;RKWM?MbJPl^eOx0CX$&G|C05z+&w|oy)!1^@s6 literal 0 HcmV?d00001 diff --git a/service/market.py b/service/market.py index 0ea234aaf..951f31456 100644 --- a/service/market.py +++ b/service/market.py @@ -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()