diff --git a/eos/db/saveddata/implantSet.py b/eos/db/saveddata/implantSet.py index d72b9097a..73036de91 100644 --- a/eos/db/saveddata/implantSet.py +++ b/eos/db/saveddata/implantSet.py @@ -35,7 +35,7 @@ mapper(ImplantSet, implant_set_table, "_ImplantSet__implants": relation( Implant, collection_class = HandledImplantBoosterList, - cascade='all,delete-orphan', + cascade='all, delete, delete-orphan', backref='set', single_parent=True, primaryjoin = implantsSetMap_table.c.setID == implant_set_table.c.ID, diff --git a/gui/setEditor.py b/gui/setEditor.py index 14037b24b..935669306 100644 --- a/gui/setEditor.py +++ b/gui/setEditor.py @@ -24,13 +24,30 @@ import service from gui.utils.clipboard import toClipboard, fromClipboard from service.targetResists import ImportError -class EditorView(BaseImplantEditorView): +class ImplantSetEditor(BaseImplantEditorView): def __init__(self, parent): BaseImplantEditorView.__init__(self, parent) - self.parent = parent - def getImplants(self): - return [] + def bindContext(self): + self.Parent.ccSets.Bind(wx.EVT_CHOICE, self.contextChanged) + + def getImplantsFromContext(self): + sIS = service.ImplantSets.getInstance() + setID = self.Parent.getActiveSet() + + return sIS.getImplants(setID) + + def addImplantToContext(self, item): + sIS = service.ImplantSets.getInstance() + setID = self.Parent.getActiveSet() + + sIS.addImplant(setID, item.ID) + + def removeImplantFromContext(self, pos): + sIS = service.ImplantSets.getInstance() + setID = self.Parent.getActiveSet() + + sIS.removeImplant(setID, self.implants[pos]) class ImplantSetEditorDlg(wx.Dialog): @@ -51,7 +68,11 @@ class ImplantSetEditorDlg(wx.Dialog): # Sort the remaining list and continue on self.choices.sort(key=lambda s: s.name) - self.ccSets = wx.Choice(self, choices=map(lambda s: s.name, self.choices)) + self.ccSets = wx.Choice(self, wx.ID_ANY, style=0) + + for set in self.choices: + i = self.ccSets.Append(set.name, set.ID) + self.ccSets.Bind(wx.EVT_CHOICE, self.setChanged) self.ccSets.SetSelection(0) @@ -92,7 +113,7 @@ class ImplantSetEditorDlg(wx.Dialog): self.sl = wx.StaticLine(self) mainSizer.Add(self.sl, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) - self.iview = EditorView(self) + self.iview = ImplantSetEditor(self) mainSizer.Add(self.iview, 0, wx.EXPAND) contentSizer = wx.BoxSizer(wx.VERTICAL) @@ -152,6 +173,10 @@ class ImplantSetEditorDlg(wx.Dialog): def closeEvent(self, event): self.Destroy() + def getActiveSet(self): + selection = self.ccSets.GetCurrentSelection() + return self.ccSets.GetClientData(selection) if selection is not None else None + def ValuesUpdated(self, event=None): ''' Event that is fired when resists values change. Iterates through all diff --git a/service/character.py b/service/character.py index cf7e03102..6078ccd8a 100644 --- a/service/character.py +++ b/service/character.py @@ -351,10 +351,12 @@ class Character(object): implant = eos.types.Implant(eos.db.getItem(itemID)) char.implants.append(implant) + eos.db.commit() def removeImplant(self, charID, implant): char = eos.db.getCharacter(charID) char.implants.remove(implant) + eos.db.commit() def getImplants(self, charID): char = eos.db.getCharacter(charID) diff --git a/service/implantSet.py b/service/implantSet.py index ff7469536..7bb52c921 100644 --- a/service/implantSet.py +++ b/service/implantSet.py @@ -39,6 +39,21 @@ class ImplantSets(): def getImplantSet(self, name): return eos.db.getImplantSet(name) + def getImplants(self, setID): + set = eos.db.getImplantSet(setID) + return set.implants + + def addImplant(self, setID, itemID): + set = eos.db.getImplantSet(setID) + implant = eos.types.Implant(eos.db.getItem(itemID)) + set.implants.append(implant) + eos.db.commit() + + def removeImplant(self, setID, implant): + set = eos.db.getImplantSet(setID) + set.implants.remove(implant) + eos.db.commit() + def newSet(self): p = eos.types.ImplantSet() p.name = ""