From a7ce1d3e0fa39f3a76ce44e5ae37f524b1d843c8 Mon Sep 17 00:00:00 2001 From: P Date: Thu, 16 Aug 2018 05:55:57 -0700 Subject: [PATCH 01/19] added insurance endpoint/no character get function --- service/esi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/esi.py b/service/esi.py index 4b5f8198f8..d51f8d99c7 100644 --- a/service/esi.py +++ b/service/esi.py @@ -77,6 +77,10 @@ def getSsoCharacter(self, id): eos.db.commit() return char + def getInsurance(self): + resp = super().getInsurance() + return resp.json() + def getSkills(self, id): char = self.getSsoCharacter(id) resp = super().getSkills(char) From 404df836294fe39b407595094e37e1a588a120dd Mon Sep 17 00:00:00 2001 From: P Date: Thu, 16 Aug 2018 05:56:18 -0700 Subject: [PATCH 02/19] added insurance endpoint/no character get function --- service/esiAccess.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service/esiAccess.py b/service/esiAccess.py index bbddc63848..82b5f08818 100644 --- a/service/esiAccess.py +++ b/service/esiAccess.py @@ -71,6 +71,7 @@ class ESIEndpoints(Enum): CHAR_SKILLS = "/v4/characters/{character_id}/skills/" CHAR_FITTINGS = "/v1/characters/{character_id}/fittings/" CHAR_DEL_FIT = "/v1/characters/{character_id}/fittings/{fitting_id}/" + INSURANCE = "/v1/insurance/prices/" class EsiAccess(object): @@ -109,6 +110,9 @@ def oauth_authorize(self): def oauth_token(self): return '%s/oauth/token' % self.sso_url + def getInsurance(self): + return self.get_nochar(ESIEndpoints.INSURANCE) + def getSkills(self, char): return self.get(char, ESIEndpoints.CHAR_SKILLS, character_id=char.characterID) @@ -268,6 +272,10 @@ def _after_request(self, resp): return resp + def get_nochar(self, endpoint, *args, **kwargs): + endpoint = endpoint.format(**kwargs) + return self._after_request(self._session.get("{}{}".format(self.esi_url, endpoint))) + def get(self, ssoChar, endpoint, *args, **kwargs): self._before_request(ssoChar) endpoint = endpoint.format(**kwargs) From 18ff28856edb70e235d37f49f602067038074aac Mon Sep 17 00:00:00 2001 From: P Date: Fri, 17 Aug 2018 01:01:47 -0700 Subject: [PATCH 03/19] initial insurance file --- service/insurance.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 service/insurance.py diff --git a/service/insurance.py b/service/insurance.py new file mode 100644 index 0000000000..ace5a17900 --- /dev/null +++ b/service/insurance.py @@ -0,0 +1,44 @@ +import sys +from logbook import Logger +import threading +from service.esi import Esi + +pyfalog = Logger(__name__) + + +class Insurance(): + instance = None + + @classmethod + def getInstance(cls): + if cls.instance is None: + cls.instance = Insurance() + + return cls.instance + + def __init__(self): + self.__testvariable = 5 + + def apiFetch(self, callback): + thread = InsuranceImportThread((self.apiFetchCallback, callback)) + thread.start() + + def apiFetchCallback(self, response, othercallback, e=None): + pyfalog.info(response) + wx.CallAfter(othercallback, e) + + +class InsuranceImportThread(threading.Thread): + def __init__(self, callback): + threading.Thread.__init__(self) + self.name = "InsuranceImport" + self.callback = callback + + def run(self): + try: + sEsi = Esi.getInstance() + resp = sEsi.getInsurance() + self.callback[0](resp, self.callback[1]) + except Exception as ex: + pyfalog.warn(ex) + self.callback[0](None, self.callback[1](sys.exc_info())) From fc6c4cdf6074dfde23a2ee6f1659c84849e19500 Mon Sep 17 00:00:00 2001 From: P Date: Fri, 17 Aug 2018 03:10:35 -0700 Subject: [PATCH 04/19] modified to use existing get function --- service/esiAccess.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/service/esiAccess.py b/service/esiAccess.py index 82b5f08818..00c7a54850 100644 --- a/service/esiAccess.py +++ b/service/esiAccess.py @@ -111,7 +111,7 @@ def oauth_token(self): return '%s/oauth/token' % self.sso_url def getInsurance(self): - return self.get_nochar(ESIEndpoints.INSURANCE) + return self.get(None, ESIEndpoints.INSURANCE) def getSkills(self, char): return self.get(char, ESIEndpoints.CHAR_SKILLS, character_id=char.characterID) @@ -272,12 +272,9 @@ def _after_request(self, resp): return resp - def get_nochar(self, endpoint, *args, **kwargs): - endpoint = endpoint.format(**kwargs) - return self._after_request(self._session.get("{}{}".format(self.esi_url, endpoint))) - def get(self, ssoChar, endpoint, *args, **kwargs): - self._before_request(ssoChar) + if ssoChar: + self._before_request(ssoChar) endpoint = endpoint.format(**kwargs) return self._after_request(self._session.get("{}{}".format(self.esi_url, endpoint))) From 0654d9018f9dba8937ff77063567c02a395cb7cf Mon Sep 17 00:00:00 2001 From: P Date: Fri, 17 Aug 2018 03:12:10 -0700 Subject: [PATCH 05/19] threaded load esi insurance info on start --- pyfa.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyfa.py b/pyfa.py index 740d443abf..49d8a041f8 100755 --- a/pyfa.py +++ b/pyfa.py @@ -138,6 +138,11 @@ def _process_args(self, largs, rargs, values): mf = MainFrame(options.title) ErrorHandler.SetParent(mf) + from service.insurance import Insurance + # Needs to be performed after wx init + sInsurance = Insurance.getInstance() + sInsurance.apiFetch(lambda response: pyfalog.debug(str(response))) + if options.profile_path: profile_path = os.path.join(options.profile_path, 'pyfa-{}.profile'.format(datetime.datetime.now().strftime('%Y%m%d_%H%M%S'))) pyfalog.debug("Starting pyfa with a profiler, saving to {}".format(profile_path)) From b58f8af298d9fb2416efc50b7bcd56d92aefa656 Mon Sep 17 00:00:00 2001 From: P Date: Fri, 17 Aug 2018 03:13:44 -0700 Subject: [PATCH 06/19] refactor, caller callback passes error instead of response if error --- service/insurance.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/service/insurance.py b/service/insurance.py index ace5a17900..5f9e18ba0b 100644 --- a/service/insurance.py +++ b/service/insurance.py @@ -1,6 +1,7 @@ import sys -from logbook import Logger +import wx import threading +from logbook import Logger from service.esi import Esi pyfalog = Logger(__name__) @@ -17,18 +18,22 @@ def getInstance(cls): return cls.instance def __init__(self): - self.__testvariable = 5 + self.allInsurance = None - def apiFetch(self, callback): - thread = InsuranceImportThread((self.apiFetchCallback, callback)) + def apiFetch(self, callerCallback): + thread = InsuranceApiThread((self.insuranceApiCallback, callerCallback)) thread.start() - def apiFetchCallback(self, response, othercallback, e=None): - pyfalog.info(response) - wx.CallAfter(othercallback, e) + # Modify the Insurance class with data from the threaded api call if there were no errors + def insuranceApiCallback(self, response, callerCallback, e=None): + if e: + wx.CallAfter(callerCallback, e) + else: + self.allInsurance = response + wx.CallAfter(callerCallback, response) -class InsuranceImportThread(threading.Thread): +class InsuranceApiThread(threading.Thread): def __init__(self, callback): threading.Thread.__init__(self) self.name = "InsuranceImport" @@ -41,4 +46,4 @@ def run(self): self.callback[0](resp, self.callback[1]) except Exception as ex: pyfalog.warn(ex) - self.callback[0](None, self.callback[1](sys.exc_info())) + self.callback[0](None, self.callback[1], sys.exc_info()) \ No newline at end of file From 119036c867565974b8e67f19e5f404d3130249c3 Mon Sep 17 00:00:00 2001 From: P Date: Fri, 17 Aug 2018 23:36:51 -0700 Subject: [PATCH 07/19] added function to get insurance of single ship --- service/insurance.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service/insurance.py b/service/insurance.py index 5f9e18ba0b..a945bb4ed1 100644 --- a/service/insurance.py +++ b/service/insurance.py @@ -32,6 +32,14 @@ def insuranceApiCallback(self, response, callerCallback, e=None): self.allInsurance = response wx.CallAfter(callerCallback, response) + def getInsurance(self, typeID): + if self.allInsurance: + # Search the insurance list for the first item that has the typeID we are looking for + try: + return next(iter([item for item in self.allInsurance if item.get('type_id') == typeID]))['levels'] + except StopIteration: + return None + class InsuranceApiThread(threading.Thread): def __init__(self, callback): From e07da8dd1d60df3db7379cea0b50722b671cf498 Mon Sep 17 00:00:00 2001 From: P Date: Fri, 17 Aug 2018 23:38:47 -0700 Subject: [PATCH 08/19] added insurance to price panel populate, refresh is next --- gui/builtinStatsViews/priceViewFull.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gui/builtinStatsViews/priceViewFull.py b/gui/builtinStatsViews/priceViewFull.py index 9eb03ea22a..8f82101016 100644 --- a/gui/builtinStatsViews/priceViewFull.py +++ b/gui/builtinStatsViews/priceViewFull.py @@ -24,6 +24,7 @@ from gui.utils.numberFormatter import formatAmount from service.price import Price from service.settings import PriceMenuSettings +from service.insurance import Insurance class PriceViewFull(StatsView): @@ -33,6 +34,7 @@ def __init__(self, parent): StatsView.__init__(self) self.parent = parent self.settings = PriceMenuSettings.getInstance() + self.insuranceLevels = None def getHeaderText(self, fit): return "Price" @@ -76,6 +78,28 @@ def populatePanel(self, contentPanel, headerPanel): setattr(self, "labelPrice%s" % _type.capitalize(), lbl) hbox.Add(lbl, 0, wx.ALIGN_LEFT) + gridInsuranceHeader = wx.GridSizer(1, 1, 0, 0) + contentSizer.Add(gridInsuranceHeader, 0, wx.EXPAND | wx.ALL, 0) + + box = wx.BoxSizer(wx.HORIZONTAL) + gridInsuranceHeader.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Insurance Prices:"), 0, wx.ALIGN_LEFT) + + gridInsuranceValues = wx.GridSizer(5, 2, 0, 0) + contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) + + for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, level), 0, wx.ALIGN_CENTER) + + lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") + setattr(self, "insurancePrice%s" % level, lbl) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(lbl, 0, wx.ALIGN_LEFT) + def refreshPanel(self, fit): if fit is not None: self.fit = fit @@ -86,9 +110,16 @@ def refreshPanel(self, fit): sPrice.getPrices(fit_items, self.processPrices) self.labelEMStatus.SetLabel("Updating prices...") + sInsurance = Insurance.getInstance() + self.insuranceLevels = sInsurance.getInsurance(fit.ship.item.ID) + self.refreshPanelPrices(fit) + self.refreshInsurancePrices(fit) self.panel.Layout() + def refreshInsurancePrices(self, fit=None): + pass + def refreshPanelPrices(self, fit=None): ship_price = 0 From f290014af57f7eda9aa14b4cf6bdee9f1f56fd81 Mon Sep 17 00:00:00 2001 From: P Date: Sat, 18 Aug 2018 04:36:53 -0700 Subject: [PATCH 09/19] all insurance implemented in price pane --- gui/builtinStatsViews/priceViewFull.py | 34 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/gui/builtinStatsViews/priceViewFull.py b/gui/builtinStatsViews/priceViewFull.py index 8f82101016..5054d8095e 100644 --- a/gui/builtinStatsViews/priceViewFull.py +++ b/gui/builtinStatsViews/priceViewFull.py @@ -85,16 +85,26 @@ def populatePanel(self, contentPanel, headerPanel): gridInsuranceHeader.Add(box, 0, wx.ALIGN_TOP) box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Insurance Prices:"), 0, wx.ALIGN_LEFT) - gridInsuranceValues = wx.GridSizer(5, 2, 0, 0) + gridInsuranceValues = wx.GridSizer(5, 3, 0, 0) contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: + # Insurance type box = wx.BoxSizer(wx.VERTICAL) gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) box.Add(wx.StaticText(contentPanel, wx.ID_ANY, level), 0, wx.ALIGN_CENTER) + # Insurance cost lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") - setattr(self, "insurancePrice%s" % level, lbl) + setattr(self, "labelInsuranceCost%s" % level, lbl) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(lbl, 0, wx.ALIGN_LEFT) + + # Insurance payout + lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") + setattr(self, "labelInsurancePayout%s" % level, lbl) box = wx.BoxSizer(wx.VERTICAL) gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) @@ -114,11 +124,25 @@ def refreshPanel(self, fit): self.insuranceLevels = sInsurance.getInsurance(fit.ship.item.ID) self.refreshPanelPrices(fit) - self.refreshInsurancePrices(fit) + self.refreshInsurancePrices() self.panel.Layout() - def refreshInsurancePrices(self, fit=None): - pass + def refreshInsurancePrices(self): + if self.insuranceLevels: + self.labelInsuranceCostBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('payout'), 3, 3, 9, currency=True)) def refreshPanelPrices(self, fit=None): From 64e7b82f3378bd83005e6c084ef5767cbe49d006 Mon Sep 17 00:00:00 2001 From: P Date: Sat, 18 Aug 2018 05:15:24 -0700 Subject: [PATCH 10/19] removed insurance from this panel --- gui/builtinStatsViews/priceViewFull.py | 57 +------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/gui/builtinStatsViews/priceViewFull.py b/gui/builtinStatsViews/priceViewFull.py index 5054d8095e..b72566a37d 100644 --- a/gui/builtinStatsViews/priceViewFull.py +++ b/gui/builtinStatsViews/priceViewFull.py @@ -24,7 +24,6 @@ from gui.utils.numberFormatter import formatAmount from service.price import Price from service.settings import PriceMenuSettings -from service.insurance import Insurance class PriceViewFull(StatsView): @@ -34,7 +33,6 @@ def __init__(self, parent): StatsView.__init__(self) self.parent = parent self.settings = PriceMenuSettings.getInstance() - self.insuranceLevels = None def getHeaderText(self, fit): return "Price" @@ -78,38 +76,6 @@ def populatePanel(self, contentPanel, headerPanel): setattr(self, "labelPrice%s" % _type.capitalize(), lbl) hbox.Add(lbl, 0, wx.ALIGN_LEFT) - gridInsuranceHeader = wx.GridSizer(1, 1, 0, 0) - contentSizer.Add(gridInsuranceHeader, 0, wx.EXPAND | wx.ALL, 0) - - box = wx.BoxSizer(wx.HORIZONTAL) - gridInsuranceHeader.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Insurance Prices:"), 0, wx.ALIGN_LEFT) - - gridInsuranceValues = wx.GridSizer(5, 3, 0, 0) - contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) - - for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: - # Insurance type - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, level), 0, wx.ALIGN_CENTER) - - # Insurance cost - lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") - setattr(self, "labelInsuranceCost%s" % level, lbl) - - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(lbl, 0, wx.ALIGN_LEFT) - - # Insurance payout - lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") - setattr(self, "labelInsurancePayout%s" % level, lbl) - - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(lbl, 0, wx.ALIGN_LEFT) - def refreshPanel(self, fit): if fit is not None: self.fit = fit @@ -120,30 +86,9 @@ def refreshPanel(self, fit): sPrice.getPrices(fit_items, self.processPrices) self.labelEMStatus.SetLabel("Updating prices...") - sInsurance = Insurance.getInstance() - self.insuranceLevels = sInsurance.getInsurance(fit.ship.item.ID) - self.refreshPanelPrices(fit) - self.refreshInsurancePrices() self.panel.Layout() - def refreshInsurancePrices(self): - if self.insuranceLevels: - self.labelInsuranceCostBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('payout'), 3, 3, 9, currency=True)) - def refreshPanelPrices(self, fit=None): ship_price = 0 @@ -221,4 +166,4 @@ def processPrices(self, prices): self.panel.Layout() -PriceViewFull.register() +PriceViewFull.register() \ No newline at end of file From 7596b823fe91eba99254470126aee15bb4430c6b Mon Sep 17 00:00:00 2001 From: P Date: Sat, 18 Aug 2018 05:19:21 -0700 Subject: [PATCH 11/19] added insurance/added insurance display optino to settings --- .../pyfaStatViewPreferences.py | 9 ++ gui/builtinStatsViews/__init__.py | 1 + gui/builtinStatsViews/insuranceViewFull.py | 101 ++++++++++++++++++ gui/statsPane.py | 1 + gui/statsView.py | 1 + service/settings.py | 1 + 6 files changed, 114 insertions(+) create mode 100644 gui/builtinStatsViews/insuranceViewFull.py diff --git a/gui/builtinPreferenceViews/pyfaStatViewPreferences.py b/gui/builtinPreferenceViews/pyfaStatViewPreferences.py index e9e0d8cb09..41810e2e16 100644 --- a/gui/builtinPreferenceViews/pyfaStatViewPreferences.py +++ b/gui/builtinPreferenceViews/pyfaStatViewPreferences.py @@ -99,6 +99,12 @@ def populatePanel(self, panel): self.rbOutgoing.SetSelection(self.settings.get('outgoing')) rbSizerRow3.Add(self.rbOutgoing, 1, wx.TOP | wx.RIGHT, 5) self.rbOutgoing.Bind(wx.EVT_RADIOBOX, self.OnOutgoingChange) + + self.rbInsurance = wx.RadioBox(panel, -1, "Insurance", wx.DefaultPosition, wx.DefaultSize, ['None', 'Minimal', 'Full'], 1, wx.RA_SPECIFY_COLS) + self.rbInsurance.EnableItem(1, False) + self.rbInsurance.SetSelection(self.settings.get('insurance')) + rbSizerRow3.Add(self.rbInsurance, 1, wx.TOP | wx.RIGHT, 5) + self.rbInsurance.Bind(wx.EVT_RADIOBOX, self.OnInsuranceChange) # We don't have views for these.....yet ''' self.rbMining = wx.RadioBox(panel, -1, "Mining", wx.DefaultPosition, wx.DefaultSize, @@ -143,6 +149,9 @@ def OnPriceChange(self, event): def OnOutgoingChange(self, event): self.settings.set('outgoing', event.GetInt()) + def OnInsuranceChange(self, event): + self.settings.set('insurance', event.GetInt()) + def OnMiningYieldChange(self, event): self.settings.set('miningyield', event.GetInt()) diff --git a/gui/builtinStatsViews/__init__.py b/gui/builtinStatsViews/__init__.py index 8769c7aefa..dd4a542e40 100644 --- a/gui/builtinStatsViews/__init__.py +++ b/gui/builtinStatsViews/__init__.py @@ -9,4 +9,5 @@ "targetingMiscViewMinimal", "priceViewFull", "priceViewMinimal", + "insuranceViewFull", ] diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py new file mode 100644 index 0000000000..21d68c6986 --- /dev/null +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -0,0 +1,101 @@ +# ============================================================================= +# Copyright (C) 2010 Diego Duclos +# +# This file is part of pyfa. +# +# pyfa is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# pyfa is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with pyfa. If not, see . +# ============================================================================= + +import wx +from gui.statsView import StatsView +from gui.utils.numberFormatter import formatAmount +from service.insurance import Insurance + + +class InsuranceViewFull(StatsView): + name = "insuranceViewFull" + + def __init__(self, parent): + StatsView.__init__(self) + self.parent = parent + self.insuranceLevels = None + + def getHeaderText(self, fit): + return "Insurance" + + def populatePanel(self, contentPanel, headerPanel): + contentSizer = contentPanel.GetSizer() + self.panel = contentPanel + self.headerPanel = headerPanel + + headerContentSizer = wx.BoxSizer(wx.HORIZONTAL) + hsizer = headerPanel.GetSizer() + hsizer.Add(headerContentSizer, 0, 0, 0) + self.labelEMStatus = wx.StaticText(headerPanel, wx.ID_ANY, "") + headerContentSizer.Add(self.labelEMStatus) + headerPanel.GetParent().AddToggleItem(self.labelEMStatus) + + gridInsuranceValues = wx.GridSizer(5, 3, 0, 0) + contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) + + for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: + # Insurance type + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, level), 0, wx.ALIGN_CENTER) + + # Insurance cost + lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") + setattr(self, "labelInsuranceCost%s" % level, lbl) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(lbl, 0, wx.ALIGN_LEFT) + + # Insurance payout + lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") + setattr(self, "labelInsurancePayout%s" % level, lbl) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(lbl, 0, wx.ALIGN_LEFT) + + def refreshPanel(self, fit): + if fit is not None: + self.labelEMStatus.SetLabel("Updating Insurance...") + sInsurance = Insurance.getInstance() + self.insuranceLevels = sInsurance.getInsurance(fit.ship.item.ID) + + self.refreshInsurancePanelPrices() + self.panel.Layout() + + def refreshInsurancePanelPrices(self): + if self.insuranceLevels: + self.labelInsuranceCostBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('payout'), 3, 3, 9, currency=True)) + + self.labelInsuranceCostPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('cost'), 3, 3, 9, currency=True)) + self.labelInsurancePayoutPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('payout'), 3, 3, 9, currency=True)) + + +InsuranceViewFull.register() diff --git a/gui/statsPane.py b/gui/statsPane.py index b3984ccfa9..c33b9a16f2 100644 --- a/gui/statsPane.py +++ b/gui/statsPane.py @@ -44,6 +44,7 @@ class StatsPane(wx.Panel): "capacitor", "targetingMisc", "price", + "insurance", ] # Don't have these....yet.... diff --git a/gui/statsView.py b/gui/statsView.py index dc4c0276b0..50d2c45edb 100644 --- a/gui/statsView.py +++ b/gui/statsView.py @@ -55,4 +55,5 @@ def refreshPanel(self, fit): priceViewMinimal, outgoingViewFull, outgoingViewMinimal, + insuranceViewFull, ) diff --git a/service/settings.py b/service/settings.py index 75bdb54057..a1c13856b6 100644 --- a/service/settings.py +++ b/service/settings.py @@ -431,6 +431,7 @@ def __init__(self): "miningyield" : 2, "drones" : 2, "outgoing" : 2, + "insurance" : 2, } # We don't have these....yet From 9e8a57daabd4a5dbb4683ec9a8f8376f724dc90b Mon Sep 17 00:00:00 2001 From: P Date: Sat, 18 Aug 2018 05:29:30 -0700 Subject: [PATCH 12/19] removed EM and header info sice we are pulling from Insurance class which has data preloaded --- gui/builtinStatsViews/insuranceViewFull.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py index 21d68c6986..f75c93f361 100644 --- a/gui/builtinStatsViews/insuranceViewFull.py +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -39,13 +39,6 @@ def populatePanel(self, contentPanel, headerPanel): self.panel = contentPanel self.headerPanel = headerPanel - headerContentSizer = wx.BoxSizer(wx.HORIZONTAL) - hsizer = headerPanel.GetSizer() - hsizer.Add(headerContentSizer, 0, 0, 0) - self.labelEMStatus = wx.StaticText(headerPanel, wx.ID_ANY, "") - headerContentSizer.Add(self.labelEMStatus) - headerPanel.GetParent().AddToggleItem(self.labelEMStatus) - gridInsuranceValues = wx.GridSizer(5, 3, 0, 0) contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) @@ -73,7 +66,6 @@ def populatePanel(self, contentPanel, headerPanel): def refreshPanel(self, fit): if fit is not None: - self.labelEMStatus.SetLabel("Updating Insurance...") sInsurance = Insurance.getInstance() self.insuranceLevels = sInsurance.getInsurance(fit.ship.item.ID) From 5f5029698daa01989dd70fa4d4e7e4f75c8801c5 Mon Sep 17 00:00:00 2001 From: P Date: Sat, 18 Aug 2018 06:17:40 -0700 Subject: [PATCH 13/19] added column descriptions --- gui/builtinStatsViews/insuranceViewFull.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py index f75c93f361..4ec7772935 100644 --- a/gui/builtinStatsViews/insuranceViewFull.py +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -38,10 +38,26 @@ def populatePanel(self, contentPanel, headerPanel): contentSizer = contentPanel.GetSizer() self.panel = contentPanel self.headerPanel = headerPanel + + # Column description + gridInsuranceValues = wx.GridSizer(1, 3, 0, 0) + contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Level"), 0, wx.ALIGN_CENTER) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Cost"), 0, wx.ALIGN_CENTER) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Payout"), 0, wx.ALIGN_CENTER) gridInsuranceValues = wx.GridSizer(5, 3, 0, 0) contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) - + for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: # Insurance type box = wx.BoxSizer(wx.VERTICAL) From d4c14e06d81c869861b65bed8c702e055b73ed5e Mon Sep 17 00:00:00 2001 From: P Date: Sat, 18 Aug 2018 06:46:34 -0700 Subject: [PATCH 14/19] added difference column --- gui/builtinStatsViews/insuranceViewFull.py | 63 +++++++++++++++------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py index 4ec7772935..e91c19284b 100644 --- a/gui/builtinStatsViews/insuranceViewFull.py +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -38,9 +38,9 @@ def populatePanel(self, contentPanel, headerPanel): contentSizer = contentPanel.GetSizer() self.panel = contentPanel self.headerPanel = headerPanel - + # Column description - gridInsuranceValues = wx.GridSizer(1, 3, 0, 0) + gridInsuranceValues = wx.GridSizer(1, 4, 0, 0) contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) box = wx.BoxSizer(wx.VERTICAL) @@ -55,9 +55,13 @@ def populatePanel(self, contentPanel, headerPanel): gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Payout"), 0, wx.ALIGN_CENTER) - gridInsuranceValues = wx.GridSizer(5, 3, 0, 0) + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Difference"), 0, wx.ALIGN_CENTER) + + gridInsuranceValues = wx.GridSizer(5, 4, 0, 0) contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) - + for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: # Insurance type box = wx.BoxSizer(wx.VERTICAL) @@ -80,6 +84,14 @@ def populatePanel(self, contentPanel, headerPanel): gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) box.Add(lbl, 0, wx.ALIGN_LEFT) + # Difference + lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") + setattr(self, "labelInsuranceDifference%s" % level, lbl) + + box = wx.BoxSizer(wx.VERTICAL) + gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) + box.Add(lbl, 0, wx.ALIGN_LEFT) + def refreshPanel(self, fit): if fit is not None: sInsurance = Insurance.getInstance() @@ -90,20 +102,35 @@ def refreshPanel(self, fit): def refreshInsurancePanelPrices(self): if self.insuranceLevels: - self.labelInsuranceCostBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutBasic.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[0].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutBronze.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[1].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutSilver.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[2].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutGold.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[3].get('payout'), 3, 3, 9, currency=True)) - - self.labelInsuranceCostPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('cost'), 3, 3, 9, currency=True)) - self.labelInsurancePayoutPlatinum.SetLabel("%s ISK" % formatAmount(self.insuranceLevels[4].get('payout'), 3, 3, 9, currency=True)) + cost = self.insuranceLevels[0].get('cost') + payout = self.insuranceLevels[0].get('payout') + self.labelInsuranceCostBasic.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) + self.labelInsurancePayoutBasic.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) + self.labelInsuranceDifferenceBasic.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) + + cost = self.insuranceLevels[1].get('cost') + payout = self.insuranceLevels[1].get('payout') + self.labelInsuranceCostBronze.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) + self.labelInsurancePayoutBronze.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) + self.labelInsuranceDifferenceBronze.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) + + cost = self.insuranceLevels[2].get('cost') + payout = self.insuranceLevels[2].get('payout') + self.labelInsuranceCostSilver.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) + self.labelInsurancePayoutSilver.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) + self.labelInsuranceDifferenceSilver.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) + + cost = self.insuranceLevels[3].get('cost') + payout = self.insuranceLevels[3].get('payout') + self.labelInsuranceCostGold.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) + self.labelInsurancePayoutGold.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) + self.labelInsuranceDifferenceGold.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) + + cost = self.insuranceLevels[4].get('cost') + payout = self.insuranceLevels[4].get('payout') + self.labelInsuranceCostPlatinum.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) + self.labelInsurancePayoutPlatinum.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) + self.labelInsuranceDifferencePlatinum.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) InsuranceViewFull.register() From 9460591a79e6a55abacddba015026fd003af6bf6 Mon Sep 17 00:00:00 2001 From: P Date: Sun, 19 Aug 2018 12:19:12 -0700 Subject: [PATCH 15/19] added context menu for column display --- gui/builtinContextMenus/insuranceOptions.py | 47 +++++++ gui/builtinStatsViews/insuranceViewFull.py | 136 +++++++++----------- gui/contextMenu.py | 1 + service/settings.py | 30 +++++ 4 files changed, 138 insertions(+), 76 deletions(-) create mode 100644 gui/builtinContextMenus/insuranceOptions.py diff --git a/gui/builtinContextMenus/insuranceOptions.py b/gui/builtinContextMenus/insuranceOptions.py new file mode 100644 index 0000000000..777205d096 --- /dev/null +++ b/gui/builtinContextMenus/insuranceOptions.py @@ -0,0 +1,47 @@ +import wx + +import gui.mainFrame +from gui.contextMenu import ContextMenu +from service.settings import InsuranceMenuSettings + + +class InsuranceOptions(ContextMenu): + def __init__(self): + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.settings = InsuranceMenuSettings.getInstance() + self.optionList = ["Cost", "Payout", "Difference"] + + def display(self, srcContext, selection): + return srcContext in ("insuranceViewFull") + + def getText(self, itmContext, selection): + return "Column Display (Requires Restart)" + + def addOption(self, menu, option): + label = option + id = ContextMenu.nextID() + self.optionIds[id] = option + menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_CHECK) + menu.Bind(wx.EVT_MENU, self.handleMode, menuItem) + return menuItem + + def getSubMenu(self, context, selection, rootMenu, i, pitem): + msw = True if "wxMSW" in wx.PlatformInfo else False + self.context = context + self.optionIds = {} + + sub = wx.Menu() + + for option in self.optionList: + menuItem = self.addOption(rootMenu if msw else sub, option) + sub.Append(menuItem) + menuItem.Check(self.settings.get(option.lower())) + + return sub + + def handleMode(self, event): + option = self.optionIds[event.Id] + self.settings.set(option.lower(), event.Int) + + +InsuranceOptions.register() diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py index e91c19284b..75e7ddfe03 100644 --- a/gui/builtinStatsViews/insuranceViewFull.py +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -21,6 +21,7 @@ from gui.statsView import StatsView from gui.utils.numberFormatter import formatAmount from service.insurance import Insurance +from service.settings import InsuranceMenuSettings class InsuranceViewFull(StatsView): @@ -30,107 +31,90 @@ def __init__(self, parent): StatsView.__init__(self) self.parent = parent self.insuranceLevels = None + self.settings = InsuranceMenuSettings.getInstance() + self.displayColumns = self.getDisplayColumns(self.settings) - def getHeaderText(self, fit): - return "Insurance" + def getDisplayColumns(self, settings): + return {'cost': self.settings.get("cost"), 'payout': self.settings.get("payout"), 'difference': self.settings.get("difference")} - def populatePanel(self, contentPanel, headerPanel): - contentSizer = contentPanel.GetSizer() - self.panel = contentPanel - self.headerPanel = headerPanel + ''' Future use when repopulate can be called during runtime, might need rewrite from changing displayColumns from list to dict + def settingsDiffer(self, settings): + newColumns = self.getDisplayColumns(settings) + if self.displayColumns == newColumns: + return False + self.displayColumns = newColumns + return True + ''' - # Column description - gridInsuranceValues = wx.GridSizer(1, 4, 0, 0) - contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) + def getHeaderText(self, fit): + return "Insurance" + def newBoxText(self, grid, contentPanel, text): box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Level"), 0, wx.ALIGN_CENTER) + grid.Add(box, 0, wx.ALIGN_TOP) + box.Add(wx.StaticText(contentPanel, wx.ID_ANY, text), 0, wx.ALIGN_CENTER) + def newBoxLabel(self, grid, contentPanel, labeltype, label): + lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") + setattr(self, "labelInsurance{}{}".format(labeltype, label), lbl) box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Cost"), 0, wx.ALIGN_CENTER) + grid.Add(box, 0, wx.ALIGN_TOP) + box.Add(lbl, 0, wx.ALIGN_LEFT) - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Payout"), 0, wx.ALIGN_CENTER) + def populatePanel(self, contentPanel, headerPanel, reset=False): + contentSizer = contentPanel.GetSizer() + self.panel = contentPanel + self.headerPanel = headerPanel - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, "Difference"), 0, wx.ALIGN_CENTER) + columnCount = sum(self.displayColumns.values()) + 1 - gridInsuranceValues = wx.GridSizer(5, 4, 0, 0) + gridInsuranceValues = wx.GridSizer(6, columnCount, 0, 0) contentSizer.Add(gridInsuranceValues, 0, wx.EXPAND | wx.ALL, 0) - for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: - # Insurance type - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(wx.StaticText(contentPanel, wx.ID_ANY, level), 0, wx.ALIGN_CENTER) - - # Insurance cost - lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") - setattr(self, "labelInsuranceCost%s" % level, lbl) + self.newBoxText(gridInsuranceValues, contentPanel, "Level") - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(lbl, 0, wx.ALIGN_LEFT) + if (self.settings.get("cost")): + self.newBoxText(gridInsuranceValues, contentPanel, "Cost") + if (self.settings.get("payout")): + self.newBoxText(gridInsuranceValues, contentPanel, "Payout") + if (self.settings.get("difference")): + self.newBoxText(gridInsuranceValues, contentPanel, "Difference") - # Insurance payout - lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") - setattr(self, "labelInsurancePayout%s" % level, lbl) - - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(lbl, 0, wx.ALIGN_LEFT) - - # Difference - lbl = wx.StaticText(contentPanel, wx.ID_ANY, "0.00 ISK") - setattr(self, "labelInsuranceDifference%s" % level, lbl) - - box = wx.BoxSizer(wx.VERTICAL) - gridInsuranceValues.Add(box, 0, wx.ALIGN_TOP) - box.Add(lbl, 0, wx.ALIGN_LEFT) + for level in ["Basic", "Bronze", "Silver", "Gold", "Platinum"]: + self.newBoxText(gridInsuranceValues, contentPanel, level) + if (self.settings.get("cost")): + self.newBoxLabel(gridInsuranceValues, contentPanel, "Cost", level) + if (self.settings.get("payout")): + self.newBoxLabel(gridInsuranceValues, contentPanel, "Payout", level) + if (self.settings.get("difference")): + self.newBoxLabel(gridInsuranceValues, contentPanel, "Difference", level) def refreshPanel(self, fit): if fit is not None: sInsurance = Insurance.getInstance() self.insuranceLevels = sInsurance.getInsurance(fit.ship.item.ID) + # Currently populate is only called on init from statsPane.py, so a restart is required for repopulate + # Could also create the 6 different configurations and enable/disable, but it looks like work is being + # done to add runtime repopulation of panels, so I'm going to just require restart for column view change + # to take effect, and then enable this function when the changes for runtime repopulation go live + # if self.settingsDiffer(self.settings): + # self.populatePanel(self.panel, self.headerPanel, True) + self.refreshInsurancePanelPrices() self.panel.Layout() def refreshInsurancePanelPrices(self): if self.insuranceLevels: - cost = self.insuranceLevels[0].get('cost') - payout = self.insuranceLevels[0].get('payout') - self.labelInsuranceCostBasic.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) - self.labelInsurancePayoutBasic.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) - self.labelInsuranceDifferenceBasic.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) - - cost = self.insuranceLevels[1].get('cost') - payout = self.insuranceLevels[1].get('payout') - self.labelInsuranceCostBronze.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) - self.labelInsurancePayoutBronze.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) - self.labelInsuranceDifferenceBronze.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) - - cost = self.insuranceLevels[2].get('cost') - payout = self.insuranceLevels[2].get('payout') - self.labelInsuranceCostSilver.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) - self.labelInsurancePayoutSilver.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) - self.labelInsuranceDifferenceSilver.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) - - cost = self.insuranceLevels[3].get('cost') - payout = self.insuranceLevels[3].get('payout') - self.labelInsuranceCostGold.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) - self.labelInsurancePayoutGold.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) - self.labelInsuranceDifferenceGold.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) - - cost = self.insuranceLevels[4].get('cost') - payout = self.insuranceLevels[4].get('payout') - self.labelInsuranceCostPlatinum.SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) - self.labelInsurancePayoutPlatinum.SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) - self.labelInsuranceDifferencePlatinum.SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) + for index, label in enumerate(["Basic", "Bronze", "Silver", "Gold", "Platinum"]): + cost = self.insuranceLevels[index].get('cost') + payout = self.insuranceLevels[index].get('payout') + if self.displayColumns["cost"]: + getattr(self, "labelInsuranceCost%s" % label).SetLabel("%s ISK" % formatAmount(cost, 3, 3, 9, currency=True)) + if self.displayColumns["payout"]: + getattr(self, "labelInsurancePayout%s" % label).SetLabel("%s ISK" % formatAmount(payout, 3, 3, 9, currency=True)) + if self.displayColumns["difference"]: + getattr(self, "labelInsuranceDifference%s" % label).SetLabel("%s ISK" % formatAmount(payout - cost, 3, 3, 9, currency=True)) InsuranceViewFull.register() diff --git a/gui/contextMenu.py b/gui/contextMenu.py index 08ea258d5b..8ec354f657 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -210,4 +210,5 @@ def getBitmap(self, context, selection): commandFits, tabbedFits, mutaplasmids, + insuranceOptions, ) diff --git a/service/settings.py b/service/settings.py index a1c13856b6..2dc5b3773d 100644 --- a/service/settings.py +++ b/service/settings.py @@ -449,6 +449,36 @@ def set(self, type, value): self.serviceStatViewDefaultSettings[type] = value +class InsuranceMenuSettings(object): + _instance = None + + @classmethod + def getInstance(cls): + if cls._instance is None: + cls._instance = InsuranceMenuSettings() + + return cls._instance + + def __init__(self): + # mode + # 0 - Do not add to total + # 1 - Add to total + InsuranceMenuDefaultSettings = { + "cost" : 1, + "payout" : 1, + "difference" : 1 + } + + self.InsuranceMenuDefaultSettings = SettingsProvider.getInstance().getSettings("pyfaInsuranceMenuSettings", + InsuranceMenuDefaultSettings) + + def get(self, type): + return self.InsuranceMenuDefaultSettings[type] + + def set(self, type, value): + self.InsuranceMenuDefaultSettings[type] = value + + class PriceMenuSettings(object): _instance = None From 2ed4e57fa7ea47bc6692e4fa2f5a0ed7c4522023 Mon Sep 17 00:00:00 2001 From: P Date: Sun, 19 Aug 2018 13:16:14 -0700 Subject: [PATCH 16/19] stripped copied GPL header --- gui/builtinStatsViews/insuranceViewFull.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py index 75e7ddfe03..33f1ba14e1 100644 --- a/gui/builtinStatsViews/insuranceViewFull.py +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -1,22 +1,3 @@ -# ============================================================================= -# Copyright (C) 2010 Diego Duclos -# -# This file is part of pyfa. -# -# pyfa is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# pyfa is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with pyfa. If not, see . -# ============================================================================= - import wx from gui.statsView import StatsView from gui.utils.numberFormatter import formatAmount From 4b945c8e5d50887b4be78dba1a3ffe13859cb1ba Mon Sep 17 00:00:00 2001 From: P Date: Sun, 19 Aug 2018 13:16:27 -0700 Subject: [PATCH 17/19] remove whitespace --- gui/builtinContextMenus/insuranceOptions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/builtinContextMenus/insuranceOptions.py b/gui/builtinContextMenus/insuranceOptions.py index 777205d096..a726d308e1 100644 --- a/gui/builtinContextMenus/insuranceOptions.py +++ b/gui/builtinContextMenus/insuranceOptions.py @@ -1,5 +1,4 @@ import wx - import gui.mainFrame from gui.contextMenu import ContextMenu from service.settings import InsuranceMenuSettings From a8484d2e00f971d165d3366cc56894039960706c Mon Sep 17 00:00:00 2001 From: P Date: Sun, 19 Aug 2018 13:23:35 -0700 Subject: [PATCH 18/19] revert to b30b3fcbf1e91bed6cfe7bcebdf14373f52a1690 (original) after stripping insurance --- gui/builtinStatsViews/priceViewFull.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/builtinStatsViews/priceViewFull.py b/gui/builtinStatsViews/priceViewFull.py index b72566a37d..9eb03ea22a 100644 --- a/gui/builtinStatsViews/priceViewFull.py +++ b/gui/builtinStatsViews/priceViewFull.py @@ -166,4 +166,4 @@ def processPrices(self, prices): self.panel.Layout() -PriceViewFull.register() \ No newline at end of file +PriceViewFull.register() From ee1f276a302072fa6d948f94d9ee3e360884e913 Mon Sep 17 00:00:00 2001 From: P Date: Sun, 19 Aug 2018 13:45:03 -0700 Subject: [PATCH 19/19] fixes to pass tests --- gui/builtinStatsViews/insuranceViewFull.py | 2 +- service/insurance.py | 2 +- service/settings.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/builtinStatsViews/insuranceViewFull.py b/gui/builtinStatsViews/insuranceViewFull.py index 33f1ba14e1..7cda109583 100644 --- a/gui/builtinStatsViews/insuranceViewFull.py +++ b/gui/builtinStatsViews/insuranceViewFull.py @@ -42,7 +42,7 @@ def newBoxLabel(self, grid, contentPanel, labeltype, label): grid.Add(box, 0, wx.ALIGN_TOP) box.Add(lbl, 0, wx.ALIGN_LEFT) - def populatePanel(self, contentPanel, headerPanel, reset=False): + def populatePanel(self, contentPanel, headerPanel): contentSizer = contentPanel.GetSizer() self.panel = contentPanel self.headerPanel = headerPanel diff --git a/service/insurance.py b/service/insurance.py index a945bb4ed1..e68c73fc44 100644 --- a/service/insurance.py +++ b/service/insurance.py @@ -54,4 +54,4 @@ def run(self): self.callback[0](resp, self.callback[1]) except Exception as ex: pyfalog.warn(ex) - self.callback[0](None, self.callback[1], sys.exc_info()) \ No newline at end of file + self.callback[0](None, self.callback[1], sys.exc_info()) diff --git a/service/settings.py b/service/settings.py index 2dc5b3773d..8b7bbeb875 100644 --- a/service/settings.py +++ b/service/settings.py @@ -469,7 +469,7 @@ def __init__(self): "difference" : 1 } - self.InsuranceMenuDefaultSettings = SettingsProvider.getInstance().getSettings("pyfaInsuranceMenuSettings", + self.InsuranceMenuDefaultSettings = SettingsProvider.getInstance().getSettings("pyfaInsuranceMenuSettings", InsuranceMenuDefaultSettings) def get(self, type):