From e85d144928a2fd55f6fa9537e7f61b3c7abf0c0d Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 23 Feb 2018 23:25:11 -0500 Subject: [PATCH] Migrate the Save Character As dialog tot he same dialog / validator as the Edit Character Name (#1419) --- gui/characterEditor.py | 56 ++++++++++++++++-------------------------- gui/mainFrame.py | 6 ++--- service/character.py | 1 + 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 626e705ad..3ef4b1ba8 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -29,7 +29,7 @@ from gui.bitmapLoader import BitmapLoader from gui.contextMenu import ContextMenu import gui.globalEvents as GE from gui.builtinViews.implantEditor import BaseImplantEditorView -from gui.builtinViews.entityEditor import EntityEditor, BaseValidator +from gui.builtinViews.entityEditor import EntityEditor, BaseValidator, TextEntryValidatedDialog from service.fit import Fit from service.character import Character from service.network import AuthenticationError, TimeoutError @@ -61,14 +61,14 @@ class CharacterTextValidor(BaseValidator): return CharacterTextValidor() def Validate(self, win): - entityEditor = win.parent textCtrl = self.GetWindow() text = textCtrl.GetValue().strip() + sChar = Character.getInstance() try: if len(text) == 0: raise ValueError("You must supply a name for the Character!") - elif text in [x.name for x in entityEditor.choices]: + elif text in [x.name for x in sChar.getCharacterList()]: raise ValueError("Character name already in use, please choose another.") return True @@ -238,8 +238,8 @@ class CharacterEditor(wx.Frame): def saveCharAs(self, event): char = self.entityEditor.getActiveEntity() - dlg = SaveCharacterAs(self, char.ID) - dlg.ShowModal() + self.SaveCharacterAs(self, char.ID) + wx.PostEvent(self, GE.CharListUpdated()) def revertChar(self, event): sChr = Character.getInstance() @@ -281,6 +281,22 @@ class CharacterEditor(wx.Frame): wx.Frame.Destroy(self) + @staticmethod + def SaveCharacterAs(parent, charID): + sChar = Character.getInstance() + name = sChar.getCharName(charID) + + dlg = TextEntryValidatedDialog(parent, CharacterTextValidor, + "Enter a name for your new Character:", + "Save Character As...") + dlg.SetValue("{} Copy".format(name)) + dlg.txtctrl.SetInsertionPointEnd() + dlg.CenterOnParent() + + if dlg.ShowModal() == wx.ID_OK: + sChar = Character.getInstance() + return sChar.saveCharacterAs(charID, dlg.txtctrl.GetValue().strip()) + class SkillTreeView(wx.Panel): def __init__(self, parent): @@ -872,36 +888,6 @@ class APIView(wx.Panel): self.stStatus.SetLabel("Unable to retrieve {}\'s skills. Error message:\n{}".format(charName, exc_obj)) -class SaveCharacterAs(wx.Dialog): - def __init__(self, parent, charID): - wx.Dialog.__init__(self, parent, title="Save Character As...", size=wx.Size(300, 60)) - self.charID = charID - self.parent = parent - sChar = Character.getInstance() - name = sChar.getCharName(charID) - bSizer1 = wx.BoxSizer(wx.HORIZONTAL) - - self.input = wx.TextCtrl(self, wx.ID_ANY, name, style=wx.TE_PROCESS_ENTER) - - bSizer1.Add(self.input, 1, wx.ALL, 5) - self.input.Bind(wx.EVT_TEXT_ENTER, self.change) - self.button = wx.Button(self, wx.ID_OK, u"Save") - bSizer1.Add(self.button, 0, wx.ALL, 5) - - self.SetSizer(bSizer1) - self.Layout() - self.Centre(wx.BOTH) - self.button.Bind(wx.EVT_BUTTON, self.change) - - def change(self, event): - sChar = Character.getInstance() - sChar.saveCharacterAs(self.charID, self.input.GetLineText(0)) - wx.PostEvent(self.parent, GE.CharListUpdated()) - - event.Skip() - self.Close() - - class SecStatusDialog(wx.Dialog): def __init__(self, parent, sec): diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 269df37e8..829450ba0 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -51,7 +51,7 @@ from gui.multiSwitch import MultiSwitch from gui.statsPane import StatsPane from gui.shipBrowser import ShipBrowser from gui.builtinShipBrowser.events import FitSelected, ImportSelected, Stage3Selected -from gui.characterEditor import CharacterEditor, SaveCharacterAs +from gui.characterEditor import CharacterEditor from gui.characterSelection import CharacterSelection from gui.patternEditor import DmgPatternEditorDlg from gui.resistsEditor import ResistsEditorDlg @@ -688,8 +688,8 @@ class MainFrame(wx.Frame, IPortUser): def saveCharAs(self, event): charID = self.charSelection.getActiveCharacter() - dlg = SaveCharacterAs(self, charID) - dlg.ShowModal() + CharacterEditor.SaveCharacterAs(self, charID) + wx.PostEvent(self, GE.CharListUpdated()) def revertChar(self, event): sChr = Character.getInstance() diff --git a/service/character.py b/service/character.py index 2075ffdaa..fba6833d8 100644 --- a/service/character.py +++ b/service/character.py @@ -253,6 +253,7 @@ class Character(object): # revert old char char.revertLevels() + return newChar.ID @staticmethod def revertCharacter(charID):