Change command-related commands a little

This commit is contained in:
DarkPhoenix
2019-04-12 22:24:13 +03:00
parent 336af0f669
commit e6c9db3eef
4 changed files with 40 additions and 46 deletions

View File

@@ -8,52 +8,52 @@ from service.fit import Fit
pyfalog = Logger(__name__)
class FitAddCommandCommand(wx.Command): # well that's an unfrtunate name
""""
from sFit.addCommand
"""
def __init__(self, fitID, commandFitID, state):
class FitAddCommandCommand(wx.Command):
def __init__(self, fitID, commandFitID, state=None):
wx.Command.__init__(self, True)
self.fitID = fitID
self.commandFitID = commandFitID
self.state = state
def Do(self):
pyfalog.debug("Projecting command fit ({0}) onto: {1}".format(self.fitID, self.commandFitID))
pyfalog.debug('Doing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
commandFit = sFit.getFit(self.commandFitID)
if not commandFit:
# if redoing when the command fit has been deleted, simply fail this command
# Command fit could have been deleted if we were redoing
if commandFit is None:
pyfalog.debug('Command fit is not available')
return False
# Already commanding this ship
if commandFit in fit.commandFits:
pyfalog.debug('Command fit had been applied already')
return False
fit.commandFitDict[commandFit.ID] = commandFit
# this bit is required -- see GH issue # 83
eos.db.saveddata_session.flush()
eos.db.saveddata_session.refresh(commandFit)
if self.state is not None:
commandInfo = commandFit.getCommandInfo(self.fitID)
if not commandInfo:
fitCommandInfo = commandFit.getCommandInfo(self.fitID)
if fitCommandInfo is None:
pyfalog.warning('Fit command info is not available')
self.Undo()
return False
commandInfo.active = self.state
fitCommandInfo.active = self.state
eos.db.commit()
return True
def Undo(self):
command = eos.db.getFit(self.commandFitID)
if not command:
# can't find the command fit, it must have been deleted. Just skip this undo
pyfalog.debug('Undoing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
# Can't find the command fit, it must have been deleted. Just skip, as deleted fit
# means that someone else just did exactly what we wanted to do
commandFit = Fit.getInstance().getFit(self.commandFitID)
if commandFit is None:
return True
from .fitRemoveCommand import FitRemoveCommandCommand
cmd = FitRemoveCommandCommand(self.fitID, self.commandFitID)
cmd.Do()
return True
cmd = FitRemoveCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID)
return cmd.Do()