Use GetModifiers() instead of asking status of individual keys

This commit is contained in:
DarkPhoenix
2019-04-27 14:22:09 +03:00
parent a919510d07
commit e865c9a399
15 changed files with 54 additions and 51 deletions

View File

@@ -89,11 +89,11 @@ class BoosterView(d.Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
boosters = self.getSelectedBoosters()
self.removeBoosters(boosters)
event.Skip()

View File

@@ -105,11 +105,11 @@ class CargoView(d.Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
cargos = self.getSelectedCargos()
self.removeCargos(cargos)
event.Skip()
@@ -132,7 +132,7 @@ class CargoView(d.Display):
fitID=self.mainFrame.getActiveFit(),
modPosition=modIdx,
cargoItemID=dstCargoItemID,
copy=wx.GetMouseState().cmdDown))
copy=wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL))
def fitChanged(self, event):
sFit = Fit.getInstance()

View File

@@ -97,11 +97,11 @@ class CommandView(d.Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
commandFits = self.getSelectedCommandFits()
self.removeCommandFits(commandFits)
event.Skip()

View File

@@ -121,11 +121,11 @@ class DroneView(Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
drones = self.getSelectedDrones()
self.removeDroneStacks(drones)
event.Skip()
@@ -230,7 +230,7 @@ class DroneView(Display):
event.Skip()
return
amount = droneStackLimit(fit, event.itemID) if wx.GetMouseState().altDown else 1
amount = droneStackLimit(fit, event.itemID) if wx.GetMouseState().GetModifiers() == wx.MOD_ALT else 1
if self.mainFrame.command.Submit(cmd.GuiAddLocalDroneCommand(fitID=fitID, itemID=event.itemID, amount=amount)):
self.mainFrame.additionsPane.select('Drones')
@@ -245,7 +245,7 @@ class DroneView(Display):
drone = self.drones[self.GetItemData(row)]
except IndexError:
return
if wx.GetMouseState().altDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
self.removeDroneStacks([drone])
else:
self.removeDrone(drone)

View File

@@ -184,11 +184,11 @@ class FighterDisplay(d.Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
fighters = self.getSelectedFighters()
self.removeFighters(fighters)
event.Skip()
@@ -295,7 +295,7 @@ class FighterDisplay(d.Display):
fighter = self.fighters[self.GetItemData(row)]
except IndexError:
return
if mstate.altDown:
if mstate.GetModifiers() == wx.MOD_ALT:
fighters = getSimilarFighters(self.original, fighter)
else:
fighters = [fighter]

View File

@@ -141,11 +141,11 @@ class ImplantDisplay(d.Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
implants = self.getSelectedImplants()
self.removeImplants(implants)
event.Skip()

View File

@@ -336,7 +336,7 @@ class ProjectedView(d.Display):
fitID = self.mainFrame.getActiveFit()
thing = self.get(row)
if isinstance(thing, es_Fit):
amount = math.inf if wx.GetMouseState().altDown else 1
amount = math.inf if wx.GetMouseState().GetModifiers() == wx.MOD_ALT else 1
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
fitID=fitID, projectedFitID=thing.ID, amount=amount))
elif isinstance(thing, es_Module):
@@ -350,7 +350,7 @@ class ProjectedView(d.Display):
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedDroneCommand(
fitID=fitID,
itemID=thing.itemID,
amount=math.inf if mstate.cmdDown or mstate.altDown else 1))
amount=math.inf if mstate.GetModifiers() == wx.MOD_ALT else 1))
elif isinstance(thing, es_Fighter):
fit = Fit.getInstance().getFit(fitID)
if thing in fit.projectedFighters:

View File

@@ -71,7 +71,7 @@ class FighterAbilities(ContextMenuCombined):
else:
if self.fighter in fit.fighters:
mainPosition = fit.fighters.index(self.fighter)
if wx.GetMouseState().altDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
fighters = getSimilarFighters(fit.fighters, self.fighter)
else:
fighters = self.selection

