Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/PyShell.py @ 26774:89dd74f7ae32 legacy-trunk
M PyShell.py
M idle
M idle.py
M idle.pyw
M setup.py
Switch back to installing IDLE as a package. The IDLE GUI and the
subprocess will both attempt to start up via the package mechanism, but if
IDLE is not yet installed it is possible to run by calling python idle.py
in the IDLE source directory, or to add the source directory to sys.path.
One advantage of doing it this way is IDLE stays off sys.path.
Developed in collaboration with Tony Lownds.
| author | Kurt B. Kaiser <kbk@shore.net> |
|---|---|
| date | Tue, 24 Dec 2002 06:36:19 +0000 |
| parents | 240fdbef8c60 |
| children | 143922a40fac |
| 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: |
| 26774 | 322 w = ['-W' + s for s in sys.warnoptions] |
| 323 # Maybe IDLE is installed and is being accessed via sys.path, | |
| 324 # or maybe it's not installed and the idle.py script is being | |
| 325 # run from the IDLE source directory. | |
| 326 if __name__ == 'idlelib.PyShell': | |
| 327 command = "__import__('idlelib.run').run.main()" | |
| 328 else: | |
| 329 command = "__import__('run').main()" | |
| 330 return [sys.executable] + w + ["-c", command, str(self.port)] | |
|
25480
9d50bc831bca
Finding a suitable interpreter to spawn needed tweaking on the Mac
Tony Lownds <tony@lownds.com>
parents:
25346
diff
changeset
|
331 |
| 25123 | 332 def start_subprocess(self): |
| 333 addr = ("localhost", self.port) | |
| 334 self.spawn_subprocess() | |
|
24559
f059d5435d65
GvR provided solution to the socket rebinding timeout problem.
Kurt B. Kaiser <kbk@shore.net>
parents:
24386
diff
changeset
|
335 # 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
|
336 for i in range(6): |
| 23547 | 337 time.sleep(i) |
| 338 try: | |
| 339 self.rpcclt = rpc.RPCClient(addr) | |
| 340 break | |
| 341 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
|
342 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
|
343 print>>sys.__stderr__, ". ", |
|
0e27b67247da
Reverse the RPC socket connection: Python execution server connects to
Kurt B. Kaiser <kbk@shore.net>
parents:
24183
diff
changeset
|
344 else: |
|
0e27b67247da
Reverse the RPC socket connection: Python execution server connects to
Kurt B. Kaiser <kbk@shore.net>
parents:
24183
diff
changeset
|
345 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
|
346 + ", retrying..." |
| 23547 | 347 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
|
348 display_port_binding_error() |
|
26772
240fdbef8c60
IDLE should exit if it fails to connect with the execution server
Kurt B. Kaiser <kbk@shore.net>
parents:
26771
diff
changeset
|
349 sys.exit() |
|
24386
0e27b67247da
Reverse the RPC socket connection: Python execution server connects to
Kurt B. Kaiser <kbk@shore.net>
parents:
24183
diff
changeset
|
350 # 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
|
351 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
|
352 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
|
353 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
|
354 self.rpcclt.register("stderr", self.tkconsole.stderr) |
| 23547 | 355 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
|
356 self.transfer_path() |
| 23547 | 357 self.poll_subprocess() |
| 358 | |
| 25123 | 359 def restart_subprocess(self): |
| 360 # close only the subprocess debugger | |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
361 debug = self.getdebugger() |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
362 if debug: |
| 25123 | 363 RemoteDebugger.close_subprocess_debugger(self.rpcclt) |
| 364 # kill subprocess, spawn a new one, accept connection | |
| 365 self.rpcclt.close() | |
| 366 self.spawn_subprocess() | |
| 367 self.rpcclt.accept() | |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
368 self.transfer_path() |
| 25123 | 369 # restart remote debugger |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
370 if debug: |
| 25123 | 371 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
|
372 # reload remote debugger breakpoints for all PyShellEditWindows |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
373 debug.load_breakpoints() |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
374 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
375 def transfer_path(self): |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
376 self.runcommand("""if 1: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
377 import sys as _sys |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
378 _sys.path = %s |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
379 del _sys |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
380 \n""" % `sys.path`) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
381 |
| 23547 | 382 active_seq = None |
| 383 | |
| 384 def poll_subprocess(self): | |
| 385 clt = self.rpcclt | |
| 386 if clt is None: | |
| 387 return | |
| 388 response = clt.pollresponse(self.active_seq) | |
| 26557 | 389 # Reschedule myself in 50 ms |
| 23547 | 390 self.tkconsole.text.after(50, self.poll_subprocess) |
| 391 if response: | |
| 392 self.tkconsole.resetoutput() | |
| 393 self.active_seq = None | |
| 394 how, what = response | |
| 395 file = self.tkconsole.console | |
| 396 if how == "OK": | |
| 397 if what is not None: | |
| 398 print >>file, `what` | |
| 399 elif how == "EXCEPTION": | |
| 400 mod, name, args, tb = what | |
| 401 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
|
402 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
|
403 self.cleanup_traceback(tb, exclude) |
| 23547 | 404 traceback.print_list(tb, file=file) |
| 26557 | 405 # try to reinstantiate the exception, stuff in the args: |
| 406 try: | |
| 407 etype = eval(mod + '.' + name) | |
| 408 val = etype() | |
| 409 val.args = args | |
| 410 except TypeError: # string exception! | |
| 411 etype = name | |
| 412 val = args | |
| 413 lines = traceback.format_exception_only(etype, val) | |
| 414 for line in lines[:-1]: | |
| 415 traceback._print(file, line, '') | |
| 416 traceback._print(file, lines[-1], '') | |
| 23547 | 417 if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"): |
| 418 self.remote_stack_viewer() | |
| 419 elif how == "ERROR": | |
| 26557 | 420 errmsg = "PyShell.ModifiedInterpreter: Subprocess ERROR:\n" |
| 421 print >>sys.__stderr__, errmsg, what | |
| 422 print >>file, errmsg, what | |
| 23547 | 423 self.tkconsole.endexecuting() |
| 424 | |
|
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
|
425 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
|
426 "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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 |
| 23547 | 449 def kill_subprocess(self): |
| 450 clt = self.rpcclt | |
| 451 self.rpcclt = None | |
| 452 if clt is not None: | |
| 453 clt.close() | |
| 454 | |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
455 debugger = None |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
456 |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
457 def setdebugger(self, debugger): |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
458 self.debugger = debugger |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
459 |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
460 def getdebugger(self): |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
461 return self.debugger |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
462 |
| 23547 | 463 def remote_stack_viewer(self): |
| 464 import RemoteObjectBrowser | |
| 465 oid = self.rpcclt.remotecall("exec", "stackviewer", ("flist",), {}) | |
| 466 if oid is None: | |
| 467 self.tkconsole.root.bell() | |
| 468 return | |
| 469 item = RemoteObjectBrowser.StubObjectTreeItem(self.rpcclt, oid) | |
| 470 from TreeWidget import ScrolledCanvas, TreeNode | |
| 471 top = Toplevel(self.tkconsole.root) | |
| 472 sc = ScrolledCanvas(top, bg="white", highlightthickness=0) | |
| 473 sc.frame.pack(expand=1, fill="both") | |
| 474 node = TreeNode(sc.canvas, None, item) | |
| 475 node.expand() | |
| 476 # XXX Should GC the remote tree when closing the window | |
| 477 | |
| 13975 | 478 gid = 0 |
| 479 | |
| 480 def execsource(self, source): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
481 "Like runsource() but assumes complete exec source" |
| 13975 | 482 filename = self.stuffsource(source) |
| 483 self.execfile(filename, source) | |
| 484 | |
| 485 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
|
486 "Execute an existing file" |
| 13975 | 487 if source is None: |
| 488 source = open(filename, "r").read() | |
| 489 try: | |
| 490 code = compile(source, filename, "exec") | |
| 491 except (OverflowError, SyntaxError): | |
| 492 self.tkconsole.resetoutput() | |
| 26557 | 493 console = self.tkconsole.console |
| 494 print >>console, 'Traceback (most recent call last):' | |
| 13975 | 495 InteractiveInterpreter.showsyntaxerror(self, filename) |
| 26468 | 496 self.tkconsole.showprompt() |
| 13975 | 497 else: |
| 498 self.runcode(code) | |
| 499 | |
| 500 def runsource(self, source): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
501 "Extend base class method: Stuff the source in the line cache first" |
| 13975 | 502 filename = self.stuffsource(source) |
| 503 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
|
504 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
|
505 warnings.filterwarnings(action="error", category=SyntaxWarning) |
| 25310 | 506 if isinstance(source, types.UnicodeType): |
| 507 import IOBinding | |
| 508 try: | |
| 509 source = source.encode(IOBinding.encoding) | |
| 510 except UnicodeError: | |
| 511 self.tkconsole.resetoutput() | |
| 512 self.write("Unsupported characters in input") | |
| 513 return | |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
514 try: |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
515 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
|
516 finally: |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
517 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
|
518 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
|
519 self.save_warnings_filters = None |
| 13975 | 520 |
| 521 def stuffsource(self, source): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
522 "Stuff source in the filename cache" |
| 13975 | 523 filename = "<pyshell#%d>" % self.gid |
| 524 self.gid = self.gid + 1 | |
| 25310 | 525 lines = source.split("\n") |
| 13975 | 526 linecache.cache[filename] = len(source)+1, 0, lines, filename |
| 527 return filename | |
| 25310 | 528 |
| 13975 | 529 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
|
530 """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
|
531 |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
532 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
|
533 with a caret. |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
534 |
|
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
535 """ |
| 13975 | 536 text = self.tkconsole.text |
| 537 stuff = self.unpackerror() | |
| 26468 | 538 if stuff: |
| 539 msg, lineno, offset, line = stuff | |
| 540 if lineno == 1: | |
| 541 pos = "iomark + %d chars" % (offset-1) | |
| 542 else: | |
| 543 pos = "iomark linestart + %d lines + %d chars" % \ | |
| 544 (lineno-1, offset-1) | |
| 545 text.tag_add("ERROR", pos) | |
| 546 text.see(pos) | |
| 547 char = text.get(pos) | |
| 548 if char and char in IDENTCHARS: | |
| 549 text.tag_add("ERROR", pos + " wordstart", pos) | |
| 550 self.tkconsole.resetoutput() | |
| 551 self.write("SyntaxError: %s\n" % str(msg)) | |
| 552 else: | |
| 13975 | 553 self.tkconsole.resetoutput() |
| 554 InteractiveInterpreter.showsyntaxerror(self, filename) | |
| 26468 | 555 self.tkconsole.showprompt() |
| 13975 | 556 |
| 557 def unpackerror(self): | |
| 558 type, value, tb = sys.exc_info() | |
| 559 ok = type is SyntaxError | |
| 560 if ok: | |
| 561 try: | |
| 562 msg, (dummy_filename, lineno, offset, line) = value | |
| 563 except: | |
| 564 ok = 0 | |
| 565 if ok: | |
| 566 return msg, lineno, offset, line | |
| 567 else: | |
| 568 return None | |
| 569 | |
| 570 def showtraceback(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
571 "Extend base class method to reset output properly" |
| 13975 | 572 self.tkconsole.resetoutput() |
| 573 self.checklinecache() | |
| 574 InteractiveInterpreter.showtraceback(self) | |
| 23547 | 575 if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"): |
| 576 self.tkconsole.open_stack_viewer() | |
| 13975 | 577 |
| 578 def checklinecache(self): | |
| 579 c = linecache.cache | |
| 580 for key in c.keys(): | |
| 581 if key[:1] + key[-1:] != "<>": | |
| 582 del c[key] | |
| 583 | |
| 25123 | 584 def display_executing_dialog(self): |
| 585 tkMessageBox.showerror( | |
| 586 "Already executing", | |
| 587 "The Python Shell window is already executing a command; " | |
| 588 "please wait until it is finished.", | |
| 589 master=self.tkconsole.text) | |
| 590 | |
| 23547 | 591 def runcommand(self, code): |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
592 "Run the code without invoking the debugger" |
| 23547 | 593 # The code better not raise an exception! |
| 594 if self.tkconsole.executing: | |
|
26471
99c78cf95610
Add missing self for method call
Neal Norwitz <nnorwitz@gmail.com>
parents:
26468
diff
changeset
|
595 self.display_executing_dialog() |
| 23547 | 596 return 0 |
| 597 if self.rpcclt: | |
| 598 self.rpcclt.remotecall("exec", "runcode", (code,), {}) | |
| 599 else: | |
| 600 exec code in self.locals | |
| 601 return 1 | |
| 602 | |
| 13975 | 603 def runcode(self, code): |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
604 "Override base class method" |
| 23547 | 605 if self.tkconsole.executing: |
|
26471
99c78cf95610
Add missing self for method call
Neal Norwitz <nnorwitz@gmail.com>
parents:
26468
diff
changeset
|
606 self.display_executing_dialog() |
| 23547 | 607 return |
| 608 self.checklinecache() | |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
609 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
|
610 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
|
611 self.save_warnings_filters = None |
| 13975 | 612 debugger = self.debugger |
| 23547 | 613 if not debugger and self.rpcclt is not None: |
| 614 self.tkconsole.beginexecuting() | |
| 615 self.active_seq = self.rpcclt.asynccall("exec", "runcode", | |
| 616 (code,), {}) | |
| 617 return | |
| 13975 | 618 try: |
| 619 self.tkconsole.beginexecuting() | |
| 620 try: | |
| 621 if debugger: | |
| 622 debugger.run(code, self.locals) | |
| 623 else: | |
| 624 exec code in self.locals | |
| 625 except SystemExit: | |
| 626 if tkMessageBox.askyesno( | |
| 627 "Exit?", | |
| 628 "Do you want to exit altogether?", | |
| 629 default="yes", | |
| 630 master=self.tkconsole.text): | |
| 631 raise | |
| 632 else: | |
| 633 self.showtraceback() | |
| 634 except: | |
| 635 self.showtraceback() | |
| 636 finally: | |
| 637 self.tkconsole.endexecuting() | |
| 638 | |
| 639 def write(self, s): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
640 "Override base class method" |
| 13975 | 641 self.tkconsole.console.write(s) |
| 642 | |
| 643 class PyShell(OutputWindow): | |
| 644 | |
| 645 shell_title = "Python Shell" | |
| 646 | |
| 647 # Override classes | |
| 648 ColorDelegator = ModifiedColorDelegator | |
| 649 UndoDelegator = ModifiedUndoDelegator | |
| 650 | |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
651 # Override menus |
|
24183
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
652 menu_specs = [ |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
653 ("file", "_File"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
654 ("edit", "_Edit"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
655 ("debug", "_Debug"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
656 ("settings", "_Settings"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
657 ("windows", "_Windows"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
658 ("help", "_Help"), |
|
1723bcdc1e85
1. Prevent Undo before IOmark in PyShell.PyShell
Kurt B. Kaiser <kbk@shore.net>
parents:
23995
diff
changeset
|
659 ] |
| 13975 | 660 |
| 661 # New classes | |
| 662 from IdleHistory import History | |
| 663 | |
| 664 def __init__(self, flist=None): | |
| 665 self.interp = ModifiedInterpreter(self) | |
| 666 if flist is None: | |
| 667 root = Tk() | |
| 668 fixwordbreaks(root) | |
| 669 root.withdraw() | |
| 670 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
|
671 # |
| 13975 | 672 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
|
673 # |
| 13975 | 674 import __builtin__ |
| 675 __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
|
676 # |
|
25261
4b6185128814
MERGE DS_RPC_BRANCH into MAIN
Kurt B. Kaiser <kbk@shore.net>
parents:
25123
diff
changeset
|
677 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
|
678 # |
| 13975 | 679 text = self.text |
| 680 text.configure(wrap="char") | |
| 681 text.bind("<<newline-and-indent>>", self.enter_callback) | |
| 682 text.bind("<<plain-newline-and-indent>>", self.linefeed_callback) | |
| 683 text.bind("<<interrupt-execution>>", self.cancel_callback) | |
| 684 text.bind("<<beginning-of-line>>", self.home_callback) | |
| 685 text.bind("<<end-of-file>>", self.eof_callback) | |
| 686 text.bind("<<open-stack-viewer>>", self.open_stack_viewer) | |
| 687 text.bind("<<toggle-debugger>>", self.toggle_debugger) | |
| 688 text.bind("<<open-python-shell>>", self.flist.open_shell) | |
| 689 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
|
690 # |
| 13975 | 691 self.save_stdout = sys.stdout |
| 692 self.save_stderr = sys.stderr | |
| 693 self.save_stdin = sys.stdin | |
| 23547 | 694 self.stdout = PseudoFile(self, "stdout") |
| 695 self.stderr = PseudoFile(self, "stderr") | |
| 13975 | 696 self.console = PseudoFile(self, "console") |
| 23547 | 697 if not use_subprocess: |
| 698 sys.stdout = self.stdout | |
| 699 sys.stderr = self.stderr | |
| 700 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
|
701 # |
| 13975 | 702 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
|
703 # |
| 23547 | 704 if use_subprocess: |
| 25123 | 705 self.interp.start_subprocess() |
| 23547 | 706 |
| 13975 | 707 reading = 0 |
| 708 executing = 0 | |
| 709 canceled = 0 | |
| 710 endoffile = 0 | |
| 711 | |
| 712 def toggle_debugger(self, event=None): | |
| 713 if self.executing: | |
| 714 tkMessageBox.showerror("Don't debug now", | |
| 715 "You can only toggle the debugger when idle", | |
| 716 master=self.text) | |
| 717 self.set_debugger_indicator() | |
| 718 return "break" | |
| 719 else: | |
| 720 db = self.interp.getdebugger() | |
| 721 if db: | |
| 722 self.close_debugger() | |
| 723 else: | |
| 724 self.open_debugger() | |
| 725 | |
| 726 def set_debugger_indicator(self): | |
| 727 db = self.interp.getdebugger() | |
| 728 self.setvar("<<toggle-debugger>>", not not db) | |
| 729 | |
| 730 def toggle_jit_stack_viewer( self, event=None): | |
| 731 pass # All we need is the variable | |
| 732 | |
| 733 def close_debugger(self): | |
| 734 db = self.interp.getdebugger() | |
| 735 if db: | |
| 736 self.interp.setdebugger(None) | |
| 737 db.close() | |
|
23995
41468f9353ce
Shutdown subprocess debugger and associated Proxies/Adapters when closing
Kurt B. Kaiser <kbk@shore.net>
parents:
23969
diff
changeset
|
738 if self.interp.rpcclt: |
|
41468f9353ce
Shutdown subprocess debugger and associated Proxies/Adapters when closing
Kurt B. Kaiser <kbk@shore.net>
parents:
23969
diff
changeset
|
739 RemoteDebugger.close_remote_debugger(self.interp.rpcclt) |
| 13975 | 740 self.resetoutput() |
| 741 self.console.write("[DEBUG OFF]\n") | |
| 742 sys.ps1 = ">>> " | |
| 743 self.showprompt() | |
| 744 self.set_debugger_indicator() | |
| 745 | |
| 746 def open_debugger(self): | |
|
23876
832f0501148b
Polish RemoteDebugger code.
Kurt B. Kaiser <kbk@shore.net>
parents:
23784
diff
changeset
|
747 # 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
|
748 # 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
|
749 # with open_remote_debugger? |
| 23547 | 750 if self.interp.rpcclt: |
| 751 return self.open_remote_debugger() | |
| 13975 | 752 import Debugger |
| 753 self.interp.setdebugger(Debugger.Debugger(self)) | |
| 754 sys.ps1 = "[DEBUG ON]\n>>> " | |
| 755 self.showprompt() | |
| 756 self.set_debugger_indicator() | |
| 757 | |
| 23547 | 758 def open_remote_debugger(self): |
| 759 gui = RemoteDebugger.start_remote_debugger(self.interp.rpcclt, self) | |
| 760 self.interp.setdebugger(gui) | |
|
25894
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
761 # Load all PyShellEditorWindow breakpoints: |
|
19500c9b58c1
Implement Restoring Breakpoints in Subprocess Debugger
Kurt B. Kaiser <kbk@shore.net>
parents:
25691
diff
changeset
|
762 gui.load_breakpoints() |
| 23547 | 763 sys.ps1 = "[DEBUG ON]\n>>> " |
| 764 self.showprompt() | |
| 765 self.set_debugger_indicator() | |
| 766 | |
| 13975 | 767 def beginexecuting(self): |
|
23995
41468f9353ce
Shutdown subprocess debugger and associated Proxies/Adapters when closing
Kurt B. Kaiser <kbk@shore.net>
parents:
23969
diff
changeset
|
768 "Helper for ModifiedInterpreter" |
| 13975 | 769 self.resetoutput() |
| 770 self.executing = 1 | |
| 771 ##self._cancel_check = self.cancel_check | |
| 772 ##sys.settrace(self._cancel_check) | |
| 773 | |
| 774 def endexecuting(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
775 "Helper for ModifiedInterpreter" |
| 13975 | 776 ##sys.settrace(None) |
| 777 ##self._cancel_check = None | |
| 778 self.executing = 0 | |
| 779 self.canceled = 0 | |
| 23547 | 780 self.showprompt() |
| 13975 | 781 |
| 782 def close(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
783 "Extend EditorWindow.close()" |
| 13975 | 784 if self.executing: |
| 785 # XXX Need to ask a question here | |
| 786 if not tkMessageBox.askokcancel( | |
| 787 "Kill?", | |
| 788 "The program is still running; do you want to kill it?", | |
| 789 default="ok", | |
| 790 master=self.text): | |
| 791 return "cancel" | |
| 792 self.canceled = 1 | |
| 793 if self.reading: | |
| 794 self.top.quit() | |
| 795 return "cancel" | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
796 return EditorWindow.close(self) |
| 13975 | 797 |
| 798 def _close(self): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
799 "Extend EditorWindow._close(), shut down debugger and execution server" |
| 13975 | 800 self.close_debugger() |
| 23547 | 801 self.interp.kill_subprocess() |
| 13975 | 802 # Restore std streams |
| 803 sys.stdout = self.save_stdout | |
| 804 sys.stderr = self.save_stderr | |
| 805 sys.stdin = self.save_stdin | |
| 806 # Break cycles | |
| 807 self.interp = None | |
| 808 self.console = None | |
| 809 self.flist.pyshell = None | |
| 810 self.history = None | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
811 EditorWindow._close(self) |
| 13975 | 812 |
| 813 def ispythonsource(self, filename): | |
|
23969
edd7c0146ac8
Clear associated breakpoints when closing an edit window.
Kurt B. Kaiser <kbk@shore.net>
parents:
23932
diff
changeset
|
814 "Override EditorWindow method: never remove the colorizer" |
| 25310 | 815 return True |
| 13975 | 816 |
| 817 def short_title(self): | |
| 818 return self.shell_title | |
| 819 | |
|
18560
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
820 COPYRIGHT = \ |
|
12e7ad108229
cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
821 '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
|
822 |
| 13975 | 823 def begin(self): |
| 824 self.resetoutput() | |
| 26747 | 825 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
|
826 (sys.version, sys.platform, self.COPYRIGHT, |
| 13975 | 827 idlever.IDLE_VERSION)) |
| 828 try: | |
| 829 sys.ps1 | |
| 830 except AttributeError: | |
| 831 sys.ps1 = ">>> " | |
| 832 self.showprompt() | |
| 833 import Tkinter | |
| 834 Tkinter._default_root = None | |
| 835 | |
| 836 def interact(self): | |
| 837 self.begin() | |
| 838 self.top.mainloop() | |
| 839 | |
| 840 def readline(self): | |
| 841 save = self.reading | |
| 842 try: | |
| 843 self.reading = 1 | |
| 844 self.top.mainloop() | |
| 845 finally: | |
| 846 self.reading = save | |
| 847 line = self.text.get("iomark", "end-1c") | |
| 848 self.resetoutput() | |
| 849 if self.canceled: | |
| 850 self.canceled = 0 | |
| 851 raise KeyboardInterrupt | |
| 852 if self.endoffile: | |
| 853 self.endoffile = 0 | |
| 854 return "" | |
| 855 return line | |
| 856 | |
| 857 def isatty(self): | |
| 25310 | 858 return True |
| 13975 | 859 |
| 860 def cancel_callback(self, event): | |
| 861 try: | |
| 862 if self.text.compare("sel.first", "!=", "sel.last"): | |
| 863 return # Active selection -- always use default binding | |
| 864 except: | |
| 865 pass | |
| 866 if not (self.executing or self.reading): | |
| 867 self.resetoutput() | |
| 868 self.write("KeyboardInterrupt\n") | |
| 869 self.showprompt() | |
| 870 return "break" | |
| 871 self.endoffile = 0 | |
| 872 if self.reading: | |
| 23547 | 873 self.canceled = 1 |
| 13975 | 874 self.top.quit() |
| 23547 | 875 elif (self.executing and self.interp.rpcclt and |
| 876 self.interp.rpcpid and hasattr(os, "kill")): | |
| 877 try: | |
| 878 from signal import SIGINT | |
| 879 except ImportError: | |
| 880 SIGINT = 2 | |
| 881 os.kill(self.interp.rpcpid, SIGINT) | |
| 882 else: | |
| 883 self.canceled = 1 | |
| 13975 | 884 return "break" |
| 885 | |
| 886 def eof_callback(self, event): | |
| 887 if self.executing and not self.reading: | |
| 888 return # Let the default binding (delete next char) take over | |
| 889 if not (self.text.compare("iomark", "==", "insert") and | |
| 890 self.text.compare("insert", "==", "end-1c")): | |
| 891 return # Let the default binding (delete next char) take over | |
| 892 if not self.executing: | |
| 893 self.resetoutput() | |
| 894 self.close() | |
| 895 else: | |
| 896 self.canceled = 0 | |
| 897 self.endoffile = 1 | |
| 898 self.top.quit() | |
| 899 return "break" | |
| 900 | |
| 901 def home_callback(self, event): | |
| 902 if event.state != 0 and event.keysym == "Home": | |
| 903 return # <Modifier-Home>; fall back to class binding | |
| 904 if self.text.compare("iomark", "<=", "insert") and \ | |
| 905 self.text.compare("insert linestart", "<=", "iomark"): | |
| 906 self.text.mark_set("insert", "iomark") | |
| 907 self.text.tag_remove("sel", "1.0", "end") | |
| 908 self.text.see("insert") | |
| 909 return "break" | |
| 910 | |
| 911 def linefeed_callback(self, event): | |
| 912 # Insert a linefeed without entering anything (still autoindented) | |
| 913 if self.reading: | |
| 914 self.text.insert("insert", "\n") | |
| 915 self.text.see("insert") | |
| 916 else: | |
| 26667 | 917 self.newline_and_indent_event(event) |
| 13975 | 918 return "break" |
| 919 | |
| 920 def enter_callback(self, event): | |
| 921 if self.executing and not self.reading: | |
| 922 return # Let the default binding (insert '\n') take over | |
| 923 # If some text is selected, recall the selection | |
| 924 # (but only if this before the I/O mark) | |
| 925 try: | |
| 926 sel = self.text.get("sel.first", "sel.last") | |
| 927 if sel: | |
| 928 if self.text.compare("sel.last", "<=", "iomark"): | |
| 929 self.recall(sel) | |
| 930 return "break" | |
| 931 except: | |
| 932 pass | |
| 933 # If we're strictly before the line containing iomark, recall | |
| 934 # the current line, less a leading prompt, less leading or | |
| 935 # trailing whitespace | |
| 936 if self.text.compare("insert", "<", "iomark linestart"): | |
| 937 # Check if there's a relevant stdin range -- if so, use it | |
| 938 prev = self.text.tag_prevrange("stdin", "insert") | |
| 939 if prev and self.text.compare("insert", "<", prev[1]): | |
| 940 self.recall(self.text.get(prev[0], prev[1])) | |
| 941 return "break" | |
| 942 next = self.text.tag_nextrange("stdin", "insert") | |
| 943 if next and self.text.compare("insert lineend", ">=", next[0]): | |
| 944 self.recall(self.text.get(next[0], next[1])) | |
| 945 return "break" | |
| 946 # No stdin mark -- just get the current line | |
| 947 self.recall(self.text.get("insert linestart", "insert lineend")) | |
| 948 return "break" | |
| 26667 | 949 # If we're between the beginning of the line and the iomark, i.e. |
| 950 # in the prompt area, complain. | |
| 951 if self.text.compare("insert", "<", "iomark"): | |
| 952 self.text.bell() | |
| 953 return "break" | |
| 13975 | 954 # If we're in the current input and there's only whitespace |
| 955 # beyond the cursor, erase that whitespace first | |
| 956 s = self.text.get("insert", "end-1c") | |
| 25310 | 957 if s and not s.strip(): |
| 13975 | 958 self.text.delete("insert", "end-1c") |
| 959 # If we're in the current input before its last line, | |
| 960 # insert a newline right at the insert point | |
| 961 if self.text.compare("insert", "<", "end-1c linestart"): | |
| 26667 | 962 self.newline_and_indent_event(event) |
| 13975 | 963 return "break" |
| 964 # We're in the last line; append a newline and submit it | |
| 965 self.text.mark_set("insert", "end-1c") | |
| 966 if self.reading: | |
| 967 self.text.insert("insert", "\n") | |
| 968 self.text.see("insert") | |
| 969 else: | |
| 26667 | 970 self.newline_and_indent_event(event) |
| 13975 | 971 self.text.tag_add("stdin", "iomark", "end-1c") |
| 972 self.text.update_idletasks() | |
| 973 if self.reading: | |
| 974 self.top.quit() # Break out of recursive mainloop() in raw_input() | |
| 975 else: | |
| 976 self.runit() | |
| 977 return "break" | |
| 978 | |
| 979 def recall(self, s): | |
| 980 if self.history: | |
| 981 self.history.recall(s) | |
| 982 | |
| 983 def runit(self): | |
| 984 line = self.text.get("iomark", "end-1c") | |
| 985 # Strip off last newline and surrounding whitespace. | |
| 986 # (To allow you to hit return twice to end a statement.) | |
| 987 i = len(line) | |
| 988 while i > 0 and line[i-1] in " \t": | |
| 989 i = i-1 | |
| 990 if i > 0 and line[i-1] == "\n": | |
| 991 i = i-1 | |
| 992 while i > 0 and line[i-1] in " \t": | |
| 993 i = i-1 | |
| 994 line = line[:i] | |
| 995 more = self.interp.runsource(line) | |
| 996 | |
| 997 def cancel_check(self, frame, what, args, | |
| 998 dooneevent=tkinter.dooneevent, | |
| 999 dontwait=tkinter.DONT_WAIT): | |
| 1000 # Hack -- use the debugger hooks to be able to handle events | |
| 1001 # and interrupt execution at any time. | |
| 1002 # This slows execution down quite a bit, so you may want to | |
| 1003 # disable this (by not calling settrace() in runcode() above) | |
| 1004 # for full-bore (uninterruptable) speed. | |
| 1005 # XXX This should become a user option. | |
| 1006 if self.canceled: | |
| 1007 return | |
| 1008 dooneevent(dontwait) | |
| 1009 if self.canceled: | |
| 1010 self.canceled = 0 | |
| 1011 raise KeyboardInterrupt | |
| 1012 return self._cancel_check | |
| 1013 | |
| 1014 def open_stack_viewer(self, event=None): | |
| 23547 | 1015 if self.interp.rpcclt: |
| 1016 return self.interp.remote_stack_viewer() | |
| 13975 | 1017 try: |
| 1018 sys.last_traceback | |
| 1019 except: | |
| 1020 tkMessageBox.showerror("No stack trace", | |
| 1021 "There is no stack trace yet.\n" | |
| 1022 "(sys.last_traceback is not defined)", | |
| 1023 master=self.text) | |
| 1024 return | |
| 1025 from StackViewer import StackBrowser | |
| 1026 sv = StackBrowser(self.root, self.flist) | |
| 1027 | |
| 1028 def showprompt(self): | |
| 1029 self.resetoutput() | |
| 1030 try: | |
| 1031 s = str(sys.ps1) | |
| 1032 except: | |
| 1033 s = "" | |
| 1034 self.console.write(s) | |
| 1035 self.text.mark_set("insert", "end-1c") | |
| 23547 | 1036 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
|
1037 self.io.reset_undo() |
| 13975 | 1038 |
| 1039 def resetoutput(self): | |
| 1040 source = self.text.get("iomark", "end-1c") | |
| 1041 if self.history: | |
| 1042 self.history.history_store(source) | |
| 1043 if self.text.get("end-2c") != "\n": | |
| 1044 self.text.insert("end-1c", "\n") | |
| 1045 self.text.mark_set("iomark", "end-1c") | |
| 23547 | 1046 self.set_line_and_column() |
| 13975 | 1047 sys.stdout.softspace = 0 |
| 1048 | |
| 1049 def write(self, s, tags=()): | |
| 1050 self.text.mark_gravity("iomark", "right") | |
| 1051 OutputWindow.write(self, s, tags, "iomark") | |
| 1052 self.text.mark_gravity("iomark", "left") | |
| 1053 if self.canceled: | |
| 1054 self.canceled = 0 | |
| 1055 raise KeyboardInterrupt | |
| 1056 | |
| 1057 class PseudoFile: | |
| 1058 | |
| 1059 def __init__(self, shell, tags): | |
| 1060 self.shell = shell | |
| 1061 self.tags = tags | |
| 23547 | 1062 self.softspace = 0 |
| 13975 | 1063 |
| 1064 def write(self, s): | |
| 1065 self.shell.write(s, self.tags) | |
| 1066 | |
| 1067 def writelines(self, l): | |
| 1068 map(self.write, l) | |
| 1069 | |
| 1070 def flush(self): | |
| 1071 pass | |
| 1072 | |
| 1073 def isatty(self): | |
| 25310 | 1074 return True |
| 13975 | 1075 |
|
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
|
1076 |
| 13975 | 1077 usage_msg = """\ |
|
26590
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 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
|
1080 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
|
1081 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
|
1082 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1083 -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
|
1084 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1085 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
|
1086 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1087 -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
|
1088 -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
|
1089 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1090 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
|
1091 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1092 -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
|
1093 -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
|
1094 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1095 -d enable the debugger |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1096 -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
|
1097 -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
|
1098 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1099 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
|
1100 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1101 [arg]* are passed to the command (-c) or script (-r) in sys.argv[1:]. |
| 13975 | 1102 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1103 Examples: |
|
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 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1106 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
|
1107 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1108 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
|
1109 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
|
1110 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1111 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
|
1112 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
|
1113 window with the title "Baz". |
| 13975 | 1114 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1115 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
|
1116 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
|
1117 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
|
1118 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1119 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
|
1120 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
|
1121 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
|
1122 sys.argv[1]. |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1123 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1124 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
|
1125 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
|
1126 and "foobar" in sys.argv[1]. |
| 13975 | 1127 """ |
| 1128 | |
|
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 def main(): |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1130 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
|
1131 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1132 enable_shell = False |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1133 enable_edit = False |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1134 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
|
1135 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
|
1136 script = None |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1137 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
|
1138 try: |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1139 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
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 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
|
1145 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
|
1146 cmd = a |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1147 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
|
1148 if o == '-d': |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1149 debug = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1150 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
|
1151 if o == '-e': |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1152 enable_edit = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1153 if o == '-h': |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1154 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
|
1155 sys.exit() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1156 if o == '-i': |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1157 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
|
1158 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
|
1159 script = a |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1160 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
|
1161 pass |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1162 else: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1163 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
|
1164 sys.exit() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1165 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
|
1166 if o == '-s': |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1167 startup = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1168 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
|
1169 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
|
1170 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
|
1171 enable_shell = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1172 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
|
1173 cmd = sys.stdin.read() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1174 enable_shell = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1175 |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1176 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
|
1177 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1178 # 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
|
1179 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
|
1180 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
|
1181 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
|
1182 sys.argv = [''] + args[1:] |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1183 elif cmd: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1184 sys.argv = ['-c'] + args |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1185 elif script: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1186 sys.argv = [script] + args |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1187 elif args: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1188 enable_edit = True |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1189 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
|
1190 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
|
1191 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
|
1192 for dir in pathx: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 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
|
1200 # 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
|
1201 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
|
1202 '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
|
1203 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
|
1204 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
|
1205 # 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
|
1206 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
|
1207 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
|
1208 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
|
1209 flist = PyShellFileList(root) |
|
26730
9b4c014b3a21
Update way a subprocess is launched for Mac OS X.
Tony Lownds <tony@lownds.com>
parents:
26693
diff
changeset
|
1210 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1211 if enable_edit: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1212 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
|
1213 for filename in args: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1214 flist.open(filename) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1215 if not args: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1216 flist.new() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1217 if enable_shell: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1218 flist.open_shell() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1219 elif enable_shell: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1220 flist.pyshell = PyShell(flist) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1221 flist.pyshell.begin() |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1222 shell = flist.pyshell |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1223 # handle remaining options: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1224 if debug: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 shell.interp.execfile(filename) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1231 if cmd or script: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1232 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
|
1233 import sys as _sys |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1234 _sys.argv = %s |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1235 del _sys |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1236 \n""" % `sys.argv`) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1237 if cmd: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1238 shell.interp.execsource(cmd) |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1239 elif script: |
|
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1240 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
|
1241 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
|
1242 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
|
1243 |
|
26590
615a25a6eb5b
Rework the command line interface, incorporating the shell/edit
Kurt B. Kaiser <kbk@shore.net>
parents:
26557
diff
changeset
|
1244 |
|
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
|
1245 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
|
1246 print """\ |
|
20306
1ca228e21a98
merged port binding error message patch
Steven M. Gava <elguavas@python.net>
parents:
18649
diff
changeset
|
1247 IDLE cannot run. |
|
1ca228e21a98
merged port binding error message patch
Steven M. Gava <elguavas@python.net>
parents:
18649
diff
changeset
|
1248 |
|
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 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
|
1250 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
|
1251 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
|
1252 |
|
1ca228e21a98
merged port binding error message patch
Steven M. Gava <elguavas@python.net>
parents:
18649
diff
changeset
|
1253 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
|
1254 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
|
1255 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
|
1256 |
|
1ca228e21a98
merged port binding error message patch
Steven M. Gava <elguavas@python.net>
parents:
18649
diff
changeset
|
1257 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
|
1258 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
|
1259 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
|
1260 """ |
| 13975 | 1261 |
| 1262 if __name__ == "__main__": | |
| 1263 main() |
