Exemplo n.º 1
0
    def activate(self, fullContext, selection, i):
        thing = selection[0]
        mainFrame = gui.mainFrame.MainFrame.getInstance()
        fitID = mainFrame.getActiveFit()
        srcContext = fullContext[0]
        if isinstance(thing, es_Fit):
            value = thing.getProjectionInfo(fitID).amount
        elif isinstance(thing, es_Fighter):
            value = thing.amountActive
        else:
            value = thing.amount

        dlg = AmountChanger(self.mainFrame, value, (0, 20)) if isinstance(
            thing, es_Fit) else AmountChanger(self.mainFrame, value)
        if dlg.ShowModal() == wx.ID_OK:

            if dlg.input.GetLineText(0).strip() == '':
                return

            sFit = Fit.getInstance()
            fit = sFit.getFit(fitID)
            cleanInput = int(
                float(re.sub(r'[^0-9.]', '',
                             dlg.input.GetLineText(0).strip())))

            if isinstance(thing, es_Cargo):
                self.mainFrame.command.Submit(
                    cmd.GuiChangeCargoAmountCommand(fitID, thing.itemID,
                                                    cleanInput))
            elif isinstance(thing, Drone):
                if srcContext == "projectedDrone":
                    self.mainFrame.command.Submit(
                        cmd.GuiChangeProjectedDroneAmountCommand(
                            fitID, thing.itemID, cleanInput))
                else:
                    self.mainFrame.command.Submit(
                        cmd.GuiChangeLocalDroneAmountCommand(
                            fitID, fit.drones.index(thing), cleanInput))
            elif isinstance(thing, es_Fit):
                self.mainFrame.command.Submit(
                    cmd.GuiChangeProjectedFitAmountCommand(
                        fitID, thing.ID, cleanInput))
            elif isinstance(thing, es_Fighter):
                if srcContext == "projectedFighter":
                    self.mainFrame.command.Submit(
                        cmd.GuiChangeProjectedFighterAmountCommand(
                            fitID, fit.projectedFighters.index(thing),
                            cleanInput))
                else:
                    self.mainFrame.command.Submit(
                        cmd.GuiChangeLocalFighterAmountCommand(
                            fitID, fit.fighters.index(thing), cleanInput))
Exemplo n.º 2
0
    def activate(self, callingWindow, fullContext, mainItem, i):
        fitID = self.mainFrame.getActiveFit()
        srcContext = fullContext[0]
        if isinstance(mainItem, es_Fit):
            try:
                value = mainItem.getProjectionInfo(fitID).amount
            except AttributeError:
                return
        else:
            value = mainItem.amount

        limits = (0, 20) if isinstance(mainItem, es_Fit) else None
        with AmountChanger(self.mainFrame, value, limits) as dlg:
            if dlg.ShowModal() == wx.ID_OK:

                if dlg.input.GetLineText(0).strip() == '':
                    return

                sFit = Fit.getInstance()
                fit = sFit.getFit(fitID)
                cleanInput = int(
                    float(
                        re.sub(r'[^0-9.]', '',
                               dlg.input.GetLineText(0).strip())))

                if isinstance(mainItem, es_Cargo):
                    self.mainFrame.command.Submit(
                        cmd.GuiChangeCargoAmountCommand(fitID=fitID,
                                                        itemID=mainItem.itemID,
                                                        amount=cleanInput))
                elif isinstance(mainItem, Drone):
                    if srcContext == "projectedDrone":
                        self.mainFrame.command.Submit(
                            cmd.GuiChangeProjectedDroneAmountCommand(
                                fitID=fitID,
                                itemID=mainItem.itemID,
                                amount=cleanInput))
                    else:
                        if mainItem in fit.drones:
                            position = fit.drones.index(mainItem)
                            self.mainFrame.command.Submit(
                                cmd.GuiChangeLocalDroneAmountCommand(
                                    fitID=fitID,
                                    position=position,
                                    amount=cleanInput))
                elif isinstance(mainItem, es_Fit):
                    self.mainFrame.command.Submit(
                        cmd.GuiChangeProjectedFitAmountCommand(
                            fitID=fitID,
                            projectedFitID=mainItem.ID,
                            amount=cleanInput))
                elif isinstance(mainItem, es_Fighter):
                    if srcContext == "projectedFighter":
                        if mainItem in fit.projectedFighters:
                            position = fit.projectedFighters.index(mainItem)
                            self.mainFrame.command.Submit(
                                cmd.GuiChangeProjectedFighterAmountCommand(
                                    fitID=fitID,
                                    position=position,
                                    amount=cleanInput))
                    else:
                        if mainItem in fit.fighters:
                            position = fit.fighters.index(mainItem)
                            self.mainFrame.command.Submit(
                                cmd.GuiChangeLocalFighterAmountCommand(
                                    fitID=fitID,
                                    position=position,
                                    amount=cleanInput))