diff --git a/gui/builtinContextMenus/fillWithModule.py b/gui/builtinContextMenus/fillWithModule.py new file mode 100644 index 000000000..9e32dbc0d --- /dev/null +++ b/gui/builtinContextMenus/fillWithModule.py @@ -0,0 +1,32 @@ +from gui.contextMenu import ContextMenu +import gui.mainFrame +# noinspection PyPackageRequirements +import wx +import gui.globalEvents as GE +from service.settings import ContextMenuSettings +import gui.fitCommands as cmd + + +class FillWithModule(ContextMenu): + def __init__(self): + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.settings = ContextMenuSettings.getInstance() + + def display(self, srcContext, selection): + return srcContext in ("fittingModule") + + def getText(self, itmContext, selection): + return u"Fill With {0}".format(itmContext if itmContext is not None else "Module") + + def activate(self, fullContext, selection, i): + + srcContext = fullContext[0] + fitID = self.mainFrame.getActiveFit() + + if srcContext == "fittingModule": + self.mainFrame.command.Submit(cmd.GuiFillWithModuleCommand(fitID, selection[0].itemID)) + return # the command takes care of the PostEvent + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + + +FillWithModule.register() diff --git a/gui/contextMenu.py b/gui/contextMenu.py index be972b0f8..7c1caf085 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -188,6 +188,7 @@ from gui.builtinContextMenus import ( # noqa: E402,F401 marketJump, # droneSplit, itemRemove, + fillWithModule, droneRemoveStack, ammoPattern, project, diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 3501e8089..42b718c5d 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -2,6 +2,7 @@ from .guiToggleModuleState import GuiModuleStateChangeCommand from .guiAddModule import GuiModuleAddCommand from .guiRemoveModule import GuiModuleRemoveCommand from .guiAddCharge import GuiModuleAddChargeCommand +from .guiFillWithModule import GuiFillWithModuleCommand from .guiSwapCloneModule import GuiModuleSwapOrCloneCommand from .guiRemoveCargo import GuiRemoveCargoCommand from .guiAddCargo import GuiAddCargoCommand diff --git a/gui/fitCommands/guiFillWithModule.py b/gui/fitCommands/guiFillWithModule.py new file mode 100644 index 000000000..0fa962bef --- /dev/null +++ b/gui/fitCommands/guiFillWithModule.py @@ -0,0 +1,50 @@ +import wx +import gui.mainFrame +from gui import globalEvents as GE +from .calc.fitAddModule import FitAddModuleCommand +from service.fit import Fit +from logbook import Logger +pyfalog = Logger(__name__) + + +class GuiFillWithModuleCommand(wx.Command): + def __init__(self, fitID, itemID, position=None): + """ + Handles adding an item, usually a module, to the Fitting Window. + + :param fitID: The fit ID that we are modifying + :param itemID: The item that is to be added to the Fitting View. If this turns out to be a charge, we attempt to + set the charge on the underlying module (requires position) + :param position: Optional. The position in fit.modules that we are attempting to set the item to + """ + wx.Command.__init__(self, True, "Module Add: {}".format(itemID)) + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.fitID = fitID + self.itemID = itemID + self.internal_history = wx.CommandProcessor() + self.position = position + self.old_mod = None + + def Do(self): + pyfalog.debug("{} Do()".format(self)) + pyfalog.debug("Trying to append a module") + added_modules = 0 + success = self.internal_history.Submit(FitAddModuleCommand(self.fitID, self.itemID)) + while (success): + added_modules += 1 + success = self.internal_history.Submit(FitAddModuleCommand(self.fitID, self.itemID)) + + if added_modules > 0: + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID)) + return True + return False + + def Undo(self): + pyfalog.debug("{} Undo()".format(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, action="moddel", typeID=self.itemID)) + return True