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