perilbrain added the comment:
"To run without saving" was the first idea I got, but it was difficult to
pursue in first phase. After your hints I think I have achieved what you have
described.
I have done a few fixes(luckily in a single file ScriptBinding.py) which are
giving satisfactory result.
I am attaching the original, modified and the diff version of files named
ScriptBindingOriginal.py, ScriptBinding.py and ScriptBinding.diff respectively.
Here is what I am getting with the new code
Traceback (most recent call last):
File "*Untitled*", line 3, in <module>
File "*Untitled*", line 2, in f
ZeroDivisionError: division by zero
This is the summary of the patch (idle-python3.4)
+import io
....
#====== One member in class for reducing annoyance ====
self.no_save = False
#====== New definition for function tabnanny======
- def tabnanny(self, filename):
+ def tabnanny(self, source):
+ f = io.StringIO(source)# , os.linesep *****Maybe*****
- with tokenize.open(filename) as f:
#====== Added 2 functions =========
def source_from_file(self, filename):
with open(filename, 'rb') as f:
source = f.read()
if b'\r' in source:
source = source.replace(b'\r\n', b'\n')
source = source.replace(b'\r', b'\n')
if source and source[-1] != ord(b'\n'):
source = source + b'\n'
return source
def source_from_editor(self):
self.editwin.io.fixlastline()
source = self.editwin.text.get("1.0", "end-1c")
return source
#====== New definition for function checksyntax======
- def checksyntax(self, filename):
+ def checksyntax(self, source, filename):
#====== Changes in function run_module_event (Main) ==========
def _run_module_event(self, event):
filename = self.getfilename()
filename = self.getfilename()
if not filename:
self.no_save = True
source = self.source_from_editor()
filename = self.editwin.top.wm_title()
else:
source = self.source_from_file(filename)
self.no_save = False
code = self.checksyntax(source, filename)
if not code:
return 'break'
if not self.tabnanny(source):
return 'break'
interp = self.shell.interp
if PyShell.use_subprocess:
interp.restart_subprocess(with_cwd=False)
if not self.no_save:
....
interp.runcode(code)
return 'break'
#====== Finally suppressing the annoyance ======
if autosave and filename:
self.editwin.io.save(None)
elif self.no_save:
filename = None
else:
confirm = self.ask_save_dialog()
Please have a review and let me know if it can solve this issue.
----------
nosy: +perilbrain
Added file: http://bugs.python.org/file45309/ScriptBinding.diff.zip
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19042>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com