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