From f34f5cb4e1638feb17474e929241420b1eca7188 Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Fri, 20 Aug 2010 19:34:28 +0200 Subject: [PATCH] Make the new and rename buttons do intresting stuff --- controller/fit.py | 14 ++++++++++++++ gui/shipBrowser.py | 48 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/controller/fit.py b/controller/fit.py index 3f3b3c706..38b5c2da2 100644 --- a/controller/fit.py +++ b/controller/fit.py @@ -18,6 +18,7 @@ #=============================================================================== import eos.db +import eos.types class Fit(object): instance = None @@ -35,3 +36,16 @@ class Fit(object): names.append(fit.name) return names + + def newFit(self, shipID, name): + fit = eos.types.Fit() + fit.ship = eos.types.Ship(eos.db.getItem(shipID)) + fit.name = name + eos.db.saveddata_session.add(fit) + eos.db.saveddata_session.flush() + return fit.ID + + def renameFit(self, fitID, newName): + fit = eos.db.getFit(fitID) + fit.name = newName + eos.db.saveddata_session.flush() diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index 03164ee39..aa8ee7779 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -28,15 +28,22 @@ class ShipBrowser(wx.Panel): self.raceImageIds[race] = imageId 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 self.build() + #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.shipView.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.changeFitName) + + + #Bind buttons + self.shipMenu.new.Bind(wx.EVT_BUTTON, self.newFit) + self.shipMenu.rename.Bind(wx.EVT_BUTTON, self.renameFit) + def build(self): if not self.built: self.built = True @@ -90,6 +97,35 @@ class ShipBrowser(wx.Panel): self.shipView.SortChildren(root) + def newFit(self, event): + root = self.shipView.GetSelection() + type, shipID = self.shipView.GetPyData(root) + if type == "fit": + root = self.shipView.GetParent(root) + type, shipID = self.shipView.GetPyData(root) + + name = "%s fit" % self.shipView.GetItemText(root) + cFit = controller.Fit.getInstance() + fitID = cFit.newFit(shipID, name) + childId = self.shipView.AppendItem(root, name, -1, data=wx.TreeItemData(("fit", fitID))) + self.shipView.SortChildren(root) + self.shipView.Expand(root) + self.shipView.SelectItem(childId) + self.shipView.EditLabel(childId) + + def renameFit(self, event): + root = self.shipView.GetSelection() + type, _ = self.shipView.GetPyData(root) + if type == "fit": + self.shipView.EditLabel(root) + + def changeFitName(self, event): + item = event.Item + newName = self.shipView.GetItemText(item) + type, fitID = self.shipView.GetPyData(item) + cFit = controller.Fit.getInstance() + cFit.renameFit(fitID, newName) + class ShipView(wx.TreeCtrl): def __init__(self, parent): wx.TreeCtrl.__init__(self, parent) @@ -99,11 +135,11 @@ class ShipView(wx.TreeCtrl): def OnCompareItems(self, treeId1, treeId2): child, cookie = self.GetFirstChild(treeId1) - if child.IsOk(): + type1, id1 = self.GetPyData(treeId1) + type2, id2 = self.GetPyData(treeId2) + if type1 in ("fit", "group"): return cmp(self.GetItemText(treeId1), self.GetItemText(treeId2)) else: - _, 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