From 51a11edc36cad49572777f83f6bba95841bdd86e Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 14 Apr 2019 20:51:39 +0300 Subject: [PATCH] Rework local drone GUI commands --- gui/builtinAdditionPanes/droneView.py | 13 +++++-- gui/builtinContextMenus/amount.py | 2 +- gui/builtinContextMenus/droneRemoveStack.py | 6 ++- gui/builtinContextMenus/itemRemove.py | 2 +- gui/fitCommands/__init__.py | 8 ++-- gui/fitCommands/drone/__init__.py | 0 .../{guiAddDrone.py => drone/add.py} | 20 +++++----- gui/fitCommands/drone/changeAmount.py | 39 +++++++++++++++++++ .../{guiRemoveDrone.py => drone/remove.py} | 20 +++++----- .../toggleState.py} | 19 ++++----- gui/fitCommands/guiChangeDroneQty.py | 31 --------------- 11 files changed, 89 insertions(+), 71 deletions(-) create mode 100644 gui/fitCommands/drone/__init__.py rename gui/fitCommands/{guiAddDrone.py => drone/add.py} (51%) create mode 100644 gui/fitCommands/drone/changeAmount.py rename gui/fitCommands/{guiRemoveDrone.py => drone/remove.py} (53%) rename gui/fitCommands/{guiToggleDrone.py => drone/toggleState.py} (52%) delete mode 100644 gui/fitCommands/guiChangeDroneQty.py diff --git a/gui/builtinAdditionPanes/droneView.py b/gui/builtinAdditionPanes/droneView.py index 9b8e29931..d05b85515 100644 --- a/gui/builtinAdditionPanes/droneView.py +++ b/gui/builtinAdditionPanes/droneView.py @@ -17,6 +17,9 @@ # along with pyfa. If not, see . # ============================================================================= + +import math + # noinspection PyPackageRequirements import wx @@ -117,7 +120,7 @@ class DroneView(Display): row = self.GetFirstSelected() if row != -1: drone = self.drones[self.GetItemData(row)] - self.removeDrone(drone) + self.removeDroneStack(drone) event.Skip() @@ -227,7 +230,11 @@ class DroneView(Display): def removeDrone(self, drone): fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, self.original.index(drone))) + self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, self.original.index(drone), 1)) + + def removeDroneStack(self, drone): + fitID = self.mainFrame.getActiveFit() + self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, self.original.index(drone), math.inf)) def click(self, event): event.Skip() @@ -237,7 +244,7 @@ class DroneView(Display): if col == self.getColIndex(State): fitID = self.mainFrame.getActiveFit() drone = self.drones[row] - self.mainFrame.command.Submit(cmd.GuiToggleDroneCommand(fitID, self.original.index(drone))) + self.mainFrame.command.Submit(cmd.GuiToggleDroneStateCommand(fitID, self.original.index(drone))) def spawnMenu(self, event): sel = self.GetFirstSelected() diff --git a/gui/builtinContextMenus/amount.py b/gui/builtinContextMenus/amount.py index f06849dc6..2bbb5ddb7 100644 --- a/gui/builtinContextMenus/amount.py +++ b/gui/builtinContextMenus/amount.py @@ -55,7 +55,7 @@ class ChangeAmount(ContextMenu): if srcContext == "projectedDrone": self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, thing.itemID, cleanInput)) else: - self.mainFrame.command.Submit(cmd.GuiChangeDroneQty(fitID, fit.drones.index(thing), cleanInput)) + self.mainFrame.command.Submit(cmd.GuiChangeDroneAmount(fitID, fit.drones.index(thing), cleanInput)) elif isinstance(thing, es_Fit): self.mainFrame.command.Submit(cmd.GuiChangeProjectedFitQty(fitID, thing.ID, cleanInput)) elif isinstance(thing, es_Fighter): diff --git a/gui/builtinContextMenus/droneRemoveStack.py b/gui/builtinContextMenus/droneRemoveStack.py index fad83f1e8..b73e2cd62 100644 --- a/gui/builtinContextMenus/droneRemoveStack.py +++ b/gui/builtinContextMenus/droneRemoveStack.py @@ -1,3 +1,5 @@ +import math + import gui.fitCommands as cmd import gui.mainFrame from gui.contextMenu import ContextMenu @@ -25,8 +27,8 @@ class ItemRemove(ContextMenu): fitID = self.mainFrame.getActiveFit() fit = sFit.getFit(fitID) - idx = fit.drones.index(selection[0]) - self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, idx, fit.drones[idx].amount)) + position = fit.drones.index(selection[0]) + self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, position, math.inf)) ItemRemove.register() diff --git a/gui/builtinContextMenus/itemRemove.py b/gui/builtinContextMenus/itemRemove.py index b6e85676b..29c3e38ae 100644 --- a/gui/builtinContextMenus/itemRemove.py +++ b/gui/builtinContextMenus/itemRemove.py @@ -43,7 +43,7 @@ class ItemRemove(ContextMenu): self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, None, selection)) return elif srcContext == "droneItem": - self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, fit.drones.index(selection[0]))) + self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, fit.drones.index(selection[0]), 1)) return elif srcContext == "fighterItem": self.mainFrame.command.Submit(cmd.GuiRemoveFighterCommand(fitID, fit.fighters.index(selection[0]))) diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 2bf7779cf..43cd1a595 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -9,12 +9,12 @@ from .commandFit.add import GuiAddCommandFitCommand from .commandFit.remove import GuiRemoveCommandFitCommand from .commandFit.toggleState import GuiToggleCommandFitStateCommand from .guiAddCharge import GuiModuleAddChargeCommand -from .guiAddDrone import GuiAddDroneCommand +from .drone.add import GuiAddDroneCommand from .guiAddFighter import GuiAddFighterCommand from .guiAddModule import GuiModuleAddCommand from .guiAddProjected import GuiAddProjectedCommand from .guiCargoToModule import GuiCargoToModuleCommand -from .guiChangeDroneQty import GuiChangeDroneQty +from .drone.changeAmount import GuiChangeDroneAmount from .guiChangeFighterQty import GuiChangeFighterQty from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty from .guiChangeProjectedFighterAmount import GuiChangeProjectedFighterAmount @@ -27,14 +27,14 @@ from .guiModuleToCargo import GuiModuleToCargoCommand from .guiMutaConvert import GuiMutaConvertCommand from .guiMutaRevert import GuiMutaRevertCommand from .guiRebaseItems import GuiRebaseItemsCommand -from .guiRemoveDrone import GuiRemoveDroneCommand +from .drone.remove import GuiRemoveDroneCommand from .guiRemoveFighter import GuiRemoveFighterCommand from .guiRemoveModule import GuiModuleRemoveCommand from .guiRemoveProjected import GuiRemoveProjectedCommand from .guiSetMode import GuiSetModeCommand from .guiSetSpoolup import GuiSetSpoolup from .guiSwapCloneModule import GuiModuleSwapOrCloneCommand -from .guiToggleDrone import GuiToggleDroneCommand +from .drone.toggleState import GuiToggleDroneStateCommand from .guiToggleFighter import GuiToggleFighterCommand from .guiToggleFighterAbility import GuiToggleFighterAbilityCommand from .guiToggleModuleState import GuiModuleStateChangeCommand diff --git a/gui/fitCommands/drone/__init__.py b/gui/fitCommands/drone/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gui/fitCommands/guiAddDrone.py b/gui/fitCommands/drone/add.py similarity index 51% rename from gui/fitCommands/guiAddDrone.py rename to gui/fitCommands/drone/add.py index 87fe44371..9cb93a33d 100644 --- a/gui/fitCommands/guiAddDrone.py +++ b/gui/fitCommands/drone/add.py @@ -1,29 +1,29 @@ import wx -from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE -from gui.fitCommands.helpers import DroneInfo -from .calcCommands.drone.localAdd import CalcAddLocalDroneCommand +from gui.fitCommands.calcCommands.drone.localAdd import CalcAddLocalDroneCommand +from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory +from service.fit import Fit class GuiAddDroneCommand(wx.Command): + def __init__(self, fitID, itemID): - wx.Command.__init__(self, True, "Drone Add") - self.internalHistory = wx.CommandProcessor() + wx.Command.__init__(self, True, 'Add Drone') + self.internalHistory = InternalCommandHistory() self.fitID = fitID self.itemID = itemID def Do(self): - cmd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=1, amountActive=0)) - if self.internalHistory.Submit(cmd): + if self.internalHistory.submit(CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=1, amountActive=0))): 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() + success = self.internalHistory.undoAll() + Fit.getInstance().recalc(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True + return success diff --git a/gui/fitCommands/drone/changeAmount.py b/gui/fitCommands/drone/changeAmount.py new file mode 100644 index 000000000..61157bf1b --- /dev/null +++ b/gui/fitCommands/drone/changeAmount.py @@ -0,0 +1,39 @@ +import math + +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calcCommands.drone.localChangeAmount import CalcChangeLocalDroneAmountCommand +from gui.fitCommands.calcCommands.drone.localRemove import CalcRemoveLocalDroneCommand +from gui.fitCommands.helpers import InternalCommandHistory +from service.fit import Fit + + +class GuiChangeDroneAmount(wx.Command): + + def __init__(self, fitID, position, amount): + wx.Command.__init__(self, True, 'Change Drone Amount') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.position = position + self.amount = amount + + def Do(self): + if self.amount > 0: + if self.internalHistory.submit(CalcChangeLocalDroneAmountCommand(fitID=self.fitID, position=self.position, amount=self.amount)): + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return True + else: + if self.internalHistory.submit(CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf)): + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + success = self.internalHistory.undoAll() + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success diff --git a/gui/fitCommands/guiRemoveDrone.py b/gui/fitCommands/drone/remove.py similarity index 53% rename from gui/fitCommands/guiRemoveDrone.py rename to gui/fitCommands/drone/remove.py index f18847e51..12c337942 100644 --- a/gui/fitCommands/guiRemoveDrone.py +++ b/gui/fitCommands/drone/remove.py @@ -1,30 +1,30 @@ import wx -from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE -from .calcCommands.drone.localRemove import CalcRemoveLocalDroneCommand +from gui.fitCommands.calcCommands.drone.localRemove import CalcRemoveLocalDroneCommand +from gui.fitCommands.helpers import InternalCommandHistory +from service.fit import Fit class GuiRemoveDroneCommand(wx.Command): - def __init__(self, fitID, position, amount=1): - wx.Command.__init__(self, True, "Drone Remove") - self.internalHistory = wx.CommandProcessor() + + def __init__(self, fitID, position, amount): + wx.Command.__init__(self, True, 'Remove Drone') + self.internalHistory = InternalCommandHistory() self.fitID = fitID self.position = position self.amount = amount def Do(self): - cmd = CalcRemoveLocalDroneCommand(self.fitID, self.position, self.amount) - if self.internalHistory.Submit(cmd): + if self.internalHistory.submit(CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=self.amount)): 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() + success = self.internalHistory.undoAll() Fit.getInstance().recalc(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True + return success diff --git a/gui/fitCommands/guiToggleDrone.py b/gui/fitCommands/drone/toggleState.py similarity index 52% rename from gui/fitCommands/guiToggleDrone.py rename to gui/fitCommands/drone/toggleState.py index a86b8d4fe..546c082b5 100644 --- a/gui/fitCommands/guiToggleDrone.py +++ b/gui/fitCommands/drone/toggleState.py @@ -1,28 +1,29 @@ import wx -from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE -from .calcCommands.drone.localToggleState import CalcToggleLocalDroneStateCommand +from gui.fitCommands.calcCommands.drone.localToggleState import CalcToggleLocalDroneStateCommand +from gui.fitCommands.helpers import InternalCommandHistory +from service.fit import Fit -class GuiToggleDroneCommand(wx.Command): +class GuiToggleDroneStateCommand(wx.Command): + def __init__(self, fitID, position): - wx.Command.__init__(self, True, "") - self.internalHistory = wx.CommandProcessor() + wx.Command.__init__(self, True, 'Toggle Drone State') + self.internalHistory = InternalCommandHistory() self.fitID = fitID self.position = position def Do(self): - if self.internalHistory.Submit(CalcToggleLocalDroneStateCommand(self.fitID, self.position)): + if self.internalHistory.submit(CalcToggleLocalDroneStateCommand(fitID=self.fitID, position=self.position)): 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() + success = self.internalHistory.undoAll() Fit.getInstance().recalc(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True + return success diff --git a/gui/fitCommands/guiChangeDroneQty.py b/gui/fitCommands/guiChangeDroneQty.py deleted file mode 100644 index 8f72ef638..000000000 --- a/gui/fitCommands/guiChangeDroneQty.py +++ /dev/null @@ -1,31 +0,0 @@ -import wx -import gui.mainFrame -from gui import globalEvents as GE -from .calcCommands.drone.localChangeAmount import CalcChangeLocalDroneAmountCommand -from service.fit import Fit -from logbook import Logger -pyfalog = Logger(__name__) - - -class GuiChangeDroneQty(wx.Command): - def __init__(self, fitID, position, amount=1): - wx.Command.__init__(self, True, "") - self.fitID = fitID - self.position = position - self.amount = amount - self.internalHistory = wx.CommandProcessor() - - def Do(self): - cmd = CalcChangeLocalDroneAmountCommand(self.fitID, self.position, 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