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 removeItem(self, event): """Double Left Click - remove module""" if event.GetModifiers() == wx.MOD_CONTROL: return row, _ = self.HitTest(event.Position) if row != -1 and row not in self.blanks and isinstance( self.mods[row], Module): col = self.getColumn(event.Position) if col != self.getColIndex(State): try: mod = self.mods[row] except IndexError: return if not isinstance(mod, Module) or mod.isEmpty: return if event.GetModifiers() == wx.MOD_ALT: fit = Fit.getInstance().getFit(self.activeFitID) positions = getSimilarModPositions(fit.modules, mod) self.mainFrame.command.Submit( cmd.GuiRemoveLocalModuleCommand(fitID=self.activeFitID, positions=positions)) else: self.removeModule(mod) else: if "wxMSW" in wx.PlatformInfo: self.click(event)
def click(self, event): mainRow, _ = self.HitTest(event.Position) if mainRow != -1: col = self.getColumn(event.Position) if col == self.getColIndex(State): mainItem = self.get(mainRow) if mainItem is None: return selection = self.getSelectedProjectors() if mainItem not in selection: selection = [mainItem] modPressed = event.GetModifiers() == wx.MOD_ALT fitID = self.mainFrame.getActiveFit() if isinstance(mainItem, EosModule) and modPressed: fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions(fit.projectedModules, mainItem) selection = [fit.projectedModules[p] for p in positions] elif isinstance(mainItem, EosFighter) and modPressed: fit = Fit.getInstance().getFit(fitID) selection = getSimilarFighters(fit.projectedFighters, mainItem) self.mainFrame.command.Submit( cmd.GuiChangeProjectedItemStatesCommand( fitID=fitID, mainItem=mainItem, items=selection, click='right' if event.GetButton() == 3 else 'left')) return event.Skip()
def click(self, event): mainRow, _ = self.HitTest(event.Position) if mainRow != -1: col = self.getColumn(event.Position) if col == self.getColIndex(State): mainItem = self.get(mainRow) if mainItem is None: return selection = self.getSelectedProjectors() if mainItem not in selection: selection = [mainItem] modPressed = wx.GetMouseState().GetModifiers() == wx.MOD_ALT fitID = self.mainFrame.getActiveFit() if isinstance(mainItem, EosModule) and modPressed: fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions(fit.projectedModules, mainItem) selection = [fit.projectedModules[p] for p in positions] elif isinstance(mainItem, EosFighter) and modPressed: fit = Fit.getInstance().getFit(fitID) selection = getSimilarFighters(fit.projectedFighters, mainItem) self.mainFrame.command.Submit(cmd.GuiChangeProjectedItemStatesCommand( fitID=fitID, mainItem=mainItem, items=selection, click='right' if event.GetButton() == 3 else 'left')) return event.Skip()
def activate(self, callingWindow, fullContext, mainItem, selection, i): fitID = self.mainFrame.getActiveFit() if isinstance(mainItem, EosFit): try: value = mainItem.getProjectionInfo(fitID).projectionRange except AttributeError: return else: value = mainItem.projectionRange if value is not None: value /= 1000 with RangeChanger(self.mainFrame, value) as dlg: if dlg.ShowModal() == wx.ID_OK: cleanInput = re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip()) if cleanInput: try: cleanInputFloat = float(cleanInput) except ValueError: return newRange = cleanInputFloat * 1000 else: newRange = None fitID = self.mainFrame.getActiveFit() items = selection if wx.GetMouseState().GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL): if isinstance(mainItem, EosModule): fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions(fit.projectedModules, mainItem) items = [fit.projectedModules[p] for p in positions] elif isinstance(mainItem, EosFighter): fit = Fit.getInstance().getFit(fitID) items = getSimilarFighters(fit.projectedFighters, mainItem) self.mainFrame.command.Submit(cmd.GuiChangeProjectedItemsProjectionRangeCommand( fitID=fitID, items=items, projectionRange=newRange))
def __handleProjectedItem(self, callingWindow, mainItem, selection): fitID = self.mainFrame.getActiveFit() if isinstance(mainItem, EosFit): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=selection, amount=math.inf)) elif isinstance(mainItem, EosModule): if wx.GetMouseState().GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL): fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions(fit.projectedModules, mainItem) items = [fit.projectedModules[p] for p in positions] else: items = selection self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=items, amount=math.inf)) elif isinstance(mainItem, EosDrone): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=selection, amount=math.inf)) elif isinstance(mainItem, EosFighter): if wx.GetMouseState().GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL): fit = Fit.getInstance().getFit(fitID) items = getSimilarFighters(fit.projectedFighters, mainItem) else: items = selection self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=items, amount=math.inf)) else: self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=selection, amount=math.inf))
def __handleProjectedItem(self, mainItem, selection): fitID = self.mainFrame.getActiveFit() if isinstance(mainItem, EosFit): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=selection, amount=math.inf)) elif isinstance(mainItem, EosModule): if wx.GetMouseState().GetModifiers() == wx.MOD_ALT: fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions(fit.projectedModules, mainItem) items = [fit.projectedModules[p] for p in positions] else: items = selection self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=items, amount=math.inf)) elif isinstance(mainItem, EosDrone): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=selection, amount=math.inf)) elif isinstance(mainItem, EosFighter): if wx.GetMouseState().GetModifiers() == wx.MOD_ALT: fit = Fit.getInstance().getFit(fitID) items = getSimilarFighters(fit.projectedFighters, mainItem) else: items = selection self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=items, amount=math.inf)) else: self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=selection, amount=math.inf))
def __handleModule(self, callingWindow, mainItem, selection): fitID = self.mainFrame.getActiveFit() fit = Fit.getInstance().getFit(fitID) if wx.GetMouseState().GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL): positions = getSimilarModPositions(fit.modules, mainItem) else: positions = [] for mod in selection: if mod in fit.modules: positions.append(fit.modules.index(mod)) self.mainFrame.command.Submit( cmd.GuiRemoveLocalModuleCommand(fitID=fitID, positions=positions))
def __handleModule(self, mainItem, selection): fitID = self.mainFrame.getActiveFit() fit = Fit.getInstance().getFit(fitID) if wx.GetMouseState().GetModifiers() == wx.MOD_ALT: positions = getSimilarModPositions(fit.modules, mainItem) else: positions = [] for mod in selection: if mod in fit.modules: positions.append(fit.modules.index(mod)) self.mainFrame.command.Submit(cmd.GuiRemoveLocalModuleCommand( fitID=fitID, positions=positions))
def onLeftDoubleClick(self, event): row, _ = self.HitTest(event.Position) if row != -1: col = self.getColumn(event.Position) if col != self.getColIndex(State): mainItem = self.get(row) if mainItem is None: return fitID = self.mainFrame.getActiveFit() modPressed = event.GetModifiers() == wx.MOD_ALT if isinstance(mainItem, EosFit): self.mainFrame.command.Submit( cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=[mainItem], amount=math.inf if modPressed else 1)) elif isinstance(mainItem, EosModule): if modPressed: fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions( fit.projectedModules, mainItem) items = [fit.projectedModules[p] for p in positions] else: items = [mainItem] self.mainFrame.command.Submit( cmd.GuiRemoveProjectedItemsCommand(fitID=fitID, items=items, amount=1)) elif isinstance(mainItem, EosDrone): self.mainFrame.command.Submit( cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=[mainItem], amount=math.inf if modPressed else 1)) elif isinstance(mainItem, EosFighter): if modPressed: fit = Fit.getInstance().getFit(fitID) items = getSimilarFighters(fit.projectedFighters, mainItem) else: items = [mainItem] self.mainFrame.command.Submit( cmd.GuiRemoveProjectedItemsCommand(fitID=fitID, items=items, amount=1)) else: self.mainFrame.command.Submit( cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=[mainItem], amount=math.inf if modPressed else 1))
def handleAmmoSwitch(self, event): charge = self.chargeIds.get(event.Id, False) if charge is False: event.Skip() return fitID = self.mainFrame.getActiveFit() sFit = Fit.getInstance() fit = sFit.getFit(fitID) mstate = wx.GetMouseState() # Switch in selection or all modules, depending on modifier key state and settings switchAll = sFit.serviceFittingOptions[ 'ammoChangeAll'] is not mstate.GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL) if switchAll: if self.srcContext == 'fittingModule': command = cmd.GuiChangeLocalModuleChargesCommand modContainer = fit.modules elif self.srcContext == 'projectedModule': command = cmd.GuiChangeProjectedModuleChargesCommand modContainer = fit.projectedModules else: return positions = getSimilarModPositions(modContainer, self.module) self.mainFrame.command.Submit( command( fitID=fitID, positions=positions, chargeItemID=charge.ID if charge is not None else None)) else: if self.srcContext == 'fittingModule': command = cmd.GuiChangeLocalModuleChargesCommand modContainer = fit.modules elif self.srcContext == 'projectedModule': command = cmd.GuiChangeProjectedModuleChargesCommand modContainer = fit.projectedModules else: return positions = [] for position, mod in enumerate(modContainer): if mod in self.selection: modCharges = self.getChargesForMod(mod) if modCharges.issubset(self.mainCharges): positions.append(position) self.mainFrame.command.Submit( command( fitID=fitID, positions=positions, chargeItemID=charge.ID if charge is not None else None))
def handleAmmoSwitch(self, event): charge = self.chargeIds.get(event.Id, False) if charge is False: event.Skip() return fitID = self.mainFrame.getActiveFit() sFit = Fit.getInstance() fit = sFit.getFit(fitID) mstate = wx.GetMouseState() # Switch in selection or all modules, depending on modifier key state and settings switchAll = sFit.serviceFittingOptions['ammoChangeAll'] is not (mstate.GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL)) if switchAll: if self.srcContext == 'fittingModule': command = cmd.GuiChangeLocalModuleChargesCommand modContainer = fit.modules elif self.srcContext == 'projectedModule': command = cmd.GuiChangeProjectedModuleChargesCommand modContainer = fit.projectedModules else: return positions = getSimilarModPositions(modContainer, self.module) self.mainFrame.command.Submit(command( fitID=fitID, positions=positions, chargeItemID=charge.ID if charge is not None else None)) else: if self.srcContext == 'fittingModule': command = cmd.GuiChangeLocalModuleChargesCommand modContainer = fit.modules elif self.srcContext == 'projectedModule': command = cmd.GuiChangeProjectedModuleChargesCommand modContainer = fit.projectedModules else: return positions = [] for position, mod in enumerate(modContainer): if mod in self.selection: modCharges = self.getChargesForMod(mod) if modCharges.issubset(self.mainCharges): positions.append(position) self.mainFrame.command.Submit(command( fitID=fitID, positions=positions, chargeItemID=charge.ID if charge is not None else None))
def __handleProjectedModule(self, varItem): fitID = self.mainFrame.getActiveFit() fit = Fit.getInstance().getFit(fitID) if wx.GetMouseState().GetModifiers() == wx.MOD_ALT: positions = getSimilarModPositions(fit.projectedModules, self.mainItem) else: sMkt = Market.getInstance() positions = [] for mod in self.selection: if mod is self.mainItem: positions.append(fit.projectedModules.index(mod)) continue if mod not in fit.projectedModules: continue modVariations = sMkt.getVariationsByItems((mod.item,)) if modVariations == self.mainVariations: positions.append(fit.projectedModules.index(mod)) self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleMetasCommand( fitID=fitID, positions=positions, newItemID=varItem.ID))
def onLeftDoubleClick(self, event): row, _ = self.HitTest(event.Position) if row != -1: col = self.getColumn(event.Position) if col != self.getColIndex(State): mainItem = self.get(row) if mainItem is None: return fitID = self.mainFrame.getActiveFit() modPressed = wx.GetMouseState().GetModifiers() == wx.MOD_ALT if isinstance(mainItem, EosFit): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=[mainItem], amount=math.inf if modPressed else 1)) elif isinstance(mainItem, EosModule): if modPressed: fit = Fit.getInstance().getFit(fitID) positions = getSimilarModPositions(fit.projectedModules, mainItem) items = [fit.projectedModules[p] for p in positions] else: items = [mainItem] self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=items, amount=1)) elif isinstance(mainItem, EosDrone): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=[mainItem], amount=math.inf if modPressed else 1)) elif isinstance(mainItem, EosFighter): if modPressed: fit = Fit.getInstance().getFit(fitID) items = getSimilarFighters(fit.projectedFighters, mainItem) else: items = [mainItem] self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=items, amount=1)) else: self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand( fitID=fitID, items=[mainItem], amount=math.inf if modPressed else 1))
def click(self, event): """ Handle click event on modules. This is only useful for the State column. If multiple items are selected, and we have clicked the State column, iterate through the selections and change State """ clickedRow, _, col = self.HitTestSubItem(event.Position) # only do State column and ignore invalid rows if clickedRow != -1 and clickedRow not in self.blanks and col == self.getColIndex( State): selectedRows = [] currentRow = self.GetFirstSelected() while currentRow != -1 and clickedRow not in self.blanks: selectedRows.append(currentRow) currentRow = self.GetNextSelected(currentRow) if clickedRow not in selectedRows: try: selectedMods = [self.mods[clickedRow]] except IndexError: return else: selectedMods = self.getSelectedMods() click = "ctrl" if event.GetModifiers( ) == wx.MOD_CONTROL or event.middleIsDown else "right" if event.GetButton( ) == 3 else "left" try: mainMod = self.mods[clickedRow] except IndexError: return if mainMod.isEmpty: return fitID = self.mainFrame.getActiveFit() fit = Fit.getInstance().getFit(fitID) if mainMod not in fit.modules: return mainPosition = fit.modules.index(mainMod) if event.GetModifiers() == wx.MOD_ALT: positions = getSimilarModPositions(fit.modules, mainMod) else: positions = [] for position, mod in enumerate(fit.modules): if mod in selectedMods: positions.append(position) self.mainFrame.command.Submit( cmd.GuiChangeLocalModuleStatesCommand( fitID=fitID, mainPosition=mainPosition, positions=positions, click=click)) # update state tooltip tooltip = self.activeColumns[col].getToolTip(self.mods[clickedRow]) if tooltip: self.SetToolTip(tooltip) else: event.Skip()