From 195b65ac9e76356f9d1beaabdaae1c42bf9b2881 Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Wed, 25 Aug 2010 11:08:23 +0200 Subject: [PATCH] Add attribute columns to the fittingView --- controller/__init__.py | 1 + controller/attribute.py | 33 ++++++++++++ gui/builtinViewColumns/__init__.py | 2 +- gui/builtinViewColumns/attributeDisplay.py | 56 +++++++++++++++++++++ gui/fittingView.py | 34 +++++++++---- gui/marketBrowser.py | 1 - icons/pg_small.png | Bin 0 -> 570 bytes 7 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 controller/attribute.py create mode 100644 gui/builtinViewColumns/attributeDisplay.py create mode 100644 icons/pg_small.png diff --git a/controller/__init__.py b/controller/__init__.py index 7e2b42ae7..48b528375 100644 --- a/controller/__init__.py +++ b/controller/__init__.py @@ -1,2 +1,3 @@ from controller.market import Market from controller.fit import Fit +from controller.attribute import Attribute diff --git a/controller/attribute.py b/controller/attribute.py new file mode 100644 index 000000000..ebd27ddc7 --- /dev/null +++ b/controller/attribute.py @@ -0,0 +1,33 @@ +#=============================================================================== +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with pyfa. If not, see . +#=============================================================================== + +import eos.db + +class Attribute(): + instance = None + @classmethod + def getInstance(cls): + if cls.instance is None: + cls.instance = Attribute() + + return cls.instance + + def getAttributeInfo(self, attributeName): + info = eos.db.getAttributeInfo(attributeName) + return info diff --git a/gui/builtinViewColumns/__init__.py b/gui/builtinViewColumns/__init__.py index 7f88f7fb6..2ba808cd1 100644 --- a/gui/builtinViewColumns/__init__.py +++ b/gui/builtinViewColumns/__init__.py @@ -1,4 +1,4 @@ -__all__ = ["moduleState", "moduleNameOrSlot"] +__all__ = ["moduleState", "moduleNameOrSlot", "attributeDisplay"] columns = {} def registerColumn(column): diff --git a/gui/builtinViewColumns/attributeDisplay.py b/gui/builtinViewColumns/attributeDisplay.py new file mode 100644 index 000000000..6600815fd --- /dev/null +++ b/gui/builtinViewColumns/attributeDisplay.py @@ -0,0 +1,56 @@ +#=============================================================================== +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with pyfa. If not, see . +#=============================================================================== + +from gui import builtinViewColumns +from gui.viewColumn import ViewColumn +from gui import bitmapLoader +import controller + +class AttributeDisplay(ViewColumn): + name = "Attribute Display" + def __init__(self, fittingView, params): + ViewColumn.__init__(self, fittingView) + cAttribute = controller.Attribute.getInstance() + info = cAttribute.getAttributeInfo(params["attribute"]) + self.info = info + if params["showIcon"]: + iconFile = info.icon.iconFile if info.icon else None + if iconFile: + bitmap = bitmapLoader.getBitmap(iconFile, "pack") + self.imageId = fittingView.imageList.Add(bitmap) + else: + self.imageId = -1 + else: + self.imageId = -1 + + if params["displayName"] or self.imageId == -1: + self.columnText = info.displayName if info.displayName != "" else info.name + + def getText(self, mod): + return "%.2f" % mod.getModifiedItemAttr(self.info.name) + + def getImageId(self, mod): + return -1 + + def getParameters(self): + return (("attribute", str, None), + ("displayName", bool, False), + ("showIcon", bool, True)) + +builtinViewColumns.registerColumn(AttributeDisplay) diff --git a/gui/fittingView.py b/gui/fittingView.py index 71d199b04..b295059a9 100644 --- a/gui/fittingView.py +++ b/gui/fittingView.py @@ -18,12 +18,14 @@ #=============================================================================== import wx - +import sys import gui.builtinViewColumns from gui.builtinViewColumns import * class FittingView(wx.ListCtrl): DEFAULT_COLS = ["Module state", "Module name/slot"] + DEFAULT_ATTR_COLS = ["power", "cpu", "capacitorNeed", "maxRange", "trackingSpeed"] + def __init__(self, parent): listStyle = wx.LC_REPORT | wx.BORDER_NONE wx.ListCtrl.__init__(self, parent, wx.ID_ANY, style=listStyle) @@ -34,19 +36,33 @@ class FittingView(wx.ListCtrl): self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.resizeChecker) self.Bind(wx.EVT_LIST_COL_CLICK, self.dragCheck) self.Bind(wx.EVT_LIST_COL_END_DRAG, self.dragCheck) + i = 0 for colName in FittingView.DEFAULT_COLS: col = gui.builtinViewColumns.getColumn(colName)(self, None) - self.activeColumns.append(col) - - info = wx.ListItem() - info.m_mask = col.mask - info.m_image = col.imageId - info.m_text = col.columnText - self.InsertColumnInfo(i, info) - self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER if col.size is wx.LIST_AUTOSIZE else col.size) + self.addColumn(i, col) i += 1 + for attrName in FittingView.DEFAULT_ATTR_COLS: + params = {"showIcon": True, + "displayName": False, + "attribute": attrName} + + col = gui.builtinViewColumns.getColumn("Attribute Display")(self, params) + self.addColumn(i, col) + i += 1 + + self.imageListBase = self.imageList.ImageCount + + def addColumn(self, i, col): + self.activeColumns.append(col) + info = wx.ListItem() + info.m_mask = col.mask + info.m_image = col.imageId + info.m_text = col.columnText + self.InsertColumnInfo(i, info) + self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER if col.size is wx.LIST_AUTOSIZE else col.size) + def resizeChecker(self, event): if self.activeColumns[event.Column].resizable is False: event.Veto() diff --git a/gui/marketBrowser.py b/gui/marketBrowser.py index 157172dd9..68ac51a6e 100644 --- a/gui/marketBrowser.py +++ b/gui/marketBrowser.py @@ -179,7 +179,6 @@ class MarketBrowser(wx.Panel): iconId = self.addItemViewImage(iconFile) index = self.itemView.InsertImageStringItem(sys.maxint, name, iconId) idNameMap[id] = name - width, _ = self.itemView.GetTextExtent(name) self.itemView.SetItemData(index, id) diff --git a/icons/pg_small.png b/icons/pg_small.png new file mode 100644 index 0000000000000000000000000000000000000000..dd7bb98e676ec04a04744424dcbab89118eb99e2 GIT binary patch literal 570 zcmV-A0>%A_P) zR72u|6%vYCi=&|rTC_6Q>Xey2W~Sq&3o30_F8u9o?!71H++5(lCd3D#$HF70I?e2A z*RWcxw3ERU=jn+!S=QZd&a}OtY1+>7{IDcRa!(gKo?aK1l9^o0@7X^lZOPyJeBOYp zD3Y%0wU!R<-no4*mt3)V+|1=@zx_Vc@)5171VV?o8NF7%no6aa@$lfowhqJ%5ni9S ze>t)GLf5q+2SWvPtvbZIy0a^**+(45g)+H(S}9jE0O|mYCV@h+xMrfLzL^_W9;_!5 zzP$sH7(mKyr-K^~@fY*?d@=iNV-~=khWlz$1VRX9GfJb6pT2xEIB?MUX?d|!k}JyO znG5^o-p;?<{E-U)U>nQIjtJ*YPfRbo7hWk9HBMO={?_!hOTAsY4=pZz5Mps*wx$`P z!$zI2sP#Dj6#yXH1x`edUZ*YQaNQt!U6uXw3m;!oX0tjqdHiNUQc|qT{ZkM=%ZV@P z=K#I}s5c1^LQIBX1OZrWw1v}kEqK7=U;9-MnZoa_IDkz66aX23&^Y7{ECB2Pn3Iv< zv$GRpPY5syzy*MA^r%*gt>^|Y0-zTizP1yD5Msh#xB9320ljCs!1X`eGynhq07*qo IM6N<$f^%^Oga7~l literal 0 HcmV?d00001