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