From 483c1c35fde05c0efea91b741e87aa4ed107d6d6 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Wed, 14 Aug 2019 08:53:26 +0300 Subject: [PATCH] Allow to use custom labels for selectors --- graphs/data/base/defs.py | 75 ++++++++++++++++++++++++++++++- graphs/data/fitEwarStats/graph.py | 4 +- graphs/gui/panel.py | 13 +++--- 3 files changed, 82 insertions(+), 10 deletions(-) diff --git a/graphs/data/base/defs.py b/graphs/data/base/defs.py index f04a85f9e..bc2b598a7 100644 --- a/graphs/data/base/defs.py +++ b/graphs/data/base/defs.py @@ -21,11 +21,65 @@ from collections import namedtuple -YDef = namedtuple('YDef', ('handle', 'unit', 'label')) -XDef = namedtuple('XDef', ('handle', 'unit', 'label', 'mainInput')) VectorDef = namedtuple('VectorDef', ('lengthHandle', 'lengthUnit', 'angleHandle', 'angleUnit', 'label')) +class YDef: + + def __init__(self, handle, unit, label, selectorLabel=None): + self.handle = handle + self.unit = unit + self.label = label + self._selectorLabel = selectorLabel + + @property + def selectorLabel(self): + if self._selectorLabel is not None: + return self._selectorLabel + return self.label + + def __hash__(self): + return hash((self.handle, self.unit, self.label, self._selectorLabel)) + + def __eq__(self, other): + if not isinstance(other, YDef): + return False + return all(( + self.handle == other.handle, + self.unit == other.unit, + self.label == other.label, + self._selectorLabel == other._selectorLabel)) + + +class XDef: + + def __init__(self, handle, unit, label, mainInput, selectorLabel=None): + self.handle = handle + self.unit = unit + self.label = label + self.mainInput = mainInput + self._selectorLabel = selectorLabel + + @property + def selectorLabel(self): + if self._selectorLabel is not None: + return self._selectorLabel + return self.label + + def __hash__(self): + return hash((self.handle, self.unit, self.label, self.mainInput, self._selectorLabel)) + + def __eq__(self, other): + if not isinstance(other, XDef): + return False + return all(( + self.handle == other.handle, + self.unit == other.unit, + self.label == other.label, + self.mainInput == other.mainInput, + self._selectorLabel == other._selectorLabel)) + + class Input: def __init__(self, handle, unit, label, iconID, defaultValue, defaultRange, mainOnly=False, mainTooltip=None, secondaryTooltip=None): @@ -38,3 +92,20 @@ class Input: self.mainOnly = mainOnly self.mainTooltip = mainTooltip self.secondaryTooltip = secondaryTooltip + + def __hash__(self): + return hash((self.handle, self.unit, self.label, self.iconID, self.defaultValue, self.defaultRange, self.mainOnly, self.mainTooltip, self.secondaryTooltip)) + + def __eq__(self, other): + if not isinstance(other, Input): + return False + return all(( + self.handle == other.handle, + self.unit == other.unit, + self.label == other.label, + self.iconID == other.iconID, + self.defaultValue == other.defaultValue, + self.defaultRange == other.defaultRange, + self.mainOnly == other.mainOnly, + self.mainTooltip == other.mainTooltip, + self.secondaryTooltip == other.secondaryTooltip)) diff --git a/graphs/data/fitEwarStats/graph.py b/graphs/data/fitEwarStats/graph.py index d2a8df840..e1e809aeb 100644 --- a/graphs/data/fitEwarStats/graph.py +++ b/graphs/data/fitEwarStats/graph.py @@ -29,8 +29,8 @@ class FitEwarStatsGraph(FitGraph): name = 'Electronic Warfare Stats' xDefs = [XDef(handle='distance', unit='km', label='Distance', mainInput=('distance', 'km'))] yDefs = [ - YDef(handle='webStr', unit='%', label='Web speed reduction'), - YDef(handle='dampStrLockRange', unit='%', label='Damp lock range reduction')] + YDef(handle='webStr', unit='%', label='Speed reduction', selectorLabel='Webs: speed reduction'), + YDef(handle='dampStrLockRange', unit='%', label='Lock range reduction', selectorLabel='Damps: lock range reduction')] inputs = [ Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=None, defaultRange=(0, 100)), Input(handle='resist', unit='%', label='Target resistance', iconID=1393, defaultValue=0, defaultRange=(0, 100))] diff --git a/graphs/gui/panel.py b/graphs/gui/panel.py index b4ca47176..2b1875942 100644 --- a/graphs/gui/panel.py +++ b/graphs/gui/panel.py @@ -136,11 +136,11 @@ class GraphControlPanel(wx.Panel): self.ySubSelection.Clear() self.xSubSelection.Clear() for yDef in view.yDefs: - self.ySubSelection.Append(self.formatLabel(yDef), yDef) + self.ySubSelection.Append(self.formatLabel(yDef, selector=True), yDef) self.ySubSelection.SetSelection(0) self.ySubSelection.Enable(len(view.yDefs) > 1) for xDef in view.xDefs: - self.xSubSelection.Append(self.formatLabel(xDef), xDef) + self.xSubSelection.Append(self.formatLabel(xDef, selector=True), xDef) self.xSubSelection.SetSelection(0) self.xSubSelection.Enable(len(view.xDefs) > 1) @@ -261,7 +261,7 @@ class GraphControlPanel(wx.Panel): view = self.graphFrame.getView() self.ySubSelection.Clear() for yDef in view.yDefs: - self.ySubSelection.Append(self.formatLabel(yDef), yDef) + self.ySubSelection.Append(self.formatLabel(yDef, selector=True), yDef) self.ySubSelection.SetSelection(selectedY) def refreshColumns(self, layout=True): @@ -387,10 +387,11 @@ class GraphControlPanel(wx.Panel): def OnResistModeChanged(self, event): self.targetList.OnResistModeChanged(event) - def formatLabel(self, axisDef): + def formatLabel(self, axisDef, selector=False): + label = axisDef.selectorLabel if selector else axisDef.label if axisDef.unit is None: - return axisDef.label - return '{}, {}'.format(axisDef.label, axisDef.unit) + return label + return '{}, {}'.format(label, axisDef.unit) def _storeCurrentValues(self): main, misc = self.getValues()