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