Implement copy context menu for additions pane
This commit is contained in:
@@ -47,3 +47,6 @@ from gui.builtinContextMenus.targetProfile import switcher
|
||||
from gui.builtinContextMenus import graphDmgIgnoreResists
|
||||
from gui.builtinContextMenus import graphDmgApplyProjected
|
||||
from gui.builtinContextMenus import graphDmgDroneMode
|
||||
# Additions panel menus
|
||||
from gui.builtinContextMenus import additionsExportSelection
|
||||
from gui.builtinContextMenus import additionsExportAll
|
||||
|
||||
44
gui/builtinContextMenus/additionsExportAll.py
Normal file
44
gui/builtinContextMenus/additionsExportAll.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from gui.utils.clipboard import toClipboard
|
||||
from service.fit import Fit
|
||||
from service.port.eft import exportDrones, exportFighters, exportCargo, exportImplants, exportBoosters
|
||||
|
||||
|
||||
viewSpecMap = {
|
||||
'droneItemMisc': ('Drones', lambda cw: cw.drones, exportDrones),
|
||||
'fighterItemMisc': ('Fighters', lambda cw: cw.fighters, exportFighters),
|
||||
'cargoItemMisc': ('Cargo Items', lambda cw: cw.cargo, exportCargo),
|
||||
'implantItemMisc': ('Implants', lambda cw: cw.implants, exportImplants),
|
||||
'implantItemMiscChar': ('Implants', lambda cw: cw.implants, exportImplants),
|
||||
'boosterItemMisc': ('Boosters', lambda cw: cw.boosters, exportBoosters)}
|
||||
|
||||
|
||||
class AdditionsExportAll(ContextMenuUnconditional):
|
||||
|
||||
def __init__(self):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
def display(self, callingWindow, srcContext):
|
||||
if srcContext not in viewSpecMap:
|
||||
return False
|
||||
fit = Fit.getInstance().getFit(self.mainFrame.getActiveFit())
|
||||
if fit is None:
|
||||
return False
|
||||
if not viewSpecMap[srcContext][1](callingWindow):
|
||||
return False
|
||||
|
||||
self.srcContext = srcContext
|
||||
return True
|
||||
|
||||
def getText(self, callingWindow, itmContext):
|
||||
return 'Copy All {}'.format(viewSpecMap[self.srcContext][0])
|
||||
|
||||
def activate(self, callingWindow, fullContext, i):
|
||||
items = viewSpecMap[self.srcContext][1](callingWindow)
|
||||
export = viewSpecMap[self.srcContext][2](items)
|
||||
if export:
|
||||
toClipboard(export)
|
||||
|
||||
|
||||
AdditionsExportAll.register()
|
||||
43
gui/builtinContextMenus/additionsExportSelection.py
Normal file
43
gui/builtinContextMenus/additionsExportSelection.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenuSelection
|
||||
from gui.utils.clipboard import toClipboard
|
||||
from service.fit import Fit
|
||||
from service.port.eft import exportDrones, exportFighters, exportCargo, exportImplants, exportBoosters
|
||||
|
||||
|
||||
viewSpecMap = {
|
||||
'droneItemMisc': ('Drones', exportDrones),
|
||||
'fighterItemMisc': ('Fighters', exportFighters),
|
||||
'cargoItemMisc': ('Cargo Items', exportCargo),
|
||||
'implantItemMisc': ('Implants', exportImplants),
|
||||
'implantItemMiscChar': ('Implants', exportImplants),
|
||||
'boosterItemMisc': ('Boosters', exportBoosters)}
|
||||
|
||||
|
||||
class AdditionsExportAll(ContextMenuSelection):
|
||||
|
||||
def __init__(self):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
def display(self, callingWindow, srcContext, selection):
|
||||
if srcContext not in viewSpecMap:
|
||||
return False
|
||||
if not selection:
|
||||
return False
|
||||
fit = Fit.getInstance().getFit(self.mainFrame.getActiveFit())
|
||||
if fit is None:
|
||||
return False
|
||||
|
||||
self.srcContext = srcContext
|
||||
return True
|
||||
|
||||
def getText(self, callingWindow, itmContext, selection):
|
||||
return 'Copy Selected {}'.format(viewSpecMap[self.srcContext][0])
|
||||
|
||||
def activate(self, callingWindow, fullContext, selection, i):
|
||||
export = viewSpecMap[self.srcContext][1](selection)
|
||||
if export:
|
||||
toClipboard(export)
|
||||
|
||||
|
||||
AdditionsExportAll.register()
|
||||
@@ -1,11 +1,7 @@
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
import gui.fitCommands as cmd
|
||||
import gui.globalEvents as GE
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from service.character import Character
|
||||
from service.implantSet import ImplantSets as s_ImplantSets
|
||||
|
||||
|
||||
|
||||
@@ -104,45 +104,32 @@ def exportEft(fit, options, callback):
|
||||
|
||||
# Section 2: drones, fighters
|
||||
minionSection = []
|
||||
droneLines = []
|
||||
for drone in sorted(fit.drones, key=lambda d: d.item.name):
|
||||
droneLines.append('{} x{}'.format(drone.item.name, drone.amount))
|
||||
if droneLines:
|
||||
minionSection.append('\n'.join(droneLines))
|
||||
fighterLines = []
|
||||
for fighter in sorted(fit.fighters, key=lambda f: f.item.name):
|
||||
fighterLines.append('{} x{}'.format(fighter.item.name, fighter.amount))
|
||||
if fighterLines:
|
||||
minionSection.append('\n'.join(fighterLines))
|
||||
droneExport = exportDrones(fit.drones)
|
||||
if droneExport:
|
||||
minionSection.append(droneExport)
|
||||
fighterExport = exportFighters(fit.fighters)
|
||||
if fighterExport:
|
||||
minionSection.append(fighterExport)
|
||||
if minionSection:
|
||||
sections.append('\n\n'.join(minionSection))
|
||||
|
||||
# Section 3: implants, boosters
|
||||
if options[PortEftOptions.IMPLANTS]:
|
||||
charSection = []
|
||||
implantLines = []
|
||||
for implant in sorted(fit.implants, key=lambda i: i.slot or 0):
|
||||
implantLines.append(implant.item.name)
|
||||
if implantLines:
|
||||
charSection.append('\n'.join(implantLines))
|
||||
boosterLines = []
|
||||
for booster in sorted(fit.boosters, key=lambda b: b.slot or 0):
|
||||
boosterLines.append(booster.item.name)
|
||||
if boosterLines:
|
||||
charSection.append('\n'.join(boosterLines))
|
||||
implantExport = exportImplants(fit.implants)
|
||||
if implantExport:
|
||||
charSection.append(implantExport)
|
||||
boosterExport = exportBoosters(fit.boosters)
|
||||
if boosterExport:
|
||||
charSection.append(boosterExport)
|
||||
if charSection:
|
||||
sections.append('\n\n'.join(charSection))
|
||||
|
||||
# Section 4: cargo
|
||||
if options[PortEftOptions.CARGO]:
|
||||
cargoLines = []
|
||||
for cargo in sorted(
|
||||
fit.cargo,
|
||||
key=lambda c: (c.item.group.category.name, c.item.group.name, c.item.name)
|
||||
):
|
||||
cargoLines.append('{} x{}'.format(cargo.item.name, cargo.amount))
|
||||
if cargoLines:
|
||||
sections.append('\n'.join(cargoLines))
|
||||
cargoExport = exportCargo(fit.cargo)
|
||||
if cargoExport:
|
||||
sections.append(cargoExport)
|
||||
|
||||
# Section 5: mutated modules' details
|
||||
mutationLines = []
|
||||
@@ -161,6 +148,41 @@ def exportEft(fit, options, callback):
|
||||
return text
|
||||
|
||||
|
||||
def exportDrones(drones):
|
||||
droneLines = []
|
||||
for drone in sorted(drones, key=lambda d: d.item.name):
|
||||
droneLines.append('{} x{}'.format(drone.item.name, drone.amount))
|
||||
return '\n'.join(droneLines)
|
||||
|
||||
|
||||
def exportFighters(fighters):
|
||||
fighterLines = []
|
||||
for fighter in sorted(fighters, key=lambda f: f.item.name):
|
||||
fighterLines.append('{} x{}'.format(fighter.item.name, fighter.amount))
|
||||
return '\n'.join(fighterLines)
|
||||
|
||||
|
||||
def exportImplants(implants):
|
||||
implantLines = []
|
||||
for implant in sorted(implants, key=lambda i: i.slot or 0):
|
||||
implantLines.append(implant.item.name)
|
||||
return '\n'.join(implantLines)
|
||||
|
||||
|
||||
def exportBoosters(boosters):
|
||||
boosterLines = []
|
||||
for booster in sorted(boosters, key=lambda b: b.slot or 0):
|
||||
boosterLines.append(booster.item.name)
|
||||
return '\n'.join(boosterLines)
|
||||
|
||||
|
||||
def exportCargo(cargos):
|
||||
cargoLines = []
|
||||
for cargo in sorted(cargos, key=lambda c: (c.item.group.category.name, c.item.group.name, c.item.name)):
|
||||
cargoLines.append('{} x{}'.format(cargo.item.name, cargo.amount))
|
||||
return '\n'.join(cargoLines)
|
||||
|
||||
|
||||
def importEft(lines):
|
||||
lines = _importPrepare(lines)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user