Files
pyfa/gui/fitCommands/gui/localFighter/remove.py
2019-04-24 15:17:30 +03:00

36 lines
1.2 KiB
Python

import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fighter.localRemove import CalcRemoveLocalFighterCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiRemoveLocalFightersCommand(wx.Command):
def __init__(self, fitID, positions):
wx.Command.__init__(self, True, 'Remove Local Fighters')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.positions = positions
def Do(self):
results = []
for position in sorted(self.positions, reverse=True):
cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=position, commit=False)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success