(self, callingWindow, fullContext, mainItem, i)
| 33 | return _t("Fill Cargo With {0}").format(itmContext) |
| 34 | |
| 35 | def activate(self, callingWindow, fullContext, mainItem, i): |
| 36 | fitID = self.mainFrame.getActiveFit() |
| 37 | fit = Fit.getInstance().getFit(fitID) |
| 38 | |
| 39 | if isinstance(mainItem, Cargo): |
| 40 | itemVolume = mainItem.item.attributes['volume'].value |
| 41 | itemID = mainItem.itemID |
| 42 | else: |
| 43 | itemVolume = mainItem.attributes['volume'].value |
| 44 | itemID = int(mainItem.ID) |
| 45 | |
| 46 | if itemVolume is None or itemVolume <= 0: |
| 47 | return |
| 48 | |
| 49 | # Calculate how many items can fit in the cargo |
| 50 | cargoCapacity = fit.ship.getModifiedItemAttr("capacity") |
| 51 | currentCargoVolume = fit.cargoBayUsed |
| 52 | availableVolume = cargoCapacity - currentCargoVolume |
| 53 | |
| 54 | if availableVolume <= 0: |
| 55 | return |
| 56 | |
| 57 | # Calculate maximum amount that can fit |
| 58 | maxAmount = int(availableVolume / itemVolume) |
| 59 | if maxAmount <= 0: |
| 60 | return |
| 61 | |
| 62 | # Add the items to cargo |
| 63 | command = cmd.GuiAddCargoCommand(fitID=fitID, itemID=itemID, amount=maxAmount) |
| 64 | if self.mainFrame.command.Submit(command): |
| 65 | self.mainFrame.additionsPane.select("Cargo", focus=False) |
| 66 | |
| 67 | |
| 68 | FillCargoWithItem.register() |
nothing calls this directly
no test coverage detected