[Idle-dev] CVS: idle ScriptBinding.py,1.21,1.22 config-main.def,1.15,1.16 configDialog.py,1.52,1.53

Kurt B. Kaiser kbk@users.sourceforge.net
Sun, 25 May 2003 23:23:12 -0700


Update of /cvsroot/idlefork/idle
In directory sc8-pr-cvs1:/tmp/cvs-serv2756

Modified Files:
	ScriptBinding.py config-main.def configDialog.py 
Log Message:
Bruce Sherwood RFE/Patch
SF 661318

Adds autosave capability to IDLE and IDLE configuration dialog.

User can Run/F5 without explicit save dialog.

The default is to require the user to confirm the save.

M ScriptBinding.py
M config-main.def
M configDialog.py


Index: ScriptBinding.py
===================================================================
RCS file: /cvsroot/idlefork/idle/ScriptBinding.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** ScriptBinding.py	24 May 2003 20:59:15 -0000	1.21
--- ScriptBinding.py	26 May 2003 06:23:10 -0000	1.22
***************
*** 25,28 ****
--- 25,30 ----
  import PyShell
  
+ from configHandler import idleConf
+ 
  IDENTCHARS = string.ascii_letters + string.digits + "_"
  
***************
*** 145,168 ****
          the current version of the source buffer has been saved.  If the user
          declines to save or cancels the Save As dialog, return None.
          """
          if not self.editwin.get_saved():
!             msg = """Source Must Be Saved
!      OK to Save?"""
!             mb = tkMessageBox.Message(
!                                 title="Save Before Run or Check",
!                                 message=msg,
!                                 icon=tkMessageBox.QUESTION,
!                                 type=tkMessageBox.OKCANCEL,
!                                 default=tkMessageBox.OK,
!                                 master=self.editwin.text)
!             reply = mb.show()
!             if reply == "ok":
                  self.editwin.io.save(None)
              else:
!                 return None
!         # filename is None if file doesn't exist
!         filename = self.editwin.io.filename
!         self.editwin.text.focus_set()
          return filename
  
      def errorbox(self, title, message):
--- 147,180 ----
          the current version of the source buffer has been saved.  If the user
          declines to save or cancels the Save As dialog, return None.
+ 
+         If the user has configured IDLE for Autosave, the file will be
+         silently saved if it already exists and is dirty.
+         
          """
+         filename = self.editwin.io.filename
          if not self.editwin.get_saved():
!             autosave = idleConf.GetOption('main', 'General',
!                                           'autosave', type='bool')
!             if autosave and filename:
                  self.editwin.io.save(None)
              else:
!                 reply = self.ask_save_dialog()
!                 self.editwin.text.focus_set()
!                 if reply == "ok":
!                     self.editwin.io.save(None)
!                     filename = self.editwin.io.filename
!                 else:
!                     filename = None
          return filename
+ 
+     def ask_save_dialog(self):
+         msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?"
+         mb = tkMessageBox.Message(title="Save Before Run or Check",
+                                   message=msg,
+                                   icon=tkMessageBox.QUESTION,
+                                   type=tkMessageBox.OKCANCEL,
+                                   default=tkMessageBox.OK,
+                                   master=self.editwin.text)
+         return mb.show()
  
      def errorbox(self, title, message):

Index: config-main.def
===================================================================
RCS file: /cvsroot/idlefork/idle/config-main.def,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** config-main.def	18 May 2003 02:21:55 -0000	1.15
--- config-main.def	26 May 2003 06:23:10 -0000	1.16
***************
*** 41,44 ****
--- 41,45 ----
  [General]
  editor-on-startup= 0
+ autosave= 0
  print-command-posix=lpr %s
  print-command-win=start /min notepad /p %s
***************
*** 50,54 ****
  font-size= 12
  font-bold= 0
! encoding=none
  
  [Indent]
--- 51,55 ----
  font-size= 12
  font-bold= 0
! encoding= none
  
  [Indent]

Index: configDialog.py
===================================================================
RCS file: /cvsroot/idlefork/idle/configDialog.py,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -r1.52 -r1.53
*** configDialog.py	10 May 2003 00:49:56 -0000	1.52
--- configDialog.py	26 May 2003 06:23:10 -0000	1.53
***************
*** 335,338 ****
--- 335,339 ----
          self.winHeight=StringVar(self)
          self.startupEdit=IntVar(self)
+         self.autoSave=IntVar(self)
          self.encoding=StringVar(self)
          self.userHelpBrowser=BooleanVar(self)
***************
*** 343,346 ****
--- 344,348 ----
          #body section frames
          frameRun=Frame(frame,borderwidth=2,relief=GROOVE)
+         frameSave=Frame(frame,borderwidth=2,relief=GROOVE)
          frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE)
          frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE)
***************
*** 348,356 ****
          #frameRun
          labelRunTitle=Label(frameRun,text='Startup Preferences')
