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