From 8d0c2042eaa9d33ef4f228601b2ebc963e4442f1 Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Sun, 15 Aug 2010 17:40:00 +0200 Subject: [PATCH] Remove a few stale variables. Add a market class to the controller. Add a method in the Market controller to grab the market root. Display the market root in the market browser. --- config.py | 1 + controller/__init__.py | 1 + controller/market.py | 55 ++++++++++++++++++++++++++++++++++++++++++ gui/bitmapLoader.py | 9 ++++++- gui/marketBrowser.py | 21 ++++++++++++++++ run.py | 2 -- 6 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 controller/market.py diff --git a/config.py b/config.py index 3c9394f2c..4a3436521 100644 --- a/config.py +++ b/config.py @@ -3,3 +3,4 @@ import sys #Path autodetection, only change if it doesn't work path = os.path.dirname(unicode(__file__, sys.getfilesystemencoding())) +homePath = os.path.expanduser(os.path.join("~", ".pyfa")) diff --git a/controller/__init__.py b/controller/__init__.py index e69de29bb..3b3ad6dd5 100644 --- a/controller/__init__.py +++ b/controller/__init__.py @@ -0,0 +1 @@ +from controller.market import Market diff --git a/controller/market.py b/controller/market.py new file mode 100644 index 000000000..f9d4a7309 --- /dev/null +++ b/controller/market.py @@ -0,0 +1,55 @@ +#=============================================================================== +# 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 Market(): + instance = None + + @classmethod + def getInstance(cls): + if cls.instance == None: + cls.instance = Market() + + return cls.instance + + + def getMarketRoot(self): + """ + Get the root of the market tree. + Returns a list, where each element is a tuple container: the ID, the name and the icon of the group + """ + + marketGroups = (9, #Modules + 1111, #Rigs + 157, #Drones + 11, #Ammo + 1112, #Subsystems + 24) #Implants & Boosters + groups = (920, ) #Effect Beacons + root = [] + for id in marketGroups: + mg = eos.db.getMarketGroup(id) + root.append((id, mg.name, mg.icon.iconFile)) + + for id in groups: + g = eos.db.getGroup(id) + root.append((id, g.name, g.icon.iconFile)) + + return root diff --git a/gui/bitmapLoader.py b/gui/bitmapLoader.py index 7362313e5..8312e02a8 100644 --- a/gui/bitmapLoader.py +++ b/gui/bitmapLoader.py @@ -26,6 +26,13 @@ def getStaticBitmap(name, parent, location): static.SetBitmap(getBitmap(name,location)) return static +locationMap = {"pack": os.path.join(config.homePath, "icons")} def getBitmap(name,location): - path = os.path.join(config.path, location, name + ".png") + if location in locationMap: + location = locationMap[location] + path = os.path.join(location, "icon%s.png" % name) + else: + location = os.path.join(config.path, location) + path = os.path.join(location, name + ".png") + return wx.Image(path).ConvertToBitmap() diff --git a/gui/marketBrowser.py b/gui/marketBrowser.py index 2a50bc50e..c3b8d76ca 100644 --- a/gui/marketBrowser.py +++ b/gui/marketBrowser.py @@ -18,6 +18,8 @@ #=============================================================================== import wx +import controller +import bitmapLoader class MarketBrowser(wx.Panel): def __init__(self, parent): @@ -29,8 +31,27 @@ class MarketBrowser(wx.Panel): vbox.Add(self.splitter, 1, wx.EXPAND) self.SetSizer(vbox) + self.marketView = wx.TreeCtrl(self.splitter) self.itemView = wx.TreeCtrl(self.splitter) + treeStyle = self.marketView.GetWindowStyleFlag() + treeStyle |= wx.TR_HIDE_ROOT + self.marketView.SetWindowStyleFlag(treeStyle) + self.itemView.SetWindowStyleFlag(treeStyle) + self.splitter.SplitHorizontally(self.marketView, self.itemView) self.splitter.SetMinimumPaneSize(10) + + self.marketRoot = self.marketView.AddRoot("Market") + self.itemRoot = self.itemView.AddRoot("Market") + + self.marketImageList = wx.ImageList(24, 24) + self.marketView.SetImageList(self.marketImageList) + + cMarket = controller.Market.getInstance() + + root = cMarket.getMarketRoot() + for id, name, iconFile in root: + iconId = self.marketImageList.Add(bitmapLoader.getBitmap(iconFile, "pack")) + self.marketView.AppendItem(self.marketRoot, name, iconId) diff --git a/run.py b/run.py index 29f504406..e2825fe3e 100644 --- a/run.py +++ b/run.py @@ -19,8 +19,6 @@ from gui.mainFrame import MainFrame import wx -import os -import sys if __name__ == "__main__": pyfa = wx.App(False)