More work on commands, this time focusing on details with module add / remove functionalities.

This commit is contained in:
blitzmann
2018-08-02 02:06:03 -04:00
parent 098f0f92ee
commit fc153915b6
8 changed files with 80 additions and 52 deletions

View File

@@ -10,26 +10,29 @@ from .calc.fitRemoveModule import FitRemoveModuleCommand
class GuiModuleRemoveCommand(wx.Command):
def __init__(self, fitID, modules):
# todo: evaluate mutaplasmid modules
"""
:param fitID: The fit ID that we are modifying
:param modules: A list of Module objects that we are attempting to remove.
"""
wx.Command.__init__(self, True, "Module Remove")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
self.fitID = fitID
self.modCache = [ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge) for mod in modules]
self.modCache = [ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge, mod.baseItemID, mod.mutaplasmidID) for mod in modules if not mod.isEmpty]
self.internal_history = wx.CommandProcessor()
def Do(self):
# todo: what happens when one remove in an array of removes fucks up? (it really shouldn't it's easy peasy)
success = self.internal_history.Submit(FitRemoveModuleCommand(self.fitID, [mod.modPosition for mod in self.modCache]))
if success is not None:
# self.slotsChanged() # todo: fix
if success:
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=set([mod.itemID for mod in self.modCache])))
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, action="modadd", typeID=set([mod.itemID for mod in self.modCache])))