diff --git a/gui/builtinAdditionPanes/implantView.py b/gui/builtinAdditionPanes/implantView.py index 1422f19ae..0b8521cea 100644 --- a/gui/builtinAdditionPanes/implantView.py +++ b/gui/builtinAdditionPanes/implantView.py @@ -23,6 +23,7 @@ import gui.display as d from gui.builtinMarketBrowser.events import ITEM_SELECTED import gui.mainFrame from gui.builtinViewColumns.state import State +from gui.utils.staticHelpers import DragDropHelper from gui.contextMenu import ContextMenu import gui.globalEvents as GE from eos.saveddata.fit import ImplantLocation @@ -31,6 +32,22 @@ from service.market import Market import gui.fitCommands as cmd +class ImplantViewDrop(wx.DropTarget): + def __init__(self, dropFn, *args, **kwargs): + super(ImplantViewDrop, self).__init__(*args, **kwargs) + self.dropFn = dropFn + # this is really transferring an EVE itemID + self.dropData = wx.TextDataObject() + self.SetDataObject(self.dropData) + + def OnData(self, x, y, t): + if self.GetData(): + dragged_data = DragDropHelper.data + data = dragged_data.split(':') + self.dropFn(x, y, data) + return t + + class ImplantView(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL) @@ -77,10 +94,7 @@ class ImplantView(wx.Panel): def OnRadioSelect(self, event): fitID = self.mainFrame.getActiveFit() if fitID is not None: - sFit = Fit.getInstance() - sFit.toggleImplantSource(fitID, ImplantLocation.FIT if self.rbFit.GetValue() else ImplantLocation.CHARACTER) - - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiChangeImplantLocation(fitID, ImplantLocation.FIT if self.rbFit.GetValue() else ImplantLocation.CHARACTER)) class ImplantDisplay(d.Display): @@ -102,12 +116,27 @@ class ImplantDisplay(d.Display): self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem) self.Bind(wx.EVT_LEFT_DOWN, self.click) self.Bind(wx.EVT_KEY_UP, self.kbEvent) + self.SetDropTarget(ImplantViewDrop(self.handleListDrag)) + if "__WXGTK__" in wx.PlatformInfo: self.Bind(wx.EVT_RIGHT_UP, self.scheduleMenu) else: self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu) + def handleListDrag(self, x, y, data): + """ + Handles dragging of items from various pyfa displays which support it + + data is list with two indices: + data[0] is hard-coded str of originating source + data[1] is typeID or index of data we want to manipulate + """ + + if data[0] == "market": + if self.mainFrame.command.Submit(cmd.GuiAddImplantCommand(self.mainFrame.getActiveFit(), int(data[1]))): + self.mainFrame.additionsPane.select("Implants") + def kbEvent(self, event): keycode = event.GetKeyCode() if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE: diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index ae651d7bd..145201559 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -31,4 +31,5 @@ from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty from .guiChangeDroneQty import GuiChangeDroneQty from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty from .guiToggleDrone import GuiToggleDroneCommand -from .guiFitRename import GuiFitRenameCommand \ No newline at end of file +from .guiFitRename import GuiFitRenameCommand +from .guiChangeImplantLocation import GuiChangeImplantLocation \ No newline at end of file diff --git a/gui/fitCommands/calc/fitChangeImplantLocation.py b/gui/fitCommands/calc/fitChangeImplantLocation.py new file mode 100644 index 000000000..fc1dec890 --- /dev/null +++ b/gui/fitCommands/calc/fitChangeImplantLocation.py @@ -0,0 +1,25 @@ +import wx +import eos.db +from logbook import Logger +pyfalog = Logger(__name__) + + +class FitChangeImplantLocation(wx.Command): + def __init__(self, fitID, source): + wx.Command.__init__(self, True, "Drone add") + self.fitID = fitID + self.source = source + self.old_source = None + + def Do(self): + pyfalog.debug("Toggling implant source for fit ID: {0}", self.fitID) + fit = eos.db.getFit(self.fitID) + self.old_source = fit.implantSource + fit.implantSource = self.source + eos.db.commit() + return True + + + def Undo(self): + cmd = FitChangeImplantLocation(self.fitID, self.old_source) + return cmd.Do() diff --git a/gui/fitCommands/guiAddImplant.py b/gui/fitCommands/guiAddImplant.py index ffbc1e0a4..79b75f014 100644 --- a/gui/fitCommands/guiAddImplant.py +++ b/gui/fitCommands/guiAddImplant.py @@ -3,7 +3,9 @@ from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE +from eos.saveddata.fit import ImplantLocation from .calc.fitAddImplant import FitAddImplantCommand +from .calc.fitChangeImplantLocation import FitChangeImplantLocation class GuiAddImplantCommand(wx.Command): @@ -16,7 +18,7 @@ class GuiAddImplantCommand(wx.Command): self.itemID = itemID def Do(self): - if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)): + if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)) and self.internal_history.Submit(FitChangeImplantLocation(self.fitID, ImplantLocation.FIT)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiChangeImplantLocation.py b/gui/fitCommands/guiChangeImplantLocation.py new file mode 100644 index 000000000..5d6c57e9d --- /dev/null +++ b/gui/fitCommands/guiChangeImplantLocation.py @@ -0,0 +1,30 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +from .calc.fitChangeImplantLocation import FitChangeImplantLocation + + +class GuiChangeImplantLocation(wx.Command): + def __init__(self, fitID, source): + wx.Command.__init__(self, True, "Implant Source Change") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.internal_history = wx.CommandProcessor() + self.fitID = fitID + self.source = source + + def Do(self): + if self.internal_history.Submit(FitChangeImplantLocation(self.fitID, self.source)): + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + for _ in self.internal_history.Commands: + self.internal_history.Undo() + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True diff --git a/service/fit.py b/service/fit.py index 3cbe96fcf..ad1e5c4dd 100644 --- a/service/fit.py +++ b/service/fit.py @@ -424,15 +424,6 @@ class Fit(FitDeprecated): else: return False - def toggleImplantSource(self, fitID, source): - pyfalog.debug("Toggling implant source for fit ID: {0}", fitID) - fit = eos.db.getFit(fitID) - fit.implantSource = source - - eos.db.commit() - self.recalc(fit) - return True - def toggleRestrictionIgnore(self, fitID): pyfalog.debug("Toggling restriction ignore for fit ID: {0}", fitID) fit = eos.db.getFit(fitID) diff --git a/service/fitDeprecated.py b/service/fitDeprecated.py index 531191b9d..4f0d79b0d 100644 --- a/service/fitDeprecated.py +++ b/service/fitDeprecated.py @@ -46,6 +46,16 @@ class FitDeprecated(object): eos.db.commit() return old_name, newName + @deprecated + def toggleImplantSource(self, fitID, source): + pyfalog.debug("Toggling implant source for fit ID: {0}", fitID) + fit = eos.db.getFit(fitID) + fit.implantSource = source + + eos.db.commit() + self.recalc(fit) + return True + @deprecated def toggleDrone(self, fitID, i): pyfalog.debug("Toggling drones for fit ID: {0}", fitID)