From 53673bb6d49f0ebd754a612c1b43d214a5817481 Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Fri, 20 Aug 2010 16:44:35 +0200 Subject: [PATCH] Make buttons in shipBrowser activate when usable --- controller/__init__.py | 1 + controller/fit.py | 37 +++++++++++++++++++++++++++++++++++++ gui/mainMenuBar.py | 2 +- gui/shipBrowser.py | 41 ++++++++++++++++++++++++++++++++++------- 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 controller/fit.py diff --git a/controller/__init__.py b/controller/__init__.py index 3b3ad6dd5..7e2b42ae7 100644 --- a/controller/__init__.py +++ b/controller/__init__.py @@ -1 +1,2 @@ from controller.market import Market +from controller.fit import Fit diff --git a/controller/fit.py b/controller/fit.py new file mode 100644 index 000000000..3f3b3c706 --- /dev/null +++ b/controller/fit.py @@ -0,0 +1,37 @@ +#=============================================================================== +# 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 Fit(object): + instance = None + @classmethod + def getInstance(cls): + if cls.instance is None: + cls.instance = Fit() + + return cls.instance + + def getFitsWithShip(self, id): + fits = eos.db.getFitsWithShip(id) + names = [] + for fit in fits: + names.append(fit.name) + + return names diff --git a/gui/mainMenuBar.py b/gui/mainMenuBar.py index 5c628883d..71e1d73d7 100644 --- a/gui/mainMenuBar.py +++ b/gui/mainMenuBar.py @@ -52,7 +52,7 @@ class MainMenuBar(wx.MenuBar): charMenu = wx.Menu() self.Append(charMenu, "&Character") - charEditItem = wx.MenuItem(charMenu, 20, "Character &Editor") + charEditItem = wx.MenuItem(charMenu, 20, "Character &Editor\tCTRL+B") charEditItem.SetBitmap(bitmapLoader.getBitmap("character_small", "icons")) charMenu.AppendItem(charEditItem) diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index cb9a57b2e..03164ee39 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -30,6 +30,7 @@ class ShipBrowser(wx.Panel): self.races.append("None") #Bind our lookup method to when the tree gets expanded self.shipView.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.expandLookup) + self.shipView.Bind(wx.EVT_TREE_SEL_CHANGED, self.toggleButtons) self.idRaceMap = {} self.shipView.races = self.races self.shipView.idRaceMap = self.idRaceMap @@ -43,10 +44,31 @@ class ShipBrowser(wx.Panel): shipRoot = cMarket.getShipRoot() iconId = self.shipImageList.Add(bitmapLoader.getBitmap("ship_small", "icons")) for id, name in shipRoot: - childId = self.shipView.AppendItem(self.shipRoot, name, iconId, data=wx.TreeItemData(id)) + childId = self.shipView.AppendItem(self.shipRoot, name, iconId, data=wx.TreeItemData(("group", id))) self.shipView.AppendItem(childId, "dummy") self.shipView.SortChildren(self.shipRoot) + + def toggleButtons(self, event): + root = self.shipView.GetSelection() + btns = (self.shipMenu.new, self.shipMenu.rename, self.shipMenu.delete, self.shipMenu.copy) + if not root.IsOk(): + for btn in btns: + btn.Enable(False) + else: + type, groupID = self.shipView.GetPyData(root) + if type == "fit": + for btn in btns: + btn.Enable() + + elif type == "ship": + for btn in btns: + btn.Enable(btn == self.shipMenu.new) + + else: + for btn in btns: + btn.Enable(False) + def expandLookup(self, event): root = event.Item child, cookie = self.shipView.GetFirstChild(root) @@ -55,11 +77,16 @@ class ShipBrowser(wx.Panel): self.shipView.Delete(child) cMarket = controller.Market.getInstance() + cFit = controller.Fit.getInstance() - for id, name, race in cMarket.getShipList(self.shipView.GetPyData(root)): - iconId = self.raceImageIds[race] if race in self.raceImageIds else -1 - self.idRaceMap[id] = race - self.shipView.AppendItem(root, name, iconId, data=wx.TreeItemData(id)) + type, groupID = self.shipView.GetPyData(root) + if type == "group": + for id, name, race in cMarket.getShipList(groupID): + iconId = self.raceImageIds[race] if race in self.raceImageIds else -1 + self.idRaceMap[id] = race + childId = self.shipView.AppendItem(root, name, iconId, data=wx.TreeItemData(("ship", id))) + for fitID, fitName in cFit.getFitsWithShip(id): + self.shipView.AppendItem(childId, fitName, -1, data=wx.TreeItemData("fit", fitID)) self.shipView.SortChildren(root) @@ -75,8 +102,8 @@ class ShipView(wx.TreeCtrl): if child.IsOk(): return cmp(self.GetItemText(treeId1), self.GetItemText(treeId2)) else: - id1 = self.GetPyData(treeId1) - id2 = self.GetPyData(treeId2) + _, id1 = self.GetPyData(treeId1) + _, id2 = self.GetPyData(treeId2) c = cmp(self.races.index(self.idRaceMap[id1] or "None"), self.races.index(self.idRaceMap[id2] or "None")) if c != 0: return c