From 53de46bab7aa676d2185a26d372f4ce8569bfae7 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 5 Jul 2019 20:15:44 +0300 Subject: [PATCH] Add graph settings and save selected graph type there --- gui/builtinGraphs/base.py | 9 +++++ gui/builtinGraphs/fitCapRegen.py | 1 + gui/builtinGraphs/fitDamageStats/graph.py | 1 + gui/builtinGraphs/fitMobility.py | 1 + gui/builtinGraphs/fitShieldRegen.py | 1 + gui/builtinGraphs/fitWarpTime.py | 1 + gui/graphFrame/frame.py | 8 +++-- service/settings.py | 44 +++++++++++++++++------ 8 files changed, 53 insertions(+), 13 deletions(-) diff --git a/gui/builtinGraphs/base.py b/gui/builtinGraphs/base.py index 2f00ac20e..1e41bc4cf 100644 --- a/gui/builtinGraphs/base.py +++ b/gui/builtinGraphs/base.py @@ -32,10 +32,14 @@ class FitGraph(metaclass=ABCMeta): # UI stuff views = [] + viewMap = {} + viewIndexMap = {} @classmethod def register(cls): FitGraph.views.append(cls) + FitGraph.viewMap[cls.internalName] = cls + FitGraph.viewIndexMap[cls.internalName] = FitGraph.views.index(cls) def __init__(self): # Format: {(fit ID, target type, target ID): data} @@ -46,6 +50,11 @@ class FitGraph(metaclass=ABCMeta): def name(self): raise NotImplementedError + @property + @abstractmethod + def internalName(self): + raise NotImplementedError + @property @abstractmethod def yDefs(self): diff --git a/gui/builtinGraphs/fitCapRegen.py b/gui/builtinGraphs/fitCapRegen.py index 1dfb65130..b8c7ac3a7 100644 --- a/gui/builtinGraphs/fitCapRegen.py +++ b/gui/builtinGraphs/fitCapRegen.py @@ -26,6 +26,7 @@ from .base import FitGraph, XDef, YDef, Input class FitCapRegenGraph(FitGraph): # UI stuff + internalName = 'capRegenGraph' name = 'Capacitor Regeneration' xDefs = [ XDef(handle='time', unit='s', label='Time', mainInput=('time', 's')), diff --git a/gui/builtinGraphs/fitDamageStats/graph.py b/gui/builtinGraphs/fitDamageStats/graph.py index 3aaf2758e..e407ef724 100644 --- a/gui/builtinGraphs/fitDamageStats/graph.py +++ b/gui/builtinGraphs/fitDamageStats/graph.py @@ -37,6 +37,7 @@ class FitDamageStatsGraph(FitGraph): self._timeCache.clear(fitID) # UI stuff + internalName = 'dmgStatsGraph' name = 'Damage Stats' xDefs = [ XDef(handle='distance', unit='km', label='Distance', mainInput=('distance', 'km')), diff --git a/gui/builtinGraphs/fitMobility.py b/gui/builtinGraphs/fitMobility.py index 385d570c2..a03603135 100644 --- a/gui/builtinGraphs/fitMobility.py +++ b/gui/builtinGraphs/fitMobility.py @@ -26,6 +26,7 @@ from .base import FitGraph, XDef, YDef, Input class FitMobilityVsTimeGraph(FitGraph): # UI stuff + internalName = 'mobilityGraph' name = 'Mobility' xDefs = [ XDef(handle='time', unit='s', label='Time', mainInput=('time', 's'))] diff --git a/gui/builtinGraphs/fitShieldRegen.py b/gui/builtinGraphs/fitShieldRegen.py index 11c20a8c1..8cb255a75 100644 --- a/gui/builtinGraphs/fitShieldRegen.py +++ b/gui/builtinGraphs/fitShieldRegen.py @@ -26,6 +26,7 @@ from .base import FitGraph, XDef, YDef, Input class FitShieldRegenGraph(FitGraph): # UI stuff + internalName = 'shieldRegenGraph' name = 'Shield Regeneration' xDefs = [ XDef(handle='time', unit='s', label='Time', mainInput=('time', 's')), diff --git a/gui/builtinGraphs/fitWarpTime.py b/gui/builtinGraphs/fitWarpTime.py index a5720c17b..50d7f4e0e 100644 --- a/gui/builtinGraphs/fitWarpTime.py +++ b/gui/builtinGraphs/fitWarpTime.py @@ -37,6 +37,7 @@ class FitWarpTimeGraph(FitGraph): self._subspeedCache.clear(fitID) # UI stuff + internalName = 'warpTimeGraph' name = 'Warp Time' xDefs = [ XDef(handle='distance', unit='AU', label='Distance', mainInput=('distance', 'AU')), diff --git a/gui/graphFrame/frame.py b/gui/graphFrame/frame.py index 92f58b25d..a696e9e51 100644 --- a/gui/graphFrame/frame.py +++ b/gui/graphFrame/frame.py @@ -31,6 +31,7 @@ import gui.globalEvents as GE import gui.mainFrame from gui.bitmap_loader import BitmapLoader from gui.builtinGraphs.base import FitGraph +from service.settings import GraphSettings from .panel import GraphControlPanel @@ -113,7 +114,9 @@ class GraphFrame(wx.Frame): # Setup - graph selector for view in FitGraph.views: self.graphSelection.Append(view.name, view()) - self.graphSelection.SetSelection(0) + viewToSelect = GraphSettings.getInstance().get('selectedGraph') + viewToSelect = FitGraph.viewIndexMap.get(viewToSelect, 0) + self.graphSelection.SetSelection(viewToSelect) self.ctrlPanel.updateControls(layout=False) # Event bindings - local events @@ -154,13 +157,14 @@ class GraphFrame(wx.Frame): self.draw() def OnGraphSwitched(self, event): + view = self.getView() + GraphSettings.getInstance().set('selectedGraph', view.internalName) self.clearCache() self.ctrlPanel.updateControls() self.draw() event.Skip() def closeWindow(self): - from gui.builtinStatsViews.resistancesViewFull import EFFECTIVE_HP_TOGGLED self.mainFrame.Unbind(GE.FIT_CHANGED, handler=self.OnFitChanged) self.ctrlPanel.unbindExternalEvents() self.Destroy() diff --git a/service/settings.py b/service/settings.py index 19426abf1..2cae8a167 100644 --- a/service/settings.py +++ b/service/settings.py @@ -30,7 +30,7 @@ from logbook import Logger pyfalog = Logger(__name__) -class SettingsProvider(object): +class SettingsProvider: if config.savePath: BASE_PATH = os.path.join(config.savePath, 'settings') settings = {} @@ -78,7 +78,7 @@ class SettingsProvider(object): settings.save() -class Settings(object): +class Settings: def __init__(self, location, info): # type: (basestring, dict) -> None # path string or empty string. @@ -129,7 +129,7 @@ class Settings(object): return list(self.info.items()) -class NetworkSettings(object): +class NetworkSettings: _instance = None # constants for serviceNetworkDefaultSettings["mode"] parameter @@ -276,7 +276,7 @@ class NetworkSettings(object): return proxies -class HTMLExportSettings(object): +class HTMLExportSettings: """ Settings used by the HTML export feature. """ @@ -312,7 +312,7 @@ class HTMLExportSettings(object): self.serviceHTMLExportSettings["path"] = path -class UpdateSettings(object): +class UpdateSettings: """ Settings used by update notification """ @@ -343,7 +343,7 @@ class UpdateSettings(object): self.serviceUpdateSettings[type] = value -class EsiSettings(object): +class EsiSettings: _instance = None @classmethod @@ -379,7 +379,7 @@ class EsiSettings(object): self.settings[type] = value -class StatViewSettings(object): +class StatViewSettings: _instance = None @classmethod @@ -416,7 +416,7 @@ class StatViewSettings(object): self.serviceStatViewDefaultSettings[type] = value -class MarketPriceSettings(object): +class MarketPriceSettings: _instance = None @classmethod @@ -450,7 +450,7 @@ class MarketPriceSettings(object): self.PriceMenuDefaultSettings[type] = value -class ContextMenuSettings(object): +class ContextMenuSettings: _instance = None @classmethod @@ -482,7 +482,7 @@ class ContextMenuSettings(object): self.ContextMenuDefaultSettings[type] = value -class EOSSettings(object): +class EOSSettings: _instance = None @classmethod @@ -501,4 +501,26 @@ class EOSSettings(object): def set(self, type, value): self.EOSSettings[type] = value -# @todo: migrate fit settings (from fit service) here? + +class GraphSettings: + + _instance = None + + @classmethod + def getInstance(cls): + if cls._instance is None: + cls._instance = GraphSettings() + return cls._instance + + def __init__(self): + defaults = { + 'selectedGraph': None, + 'mobileDroneMode': 0, + 'ignoreResists': True} + self.settings = SettingsProvider.getInstance().getSettings('graphSettings', defaults) + + def get(self, type): + return self.settings[type] + + def set(self, type, value): + self.settings[type] = value