@@ -491,7 +491,7 @@ def SetUpEditor(self):
491491
492492 # Global default style
493493 if wx .Platform == '__WXMSW__' :
494- print ("DEBUG: Setup on Windows" )
494+ # print("DEBUG: Setup on Windows")
495495 self .StyleSetSpec (stc .STC_STYLE_DEFAULT ,
496496 'fore:#000000,back:#FFFFFF,face:Space Mono' ) # Courier New')
497497 elif wx .Platform == '__WXMAC__' :
@@ -584,16 +584,17 @@ class CodeEditorPanel(wx.Panel):
584584 """Panel for the 'Code Editor' tab"""
585585 def __init__ (self , parent , mainFrame , path = None ):
586586 self .log = sys .stdout # From FileDialog
587+ self .path = path
587588 wx .Panel .__init__ (self , parent , size = (1 ,1 ))
588589 self .mainFrame = mainFrame
589590 self .editor = SourceCodeEditor (self )
590591 self .editor .RegisterModifiedEvent (self .OnCodeModified )
591592
592593 self .btnSave = wx .Button (self , - 1 , "Save Changes" )
593- self .btnRestore = wx .Button (self , - 1 , "Delete Modified" )
594+ # self.btnRestore = wx.Button(self, -1, "Delete Modified")
594595 self .btnSave .Enable (False )
595596 self .btnSave .Bind (wx .EVT_BUTTON , self .OnSave )
596- self .btnRestore .Bind (wx .EVT_BUTTON , self .OnRestore )
597+ # self.btnRestore.Bind(wx.EVT_BUTTON, self.OnRestore)
597598
598599 # From FileDialog
599600 self .btnOpen = wx .Button (self , - 1 , "Open..." )
@@ -615,7 +616,7 @@ def __init__(self, parent, mainFrame, path=None):
615616 radioButton .Bind (wx .EVT_RADIOBUTTON , self .OnRadioButton )
616617
617618 self .controlBox .Add (self .btnSave , 0 , wx .RIGHT , 5 )
618- self .controlBox .Add (self .btnRestore , 0 , wx .RIGHT , 5 )
619+ # self.controlBox.Add(self.btnRestore, 0, wx.RIGHT, 5)
619620 self .controlBox .Add (self .btnOpen , 0 , wx .RIGHT , 5 )
620621 self .controlBox .Add (self .btnSaveAs , 0 )
621622
@@ -626,8 +627,9 @@ def __init__(self, parent, mainFrame, path=None):
626627
627628 self .box .Fit (self )
628629 self .SetSizer (self .box )
629- if path :
630- self .LoadFile (path )
630+ if self .path :
631+ # print("DEBUG: path is init = %s" % self.path)
632+ self .LoadFile (self .path )
631633
632634 def LoadFile (self , path ):
633635 # Open
@@ -691,19 +693,26 @@ def ReloadDemo(self):
691693 def OnCodeModified (self , event ):
692694 self .btnSave .Enable (self .editor .IsModified ())
693695
694- def OnSave (self , modifiedFilename ):
695- if os .path .isfile (modifiedFilename ):
696- overwriteMsg = "You are about to overwrite an existing file\n " + \
697- "Do you want to continue?"
698- dlg = wx .MessageDialog (self , overwriteMsg , "Editor Writer" ,
699- wx .YES_NO | wx .NO_DEFAULT | wx .ICON_EXCLAMATION )
700- result = dlg .ShowModal ()
701- if result == wx .ID_NO :
702- return
703- dlg .Destroy ()
696+ def OnSave (self , event , path = None ):
697+ if self .path is None :
698+ self .path = "noname"
699+ self .OnButton2 (event )
700+ return
701+ # print("DEBUG: OnSave path is init = %s passado %s" % (self.path, path))
702+ if path :
703+ if path != self .path and os .path .isfile (path ):
704+ overwriteMsg = "You are about to overwrite an existing file\n " + \
705+ "Do you want to continue?"
706+ dlg = wx .MessageDialog (self , overwriteMsg , "Editor Writer" ,
707+ wx .YES_NO | wx .NO_DEFAULT | wx .ICON_EXCLAMATION )
708+ result = dlg .ShowModal ()
709+ if result == wx .ID_NO :
710+ return
711+ dlg .Destroy ()
712+ self .path = path
704713
705714 # Save
706- f = open (modifiedFilename , "wb" )
715+ f = open (self . path , "wb" )
707716 source = self .editor .GetTextRaw ()
708717 # print("DEBUG: Test is Unicode %s",isUTF8Strict(source))
709718 if isUTF8Strict (source ):
@@ -723,23 +732,8 @@ def OnSave(self, modifiedFilename):
723732 f .write ('' .join (data ))
724733 finally :
725734 f .close ()
726- # idx = 0
727- # while source[idx]:
728- # try:
729- # s = bytes(source[idx:-1].encoding('UTF-8'))
730- # bsource.append(s)
731- # idx += len(s)
732- # except:
733- # print("DEBUG: index=%d" % idx)
734- # idx += 1
735- # bsource.append(source[idx])
736- # try:
737- # f.write(bsource)
738- # print("DEBUG: Saved bytes")
739- # finally:
740- # f.close()
741-
742- # busy = wx.BusyInfo("Reloading Code module...")
735+
736+ # busy = wx.BusyInfo("Reloading Code module...")
743737 # self.CodeModules.LoadFromFile(modModified, modifiedFilename)
744738 #self.ActiveModuleChanged()
745739
@@ -766,9 +760,13 @@ def OnButton(self, evt):
766760 #
767761 # Finally, if the directory is changed in the process of getting files, this
768762 # dialog is set up to change the current working directory to the path chosen.
763+ if self .path :
764+ cwd = os .path .dirname (self .path )
765+ else :
766+ cwd = os .getcwd ()
769767 dlg = wx .FileDialog (
770768 self , message = "Choose a file" ,
771- defaultDir = os . getcwd () ,
769+ defaultDir = cwd ,
772770 defaultFile = "" ,
773771 wildcard = wildcard ,
774772 style = wx .FD_OPEN |
@@ -796,6 +794,8 @@ def OnButton(self, evt):
796794 finally :
797795 f .close ()
798796
797+ # store the new path
798+ self .path = path
799799 # self.log.write('%s\n' % source)
800800 self .LoadSource (source ) # Just the last file
801801 # Compare this with the debug above; did we change working dirs?
@@ -817,9 +817,16 @@ def OnButton2(self, evt):
817817 # Unlike the 'open dialog' example found elsewhere, this example does NOT
818818 # force the current working directory to change if the user chooses a different
819819 # directory than the one initially set.
820+ fname = ""
821+ if self .path :
822+ cwd = os .path .dirname (self .path )
823+ fname = os .path .basename (self .path )
824+ else :
825+ cwd = os .getcwd ()
826+ self .path = "noname"
820827 dlg = wx .FileDialog (
821- self , message = "Save file as ..." , defaultDir = os . getcwd () ,
822- defaultFile = "" , wildcard = wildcard , style = wx .FD_SAVE
828+ self , message = "Save file as ..." , defaultDir = cwd ,
829+ defaultFile = fname , wildcard = wildcard , style = wx .FD_SAVE
823830 ) # | wx.FD_OVERWRITE_PROMPT
824831
825832 # This sets the default filter that the user will initially see. Otherwise,
@@ -846,7 +853,9 @@ def OnButton2(self, evt):
846853 #
847854 # You might want to add some error checking :-)
848855 #
849- self .OnSave (path )
856+ # store the new path
857+ # self.path = path
858+ self .OnSave (evt , path )
850859 # Note that the current working dir didn't change. This is good since
851860 # that's the way we set it up.
852861 # self.log.WriteText("CWD: %s\n" % os.getcwd())
0 commit comments