Make buttons in shipBrowser activate when usable
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from controller.market import Market
|
||||
from controller.fit import Fit
|
||||
|
||||
37
controller/fit.py
Normal file
37
controller/fit.py
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
#===============================================================================
|
||||
|
||||
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
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user