Add line lightness column

This commit is contained in:
DarkPhoenix
2019-08-06 15:13:35 +03:00
parent e14d3d7214
commit e3ac9a7722
9 changed files with 113 additions and 31 deletions

View File

@@ -20,7 +20,7 @@
from collections import OrderedDict, namedtuple
from service.const import Color
from service.const import GraphColor
ColorData = namedtuple('ColorData', ('hsl', 'name', 'iconName'))
@@ -28,14 +28,14 @@ ColorData = namedtuple('ColorData', ('hsl', 'name', 'iconName'))
# In HSL format
BASE_COLORS = OrderedDict([
(Color.red, ColorData((0 / 360.0, 1.0, 0.5), 'Red', 'color_red')),
(Color.green, ColorData((120 / 360.0, 1.0, 0.5), 'Green', 'color_green')),
(Color.blue, ColorData((240 / 360.0, 1.0, 0.5), 'Blue', 'color_blue')),
(Color.yellow, ColorData((56 / 360.0, 1.0, 0.5), 'Yellow', 'color_yellow')),
(Color.cyan, ColorData((180 / 360.0, 1.0, 0.5), 'Cyan', 'color_cyan')),
(Color.magenta, ColorData((300 / 360.0, 1.0, 0.5), 'Magenta', 'color_magenta')),
(Color.orange, ColorData((40 / 360.0, 1.0, 0.5), 'Orange', 'color_orange')),
(Color.purple, ColorData((275 / 360.0, 1.0, 0.5), 'Purple', 'color_purple'))])
(GraphColor.red, ColorData((0 / 360.0, 1.0, 0.5), 'Red', 'color_red')),
(GraphColor.green, ColorData((120 / 360.0, 1.0, 0.5), 'Green', 'color_green')),
(GraphColor.blue, ColorData((240 / 360.0, 1.0, 0.5), 'Blue', 'color_blue')),
(GraphColor.yellow, ColorData((56 / 360.0, 1.0, 0.5), 'Yellow', 'color_yellow')),
(GraphColor.cyan, ColorData((180 / 360.0, 1.0, 0.5), 'Cyan', 'color_cyan')),
(GraphColor.magenta, ColorData((300 / 360.0, 1.0, 0.5), 'Magenta', 'color_magenta')),
(GraphColor.orange, ColorData((40 / 360.0, 1.0, 0.5), 'Orange', 'color_orange')),
(GraphColor.purple, ColorData((275 / 360.0, 1.0, 0.5), 'Purple', 'color_purple'))])
def hsl_to_hsv(hsl):
@@ -43,3 +43,13 @@ def hsl_to_hsv(hsl):
s *= l if (l < 0.5) else (1 - l)
l += s
return (h, 2 * s / l, l)
def darken(hsl):
h, s, l = hsl
return h, s * 0.7, l * 0.7
def brighten(hsl):
h, s, l = hsl
return h, s * 0.7, l + (1 - l) * 0.4

View File

