def optimizeFitPrice(self, event): fitID = self.getActiveFit() sFit = Fit.getInstance() fit = sFit.getFit(fitID) if fit: def updateFitCb(replacementsCheaper): del self.waitDialog del self.disablerAll rebaseMap = { k.ID: v.ID for k, v in replacementsCheaper.items() } self.command.Submit( cmd.GuiRebaseItemsCommand(fitID=fitID, rebaseMap=rebaseMap)) fitItems = { i for i in Fit.fitItemIter(fit, forceFitImplants=True) if i is not fit.ship.item } self.disablerAll = wx.WindowDisabler() self.waitDialog = wx.BusyInfo("Please Wait...", parent=self) Price.getInstance().findCheaperReplacements(fitItems, updateFitCb, fetchTimeout=10)
def refreshPanel(self, fit): if fit is not None: self.fit = fit fit_items = set(Fit.fitItemIter(fit)) Price.getInstance().getPrices(fit_items, self.processPrices, fetchTimeout=30) self.labelEMStatus.SetLabel("Updating prices...") self.refreshPanelPrices(fit) self.panel.Layout()
def delayedText(self, mod, display, colItem): sPrice = ServicePrice.getInstance() def callback(item): priceObj = item[0] colItem.SetText(formatPrice(mod, priceObj)) display.SetItem(colItem) sPrice.getPrices([mod.item], callback, waitforthread=True)
def refreshPanel(self, fit): if fit is not None: self.fit = fit fit_items = Price.fitItemsList(fit) sPrice = Price.getInstance() sPrice.getPrices(fit_items, self.processPrices) self.labelEMStatus.SetLabel("Updating prices...") self.refreshPanelPrices(fit) self.panel.Layout()
def delayedText(self, mod, display, colItem): sPrice = ServicePrice.getInstance() def callback(item): priceObj = item[0] colItem.SetText(formatPrice(mod, priceObj)) display.SetItem(colItem) item = mod if isinstance(mod, Item) else mod.item wait = not isinstance(mod, Item) sPrice.getPrices([item], callback, waitforthread=wait)
def delayedText(self, mod, display, colItem): sPrice = ServicePrice.getInstance() def callback(item): price = item[0] text = formatAmount(price.price, 3, 3, 9, currency=True) if price.price else "" if price.failed: text += " (!)" colItem.SetText(text) display.SetItem(colItem) sPrice.getPrices([mod.item], callback, True)
def delayedText(self, mod, display, colItem): sPrice = ServicePrice.getInstance() def callback(item): price = item.item.price text = formatAmount(price.price, 3, 3, 9, currency=True) if price.price else "" if price.failed: text += " (!)" colItem.SetText(text) display.SetItem(colItem) sPrice.getPrices([mod.item], callback, True)
def delayedText(self, mod, display, colItem): sPrice = ServicePrice.getInstance() def callback(item): price = item[0] textItems = [] if price.price: textItems.append(formatAmount(price.price, 3, 3, 9, currency=True)) if price.status == PriceStatus.fail: textItems.append("(!)") colItem.SetText(" ".join(textItems)) display.SetItem(colItem) sPrice.getPrices([mod.item], callback, True)
def exportMultiBuy(fit, options, callback): itemAmounts = {} for module in fit.modules: if module.item: # Mutated items are of no use for multibuy if module.isMutated: continue _addItem(itemAmounts, module.item) if module.charge and options[PortMultiBuyOptions.LOADED_CHARGES]: _addItem(itemAmounts, module.charge, module.numCharges) for drone in fit.drones: _addItem(itemAmounts, drone.item, drone.amount) for fighter in fit.fighters: _addItem(itemAmounts, fighter.item, fighter.amount) if options[PortMultiBuyOptions.CARGO]: for cargo in fit.cargo: _addItem(itemAmounts, cargo.item, cargo.amount) if options[PortMultiBuyOptions.IMPLANTS]: for implant in fit.implants: _addItem(itemAmounts, implant.item) if options[PortMultiBuyOptions.BOOSTERS]: for booster in fit.boosters: _addItem(itemAmounts, booster.item) if options[PortMultiBuyOptions.OPTIMIZE_PRICES]: def formatCheaperExportCb(replacementsCheaper): updatedAmounts = {} for item, itemAmount in itemAmounts.items(): _addItem(updatedAmounts, replacementsCheaper.get(item, item), itemAmount) string = _prepareString(fit.ship.item, updatedAmounts) callback(string) priceSvc = sPrc.getInstance() priceSvc.findCheaperReplacements(itemAmounts, formatCheaperExportCb) else: string = _prepareString(fit.ship.item, itemAmounts) if callback: callback(string) else: return string
def exportMultiBuy(fit, options, callback): itemAmounts = {} for module in fit.modules: if module.item: # Mutated items are of no use for multibuy if module.isMutated: continue _addItem(itemAmounts, module.item) if module.charge and options[PortMultiBuyOptions.LOADED_CHARGES]: _addItem(itemAmounts, module.charge, module.numCharges) for drone in fit.drones: _addItem(itemAmounts, drone.item, drone.amount) for fighter in fit.fighters: _addItem(itemAmounts, fighter.item, fighter.amountActive) if options[PortMultiBuyOptions.CARGO]: for cargo in fit.cargo: _addItem(itemAmounts, cargo.item, cargo.amount) if options[PortMultiBuyOptions.IMPLANTS]: for implant in fit.implants: _addItem(itemAmounts, implant.item) for booster in fit.boosters: _addItem(itemAmounts, booster.item) if options[PortMultiBuyOptions.OPTIMIZE_PRICES]: def formatCheaperExportCb(replacementsCheaper): updatedAmounts = {} for item, itemAmount in itemAmounts.items(): _addItem(updatedAmounts, replacementsCheaper.get(item, item), itemAmount) string = _prepareString(fit.ship.item, updatedAmounts) callback(string) priceSvc = sPrc.getInstance() priceSvc.findCheaperReplacements(itemAmounts, formatCheaperExportCb) else: string = _prepareString(fit.ship.item, itemAmounts) if callback: callback(string) else: return string
def __init__(self, parent, stuff, item, items, context=None): # Start dealing with Price stuff to get that thread going sPrice = ServicePrice.getInstance() sPrice.getPrices(items, self.UpdateList) wx.Panel.__init__(self, parent) mainSizer = wx.BoxSizer(wx.VERTICAL) self.paramList = AutoListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_VRULES | wx.NO_BORDER) mainSizer.Add(self.paramList, 1, wx.ALL | wx.EXPAND, 0) self.SetSizer(mainSizer) self.toggleView = 1 self.stuff = stuff self.currentSort = None self.sortReverse = False self.item = item self.items = sorted(items, key=lambda x: x.attributes['metaLevel'].value if 'metaLevel' in x.attributes else 0) self.attrs = {} # get a dict of attrName: attrInfo of all unique attributes across all items for item in self.items: for attr in list(item.attributes.keys()): if item.attributes[attr].info.displayName: self.attrs[attr] = item.attributes[attr].info # Process attributes for items and find ones that differ for attr in list(self.attrs.keys()): value = None for item in self.items: # we can automatically break here if this item doesn't have the attribute, # as that means at least one item did if attr not in item.attributes: break # this is the first attribute for the item set, set the initial value if value is None: value = item.attributes[attr].value continue if attr not in item.attributes or item.attributes[ attr].value != value: break else: # attribute values were all the same, delete del self.attrs[attr] self.m_staticline = wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) mainSizer.Add(self.m_staticline, 0, wx.EXPAND) bSizer = wx.BoxSizer(wx.HORIZONTAL) self.totalAttrsLabel = wx.StaticText(self, wx.ID_ANY, " ", wx.DefaultPosition, wx.DefaultSize, 0) bSizer.Add(self.totalAttrsLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT) self.toggleViewBtn = wx.ToggleButton(self, wx.ID_ANY, "Toggle view mode", wx.DefaultPosition, wx.DefaultSize, 0) bSizer.Add(self.toggleViewBtn, 0, wx.ALIGN_CENTER_VERTICAL) self.refreshBtn = wx.Button(self, wx.ID_ANY, "Refresh", wx.DefaultPosition, wx.DefaultSize, wx.BU_EXACTFIT) bSizer.Add(self.refreshBtn, 0, wx.ALIGN_CENTER_VERTICAL) self.refreshBtn.Bind(wx.EVT_BUTTON, self.RefreshValues) mainSizer.Add(bSizer, 0, wx.ALIGN_RIGHT) self.PopulateList() self.toggleViewBtn.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleViewMode) self.Bind(wx.EVT_LIST_COL_CLICK, self.SortCompareCols)
def activate(self, fullContext, selection, i): sPrc = Price.getInstance() sPrc.clearPriceCache() wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
def __init__(self, parent, stuff, item, items, context=None): # Start dealing with Price stuff to get that thread going sPrice = ServicePrice.getInstance() sPrice.getPrices(items, self.UpdateList) wx.Panel.__init__(self, parent) mainSizer = wx.BoxSizer(wx.VERTICAL) self.paramList = AutoListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_VRULES | wx.NO_BORDER) mainSizer.Add(self.paramList, 1, wx.ALL | wx.EXPAND, 0) self.SetSizer(mainSizer) self.toggleView = 1 self.stuff = stuff self.currentSort = None self.sortReverse = False self.item = item self.items = sorted(items, key=lambda x: x.attributes['metaLevel'].value if 'metaLevel' in x.attributes else 0) self.attrs = {} # get a dict of attrName: attrInfo of all unique attributes across all items for item in self.items: for attr in list(item.attributes.keys()): if item.attributes[attr].info.displayName: self.attrs[attr] = item.attributes[attr].info # Process attributes for items and find ones that differ for attr in list(self.attrs.keys()): value = None for item in self.items: # we can automatically break here if this item doesn't have the attribute, # as that means at least one item did if attr not in item.attributes: break # this is the first attribute for the item set, set the initial value if value is None: value = item.attributes[attr].value continue if attr not in item.attributes or item.attributes[attr].value != value: break else: # attribute values were all the same, delete del self.attrs[attr] self.m_staticline = wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) mainSizer.Add(self.m_staticline, 0, wx.EXPAND) bSizer = wx.BoxSizer(wx.HORIZONTAL) self.totalAttrsLabel = wx.StaticText(self, wx.ID_ANY, " ", wx.DefaultPosition, wx.DefaultSize, 0) bSizer.Add(self.totalAttrsLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT) self.toggleViewBtn = wx.ToggleButton(self, wx.ID_ANY, "Toggle view mode", wx.DefaultPosition, wx.DefaultSize, 0) bSizer.Add(self.toggleViewBtn, 0, wx.ALIGN_CENTER_VERTICAL) self.refreshBtn = wx.Button(self, wx.ID_ANY, "Refresh", wx.DefaultPosition, wx.DefaultSize, wx.BU_EXACTFIT) bSizer.Add(self.refreshBtn, 0, wx.ALIGN_CENTER_VERTICAL) self.refreshBtn.Bind(wx.EVT_BUTTON, self.RefreshValues) mainSizer.Add(bSizer, 0, wx.ALIGN_RIGHT) self.PopulateList() self.toggleViewBtn.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleViewMode) self.Bind(wx.EVT_LIST_COL_CLICK, self.SortCompareCols)