From 15ba5c8ace1b1fcb2a22e48d0af87838a06ca37e Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 3 Aug 2018 02:01:42 -0400 Subject: [PATCH] Convert tactical mode switching --- gui/builtinContextMenus/tacticalMode.py | 6 ++--- gui/fitCommands/__init__.py | 1 + gui/fitCommands/calc/fitSetMode.py | 34 +++++++++++++++++++++++++ gui/fitCommands/guiSetMode.py | 31 ++++++++++++++++++++++ service/fit.py | 1 + 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 gui/fitCommands/calc/fitSetMode.py create mode 100644 gui/fitCommands/guiSetMode.py diff --git a/gui/builtinContextMenus/tacticalMode.py b/gui/builtinContextMenus/tacticalMode.py index e09b26940..04c82574f 100644 --- a/gui/builtinContextMenus/tacticalMode.py +++ b/gui/builtinContextMenus/tacticalMode.py @@ -6,7 +6,7 @@ import gui.mainFrame import gui.globalEvents as GE from service.fit import Fit from service.settings import ContextMenuSettings - +import gui.fitCommands as cmd class TacticalMode(ContextMenu): def __init__(self): @@ -60,10 +60,8 @@ class TacticalMode(ContextMenu): event.Skip() return - sFit = Fit.getInstance() fitID = self.mainFrame.getActiveFit() - sFit.setMode(fitID, self.modeIds[event.Id]) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiSetModeCommand(fitID, self.modeIds[event.Id])) TacticalMode.register() diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 89a74b369..c7a37439f 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -7,3 +7,4 @@ from .guiRemoveCargo import GuiRemoveCargoCommand from .guiAddCargo import GuiAddCargoCommand from .guiRemoveImplant import GuiRemoveImplantCommand from .guiAddImplant import GuiAddImplantCommand +from .guiSetMode import GuiSetModeCommand \ No newline at end of file diff --git a/gui/fitCommands/calc/fitSetMode.py b/gui/fitCommands/calc/fitSetMode.py new file mode 100644 index 000000000..183c292aa --- /dev/null +++ b/gui/fitCommands/calc/fitSetMode.py @@ -0,0 +1,34 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +pyfalog = Logger(__name__) + + +class FitSetModeCommand(wx.Command): + """" + from sFit.setMode + """ + def __init__(self, fitID, mode): + wx.Command.__init__(self, True, "Cargo add") + self.fitID = fitID + self.mode = mode + self.old_mode = None + + def Do(self): + pyfalog.debug("Set mode for fit ID: {0}", self.fitID) + fit = eos.db.getFit(self.fitID) + self.old_mode = fit.mode + fit.mode = self.mode + eos.db.commit() + return True + + def Undo(self): + cmd = FitSetModeCommand(self.fitID, self.old_mode) + cmd.Do() + return True diff --git a/gui/fitCommands/guiSetMode.py b/gui/fitCommands/guiSetMode.py new file mode 100644 index 000000000..2c1e4864c --- /dev/null +++ b/gui/fitCommands/guiSetMode.py @@ -0,0 +1,31 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +from .calc.fitSetMode import FitSetModeCommand + +class GuiSetModeCommand(wx.Command): + def __init__(self, fitID, mode): + wx.Command.__init__(self, True, "Cargo Add") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.internal_history = wx.CommandProcessor() + self.fitID = fitID + # can set his up no to not have to set variables on our object + self.cmd = FitSetModeCommand(fitID, mode) + + def Do(self): + if self.internal_history.Submit(self.cmd): + 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 d3ed7d9c7..47c9c2960 100644 --- a/service/fit.py +++ b/service/fit.py @@ -1155,6 +1155,7 @@ class Fit(object): self.recalc(fit) + @deprecated def setMode(self, fitID, mode): pyfalog.debug("Set mode for fit ID: {0}", fitID) if fitID is None: