From a5efea56ab0b563fb339ece5868ef9a382a214a2 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 12:28:36 +0300 Subject: [PATCH 01/15] Change description of export options a little --- service/port/eft.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service/port/eft.py b/service/port/eft.py index 1cc262e78..b1e24c74b 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -53,12 +53,12 @@ OFFLINE_SUFFIX = '/OFFLINE' EFT_OPTIONS = { Options.IMPLANTS.value: { - "name": "Implants", - "description": "Exports implants" + 'name': 'Implants && Boosters', + 'description': 'Exports implants and boosters' }, Options.MUTATIONS.value: { - "name": "Mutated Attributes", - "description": "Exports Abyssal stats" + 'name': 'Mutated Attributes', + 'description': 'Exports mutated modules\' stats' } } From f2deb0e6c754c4d31de6df69b7075ee9b2669f07 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 12:57:27 +0300 Subject: [PATCH 02/15] Make sure order of options doesn't depend on order of options in memory (which can be random as it's dict) --- gui/copySelectDialog.py | 8 ++++---- service/port/eft.py | 14 ++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 10eff2647..4453fab39 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -64,10 +64,10 @@ class CopySelectDialog(wx.Dialog): if format == "EFT": bsizer = wx.BoxSizer(wx.VERTICAL) - for x, v in EFT_OPTIONS.items(): - ch = wx.CheckBox(self, -1, v['name']) - self.options[x] = ch - if self.settings['options'] & x: + for optId, optName, optDesc in EFT_OPTIONS: + ch = wx.CheckBox(self, -1, optName) + self.options[optId] = ch + if self.settings['options'] & optId: ch.SetValue(True) bsizer.Add(ch, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 3) mainSizer.Add(bsizer, 1, wx.EXPAND | wx.LEFT, 20) diff --git a/service/port/eft.py b/service/port/eft.py index b1e24c74b..00525a398 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -51,16 +51,10 @@ MODULE_CATS = ('Module', 'Subsystem', 'Structure Module') SLOT_ORDER = (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM, Slot.SERVICE) OFFLINE_SUFFIX = '/OFFLINE' -EFT_OPTIONS = { - Options.IMPLANTS.value: { - 'name': 'Implants && Boosters', - 'description': 'Exports implants and boosters' - }, - Options.MUTATIONS.value: { - 'name': 'Mutated Attributes', - 'description': 'Exports mutated modules\' stats' - } -} +EFT_OPTIONS = ( + (Options.IMPLANTS.value, 'Implants && Boosters', 'Exports implants and boosters'), + (Options.MUTATIONS.value, 'Mutated Attributes', 'Exports mutated modules\' stats'), +) def exportEft(fit, options): From 98e678107740f3800a4a6d3f6291da7f079dd4d4 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 13:13:00 +0300 Subject: [PATCH 03/15] Make sure order of export formats is also the same --- gui/copySelectDialog.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 4453fab39..d0eba966b 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -18,8 +18,11 @@ # ============================================================================= +from collections import OrderedDict + # noinspection PyPackageRequirements import wx + from service.port.eft import EFT_OPTIONS from service.settings import SettingsProvider @@ -39,14 +42,14 @@ class CopySelectDialog(wx.Dialog): self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": 0}) - self.copyFormats = { - "EFT": CopySelectDialog.copyFormatEft, - "XML": CopySelectDialog.copyFormatXml, - "DNA": CopySelectDialog.copyFormatDna, - "ESI": CopySelectDialog.copyFormatEsi, - "MultiBuy": CopySelectDialog.copyFormatMultiBuy, - "EFS": CopySelectDialog.copyFormatEfs - } + self.copyFormats = OrderedDict(( + ("EFT", CopySelectDialog.copyFormatEft), + ("XML", CopySelectDialog.copyFormatXml), + ("DNA", CopySelectDialog.copyFormatDna), + ("ESI", CopySelectDialog.copyFormatEsi), + ("MultiBuy", CopySelectDialog.copyFormatMultiBuy), + ("EFS", CopySelectDialog.copyFormatEfs), + )) self.options = {} From 3bc1ce195cc42344d85d487bb49783d94aa92b36 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 14:04:28 +0300 Subject: [PATCH 04/15] Change the way we store options --- gui/copySelectDialog.py | 63 ++++++++++++++++++++++++----------------- gui/mainFrame.py | 8 +----- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index d0eba966b..ff992a7f4 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -40,37 +40,44 @@ class CopySelectDialog(wx.Dialog): style=wx.DEFAULT_DIALOG_STYLE) mainSizer = wx.BoxSizer(wx.VERTICAL) - self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": 0}) + self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": {}}) + # Overwrite older options format which was plain int storing EFT options + if not isinstance(self.settings["options"], dict): + self.settings["options"] = {CopySelectDialog.copyFormatEft: self.settings["options"]} self.copyFormats = OrderedDict(( - ("EFT", CopySelectDialog.copyFormatEft), - ("XML", CopySelectDialog.copyFormatXml), - ("DNA", CopySelectDialog.copyFormatDna), - ("ESI", CopySelectDialog.copyFormatEsi), - ("MultiBuy", CopySelectDialog.copyFormatMultiBuy), - ("EFS", CopySelectDialog.copyFormatEfs), + ("EFT", (CopySelectDialog.copyFormatEft, EFT_OPTIONS)), + ("XML", (CopySelectDialog.copyFormatXml, None)), + ("DNA", (CopySelectDialog.copyFormatDna, None)), + ("ESI", (CopySelectDialog.copyFormatEsi, None)), + ("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, None)), + ("EFS", (CopySelectDialog.copyFormatEfs, None)), )) self.options = {} - for i, format in enumerate(self.copyFormats.keys()): - if i == 0: - rdo = wx.RadioButton(self, wx.ID_ANY, format, style=wx.RB_GROUP) + initialized = False + for formatName, formatData in self.copyFormats.items(): + formatId, formatOptions = formatData + if not initialized: + rdo = wx.RadioButton(self, wx.ID_ANY, formatName, style=wx.RB_GROUP) + initialized = True else: - rdo = wx.RadioButton(self, wx.ID_ANY, format) + rdo = wx.RadioButton(self, wx.ID_ANY, formatName) rdo.Bind(wx.EVT_RADIOBUTTON, self.Selected) - if self.settings['format'] == self.copyFormats[format]: + if self.settings['format'] == formatId: rdo.SetValue(True) - self.copyFormat = self.copyFormats[format] + self.copyFormat = formatId mainSizer.Add(rdo, 0, wx.EXPAND | wx.ALL, 5) - if format == "EFT": + if formatOptions: bsizer = wx.BoxSizer(wx.VERTICAL) + self.options[formatId] = {} - for optId, optName, optDesc in EFT_OPTIONS: + for optId, optName, optDesc in formatOptions: ch = wx.CheckBox(self, -1, optName) - self.options[optId] = ch - if self.settings['options'] & optId: + self.options[formatId][optId] = ch + if self.settings['options'].get(formatId, 0) & optId: ch.SetValue(True) bsizer.Add(ch, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 3) mainSizer.Add(bsizer, 1, wx.EXPAND | wx.LEFT, 20) @@ -86,21 +93,25 @@ class CopySelectDialog(wx.Dialog): def Selected(self, event): obj = event.GetEventObject() - format = obj.GetLabel() - self.copyFormat = self.copyFormats[format] + formatName = obj.GetLabel() + self.copyFormat = self.copyFormats[formatName][0] self.toggleOptions() self.Fit() def toggleOptions(self): - for ch in self.options.values(): - ch.Enable(self.GetSelected() == CopySelectDialog.copyFormatEft) + for formatId in self.options: + for optId, checkbox in self.options[formatId].items(): + checkbox.Enable(self.GetSelected() == formatId) def GetSelected(self): return self.copyFormat def GetOptions(self): - i = 0 - for x, v in self.options.items(): - if v.IsChecked(): - i = i ^ x - return i + options = {} + for formatId in self.options: + optVal = 0 + for optId, checkbox in self.options[formatId].items(): + if checkbox.IsChecked(): + optVal = optVal ^ optId + options[formatId] = optVal + return options diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 5f3aa6441..669a5f7c6 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -703,10 +703,6 @@ class MainFrame(wx.Frame): fit = db_getFit(self.getActiveFit()) toClipboard(Port.exportEft(fit, options)) - def clipboardEftImps(self, options): - fit = db_getFit(self.getActiveFit()) - toClipboard(Port.exportEftImps(fit)) - def clipboardDna(self, options): fit = db_getFit(self.getActiveFit()) toClipboard(Port.exportDna(fit)) @@ -744,7 +740,6 @@ class MainFrame(wx.Frame): def exportToClipboard(self, event): CopySelectDict = {CopySelectDialog.copyFormatEft: self.clipboardEft, - # CopySelectDialog.copyFormatEftImps: self.clipboardEftImps, CopySelectDialog.copyFormatXml: self.clipboardXml, CopySelectDialog.copyFormatDna: self.clipboardDna, CopySelectDialog.copyFormatEsi: self.clipboardEsi, @@ -758,8 +753,7 @@ class MainFrame(wx.Frame): settings = SettingsProvider.getInstance().getSettings("pyfaExport") settings["format"] = selected settings["options"] = options - - CopySelectDict[selected](options) + CopySelectDict[selected](options.get(selected)) try: dlg.Destroy() From 59569d46aed784315e9420abf797457d95c50d3a Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 14:11:03 +0300 Subject: [PATCH 05/15] Add implants & boosters option to multibuy export --- gui/copySelectDialog.py | 3 ++- gui/mainFrame.py | 2 +- service/port/eft.py | 11 ++++++----- service/port/multibuy.py | 22 +++++++++++++++++----- service/port/port.py | 4 ++-- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index ff992a7f4..628afd04d 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -24,6 +24,7 @@ from collections import OrderedDict import wx from service.port.eft import EFT_OPTIONS +from service.port.multibuy import MULTIBUY_OPTIONS from service.settings import SettingsProvider @@ -50,7 +51,7 @@ class CopySelectDialog(wx.Dialog): ("XML", (CopySelectDialog.copyFormatXml, None)), ("DNA", (CopySelectDialog.copyFormatDna, None)), ("ESI", (CopySelectDialog.copyFormatEsi, None)), - ("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, None)), + ("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, MULTIBUY_OPTIONS)), ("EFS", (CopySelectDialog.copyFormatEfs, None)), )) diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 669a5f7c6..cfe1cef63 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -717,7 +717,7 @@ class MainFrame(wx.Frame): def clipboardMultiBuy(self, options): fit = db_getFit(self.getActiveFit()) - toClipboard(Port.exportMultiBuy(fit)) + toClipboard(Port.exportMultiBuy(fit, options)) def clipboardEfs(self, options): fit = db_getFit(self.getActiveFit()) diff --git a/service/port/eft.py b/service/port/eft.py index 00525a398..548ef9de4 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -19,6 +19,7 @@ import re +from enum import Enum from logbook import Logger @@ -36,7 +37,6 @@ from service.fit import Fit as svcFit from service.market import Market from service.port.muta import parseMutant, renderMutant from service.port.shared import IPortUser, fetchItem, processing_notify -from enum import Enum pyfalog = Logger(__name__) @@ -47,16 +47,17 @@ class Options(Enum): MUTATIONS = 2 -MODULE_CATS = ('Module', 'Subsystem', 'Structure Module') -SLOT_ORDER = (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM, Slot.SERVICE) -OFFLINE_SUFFIX = '/OFFLINE' - EFT_OPTIONS = ( (Options.IMPLANTS.value, 'Implants && Boosters', 'Exports implants and boosters'), (Options.MUTATIONS.value, 'Mutated Attributes', 'Exports mutated modules\' stats'), ) +MODULE_CATS = ('Module', 'Subsystem', 'Structure Module') +SLOT_ORDER = (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM, Slot.SERVICE) +OFFLINE_SUFFIX = '/OFFLINE' + + def exportEft(fit, options): # EFT formatted export is split in several sections, each section is # separated from another using 2 blank lines. Sections might have several diff --git a/service/port/multibuy.py b/service/port/multibuy.py index f50750e76..4b5ad89fd 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -18,10 +18,21 @@ # ============================================================================= +from enum import Enum + from service.fit import Fit as svcFit -def exportMultiBuy(fit): +class Options(Enum): + IMPLANTS = 1 + + +MULTIBUY_OPTIONS = ( + (Options.IMPLANTS.value, 'Implants && Boosters', 'Exports implants and boosters'), +) + + +def exportMultiBuy(fit, options): itemCounts = {} def addItem(item, quantity=1): @@ -45,11 +56,12 @@ def exportMultiBuy(fit): for cargo in fit.cargo: addItem(cargo.item, cargo.amount) - for implant in fit.implants: - addItem(implant.item) + if options & Options.IMPLANTS.value: + for implant in fit.implants: + addItem(implant.item) - for booster in fit.boosters: - addItem(booster.item) + for booster in fit.boosters: + addItem(booster.item) exportLines = [] exportLines.append(fit.ship.item.name) diff --git a/service/port/port.py b/service/port/port.py index cad3dfae2..409991819 100644 --- a/service/port/port.py +++ b/service/port/port.py @@ -284,5 +284,5 @@ class Port(object): # Multibuy-related methods @staticmethod - def exportMultiBuy(fit): - return exportMultiBuy(fit) + def exportMultiBuy(fit, options): + return exportMultiBuy(fit, options) From 0997a543244425f7303cd93dc2b1aa0f1c923463 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 14:44:38 +0300 Subject: [PATCH 06/15] Add option to export disable cargo export for multibuy --- gui/copySelectDialog.py | 8 ++++---- service/port/eft.py | 4 ++-- service/port/multibuy.py | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 628afd04d..666eeb060 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -76,11 +76,11 @@ class CopySelectDialog(wx.Dialog): self.options[formatId] = {} for optId, optName, optDesc in formatOptions: - ch = wx.CheckBox(self, -1, optName) - self.options[formatId][optId] = ch + checkbox = wx.CheckBox(self, -1, optName) + self.options[formatId][optId] = checkbox if self.settings['options'].get(formatId, 0) & optId: - ch.SetValue(True) - bsizer.Add(ch, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 3) + checkbox.SetValue(True) + bsizer.Add(checkbox, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 3) mainSizer.Add(bsizer, 1, wx.EXPAND | wx.LEFT, 20) buttonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL) diff --git a/service/port/eft.py b/service/port/eft.py index 548ef9de4..91d0b8d47 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -48,8 +48,8 @@ class Options(Enum): EFT_OPTIONS = ( - (Options.IMPLANTS.value, 'Implants && Boosters', 'Exports implants and boosters'), - (Options.MUTATIONS.value, 'Mutated Attributes', 'Exports mutated modules\' stats'), + (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters'), + (Options.MUTATIONS.value, 'Mutated Attributes', 'Export mutated modules\' stats'), ) diff --git a/service/port/multibuy.py b/service/port/multibuy.py index 4b5ad89fd..6a3c4425e 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -25,10 +25,12 @@ from service.fit import Fit as svcFit class Options(Enum): IMPLANTS = 1 + CARGO = 2 MULTIBUY_OPTIONS = ( - (Options.IMPLANTS.value, 'Implants && Boosters', 'Exports implants and boosters'), + (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters'), + (Options.CARGO.value, 'Cargo', 'Export cargo contents'), ) @@ -53,8 +55,9 @@ def exportMultiBuy(fit, options): for fighter in fit.fighters: addItem(fighter.item, fighter.amountActive) - for cargo in fit.cargo: - addItem(cargo.item, cargo.amount) + if options & Options.CARGO.value: + for cargo in fit.cargo: + addItem(cargo.item, cargo.amount) if options & Options.IMPLANTS.value: for implant in fit.implants: From 89656b04ad6b9a790edcddaa745f2bdb2ef4fcc9 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 11 Feb 2019 14:50:44 +0300 Subject: [PATCH 07/15] Do not export mutated items for multibuy --- eos/saveddata/module.py | 4 ++++ service/port/eft.py | 5 ++--- service/port/multibuy.py | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index c4c2f0b00..4ff5113f2 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -965,6 +965,10 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): else: return currState + @property + def isMutated(self): + return bool(self.mutators) + def __deepcopy__(self, memo): item = self.item if item is None: diff --git a/service/port/eft.py b/service/port/eft.py index 91d0b8d47..d7e4174ef 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -80,13 +80,12 @@ def exportEft(fit, options): modules = modsBySlotType.get(slotType, ()) for module in modules: if module.item: - mutated = bool(module.mutators) # if module was mutated, use base item name for export - if mutated: + if module.isMutated: modName = module.baseItem.name else: modName = module.item.name - if mutated and options & Options.MUTATIONS.value: + if module.isMutated and options & Options.MUTATIONS.value: mutants[mutantReference] = module mutationSuffix = ' [{}]'.format(mutantReference) mutantReference += 1 diff --git a/service/port/multibuy.py b/service/port/multibuy.py index 6a3c4425e..550721e18 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -45,6 +45,9 @@ def exportMultiBuy(fit, options): exportCharges = svcFit.getInstance().serviceFittingOptions["exportCharges"] for module in fit.modules: if module.item: + # Mutated items are of no use for multibuy + if module.isMutated: + continue addItem(module.item) if exportCharges and module.charge: addItem(module.charge, module.numCharges) From ce9db79552c453dfe5451568c18dd9b586698c9d Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 08:39:03 +0300 Subject: [PATCH 08/15] Do not redefine property --- eos/saveddata/module.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index 4ff5113f2..c4c2f0b00 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -965,10 +965,6 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): else: return currState - @property - def isMutated(self): - return bool(self.mutators) - def __deepcopy__(self, memo): item = self.item if item is None: From 980c84b911ebae3681160b911bb62bb32b585582 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 10:37:51 +0300 Subject: [PATCH 09/15] Add support for default export option values --- gui/copySelectDialog.py | 33 ++++++++++++++++++++++----------- service/port/eft.py | 4 ++-- service/port/multibuy.py | 4 ++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 666eeb060..10141a1be 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -41,11 +41,6 @@ class CopySelectDialog(wx.Dialog): style=wx.DEFAULT_DIALOG_STYLE) mainSizer = wx.BoxSizer(wx.VERTICAL) - self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": {}}) - # Overwrite older options format which was plain int storing EFT options - if not isinstance(self.settings["options"], dict): - self.settings["options"] = {CopySelectDialog.copyFormatEft: self.settings["options"]} - self.copyFormats = OrderedDict(( ("EFT", (CopySelectDialog.copyFormatEft, EFT_OPTIONS)), ("XML", (CopySelectDialog.copyFormatXml, None)), @@ -55,6 +50,18 @@ class CopySelectDialog(wx.Dialog): ("EFS", (CopySelectDialog.copyFormatEfs, None)), )) + defaultFormatOptions = {} + for formatId, formatOptions in self.copyFormats.values(): + if formatOptions is None: + continue + defaultFormatOptions[formatId] = self._GetFormatOptions( + {option[0]: option[3] for option in formatOptions}) + + self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": defaultFormatOptions}) + # Overwrite older options format which was plain int storing EFT options + if not isinstance(self.settings["options"], dict): + self.settings["options"] = {CopySelectDialog.copyFormatEft: self.settings["options"]} + self.options = {} initialized = False @@ -75,7 +82,7 @@ class CopySelectDialog(wx.Dialog): bsizer = wx.BoxSizer(wx.VERTICAL) self.options[formatId] = {} - for optId, optName, optDesc in formatOptions: + for optId, optName, optDesc, optDefault in formatOptions: checkbox = wx.CheckBox(self, -1, optName) self.options[formatId][optId] = checkbox if self.settings['options'].get(formatId, 0) & optId: @@ -110,9 +117,13 @@ class CopySelectDialog(wx.Dialog): def GetOptions(self): options = {} for formatId in self.options: - optVal = 0 - for optId, checkbox in self.options[formatId].items(): - if checkbox.IsChecked(): - optVal = optVal ^ optId - options[formatId] = optVal + options[formatId] = self._GetFormatOptions( + {optId: ch.IsChecked() for optId, ch in self.options[formatId].items()}) return options + + def _GetFormatOptions(self, optMap): + optVal = 0 + for optId, optState in optMap.items(): + if optState: + optVal = optVal ^ optId + return optVal diff --git a/service/port/eft.py b/service/port/eft.py index d7e4174ef..48b0e5350 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -48,8 +48,8 @@ class Options(Enum): EFT_OPTIONS = ( - (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters'), - (Options.MUTATIONS.value, 'Mutated Attributes', 'Export mutated modules\' stats'), + (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', True), + (Options.MUTATIONS.value, 'Mutated Attributes', 'Export mutated modules\' stats', True), ) diff --git a/service/port/multibuy.py b/service/port/multibuy.py index 550721e18..644836693 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -29,8 +29,8 @@ class Options(Enum): MULTIBUY_OPTIONS = ( - (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters'), - (Options.CARGO.value, 'Cargo', 'Export cargo contents'), + (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', False), + (Options.CARGO.value, 'Cargo', 'Export cargo contents', True), ) From 4324b846e007d1fca7fabb6b57d0864cb7fba81c Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 12:18:42 +0300 Subject: [PATCH 10/15] Disable XML and DNA export --- gui/copySelectDialog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 10141a1be..6ead8c44a 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -43,8 +43,8 @@ class CopySelectDialog(wx.Dialog): self.copyFormats = OrderedDict(( ("EFT", (CopySelectDialog.copyFormatEft, EFT_OPTIONS)), - ("XML", (CopySelectDialog.copyFormatXml, None)), - ("DNA", (CopySelectDialog.copyFormatDna, None)), + # ("XML", (CopySelectDialog.copyFormatXml, None)), + # ("DNA", (CopySelectDialog.copyFormatDna, None)), ("ESI", (CopySelectDialog.copyFormatEsi, None)), ("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, MULTIBUY_OPTIONS)), ("EFS", (CopySelectDialog.copyFormatEfs, None)), From eeef2104c24c0fedb39d50c1c0034b959d3ddb2e Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 13:03:15 +0300 Subject: [PATCH 11/15] Move option of exporting charges from general preferences to EFT and multibuy exports --- gui/builtinPreferenceViews/pyfaGeneralPreferences.py | 9 --------- service/fit.py | 1 - service/port/dna.py | 2 +- service/port/eft.py | 7 ++++--- service/port/esi.py | 2 +- service/port/multibuy.py | 7 +++---- service/port/xml.py | 2 +- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/gui/builtinPreferenceViews/pyfaGeneralPreferences.py b/gui/builtinPreferenceViews/pyfaGeneralPreferences.py index a31e56f8a..51d32ab5d 100644 --- a/gui/builtinPreferenceViews/pyfaGeneralPreferences.py +++ b/gui/builtinPreferenceViews/pyfaGeneralPreferences.py @@ -76,10 +76,6 @@ class PFGeneralPref(PreferenceView): self.cbGaugeAnimation = wx.CheckBox(panel, wx.ID_ANY, "Animate gauges", wx.DefaultPosition, wx.DefaultSize, 0) mainSizer.Add(self.cbGaugeAnimation, 0, wx.ALL | wx.EXPAND, 5) - self.cbExportCharges = wx.CheckBox(panel, wx.ID_ANY, "Export loaded charges", wx.DefaultPosition, - wx.DefaultSize, 0) - mainSizer.Add(self.cbExportCharges, 0, wx.ALL | wx.EXPAND, 5) - self.cbOpenFitInNew = wx.CheckBox(panel, wx.ID_ANY, "Open fittings in a new page by default", wx.DefaultPosition, wx.DefaultSize, 0) mainSizer.Add(self.cbOpenFitInNew, 0, wx.ALL | wx.EXPAND, 5) @@ -133,7 +129,6 @@ class PFGeneralPref(PreferenceView): self.cbShowTooltip.SetValue(self.sFit.serviceFittingOptions["showTooltip"] or False) self.cbMarketShortcuts.SetValue(self.sFit.serviceFittingOptions["showMarketShortcuts"] or False) self.cbGaugeAnimation.SetValue(self.sFit.serviceFittingOptions["enableGaugeAnimation"]) - self.cbExportCharges.SetValue(self.sFit.serviceFittingOptions["exportCharges"]) self.cbOpenFitInNew.SetValue(self.sFit.serviceFittingOptions["openFitInNew"]) self.chPriceSource.SetStringSelection(self.sFit.serviceFittingOptions["priceSource"]) self.chPriceSystem.SetStringSelection(self.sFit.serviceFittingOptions["priceSystem"]) @@ -151,7 +146,6 @@ class PFGeneralPref(PreferenceView): self.cbShowTooltip.Bind(wx.EVT_CHECKBOX, self.onCBShowTooltip) self.cbMarketShortcuts.Bind(wx.EVT_CHECKBOX, self.onCBShowShortcuts) self.cbGaugeAnimation.Bind(wx.EVT_CHECKBOX, self.onCBGaugeAnimation) - self.cbExportCharges.Bind(wx.EVT_CHECKBOX, self.onCBExportCharges) self.cbOpenFitInNew.Bind(wx.EVT_CHECKBOX, self.onCBOpenFitInNew) self.chPriceSource.Bind(wx.EVT_CHOICE, self.onPricesSourceSelection) self.chPriceSystem.Bind(wx.EVT_CHOICE, self.onPriceSelection) @@ -220,9 +214,6 @@ class PFGeneralPref(PreferenceView): def onCBGaugeAnimation(self, event): self.sFit.serviceFittingOptions["enableGaugeAnimation"] = self.cbGaugeAnimation.GetValue() - def onCBExportCharges(self, event): - self.sFit.serviceFittingOptions["exportCharges"] = self.cbExportCharges.GetValue() - def onCBOpenFitInNew(self, event): self.sFit.serviceFittingOptions["openFitInNew"] = self.cbOpenFitInNew.GetValue() diff --git a/service/fit.py b/service/fit.py index ad1e5c4dd..035bb50ee 100644 --- a/service/fit.py +++ b/service/fit.py @@ -89,7 +89,6 @@ class Fit(FitDeprecated): "showTooltip": True, "showMarketShortcuts": False, "enableGaugeAnimation": True, - "exportCharges": True, "openFitInNew": False, "priceSystem": "Jita", "priceSource": "eve-marketdata.com", diff --git a/service/port/dna.py b/service/port/dna.py index bd2645ef8..bc64e9e99 100644 --- a/service/port/dna.py +++ b/service/port/dna.py @@ -138,7 +138,7 @@ def exportDna(fit): mods[mod.itemID] = 0 mods[mod.itemID] += 1 - if mod.charge and sFit.serviceFittingOptions["exportCharges"]: + if mod.charge: if mod.chargeID not in charges: charges[mod.chargeID] = 0 # `or 1` because some charges (ie scripts) are without qty diff --git a/service/port/eft.py b/service/port/eft.py index 48b0e5350..9c48dd1d0 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -45,11 +45,13 @@ pyfalog = Logger(__name__) class Options(Enum): IMPLANTS = 1 MUTATIONS = 2 + LOADED_CHARGES = 3 EFT_OPTIONS = ( - (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', True), + (Options.LOADED_CHARGES.value, 'Loaded Charges', 'Export charges loaded into modules', True), (Options.MUTATIONS.value, 'Mutated Attributes', 'Export mutated modules\' stats', True), + (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', True), ) @@ -68,7 +70,6 @@ def exportEft(fit, options): # Section 1: modules, rigs, subsystems, services modsBySlotType = {} - sFit = svcFit.getInstance() for module in fit.modules: modsBySlotType.setdefault(module.slot, []).append(module) modSection = [] @@ -92,7 +93,7 @@ def exportEft(fit, options): else: mutationSuffix = '' modOfflineSuffix = ' {}'.format(OFFLINE_SUFFIX) if module.state == State.OFFLINE else '' - if module.charge and sFit.serviceFittingOptions['exportCharges']: + if module.charge and options & Options.LOADED_CHARGES.value: rackLines.append('{}, {}{}{}'.format( modName, module.charge.name, modOfflineSuffix, mutationSuffix)) else: diff --git a/service/port/esi.py b/service/port/esi.py index f1e02d13a..8268f23fa 100644 --- a/service/port/esi.py +++ b/service/port/esi.py @@ -97,7 +97,7 @@ def exportESI(ofit): item['type_id'] = module.item.ID fit['items'].append(item) - if module.charge and sFit.serviceFittingOptions["exportCharges"]: + if module.charge: if module.chargeID not in charges: charges[module.chargeID] = 0 # `or 1` because some charges (ie scripts) are without qty diff --git a/service/port/multibuy.py b/service/port/multibuy.py index 644836693..d31b9f33a 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -20,15 +20,15 @@ from enum import Enum -from service.fit import Fit as svcFit - class Options(Enum): IMPLANTS = 1 CARGO = 2 + LOADED_CHARGES = 3 MULTIBUY_OPTIONS = ( + (Options.LOADED_CHARGES.value, 'Loaded Charges', 'Export charges loaded into modules', True), (Options.IMPLANTS.value, 'Implants && Boosters', 'Export implants and boosters', False), (Options.CARGO.value, 'Cargo', 'Export cargo contents', True), ) @@ -42,14 +42,13 @@ def exportMultiBuy(fit, options): itemCounts[item] = 0 itemCounts[item] += quantity - exportCharges = svcFit.getInstance().serviceFittingOptions["exportCharges"] for module in fit.modules: if module.item: # Mutated items are of no use for multibuy if module.isMutated: continue addItem(module.item) - if exportCharges and module.charge: + if module.charge and options & Options.LOADED_CHARGES.value: addItem(module.charge, module.numCharges) for drone in fit.drones: diff --git a/service/port/xml.py b/service/port/xml.py index 54d5a98eb..432bbcdd8 100644 --- a/service/port/xml.py +++ b/service/port/xml.py @@ -283,7 +283,7 @@ def exportXml(iportuser, *fits): hardware.setAttribute("slot", "%s slot %d" % (slotName, slotId)) fitting.appendChild(hardware) - if module.charge and sFit.serviceFittingOptions["exportCharges"]: + if module.charge: if module.charge.name not in charges: charges[module.charge.name] = 0 # `or 1` because some charges (ie scripts) are without qty From d55d6c3e5e53412714380b670486eb127119f3d3 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 13:14:31 +0300 Subject: [PATCH 12/15] Rework the way options are stored --- gui/copySelectDialog.py | 24 ++++++------------------ service/port/eft.py | 8 ++++---- service/port/multibuy.py | 6 +++--- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 6ead8c44a..49ebb6ac1 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -43,24 +43,20 @@ class CopySelectDialog(wx.Dialog): self.copyFormats = OrderedDict(( ("EFT", (CopySelectDialog.copyFormatEft, EFT_OPTIONS)), + ("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, MULTIBUY_OPTIONS)), + ("ESI", (CopySelectDialog.copyFormatEsi, None)), + ("EFS", (CopySelectDialog.copyFormatEfs, None)), # ("XML", (CopySelectDialog.copyFormatXml, None)), # ("DNA", (CopySelectDialog.copyFormatDna, None)), - ("ESI", (CopySelectDialog.copyFormatEsi, None)), - ("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, MULTIBUY_OPTIONS)), - ("EFS", (CopySelectDialog.copyFormatEfs, None)), )) defaultFormatOptions = {} for formatId, formatOptions in self.copyFormats.values(): if formatOptions is None: continue - defaultFormatOptions[formatId] = self._GetFormatOptions( - {option[0]: option[3] for option in formatOptions}) + defaultFormatOptions[formatId] = {opt[0]: opt[3] for opt in formatOptions} self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": defaultFormatOptions}) - # Overwrite older options format which was plain int storing EFT options - if not isinstance(self.settings["options"], dict): - self.settings["options"] = {CopySelectDialog.copyFormatEft: self.settings["options"]} self.options = {} @@ -85,7 +81,7 @@ class CopySelectDialog(wx.Dialog): for optId, optName, optDesc, optDefault in formatOptions: checkbox = wx.CheckBox(self, -1, optName) self.options[formatId][optId] = checkbox - if self.settings['options'].get(formatId, 0) & optId: + if self.settings['options'].get(formatId, {}).get(optId, defaultFormatOptions.get(formatId, {}).get(optId)): checkbox.SetValue(True) bsizer.Add(checkbox, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 3) mainSizer.Add(bsizer, 1, wx.EXPAND | wx.LEFT, 20) @@ -117,13 +113,5 @@ class CopySelectDialog(wx.Dialog): def GetOptions(self): options = {} for formatId in self.options: - options[formatId] = self._GetFormatOptions( - {optId: ch.IsChecked() for optId, ch in self.options[formatId].items()}) + options[formatId] = {optId: ch.IsChecked() for optId, ch in self.options[formatId].items()} return options - - def _GetFormatOptions(self, optMap): - optVal = 0 - for optId, optState in optMap.items(): - if optState: - optVal = optVal ^ optId - return optVal diff --git a/service/port/eft.py b/service/port/eft.py index 9c48dd1d0..4c0d1c6a8 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -86,14 +86,14 @@ def exportEft(fit, options): modName = module.baseItem.name else: modName = module.item.name - if module.isMutated and options & Options.MUTATIONS.value: + if module.isMutated and options[Options.MUTATIONS.value]: mutants[mutantReference] = module mutationSuffix = ' [{}]'.format(mutantReference) mutantReference += 1 else: mutationSuffix = '' modOfflineSuffix = ' {}'.format(OFFLINE_SUFFIX) if module.state == State.OFFLINE else '' - if module.charge and options & Options.LOADED_CHARGES.value: + if module.charge and options[Options.LOADED_CHARGES.value]: rackLines.append('{}, {}{}{}'.format( modName, module.charge.name, modOfflineSuffix, mutationSuffix)) else: @@ -122,7 +122,7 @@ def exportEft(fit, options): sections.append('\n\n'.join(minionSection)) # Section 3: implants, boosters - if options & Options.IMPLANTS.value: + if options[Options.IMPLANTS.value]: charSection = [] implantLines = [] for implant in fit.implants: @@ -149,7 +149,7 @@ def exportEft(fit, options): # Section 5: mutated modules' details mutationLines = [] - if mutants and options & Options.MUTATIONS.value: + if mutants and options[Options.MUTATIONS.value]: 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 d31b9f33a..1c6b78836 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -48,7 +48,7 @@ def exportMultiBuy(fit, options): if module.isMutated: continue addItem(module.item) - if module.charge and options & Options.LOADED_CHARGES.value: + if module.charge and options[Options.LOADED_CHARGES.value]: addItem(module.charge, module.numCharges) for drone in fit.drones: @@ -57,11 +57,11 @@ def exportMultiBuy(fit, options): for fighter in fit.fighters: addItem(fighter.item, fighter.amountActive) - if options & Options.CARGO.value: + if options[Options.CARGO.value]: for cargo in fit.cargo: addItem(cargo.item, cargo.amount) - if options & Options.IMPLANTS.value: + if options[Options.IMPLANTS.value]: for implant in fit.implants: addItem(implant.item) From 9eea99f600050bae2f4fd472aa50e05908514cb0 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 13:28:18 +0300 Subject: [PATCH 13/15] Do not export if user presses cancel --- gui/mainFrame.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gui/mainFrame.py b/gui/mainFrame.py index cfe1cef63..a37f1afd0 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -746,14 +746,16 @@ class MainFrame(wx.Frame): CopySelectDialog.copyFormatMultiBuy: self.clipboardMultiBuy, CopySelectDialog.copyFormatEfs: self.clipboardEfs} dlg = CopySelectDialog(self) - dlg.ShowModal() - selected = dlg.GetSelected() - options = dlg.GetOptions() + btnPressed = dlg.ShowModal() + + if btnPressed == wx.ID_OK: + selected = dlg.GetSelected() + options = dlg.GetOptions() - settings = SettingsProvider.getInstance().getSettings("pyfaExport") - settings["format"] = selected - settings["options"] = options - CopySelectDict[selected](options.get(selected)) + settings = SettingsProvider.getInstance().getSettings("pyfaExport") + settings["format"] = selected + settings["options"] = options + CopySelectDict[selected](options.get(selected)) try: dlg.Destroy() From cf9d2082ef5fd84c2da9d2c710c4fa6b0cf0417e Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 21 Feb 2019 10:44:37 +0300 Subject: [PATCH 14/15] Fix codacy issues --- gui/copySelectDialog.py | 4 ++-- gui/mainFrame.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 49ebb6ac1..26910f466 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -78,7 +78,7 @@ class CopySelectDialog(wx.Dialog): bsizer = wx.BoxSizer(wx.VERTICAL) self.options[formatId] = {} - for optId, optName, optDesc, optDefault in formatOptions: + for optId, optName, optDesc, _ in formatOptions: checkbox = wx.CheckBox(self, -1, optName) self.options[formatId][optId] = checkbox if self.settings['options'].get(formatId, {}).get(optId, defaultFormatOptions.get(formatId, {}).get(optId)): @@ -104,7 +104,7 @@ class CopySelectDialog(wx.Dialog): def toggleOptions(self): for formatId in self.options: - for optId, checkbox in self.options[formatId].items(): + for checkbox in self.options[formatId].values(): checkbox.Enable(self.GetSelected() == formatId) def GetSelected(self): diff --git a/gui/mainFrame.py b/gui/mainFrame.py index a37f1afd0..d5bc8f0e9 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -747,7 +747,7 @@ class MainFrame(wx.Frame): CopySelectDialog.copyFormatEfs: self.clipboardEfs} dlg = CopySelectDialog(self) btnPressed = dlg.ShowModal() - + if btnPressed == wx.ID_OK: selected = dlg.GetSelected() options = dlg.GetOptions() From b2bcdf0a46397d96e9d3a5a411fda76bde2094f7 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 21 Feb 2019 12:16:36 +0300 Subject: [PATCH 15/15] Replace old export option format with new one when needed --- gui/copySelectDialog.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 26910f466..91725e048 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -57,6 +57,10 @@ class CopySelectDialog(wx.Dialog): defaultFormatOptions[formatId] = {opt[0]: opt[3] for opt in formatOptions} self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": defaultFormatOptions}) + # Options used to be stored as int (EFT export options only), + # overwrite them with new format when needed + if isinstance(self.settings["options"], int): + self.settings["options"] = defaultFormatOptions self.options = {}