Add in logic that required an entity for implant sets and target resists (not needed for character or damage profiles as we have read-only defaults)

This commit is contained in:
blitzmann
2016-03-30 00:03:48 -04:00
parent 1161037092
commit 39b2f87194
4 changed files with 47 additions and 11 deletions

View File

@@ -18,6 +18,8 @@ class BaseValidator(wx.PyValidator):
class TextEntryValidatedDialog(wx.TextEntryDialog):
def __init__(self, parent, validator=None, *args, **kargs):
wx.TextEntryDialog.__init__(self, parent, *args, **kargs)
self.parent = parent
self.txtctrl = self.FindWindowById(3000)
if validator:
self.txtctrl.SetValidator(validator())
@@ -35,7 +37,7 @@ class EntityEditor (wx.Panel):
self.validator = None
self.navSizer = wx.BoxSizer(wx.HORIZONTAL)
self.choices = self.getEntitiesFromContext()
self.choices = []
self.choices.sort(key=lambda p: p.name)
self.entityChoices = wx.Choice(self, choices=map(lambda p: p.name, self.choices))
self.navSizer.Add(self.entityChoices, 1, wx.ALL, 5)
@@ -60,10 +62,11 @@ class EntityEditor (wx.Panel):
setattr(self, "btn%s" % name.capitalize(), btn)
self.navSizer.Add(btn, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)
self.entityChoices.SetSelection(0)
self.SetSizer(self.navSizer)
self.Layout()
self.refreshEntityList()
def SetEditorValidator(self, validator=None):
""" Sets validator class (not an instance of the class) """
self.validator = validator
@@ -98,6 +101,8 @@ class EntityEditor (wx.Panel):
new = self.DoNew(dlg.GetValue().strip())
self.refreshEntityList(new)
wx.PostEvent(self.entityChoices, wx.CommandEvent(wx.wxEVT_COMMAND_CHOICE_SELECTED))
else:
return False
def OnCopy(self, event):
dlg = TextEntryValidatedDialog(self, self.validator,
@@ -141,6 +146,7 @@ class EntityEditor (wx.Panel):
def refreshEntityList(self, selected=None):
self.choices = self.getEntitiesFromContext()
self.entityChoices.Clear()
self.entityChoices.AppendItems(map(lambda p: p.name, self.choices))
if selected:
idx = self.choices.index(selected)
@@ -155,4 +161,13 @@ class EntityEditor (wx.Panel):
return self.choices[self.entityChoices.GetSelection()]
def setActiveEntity(self, entity):
self.entityChoices.SetSelection(self.choices.index(entity))
self.entityChoices.SetSelection(self.choices.index(entity))
def checkEntitiesExist(self):
if len(self.choices) == 0:
self.Parent.Hide()
if self.OnNew(None) is False:
return False
self.Parent.Show()
return True

View File

@@ -359,9 +359,7 @@ class MainFrame(wx.Frame):
dlg.Show()
def showTargetResistsEditor(self, event):
dlg=ResistsEditorDlg(self)
dlg.ShowModal()
dlg.Destroy()
ResistsEditorDlg(self)
def showDamagePatternEditor(self, event):
dlg=DmgPatternEditorDlg(self)
@@ -369,9 +367,7 @@ class MainFrame(wx.Frame):
dlg.Destroy()
def showImplantSetEditor(self, event):
dlg=ImplantSetEditorDlg(self)
dlg.ShowModal()
dlg.Destroy()
ImplantSetEditorDlg(self)
def showExportDialog(self, event):
""" Export active fit """

View File

@@ -33,7 +33,7 @@ class TargetResistsTextValidor(BaseValidator):
return TargetResistsTextValidor()
def Validate(self, win):
profileEditor = win.Parent
profileEditor = win.parent.Parent
textCtrl = self.GetWindow()
text = textCtrl.GetValue().strip()
@@ -169,6 +169,10 @@ class ResistsEditorDlg(wx.Dialog):
btn.SetToolTipString("%s patterns %s clipboard" % (name, direction) )
footerSizer.Add(btn, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_RIGHT)
if not self.entityEditor.checkEntitiesExist():
self.Destroy()
return
self.Layout()
bsize = self.GetBestSize()
self.SetSize((-1, bsize.height))
@@ -178,6 +182,8 @@ class ResistsEditorDlg(wx.Dialog):
self.patternChanged()
self.ShowModal()
def closeEvent(self, event):
self.Destroy()
@@ -230,6 +236,11 @@ class ResistsEditorDlg(wx.Dialog):
def patternChanged(self, event=None):
"Event fired when user selects pattern. Can also be called from script"
if not self.entityEditor.checkEntitiesExist():
self.Destroy()
return
p = self.entityEditor.getActiveEntity()
if p is None:
return

View File

@@ -36,7 +36,7 @@ class ImplantTextValidor(BaseValidator):
return ImplantTextValidor()
def Validate(self, win):
profileEditor = win.Parent
profileEditor = win.parent.Parent
textCtrl = self.GetWindow()
text = textCtrl.GetValue().strip()
@@ -163,9 +163,23 @@ class ImplantSetEditorDlg(wx.Dialog):
self.SetSizer(mainSizer)
self.Layout()
if not self.entityEditor.checkEntitiesExist():
self.Destroy()
return
self.Bind(wx.EVT_CHOICE, self.entityChanged)
self.Import.Bind(wx.EVT_BUTTON, self.importPatterns)
self.Export.Bind(wx.EVT_BUTTON, self.exportPatterns)
self.CenterOnParent()
self.ShowModal()
def entityChanged(self, event):
if not self.entityEditor.checkEntitiesExist():
self.Destroy()
return
def closeEvent(self, event):
self.Destroy()