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
Comments
Current Flow:-
Problem:- Solution:- 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:
.... |
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. |
Thanks Terry, I tried searching for a similar issue but failed. Feels like signing contributor form will take a while. |
In my additional comment, I explored the idea of running without saving, not even to a temp file. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: