Automatically assign colors
This commit is contained in:
@@ -23,6 +23,7 @@ import wx
|
|||||||
|
|
||||||
import gui.display
|
import gui.display
|
||||||
from eos.saveddata.targetProfile import TargetProfile
|
from eos.saveddata.targetProfile import TargetProfile
|
||||||
|
from graphs.colors import BASE_COLORS
|
||||||
from graphs.wrapper import SourceWrapper, TargetWrapper
|
from graphs.wrapper import SourceWrapper, TargetWrapper
|
||||||
from gui.contextMenu import ContextMenu
|
from gui.contextMenu import ContextMenu
|
||||||
from service.const import GraphCacheCleanupReason
|
from service.const import GraphCacheCleanupReason
|
||||||
@@ -129,10 +130,6 @@ class BaseWrapperList(gui.display.Display):
|
|||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
# Wrapper-related methods
|
# Wrapper-related methods
|
||||||
@property
|
|
||||||
def wrapperClass(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def getWrapper(self, row):
|
def getWrapper(self, row):
|
||||||
if row == -1:
|
if row == -1:
|
||||||
return None
|
return None
|
||||||
@@ -165,7 +162,7 @@ class BaseWrapperList(gui.display.Display):
|
|||||||
return wrappers
|
return wrappers
|
||||||
|
|
||||||
def appendItem(self, item):
|
def appendItem(self, item):
|
||||||
self._wrappers.append(self.wrapperClass(item))
|
raise NotImplemented
|
||||||
|
|
||||||
def containsFitID(self, fitID):
|
def containsFitID(self, fitID):
|
||||||
for wrapper in self._wrappers:
|
for wrapper in self._wrappers:
|
||||||
@@ -239,7 +236,6 @@ class SourceWrapperList(BaseWrapperList):
|
|||||||
'Color',
|
'Color',
|
||||||
'Base Icon',
|
'Base Icon',
|
||||||
'Base Name')
|
'Base Name')
|
||||||
wrapperClass = SourceWrapper
|
|
||||||
|
|
||||||
def __init__(self, graphFrame, parent):
|
def __init__(self, graphFrame, parent):
|
||||||
super().__init__(graphFrame, parent)
|
super().__init__(graphFrame, parent)
|
||||||
@@ -251,6 +247,20 @@ class SourceWrapperList(BaseWrapperList):
|
|||||||
self.appendItem(fit)
|
self.appendItem(fit)
|
||||||
self.updateView()
|
self.updateView()
|
||||||
|
|
||||||
|
def appendItem(self, item):
|
||||||
|
# Find out least used color
|
||||||
|
colorUseMap = {c: 0 for c in BASE_COLORS}
|
||||||
|
for wrapper in self._wrappers:
|
||||||
|
if wrapper.color not in colorUseMap:
|
||||||
|
continue
|
||||||
|
colorUseMap[wrapper.color] += 1
|
||||||
|
leastUses = min(colorUseMap.values(), default=0)
|
||||||
|
color = None
|
||||||
|
for color in BASE_COLORS:
|
||||||
|
if leastUses == colorUseMap.get(color, 0):
|
||||||
|
break
|
||||||
|
self._wrappers.append(SourceWrapper(item, color))
|
||||||
|
|
||||||
def spawnMenu(self, event):
|
def spawnMenu(self, event):
|
||||||
selection = self.getSelectedWrappers()
|
selection = self.getSelectedWrappers()
|
||||||
clickedPos = self.getRowByAbs(event.Position)
|
clickedPos = self.getRowByAbs(event.Position)
|
||||||
@@ -271,7 +281,6 @@ class TargetWrapperList(BaseWrapperList):
|
|||||||
DEFAULT_COLS = (
|
DEFAULT_COLS = (
|
||||||
'Base Icon',
|
'Base Icon',
|
||||||
'Base Name')
|
'Base Name')
|
||||||
wrapperClass = TargetWrapper
|
|
||||||
|
|
||||||
def __init__(self, graphFrame, parent):
|
def __init__(self, graphFrame, parent):
|
||||||
super().__init__(graphFrame, parent)
|
super().__init__(graphFrame, parent)
|
||||||
@@ -281,6 +290,9 @@ class TargetWrapperList(BaseWrapperList):
|
|||||||
self.appendItem(TargetProfile.getIdeal())
|
self.appendItem(TargetProfile.getIdeal())
|
||||||
self.updateView()
|
self.updateView()
|
||||||
|
|
||||||
|
def appendItem(self, item):
|
||||||
|
self._wrappers.append(TargetWrapper(item))
|
||||||
|
|
||||||
def spawnMenu(self, event):
|
def spawnMenu(self, event):
|
||||||
selection = self.getSelectedWrappers()
|
selection = self.getSelectedWrappers()
|
||||||
clickedPos = self.getRowByAbs(event.Position)
|
clickedPos = self.getRowByAbs(event.Position)
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ class BaseWrapper:
|
|||||||
|
|
||||||
class SourceWrapper(BaseWrapper):
|
class SourceWrapper(BaseWrapper):
|
||||||
|
|
||||||
def __init__(self, item):
|
def __init__(self, item, color):
|
||||||
super().__init__(item)
|
super().__init__(item)
|
||||||
self._color = None
|
self._color = color
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color(self):
|
def color(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user