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