From bcbed3df39c02c7e9872f914d2b112b86646ad7a Mon Sep 17 00:00:00 2001 From: blitzmann Date: Thu, 16 Aug 2018 00:24:31 -0400 Subject: [PATCH] Fix an issue which caused pyfa to crash (turns out instantiating the commands in the init was not a good idea) --- gui/devTools.py | 15 +++++++++++++-- gui/fitCommands/guiAddBooster.py | 7 +++---- gui/fitCommands/guiAddCargo.py | 11 ++++++----- gui/fitCommands/guiAddCharge.py | 6 +++--- gui/fitCommands/guiAddCommand.py | 5 ++--- gui/fitCommands/guiAddFighter.py | 4 ++-- gui/fitCommands/guiAddImplant.py | 11 ++++++----- gui/fitCommands/guiCargoToModule.py | 1 + gui/fitCommands/guiMetaSwap.py | 3 +-- gui/fitCommands/guiModuleToCargo.py | 1 + gui/fitCommands/guiRemoveBooster.py | 7 +++---- gui/fitCommands/guiRemoveCargo.py | 9 ++++----- gui/fitCommands/guiRemoveCommand.py | 5 ++--- gui/fitCommands/guiRemoveImplant.py | 9 ++++----- gui/fitCommands/guiRemoveModule.py | 1 - gui/fitCommands/guiSetMode.py | 5 ++--- gui/fitCommands/guiSwapCloneModule.py | 4 ++++ gui/fitCommands/guiToggleCommand.py | 5 ++--- gui/fitCommands/guiToggleModuleState.py | 3 +-- 19 files changed, 60 insertions(+), 52 deletions(-) diff --git a/gui/devTools.py b/gui/devTools.py index 98a14662c..88486431a 100644 --- a/gui/devTools.py +++ b/gui/devTools.py @@ -35,7 +35,7 @@ class DevTools(wx.Dialog): def __init__(self, parent): wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title="Damage Pattern Editor", size=wx.Size(400, 240)) - + self.mainFrame = parent self.block = False self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) @@ -56,13 +56,19 @@ class DevTools(wx.Dialog): self.fitTest = wx.Button(self, wx.ID_ANY, "Test fits", wx.DefaultPosition, wx.DefaultSize, 0) mainSizer.Add(self.fitTest, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) - self.fitTest .Bind(wx.EVT_BUTTON, self.fit_test) + self.fitTest.Bind(wx.EVT_BUTTON, self.fit_test) + + self.cmdPrint = wx.Button(self, wx.ID_ANY, "Command Print", wx.DefaultPosition, wx.DefaultSize, 0) + mainSizer.Add(self.cmdPrint, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) + + self.cmdPrint.Bind(wx.EVT_BUTTON, self.cmd_print) self.SetSizer(mainSizer) self.Layout() self.CenterOnParent() self.Show() + print(parent) def objects_by_id(self, evt): input = self.id_get.GetValue() @@ -81,6 +87,11 @@ class DevTools(wx.Dialog): else: print(None) + def cmd_print(self, evt): + print("="*20) + for x in self.mainFrame.command.GetCommands(): + print("{}{} {}".format("==> " if x == self.mainFrame.command.GetCurrentCommand() else "", x.GetName(), x)) + def gc_collect(self, evt): print(gc.collect()) print(gc.get_debug()) diff --git a/gui/fitCommands/guiAddBooster.py b/gui/fitCommands/guiAddBooster.py index 3dc423cf6..fc89209cb 100644 --- a/gui/fitCommands/guiAddBooster.py +++ b/gui/fitCommands/guiAddBooster.py @@ -12,18 +12,17 @@ class GuiAddBoosterCommand(wx.Command): 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 = FitAddBoosterCommand(fitID, itemID) + self.itemID = itemID def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitAddBoosterCommand(self.fitID, self.itemID)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) diff --git a/gui/fitCommands/guiAddCargo.py b/gui/fitCommands/guiAddCargo.py index db923c7d1..d23af64bb 100644 --- a/gui/fitCommands/guiAddCargo.py +++ b/gui/fitCommands/guiAddCargo.py @@ -12,18 +12,19 @@ class GuiAddCargoCommand(wx.Command): 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 = FitAddCargoCommand(fitID, itemID, amount, replace) + self.itemID = itemID + self.amount = amount + self.replace = replace def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitAddCargoCommand(self.fitID, self.itemID, self.amount, self.replace)): wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiAddCharge.py b/gui/fitCommands/guiAddCharge.py index 6d1e5e70a..26ae3bf94 100644 --- a/gui/fitCommands/guiAddCharge.py +++ b/gui/fitCommands/guiAddCharge.py @@ -12,11 +12,11 @@ class GuiModuleAddChargeCommand(wx.Command): 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 = FitSetChargeCommand(fitID, [mod.modPosition for mod in modules], itemID) + self.itemID = itemID + self.positions = [mod.modPosition for mod in modules] def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitSetChargeCommand(self.fitID, self.positions, self.itemID)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiAddCommand.py b/gui/fitCommands/guiAddCommand.py index a46da244e..38f3a1110 100644 --- a/gui/fitCommands/guiAddCommand.py +++ b/gui/fitCommands/guiAddCommand.py @@ -12,11 +12,10 @@ class GuiAddCommandCommand(wx.Command): 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 = FitAddCommandCommand(fitID, commandFitID) + self.commandFitID = commandFitID def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitAddCommandCommand(self.fitID, self.commandFitID)): wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) self.sFit.recalc(self.fitID) return True diff --git a/gui/fitCommands/guiAddFighter.py b/gui/fitCommands/guiAddFighter.py index 095688142..2e699b53a 100644 --- a/gui/fitCommands/guiAddFighter.py +++ b/gui/fitCommands/guiAddFighter.py @@ -15,8 +15,7 @@ class GuiAddFighterCommand(wx.Command): self.itemID = itemID def Do(self): - cmd = FitAddFighterCommand(self.fitID, self.itemID) - if self.internal_history.Submit(cmd): + if self.internal_history.Submit(FitAddFighterCommand(self.fitID, self.itemID)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True @@ -25,6 +24,7 @@ class GuiAddFighterCommand(wx.Command): 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/gui/fitCommands/guiAddImplant.py b/gui/fitCommands/guiAddImplant.py index 33495398d..d819a55d3 100644 --- a/gui/fitCommands/guiAddImplant.py +++ b/gui/fitCommands/guiAddImplant.py @@ -12,18 +12,19 @@ class GuiAddImplantCommand(wx.Command): 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 = FitAddImplantCommand(fitID, itemID) + self.itemID = itemID def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)): + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiCargoToModule.py b/gui/fitCommands/guiCargoToModule.py index 3ce9cc4b0..506c47001 100644 --- a/gui/fitCommands/guiCargoToModule.py +++ b/gui/fitCommands/guiCargoToModule.py @@ -71,5 +71,6 @@ class GuiCargoToModuleCommand(wx.Command): 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/gui/fitCommands/guiMetaSwap.py b/gui/fitCommands/guiMetaSwap.py index e5f3848a5..9b4af4039 100644 --- a/gui/fitCommands/guiMetaSwap.py +++ b/gui/fitCommands/guiMetaSwap.py @@ -46,7 +46,6 @@ class GuiMetaSwapCommand(wx.Command): elif context == 'droneItem': raise NotImplementedError() - def Do(self): for cmds in self.data: for cmd in cmds: @@ -57,7 +56,7 @@ class GuiMetaSwapCommand(wx.Command): return True def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) diff --git a/gui/fitCommands/guiModuleToCargo.py b/gui/fitCommands/guiModuleToCargo.py index d59680408..c0b483d2c 100644 --- a/gui/fitCommands/guiModuleToCargo.py +++ b/gui/fitCommands/guiModuleToCargo.py @@ -67,5 +67,6 @@ class GuiModuleToCargoCommand(wx.Command): 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/gui/fitCommands/guiRemoveBooster.py b/gui/fitCommands/guiRemoveBooster.py index 2155ab120..0e96f1c2e 100644 --- a/gui/fitCommands/guiRemoveBooster.py +++ b/gui/fitCommands/guiRemoveBooster.py @@ -12,18 +12,17 @@ class GuiRemoveBoosterCommand(wx.Command): 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 = FitRemoveBoosterCommand(fitID, position) + self.position = position def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitRemoveBoosterCommand(self.fitID, self.position)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) diff --git a/gui/fitCommands/guiRemoveCargo.py b/gui/fitCommands/guiRemoveCargo.py index 210252418..ec42e4d3c 100644 --- a/gui/fitCommands/guiRemoveCargo.py +++ b/gui/fitCommands/guiRemoveCargo.py @@ -12,18 +12,17 @@ class GuiRemoveCargoCommand(wx.Command): 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 = FitRemoveCargoCommand(fitID, itemID, stack=True) + self.itemID = itemID def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitRemoveCargoCommand(self.fitID, self.itemID, stack=True)): wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.GetCommands(): self.internal_history.Undo() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiRemoveCommand.py b/gui/fitCommands/guiRemoveCommand.py index d01abce08..351f9697b 100644 --- a/gui/fitCommands/guiRemoveCommand.py +++ b/gui/fitCommands/guiRemoveCommand.py @@ -12,11 +12,10 @@ class GuiRemoveCommandCommand(wx.Command): 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 = FitRemoveCommandCommand(fitID, commandFitID) + self.commandFitID = commandFitID def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitRemoveCommandCommand(self.fitID, self.commandFitID)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiRemoveImplant.py b/gui/fitCommands/guiRemoveImplant.py index af96355a4..7c9c6a4c1 100644 --- a/gui/fitCommands/guiRemoveImplant.py +++ b/gui/fitCommands/guiRemoveImplant.py @@ -12,18 +12,17 @@ class GuiRemoveImplantCommand(wx.Command): 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 = FitRemoveImplantCommand(fitID, position) + self.position = position def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitRemoveImplantCommand(self.fitID, self.position)): wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiRemoveModule.py b/gui/fitCommands/guiRemoveModule.py index 169dbe593..848708856 100644 --- a/gui/fitCommands/guiRemoveModule.py +++ b/gui/fitCommands/guiRemoveModule.py @@ -3,7 +3,6 @@ from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE - from .helpers import ModuleInfoCache from .calc.fitRemoveModule import FitRemoveModuleCommand diff --git a/gui/fitCommands/guiSetMode.py b/gui/fitCommands/guiSetMode.py index 2c1e4864c..0ad7b80f6 100644 --- a/gui/fitCommands/guiSetMode.py +++ b/gui/fitCommands/guiSetMode.py @@ -12,11 +12,10 @@ class GuiSetModeCommand(wx.Command): 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) + self.mode = mode def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitSetModeCommand(self.fitID, self.mode)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiSwapCloneModule.py b/gui/fitCommands/guiSwapCloneModule.py index 65ddea591..cbeaf0845 100644 --- a/gui/fitCommands/guiSwapCloneModule.py +++ b/gui/fitCommands/guiSwapCloneModule.py @@ -42,5 +42,9 @@ class GuiModuleSwapOrCloneCommand(wx.Command): pyfalog.debug("{} Undo()".format(self)) for _ in self.internal_history.Commands: self.internal_history.Undo() + + if self.clone: + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiToggleCommand.py b/gui/fitCommands/guiToggleCommand.py index b7f07ed78..85f32c143 100644 --- a/gui/fitCommands/guiToggleCommand.py +++ b/gui/fitCommands/guiToggleCommand.py @@ -12,11 +12,10 @@ class GuiToggleCommandCommand(wx.Command): 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 = FitToggleCommandCommand(fitID, commandFitID) + self.commandFitID = commandFitID def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitToggleCommandCommand(self.fitID, self.commandFitID)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiToggleModuleState.py b/gui/fitCommands/guiToggleModuleState.py index 7fcd824b1..d87339347 100644 --- a/gui/fitCommands/guiToggleModuleState.py +++ b/gui/fitCommands/guiToggleModuleState.py @@ -17,10 +17,9 @@ class GuiModuleStateChangeCommand(wx.Command): self.modules = modules self.click = click self.internal_history = wx.CommandProcessor() - self.cmd = FitChangeStatesCommand(self.fitID, self.baseMod, self.modules, self.click) def Do(self): - if self.internal_history.Submit(self.cmd): + if self.internal_history.Submit(FitChangeStatesCommand(self.fitID, self.baseMod, self.modules, self.click)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True