!         labelRunChoiceTitle=Label(frameRun,text='On Startup : ')
          radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
              value=1,command=self.SetKeysType,text="Open Edit Window")
          radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
              value=0,command=self.SetKeysType,text='Open Shell Window')
          #frameWinSize
          labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+
--- 350,365 ----
          #frameRun
          labelRunTitle=Label(frameRun,text='Startup Preferences')
!         labelRunChoiceTitle=Label(frameRun,text='At Startup')
          radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
              value=1,command=self.SetKeysType,text="Open Edit Window")
          radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
              value=0,command=self.SetKeysType,text='Open Shell Window')
+         #frameSave
+         labelSaveTitle=Label(frameSave,text='Autosave Preference')
+         labelRunSaveTitle=Label(frameSave,text='At Start of Run (F5)  ')
+         radioSaveAsk=Radiobutton(frameSave,variable=self.autoSave,
+             value=0,command=self.SetKeysType,text="Prompt to Save")
+         radioSaveAuto=Radiobutton(frameSave,variable=self.autoSave,
+             value=1,command=self.SetKeysType,text='No Prompt')
          #frameWinSize
          labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+
***************
*** 371,375 ****
              value="none",text="None")
          #frameHelp
!         labelHelpTitle=Label(frameHelp,text='Help Options')
          frameHelpList=Frame(frameHelp)
          frameHelpListButtons=Frame(frameHelpList)
--- 380,384 ----
              value="none",text="None")
          #frameHelp
!         ##labelHelpTitle=Label(frameHelp,text='Help Options')
          frameHelpList=Frame(frameHelp)
          frameHelpListButtons=Frame(frameHelpList)
***************
*** 397,408 ****
          #body
          frameRun.pack(side=TOP,padx=5,pady=5,fill=X)
          frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X)
! 	frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X)
          frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
          #frameRun
          labelRunTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
          labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
!         radioStartupEdit.pack(side=LEFT,anchor=W,padx=5,pady=5)
!         radioStartupShell.pack(side=LEFT,anchor=W,padx=5,pady=5)
          #frameWinSize
          labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
--- 406,423 ----
          #body
          frameRun.pack(side=TOP,padx=5,pady=5,fill=X)
+         frameSave.pack(side=TOP,padx=5,pady=5,fill=X)
          frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X)
!         frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X)
          frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
          #frameRun
          labelRunTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
          labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
!         radioStartupShell.pack(side=RIGHT,anchor=W,padx=5,pady=5)
!         radioStartupEdit.pack(side=RIGHT,anchor=W,padx=5,pady=5)
!         #frameSave
!         labelSaveTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
!         labelRunSaveTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
!         radioSaveAuto.pack(side=RIGHT,anchor=W,padx=5,pady=5)
!         radioSaveAsk.pack(side=RIGHT,anchor=W,padx=5,pady=5)
          #frameWinSize
          labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
***************
*** 417,421 ****
          radioEncLocale.pack(side=RIGHT,anchor=E,pady=5)
          #frameHelp
!         labelHelpTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
          frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y)
          frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
--- 432,436 ----
          radioEncLocale.pack(side=RIGHT,anchor=E,pady=5)
          #frameHelp
!         ##labelHelpTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
          frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y)
          frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
***************
*** 449,452 ****
--- 464,468 ----
          self.winHeight.trace_variable('w',self.VarChanged_winHeight)
          self.startupEdit.trace_variable('w',self.VarChanged_startupEdit)
+         self.autoSave.trace_variable('w',self.VarChanged_autoSave)
          self.encoding.trace_variable('w',self.VarChanged_encoding)
  
***************
*** 543,546 ****
--- 559,566 ----
          self.AddChangedItem('main','General','editor-on-startup',value)
  
+     def VarChanged_autoSave(self,*params):
+         value=self.autoSave.get()
+         self.AddChangedItem('main','General','autosave',value)
+ 
      def VarChanged_encoding(self,*params):
          value=self.encoding.get()
***************
*** 1039,1047 ****
          self.startupEdit.set(idleConf.GetOption('main','General',
                  'editor-on-startup',default=1,type='bool'))
          #initial window size
          self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
          self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
          # default source encoding
!         self.encoding.set(idleConf.GetOption('main','EditorWindow','encoding'))
          # additional help sources
          self.userHelpList = idleConf.GetAllExtraHelpSourcesList()
--- 1059,1071 ----
          self.startupEdit.set(idleConf.GetOption('main','General',
                  'editor-on-startup',default=1,type='bool'))
+         #autosave state
+         self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave',
+                                              default=0, type='bool'))
          #initial window size
          self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
          self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
          # default source encoding
!         self.encoding.set(idleConf.GetOption('main', 'EditorWindow',
!                                              'encoding', default='none'))
          # additional help sources
          self.userHelpList = idleConf.GetAllExtraHelpSourcesList()