View File

@@ -59,7 +59,7 @@ class RemoveItem(ContextMenuCombined):
def __handleModule(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if wx.GetMouseState().altDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
positions = getSimilarModPositions(fit.modules, mainItem)
else:
positions = []
@@ -82,7 +82,7 @@ class RemoveItem(ContextMenuCombined):
def __handleFighter(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if wx.GetMouseState().altDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
fighters = getSimilarFighters(fit.fighters, mainItem)
else:
fighters = selection

View File

@@ -54,7 +54,7 @@ class ItemStats(ContextMenuSingle):
mstate = wx.GetMouseState()
reuse = False
if mstate.shiftDown:
if mstate.GetModifiers() == wx.MOD_SHIFT:
reuse = True
if self.mainFrame.GetActiveStatsWindow() is None and reuse:

View File

@@ -147,7 +147,7 @@ class ChangeItemToVariation(ContextMenuCombined):
def __handleModule(self, varItem):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if wx.GetMouseState().altDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
positions = getSimilarModPositions(fit.modules, self.mainItem)
else:
sMkt = Market.getInstance()
@@ -186,7 +186,7 @@ class ChangeItemToVariation(ContextMenuCombined):
def __handleFighter(self, varItem):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if wx.GetMouseState().altDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
fighters = getSimilarFighters(fit.fighters, self.mainItem)
else:
fighters = self.selection

View File

@@ -230,7 +230,7 @@ class ChangeModuleAmmo(ContextMenuCombined):
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.cmdDown or mstate.altDown)
switchAll = sFit.serviceFittingOptions['ammoChangeAll'] is not mstate.GetModifiers() in (wx.MOD_ALT, wx.MOD_CONTROL)
if switchAll:
if self.srcContext == 'fittingModule':
command = cmd.GuiChangeLocalModuleChargesCommand

View File

@@ -346,7 +346,8 @@ class FitItem(SFItem.SFBrowserItem):
return
# to prevent accidental deletion, give dialog confirmation unless shift is depressed
if wx.GetMouseState().ShiftDown() or wx.GetMouseState().MiddleIsDown():
mstate = wx.GetMouseState()
if mstate.GetModifiers() == wx.MOD_SHIFT or mstate.MiddleIsDown():
self.deleteFit()
else:
dlg = wx.MessageDialog(

View File

@@ -75,7 +75,7 @@ class FitSpawner(gui.multiSwitch.TabSpawner):
sFit = Fit.getInstance()
openFitInNew = sFit.serviceFittingOptions["openFitInNew"]
mstate = wx.GetMouseState()
modifierKey = mstate.cmdDown
modifierKey = mstate.GetModifiers() == wx.MOD_CONTROL
if from_import or (not openFitInNew and modifierKey) or startup or (openFitInNew and not modifierKey):
self.multiSwitch.AddPage()
@@ -281,11 +281,11 @@ class FittingView(d.Display):
def kbEvent(self, event):
keycode = event.GetKeyCode()
mstate = wx.GetMouseState()
if keycode == wx.WXK_ESCAPE and not mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
if keycode == wx.WXK_ESCAPE and mstate.GetModifiers() == wx.MOD_NONE:
self.unselectAll()
if keycode == 65 and mstate.cmdDown and not mstate.altDown and not mstate.shiftDown:
elif keycode == 65 and mstate.GetModifiers() == wx.MOD_CONTROL:
self.selectAll()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
elif keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
modules = [m for m in self.getSelectedMods() if not m.isEmpty]
self.removeModule(modules)
event.Skip()
@@ -374,7 +374,7 @@ class FittingView(d.Display):
if item is None:
event.Skip()
return
batchOp = wx.GetMouseState().altDown and getattr(event, 'allowBatch', None) is not False
batchOp = wx.GetMouseState().GetModifiers() == wx.MOD_ALT and getattr(event, 'allowBatch', None) is not False
# If we've selected ammo, then apply to the selected module(s)
if item.isCharge:
positions = []
@@ -400,7 +400,7 @@ class FittingView(d.Display):
def removeItem(self, event):
"""Double Left Click - remove module"""
if event.cmdDown:
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):
@@ -412,7 +412,7 @@ class FittingView(d.Display):
return
if not isinstance(mod, Module) or mod.isEmpty:
return
if event.altDown:
if event.GetModifiers() == wx.MOD_ALT:
fit = Fit.getInstance().getFit(self.activeFitID)
positions = getSimilarModPositions(fit.modules, mod)
self.mainFrame.command.Submit(cmd.GuiRemoveLocalModuleCommand(
@@ -458,15 +458,15 @@ class FittingView(d.Display):
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.altDown else [dstPos]
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.altDown:
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.altDown:
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))
@@ -477,7 +477,7 @@ class FittingView(d.Display):
positionsAll = list(range(len(fit.modules)))
if dstMod is None or dstMod.isEmpty:
positions = positionsAll
elif mstate.altDown:
elif mstate.GetModifiers() == wx.MOD_ALT:
positions = getSimilarModPositions(fit.modules, dstMod)
failoverToAll = True
else:
@@ -504,7 +504,10 @@ class FittingView(d.Display):
if mod in fit.modules:
position = fit.modules.index(mod)
self.mainFrame.command.Submit(cmd.GuiCargoToLocalModuleCommand(
fitID=fitID, cargoItemID=cargoItemID, modPosition=position, copy=wx.GetMouseState().cmdDown))
fitID=fitID,
cargoItemID=cargoItemID,
modPosition=position,
copy=wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL))
def swapItems(self, x, y, srcIdx):
"""Swap two modules in fitting window"""
@@ -529,13 +532,13 @@ class FittingView(d.Display):
return
mod2Position = fit.modules.index(mod2)
mstate = wx.GetMouseState()
if mstate.cmdDown and mstate.altDown:
if mstate.GetModifiers() == wx.MOD_CONTROL | wx.MOD_ALT:
self.mainFrame.command.Submit(cmd.GuiFillWithClonedLocalModulesCommand(
fitID=self.activeFitID, position=srcIdx))
elif mstate.cmdDown and mod2.isEmpty:
elif mstate.GetModifiers() == wx.MOD_CONTROL and mod2.isEmpty:
self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
fitID=self.activeFitID, srcPosition=srcIdx, dstPosition=mod2Position))
elif not mstate.cmdDown:
elif mstate.GetModifiers() == wx.MOD_NONE:
self.mainFrame.command.Submit(cmd.GuiSwapLocalModulesCommand(
fitID=self.activeFitID, position1=srcIdx, position2=mod2Position))
@@ -696,7 +699,7 @@ class FittingView(d.Display):
else:
selectedMods = self.getSelectedMods()
click = "ctrl" if event.cmdDown or event.middleIsDown else "right" if event.GetButton() == 3 else "left"
click = "ctrl" if event.GetModifiers() == wx.MOD_CONTROL or event.middleIsDown else "right" if event.GetButton() == 3 else "left"
try:
mainMod = self.mods[self.GetItemData(row)]
@@ -709,7 +712,7 @@ class FittingView(d.Display):
if mainMod not in fit.modules:
return
mainPosition = fit.modules.index(mainMod)
if event.altDown:
if event.GetModifiers() == wx.MOD_ALT:
positions = getSimilarModPositions(fit.modules, mainMod)
else:
positions = []

View File

@@ -83,10 +83,9 @@ class MarketBrowser(wx.Panel):
def toggleMetaButton(self, event):
"""Process clicks on toggle buttons"""
mstate = wx.GetMouseState()
clickedBtn = event.EventObject
if mstate.cmdDown:
if wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL:
activeBtns = [btn for btn in self.metaButtons if btn.GetValue()]
if activeBtns:
clickedBtn.setUserSelection(clickedBtn.GetValue())