Rework cargo-related GUI commands and use command when deleting item from cargo with delete key
This commit is contained in:
@@ -85,7 +85,7 @@ class BoosterView(d.Display):
|
||||
|
||||
def kbEvent(self, event):
|
||||
keycode = event.GetKeyCode()
|
||||
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
|
||||
if keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE):
|
||||
row = self.GetFirstSelected()
|
||||
if row != -1:
|
||||
self.removeBooster(self.boosters[self.GetItemData(row)])
|
||||
|
||||
@@ -80,7 +80,7 @@ class CargoView(d.Display):
|
||||
elif data[0] == "market":
|
||||
fit = self.mainFrame.getActiveFit()
|
||||
if fit:
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fit, int(data[1])))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fit, int(data[1]), 1))
|
||||
|
||||
def startDrag(self, event):
|
||||
row = event.GetIndex()
|
||||
@@ -97,13 +97,12 @@ class CargoView(d.Display):
|
||||
|
||||
def kbEvent(self, event):
|
||||
keycode = event.GetKeyCode()
|
||||
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
sFit = Fit.getInstance()
|
||||
if keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE):
|
||||
row = self.GetFirstSelected()
|
||||
if row != -1:
|
||||
sFit.removeCargo(fitID, self.GetItemData(row))
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cargo = self.cargo[self.GetItemData(row)]
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCargoCommand(fitID=fitID, itemID=cargo.itemID))
|
||||
event.Skip()
|
||||
|
||||
def swapModule(self, x, y, modIdx):
|
||||
|
||||
@@ -136,7 +136,7 @@ class ImplantDisplay(d.Display):
|
||||
|
||||
def kbEvent(self, event):
|
||||
keycode = event.GetKeyCode()
|
||||
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
|
||||
if keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE):
|
||||
row = self.GetFirstSelected()
|
||||
if row != -1:
|
||||
self.removeImplant(self.implants[self.GetItemData(row)])
|
||||
|
||||
@@ -50,7 +50,7 @@ class ChangeAmount(ContextMenu):
|
||||
cleanInput = int(float(re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip())))
|
||||
|
||||
if isinstance(thing, es_Cargo):
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeCargoQty(fitID, thing.itemID, cleanInput))
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeCargoAmount(fitID, thing.itemID, cleanInput))
|
||||
elif isinstance(thing, Drone):
|
||||
if srcContext == "projectedDrone":
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, thing.itemID, cleanInput))
|
||||
|
||||
@@ -35,7 +35,7 @@ class Cargo(ContextMenu):
|
||||
|
||||
typeID = int(selection[0].ID)
|
||||
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fitID, typeID))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fitID, typeID, 1))
|
||||
self.mainFrame.additionsPane.select("Cargo")
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ from .booster.add import GuiAddBoosterCommand
|
||||
from .booster.remove import GuiRemoveBoosterCommand
|
||||
from .booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand
|
||||
from .booster.toggleState import GuiToggleBoosterStateCommand
|
||||
from .guiAddCargo import GuiAddCargoCommand
|
||||
from .cargo.add import GuiAddCargoCommand
|
||||
from .cargo.changeAmount import GuiChangeCargoAmount
|
||||
from .cargo.remove import GuiRemoveCargoCommand
|
||||
from .guiAddCharge import GuiModuleAddChargeCommand
|
||||
from .guiAddCommand import GuiAddCommandCommand
|
||||
from .guiAddDrone import GuiAddDroneCommand
|
||||
@@ -10,7 +12,6 @@ from .guiAddFighter import GuiAddFighterCommand
|
||||
from .guiAddModule import GuiModuleAddCommand
|
||||
from .guiAddProjected import GuiAddProjectedCommand
|
||||
from .guiCargoToModule import GuiCargoToModuleCommand
|
||||
from .guiChangeCargoQty import GuiChangeCargoQty
|
||||
from .guiChangeDroneQty import GuiChangeDroneQty
|
||||
from .guiChangeFighterQty import GuiChangeFighterQty
|
||||
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
@@ -24,7 +25,6 @@ from .guiModuleToCargo import GuiModuleToCargoCommand
|
||||
from .guiMutaConvert import GuiMutaConvertCommand
|
||||
from .guiMutaRevert import GuiMutaRevertCommand
|
||||
from .guiRebaseItems import GuiRebaseItemsCommand
|
||||
from .guiRemoveCargo import GuiRemoveCargoCommand
|
||||
from .guiRemoveCommand import GuiRemoveCommandCommand
|
||||
from .guiRemoveDrone import GuiRemoveDroneCommand
|
||||
from .guiRemoveFighter import GuiRemoveFighterCommand
|
||||
|
||||
0
gui/fitCommands/cargo/__init__.py
Normal file
0
gui/fitCommands/cargo/__init__.py
Normal file
@@ -1,29 +1,27 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.helpers import CargoInfo
|
||||
from .calcCommands.cargo.add import CalcAddCargoCommand
|
||||
from gui.fitCommands.calcCommands.cargo.add import CalcAddCargoCommand
|
||||
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory
|
||||
|
||||
|
||||
class GuiAddCargoCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID, amount=1):
|
||||
wx.Command.__init__(self, True, "Cargo Add")
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
def __init__(self, fitID, itemID, amount):
|
||||
wx.Command.__init__(self, True, 'Add Cargo')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
if self.internalHistory.Submit(CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))):
|
||||
if self.internalHistory.submit(CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))):
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
success = self.internalHistory.undoAll()
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return success
|
||||
35
gui/fitCommands/cargo/changeAmount.py
Normal file
35
gui/fitCommands/cargo/changeAmount.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import math
|
||||
|
||||
import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calcCommands.cargo.changeAmount import CalcChangeCargoAmountCommand
|
||||
from gui.fitCommands.calcCommands.cargo.remove import CalcRemoveCargoCommand
|
||||
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory
|
||||
|
||||
|
||||
class GuiChangeCargoAmount(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID, amount):
|
||||
wx.Command.__init__(self, True, 'Change Cargo Amount')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
if self.amount > 0:
|
||||
if self.internalHistory.submit(CalcChangeCargoAmountCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))):
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
else:
|
||||
if self.internalHistory.submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))):
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
@@ -1,29 +1,28 @@
|
||||
import math
|
||||
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.helpers import CargoInfo
|
||||
from .calcCommands.cargo.remove import CalcRemoveCargoCommand
|
||||
from gui.fitCommands.calcCommands.cargo.remove import CalcRemoveCargoCommand
|
||||
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory
|
||||
|
||||
|
||||
class GuiRemoveCargoCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Cargo Remove")
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
wx.Command.__init__(self, True, 'Remove Cargo')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
if self.internalHistory.Submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))):
|
||||
if self.internalHistory.submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))):
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.GetCommands():
|
||||
self.internalHistory.Undo()
|
||||
success = self.internalHistory.undoAll()
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return success
|
||||
@@ -1,33 +0,0 @@
|
||||
import wx
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calcCommands.cargo.changeAmount import CalcChangeCargoAmountCommand
|
||||
from service.fit import Fit
|
||||
from gui.fitCommands.helpers import CargoInfo
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiChangeCargoQty(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID, amount):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.amount = amount
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcChangeCargoAmountCommand(self.fitID, CargoInfo(itemID=self.itemID, amount=self.amount))
|
||||
if self.internalHistory.Submit(cmd):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
@@ -607,18 +607,6 @@ class FitDeprecated(object):
|
||||
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def removeCargo(self, fitID, position):
|
||||
pyfalog.debug("Removing cargo from position ({0}) fit ID: {1}", position, fitID)
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
charge = fit.cargo[position]
|
||||
fit.cargo.remove(charge)
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def addFighter(self, fitID, itemID, recalc=True):
|
||||
pyfalog.debug("Adding fighters ({0}) to fit ID: {1}", itemID, fitID)
|
||||
|
||||
Reference in New Issue
Block a user