This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author perilbrain
Recipients perilbrain, terry.reedy
Date 2016-11-01.17:51:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1478022689.78.0.930783075071.issue28581@psf.upfronthosting.co.za>
In-reply-to
Content
Current Flow:-
- If you create a new file in idle and try to run it, the editor asks to save the file. However if user presses cancel button the code is not executed.

Problem:-
I have been using idle for over 5 years and this behavior is quite annoying(along with paste :) !!). We are often required to copy code from various sites say some tutorial or code samples which are good for one time usage.

Solution:-
If a user presses cancel button then set a flag in IOBinding say "optedTemp", save it to a named temporary file, execute the code and close the file. If user again runs the code, check for this flag. If it is true then there is no need to ask for saving the code and again create the temporary file, execute, close. If some one needs to save this code they can use the "save as" menu which sets off the optedTemp flag.

Here is the code I propose (check for "#+++++++++++++++++++++")

==================idlelib/ScriptBinding.py===============
# At top
import tempfile  #+++++++++++++++++++++

# New definition of functions:-


    def _run_module_event(self, event):
        filename = self.getfilename()
        tempCode = None #+++++++++++++++++++++
        if not filename:            
            tempCode = tempfile.NamedTemporaryFile(suffix = ".py") #+++++++++++++++++++++
            filename = tempCode.name #****Added***
            self.editwin.io.writefile( filename ) #+++++++++++++++++++++
            self.editwin.io.optedTemp = True #+++++++++++++++++++++
            #return 'break'
        code = self.checksyntax(filename)
        ......
        interp.runcode(code)
        if tempCode is not None: #+++++++++++++++++++++
            tempCode.close() #+++++++++++++++++++++
        return 'break'

    def getfilename(self):
        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)
            elif self.editwin.io.optedTemp: #+++++++++++++++++++++
                filename = None #+++++++++++++++++++++
            else:
                confirm = self.ask_save_dialog()
                self.editwin.text.focus_set()
                if confirm:
                    self.editwin.io.save(None)
                    filename = self.editwin.io.filename
                else:
                    filename = None
        return filename

============idlelib/IOBinding.py======================

def __init__(self, editwin):
        #....
        self.__id_print = self.text.bind("<<print-window>>", self.print_window)
        self.optedTemp = False #+++++++++++++++++++++

def save_as(self, event):
        filename = self.asksavefile()
        if filename:
            if self.writefile(filename):
                self.set_filename(filename)
                self.set_saved(1)
                self.optedTemp = False #+++++++++++++++++++++
                try:
                    self.editwin.store_file_breaks()
                except AttributeError:
                    ....
History
Date User Action Args
2016-11-01 17:51:29perilbrainsetrecipients: + perilbrain, terry.reedy
2016-11-01 17:51:29perilbrainsetmessageid: <1478022689.78.0.930783075071.issue28581@psf.upfronthosting.co.za>
2016-11-01 17:51:29perilbrainlinkissue28581 messages
2016-11-01 17:51:28perilbraincreate