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