def addModule(self, x, y, itemID): """Add a module from the market browser (from dragging it)""" fitID = self.mainFrame.getActiveFit() item = Market.getInstance().getItem(itemID) fit = Fit.getInstance().getFit(fitID) dstRow, _ = self.HitTest((x, y)) if dstRow == -1 or dstRow in self.blanks: dstMod = None else: try: dstMod = self.mods[dstRow] except IndexError: dstMod = None if not isinstance(dstMod, Module): dstMod = None if dstMod not in fit.modules: dstMod = None dstPos = fit.modules.index(dstMod) if dstMod is not None else None mstate = wx.GetMouseState() # If we dropping on a module, try to replace, or add if replacement fails if item.isModule and dstMod is not None and not dstMod.isEmpty: positions = getSimilarModPositions(fit.modules, dstMod) if mstate.GetModifiers() == wx.MOD_ALT else [dstPos] command = cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=positions) if not self.mainFrame.command.Submit(command): if mstate.GetModifiers() == wx.MOD_ALT: self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID)) else: self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) elif item.isModule: if mstate.GetModifiers() == wx.MOD_ALT: self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID)) elif dstPos is not None: self.mainFrame.command.Submit(cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=[dstPos])) else: self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) elif item.isSubsystem: self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) elif item.isCharge: failoverToAll = False positionsAll = list(range(len(fit.modules))) if dstMod is None or dstMod.isEmpty: positions = positionsAll elif mstate.GetModifiers() == wx.MOD_ALT: positions = getSimilarModPositions(fit.modules, dstMod) failoverToAll = True else: positions = [fit.modules.index(dstMod)] if len(positions) > 0: command = cmd.GuiChangeLocalModuleChargesCommand(fitID=fitID, positions=positions, chargeItemID=itemID) if not self.mainFrame.command.Submit(command) and failoverToAll: self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand( fitID=fitID, positions=positionsAll, chargeItemID=itemID))
def appendItem(self, event): """ Adds items that are double clicks from the market browser. We handle both modules and ammo """ if not self: event.Skip() return if self.parent.IsActive(self): itemID = event.itemID fitID = self.activeFitID if fitID is not None: item = Market.getInstance().getItem(itemID, eager='group.category') if item is None or not (item.isModule or item.isSubsystem): event.Skip() return if item.isCharge: # If we've selected ammo, then apply to the selected module(s) modules = [] sel = self.GetFirstSelected() while sel != -1 and sel not in self.blanks: mod = self.mods[self.GetItemData(sel)] if isinstance(mod, Module) and not mod.isEmpty: modules.append(self.mods[self.GetItemData(sel)]) sel = self.GetNextSelected(sel) if len(modules) > 0: self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(fitID, modules, itemID)) else: self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID, itemID)) event.Skip()
def appendItem(self, event): """ Adds items that are double clicks from the market browser. We handle both modules and ammo """ if not self: event.Skip() return if self.parent.IsActive(self): itemID = event.itemID fitID = self.activeFitID if fitID is not None: item = Market.getInstance().getItem(itemID, eager='group.category') if item is None: event.Skip() return batchOp = wx.GetMouseState( ).GetModifiers() == wx.MOD_ALT and getattr( event, 'allowBatch', None) is not False if (item.isModule and not batchOp) or item.isSubsystem: self.mainFrame.command.Submit( cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) elif item.isModule and batchOp: self.mainFrame.command.Submit( cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID)) event.Skip()
def appendItem(self, event): """ Adds items that are double clicks from the market browser. We handle both modules and ammo """ if not self: event.Skip() return if self.parent.IsActive(self): itemID = event.itemID fitID = self.activeFitID if fitID is not None: item = Market.getInstance().getItem(itemID, eager='group.category') if item is None: event.Skip() return batchOp = wx.GetMouseState().altDown and getattr( event, 'allowBatch', None) is not False # If we've selected ammo, then apply to the selected module(s) if item.isCharge: positions = [] fit = Fit.getInstance().getFit(fitID) if batchOp: for position, mod in enumerate(fit.modules): if isinstance(mod, Module) and not mod.isEmpty: positions.append(position) else: sel = self.GetFirstSelected() while sel != -1 and sel not in self.blanks: try: mod = self.mods[self.GetItemData(sel)] except IndexError: sel = self.GetNextSelected(sel) continue if isinstance( mod, Module ) and not mod.isEmpty and mod in fit.modules: positions.append(fit.modules.index(mod)) sel = self.GetNextSelected(sel) if len(positions) > 0: self.mainFrame.command.Submit( cmd.GuiChangeLocalModuleChargesCommand( fitID=fitID, positions=positions, chargeItemID=itemID)) elif (item.isModule and not batchOp) or item.isSubsystem: self.mainFrame.command.Submit( cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) elif item.isModule and batchOp: self.mainFrame.command.Submit( cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID)) event.Skip()
def addModule(self, x, y, itemID): """Add a module from the market browser (from dragging it)""" dstRow, _ = self.HitTest((x, y)) if dstRow != -1 and dstRow not in self.blanks: fitID = self.mainFrame.getActiveFit() mod = self.mods[dstRow] if not isinstance(mod, Module): # make sure we're not adding something to a T3D Mode return self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID, itemID, self.mods[dstRow].modPosition))
def importFromClipboard(self, event): clipboard = fromClipboard() activeFit = self.getActiveFit() try: importType, importData = Port().importFitFromBuffer( clipboard, activeFit) if importType == "FittingItem": baseItem, mutaplasmidItem, mutations = importData[0] if mutaplasmidItem: self.command.Submit( cmd.GuiImportLocalMutatedModuleCommand( activeFit, baseItem, mutaplasmidItem, mutations)) else: self.command.Submit( cmd.GuiAddLocalModuleCommand(activeFit, baseItem.ID)) return if importType == "AdditionsDrones": if self.command.Submit( cmd.GuiImportLocalDronesCommand( activeFit, [(i.ID, a) for i, a in importData[0]])): self.additionsPane.select("Drones") return if importType == "AdditionsFighters": if self.command.Submit( cmd.GuiImportLocalFightersCommand( activeFit, [(i.ID, a) for i, a in importData[0]])): self.additionsPane.select("Fighters") return if importType == "AdditionsImplants": if self.command.Submit( cmd.GuiImportImplantsCommand( activeFit, [(i.ID, a) for i, a in importData[0]])): self.additionsPane.select("Implants") return if importType == "AdditionsBoosters": if self.command.Submit( cmd.GuiImportBoostersCommand( activeFit, [(i.ID, a) for i, a in importData[0]])): self.additionsPane.select("Boosters") return if importType == "AdditionsCargo": if self.command.Submit( cmd.GuiImportCargosCommand( activeFit, [(i.ID, a) for i, a in importData[0]])): self.additionsPane.select("Cargo") return except (KeyboardInterrupt, SystemExit): raise except: pyfalog.error("Attempt to import failed:\n{0}", clipboard) else: self._openAfterImport(importData)