Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/ScriptBinding.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 1b5abba0c808 |
| children | aa1350c7d196 |
| rev | line source |
|---|---|
| 13975 | 1 """Extension to execute code outside the Python shell window. |
| 2 | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
23547
diff
changeset
|
3 This adds the following commands: |
| 13975 | 4 |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
23547
diff
changeset
|
5 - Check module does a full syntax check of the current module. |
| 26693 | 6 It also runs the tabnanny to catch any inconsistent tabs. |
| 13975 | 7 |
| 25123 | 8 - Run module executes the module's code in the __main__ namespace. The window |
| 26693 | 9 must have been saved previously. The module is added to sys.modules, and is |
| 10 also added to the __main__ namespace. | |
| 13975 | 11 |
| 26693 | 12 XXX GvR Redesign this interface (yet again) as follows: |
| 23547 | 13 |
| 27390 | 14 - Present a dialog box for ``Run Module'' |
| 23547 | 15 |
| 16 - Allow specify command line arguments in the dialog box | |
| 17 | |
| 13975 | 18 """ |
| 19 | |
| 29346 | 20 import os |
| 26693 | 21 import re |
| 22 import string | |
| 23 import tabnanny | |
| 24 import tokenize | |
|
47183
b53604fad54b
Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents:
47101
diff
changeset
|
25 import tkMessageBox |
|
60144
eab361617f6a
#7092: Fix additional "-3" warnings in the idlelib package, and convert to absolute imports.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47183
diff
changeset
|
26 from idlelib import PyShell |
| 13975 | 27 |
|
60144
eab361617f6a
#7092: Fix additional "-3" warnings in the idlelib package, and convert to absolute imports.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47183
diff
changeset
|
28 from idlelib.configHandler import idleConf |
|
70177
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
29 from idlelib import macosxSupport |
| 29266 | 30 |
| 26693 | 31 IDENTCHARS = string.ascii_letters + string.digits + "_" |
| 32 | |
| 13975 | 33 indent_message = """Error: Inconsistent indentation detected! |
| 34 | |
|
35065
aa1c5366607d
1. Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
35 1) Your indentation is outright incorrect (easy to fix), OR |
| 13975 | 36 |
|
35065
aa1c5366607d
1. Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
37 2) Your indentation mixes tabs and spaces. |
| 13975 | 38 |
|
35065
aa1c5366607d
1. Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
39 To fix case 2, change all tabs to spaces by using Edit->Select All followed \ |
|
aa1c5366607d
1. Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
40 by Format->Untabify Region and specify the number of columns used by each tab. |
|
aa1c5366607d
1. Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
41 """ |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
23547
diff
changeset
|
42 |
| 13975 | 43 class ScriptBinding: |
|
18497
42741e677338
py-cvs merge, better error dialog
Steven M. Gava <elguavas@python.net>
parents:
13975
diff
changeset
|
44 |
| 13975 | 45 menudefs = [ |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
23547
diff
changeset
|
46 ('run', [None, |
| 26693 | 47 ('Check Module', '<<check-module>>'), |
| 27390 | 48 ('Run Module', '<<run-module>>'), ]), ] |
| 13975 | 49 |
| 50 def __init__(self, editwin): | |
| 51 self.editwin = editwin | |
| 52 # Provide instance variables referenced by Debugger | |
| 53 # XXX This should be done differently | |
| 54 self.flist = self.editwin.flist | |
|
39165
0c00e2f509e0
- EditorWindow.test() was failing. Bug 1417598
Kurt B. Kaiser <kbk@shore.net>
parents:
35384
diff
changeset
|
55 self.root = self.editwin.root |
| 13975 | 56 |
|
70177
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
57 if macosxSupport.runningAsOSXApp(): |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
58 self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event) |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
59 |
|
35384
34ff7ca4cef8
Revert previous code elimination, 'filename' is needed.
Kurt B. Kaiser <kbk@shore.net>
parents:
35383
diff
changeset
|
60 def check_module_event(self, event): |
| 13975 | 61 filename = self.getfilename() |
| 62 if not filename: | |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
63 return 'break' |
|
39945
257daf39b08c
Some syntax errors were being caught by tokenize during the tabnanny
Kurt B. Kaiser <kbk@shore.net>
parents:
39424
diff
changeset
|
64 if not self.checksyntax(filename): |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
65 return 'break' |
| 13975 | 66 if not self.tabnanny(filename): |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
67 return 'break' |
| 13975 | 68 |
| 69 def tabnanny(self, filename): | |
| 70 f = open(filename, 'r') | |
| 71 try: | |
| 25312 | 72 tabnanny.process_tokens(tokenize.generate_tokens(f.readline)) |
| 13975 | 73 except tokenize.TokenError, msg: |
|
29363
c66100c09ea1
SF 747667 Error Doesn't Decolorize
Kurt B. Kaiser <kbk@shore.net>
parents:
29346
diff
changeset
|
74 msgtxt, (lineno, start) = msg |
|
c66100c09ea1
SF 747667 Error Doesn't Decolorize
Kurt B. Kaiser <kbk@shore.net>
parents:
29346
diff
changeset
|
75 self.editwin.gotoline(lineno) |
|
c66100c09ea1
SF 747667 Error Doesn't Decolorize
Kurt B. Kaiser <kbk@shore.net>
parents:
29346
diff
changeset
|
76 self.errorbox("Tabnanny Tokenizing Error", |
|
c66100c09ea1
SF 747667 Error Doesn't Decolorize
Kurt B. Kaiser <kbk@shore.net>
parents:
29346
diff
changeset
|
77 "Token Error: %s" % msgtxt) |
| 26475 | 78 return False |
| 13975 | 79 except tabnanny.NannyNag, nag: |
| 80 # The error messages from tabnanny are too confusing... | |
| 81 self.editwin.gotoline(nag.get_lineno()) | |
| 82 self.errorbox("Tab/space error", indent_message) | |
| 26475 | 83 return False |
| 84 return True | |
| 13975 | 85 |
| 86 def checksyntax(self, filename): | |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
87 self.shell = shell = self.flist.open_shell() |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
88 saved_stream = shell.get_warning_stream() |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
89 shell.set_warning_stream(shell.stderr) |
| 13975 | 90 f = open(filename, 'r') |
| 91 source = f.read() | |
| 92 f.close() | |
| 93 if '\r' in source: | |
| 94 source = re.sub(r"\r\n", "\n", source) | |
|
35383
04dd5b06d3c8
1. Mac line endings were incorrect when pasting code from some browsers
Kurt B. Kaiser <kbk@shore.net>
parents:
35065
diff
changeset
|
95 source = re.sub(r"\r", "\n", source) |
| 13975 | 96 if source and source[-1] != '\n': |
| 97 source = source + '\n' | |
|
29363
c66100c09ea1
SF 747667 Error Doesn't Decolorize
Kurt B. Kaiser <kbk@shore.net>
parents:
29346
diff
changeset
|
98 text = self.editwin.text |
|
c66100c09ea1
SF 747667 Error Doesn't Decolorize
Kurt B. Kaiser <kbk@shore.net>
parents:
29346
diff
changeset
|
99 text.tag_remove("ERROR", "1.0", "end") |
| 13975 | 100 try: |
| 101 try: | |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
102 # If successful, return the compiled code |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
103 return compile(source, filename, "exec") |
|
73583
e277fe8380e0
Issue #8793: Prevent IDLE crash in 2.7 when given strings with
Ned Deily <nad@acm.org>
parents:
70177
diff
changeset
|
104 except (SyntaxError, OverflowError, ValueError), err: |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
105 try: |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
106 msg, (errorfilename, lineno, offset, line) = err |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
107 if not errorfilename: |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
108 err.args = msg, (filename, lineno, offset, line) |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
109 err.filename = filename |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
110 self.colorize_syntax_error(msg, lineno, offset) |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
111 except: |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
112 msg = "*** " + str(err) |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
113 self.errorbox("Syntax error", |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
114 "There's an error in your program:\n" + msg) |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
115 return False |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
116 finally: |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
117 shell.set_warning_stream(saved_stream) |
| 26959 | 118 |
| 26693 | 119 def colorize_syntax_error(self, msg, lineno, offset): |
| 120 text = self.editwin.text | |
| 121 pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) | |
| 122 text.tag_add("ERROR", pos) | |
| 123 char = text.get(pos) | |
| 124 if char and char in IDENTCHARS: | |
| 125 text.tag_add("ERROR", pos + " wordstart", pos) | |
| 126 if '\n' == text.get(pos): # error at line end | |
| 127 text.mark_set("insert", pos) | |
| 128 else: | |
| 129 text.mark_set("insert", pos + "+1c") | |
| 130 text.see(pos) | |
| 26959 | 131 |
| 27390 | 132 def run_module_event(self, event): |
| 29346 | 133 """Run the module after setting up the environment. |
| 134 | |
| 135 First check the syntax. If OK, make sure the shell is active and | |
| 136 then transfer the arguments, set the run environment's working | |
| 137 directory to the directory of the module being executed and also | |
| 138 add that directory to its sys.path if not already included. | |
| 139 | |
| 140 """ | |
|
35384
34ff7ca4cef8
Revert previous code elimination, 'filename' is needed.
Kurt B. Kaiser <kbk@shore.net>
parents:
35383
diff
changeset
|
141 filename = self.getfilename() |
|
34ff7ca4cef8
Revert previous code elimination, 'filename' is needed.
Kurt B. Kaiser <kbk@shore.net>
parents:
35383
diff
changeset
|
142 if not filename: |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
143 return 'break' |
|
35384
34ff7ca4cef8
Revert previous code elimination, 'filename' is needed.
Kurt B. Kaiser <kbk@shore.net>
parents:
35383
diff
changeset
|
144 code = self.checksyntax(filename) |
| 26693 | 145 if not code: |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
146 return 'break' |
|
39945
257daf39b08c
Some syntax errors were being caught by tokenize during the tabnanny
Kurt B. Kaiser <kbk@shore.net>
parents:
39424
diff
changeset
|
147 if not self.tabnanny(filename): |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
148 return 'break' |
|
74692
1b5abba0c808
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73583
diff
changeset
|
149 interp = self.shell.interp |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
27920
diff
changeset
|
150 if PyShell.use_subprocess: |
|
74692
1b5abba0c808
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73583
diff
changeset
|
151 interp.restart_subprocess(with_cwd=False) |
| 29346 | 152 dirname = os.path.dirname(filename) |
| 23547 | 153 # XXX Too often this discards arguments the user just set... |
| 154 interp.runcommand("""if 1: | |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31412
diff
changeset
|
155 _filename = %r |
| 23547 | 156 import sys as _sys |
| 157 from os.path import basename as _basename | |
| 158 if (not _sys.argv or | |
| 159 _basename(_sys.argv[0]) != _basename(_filename)): | |
| 160 _sys.argv = [_filename] | |
| 29346 | 161 import os as _os |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31412
diff
changeset
|
162 _os.chdir(%r) |
| 29346 | 163 del _filename, _sys, _basename, _os |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31412
diff
changeset
|
164 \n""" % (filename, dirname)) |
|
29122
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29119
diff
changeset
|
165 interp.prepend_syspath(filename) |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
166 # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
167 # go to __stderr__. With subprocess, they go to the shell. |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
168 # Need to change streams in PyShell.ModifiedInterpreter. |
| 26693 | 169 interp.runcode(code) |
|
45366
d8f12bae378a
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
Kurt B. Kaiser <kbk@shore.net>
parents:
39945
diff
changeset
|
170 return 'break' |
| 13975 | 171 |
|
70177
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
172 if macosxSupport.runningAsOSXApp(): |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
173 # Tk-Cocoa in MacOSX is broken until at least |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
174 # Tk 8.5.9, and without this rather |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
175 # crude workaround IDLE would hang when a user |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
176 # tries to run a module using the keyboard shortcut |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
177 # (the menu item works fine). |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
178 _run_module_event = run_module_event |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
179 |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
180 def run_module_event(self, event): |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
181 self.editwin.text_frame.after(200, |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
182 lambda: self.editwin.text_frame.event_generate('<<run-module-event-2>>')) |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
183 return 'break' |
|
578020fe2875
(backport) Fixes #11088: IDLE crashes when using F5 to run a script on OSX with Tk 8.5
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
70061
diff
changeset
|
184 |
| 13975 | 185 def getfilename(self): |
|
26713
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
186 """Get source filename. If not saved, offer to save (or create) file |
|
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
187 |
|
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
188 The debugger requires a source file. Make sure there is one, and that |
|
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
189 the current version of the source buffer has been saved. If the user |
|
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
190 declines to save or cancels the Save As dialog, return None. |
| 29266 | 191 |
| 192 If the user has configured IDLE for Autosave, the file will be | |
| 193 silently saved if it already exists and is dirty. | |
| 29271 | 194 |
|
26713
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
195 """ |
| 29266 | 196 filename = self.editwin.io.filename |
| 13975 | 197 if not self.editwin.get_saved(): |
| 29266 | 198 autosave = idleConf.GetOption('main', 'General', |
| 199 'autosave', type='bool') | |
| 200 if autosave and filename: | |
|
26713
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
201 self.editwin.io.save(None) |
|
eab6d7c80341
If Edit window has not been saved, offer to save if user tries to Run or
Kurt B. Kaiser <kbk@shore.net>
parents:
26693
diff
changeset
|
202 else: |
|
70061
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
203 confirm = self.ask_save_dialog() |
| 29266 | 204 self.editwin.text.focus_set() |
|
70061
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
205 if confirm: |
| 29266 | 206 self.editwin.io.save(None) |
| 207 filename = self.editwin.io.filename | |
| 208 else: | |
| 209 filename = None | |
| 13975 | 210 return filename |
| 211 | |
| 29266 | 212 def ask_save_dialog(self): |
| 213 msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?" | |
|
70061
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
214 confirm = tkMessageBox.askokcancel(title="Save Before Run or Check", |
|
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
215 message=msg, |
|
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
216 default=tkMessageBox.OK, |
|
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
217 master=self.editwin.text) |
|
ac14158462cf
Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
Kurt B. Kaiser <kbk@shore.net>
parents:
60144
diff
changeset
|
218 return confirm |
| 29266 | 219 |
| 13975 | 220 def errorbox(self, title, message): |
| 221 # XXX This should really be a function of EditorWindow... | |
| 222 tkMessageBox.showerror(title, message, master=self.editwin.text) | |
| 223 self.editwin.text.focus_set() |
