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