diff --git a/gui/fittingView.py b/gui/fittingView.py index 3f5dce7ee..f0837adf0 100644 --- a/gui/fittingView.py +++ b/gui/fittingView.py @@ -38,17 +38,43 @@ class FittingView(d.Display): "Max range", "Module Ammo"] + class FittingViewDrop(wx.PyDropTarget): + def __init__(self, dropFn): + wx.PyDropTarget.__init__(self) + self.dropFn = dropFn + # this is really transferring an EvE itemID + self.dropData = wx.PyTextDataObject() + self.SetDataObject(self.dropData) + + def OnData(self, x, y, t): + if self.GetData(): + self.dropFn(x, y, int(self.dropData.GetText())) + return t + def __init__(self, parent): d.Display.__init__(self, parent) self.mainFrame.Bind(FIT_CHANGED, self.fitChanged) self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem) + self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.startDrag) if "__WXGTK__" in wx.PlatformInfo: self.Bind(wx.EVT_RIGHT_UP, self.scheduleMenu) else: self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu) + self.SetDropTarget(self.FittingViewDrop(self.swapItems)) self.activeFitID = None + def startDrag(self, event): + data = wx.PyTextDataObject() + row = event.GetIndex() + data.SetText(str(self.GetItemData(row))) + + dropSource = wx.DropSource(self) + dropSource.SetData(data) + res = dropSource.DoDragDrop() + + # We always copy drag + self.Bind(wx.EVT_KEY_UP, self.kbEvent) def kbEvent(self,event): @@ -104,6 +130,24 @@ class FittingView(d.Display): if populate: self.slotsChanged() wx.PostEvent(self.mainFrame, FitChanged(fitID=self.activeFitID)) + def swapItems(self, x, y, itemID): + + srcRow = self.FindItemData(-1,itemID) + dstRow, _ = self.HitTest((x, y)) + if srcRow != -1 and dstRow != -1: + cFit = service.Fit.getInstance() +# populate = cFit.swapModules(self.activeFitID, self.mods[self.GetItemData(srcRow)].position, self.mods[self.GetItemData(dstRow)].position) +# cFit.swapModules(self.GetItemData(srcRow), self.GetItemData(dstRow)) + src = self.mods[self.GetItemData(srcRow)].position + dest = self.mods[self.GetItemData(dstRow)].position + self.mods[self.GetItemData(dstRow)].position = src + self.mods[self.GetItemData(srcRow)].position = dest + +# if populate is not None: + self.slotsChanged() + wx.PostEvent(self.mainFrame, FitChanged(fitID=self.activeFitID)) + + def generateMods(self): cFit = service.Fit.getInstance() fit = cFit.getFit(self.activeFitID) diff --git a/service/fit.py b/service/fit.py index 79981cfac..b5f7bca37 100644 --- a/service/fit.py +++ b/service/fit.py @@ -180,6 +180,19 @@ class Fit(object): eos.db.commit() return numSlots != len(fit.modules) + def swapModules(self, position1, position2): + return True + fit = eos.db.getFit(fitID) + if fit.modules[position1].isEmpty or fit.modules[position2].isEmpty: + return None + +# fit.modules[position1], fit.modules[position2] = fit.modules[position2], fit.modules[position1] + fit.modules[position1].position = position2 + fit.modules[position2].position = position1 + print position1,position2 + eos.db.commit() + return True + def addDrone(self, fitID, itemID): if fitID == None: return False