From cdaf5cc168cff0369279a9e16e477717302ecd6d Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 21 Mar 2019 12:55:39 +0300 Subject: [PATCH 1/4] No need to use .value for IntEnums --- service/port/eft.py | 14 +++++++------- service/port/multibuy.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/service/port/eft.py b/service/port/eft.py index e1c15be7e..1c8086d50 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -43,9 +43,9 @@ from service.port.shared import IPortUser, fetchItem, processing_notify pyfalog = Logger(__name__) EFT_OPTIONS = ( - (PortEftOptions.LOADED_CHARGES.value, 'Loaded Charges', 'Export charges loaded into modules', True), - (PortEftOptions.MUTATIONS.value, 'Mutated Attributes', 'Export mutated modules\' stats', True), - (PortEftOptions.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', True), + (PortEftOptions.LOADED_CHARGES, 'Loaded Charges', 'Export charges loaded into modules', True), + (PortEftOptions.MUTATIONS, 'Mutated Attributes', 'Export mutated modules\' stats', True), + (PortEftOptions.IMPLANTS, 'Implants && Boosters', 'Export implants and boosters', True), ) @@ -80,14 +80,14 @@ def exportEft(fit, options, callback): modName = module.baseItem.name else: modName = module.item.name - if module.isMutated and options[PortEftOptions.MUTATIONS.value]: + if module.isMutated and options[PortEftOptions.MUTATIONS]: mutants[mutantReference] = module mutationSuffix = ' [{}]'.format(mutantReference) mutantReference += 1 else: mutationSuffix = '' modOfflineSuffix = ' {}'.format(OFFLINE_SUFFIX) if module.state == FittingModuleState.OFFLINE else '' - if module.charge and options[PortEftOptions.LOADED_CHARGES.value]: + if module.charge and options[PortEftOptions.LOADED_CHARGES]: rackLines.append('{}, {}{}{}'.format( modName, module.charge.name, modOfflineSuffix, mutationSuffix)) else: @@ -116,7 +116,7 @@ def exportEft(fit, options, callback): sections.append('\n\n'.join(minionSection)) # Section 3: implants, boosters - if options[PortEftOptions.IMPLANTS.value]: + if options[PortEftOptions.IMPLANTS]: charSection = [] implantLines = [] for implant in fit.implants: @@ -143,7 +143,7 @@ def exportEft(fit, options, callback): # Section 5: mutated modules' details mutationLines = [] - if mutants and options[PortEftOptions.MUTATIONS.value]: + if mutants and options[PortEftOptions.MUTATIONS]: for mutantReference in sorted(mutants): mutant = mutants[mutantReference] mutationLines.append(renderMutant(mutant, firstPrefix='[{}] '.format(mutantReference), prefix=' ')) diff --git a/service/port/multibuy.py b/service/port/multibuy.py index fbb099a6d..2dfe7eff8 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -23,10 +23,10 @@ from service.price import Price as sPrc MULTIBUY_OPTIONS = ( - (PortMultiBuyOptions.LOADED_CHARGES.value, 'Loaded Charges', 'Export charges loaded into modules', True), - (PortMultiBuyOptions.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', False), - (PortMultiBuyOptions.CARGO.value, 'Cargo', 'Export cargo contents', True), - (PortMultiBuyOptions.OPTIMIZE_PRICES.value, 'Optimize Prices', 'Replace items by cheaper alternatives', False), + (PortMultiBuyOptions.LOADED_CHARGES, 'Loaded Charges', 'Export charges loaded into modules', True), + (PortMultiBuyOptions.IMPLANTS, 'Implants && Boosters', 'Export implants and boosters', False), + (PortMultiBuyOptions.CARGO, 'Cargo', 'Export cargo contents', True), + (PortMultiBuyOptions.OPTIMIZE_PRICES, 'Optimize Prices', 'Replace items by cheaper alternatives', False), ) @@ -39,7 +39,7 @@ def exportMultiBuy(fit, options, callback): if module.isMutated: continue _addItem(itemAmounts, module.item) - if module.charge and options[PortMultiBuyOptions.LOADED_CHARGES.value]: + if module.charge and options[PortMultiBuyOptions.LOADED_CHARGES]: _addItem(itemAmounts, module.charge, module.numCharges) for drone in fit.drones: @@ -48,18 +48,18 @@ def exportMultiBuy(fit, options, callback): for fighter in fit.fighters: _addItem(itemAmounts, fighter.item, fighter.amountActive) - if options[PortMultiBuyOptions.CARGO.value]: + if options[PortMultiBuyOptions.CARGO]: for cargo in fit.cargo: _addItem(itemAmounts, cargo.item, cargo.amount) - if options[PortMultiBuyOptions.IMPLANTS.value]: + 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.value]: + if options[PortMultiBuyOptions.OPTIMIZE_PRICES]: def formatCheaperExportCb(replacementsCheaper): updatedAmounts = {} From 6291fe16263eab02583af8a01bc242b90d669487 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 21 Mar 2019 13:01:21 +0300 Subject: [PATCH 2/4] Fix HTML export (#1890) --- gui/utils/exportHtml.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gui/utils/exportHtml.py b/gui/utils/exportHtml.py index d1c0af9d0..608b52396 100644 --- a/gui/utils/exportHtml.py +++ b/gui/utils/exportHtml.py @@ -2,6 +2,7 @@ import threading import time # noinspection PyPackageRequirements import wx +from service.const import PortEftOptions from service.settings import HTMLExportSettings from service.fit import Fit from service.port import Port @@ -208,8 +209,10 @@ class exportHtmlThread(threading.Thread): if self.stopRunning: return try: - eftFit = Port.exportEft(getFit(fit[0])) - print(eftFit) + eftFit = Port.exportEft(getFit(fit[0]), options={ + PortEftOptions.IMPLANTS: True, + PortEftOptions.MUTATIONS: True, + PortEftOptions.LOADED_CHARGES: True}) HTMLfit = ( '
  • Date: Thu, 21 Mar 2019 23:55:25 +0300 Subject: [PATCH 3/4] Sort boosters by slot --- gui/builtinAdditionPanes/boosterView.py | 3 +++ service/port/eft.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gui/builtinAdditionPanes/boosterView.py b/gui/builtinAdditionPanes/boosterView.py index 11bac08ca..eda07eb5e 100644 --- a/gui/builtinAdditionPanes/boosterView.py +++ b/gui/builtinAdditionPanes/boosterView.py @@ -110,6 +110,9 @@ class BoosterView(d.Display): self.origional = fit.boosters if fit is not None else None self.boosters = stuff = fit.boosters[:] if fit is not None else None + if stuff is not None: + stuff.sort(key=lambda booster: booster.slot or 0) + if event.fitID != self.lastFitId: self.lastFitId = event.fitID diff --git a/service/port/eft.py b/service/port/eft.py index 1c8086d50..9206cba32 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -119,12 +119,12 @@ def exportEft(fit, options, callback): if options[PortEftOptions.IMPLANTS]: charSection = [] implantLines = [] - for implant in fit.implants: + for implant in sorted(fit.implants, key=lambda i: i.slot or 0): implantLines.append(implant.item.name) if implantLines: charSection.append('\n'.join(implantLines)) boosterLines = [] - for booster in fit.boosters: + for booster in sorted(fit.boosters, key=lambda b: b.slot): boosterLines.append(booster.item.name) if boosterLines: charSection.append('\n'.join(boosterLines)) From 8380f516e829e3f3d337078fedb1c29581148e14 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 21 Mar 2019 23:56:44 +0300 Subject: [PATCH 4/4] Add fallback for safety --- service/port/eft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/port/eft.py b/service/port/eft.py index 9206cba32..b6c57967f 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -124,7 +124,7 @@ def exportEft(fit, options, callback): if implantLines: charSection.append('\n'.join(implantLines)) boosterLines = [] - for booster in sorted(fit.boosters, key=lambda b: b.slot): + for booster in sorted(fit.boosters, key=lambda b: b.slot or 0): boosterLines.append(booster.item.name) if boosterLines: charSection.append('\n'.join(boosterLines))