From 5b898a678be87cc79f700d16c029ca06109f0a34 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 6 Aug 2019 14:15:13 +0300 Subject: [PATCH] Handle changing colors via color picker --- graphs/gui/lists.py | 21 +++++++++++++ graphs/gui/stylePickers.py | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 graphs/gui/stylePickers.py diff --git a/graphs/gui/lists.py b/graphs/gui/lists.py index dc9a72110..86e9d85d9 100644 --- a/graphs/gui/lists.py +++ b/graphs/gui/lists.py @@ -25,9 +25,11 @@ 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.contextMenu import ContextMenu from service.const import GraphCacheCleanupReason from service.fit import Fit +from .stylePickers import ColorPickerPopup class BaseWrapperList(gui.display.Display): @@ -41,6 +43,7 @@ class BaseWrapperList(gui.display.Display): self.hoveredColumn = None self.Bind(wx.EVT_CHAR_HOOK, self.kbEvent) + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow) @@ -113,6 +116,24 @@ class BaseWrapperList(gui.display.Display): self.updateView() self.graphFrame.draw() + def OnLeftDown(self, event): + row, _ = self.HitTest(event.Position) + if row != -1: + col = self.getColumn(event.Position) + if col == self.getColIndex(LineColor): + wrapper = self.getWrapper(row) + if wrapper is not None: + win = ColorPickerPopup(parent=self, wrapper=wrapper, ncol=4, nrow=2) + pos = wx.GetMousePosition() + win.Position(pos, (0, 0)) + win.Popup() + return + event.Skip() + + def OnColorChange(self): + self.updateView() + self.graphFrame.draw() + def OnLeftDClick(self, event): row, _ = self.HitTest(event.Position) wrapper = self.getWrapper(row) diff --git a/graphs/gui/stylePickers.py b/graphs/gui/stylePickers.py new file mode 100644 index 000000000..427f76f00 --- /dev/null +++ b/graphs/gui/stylePickers.py @@ -0,0 +1,61 @@ +# ============================================================================= +# 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 . +# ============================================================================= + + +# noinspection PyPackageRequirements +import wx + +from graphs.colors import BASE_COLORS +from gui.bitmap_loader import BitmapLoader + + +class ColorPickerPopup(wx.PopupTransientWindow): + + def __init__(self, parent, wrapper, ncol=0, nrow=0): + super().__init__(parent, flags=wx.BORDER_STATIC) + self.wrapper = wrapper + ncol = ncol or len(BASE_COLORS) + nrow = nrow or int(len(BASE_COLORS) / ncol) + (1 if (len(BASE_COLORS) % ncol) else 0) + + self.SetBackgroundColour(wx.Colour(255, 255, 255)) + sizer = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(sizer) + + grid = wx.GridSizer(nrow, ncol, 0, 0) + self.patches = list() + for colorID, colorData in BASE_COLORS.items(): + icon = wx.StaticBitmap(self, wx.ID_ANY, BitmapLoader.getBitmap(colorData.iconName, 'gui')) + icon.colorID = colorID + icon.SetToolTip(colorData.name) + icon.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) + grid.Add(icon, flag=wx.ALL, border=3) + + sizer.Add(grid) + sizer.Fit(self) + self.Layout() + + def OnLeftDown(self, event): + colorID = getattr(event.GetEventObject(), 'colorID', None) + if colorID is not None: + self.wrapper.color = colorID + self.Parent.OnColorChange() + self.Hide() + self.Destroy() + return + event.Skip()