From 881b92a6eaa0f241abd18d2235aa5fc5534d4c78 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 28 Oct 2018 21:59:14 -0400 Subject: [PATCH] Convert implant location change to a command --- gui/builtinAdditionPanes/implantView.py | 5 +--- gui/fitCommands/__init__.py | 3 +- .../calc/fitChangeImplantLocation.py | 25 ++++++++++++++++ gui/fitCommands/guiAddImplant.py | 4 ++- gui/fitCommands/guiChangeImplantLocation.py | 30 +++++++++++++++++++ service/fit.py | 9 ------ service/fitDeprecated.py | 10 +++++++ 7 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 gui/fitCommands/calc/fitChangeImplantLocation.py create mode 100644 gui/fitCommands/guiChangeImplantLocation.py diff --git a/gui/builtinAdditionPanes/implantView.py b/gui/builtinAdditionPanes/implantView.py index 1422f19ae..5cdc72679 100644 --- a/gui/builtinAdditionPanes/implantView.py +++ b/gui/builtinAdditionPanes/implantView.py @@ -77,10 +77,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): 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)