Do not show implant set editor if user cancels addition of an implant set
This commit is contained in:
@@ -1,25 +1,77 @@
|
||||
import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class ImplantSetSave(ContextMenuUnconditional):
|
||||
|
||||
def __init__(self):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
def display(self, callingWindow, srcContext):
|
||||
|
||||
if not hasattr(callingWindow, 'implants'):
|
||||
if srcContext not in ('implantItemMisc', 'implantItemMiscChar'):
|
||||
return False
|
||||
|
||||
implantList = callingWindow.implants
|
||||
if not implantList or len(implantList) == 0:
|
||||
fit = Fit.getInstance().getFit(self.mainFrame.getActiveFit())
|
||||
self.implants = fit.appliedImplants[:]
|
||||
if not self.implants:
|
||||
return False
|
||||
|
||||
return srcContext in ("implantItemMisc", "implantItemMiscChar")
|
||||
return True
|
||||
|
||||
def getText(self, callingWindow, context):
|
||||
return "Save as New Implant Set"
|
||||
return 'Save as New Implant Set'
|
||||
|
||||
def activate(self, callingWindow, fullContext, i):
|
||||
implantList = callingWindow.implants
|
||||
callingWindow.mainFrame.OnShowImplantSetEditor(None, implantList)
|
||||
with NameDialog(self.mainFrame, '') as dlg:
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
name = dlg.input.GetLineText(0).strip()
|
||||
if name == '':
|
||||
return
|
||||
from gui.setEditor import ImplantSetEditor
|
||||
ImplantSetEditor.openOne(parent=self.mainFrame, dataToAdd=(name, self.implants))
|
||||
|
||||
|
||||
ImplantSetSave.register()
|
||||
|
||||
|
||||
class NameDialog(wx.Dialog):
|
||||
|
||||
def __init__(self, parent, value):
|
||||
super().__init__(parent, title='New Implant Set', style=wx.DEFAULT_DIALOG_STYLE)
|
||||
self.SetMinSize((346, 156))
|
||||
|
||||
bSizer1 = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
bSizer2 = wx.BoxSizer(wx.VERTICAL)
|
||||
text = wx.StaticText(self, wx.ID_ANY, 'Enter a name for your new Implant Set:')
|
||||
bSizer2.Add(text, 0)
|
||||
|
||||
bSizer1.Add(bSizer2, 0, wx.ALL, 10)
|
||||
|
||||
self.input = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
|
||||
if value is None:
|
||||
value = ''
|
||||
else:
|
||||
value = str(value)
|
||||
self.input.SetValue(value)
|
||||
self.input.SelectAll()
|
||||
|
||||
bSizer1.Add(self.input, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 15)
|
||||
|
||||
bSizer3 = wx.BoxSizer(wx.VERTICAL)
|
||||
bSizer3.Add(wx.StaticLine(self, wx.ID_ANY), 0, wx.BOTTOM | wx.EXPAND, 15)
|
||||
|
||||
bSizer3.Add(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL), 0, wx.EXPAND)
|
||||
bSizer1.Add(bSizer3, 0, wx.ALL | wx.EXPAND, 10)
|
||||
|
||||
self.input.SetFocus()
|
||||
self.input.Bind(wx.EVT_TEXT_ENTER, self.processEnter)
|
||||
self.SetSizer(bSizer1)
|
||||
self.CenterOnParent()
|
||||
self.Fit()
|
||||
|
||||
def processEnter(self, evt):
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
@@ -442,8 +442,8 @@ class MainFrame(wx.Frame):
|
||||
def OnShowDamagePatternEditor(self, event):
|
||||
DmgPatternEditor.openOne(parent=self)
|
||||
|
||||
def OnShowImplantSetEditor(self, event, dataToAdd=None):
|
||||
ImplantSetEditor.openOne(parent=self, dataToAdd=dataToAdd)
|
||||
def OnShowImplantSetEditor(self, event):
|
||||
ImplantSetEditor.openOne(parent=self)
|
||||
|
||||
def OnShowExportDialog(self, event):
|
||||
""" Export active fit """
|
||||
|
||||
@@ -84,14 +84,6 @@ 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):
|
||||
|
||||
@@ -114,7 +106,7 @@ class ImplantSetEditorView(BaseImplantEditorView):
|
||||
sIS = ImplantSets.getInstance()
|
||||
set_ = self.Parent.entityEditor.getActiveEntity()
|
||||
|
||||
sIS.addImplant(set_.ID, item.ID)
|
||||
sIS.addImplants(set_.ID, item.ID)
|
||||
|
||||
def removeImplantFromContext(self, implant):
|
||||
sIS = ImplantSets.getInstance()
|
||||
@@ -175,8 +167,11 @@ class ImplantSetEditor(AuxiliaryFrame):
|
||||
self.Layout()
|
||||
|
||||
if dataToAdd:
|
||||
# add an implant set using data passed from outside
|
||||
self.entityEditor.addExternalDataToSet(dataToAdd)
|
||||
name, implants = dataToAdd
|
||||
newSet = self.entityEditor.DoNew(name)
|
||||
ImplantSets.getInstance().addImplants(newSet.ID, *[i.item.ID for i in implants])
|
||||
self.entityEditor.refreshEntityList(newSet)
|
||||
wx.PostEvent(self.entityEditor.entityChoices, wx.CommandEvent(wx.wxEVT_COMMAND_CHOICE_SELECTED))
|
||||
elif not self.entityEditor.checkEntitiesExist():
|
||||
self.Close()
|
||||
return
|
||||
|
||||
@@ -52,11 +52,12 @@ class ImplantSets:
|
||||
return eos.db.getImplantSet(setID).implants
|
||||
|
||||
@staticmethod
|
||||
def addImplant(setID, itemID):
|
||||
def addImplants(setID, *itemIDs):
|
||||
implant_set = eos.db.getImplantSet(setID)
|
||||
implant = es_Implant(eos.db.getItem(itemID))
|
||||
implant_set.implants.makeRoom(implant)
|
||||
implant_set.implants.append(implant)
|
||||
for itemID in itemIDs:
|
||||
implant = es_Implant(eos.db.getItem(itemID))
|
||||
implant_set.implants.makeRoom(implant)
|
||||
implant_set.implants.append(implant)
|
||||
eos.db.commit()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user