@@ -269,12 +269,14 @@ class GraphFrame(wx.Frame):
else:
iterList = tuple((f, None) for f in sources)
for source, target in iterList:
# Get color data
try:
colorData = BASE_COLORS[source.color]
colorData = BASE_COLORS[source.colorID]
except KeyError:
pyfalog.warning('Invalid color for "{0}"', source.name)
continue
color = hsv_to_rgb(hsl_to_hsv(colorData.hsl))
# Get point data
try:
xs, ys = view.getPlotPoints(
mainInput=mainInput,

View File

@@ -25,7 +25,7 @@ import gui.display
from eos.saveddata.targetProfile import TargetProfile
from graphs.colors import BASE_COLORS
from graphs.wrapper import SourceWrapper, TargetWrapper
from gui.builtinViewColumns.color import LineColor
from gui.builtinViewColumns.graphColor import GraphColor
from gui.contextMenu import ContextMenu
from service.const import GraphCacheCleanupReason
from service.fit import Fit
@@ -120,7 +120,7 @@ class BaseWrapperList(gui.display.Display):
row, _ = self.HitTest(event.Position)
if row != -1:
col = self.getColumn(event.Position)
if col == self.getColIndex(LineColor):
if col == self.getColIndex(GraphColor):
wrapper = self.getWrapper(row)
if wrapper is not None:
win = ColorPickerPopup(parent=self, wrapper=wrapper, ncol=4, nrow=2)
@@ -254,7 +254,7 @@ class BaseWrapperList(gui.display.Display):
class SourceWrapperList(BaseWrapperList):
DEFAULT_COLS = (
'Color',
'Graph Color',
'Base Icon',
'Base Name')
@@ -272,9 +272,9 @@ class SourceWrapperList(BaseWrapperList):
# Find out least used color
colorUseMap = {c: 0 for c in BASE_COLORS}
for wrapper in self._wrappers:
if wrapper.color not in colorUseMap:
if wrapper.colorID not in colorUseMap:
continue
colorUseMap[wrapper.color] += 1
colorUseMap[wrapper.colorID] += 1
leastUses = min(colorUseMap.values(), default=0)
color = None
for color in BASE_COLORS:
@@ -300,6 +300,7 @@ class SourceWrapperList(BaseWrapperList):
class TargetWrapperList(BaseWrapperList):
DEFAULT_COLS = (
'Graph Lightness',
'Base Icon',
'Base Name')
@@ -312,7 +313,7 @@ class TargetWrapperList(BaseWrapperList):
self.updateView()
def appendItem(self, item):
self._wrappers.append(TargetWrapper(item))
self._wrappers.append(TargetWrapper(item, None))
def spawnMenu(self, event):
selection = self.getSelectedWrappers()

View File

@@ -53,7 +53,7 @@ class ColorPickerPopup(wx.PopupTransientWindow):
def OnLeftDown(self, event):
colorID = getattr(event.GetEventObject(), 'colorID', None)
if colorID is not None:
self.wrapper.color = colorID
self.wrapper.colorID = colorID
self.Parent.OnColorChange()
self.Hide()
self.Destroy()

View File

@@ -95,25 +95,34 @@ class BaseWrapper:
class SourceWrapper(BaseWrapper):
def __init__(self, item, color):
def __init__(self, item, colorID):
super().__init__(item)
self._color = color
self._colorID = colorID
@property
def color(self):
return self._color
def colorID(self):
return self._colorID
@color.setter
def color(self, value):
self._color = value
@colorID.setter
def colorID(self, value):
self._colorID = value
class TargetWrapper(BaseWrapper):
def __init__(self, item):
def __init__(self, item, lightness):
super().__init__(item=item)
self._lightness = lightness
self.__resistMode = TargetResistMode.auto
@property
def lightness(self):
return self._lightness
@lightness.setter
def lightness(self, value):
self._lightness = value
@property
def resistMode(self):
return self.__resistMode

View File

@@ -25,9 +25,9 @@ from graphs.wrapper import SourceWrapper
from gui.viewColumn import ViewColumn
class LineColor(ViewColumn):
class GraphColor(ViewColumn):
name = 'Color'
name = 'Graph Color'
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
@@ -39,7 +39,7 @@ class LineColor(ViewColumn):
def getImageId(self, stuff):
if isinstance(stuff, SourceWrapper):
try:
color_data = BASE_COLORS[stuff.color]
color_data = BASE_COLORS[stuff.colorID]
except KeyError:
return -1
img = self.fittingView.imageList.GetImageIndex(color_data.iconName, 'gui')
@@ -52,4 +52,4 @@ class LineColor(ViewColumn):
return ''
LineColor.register()
GraphColor.register()

View File

@@ -0,0 +1,51 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
# noinspection PyPackageRequirements
import wx
from graphs.colors import BASE_COLORS
from graphs.wrapper import TargetWrapper
from gui.viewColumn import ViewColumn
class GraphLightness(ViewColumn):
name = 'Graph Lightness'
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.resizable = False
self.size = 20
self.maxsize = self.size
self.mask = wx.LIST_MASK_TEXT
def getImageId(self, stuff):
if isinstance(stuff, TargetWrapper):
# img = self.fittingView.imageList.GetImageIndex(color_data.iconName, 'gui')
return -1
return -1
def getToolTip(self, stuff):
if isinstance(stuff, TargetWrapper):
return 'Change line brightness'
return ''
GraphLightness.register()

View File

@@ -76,7 +76,8 @@ from gui.builtinViewColumns import ( # noqa: E402, F401
baseIcon,
baseName,
capacitorUse,
color,
graphColor,
graphLightness,
maxRange,
misc,
price,

View File

@@ -139,8 +139,9 @@ class TargetResistMode(IntEnum):
hull = autoId()
weightedAverage = autoId()
@unique
class Color(IntEnum):
class GraphColor(IntEnum):
red = autoId()
green = autoId()
blue = autoId()
@@ -149,3 +150,10 @@ class Color(IntEnum):
magenta = autoId()
orange = autoId()
purple = autoId()
@unique
class GraphLightness(IntEnum):
normal = autoId()
dark = autoId()
bright = autoId()