Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/PyShell.py @ 75847:cdcd1f7f0882
Merge from 3.2 for issue #3573, fix Misc/NEWS as Ned Deily guess.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Wed, 21 Mar 2012 13:31:12 +0200 |
| parents | 01404295138d a95b19b3b4cd |
| children | 89878808f4ce |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
55642
diff
changeset
|
1 #! /usr/bin/env python3 |
| 13975 | 2 |
|
72173
fe7777f1ed14
Issue #12636: IDLE reads the coding cookie when executing a Python script.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72172
diff
changeset
|
3 import getopt |
| 13975 | 4 import os |
| 26468 | 5 import os.path |
| 13975 | 6 import re |
| 23547 | 7 import socket |
|
72173
fe7777f1ed14
Issue #12636: IDLE reads the coding cookie when executing a Python script.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72172
diff
changeset
|
8 import subprocess |
|
fe7777f1ed14
Issue #12636: IDLE reads the coding cookie when executing a Python script.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72172
diff
changeset
|
9 import sys |
|
fe7777f1ed14
Issue #12636: IDLE reads the coding cookie when executing a Python script.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72172
diff
changeset
|
10 import threading |
| 23547 | 11 import time |
|
72173
fe7777f1ed14
Issue #12636: IDLE reads the coding cookie when executing a Python script.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72172
diff
changeset
|
12 import tokenize |
| 25322 | 13 import traceback |
| 14 import types | |
| 13975 | 15 |
| 16 import linecache | |
| 17 from code import InteractiveInterpreter | |
| 18 | |
|
31013
270d59e346e6
Keybindings with the Shift modifier now work correctly. So do bindings
Kurt B. Kaiser <kbk@shore.net>
parents:
30142
diff
changeset
|
19 try: |
|
47130
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
46978
diff
changeset
|
20 from tkinter import * |
|
31013
270d59e346e6
Keybindings with the Shift modifier now work correctly. So do bindings
Kurt B. Kaiser <kbk@shore.net>
parents:
30142
diff
changeset
|
21 except ImportError: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
22 print("** IDLE can't import Tkinter. " \ |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
23 "Your Python may not be configured for Tk. **", file=sys.__stderr__) |
|
31013
270d59e346e6
Keybindings with the Shift modifier now work correctly. So do bindings
Kurt B. Kaiser <kbk@shore.net>
parents:
30142
diff
changeset
|
24 sys.exit(1) |
|
47130
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
46978
diff
changeset
|
25 import tkinter.messagebox as tkMessageBox |
| 13975 | 26 |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
27 from idlelib.EditorWindow import EditorWindow, fixwordbreaks |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
28 from idlelib.FileList import FileList |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
29 from idlelib.ColorDelegator import ColorDelegator |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
30 from idlelib.UndoDelegator import UndoDelegator |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
31 from idlelib.OutputWindow import OutputWindow |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
32 from idlelib.configHandler import idleConf |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
33 from idlelib import idlever |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
34 from idlelib import rpc |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
35 from idlelib import Debugger |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
36 from idlelib import RemoteDebugger |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
37 from idlelib import macosxSupport |
| 23547 | 38 |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
39 HOST = '127.0.0.1' # python execution server on localhost loopback |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
40 PORT = 0 # someday pass in host, port for remote debug capability |
|
25346
6dec74f44242
Fix bug I created during merge from Python-idle.
Kurt B. Kaiser <kbk@shore.net>
parents:
25322
diff
changeset
|
41 |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
42 # Override warnings module to write to warning_stream. Initialize to send IDLE |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
43 # internal warnings to the console. ScriptBinding.check_syntax() will |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
44 # temporarily redirect the stream to the shell window to display warnings when |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
45 # checking user's code. |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
46 global warning_stream |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
47 warning_stream = sys.__stderr__ |
| 23547 | 48 try: |
| 49 import warnings | |
| 50 except ImportError: | |
| 51 pass | |
| 52 else: | |
|
49553
3ff7bb830519
Merged revisions 66887,66891,66902-66903,66905-66906,66911-66913,66922,66927-66928,66936,66939-66940,66962,66964,66973 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47130
diff
changeset
|
53 def idle_showwarning(message, category, filename, lineno, |
|
3ff7bb830519
Merged revisions 66887,66891,66902-66903,66905-66906,66911-66913,66922,66927-66928,66936,66939-66940,66962,66964,66973 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47130
diff
changeset
|
54 file=None, line=None): |
|
55642
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
55 if file is None: |
|
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
56 file = warning_stream |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
57 try: |
|
55642
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
58 file.write(warnings.formatwarning(message, category, filename, |
|
71171
e9c406a53972
Fix closes issue12438 - idlelib.PyShell's showformatwarning method was passing an incorrect arg.
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
59 lineno, line=line)) |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
60 except IOError: |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
61 pass ## file (probably __stderr__) is invalid, warning dropped. |
| 23547 | 62 warnings.showwarning = idle_showwarning |
|
55642
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
63 def idle_formatwarning(message, category, filename, lineno, line=None): |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
64 """Format warnings the IDLE way""" |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
65 s = "\nWarning (from warnings module):\n" |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
66 s += ' File \"%s\", line %s\n' % (filename, lineno) |
|
55642
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
67 if line is None: |
|
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
68 line = linecache.getline(filename, lineno) |
|
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
69 line = line.strip() |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
70 if line: |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
71 s += " %s\n" % line |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
72 s += "%s: %s\n>>> " % (category.__name__, message) |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
73 return s |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
74 warnings.formatwarning = idle_formatwarning |
| 23547 | 75 |
|
33989
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
76 def extended_linecache_checkcache(filename=None, |
|
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
77 orig_checkcache=linecache.checkcache): |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
78 """Extend linecache.checkcache to preserve the <pyshell#...> entries |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
79 |
|
33989
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
80 Rather than repeating the linecache code, patch it to save the |
|
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
81 <pyshell#...> entries, call the original linecache.checkcache() |
|
55642
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
82 (skipping them), and then restore the saved entries. |
|
33989
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
83 |
|
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
84 orig_checkcache is bound at definition time to the original |
|
4f2bbd471a21
The change in the linecache.checkcache() signature at rev 1.13 caused IDLE to exit
Kurt B. Kaiser <kbk@shore.net>
parents:
33218
diff
changeset
|
85 method, allowing it to be patched. |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
86 """ |
| 13975 | 87 cache = linecache.cache |
| 88 save = {} | |
|
55642
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
89 for key in list(cache): |
|
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
90 if key[:1] + key[-1:] == '<>': |
|
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
91 save[key] = cache.pop(key) |
|
e4a83e91521a
Merged revisions 74446-74449 via svnmerge from
Guilherme Polo <ggpolo@gmail.com>
parents:
52849
diff
changeset
|
92 orig_checkcache(filename) |
| 13975 | 93 cache.update(save) |
| 26959 | 94 |
|
26463
c88f6fff1c3f
Correct an error introduced at Rev 1.30. The keyword arg is necessary
Kurt B. Kaiser <kbk@shore.net>
parents:
26028
diff
changeset
|
95 # Patch linecache.checkcache(): |
|
c88f6fff1c3f
Correct an error introduced at Rev 1.30. The keyword arg is necessary
Kurt B. Kaiser <kbk@shore.net>
parents:
26028
diff
changeset
|
96 linecache.checkcache = extended_linecache_checkcache |
| 13975 | 97 |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
98 |
| 13975 | 99 class PyShellEditorWindow(EditorWindow): |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
32512
diff
changeset
|
100 "Regular text edit window in IDLE, supports breakpoints" |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
101 |
| 13975 | 102 def __init__(self, *args): |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
103 self.breakpoints = [] |
|
29794
94e5d1b8f696
SF patch #768187: replace apply(f, args, kwds) with f(*args, **kwds)
Raymond Hettinger <python@rcn.com>
parents:
29788
diff
changeset
|
104 EditorWindow.__init__(self, *args) |
| 13975 | 105 self.text.bind("<<set-breakpoint-here>>", self.set_breakpoint_here) |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
106 self.text.bind("<<clear-breakpoint-here>>", self.clear_breakpoint_here) |
| 13975 | 107 self.text.bind("<<open-python-shell>>", self.flist.open_shell) |
| 108 | |
| 26659 | 109 self.breakpointPath = os.path.join(idleConf.GetUserCfgDir(), |
| 110 'breakpoints.lst') | |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
111 # whenever a file is changed, restore breakpoints |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
112 if self.io.filename: self.restore_file_breaks() |
| 26659 | 113 def filename_changed_hook(old_hook=self.io.filename_change_hook, |
| 114 self=self): | |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
115 self.restore_file_breaks() |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
116 old_hook() |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
117 self.io.set_filename_change_hook(filename_changed_hook) |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
118 |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
119 rmenu_specs = [("Set Breakpoint", "<<set-breakpoint-here>>"), |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
120 ("Clear Breakpoint", "<<clear-breakpoint-here>>")] |
| 13975 | 121 |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
122 def set_breakpoint(self, lineno): |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
123 text = self.text |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
124 filename = self.io.filename |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
125 text.tag_add("BREAK", "%d.0" % lineno, "%d.0" % (lineno+1)) |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
126 try: |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
127 i = self.breakpoints.index(lineno) |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
128 except ValueError: # only add if missing, i.e. do once |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
129 self.breakpoints.append(lineno) |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
130 try: # update the subprocess debugger |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
131 debug = self.flist.pyshell.interp.debugger |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
132 debug.set_breakpoint_here(filename, lineno) |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
133 except: # but debugger may not be active right now.... |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
134 pass |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
135 |
| 13975 | 136 def set_breakpoint_here(self, event=None): |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
137 text = self.text |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
138 filename = self.io.filename |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
139 if not filename: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
140 text.bell() |
| 13975 | 141 return |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
142 lineno = int(float(text.index("insert"))) |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
143 self.set_breakpoint(lineno) |
| 13975 | 144 |
|
23932
eab8eca9ec51
1. Debugger Breakpoints, finish implementation
Kurt B. Kaiser <kbk@shore.net>
parents:
23876
diff
changeset
|
145 def clear_breakpoint_here(self, event=None): |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
146 text = self.text |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
147 filename = self.io.filename |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
148 if not filename: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
149 text.bell() |
|
23932
eab8eca9ec51
1. Debugger Breakpoints, finish implementation
Kurt B. Kaiser <kbk@shore.net>
parents:
23876
diff
changeset
|
150 return |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
151 lineno = int(float(text.index("insert"))) |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
152 try: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
153 self.breakpoints.remove(lineno) |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
154 except: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
155 pass |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
156 text.tag_remove("BREAK", "insert linestart",\ |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
157 "insert lineend +1char") |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
158 try: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
159 debug = self.flist.pyshell.interp.debugger |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
160 debug.clear_breakpoint_here(filename, lineno) |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
161 except: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
162 pass |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
163 |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
164 def clear_file_breaks(self): |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
165 if self.breakpoints: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
166 text = self.text |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
167 filename = self.io.filename |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
168 if not filename: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
169 text.bell() |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
170 return |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
171 self.breakpoints = [] |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
172 text.tag_remove("BREAK", "1.0", END) |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
173 try: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
174 debug = self.flist.pyshell.interp.debugger |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
175 debug.clear_file_breaks(filename) |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
176 except: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
177 pass |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
178 |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
179 def store_file_breaks(self): |
| 26659 | 180 "Save breakpoints when file is saved" |
| 181 # XXX 13 Dec 2002 KBK Currently the file must be saved before it can | |
| 182 # be run. The breaks are saved at that time. If we introduce | |
| 183 # a temporary file save feature the save breaks functionality | |
| 184 # needs to be re-verified, since the breaks at the time the | |
| 185 # temp file is created may differ from the breaks at the last | |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
186 # permanent save of the file. Currently, a break introduced |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
187 # after a save will be effective, but not persistent. |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
188 # This is necessary to keep the saved breaks synched with the |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
189 # saved file. |
| 26659 | 190 # |
| 191 # Breakpoints are set as tagged ranges in the text. Certain | |
| 192 # kinds of edits cause these ranges to be deleted: Inserting | |
| 193 # or deleting a line just before a breakpoint, and certain | |
| 194 # deletions prior to a breakpoint. These issues need to be | |
| 195 # investigated and understood. It's not clear if they are | |
| 196 # Tk issues or IDLE issues, or whether they can actually | |
| 197 # be fixed. Since a modified file has to be saved before it is | |
| 198 # run, and since self.breakpoints (from which the subprocess | |
| 199 # debugger is loaded) is updated during the save, the visible | |
| 200 # breaks stay synched with the subprocess even if one of these | |
| 201 # unexpected breakpoint deletions occurs. | |
| 202 breaks = self.breakpoints | |
| 203 filename = self.io.filename | |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
204 try: |
|
72172
d1d2dfbca812
IDLE: fix some RessourceWarning, reuse tokenize.open()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71746
diff
changeset
|
205 with open(self.breakpointPath, "r") as fp: |
|
d1d2dfbca812
IDLE: fix some RessourceWarning, reuse tokenize.open()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71746
diff
changeset
|
206 lines = fp.readlines() |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
207 except IOError: |
| 26659 | 208 lines = [] |
|
73968
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
209 try: |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
210 with open(self.breakpointPath, "w") as new_file: |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
211 for line in lines: |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
212 if not line.startswith(filename + '='): |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
213 new_file.write(line) |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
214 self.update_breakpoints() |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
215 breaks = self.breakpoints |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
216 if breaks: |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
217 new_file.write(filename + '=' + str(breaks) + '\n') |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
218 except IOError as err: |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
219 if not getattr(self.root, "breakpoint_error_displayed", False): |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
220 self.root.breakpoint_error_displayed = True |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
221 tkMessageBox.showerror(title='IDLE Error', |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
222 message='Unable to update breakpoint list:\n%s' |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
223 % str(err), |
|
26e3e542d20d
Issue #4625: If IDLE cannot write to its recent file or breakpoint
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
224 parent=self.text) |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
225 |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
226 def restore_file_breaks(self): |
|
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
227 self.text.update() # this enables setting "BREAK" tags to be visible |
| 26659 | 228 filename = self.io.filename |
| 229 if filename is None: | |
| 230 return | |
|
26028
64a96b97e1e9
Set breakpoints on remote debugger
Chui Tey <chui.tey@advdata.com.au>
parents:
26025
diff
changeset
|
231 if os.path.isfile(self.breakpointPath): |
|
72172
d1d2dfbca812
IDLE: fix some RessourceWarning, reuse tokenize.open()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71746
diff
changeset
|
232 with open(self.breakpointPath, "r") as fp: |
|
d1d2dfbca812
IDLE: fix some RessourceWarning, reuse tokenize.open()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71746
diff
changeset
|
233 lines = fp.readlines() |
|
26028
64a96b97e1e9
Set breakpoints on remote debugger
Chui Tey <chui.tey@advdata.com.au>
parents:
26025
diff
changeset
|
234 for line in lines: |
| 26659 | 235 if line.startswith(filename + '='): |
| 26959 | 236 breakpoint_linenumbers = eval(line[len(filename)+1:]) |
|
26028
64a96b97e1e9
Set breakpoints on remote debugger
Chui Tey <chui.tey@advdata.com.au>
parents:
26025
diff
changeset
|
237 for breakpoint_linenumber in breakpoint_linenumbers: |
|
64a96b97e1e9
Set breakpoints on remote debugger
Chui Tey <chui.tey@advdata.com.au>
parents:
26025
diff
changeset
|
238 self.set_breakpoint(breakpoint_linenumber) |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
239 |
| 26659 | 240 def update_breakpoints(self): |
| 241 "Retrieves all the breakpoints in the current window" | |
|
26025
18e09720738f
Recalls breakpoints set in a file
Chui Tey <chui.tey@advdata.com.au>
parents:
25894
diff
changeset
|
242 text = self.text |
| 26659 | 243 ranges = text.tag_ranges("BREAK") |
| 244 linenumber_list = self.ranges_to_linenumbers(ranges) | |
| 245 self.breakpoints = linenumber_list | |
| 246 | |
| 247 def ranges_to_linenumbers(self, ranges): | |
| 248 lines = [] | |
| 249 for index in range(0, len(ranges), 2): | |
| 250 lineno = int(float(ranges[index])) | |
| 251 end = int(float(ranges[index+1])) | |
| 252 while lineno < end: | |
| 253 lines.append(lineno) | |
| 254 lineno += 1 | |
| 255 return lines | |
| 256 | |
|
26771
fc7fdec3fb86
1. RPC stack levels were not pruned from traceback unless IDLE was started
Kurt B. Kaiser <kbk@shore.net>
parents:
26758
diff
changeset
|
257 # XXX 13 Dec 2002 KBK Not used currently |
| 26659 | 258 # def saved_change_hook(self): |
| 259 # "Extend base method - clear breaks if module is modified" | |
| 260 # if not self.get_saved(): | |
| 261 # self.clear_file_breaks() | |
| 262 # EditorWindow.saved_change_hook(self) | |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
263 |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
264 def _close(self): |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
265 "Extend base method - clear breaks when module is closed" |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
266 self.clear_file_breaks() |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
267 EditorWindow._close(self) |
| 26959 | 268 |
| 13975 | 269 |
| 270 class PyShellFileList(FileList): | |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
32512
diff
changeset
|
271 "Extend base class: IDLE supports a shell and breakpoints" |
| 13975 | 272 |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
32512
diff
changeset
|
273 # override FileList's class variable, instances return PyShellEditorWindow |
|
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
32512
diff
changeset
|
274 # instead of EditorWindow when new edit windows are created. |
| 13975 | 275 EditorWindow = PyShellEditorWindow |
| 276 | |
| 277 pyshell = None | |
| 278 | |
| 279 def open_shell(self, event=None): | |
| 280 if self.pyshell: | |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
32512
diff
changeset
|
281 self.pyshell.top.wakeup() |
| 13975 | 282 else: |
| 283 self.pyshell = PyShell(self) | |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
284 if self.pyshell: |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
285 if not self.pyshell.begin(): |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
286 return None |
| 13975 | 287 return self.pyshell |
| 288 | |
| 289 | |
| 290 class ModifiedColorDelegator(ColorDelegator): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
291 "Extend base class: colorizer for the shell window itself" |
| 26959 | 292 |
|
22111
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
293 def __init__(self): |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
294 ColorDelegator.__init__(self) |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
295 self.LoadTagDefs() |
| 13975 | 296 |
| 297 def recolorize_main(self): | |
| 298 self.tag_remove("TODO", "1.0", "iomark") | |
| 299 self.tag_add("SYNC", "1.0", "iomark") | |
| 300 ColorDelegator.recolorize_main(self) | |
| 26959 | 301 |
|
22111
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
302 def LoadTagDefs(self): |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
303 ColorDelegator.LoadTagDefs(self) |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
304 theme = idleConf.GetOption('main','Theme','name') |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
305 self.tagdefs.update({ |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
306 "stdin": {'background':None,'foreground':None}, |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
307 "stdout": idleConf.GetHighlight(theme, "stdout"), |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
308 "stderr": idleConf.GetHighlight(theme, "stderr"), |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
309 "console": idleConf.GetHighlight(theme, "console"), |
|
c494084dc6d8
First work on making config changes dynamic,
Steven M. Gava <elguavas@python.net>
parents:
21627
diff
changeset
|
310 }) |
| 13975 | 311 |
| 312 class ModifiedUndoDelegator(UndoDelegator): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
313 "Extend base class: forbid insert/delete before the I/O mark" |
| 13975 | 314 |
| 315 def insert(self, index, chars, tags=None): | |
| 316 try: | |
| 317 if self.delegate.compare(index, "<", "iomark"): | |
| 318 self.delegate.bell() | |
| 319 return | |
| 320 except TclError: | |
| 321 pass | |
| 322 UndoDelegator.insert(self, index, chars, tags) | |
| 323 | |
| 324 def delete(self, index1, index2=None): | |
| 325 try: | |
| 326 if self.delegate.compare(index1, "<", "iomark"): | |
| 327 self.delegate.bell() | |
| 328 return | |
| 329 except TclError: | |
| 330 pass | |
| 331 UndoDelegator.delete(self, index1, index2) | |
| 332 | |
| 29254 | 333 |
| 334 class MyRPCClient(rpc.RPCClient): | |
| 335 | |
| 336 def handle_EOF(self): | |
| 337 "Override the base class - just re-raise EOFError" | |
| 338 raise EOFError | |
| 339 | |
| 29271 | 340 |
| 13975 | 341 class ModifiedInterpreter(InteractiveInterpreter): |
| 342 | |
| 343 def __init__(self, tkconsole): | |
| 344 self.tkconsole = tkconsole | |
| 345 locals = sys.modules['__main__'].__dict__ | |
| 346 InteractiveInterpreter.__init__(self, locals=locals) | |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
347 self.save_warnings_filters = None |
|
29256
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
348 self.restarting = False |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
349 self.subprocess_arglist = None |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
350 self.port = PORT |
|
73233
9fbf79d6be56
Issue 13296: Fix IDLE to clear compile __future__ flags on shell restart.
Ned Deily <nad@acm.org>
parents:
72382
diff
changeset
|
351 self.original_compiler_flags = self.compile.compiler.flags |
| 13975 | 352 |
| 23547 | 353 rpcclt = None |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
354 rpcsubproc = None |
| 23547 | 355 |
| 26959 | 356 def spawn_subprocess(self): |
|
60063
e63d4678fca7
Note: only the relevant parts of r79474 are merged.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
52849
diff
changeset
|
357 if self.subprocess_arglist is None: |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
358 self.subprocess_arglist = self.build_subprocess_arglist() |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
359 self.rpcsubproc = subprocess.Popen(self.subprocess_arglist) |
| 25123 | 360 |
|
26730
9b4c014b3a21
Update way a subprocess is launched for Mac OS X.
Tony Lownds <tony@lownds.com>
parents:
26693
diff
changeset
|
361 def build_subprocess_arglist(self): |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
362 assert (self.port!=0), ( |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
363 "Socket should have been assigned a port number.") |
|
29101
32e70ad79f66
1. The command-line arguments for subprocesses no longer need to be
Tony Lownds <tony@lownds.com>
parents:
29076
diff
changeset
|
364 w = ['-W' + s for s in sys.warnoptions] |
|
32e70ad79f66
1. The command-line arguments for subprocesses no longer need to be
Tony Lownds <tony@lownds.com>
parents:
29076
diff
changeset
|
365 # Maybe IDLE is installed and is being accessed via sys.path, |
|
32e70ad79f66
1. The command-line arguments for subprocesses no longer need to be
Tony Lownds <tony@lownds.com>
parents:
29076
diff
changeset
|
366 # or maybe it's not installed and the idle.py script is being |
|
32e70ad79f66
1. The command-line arguments for subprocesses no longer need to be
Tony Lownds <tony@lownds.com>
parents:
29076
diff
changeset
|
367 # run from the IDLE source directory. |
|
29281
4992c60d422b
Added a config-main General option to delete sys.exitfunc. The default
Kurt B. Kaiser <kbk@shore.net>
parents:
29271
diff
changeset
|
368 del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc', |
|
4992c60d422b
Added a config-main General option to delete sys.exitfunc. The default
Kurt B. Kaiser <kbk@shore.net>
parents:
29271
diff
changeset
|
369 default=False, type='bool') |
|
29101
32e70ad79f66
1. The command-line arguments for subprocesses no longer need to be
Tony Lownds <tony@lownds.com>
parents:
29076
diff
changeset
|
370 if __name__ == 'idlelib.PyShell': |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
371 command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,) |
|
25480
9d50bc831bca
Finding a suitable interpreter to spawn needed tweaking on the Mac
Tony Lownds <tony@lownds.com>
parents:
25346
diff
changeset
|
372 else: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
373 command = "__import__('run').main(%r)" % (del_exitf,) |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
374 return [sys.executable] + w + ["-c", command, str(self.port)] |
|
25480
9d50bc831bca
Finding a suitable interpreter to spawn needed tweaking on the Mac
Tony Lownds <tony@lownds.com>
parents:
25346
diff
changeset
|
375 |
| 25123 | 376 def start_subprocess(self): |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
377 addr = (HOST, self.port) |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
378 # GUI makes several attempts to acquire socket, listens for connection |
|
29120
addd437be749
1. Make the startup more robust by not spawning the subprocess if IDLE
Kurt B. Kaiser <kbk@shore.net>
parents:
29119
diff
changeset
|
379 for i in range(3): |
| 23547 | 380 time.sleep(i) |
| 381 try: | |
| 29254 | 382 self.rpcclt = MyRPCClient(addr) |
| 23547 | 383 break |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
384 except socket.error as err: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
385 pass |
| 23547 | 386 else: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
387 self.display_port_binding_error() |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
388 return None |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
389 # if PORT was 0, system will assign an 'ephemeral' port. Find it out: |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
390 self.port = self.rpcclt.listening_sock.getsockname()[1] |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
391 # if PORT was not 0, probably working with a remote execution server |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
392 if PORT != 0: |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
393 # To allow reconnection within the 2MSL wait (cf. Stevens TCP |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
394 # V1, 18.6), set SO_REUSEADDR. Note that this can be problematic |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
395 # on Windows since the implementation allows two active sockets on |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
396 # the same address! |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
397 self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET, |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
398 socket.SO_REUSEADDR, 1) |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
399 self.spawn_subprocess() |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
400 #time.sleep(20) # test to simulate GUI not accepting connection |
|
24386
0e27b67247da
Reverse the RPC socket connection: Python execution server connects to
Kurt B. Kaiser <kbk@shore.net>
parents:
24183
diff
changeset
|
401 # Accept the connection from the Python execution server |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
402 self.rpcclt.listening_sock.settimeout(10) |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
403 try: |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
404 self.rpcclt.accept() |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
405 except socket.timeout as err: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
406 self.display_no_subprocess_error() |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
407 return None |
|
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
|
408 self.rpcclt.register("stdin", self.tkconsole) |
|
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
|
409 self.rpcclt.register("stdout", self.tkconsole.stdout) |
|
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
|
410 self.rpcclt.register("stderr", self.tkconsole.stderr) |
| 23547 | 411 self.rpcclt.register("flist", self.tkconsole.flist) |
| 27545 | 412 self.rpcclt.register("linecache", linecache) |
|
29353
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
413 self.rpcclt.register("interp", self) |
|
74693
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
414 self.transfer_path(with_cwd=True) |
| 23547 | 415 self.poll_subprocess() |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
416 return self.rpcclt |
| 23547 | 417 |
|
74693
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
418 def restart_subprocess(self, with_cwd=False): |
|
29256
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
419 if self.restarting: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
420 return self.rpcclt |
|
29256
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
421 self.restarting = True |
| 25123 | 422 # close only the subprocess debugger |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
423 debug = self.getdebugger() |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
424 if debug: |
| 27920 | 425 try: |
|
29076
ad84fe58ec2f
1. RemoteDebugger now runs user code in subprocess MainThread
Kurt B. Kaiser <kbk@shore.net>
parents:
29059
diff
changeset
|
426 # Only close subprocess debugger, don't unregister gui_adap! |
| 27920 | 427 RemoteDebugger.close_subprocess_debugger(self.rpcclt) |
| 428 except: | |
| 429 pass | |
| 430 # Kill subprocess, spawn a new one, accept connection. | |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
431 self.rpcclt.close() |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
432 self.terminate_subprocess() |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
433 console = self.tkconsole |
|
29256
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
434 was_executing = console.executing |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
435 console.executing = False |
| 25123 | 436 self.spawn_subprocess() |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
437 try: |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
438 self.rpcclt.accept() |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
439 except socket.timeout as err: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
440 self.display_no_subprocess_error() |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
441 return None |
|
74693
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
442 self.transfer_path(with_cwd=with_cwd) |
| 27074 | 443 # annotate restart in shell window and mark it |
| 27336 | 444 console.text.delete("iomark", "end-1c") |
|
29256
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
445 if was_executing: |
|
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
446 console.write('\n') |
|
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
447 console.showprompt() |
| 27074 | 448 halfbar = ((int(console.width) - 16) // 2) * '=' |
| 449 console.write(halfbar + ' RESTART ' + halfbar) | |
| 450 console.text.mark_set("restart", "end-1c") | |
| 451 console.text.mark_gravity("restart", "left") | |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
452 console.showprompt() |
| 27920 | 453 # restart subprocess debugger |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
454 if debug: |
|
29076
ad84fe58ec2f
1. RemoteDebugger now runs user code in subprocess MainThread
Kurt B. Kaiser <kbk@shore.net>
parents:
29059
diff
changeset
|
455 # Restarted debugger connects to current instance of debug GUI |
| 25123 | 456 gui = RemoteDebugger.restart_subprocess_debugger(self.rpcclt) |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
457 # reload remote debugger breakpoints for all PyShellEditWindows |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
458 debug.load_breakpoints() |
|
73233
9fbf79d6be56
Issue 13296: Fix IDLE to clear compile __future__ flags on shell restart.
Ned Deily <nad@acm.org>
parents:
72382
diff
changeset
|
459 self.compile.compiler.flags = self.original_compiler_flags |
|
29256
b909fdf0edf8
Improved the RESTART annotation in the shell window when the user
Kurt B. Kaiser <kbk@shore.net>
parents:
29254
diff
changeset
|
460 self.restarting = False |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
461 return self.rpcclt |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
462 |
| 27920 | 463 def __request_interrupt(self): |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
464 self.rpcclt.remotecall("exec", "interrupt_the_server", (), {}) |
| 27920 | 465 |
| 466 def interrupt_subprocess(self): | |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
467 threading.Thread(target=self.__request_interrupt).start() |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
468 |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
469 def kill_subprocess(self): |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
470 try: |
|
73399
ce483d696c06
Issue #13300: Fix IDLE Restart Shell command failure introduced by
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
471 self.rpcclt.listening_sock.close() |
|
ce483d696c06
Issue #13300: Fix IDLE Restart Shell command failure introduced by
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
472 except AttributeError: # no socket |
|
ce483d696c06
Issue #13300: Fix IDLE Restart Shell command failure introduced by
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
473 pass |
|
ce483d696c06
Issue #13300: Fix IDLE Restart Shell command failure introduced by
Ned Deily <nad@acm.org>
parents:
73233
diff
changeset
|
474 try: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
475 self.rpcclt.close() |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
476 except AttributeError: # no socket |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
477 pass |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
478 self.terminate_subprocess() |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
479 self.tkconsole.executing = False |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
480 self.rpcclt = None |
| 27920 | 481 |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
482 def terminate_subprocess(self): |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
483 "Make sure subprocess is terminated" |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
484 try: |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
485 self.rpcsubproc.kill() |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
486 except OSError: |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
487 # process already terminated |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
488 return |
|
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
489 else: |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
490 try: |
|
71746
cc86f4ca5020
Issue #12540: Prevent zombie IDLE processes on Windows due to changes
Ned Deily <nad@acm.org>
parents:
71171
diff
changeset
|
491 self.rpcsubproc.wait() |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
492 except OSError: |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
493 return |
| 28385 | 494 |
|
74693
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
495 def transfer_path(self, with_cwd=False): |
|
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
496 if with_cwd: # Issue 13506 |
|
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
497 path = [''] # include Current Working Directory |
|
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
498 path.extend(sys.path) |
|
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
499 else: |
|
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
500 path = sys.path |
| 74696 | 501 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
502 self.runcommand("""if 1: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
503 import sys as _sys |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
504 _sys.path = %r |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
505 del _sys |
|
74693
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
506 \n""" % (path,)) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
507 |
| 23547 | 508 active_seq = None |
| 509 | |
| 510 def poll_subprocess(self): | |
| 511 clt = self.rpcclt | |
| 512 if clt is None: | |
| 513 return | |
| 27920 | 514 try: |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
515 response = clt.pollresponse(self.active_seq, wait=0.05) |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
516 except (EOFError, IOError, KeyboardInterrupt): |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
517 # lost connection or subprocess terminated itself, restart |
|
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
518 # [the KBI is from rpc.SocketIO.handle_EOF()] |
| 29254 | 519 if self.tkconsole.closing: |
| 520 return | |
| 27920 | 521 response = None |
| 522 self.restart_subprocess() | |
| 23547 | 523 if response: |
| 524 self.tkconsole.resetoutput() | |
| 525 self.active_seq = None | |
| 526 how, what = response | |
| 27379 | 527 console = self.tkconsole.console |
| 23547 | 528 if how == "OK": |
| 529 if what is not None: | |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
530 print(repr(what), file=console) |
| 23547 | 531 elif how == "EXCEPTION": |
| 532 if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"): | |
| 533 self.remote_stack_viewer() | |
| 534 elif how == "ERROR": | |
| 26557 | 535 errmsg = "PyShell.ModifiedInterpreter: Subprocess ERROR:\n" |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
536 print(errmsg, what, file=sys.__stderr__) |
|
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
537 print(errmsg, what, file=console) |
| 27379 | 538 # we received a response to the currently active seq number: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
539 try: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
540 self.tkconsole.endexecuting() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
541 except AttributeError: # shell may have closed |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
542 pass |
|
29171
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
543 # Reschedule myself |
|
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
544 if not self.tkconsole.closing: |
|
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
545 self.tkconsole.text.after(self.tkconsole.pollinterval, |
|
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
546 self.poll_subprocess) |
| 23547 | 547 |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
548 debugger = None |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
549 |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
550 def setdebugger(self, debugger): |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
551 self.debugger = debugger |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
552 |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
553 def getdebugger(self): |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
554 return self.debugger |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
555 |
|
29353
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
556 def open_remote_stack_viewer(self): |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
557 """Initiate the remote stack viewer from a separate thread. |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
558 |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
559 This method is called from the subprocess, and by returning from this |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
560 method we allow the subprocess to unblock. After a bit the shell |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
561 requests the subprocess to open the remote stack viewer which returns a |
|
63176
227dee278638
Merged revisions 83103 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60063
diff
changeset
|
562 static object looking at the last exception. It is queried through |
|
29353
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
563 the RPC mechanism. |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
564 |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
565 """ |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
566 self.tkconsole.text.after(300, self.remote_stack_viewer) |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
567 return |
|
b1395014714a
Modify the remote stack viewer to work in the threaded subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29281
diff
changeset
|
568 |
| 23547 | 569 def remote_stack_viewer(self): |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
570 from idlelib import RemoteObjectBrowser |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
571 oid = self.rpcclt.remotequeue("exec", "stackviewer", ("flist",), {}) |
| 23547 | 572 if oid is None: |
| 573 self.tkconsole.root.bell() | |
| 574 return | |
| 575 item = RemoteObjectBrowser.StubObjectTreeItem(self.rpcclt, oid) | |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
576 from idlelib.TreeWidget import ScrolledCanvas, TreeNode |
| 23547 | 577 top = Toplevel(self.tkconsole.root) |
|
31625
1b02c77cdcfe
Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
578 theme = idleConf.GetOption('main','Theme','name') |
|
1b02c77cdcfe
Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
579 background = idleConf.GetHighlight(theme, 'normal')['background'] |
|
1b02c77cdcfe
Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
Kurt B. Kaiser <kbk@shore.net>
parents:
31515
diff
changeset
|
580 sc = ScrolledCanvas(top, bg=background, highlightthickness=0) |
| 23547 | 581 sc.frame.pack(expand=1, fill="both") |
| 582 node = TreeNode(sc.canvas, None, item) | |
| 583 node.expand() | |
| 584 # XXX Should GC the remote tree when closing the window | |
| 585 | |
| 13975 | 586 gid = 0 |
| 587 | |
| 588 def execsource(self, source): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
589 "Like runsource() but assumes complete exec source" |
| 13975 | 590 filename = self.stuffsource(source) |
| 591 self.execfile(filename, source) | |
| 592 | |
| 593 def execfile(self, filename, source=None): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
594 "Execute an existing file" |
| 13975 | 595 if source is None: |
|
72173
fe7777f1ed14
Issue #12636: IDLE reads the coding cookie when executing a Python script.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72172
diff
changeset
|
596 with tokenize.open(filename) as fp: |
|
72172
d1d2dfbca812
IDLE: fix some RessourceWarning, reuse tokenize.open()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71746
diff
changeset
|
597 source = fp.read() |
| 13975 | 598 try: |
| 599 code = compile(source, filename, "exec") | |
| 600 except (OverflowError, SyntaxError): | |
| 601 self.tkconsole.resetoutput() | |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
602 tkerr = self.tkconsole.stderr |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
603 print('*** Error in script or command!\n', file=tkerr) |
|
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
604 print('Traceback (most recent call last):', file=tkerr) |
| 13975 | 605 InteractiveInterpreter.showsyntaxerror(self, filename) |
| 26468 | 606 self.tkconsole.showprompt() |
| 13975 | 607 else: |
| 608 self.runcode(code) | |
| 609 | |
| 610 def runsource(self, source): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
611 "Extend base class method: Stuff the source in the line cache first" |
| 13975 | 612 filename = self.stuffsource(source) |
| 613 self.more = 0 | |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
614 self.save_warnings_filters = warnings.filters[:] |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
615 warnings.filterwarnings(action="error", category=SyntaxWarning) |
|
42571
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
616 # at the moment, InteractiveInterpreter expects str |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
617 assert isinstance(source, str) |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
618 #if isinstance(source, str): |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
619 # from idlelib import IOBinding |
|
42571
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
620 # try: |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
621 # source = source.encode(IOBinding.encoding) |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
622 # except UnicodeError: |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
623 # self.tkconsole.resetoutput() |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
624 # self.write("Unsupported characters in input\n") |
|
7a45e8b78d63
Expect that source strings are Unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
42555
diff
changeset
|
625 # return |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
626 try: |
|
34948
e4e0cff16bc7
Improve subprocess link error notification
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
627 # InteractiveInterpreter.runsource() calls its runcode() method, |
|
e4e0cff16bc7
Improve subprocess link error notification
Kurt B. Kaiser <kbk@shore.net>
parents:
34443
diff
changeset
|
628 # which is overridden (see below) |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
629 return InteractiveInterpreter.runsource(self, source, filename) |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
630 finally: |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
631 if self.save_warnings_filters is not None: |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
632 warnings.filters[:] = self.save_warnings_filters |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
633 self.save_warnings_filters = None |
| 13975 | 634 |
| 635 def stuffsource(self, source): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
636 "Stuff source in the filename cache" |
| 13975 | 637 filename = "<pyshell#%d>" % self.gid |
| 638 self.gid = self.gid + 1 | |
| 25310 | 639 lines = source.split("\n") |
| 13975 | 640 linecache.cache[filename] = len(source)+1, 0, lines, filename |
| 641 return filename | |
| 26959 | 642 |
|
29122
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
643 def prepend_syspath(self, filename): |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
644 "Prepend sys.path with file's directory if not already included" |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
645 self.runcommand("""if 1: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
646 _filename = %r |
|
29122
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
647 import sys as _sys |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
648 from os.path import dirname as _dirname |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
649 _dir = _dirname(_filename) |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
650 if not _dir in _sys.path: |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
651 _sys.path.insert(0, _dir) |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
652 del _filename, _sys, _dirname, _dir |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
653 \n""" % (filename,)) |
|
29122
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
654 |
| 13975 | 655 def showsyntaxerror(self, filename=None): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
656 """Override Interactive Interpreter method: Use Colorizing |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
657 |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
658 Color the offending position instead of printing it and pointing at it |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
659 with a caret. |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
660 |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
661 """ |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
662 tkconsole = self.tkconsole |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
663 text = tkconsole.text |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
664 text.tag_remove("ERROR", "1.0", "end") |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
665 type, value, tb = sys.exc_info() |
|
72382
e74860883a9c
Issue #9871: Prevent IDLE 3 crash when given byte stings
Ned Deily <nad@acm.org>
parents:
72173
diff
changeset
|
666 msg = getattr(value, 'msg', '') or value or "<no detail available>" |
|
e74860883a9c
Issue #9871: Prevent IDLE 3 crash when given byte stings
Ned Deily <nad@acm.org>
parents:
72173
diff
changeset
|
667 lineno = getattr(value, 'lineno', '') or 1 |
|
e74860883a9c
Issue #9871: Prevent IDLE 3 crash when given byte stings
Ned Deily <nad@acm.org>
parents:
72173
diff
changeset
|
668 offset = getattr(value, 'offset', '') or 0 |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
669 if offset == 0: |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
670 lineno += 1 #mark end of offending line |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
671 if lineno == 1: |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
672 pos = "iomark + %d chars" % (offset-1) |
| 26468 | 673 else: |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
674 pos = "iomark linestart + %d lines + %d chars" % \ |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
675 (lineno-1, offset-1) |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
676 tkconsole.colorize_syntax_error(text, pos) |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
677 tkconsole.resetoutput() |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
678 self.write("SyntaxError: %s\n" % msg) |
|
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42324
diff
changeset
|
679 tkconsole.showprompt() |
| 13975 | 680 |
| 681 def showtraceback(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
682 "Extend base class method to reset output properly" |
| 13975 | 683 self.tkconsole.resetoutput() |
| 684 self.checklinecache() | |
| 685 InteractiveInterpreter.showtraceback(self) | |
| 23547 | 686 if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"): |
| 687 self.tkconsole.open_stack_viewer() | |
| 13975 | 688 |
| 689 def checklinecache(self): | |
| 690 c = linecache.cache | |
|
42324
4bbbe0c55fa2
Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42309
diff
changeset
|
691 for key in list(c.keys()): |
| 13975 | 692 if key[:1] + key[-1:] != "<>": |
| 693 del c[key] | |
| 694 | |
| 23547 | 695 def runcommand(self, code): |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
696 "Run the code without invoking the debugger" |
| 23547 | 697 # The code better not raise an exception! |
| 698 if self.tkconsole.executing: | |
|
26471
99c78cf95610
Add missing self for method call
Neal Norwitz <nnorwitz@gmail.com>
parents:
26468
diff
changeset
|
699 self.display_executing_dialog() |
| 23547 | 700 return 0 |
| 701 if self.rpcclt: | |
|
29034
656493534cc7
1. Implement processing of user code in subprocess MainThread. Pass loop
Kurt B. Kaiser <kbk@shore.net>
parents:
28385
diff
changeset
|
702 self.rpcclt.remotequeue("exec", "runcode", (code,), {}) |
| 23547 | 703 else: |
|
39782
c94f37054f19
Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents:
39610
diff
changeset
|
704 exec(code, self.locals) |
| 23547 | 705 return 1 |
| 706 | |
| 13975 | 707 def runcode(self, code): |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
708 "Override base class method" |
| 23547 | 709 if self.tkconsole.executing: |
| 27920 | 710 self.interp.restart_subprocess() |
| 23547 | 711 self.checklinecache() |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
712 if self.save_warnings_filters is not None: |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
713 warnings.filters[:] = self.save_warnings_filters |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
714 self.save_warnings_filters = None |
| 13975 | 715 debugger = self.debugger |
| 716 try: | |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
717 self.tkconsole.beginexecuting() |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
718 if not debugger and self.rpcclt is not None: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
719 self.active_seq = self.rpcclt.asyncqueue("exec", "runcode", |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
720 (code,), {}) |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
721 elif debugger: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
722 debugger.run(code, self.locals) |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
723 else: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
724 exec(code, self.locals) |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
725 except SystemExit: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
726 if not self.tkconsole.closing: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
727 if tkMessageBox.askyesno( |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
728 "Exit?", |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
729 "Do you want to exit altogether?", |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
730 default="yes", |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
731 master=self.tkconsole.text): |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
732 raise |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
733 else: |
|
40916
f5790f96acf3
Fix merge bug (lost line causing syntax error).
Guido van Rossum <guido@python.org>
parents:
40893
diff
changeset
|
734 self.showtraceback() |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
735 else: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
736 raise |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
737 except: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
738 if use_subprocess: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
739 print("IDLE internal error in runcode()", |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
740 file=self.tkconsole.stderr) |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
741 self.showtraceback() |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
742 self.tkconsole.endexecuting() |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
743 else: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
744 if self.tkconsole.canceled: |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
745 self.tkconsole.canceled = False |
|
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
746 print("KeyboardInterrupt", file=self.tkconsole.stderr) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
747 else: |
|
40893
32c4897b5d46
Merged revisions 53623-53858 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40799
diff
changeset
|
748 self.showtraceback() |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
749 finally: |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
750 if not use_subprocess: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
751 try: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
752 self.tkconsole.endexecuting() |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
753 except AttributeError: # shell may have closed |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
754 pass |
| 13975 | 755 |
| 756 def write(self, s): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
757 "Override base class method" |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
758 self.tkconsole.stderr.write(s) |
| 13975 | 759 |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
760 def display_port_binding_error(self): |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
761 tkMessageBox.showerror( |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
762 "Port Binding Error", |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
763 "IDLE can't bind to a TCP/IP port, which is necessary to " |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
764 "communicate with its Python execution server. This might be " |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
765 "because no networking is installed on this computer. " |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
766 "Run IDLE with the -n command line switch to start without a " |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
767 "subprocess and refer to Help/IDLE Help 'Running without a " |
|
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
768 "subprocess' for further details.", |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
769 master=self.tkconsole.text) |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
770 |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
771 def display_no_subprocess_error(self): |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
772 tkMessageBox.showerror( |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
773 "Subprocess Startup Error", |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
774 "IDLE's subprocess didn't make connection. Either IDLE can't " |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
775 "start a subprocess or personal firewall software is blocking " |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
776 "the connection.", |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
777 master=self.tkconsole.text) |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
778 |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
779 def display_executing_dialog(self): |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
780 tkMessageBox.showerror( |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
781 "Already executing", |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
782 "The Python Shell window is already executing a command; " |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
783 "please wait until it is finished.", |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
784 master=self.tkconsole.text) |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
785 |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
786 |
| 13975 | 787 class PyShell(OutputWindow): |
| 788 | |
| 789 shell_title = "Python Shell" | |
| 790 | |
| 791 # Override classes | |
| 792 ColorDelegator = ModifiedColorDelegator | |
| 793 UndoDelegator = ModifiedUndoDelegator | |
| 794 | |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
795 # Override menus |
|
24183
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
796 menu_specs = [ |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
797 ("file", "_File"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
798 ("edit", "_Edit"), |
| 27336 | 799 ("debug", "_Debug"), |
| 27074 | 800 ("options", "_Options"), |
|
24183
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
801 ("windows", "_Windows"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
802 ("help", "_Help"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
803 ] |
| 13975 | 804 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
805 if macosxSupport.runningAsOSXApp(): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
806 del menu_specs[-3] |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
807 menu_specs[-2] = ("windows", "_Window") |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
808 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
809 |
| 13975 | 810 # New classes |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
811 from idlelib.IdleHistory import History |
| 13975 | 812 |
| 813 def __init__(self, flist=None): | |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
814 if use_subprocess: |
| 29254 | 815 ms = self.menu_specs |
| 816 if ms[2][0] != "shell": | |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
817 ms.insert(2, ("shell", "She_ll")) |
| 13975 | 818 self.interp = ModifiedInterpreter(self) |
| 819 if flist is None: | |
| 820 root = Tk() | |
| 821 fixwordbreaks(root) | |
| 822 root.withdraw() | |
| 823 flist = PyShellFileList(root) | |
|
25691
b39bd03a8dab
M CallTips.py Add support for getting calltip from subprocess,
Kurt B. Kaiser <kbk@shore.net>
parents:
25480
diff
changeset
|
824 # |
| 13975 | 825 OutputWindow.__init__(self, flist, None, None) |
|
25691
b39bd03a8dab
M CallTips.py Add support for getting calltip from subprocess,
Kurt B. Kaiser <kbk@shore.net>
parents:
25480
diff
changeset
|
826 # |
| 34443 | 827 ## self.config(usetabs=1, indentwidth=8, context_use_ps1=1) |
| 828 self.usetabs = True | |
| 829 # indentwidth must be 8 when using tabs. See note in EditorWindow: | |
| 830 self.indentwidth = 8 | |
| 831 self.context_use_ps1 = True | |
|
25691
b39bd03a8dab
M CallTips.py Add support for getting calltip from subprocess,
Kurt B. Kaiser <kbk@shore.net>
parents:
25480
diff
changeset
|
832 # |
| 13975 | 833 text = self.text |
| 834 text.configure(wrap="char") | |
| 835 text.bind("<<newline-and-indent>>", self.enter_callback) | |
| 836 text.bind("<<plain-newline-and-indent>>", self.linefeed_callback) | |
| 837 text.bind("<<interrupt-execution>>", self.cancel_callback) | |
| 838 text.bind("<<end-of-file>>", self.eof_callback) | |
| 839 text.bind("<<open-stack-viewer>>", self.open_stack_viewer) | |
|
29059
92ebd3daf507
1. Update debugger to not trace RPC code even when calling Queue and
Kurt B. Kaiser <kbk@shore.net>
parents:
29034
diff
changeset
|
840 text.bind("<<toggle-debugger>>", self.toggle_debugger) |
| 13975 | 841 text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer) |
|
44282
541052b044f0
Shell was not colorizing due to bug introduced at r57998, Bug 1586.
Kurt B. Kaiser <kbk@shore.net>
parents:
43734
diff
changeset
|
842 self.color = color = self.ColorDelegator() |
|
541052b044f0
Shell was not colorizing due to bug introduced at r57998, Bug 1586.
Kurt B. Kaiser <kbk@shore.net>
parents:
43734
diff
changeset
|
843 self.per.insertfilter(color) |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
844 if use_subprocess: |
|
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
845 text.bind("<<view-restart>>", self.view_restart_mark) |
|
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
846 text.bind("<<restart-shell>>", self.restart_shell) |
|
25691
b39bd03a8dab
M CallTips.py Add support for getting calltip from subprocess,
Kurt B. Kaiser <kbk@shore.net>
parents:
25480
diff
changeset
|
847 # |
| 13975 | 848 self.save_stdout = sys.stdout |
| 849 self.save_stderr = sys.stderr | |
| 850 self.save_stdin = sys.stdin | |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
851 from idlelib import IOBinding |
|
29582
ee14e5b06ed1
Idlefork patch #682347: convert Unicode strings from readline to
Martin v. Löwis <martin@v.loewis.de>
parents:
29476
diff
changeset
|
852 self.stdout = PseudoFile(self, "stdout", IOBinding.encoding) |
|
ee14e5b06ed1
Idlefork patch #682347: convert Unicode strings from readline to
Martin v. Löwis <martin@v.loewis.de>
parents:
29476
diff
changeset
|
853 self.stderr = PseudoFile(self, "stderr", IOBinding.encoding) |
|
ee14e5b06ed1
Idlefork patch #682347: convert Unicode strings from readline to
Martin v. Löwis <martin@v.loewis.de>
parents:
29476
diff
changeset
|
854 self.console = PseudoFile(self, "console", IOBinding.encoding) |
| 23547 | 855 if not use_subprocess: |
| 856 sys.stdout = self.stdout | |
|
43120
fec2c0299a8c
1. Don't encode input strings to bytes.
Kurt B. Kaiser <kbk@shore.net>
parents:
42881
diff
changeset
|
857 sys.stderr = self.stderr |
| 23547 | 858 sys.stdin = self |
|
44380
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
859 try: |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
860 # page help() text to shell. |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
861 import pydoc # import must be done here to capture i/o rebinding. |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
862 # XXX KBK 27Dec07 use a textView someday, but must work w/o subproc |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
863 pydoc.pager = pydoc.plainpager |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
864 except: |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
865 sys.stderr = sys.__stderr__ |
|
08468a263a95
help() was not paging to the shell. Issue1650.
Kurt B. Kaiser <kbk@shore.net>
parents:
44282
diff
changeset
|
866 raise |
|
25691
b39bd03a8dab
M CallTips.py Add support for getting calltip from subprocess,
Kurt B. Kaiser <kbk@shore.net>
parents:
25480
diff
changeset
|
867 # |
| 13975 | 868 self.history = self.History(self.text) |
|
25691
b39bd03a8dab
M CallTips.py Add support for getting calltip from subprocess,
Kurt B. Kaiser <kbk@shore.net>
parents:
25480
diff
changeset
|
869 # |
|
29171
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
870 self.pollinterval = 50 # millisec |
| 23547 | 871 |
|
32272
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
872 def get_standard_extension_names(self): |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
873 return idleConf.GetExtensions(shell_only=True) |
|
014b0d84422f
Noam Raphel: Further developemt of CodeContext feature.
Kurt B. Kaiser <kbk@shore.net>
parents:
31625
diff
changeset
|
874 |
| 27920 | 875 reading = False |
| 876 executing = False | |
| 877 canceled = False | |
| 878 endoffile = False | |
| 879 closing = False | |
| 13975 | 880 |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
881 def set_warning_stream(self, stream): |
| 32512 | 882 global warning_stream |
| 883 warning_stream = stream | |
|
32484
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
884 |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
885 def get_warning_stream(self): |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
886 return warning_stream |
|
f3cb95cd413f
Redirect the warning stream to the shell during the ScriptBinding check of user code
Kurt B. Kaiser <kbk@shore.net>
parents:
32272
diff
changeset
|
887 |
| 13975 | 888 def toggle_debugger(self, event=None): |
| 889 if self.executing: | |
| 890 tkMessageBox.showerror("Don't debug now", | |
| 891 "You can only toggle the debugger when idle", | |
| 892 master=self.text) | |
| 893 self.set_debugger_indicator() | |
| 894 return "break" | |
| 895 else: | |
| 896 db = self.interp.getdebugger() | |
| 897 if db: | |
| 898 self.close_debugger() | |
| 899 else: | |
| 900 self.open_debugger() | |
| 901 | |
| 902 def set_debugger_indicator(self): | |
| 903 db = self.interp.getdebugger() | |
| 904 self.setvar("<<toggle-debugger>>", not not db) | |
| 905 | |
| 27074 | 906 def toggle_jit_stack_viewer(self, event=None): |
| 13975 | 907 pass # All we need is the variable |
| 908 | |
| 909 def close_debugger(self): | |
| 910 db = self.interp.getdebugger() | |
| 911 if db: | |
| 912 self.interp.setdebugger(None) | |
| 913 db.close() | |
|
23995
41468f9353ce
Shutdown subprocess debugger and associated Proxies/Adapters when closing
Kurt B. Kaiser <kbk@shore.net>
parents:
23969
diff
changeset
|
914 if self.interp.rpcclt: |
|
41468f9353ce
Shutdown subprocess debugger and associated Proxies/Adapters when closing
Kurt B. Kaiser <kbk@shore.net>
parents:
23969
diff
changeset
|
915 RemoteDebugger.close_remote_debugger(self.interp.rpcclt) |
| 13975 | 916 self.resetoutput() |
| 917 self.console.write("[DEBUG OFF]\n") | |
| 918 sys.ps1 = ">>> " | |
| 919 self.showprompt() | |
| 920 self.set_debugger_indicator() | |
| 921 | |
| 922 def open_debugger(self): | |
| 23547 | 923 if self.interp.rpcclt: |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
924 dbg_gui = RemoteDebugger.start_remote_debugger(self.interp.rpcclt, |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
925 self) |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
926 else: |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
927 dbg_gui = Debugger.Debugger(self) |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
928 self.interp.setdebugger(dbg_gui) |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
929 dbg_gui.load_breakpoints() |
| 23547 | 930 sys.ps1 = "[DEBUG ON]\n>>> " |
| 931 self.showprompt() | |
| 932 self.set_debugger_indicator() | |
| 933 | |
| 13975 | 934 def beginexecuting(self): |
|
23995
41468f9353ce
Shutdown subprocess debugger and associated Proxies/Adapters when closing
Kurt B. Kaiser <kbk@shore.net>
parents:
23969
diff
changeset
|
935 "Helper for ModifiedInterpreter" |
| 13975 | 936 self.resetoutput() |
| 937 self.executing = 1 | |
| 938 | |
| 939 def endexecuting(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
940 "Helper for ModifiedInterpreter" |
| 13975 | 941 self.executing = 0 |
| 942 self.canceled = 0 | |
| 23547 | 943 self.showprompt() |
| 13975 | 944 |
| 945 def close(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
946 "Extend EditorWindow.close()" |
| 13975 | 947 if self.executing: |
| 27920 | 948 response = tkMessageBox.askokcancel( |
| 13975 | 949 "Kill?", |
| 27920 | 950 "The program is still running!\n Do you want to kill it?", |
| 13975 | 951 default="ok", |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
952 parent=self.text) |
|
46222
aed698c8647b
Merged revisions 62021,62029,62035-62038,62043-62044,62052-62053 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
44380
diff
changeset
|
953 if response is False: |
| 13975 | 954 return "cancel" |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
955 if self.reading: |
|
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
956 self.top.quit() |
|
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
957 self.canceled = True |
| 29254 | 958 self.closing = True |
| 959 # Wait for poll_subprocess() rescheduling to stop | |
| 960 self.text.after(2 * self.pollinterval, self.close2) | |
|
29171
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
961 |
|
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
962 def close2(self): |
|
9cf09f92b198
Fix race exposed by 2.4 GHz XP box: Don't tear down PyShell until
Kurt B. Kaiser <kbk@shore.net>
parents:
29122
diff
changeset
|
963 return EditorWindow.close(self) |
| 13975 | 964 |
| 965 def _close(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
966 "Extend EditorWindow._close(), shut down debugger and execution server" |
| 13975 | 967 self.close_debugger() |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
968 if use_subprocess: |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
969 self.interp.kill_subprocess() |
| 13975 | 970 # Restore std streams |
| 971 sys.stdout = self.save_stdout | |
| 972 sys.stderr = self.save_stderr | |
| 973 sys.stdin = self.save_stdin | |
| 974 # Break cycles | |
| 975 self.interp = None | |
| 976 self.console = None | |
| 977 self.flist.pyshell = None | |
| 978 self.history = None | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
979 EditorWindow._close(self) |
| 13975 | 980 |
| 981 def ispythonsource(self, filename): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
982 "Override EditorWindow method: never remove the colorizer" |
| 25310 | 983 return True |
| 13975 | 984 |
| 985 def short_title(self): | |
| 986 return self.shell_title | |
| 987 | |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
988 COPYRIGHT = \ |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
989 'Type "copyright", "credits" or "license()" for more information.' |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
990 |
| 13975 | 991 def begin(self): |
|
42533
6a09423164fe
Fix what appears to be a very old bug. Tkinter in struni is more intolerant
Kurt B. Kaiser <kbk@shore.net>
parents:
42531
diff
changeset
|
992 self.text.mark_set("iomark", "insert") |
| 13975 | 993 self.resetoutput() |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
994 if use_subprocess: |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
995 nosub = '' |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
996 client = self.interp.start_subprocess() |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
997 if not client: |
|
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
998 self.close() |
|
31414
14dea6f8b0c3
There was an error in the Tk error dialog fix at Rev 1.84 which caused starting
Kurt B. Kaiser <kbk@shore.net>
parents:
31412
diff
changeset
|
999 return False |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
1000 else: |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
1001 nosub = "==== No Subprocess ====" |
|
51087
f138fbe2945e
Forward port r68985: Idle startup message.
Raymond Hettinger <python@rcn.com>
parents:
49553
diff
changeset
|
1002 self.write("Python %s on %s\n%s\n%s" % |
|
f138fbe2945e
Forward port r68985: Idle startup message.
Raymond Hettinger <python@rcn.com>
parents:
49553
diff
changeset
|
1003 (sys.version, sys.platform, self.COPYRIGHT, nosub)) |
| 13975 | 1004 self.showprompt() |
|
47130
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
46978
diff
changeset
|
1005 import tkinter |
|
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
46978
diff
changeset
|
1006 tkinter._default_root = None # 03Jan04 KBK What's this? |
|
31414
14dea6f8b0c3
There was an error in the Tk error dialog fix at Rev 1.84 which caused starting
Kurt B. Kaiser <kbk@shore.net>
parents:
31412
diff
changeset
|
1007 return True |
| 13975 | 1008 |
| 1009 def readline(self): | |
| 1010 save = self.reading | |
| 1011 try: | |
| 1012 self.reading = 1 | |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1013 self.top.mainloop() # nested mainloop() |
| 13975 | 1014 finally: |
| 1015 self.reading = save | |
| 1016 line = self.text.get("iomark", "end-1c") | |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1017 if len(line) == 0: # may be EOF if we quit our mainloop with Ctrl-C |
|
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1018 line = "\n" |
| 13975 | 1019 self.resetoutput() |
| 1020 if self.canceled: | |
| 1021 self.canceled = 0 | |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1022 if not use_subprocess: |
|
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1023 raise KeyboardInterrupt |
| 13975 | 1024 if self.endoffile: |
| 1025 self.endoffile = 0 | |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1026 line = "" |
| 13975 | 1027 return line |
| 1028 | |
| 1029 def isatty(self): | |
| 25310 | 1030 return True |
| 13975 | 1031 |
| 27920 | 1032 def cancel_callback(self, event=None): |
| 13975 | 1033 try: |
| 1034 if self.text.compare("sel.first", "!=", "sel.last"): | |
| 1035 return # Active selection -- always use default binding | |
| 1036 except: | |
| 1037 pass | |
| 1038 if not (self.executing or self.reading): | |
| 1039 self.resetoutput() | |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
1040 self.interp.write("KeyboardInterrupt\n") |
| 13975 | 1041 self.showprompt() |
| 1042 return "break" | |
| 1043 self.endoffile = 0 | |
| 27920 | 1044 self.canceled = 1 |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1045 if (self.executing and self.interp.rpcclt): |
| 29254 | 1046 if self.interp.getdebugger(): |
| 1047 self.interp.restart_subprocess() | |
| 1048 else: | |
| 1049 self.interp.interrupt_subprocess() | |
|
34240
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1050 if self.reading: |
|
914534f6ef61
The GUI was hanging if the shell window was closed while a raw_input()
Kurt B. Kaiser <kbk@shore.net>
parents:
34212
diff
changeset
|
1051 self.top.quit() # exit the nested mainloop() in readline() |
| 13975 | 1052 return "break" |
| 1053 | |
| 1054 def eof_callback(self, event): | |
| 1055 if self.executing and not self.reading: | |
| 1056 return # Let the default binding (delete next char) take over | |
| 1057 if not (self.text.compare("iomark", "==", "insert") and | |
| 1058 self.text.compare("insert", "==", "end-1c")): | |
| 1059 return # Let the default binding (delete next char) take over | |
| 1060 if not self.executing: | |
| 1061 self.resetoutput() | |
| 1062 self.close() | |
| 1063 else: | |
| 1064 self.canceled = 0 | |
| 1065 self.endoffile = 1 | |
| 1066 self.top.quit() | |
| 1067 return "break" | |
| 1068 | |
| 1069 def linefeed_callback(self, event): | |
| 1070 # Insert a linefeed without entering anything (still autoindented) | |
| 1071 if self.reading: | |
| 1072 self.text.insert("insert", "\n") | |
| 1073 self.text.see("insert") | |
| 1074 else: | |
| 26667 | 1075 self.newline_and_indent_event(event) |
| 13975 | 1076 return "break" |
| 1077 | |
| 1078 def enter_callback(self, event): | |
| 1079 if self.executing and not self.reading: | |
| 1080 return # Let the default binding (insert '\n') take over | |
| 1081 # If some text is selected, recall the selection | |
| 1082 # (but only if this before the I/O mark) | |
| 1083 try: | |
| 1084 sel = self.text.get("sel.first", "sel.last") | |
| 1085 if sel: | |
| 1086 if self.text.compare("sel.last", "<=", "iomark"): | |
|
35112
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1087 self.recall(sel, event) |
| 13975 | 1088 return "break" |
| 1089 except: | |
| 1090 pass | |
| 1091 # If we're strictly before the line containing iomark, recall | |
| 1092 # the current line, less a leading prompt, less leading or | |
| 1093 # trailing whitespace | |
| 1094 if self.text.compare("insert", "<", "iomark linestart"): | |
| 1095 # Check if there's a relevant stdin range -- if so, use it | |
| 1096 prev = self.text.tag_prevrange("stdin", "insert") | |
| 1097 if prev and self.text.compare("insert", "<", prev[1]): | |
|
35112
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1098 self.recall(self.text.get(prev[0], prev[1]), event) |
| 13975 | 1099 return "break" |
| 1100 next = self.text.tag_nextrange("stdin", "insert") | |
| 1101 if next and self.text.compare("insert lineend", ">=", next[0]): | |
|
35112
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1102 self.recall(self.text.get(next[0], next[1]), event) |
| 13975 | 1103 return "break" |
| 26827 | 1104 # No stdin mark -- just get the current line, less any prompt |
|
35891
8fd46b660e66
Merge IDLE-syntax-branch r39668:41449 into trunk
Kurt B. Kaiser <kbk@shore.net>
parents:
35504
diff
changeset
|
1105 indices = self.text.tag_nextrange("console", "insert linestart") |
|
8fd46b660e66
Merge IDLE-syntax-branch r39668:41449 into trunk
Kurt B. Kaiser <kbk@shore.net>
parents:
35504
diff
changeset
|
1106 if indices and \ |
|
8fd46b660e66
Merge IDLE-syntax-branch r39668:41449 into trunk
Kurt B. Kaiser <kbk@shore.net>
parents:
35504
diff
changeset
|
1107 self.text.compare(indices[0], "<=", "insert linestart"): |
|
8fd46b660e66
Merge IDLE-syntax-branch r39668:41449 into trunk
Kurt B. Kaiser <kbk@shore.net>
parents:
35504
diff
changeset
|
1108 self.recall(self.text.get(indices[1], "insert lineend"), event) |
|
8fd46b660e66
Merge IDLE-syntax-branch r39668:41449 into trunk
Kurt B. Kaiser <kbk@shore.net>
parents:
35504
diff
changeset
|
1109 else: |
|
8fd46b660e66
Merge IDLE-syntax-branch r39668:41449 into trunk
Kurt B. Kaiser <kbk@shore.net>
parents:
35504
diff
changeset
|
1110 self.recall(self.text.get("insert linestart", "insert lineend"), event) |
| 13975 | 1111 return "break" |
| 26667 | 1112 # If we're between the beginning of the line and the iomark, i.e. |
| 26827 | 1113 # in the prompt area, move to the end of the prompt |
| 26667 | 1114 if self.text.compare("insert", "<", "iomark"): |
| 26827 | 1115 self.text.mark_set("insert", "iomark") |
| 13975 | 1116 # If we're in the current input and there's only whitespace |
| 1117 # beyond the cursor, erase that whitespace first | |
| 1118 s = self.text.get("insert", "end-1c") | |
| 25310 | 1119 if s and not s.strip(): |
| 13975 | 1120 self.text.delete("insert", "end-1c") |
| 1121 # If we're in the current input before its last line, | |
| 1122 # insert a newline right at the insert point | |
| 1123 if self.text.compare("insert", "<", "end-1c linestart"): | |
| 26667 | 1124 self.newline_and_indent_event(event) |
| 13975 | 1125 return "break" |
| 1126 # We're in the last line; append a newline and submit it | |
| 1127 self.text.mark_set("insert", "end-1c") | |
| 1128 if self.reading: | |
| 1129 self.text.insert("insert", "\n") | |
| 1130 self.text.see("insert") | |
| 1131 else: | |
| 26667 | 1132 self.newline_and_indent_event(event) |
| 13975 | 1133 self.text.tag_add("stdin", "iomark", "end-1c") |
| 1134 self.text.update_idletasks() | |
| 1135 if self.reading: | |
|
37045
081b4f0e81b7
Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents:
35891
diff
changeset
|
1136 self.top.quit() # Break out of recursive mainloop() |
| 13975 | 1137 else: |
| 1138 self.runit() | |
| 1139 return "break" | |
| 1140 | |
|
35112
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1141 def recall(self, s, event): |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1142 # remove leading and trailing empty or whitespace lines |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1143 s = re.sub(r'^\s*\n', '' , s) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1144 s = re.sub(r'\n\s*$', '', s) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1145 lines = s.split('\n') |
|
35112
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1146 self.text.undo_block_start() |
|
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1147 try: |
|
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1148 self.text.tag_remove("sel", "1.0", "end") |
|
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1149 self.text.mark_set("insert", "end-1c") |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1150 prefix = self.text.get("insert linestart", "insert") |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1151 if prefix.rstrip().endswith(':'): |
| 35118 | 1152 self.newline_and_indent_event(event) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1153 prefix = self.text.get("insert linestart", "insert") |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1154 self.text.insert("insert", lines[0].strip()) |
| 35118 | 1155 if len(lines) > 1: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1156 orig_base_indent = re.search(r'^([ \t]*)', lines[0]).group(0) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1157 new_base_indent = re.search(r'^([ \t]*)', prefix).group(0) |
| 35118 | 1158 for line in lines[1:]: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1159 if line.startswith(orig_base_indent): |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1160 # replace orig base indentation with new indentation |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1161 line = new_base_indent + line[len(orig_base_indent):] |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1162 self.text.insert('insert', '\n'+line.rstrip()) |
|
35112
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1163 finally: |
|
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1164 self.text.see("insert") |
|
58632092e023
<Enter> when cursor is on a previous command retrieves that command. Instead
Kurt B. Kaiser <kbk@shore.net>
parents:
34948
diff
changeset
|
1165 self.text.undo_block_stop() |
| 13975 | 1166 |
| 1167 def runit(self): | |
| 1168 line = self.text.get("iomark", "end-1c") | |
| 1169 # Strip off last newline and surrounding whitespace. | |
| 1170 # (To allow you to hit return twice to end a statement.) | |
| 1171 i = len(line) | |
| 1172 while i > 0 and line[i-1] in " \t": | |
| 1173 i = i-1 | |
| 1174 if i > 0 and line[i-1] == "\n": | |
| 1175 i = i-1 | |
| 1176 while i > 0 and line[i-1] in " \t": | |
| 1177 i = i-1 | |
| 1178 line = line[:i] | |
| 1179 more = self.interp.runsource(line) | |
| 1180 | |
| 1181 def open_stack_viewer(self, event=None): | |
| 23547 | 1182 if self.interp.rpcclt: |
| 1183 return self.interp.remote_stack_viewer() | |
| 13975 | 1184 try: |
| 1185 sys.last_traceback | |
| 1186 except: | |
| 1187 tkMessageBox.showerror("No stack trace", | |
| 1188 "There is no stack trace yet.\n" | |
| 1189 "(sys.last_traceback is not defined)", | |
| 1190 master=self.text) | |
| 1191 return | |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42571
diff
changeset
|
1192 from idlelib.StackViewer import StackBrowser |
| 13975 | 1193 sv = StackBrowser(self.root, self.flist) |
| 1194 | |
| 27074 | 1195 def view_restart_mark(self, event=None): |
| 1196 self.text.see("iomark") | |
| 1197 self.text.see("restart") | |
| 1198 | |
| 1199 def restart_shell(self, event=None): | |
|
74693
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
1200 "Callback for Run/Restart Shell Cntl-F6" |
|
1993aa091d89
#13506 Add '' to path for interactive interpreter by adding with_cwd parameter
Terry Jan Reedy <tjreedy@udel.edu>
parents:
73968
diff
changeset
|
1201 self.interp.restart_subprocess(with_cwd=True) |
| 27074 | 1202 |
| 13975 | 1203 def showprompt(self): |
| 1204 self.resetoutput() | |
| 1205 try: | |
| 1206 s = str(sys.ps1) | |
| 1207 except: | |
| 1208 s = "" | |
| 1209 self.console.write(s) | |
| 1210 self.text.mark_set("insert", "end-1c") | |
| 23547 | 1211 self.set_line_and_column() |
|
24183
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
1212 self.io.reset_undo() |
| 13975 | 1213 |
| 1214 def resetoutput(self): | |
| 1215 source = self.text.get("iomark", "end-1c") | |
| 1216 if self.history: | |
| 1217 self.history.history_store(source) | |
| 1218 if self.text.get("end-2c") != "\n": | |
| 1219 self.text.insert("end-1c", "\n") | |
| 1220 self.text.mark_set("iomark", "end-1c") | |
| 23547 | 1221 self.set_line_and_column() |
| 13975 | 1222 |
| 1223 def write(self, s, tags=()): | |
|
75641
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1224 if isinstance(s, str) and len(s) and max(s) > '\uffff': |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1225 # Tk doesn't support outputting non-BMP characters |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1226 # Let's assume what printed string is not very long, |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1227 # find first non-BMP character and construct informative |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1228 # UnicodeEncodeError exception. |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1229 for start, char in enumerate(s): |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1230 if char > '\uffff': |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1231 break |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1232 raise UnicodeEncodeError("UCS-2", char, start, start+1, |
|
c06b94c5c609
Issue #14200: Idle shell crash on printing non-BMP unicode character.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74697
diff
changeset
|
1233 'Non-BMP character not supported in Tk') |
| 27920 | 1234 try: |
| 1235 self.text.mark_gravity("iomark", "right") | |
| 1236 OutputWindow.write(self, s, tags, "iomark") | |
| 1237 self.text.mark_gravity("iomark", "left") | |
| 1238 except: | |
|
42555
3e682ae9d298
1. Catch TypeError exception when writing to OutputWindow
Kurt B. Kaiser <kbk@shore.net>
parents:
42533
diff
changeset
|
1239 raise ###pass # ### 11Aug07 KBK if we are expecting exceptions |
|
3e682ae9d298
1. Catch TypeError exception when writing to OutputWindow
Kurt B. Kaiser <kbk@shore.net>
parents:
42533
diff
changeset
|
1240 # let's find out what they are and be specific. |
| 13975 | 1241 if self.canceled: |
| 1242 self.canceled = 0 | |
|
29119
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
1243 if not use_subprocess: |
|
7875fcaae7a3
1. Restore the capability to run and debug without a subprocess.
Kurt B. Kaiser <kbk@shore.net>
parents:
29101
diff
changeset
|
1244 raise KeyboardInterrupt |
| 13975 | 1245 |
|
34212
1e8b033f91dc
The remote procedure call module rpc.py can now access data attributes of
Kurt B. Kaiser <kbk@shore.net>
parents:
33989
diff
changeset
|
1246 class PseudoFile(object): |
| 13975 | 1247 |
|
29582
ee14e5b06ed1
Idlefork patch #682347: convert Unicode strings from readline to
Martin v. Löwis <martin@v.loewis.de>
parents:
29476
diff
changeset
|
1248 def __init__(self, shell, tags, encoding=None): |
| 13975 | 1249 self.shell = shell |
| 1250 self.tags = tags | |
|
29582
ee14e5b06ed1
Idlefork patch #682347: convert Unicode strings from readline to
Martin v. Löwis <martin@v.loewis.de>
parents:
29476
diff
changeset
|
1251 self.encoding = encoding |
| 13975 | 1252 |
| 1253 def write(self, s): | |
| 1254 self.shell.write(s, self.tags) | |
| 1255 | |
|
42507
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42455
diff
changeset
|
1256 def writelines(self, lines): |
|
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42455
diff
changeset
|
1257 for line in lines: |
|
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42455
diff
changeset
|
1258 self.write(line) |
| 13975 | 1259 |
| 1260 def flush(self): | |
| 1261 pass | |
| 1262 | |
| 1263 def isatty(self): | |
| 25310 | 1264 return True |
| 13975 | 1265 |
|
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
|
1266 |
| 13975 | 1267 usage_msg = """\ |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1268 |
|
29122
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
1269 USAGE: idle [-deins] [-t title] [file]* |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
1270 idle [-dns] [-t title] (-c cmd | -r file) [arg]* |
|
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
1271 idle [-dns] [-t title] - [arg]* |
| 26959 | 1272 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1273 -h print this help message and exit |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
1274 -n run IDLE without a subprocess (see Help/IDLE Help for details) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1275 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1276 The following options will override the IDLE 'settings' configuration: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1277 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1278 -e open an edit window |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1279 -i open a shell window |
|
18649
8aa63aea7269
Implement idle command interface as suggested by GvR [idle-dev] 16 July
Kurt B. Kaiser <kbk@shore.net>
parents:
18614
diff
changeset
|
1280 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1281 The following options imply -i and will open a shell: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1282 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1283 -c cmd run the command in a shell, or |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1284 -r file run script from file |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1285 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1286 -d enable the debugger |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1287 -s run $IDLESTARTUP or $PYTHONSTARTUP before anything else |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1288 -t title set title of shell window |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1289 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1290 A default edit window will be bypassed when -c, -r, or - are used. |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1291 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1292 [arg]* are passed to the command (-c) or script (-r) in sys.argv[1:]. |
| 13975 | 1293 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1294 Examples: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1295 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1296 idle |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1297 Open an edit window or shell depending on IDLE's configuration. |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1298 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1299 idle foo.py foobar.py |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1300 Edit the files, also open a shell if configured to start with shell. |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1301 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1302 idle -est "Baz" foo.py |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1303 Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1304 window with the title "Baz". |
| 13975 | 1305 |
|
46978
55d8c35322a7
Convert a lot of print statements to print functions in docstrings,
Neal Norwitz <nnorwitz@gmail.com>
parents:
46664
diff
changeset
|
1306 idle -c "import sys; print(sys.argv)" "foo" |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1307 Open a shell window and run the command, passing "-c" in sys.argv[0] |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1308 and "foo" in sys.argv[1]. |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1309 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1310 idle -d -s -r foo.py "Hello World" |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1311 Open a shell window, run a startup script, enable the debugger, and |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1312 run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1313 sys.argv[1]. |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1314 |
|
46978
55d8c35322a7
Convert a lot of print statements to print functions in docstrings,
Neal Norwitz <nnorwitz@gmail.com>
parents:
46664
diff
changeset
|
1315 echo "import sys; print(sys.argv)" | idle - "foobar" |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1316 Open a shell window, run the script piped in, passing '' in sys.argv[0] |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1317 and "foobar" in sys.argv[1]. |
| 13975 | 1318 """ |
| 1319 | |
|
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
|
1320 def main(): |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1321 global flist, root, use_subprocess |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1322 |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
1323 use_subprocess = True |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
1324 enable_shell = True |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1325 enable_edit = False |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1326 debug = False |
|
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
|
1327 cmd = None |
|
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
|
1328 script = None |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1329 startup = False |
|
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
|
1330 try: |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
1331 opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:") |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
1332 except getopt.error as msg: |
|
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
|
1333 sys.stderr.write("Error: %s\n" % str(msg)) |
|
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
|
1334 sys.stderr.write(usage_msg) |
|
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
|
1335 sys.exit(2) |
|
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
|
1336 for o, a in opts: |
|
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
|
1337 if o == '-c': |
|
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
|
1338 cmd = a |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1339 enable_shell = True |
|
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
|
1340 if o == '-d': |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1341 debug = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1342 enable_shell = True |
|
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
|
1343 if o == '-e': |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1344 enable_edit = True |
|
52849
a014dc47b552
Merged revisions 71126 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
51087
diff
changeset
|
1345 enable_shell = False |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1346 if o == '-h': |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1347 sys.stdout.write(usage_msg) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1348 sys.exit() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1349 if o == '-i': |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1350 enable_shell = True |
|
29121
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
1351 if o == '-n': |
|
29f19460f067
1. Add a command line switch to run without the subprocess
Kurt B. Kaiser <kbk@shore.net>
parents:
29120
diff
changeset
|
1352 use_subprocess = False |
|
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
|
1353 if o == '-r': |
|
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
|
1354 script = a |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1355 if os.path.isfile(script): |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1356 pass |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1357 else: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
1358 print("No script file: ", script) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1359 sys.exit() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1360 enable_shell = True |
|
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
|
1361 if o == '-s': |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1362 startup = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1363 enable_shell = True |
|
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
|
1364 if o == '-t': |
|
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
|
1365 PyShell.shell_title = a |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1366 enable_shell = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1367 if args and args[0] == '-': |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1368 cmd = sys.stdin.read() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1369 enable_shell = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1370 # process sys.argv and sys.path: |
|
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
|
1371 for i in range(len(sys.path)): |
|
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
|
1372 sys.path[i] = os.path.abspath(sys.path[i]) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1373 if args and args[0] == '-': |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1374 sys.argv = [''] + args[1:] |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1375 elif cmd: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1376 sys.argv = ['-c'] + args |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1377 elif script: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1378 sys.argv = [script] + args |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1379 elif args: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1380 enable_edit = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1381 pathx = [] |
|
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
|
1382 for filename in args: |
|
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
|
1383 pathx.append(os.path.dirname(filename)) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1384 for dir in pathx: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1385 dir = os.path.abspath(dir) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1386 if not dir in sys.path: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1387 sys.path.insert(0, dir) |
|
26741
cadfce66d861
When IDLE is installed and run from a startup script, the script's
Kurt B. Kaiser <kbk@shore.net>
parents:
26740
diff
changeset
|
1388 else: |
|
42881
4c78c048c3ba
os.getcwd() now returns a normal string (ie, unicode)
Neal Norwitz <nnorwitz@gmail.com>
parents:
42726
diff
changeset
|
1389 dir = os.getcwd() |
|
4c78c048c3ba
os.getcwd() now returns a normal string (ie, unicode)
Neal Norwitz <nnorwitz@gmail.com>
parents:
42726
diff
changeset
|
1390 if dir not in sys.path: |
|
26741
cadfce66d861
When IDLE is installed and run from a startup script, the script's
Kurt B. Kaiser <kbk@shore.net>
parents:
26740
diff
changeset
|
1391 sys.path.insert(0, dir) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1392 # check the IDLE settings configuration (but command line overrides) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1393 edit_start = idleConf.GetOption('main', 'General', |
| 26959 | 1394 'editor-on-startup', type='bool') |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1395 enable_edit = enable_edit or edit_start |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1396 # start editor and/or shell windows: |
|
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
|
1397 root = Tk(className="Idle") |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1398 |
|
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
|
1399 fixwordbreaks(root) |
|
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
|
1400 root.withdraw() |
|
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
|
1401 flist = PyShellFileList(root) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1402 macosxSupport.setupApp(root, flist) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1403 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1404 if enable_edit: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1405 if not (cmd or script): |
|
75846
a95b19b3b4cd
#3573: idle now doesn't hungs if launched as: idle -e <directory>
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74696
diff
changeset
|
1406 for filename in args[:]: |
|
a95b19b3b4cd
#3573: idle now doesn't hungs if launched as: idle -e <directory>
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74696
diff
changeset
|
1407 if flist.open(filename) is None: |
|
a95b19b3b4cd
#3573: idle now doesn't hungs if launched as: idle -e <directory>
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74696
diff
changeset
|
1408 # filename is a directory actually, disconsider it |
|
a95b19b3b4cd
#3573: idle now doesn't hungs if launched as: idle -e <directory>
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
74696
diff
changeset
|
1409 args.remove(filename) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1410 if not args: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1411 flist.new() |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
1412 if enable_shell: |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1413 shell = flist.open_shell() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1414 if not shell: |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
1415 return # couldn't open shell |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1416 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1417 if macosxSupport.runningAsOSXApp() and flist.dict: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1418 # On OSX: when the user has double-clicked on a file that causes |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1419 # IDLE to be launched the shell window will open just in front of |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1420 # the file she wants to see. Lower the interpreter window when |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1421 # there are open files. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1422 shell.top.lower() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1423 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1424 shell = flist.pyshell |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1425 # handle remaining options: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1426 if debug: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1427 shell.open_debugger() |
|
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
|
1428 if startup: |
|
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
|
1429 filename = os.environ.get("IDLESTARTUP") or \ |
|
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
|
1430 os.environ.get("PYTHONSTARTUP") |
|
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
|
1431 if filename and os.path.isfile(filename): |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1432 shell.interp.execfile(filename) |
|
31412
266f226f471d
Added a Tk error dialog to run.py inform the user if the subprocess can't
Kurt B. Kaiser <kbk@shore.net>
parents:
31013
diff
changeset
|
1433 if shell and cmd or script: |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1434 shell.interp.runcommand("""if 1: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1435 import sys as _sys |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
1436 _sys.argv = %r |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1437 del _sys |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
31414
diff
changeset
|
1438 \n""" % (sys.argv,)) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1439 if cmd: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1440 shell.interp.execsource(cmd) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1441 elif script: |
|
29122
c7dfda993b2f
1. When a module is run from an EditorWindow, if its directory is not in
Kurt B. Kaiser <kbk@shore.net>
parents:
29121
diff
changeset
|
1442 shell.interp.prepend_syspath(script) |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1443 shell.interp.execfile(script) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1444 |
|
67595
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1445 # Check for problematic OS X Tk versions and print a warning message |
|
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1446 # in the IDLE shell window; this is less intrusive than always opening |
|
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1447 # a separate window. |
|
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1448 tkversionwarning = macosxSupport.tkVersionWarning(root) |
|
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1449 if tkversionwarning: |
|
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1450 shell.interp.runcommand(''.join(("print('", tkversionwarning, "')"))) |
|
18ab8e0e6702
#10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5,
Ned Deily <nad@acm.org>
parents:
63175
diff
changeset
|
1451 |
|
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
|
1452 root.mainloop() |
|
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
|
1453 root.destroy() |
|
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
|
1454 |
| 13975 | 1455 if __name__ == "__main__": |
|
29476
51060b169b32
Support testing in .../Lib/idlelib when calling <python PyShell.py>
Kurt B. Kaiser <kbk@shore.net>
parents:
29452
diff
changeset
|
1456 sys.modules['PyShell'] = sys.modules['__main__'] |
| 13975 | 1457 main() |
