Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running code without explicitly saving the file. #72767

Closed
perilbrain mannequin opened this issue Nov 1, 2016 · 4 comments
Closed

Allow running code without explicitly saving the file. #72767

perilbrain mannequin opened this issue Nov 1, 2016 · 4 comments
Assignees
Labels
3.7 (EOL) end of life topic-IDLE type-feature A feature request or enhancement

Comments

@perilbrain
Copy link
Mannequin

perilbrain mannequin commented Nov 1, 2016

BPO 28581
Nosy @terryjreedy
Superseder
  • bpo-19042: Idle: run from editor without explicit save
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2016-11-02.04:29:08.032>
    created_at = <Date 2016-11-01.17:51:29.736>
    labels = ['expert-IDLE', 'type-feature', '3.7']
    title = 'Allow running code without explicitly saving the file.'
    updated_at = <Date 2016-11-02.05:18:42.072>
    user = 'https://bugs.python.org/perilbrain'

    bugs.python.org fields:

    activity = <Date 2016-11-02.05:18:42.072>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2016-11-02.04:29:08.032>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2016-11-01.17:51:29.736>
    creator = 'perilbrain'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 28581
    keywords = []
    message_count = 4.0
    messages = ['279885', '279896', '279897', '279899']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'perilbrain']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '19042'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue28581'
    versions = ['Python 3.6', 'Python 3.7']

    @perilbrain
    Copy link
    Mannequin Author

    perilbrain mannequin commented Nov 1, 2016

    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:
                        ....

    @perilbrain perilbrain mannequin assigned terryjreedy Nov 1, 2016
    @perilbrain perilbrain mannequin added topic-IDLE type-feature A feature request or enhancement labels Nov 1, 2016
    @terryjreedy
    Copy link
    Member

    I agree that this is a problem that needs a solution. Your post gives the justification very well. I already opened bpo-19042 for this issue, so as is our usual policy, I am merging this duplicate into that one.

    Thank you for submitting a patch. To apply it, we need a Contributor Agreement. One can be signed electronically. See https://www.python.org/psf/contrib/. An '*' will appear after your name once a CA has been received and registered. I will take a good look once this happens.

    I the meanwhile, I will add a reference to this issue and patch, as well as additional comments, to bpo-19042.

    @terryjreedy terryjreedy added the 3.7 (EOL) end of life label Nov 2, 2016
    @perilbrain
    Copy link
    Mannequin Author

    perilbrain mannequin commented Nov 2, 2016

    Thanks Terry, I tried searching for a similar issue but failed.

    Feels like signing contributor form will take a while.
    Meantime please feel free to tweak/improve and implement code in your way (Mine is a bit rough solution not even abiding by naming convention), if this is some licensing issue.

    @terryjreedy
    Copy link
    Member

    In my additional comment, I explored the idea of running without saving, not even to a temp file.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life topic-IDLE type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant