diff --git a/gui/builtinViews/entityEditor.py b/gui/builtinViews/entityEditor.py index faaf1e3bb..112c1c63e 100644 --- a/gui/builtinViews/entityEditor.py +++ b/gui/builtinViews/entityEditor.py @@ -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)) \ No newline at end of file + 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 \ No newline at end of file diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 3b76a13c9..7557813db 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -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 """ diff --git a/gui/resistsEditor.py b/gui/resistsEditor.py index 57b438dc5..374f9c1fc 100644 --- a/gui/resistsEditor.py +++ b/gui/resistsEditor.py @@ -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 diff --git a/gui/setEditor.py b/gui/setEditor.py index 3b283d601..4e8baa9ed 100644 --- a/gui/setEditor.py +++ b/gui/setEditor.py @@ -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()