Merge branch 'commandRefactor' of https://bitbucket.org/blitzmann/pyfa-playground into commandRefactor

This commit is contained in:
Ryan Holmes
2018-08-16 23:41:19 -04:00
19 changed files with 60 additions and 52 deletions

View File

@@ -35,7 +35,7 @@ class DevTools(wx.Dialog):
def __init__(self, parent): def __init__(self, parent):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title="Damage Pattern Editor", size=wx.Size(400, 240)) 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.block = False
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) 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) 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) 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.SetSizer(mainSizer)
self.Layout() self.Layout()
self.CenterOnParent() self.CenterOnParent()
self.Show() self.Show()
print(parent)
def objects_by_id(self, evt): def objects_by_id(self, evt):
input = self.id_get.GetValue() input = self.id_get.GetValue()
@@ -81,6 +87,11 @@ class DevTools(wx.Dialog):
else: else:
print(None) 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): def gc_collect(self, evt):
print(gc.collect()) print(gc.collect())
print(gc.get_debug()) print(gc.get_debug())

View File

@@ -12,18 +12,17 @@ class GuiAddBoosterCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.itemID = itemID
self.cmd = FitAddBoosterCommand(fitID, itemID)
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
return False return False
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
self.sFit.recalc(self.fitID) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))

View File

@@ -12,18 +12,19 @@ class GuiAddCargoCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.itemID = itemID
self.cmd = FitAddCargoCommand(fitID, itemID, amount, replace) self.amount = amount
self.replace = replace
def Do(self): 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)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
return False return False
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,11 +12,11 @@ class GuiModuleAddChargeCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.itemID = itemID
self.cmd = FitSetChargeCommand(fitID, [mod.modPosition for mod in modules], itemID) self.positions = [mod.modPosition for mod in modules]
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,11 +12,10 @@ class GuiAddCommandCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.commandFitID = commandFitID
self.cmd = FitAddCommandCommand(fitID, commandFitID)
def Do(self): 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)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
self.sFit.recalc(self.fitID) self.sFit.recalc(self.fitID)
return True return True

View File

@@ -15,8 +15,7 @@ class GuiAddFighterCommand(wx.Command):
self.itemID = itemID self.itemID = itemID
def Do(self): def Do(self):
cmd = FitAddFighterCommand(self.fitID, self.itemID) if self.internal_history.Submit(FitAddFighterCommand(self.fitID, self.itemID)):
if self.internal_history.Submit(cmd):
self.sFit.recalc(self.fitID) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
@@ -25,6 +24,7 @@ class GuiAddFighterCommand(wx.Command):
def Undo(self): def Undo(self):
for _ in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,18 +12,19 @@ class GuiAddImplantCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.itemID = itemID
self.cmd = FitAddImplantCommand(fitID, itemID)
def Do(self): 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)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
return False return False
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() 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 return True

View File

@@ -71,5 +71,6 @@ class GuiCargoToModuleCommand(wx.Command):
def Undo(self): def Undo(self):
for _ in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -46,7 +46,6 @@ class GuiMetaSwapCommand(wx.Command):
elif context == 'droneItem': elif context == 'droneItem':
raise NotImplementedError() raise NotImplementedError()
def Do(self): def Do(self):
for cmds in self.data: for cmds in self.data:
for cmd in cmds: for cmd in cmds:
@@ -57,7 +56,7 @@ class GuiMetaSwapCommand(wx.Command):
return True return True
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
self.sFit.recalc(self.fitID) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))

View File

@@ -67,5 +67,6 @@ class GuiModuleToCargoCommand(wx.Command):
def Undo(self): def Undo(self):
for _ in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,18 +12,17 @@ class GuiRemoveBoosterCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.position = position
self.cmd = FitRemoveBoosterCommand(fitID, position)
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
return False return False
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
self.sFit.recalc(self.fitID) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))

View File

@@ -12,18 +12,17 @@ class GuiRemoveCargoCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.itemID = itemID
self.cmd = FitRemoveCargoCommand(fitID, itemID, stack=True)
def Do(self): 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)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
return False return False
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.GetCommands():
self.internal_history.Undo() self.internal_history.Undo()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,11 +12,10 @@ class GuiRemoveCommandCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.commandFitID = commandFitID
self.cmd = FitRemoveCommandCommand(fitID, commandFitID)
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,18 +12,17 @@ class GuiRemoveImplantCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.position = position
self.cmd = FitRemoveImplantCommand(fitID, position)
def Do(self): 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)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True
return False return False
def Undo(self): def Undo(self):
for x in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -3,7 +3,6 @@ from service.fit import Fit
import gui.mainFrame import gui.mainFrame
from gui import globalEvents as GE from gui import globalEvents as GE
from .helpers import ModuleInfoCache from .helpers import ModuleInfoCache
from .calc.fitRemoveModule import FitRemoveModuleCommand from .calc.fitRemoveModule import FitRemoveModuleCommand

View File

@@ -12,11 +12,10 @@ class GuiSetModeCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.mode = mode
self.cmd = FitSetModeCommand(fitID, mode)
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -42,5 +42,9 @@ class GuiModuleSwapOrCloneCommand(wx.Command):
pyfalog.debug("{} Undo()".format(self)) pyfalog.debug("{} Undo()".format(self))
for _ in self.internal_history.Commands: for _ in self.internal_history.Commands:
self.internal_history.Undo() self.internal_history.Undo()
if self.clone:
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -12,11 +12,10 @@ class GuiToggleCommandCommand(wx.Command):
self.sFit = Fit.getInstance() self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.fitID = fitID self.fitID = fitID
# can set his up no to not have to set variables on our object self.commandFitID = commandFitID
self.cmd = FitToggleCommandCommand(fitID, commandFitID)
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -17,10 +17,9 @@ class GuiModuleStateChangeCommand(wx.Command):
self.modules = modules self.modules = modules
self.click = click self.click = click
self.internal_history = wx.CommandProcessor() self.internal_history = wx.CommandProcessor()
self.cmd = FitChangeStatesCommand(self.fitID, self.baseMod, self.modules, self.click)
def Do(self): 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) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True