Implement drone toggle command
This commit is contained in:
@@ -239,10 +239,8 @@ class DroneView(Display):
|
||||
col = self.getColumn(event.Position)
|
||||
if col == self.getColIndex(State):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
sFit = Fit.getInstance()
|
||||
drone = self.drones[row]
|
||||
sFit.toggleDrone(fitID, self.original.index(drone))
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleDroneCommand(fitID, self.original.index(drone)))
|
||||
|
||||
def scheduleMenu(self, event):
|
||||
event.Skip()
|
||||
|
||||
@@ -29,4 +29,5 @@ from .guiChangeFighterQty import GuiChangeFighterQty
|
||||
from .guiChangeCargoQty import GuiChangeCargoQty
|
||||
from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty
|
||||
from .guiChangeDroneQty import GuiChangeDroneQty
|
||||
from.guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
from .guiToggleDrone import GuiToggleDroneCommand
|
||||
35
gui/fitCommands/calc/fitToggleDrone.py
Normal file
35
gui/fitCommands/calc/fitToggleDrone.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
class FitToggleDroneCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleDrone
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Cargo add")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling drones for fit ID: {0}", self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
d = fit.drones[self.position]
|
||||
if d.amount == d.amountActive:
|
||||
d.amountActive = 0
|
||||
else:
|
||||
d.amountActive = d.amount
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleDroneCommand(self.fitID, self.position)
|
||||
return cmd.Do()
|
||||
30
gui/fitCommands/guiToggleDrone.py
Normal file
30
gui/fitCommands/guiToggleDrone.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleDrone import FitToggleDroneCommand
|
||||
|
||||
class GuiToggleDroneCommand(wx.Command):
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleDroneCommand(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 _ 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
|
||||
|
||||
Reference in New Issue
Block a user