Merge pull request #2103 from Gochim/issue/2073
Issue #2073: Added ability to add a list of implants from implant view to a new implant set
This commit is contained in:
@@ -299,7 +299,10 @@ class ImplantDisplay(d.Display):
|
||||
sourceContext1 = "implantItem" if fit.implantSource == ImplantLocation.FIT else "implantItemChar"
|
||||
sourceContext2 = "implantItemMisc" if fit.implantSource == ImplantLocation.FIT else "implantItemMiscChar"
|
||||
itemContext = None if mainImplant is None else Market.getInstance().getCategoryByItem(mainImplant.item).name
|
||||
menu = ContextMenu.getMenu(self, mainImplant, selection, (sourceContext1, itemContext), (sourceContext2, itemContext))
|
||||
menu = ContextMenu.getMenu(self, mainImplant, selection,
|
||||
(sourceContext1, itemContext),
|
||||
(sourceContext2, itemContext)
|
||||
)
|
||||
if menu:
|
||||
self.PopupMenu(menu)
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ from gui.builtinContextMenus import cargoAdd
|
||||
from gui.builtinContextMenus import cargoAddAmmo
|
||||
from gui.builtinContextMenus import itemProject
|
||||
from gui.builtinContextMenus import ammoToDmgPattern
|
||||
from gui.builtinContextMenus import implantSetLoad
|
||||
from gui.builtinContextMenus import implantSetAdd
|
||||
# Price
|
||||
from gui.builtinContextMenus import priceOptions
|
||||
|
||||
@@ -1,52 +1,25 @@
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from service.implantSet import ImplantSets as s_ImplantSets
|
||||
|
||||
|
||||
class AddImplantSet(ContextMenuUnconditional):
|
||||
class ImplantSetAdd(ContextMenuUnconditional):
|
||||
|
||||
def display(self, callingWindow, srcContext):
|
||||
|
||||
sIS = s_ImplantSets.getInstance()
|
||||
implantSets = sIS.getImplantSetList()
|
||||
|
||||
if len(implantSets) == 0:
|
||||
if not hasattr(callingWindow, 'implants'):
|
||||
return False
|
||||
return srcContext in ("implantItemMisc", "implantEditor")
|
||||
|
||||
def getText(self, callingWindow, itmContext):
|
||||
return "Add Implant Set"
|
||||
implantList = callingWindow.implants
|
||||
if not implantList or len(implantList) == 0:
|
||||
return False
|
||||
|
||||
def getSubMenu(self, callingWindow, context, rootMenu, i, pitem):
|
||||
m = wx.Menu()
|
||||
bindmenu = rootMenu if "wxMSW" in wx.PlatformInfo else m
|
||||
return srcContext in ("implantItemMisc", "implantItemMiscChar")
|
||||
|
||||
sIS = s_ImplantSets.getInstance()
|
||||
implantSets = sIS.getImplantSetList()
|
||||
def getText(self, callingWindow, context):
|
||||
return "Add As New Implant Set"
|
||||
|
||||
self.context = context
|
||||
self.callingWindow = callingWindow
|
||||
|
||||
self.idmap = {}
|
||||
|
||||
for set in sorted(implantSets, key=lambda i: i.name):
|
||||
id = ContextMenuUnconditional.nextID()
|
||||
mitem = wx.MenuItem(rootMenu, id, set.name)
|
||||
bindmenu.Bind(wx.EVT_MENU, self.handleSelection, mitem)
|
||||
self.idmap[id] = set
|
||||
m.Append(mitem)
|
||||
|
||||
return m
|
||||
|
||||
def handleSelection(self, event):
|
||||
impSet = self.idmap.get(event.Id, None)
|
||||
if impSet is None:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
self.callingWindow.addImplantSet(impSet)
|
||||
def activate(self, callingWindow, fullContext, i):
|
||||
implantList = callingWindow.implants
|
||||
callingWindow.mainFrame.OnShowImplantSetEditor(None, implantList)
|
||||
|
||||
|
||||
AddImplantSet.register()
|
||||
ImplantSetAdd.register()
|
||||
|
||||
53
gui/builtinContextMenus/implantSetLoad.py
Normal file
53
gui/builtinContextMenus/implantSetLoad.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from service.implantSet import ImplantSets as s_ImplantSets
|
||||
|
||||
|
||||
class ImplantSetLoad(ContextMenuUnconditional):
|
||||
|
||||
def display(self, callingWindow, srcContext):
|
||||
|
||||
sIS = s_ImplantSets.getInstance()
|
||||
implantSets = sIS.getImplantSetList()
|
||||
|
||||
if len(implantSets) == 0:
|
||||
return False
|
||||
|
||||
return srcContext in ("implantItemMisc", "implantEditor")
|
||||
|
||||
def getText(self, callingWindow, context):
|
||||
return "Apply Implant Set"
|
||||
|
||||
def getSubMenu(self, callingWindow, context, rootMenu, i, pitem):
|
||||
m = wx.Menu()
|
||||
bindmenu = rootMenu if "wxMSW" in wx.PlatformInfo else m
|
||||
|
||||
sIS = s_ImplantSets.getInstance()
|
||||
implantSets = sIS.getImplantSetList()
|
||||
|
||||
self.context = context
|
||||
self.callingWindow = callingWindow
|
||||
|
||||
self.idmap = {}
|
||||
|
||||
for set in sorted(implantSets, key=lambda i: i.name):
|
||||
id = ContextMenuUnconditional.nextID()
|
||||
mitem = wx.MenuItem(rootMenu, id, set.name)
|
||||
bindmenu.Bind(wx.EVT_MENU, self.handleSelection, mitem)
|
||||
self.idmap[id] = set
|
||||
m.Append(mitem)
|
||||
|
||||
return m
|
||||
|
||||
def handleSelection(self, event):
|
||||
impSet = self.idmap.get(event.Id, None)
|
||||
if impSet is None:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
self.callingWindow.addImplantSet(impSet)
|
||||
|
||||
|
||||
ImplantSetLoad.register()
|
||||
@@ -178,10 +178,17 @@ class EntityEditor(wx.Panel):
|
||||
return True
|
||||
|
||||
def checkEntitiesExist(self):
|
||||
if len(self.choices) == 0:
|
||||
self.Parent.Hide()
|
||||
if self.OnNew(None) is False:
|
||||
return False
|
||||
self.Parent.Show()
|
||||
if len(self.choices) > 0:
|
||||
return True
|
||||
else:
|
||||
return self.enterNewEntity()
|
||||
|
||||
def enterNewEntity(self):
|
||||
self.Parent.Hide()
|
||||
if self.OnNew(None) is False:
|
||||
return False
|
||||
self.Parent.Show()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -442,8 +442,8 @@ class MainFrame(wx.Frame):
|
||||
def OnShowDamagePatternEditor(self, event):
|
||||
DmgPatternEditor.openOne(parent=self)
|
||||
|
||||
def OnShowImplantSetEditor(self, event):
|
||||
ImplantSetEditor.openOne(parent=self)
|
||||
def OnShowImplantSetEditor(self, event, dataToAdd=None):
|
||||
ImplantSetEditor.openOne(parent=self, dataToAdd=dataToAdd)
|
||||
|
||||
def OnShowExportDialog(self, event):
|
||||
""" Export active fit """
|
||||
|
||||
@@ -47,7 +47,7 @@ class ImplantTextValidor(BaseValidator):
|
||||
if len(text) == 0:
|
||||
raise ValueError("You must supply a name for the Implant Set!")
|
||||
elif text in [x.name for x in entityEditor.choices]:
|
||||
raise ValueError("Imlplant Set name already in use, please choose another.")
|
||||
raise ValueError("Implant Set name already in use, please choose another.")
|
||||
|
||||
return True
|
||||
except ValueError as e:
|
||||
@@ -84,6 +84,14 @@ class ImplantSetEntityEditor(EntityEditor):
|
||||
sIS = ImplantSets.getInstance()
|
||||
sIS.deleteSet(entity)
|
||||
|
||||
def addExternalDataToSet(self, dataToAdd):
|
||||
""" Add new set and fill it with data from the current fit """
|
||||
if self.enterNewEntity():
|
||||
sIS = ImplantSets.getInstance()
|
||||
set_ = self.Parent.entityEditor.getActiveEntity()
|
||||
for item in dataToAdd:
|
||||
sIS.addImplant(set_.ID, item.item.ID)
|
||||
|
||||
|
||||
class ImplantSetEditorView(BaseImplantEditorView):
|
||||
|
||||
@@ -117,7 +125,7 @@ class ImplantSetEditorView(BaseImplantEditorView):
|
||||
|
||||
class ImplantSetEditor(AuxiliaryFrame):
|
||||
|
||||
def __init__(self, parent):
|
||||
def __init__(self, parent, dataToAdd=None):
|
||||
super().__init__(
|
||||
parent, id=wx.ID_ANY, title="Implant Set Editor", resizeable=True,
|
||||
size=wx.Size(950, 500) if "wxGTK" in wx.PlatformInfo else wx.Size(850, 420))
|
||||
@@ -166,7 +174,10 @@ class ImplantSetEditor(AuxiliaryFrame):
|
||||
self.SetSizer(mainSizer)
|
||||
self.Layout()
|
||||
|
||||
if not self.entityEditor.checkEntitiesExist():
|
||||
if dataToAdd:
|
||||
# add an implant set using data passed from outside
|
||||
self.entityEditor.addExternalDataToSet(dataToAdd)
|
||||
elif not self.entityEditor.checkEntitiesExist():
|
||||
self.Close()
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user