Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- evalkit_cambrian/lib/python3.10/idlelib/CREDITS.txt +47 -0
- evalkit_cambrian/lib/python3.10/idlelib/ChangeLog +1591 -0
- evalkit_cambrian/lib/python3.10/idlelib/HISTORY.txt +296 -0
- evalkit_cambrian/lib/python3.10/idlelib/NEWS2x.txt +660 -0
- evalkit_cambrian/lib/python3.10/idlelib/README.txt +290 -0
- evalkit_cambrian/lib/python3.10/idlelib/__init__.py +10 -0
- evalkit_cambrian/lib/python3.10/idlelib/__main__.py +8 -0
- evalkit_cambrian/lib/python3.10/idlelib/autocomplete.py +228 -0
- evalkit_cambrian/lib/python3.10/idlelib/autoexpand.py +96 -0
- evalkit_cambrian/lib/python3.10/idlelib/calltip.py +205 -0
- evalkit_cambrian/lib/python3.10/idlelib/calltip_w.py +201 -0
- evalkit_cambrian/lib/python3.10/idlelib/colorizer.py +384 -0
- evalkit_cambrian/lib/python3.10/idlelib/config-extensions.def +62 -0
- evalkit_cambrian/lib/python3.10/idlelib/config-highlight.def +105 -0
- evalkit_cambrian/lib/python3.10/idlelib/config-keys.def +309 -0
- evalkit_cambrian/lib/python3.10/idlelib/config-main.def +93 -0
- evalkit_cambrian/lib/python3.10/idlelib/config_key.py +354 -0
- evalkit_cambrian/lib/python3.10/idlelib/configdialog.py +0 -0
- evalkit_cambrian/lib/python3.10/idlelib/debugger.py +550 -0
- evalkit_cambrian/lib/python3.10/idlelib/debugger_r.py +393 -0
- evalkit_cambrian/lib/python3.10/idlelib/delegator.py +33 -0
- evalkit_cambrian/lib/python3.10/idlelib/dynoption.py +55 -0
- evalkit_cambrian/lib/python3.10/idlelib/editor.py +1683 -0
- evalkit_cambrian/lib/python3.10/idlelib/format.py +426 -0
- evalkit_cambrian/lib/python3.10/idlelib/help.html +1178 -0
- evalkit_cambrian/lib/python3.10/idlelib/help.py +294 -0
- evalkit_cambrian/lib/python3.10/idlelib/help_about.py +212 -0
- evalkit_cambrian/lib/python3.10/idlelib/hyperparser.py +312 -0
- evalkit_cambrian/lib/python3.10/idlelib/idle.py +14 -0
- evalkit_cambrian/lib/python3.10/idlelib/macosx.py +301 -0
- evalkit_cambrian/lib/python3.10/idlelib/multicall.py +448 -0
- evalkit_cambrian/lib/python3.10/idlelib/parenmatch.py +183 -0
- evalkit_cambrian/lib/python3.10/idlelib/pathbrowser.py +111 -0
- evalkit_cambrian/lib/python3.10/idlelib/percolator.py +118 -0
- evalkit_cambrian/lib/python3.10/idlelib/pyparse.py +589 -0
- evalkit_cambrian/lib/python3.10/idlelib/pyshell.py +1713 -0
- evalkit_cambrian/lib/python3.10/idlelib/query.py +392 -0
- evalkit_cambrian/lib/python3.10/idlelib/replace.py +307 -0
- evalkit_cambrian/lib/python3.10/idlelib/rpc.py +635 -0
- evalkit_cambrian/lib/python3.10/idlelib/run.py +642 -0
- evalkit_cambrian/lib/python3.10/idlelib/runscript.py +213 -0
- evalkit_cambrian/lib/python3.10/idlelib/scrolledlist.py +149 -0
- evalkit_cambrian/lib/python3.10/idlelib/search.py +164 -0
- evalkit_cambrian/lib/python3.10/idlelib/searchbase.py +210 -0
- evalkit_cambrian/lib/python3.10/idlelib/searchengine.py +234 -0
- evalkit_cambrian/lib/python3.10/idlelib/stackviewer.py +155 -0
- evalkit_cambrian/lib/python3.10/idlelib/statusbar.py +50 -0
- evalkit_cambrian/lib/python3.10/idlelib/textview.py +193 -0
- evalkit_cambrian/lib/python3.10/idlelib/tooltip.py +186 -0
.gitattributes
CHANGED
|
@@ -267,3 +267,4 @@ evalkit_cambrian/lib/python3.10/ensurepip/_bundled/setuptools-65.5.0-py3-none-an
|
|
| 267 |
evalkit_cambrian/lib/python3.10/tkinter/__pycache__/__init__.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 268 |
evalkit_cambrian/lib/python3.10/ensurepip/_bundled/pip-23.0.1-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
| 269 |
evalkit_cambrian/bin/lzcat filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 267 |
evalkit_cambrian/lib/python3.10/tkinter/__pycache__/__init__.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 268 |
evalkit_cambrian/lib/python3.10/ensurepip/_bundled/pip-23.0.1-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
| 269 |
evalkit_cambrian/bin/lzcat filter=lfs diff=lfs merge=lfs -text
|
| 270 |
+
evalkit_cambrian/lib/python3.10/lib2to3/tests/__pycache__/test_fixers.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
evalkit_cambrian/lib/python3.10/idlelib/CREDITS.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Guido van Rossum, as well as being the creator of the Python language, is the
|
| 2 |
+
original creator of IDLE. Other contributors prior to Version 0.8 include
|
| 3 |
+
Mark Hammond, Jeremy Hylton, Tim Peters, and Moshe Zadka.
|
| 4 |
+
|
| 5 |
+
Until Python 2.3, IDLE's development was carried out in the SF IDLEfork project. The
|
| 6 |
+
objective was to develop a version of IDLE which had an execution environment
|
| 7 |
+
which could be initialized prior to each run of user code.
|
| 8 |
+
IDLefork was merged into the Python code base in 2003.
|
| 9 |
+
|
| 10 |
+
The IDLEfork project was initiated by David Scherer, with some help from Peter
|
| 11 |
+
Schneider-Kamp and Nicholas Riley. David wrote the first version of the RPC
|
| 12 |
+
code and designed a fast turn-around environment for VPython. Guido developed
|
| 13 |
+
the RPC code and Remote Debugger currently integrated in IDLE. Bruce Sherwood
|
| 14 |
+
contributed considerable time testing and suggesting improvements.
|
| 15 |
+
|
| 16 |
+
Besides David and Guido, the main developers who were active on IDLEfork
|
| 17 |
+
are Stephen M. Gava, who implemented the configuration GUI, the new
|
| 18 |
+
configuration system, and the About dialog, and Kurt B. Kaiser, who completed
|
| 19 |
+
the integration of the RPC and remote debugger, implemented the threaded
|
| 20 |
+
subprocess, and made a number of usability enhancements.
|
| 21 |
+
|
| 22 |
+
Other contributors include Raymond Hettinger, Tony Lownds (Mac integration),
|
| 23 |
+
Neal Norwitz (code check and clean-up), Ronald Oussoren (Mac integration),
|
| 24 |
+
Noam Raphael (Code Context, Call Tips, many other patches), and Chui Tey (RPC
|
| 25 |
+
integration, debugger integration and persistent breakpoints).
|
| 26 |
+
|
| 27 |
+
Scott David Daniels, Tal Einat, Hernan Foffani, Christos Georgiou,
|
| 28 |
+
Jim Jewett, Martin v. Löwis, Jason Orendorff, Guilherme Polo, Josh Robb,
|
| 29 |
+
Nigel Rowe, Bruce Sherwood, Jeff Shute, and Weeble have submitted useful
|
| 30 |
+
patches. Thanks, guys!
|
| 31 |
+
|
| 32 |
+
Major contributors since 2005:
|
| 33 |
+
|
| 34 |
+
- 2005: Tal Einat
|
| 35 |
+
- 2010: Terry Jan Reedy (current maintainer)
|
| 36 |
+
- 2013: Roger Serwys
|
| 37 |
+
- 2014: Saimadhav Heblikar
|
| 38 |
+
- 2015: Mark Roseman
|
| 39 |
+
- 2017: Louie Lu, Cheryl Sabella, and Serhiy Storchaka
|
| 40 |
+
|
| 41 |
+
For additional details refer to NEWS.txt and Changelog.
|
| 42 |
+
|
| 43 |
+
Please contact the IDLE maintainer ([email protected]) to have yourself included
|
| 44 |
+
here if you are one of those we missed!
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
evalkit_cambrian/lib/python3.10/idlelib/ChangeLog
ADDED
|
@@ -0,0 +1,1591 @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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Please refer to the IDLEfork and IDLE CVS repositories for
|
| 2 |
+
change details subsequent to the 0.8.1 release.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
IDLEfork ChangeLog
|
| 6 |
+
==================
|
| 7 |
+
|
| 8 |
+
2001-07-20 11:35 elguavas
|
| 9 |
+
|
| 10 |
+
* README.txt, NEWS.txt: bring up to date for 0.8.1 release
|
| 11 |
+
|
| 12 |
+
2001-07-19 16:40 elguavas
|
| 13 |
+
|
| 14 |
+
* IDLEFORK.html: replaced by IDLEFORK-index.html
|
| 15 |
+
|
| 16 |
+
2001-07-19 16:39 elguavas
|
| 17 |
+
|
| 18 |
+
* IDLEFORK-index.html: updated placeholder idlefork homepage
|
| 19 |
+
|
| 20 |
+
2001-07-19 14:49 elguavas
|
| 21 |
+
|
| 22 |
+
* ChangeLog, EditorWindow.py, INSTALLATION, NEWS.txt, README.txt,
|
| 23 |
+
TODO.txt, idlever.py:
|
| 24 |
+
minor tidy-ups ready for 0.8.1 alpha tarball release
|
| 25 |
+
|
| 26 |
+
2001-07-17 15:12 kbk
|
| 27 |
+
|
| 28 |
+
* INSTALLATION, setup.py: INSTALLATION: Remove the coexist.patch
|
| 29 |
+
instructions
|
| 30 |
+
|
| 31 |
+
**************** setup.py:
|
| 32 |
+
|
| 33 |
+
Remove the idles script, add some words on IDLE Fork to the
|
| 34 |
+
long_description, and clean up some line spacing.
|
| 35 |
+
|
| 36 |
+
2001-07-17 15:01 kbk
|
| 37 |
+
|
| 38 |
+
* coexist.patch: Put this in the attic, at least for now...
|
| 39 |
+
|
| 40 |
+
2001-07-17 14:59 kbk
|
| 41 |
+
|
| 42 |
+
* PyShell.py, idle, idles: Implement idle command interface as
|
| 43 |
+
suggested by GvR [idle-dev] 16 July **************** PyShell: Added
|
| 44 |
+
functionality:
|
| 45 |
+
|
| 46 |
+
usage: idle.py [-c command] [-d] [-i] [-r script] [-s] [-t title]
|
| 47 |
+
[arg] ...
|
| 48 |
+
|
| 49 |
+
idle file(s) (without options) edit the file(s)
|
| 50 |
+
|
| 51 |
+
-c cmd run the command in a shell -d enable the
|
| 52 |
+
debugger -i open an interactive shell -i file(s) open a
|
| 53 |
+
shell and also an editor window for each file -r script run a file
|
| 54 |
+
as a script in a shell -s run $IDLESTARTUP or
|
| 55 |
+
$PYTHONSTARTUP before anything else -t title set title of shell
|
| 56 |
+
window
|
| 57 |
+
|
| 58 |
+
Remaining arguments are applied to the command (-c) or script (-r).
|
| 59 |
+
|
| 60 |
+
****************** idles: Removed the idles script, not needed
|
| 61 |
+
|
| 62 |
+
****************** idle: Removed the IdleConf references, not
|
| 63 |
+
required anymore
|
| 64 |
+
|
| 65 |
+
2001-07-16 17:08 kbk
|
| 66 |
+
|
| 67 |
+
* INSTALLATION, coexist.patch: Added installation instructions.
|
| 68 |
+
|
| 69 |
+
Added a patch which modifies idlefork so that it can co-exist with
|
| 70 |
+
"official" IDLE in the site-packages directory. This patch is not
|
| 71 |
+
necessary if only idlefork IDLE is installed. See INSTALLATION for
|
| 72 |
+
further details.
|
| 73 |
+
|
| 74 |
+
2001-07-16 15:50 kbk
|
| 75 |
+
|
| 76 |
+
* idles: Add a script "idles" which opens a Python Shell window.
|
| 77 |
+
|
| 78 |
+
The default behaviour of idlefork idle is to open an editor window
|
| 79 |
+
instead of a shell. Complex expressions may be run in a fresh
|
| 80 |
+
environment by selecting "run". There are times, however, when a
|
| 81 |
+
shell is desired. Though one can be started by "idle -t 'foo'",
|
| 82 |
+
this script is more convenient. In addition, a shell and an editor
|
| 83 |
+
window can be started in parallel by "idles -e foo.py".
|
| 84 |
+
|
| 85 |
+
2001-07-16 15:25 kbk
|
| 86 |
+
|
| 87 |
+
* PyShell.py: Call out IDLE Fork in startup message.
|
| 88 |
+
|
| 89 |
+
2001-07-16 14:00 kbk
|
| 90 |
+
|
| 91 |
+
* PyShell.py, setup.py: Add a script "idles" which opens a Python
|
| 92 |
+
Shell window.
|
| 93 |
+
|
| 94 |
+
The default behaviour of idlefork idle is to open an editor window
|
| 95 |
+
instead of a shell. Complex expressions may be run in a fresh
|
| 96 |
+
environment by selecting "run". There are times, however, when a
|
| 97 |
+
shell is desired. Though one can be started by "idle -t 'foo'",
|
| 98 |
+
this script is more convenient. In addition, a shell and an editor
|
| 99 |
+
window can be started in parallel by "idles -e foo.py".
|
| 100 |
+
|
| 101 |
+
2001-07-15 03:06 kbk
|
| 102 |
+
|
| 103 |
+
* pyclbr.py, tabnanny.py: tabnanny and pyclbr are now found in /Lib
|
| 104 |
+
|
| 105 |
+
2001-07-15 02:29 kbk
|
| 106 |
+
|
| 107 |
+
* BrowserControl.py: Remove, was retained for 1.5.2 support
|
| 108 |
+
|
| 109 |
+
2001-07-14 15:48 kbk
|
| 110 |
+
|
| 111 |
+
* setup.py: Installing Idle to site-packages via Distutils does not
|
| 112 |
+
copy the Idle help.txt file.
|
| 113 |
+
|
| 114 |
+
Ref SF Python Patch 422471
|
| 115 |
+
|
| 116 |
+
2001-07-14 15:26 kbk
|
| 117 |
+
|
| 118 |
+
* keydefs.py: py-cvs-2001_07_13 (Rev 1.3) merge
|
| 119 |
+
|
| 120 |
+
"Make copy, cut and paste events case insensitive. Reported by
|
| 121 |
+
Patrick K. O'Brien on idle-dev. (Should other bindings follow
|
| 122 |
+
suit?)" --GvR
|
| 123 |
+
|
| 124 |
+
2001-07-14 15:21 kbk
|
| 125 |
+
|
| 126 |
+
* idle.py: py-cvs-2001_07_13 (Rev 1.4) merge
|
| 127 |
+
|
| 128 |
+
"Move the action of loading the configuration to the IdleConf
|
| 129 |
+
module rather than the idle.py script. This has advantages and
|
| 130 |
+
disadvantages; the biggest advantage being that we can more easily
|
| 131 |
+
have an alternative main program." --GvR
|
| 132 |
+
|
| 133 |
+
2001-07-14 15:18 kbk
|
| 134 |
+
|
| 135 |
+
* extend.txt: py-cvs-2001_07_13 (Rev 1.4) merge
|
| 136 |
+
|
| 137 |
+
"Quick update to the extension mechanism (extend.py is gone, long
|
| 138 |
+
live config.txt)" --GvR
|
| 139 |
+
|
| 140 |
+
2001-07-14 15:15 kbk
|
| 141 |
+
|
| 142 |
+
* StackViewer.py: py-cvs-2001_07_13 (Rev 1.16) merge
|
| 143 |
+
|
| 144 |
+
"Refactored, with some future plans in mind. This now uses the new
|
| 145 |
+
gotofileline() method defined in FileList.py" --GvR
|
| 146 |
+
|
| 147 |
+
2001-07-14 15:10 kbk
|
| 148 |
+
|
| 149 |
+
* PyShell.py: py-cvs-2001_07_13 (Rev 1.34) merge
|
| 150 |
+
|
| 151 |
+
"Amazing. A very subtle change in policy in descr-branch actually
|
| 152 |
+
found a bug here. Here's the deal: Class PyShell derives from
|
| 153 |
+
class OutputWindow. Method PyShell.close() wants to invoke its
|
| 154 |
+
parent method, but because PyShell long ago was inherited from
|
| 155 |
+
class PyShellEditorWindow, it invokes
|
| 156 |
+
PyShelEditorWindow.close(self). Now, class PyShellEditorWindow
|
| 157 |
+
itself derives from class OutputWindow, and inherits the close()
|
| 158 |
+
method from there without overriding it. Under the old rules,
|
| 159 |
+
PyShellEditorWindow.close would return an unbound method restricted
|
| 160 |
+
to the class that defined the implementation of close(), which was
|
| 161 |
+
OutputWindow.close. Under the new rules, the unbound method is
|
| 162 |
+
restricted to the class whose method was requested, that is
|
| 163 |
+
PyShellEditorWindow, and this was correctly trapped as an error."
|
| 164 |
+
--GvR
|
| 165 |
+
|
| 166 |
+
2001-07-14 14:59 kbk
|
| 167 |
+
|
| 168 |
+
* PyParse.py: py-cvs-2001_07_13 (Rel 1.9) merge
|
| 169 |
+
|
| 170 |
+
"Taught IDLE's autoident parser that "yield" is a keyword that
|
| 171 |
+
begins a stmt. Along w/ the preceding change to keyword.py, making
|
| 172 |
+
all this work w/ a future-stmt just looks harder and harder."
|
| 173 |
+
--tim_one
|
| 174 |
+
|
| 175 |
+
(From Rel 1.8: "Hack to make this still work with Python 1.5.2.
|
| 176 |
+
;-( " --fdrake)
|
| 177 |
+
|
| 178 |
+
2001-07-14 14:51 kbk
|
| 179 |
+
|
| 180 |
+
* IdleConf.py: py-cvs-2001_07_13 (Rel 1.7) merge
|
| 181 |
+
|
| 182 |
+
"Move the action of loading the configuration to the IdleConf
|
| 183 |
+
module rather than the idle.py script. This has advantages and
|
| 184 |
+
disadvantages; the biggest advantage being that we can more easily
|
| 185 |
+
have an alternative main program." --GvR
|
| 186 |
+
|
| 187 |
+
2001-07-14 14:45 kbk
|
| 188 |
+
|
| 189 |
+
* FileList.py: py-cvs-2000_07_13 (Rev 1.9) merge
|
| 190 |
+
|
| 191 |
+
"Delete goodname() method, which is unused. Add gotofileline(), a
|
| 192 |
+
convenience method which I intend to use in a variant. Rename
|
| 193 |
+
test() to _test()." --GvR
|
| 194 |
+
|
| 195 |
+
This was an interesting merge. The join completely missed removing
|
| 196 |
+
goodname(), which was adjacent, but outside of, a small conflict.
|
| 197 |
+
I only caught it by comparing the 1.1.3.2/1.1.3.3 diff. CVS ain't
|
| 198 |
+
infallible.
|
| 199 |
+
|
| 200 |
+
2001-07-14 13:58 kbk
|
| 201 |
+
|
| 202 |
+
* EditorWindow.py: py-cvs-2000_07_13 (Rev 1.38) merge "Remove
|
| 203 |
+
legacy support for the BrowserControl module; the webbrowser module
|
| 204 |
+
has been included since Python 2.0, and that is the preferred
|
| 205 |
+
interface." --fdrake
|
| 206 |
+
|
| 207 |
+
2001-07-14 13:32 kbk
|
| 208 |
+
|
| 209 |
+
* EditorWindow.py, FileList.py, IdleConf.py, PyParse.py,
|
| 210 |
+
PyShell.py, StackViewer.py, extend.txt, idle.py, keydefs.py: Import
|
| 211 |
+
the 2001 July 13 23:59 GMT version of Python CVS IDLE on the
|
| 212 |
+
existing 1.1.3 vendor branch named py-cvs-vendor-branch. Release
|
| 213 |
+
tag is py-cvs-2001_07_13.
|
| 214 |
+
|
| 215 |
+
2001-07-14 12:02 kbk
|
| 216 |
+
|
| 217 |
+
* Icons/python.gif: py-cvs-rel2_1 (Rev 1.2) merge Copied py-cvs rev
|
| 218 |
+
1.2 changed file to idlefork MAIN
|
| 219 |
+
|
| 220 |
+
2001-07-14 11:58 kbk
|
| 221 |
+
|
| 222 |
+
* Icons/minusnode.gif: py-cvs-rel2_1 (Rev 1.2) merge Copied py-cvs
|
| 223 |
+
1.2 changed file to idlefork MAIN
|
| 224 |
+
|
| 225 |
+
2001-07-14 11:23 kbk
|
| 226 |
+
|
| 227 |
+
* ScrolledList.py: py-cvs-rel2_1 (rev 1.5) merge - whitespace
|
| 228 |
+
normalization
|
| 229 |
+
|
| 230 |
+
2001-07-14 11:20 kbk
|
| 231 |
+
|
| 232 |
+
* Separator.py: py-cvs-rel2_1 (Rev 1.3) merge - whitespace
|
| 233 |
+
normalization
|
| 234 |
+
|
| 235 |
+
2001-07-14 11:16 kbk
|
| 236 |
+
|
| 237 |
+
* StackViewer.py: py-cvs-rel2_1 (Rev 1.15) merge - whitespace
|
| 238 |
+
normalization
|
| 239 |
+
|
| 240 |
+
2001-07-14 11:14 kbk
|
| 241 |
+
|
| 242 |
+
* ToolTip.py: py-cvs-rel2_1 (Rev 1.2) merge - whitespace
|
| 243 |
+
normalization
|
| 244 |
+
|
| 245 |
+
2001-07-14 10:13 kbk
|
| 246 |
+
|
| 247 |
+
* PyShell.py: cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
|
| 248 |
+
|
| 249 |
+
Merged the following py-cvs revs without conflict: 1.29 Reduce
|
| 250 |
+
copyright text output at startup 1.30 Delay setting sys.args until
|
| 251 |
+
Tkinter is fully initialized 1.31 Whitespace normalization 1.32
|
| 252 |
+
Turn syntax warning into error when interactive 1.33 Fix warning
|
| 253 |
+
initialization bug
|
| 254 |
+
|
| 255 |
+
Note that module is extensively modified wrt py-cvs
|
| 256 |
+
|
| 257 |
+
2001-07-14 06:33 kbk
|
| 258 |
+
|
| 259 |
+
* PyParse.py: py-cvs-rel2_1 (Rev 1.6 - 1.8) merge Fix autoindent
|
| 260 |
+
bug and deflect Unicode from text.get()
|
| 261 |
+
|
| 262 |
+
2001-07-14 06:00 kbk
|
| 263 |
+
|
| 264 |
+
* Percolator.py: py-cvs-rel2_1 (Rev 1.3) "move "from Tkinter import
|
| 265 |
+
*" to module level" --jhylton
|
| 266 |
+
|
| 267 |
+
2001-07-14 05:57 kbk
|
| 268 |
+
|
| 269 |
+
* PathBrowser.py: py-cvs-rel2_1 (Rev 1.6) merge - whitespace
|
| 270 |
+
normalization
|
| 271 |
+
|
| 272 |
+
2001-07-14 05:49 kbk
|
| 273 |
+
|
| 274 |
+
* ParenMatch.py: cvs-py-rel2_1 (Rev 1.5) merge - whitespace
|
| 275 |
+
normalization
|
| 276 |
+
|
| 277 |
+
2001-07-14 03:57 kbk
|
| 278 |
+
|
| 279 |
+
* ObjectBrowser.py: py-cvs-rel2_1 (Rev 1.3) merge "Make the test
|
| 280 |
+
program work outside IDLE." -- GvR
|
| 281 |
+
|
| 282 |
+
2001-07-14 03:52 kbk
|
| 283 |
+
|
| 284 |
+
* MultiStatusBar.py: py-cvs-rel2_1 (Rev 1.2) merge - whitespace
|
| 285 |
+
normalization
|
| 286 |
+
|
| 287 |
+
2001-07-14 03:44 kbk
|
| 288 |
+
|
| 289 |
+
* MultiScrolledLists.py: py-cvs-rel2_1 (Rev 1.2) merge - whitespace
|
| 290 |
+
normalization
|
| 291 |
+
|
| 292 |
+
2001-07-14 03:40 kbk
|
| 293 |
+
|
| 294 |
+
* IdleHistory.py: py-cvs-rel2_1 (Rev 1.4) merge - whitespace
|
| 295 |
+
normalization
|
| 296 |
+
|
| 297 |
+
2001-07-14 03:38 kbk
|
| 298 |
+
|
| 299 |
+
* IdleConf.py: py-cvs-rel2_1 (Rev 1.6) merge - whitespace
|
| 300 |
+
normalization
|
| 301 |
+
|
| 302 |
+
2001-07-13 14:18 kbk
|
| 303 |
+
|
| 304 |
+
* IOBinding.py: py-cvs-rel2_1 (Rev 1.4) merge - move "import *" to
|
| 305 |
+
module level
|
| 306 |
+
|
| 307 |
+
2001-07-13 14:12 kbk
|
| 308 |
+
|
| 309 |
+
* FormatParagraph.py: py-cvs-rel2_1 (Rev 1.9) merge - whitespace
|
| 310 |
+
normalization
|
| 311 |
+
|
| 312 |
+
2001-07-13 14:07 kbk
|
| 313 |
+
|
| 314 |
+
* FileList.py: py-cvs-rel2_1 (Rev 1.8) merge - whitespace
|
| 315 |
+
normalization
|
| 316 |
+
|
| 317 |
+
2001-07-13 13:35 kbk
|
| 318 |
+
|
| 319 |
+
* EditorWindow.py: py-cvs-rel2_1 (Rev 1.33 - 1.37) merge
|
| 320 |
+
|
| 321 |
+
VP IDLE version depended on VP's ExecBinding.py and spawn.py to get
|
| 322 |
+
the path to the Windows Doc directory (relative to python.exe).
|
| 323 |
+
Removed this conflicting code in favor of py-cvs updates which on
|
| 324 |
+
Windows use a hard coded path relative to the location of this
|
| 325 |
+
module. py-cvs updates include support for webbrowser.py. Module
|
| 326 |
+
still has BrowserControl.py for 1.5.2 support.
|
| 327 |
+
|
| 328 |
+
At this point, the differences wrt py-cvs relate to menu
|
| 329 |
+
functionality.
|
| 330 |
+
|
| 331 |
+
2001-07-13 11:30 kbk
|
| 332 |
+
|
| 333 |
+
* ConfigParser.py: py-cvs-rel2_1 merge - Remove, lives in /Lib
|
| 334 |
+
|
| 335 |
+
2001-07-13 10:10 kbk
|
| 336 |
+
|
| 337 |
+
* Delegator.py: py-cvs-rel2_1 (Rev 1.3) merge - whitespace
|
| 338 |
+
normalization
|
| 339 |
+
|
| 340 |
+
2001-07-13 10:07 kbk
|
| 341 |
+
|
| 342 |
+
* Debugger.py: py-cvs-rel2_1 (Rev 1.15) merge - whitespace
|
| 343 |
+
normalization
|
| 344 |
+
|
| 345 |
+
2001-07-13 10:04 kbk
|
| 346 |
+
|
| 347 |
+
* ColorDelegator.py: py-cvs-rel2_1 (Rev 1.11 and 1.12) merge
|
| 348 |
+
Colorize "as" after "import" / use DEBUG instead of __debug__
|
| 349 |
+
|
| 350 |
+
2001-07-13 09:54 kbk
|
| 351 |
+
|
| 352 |
+
* ClassBrowser.py: py-cvs-rel2_1 (Rev 1.12) merge - whitespace
|
| 353 |
+
normalization
|
| 354 |
+
|
| 355 |
+
2001-07-13 09:41 kbk
|
| 356 |
+
|
| 357 |
+
* BrowserControl.py: py-cvs-rel2_1 (Rev 1.1) merge - New File -
|
| 358 |
+
Force HEAD to trunk with -f Note: browser.py was renamed
|
| 359 |
+
BrowserControl.py 10 May 2000. It provides a collection of classes
|
| 360 |
+
and convenience functions to control external browsers "for 1.5.2
|
| 361 |
+
support". It was removed from py-cvs 18 April 2001.
|
| 362 |
+
|
| 363 |
+
2001-07-13 09:10 kbk
|
| 364 |
+
|
| 365 |
+
* CallTips.py: py-cvs-rel2_1 (Rev 1.8) merge - whitespace
|
| 366 |
+
normalization
|
| 367 |
+
|
| 368 |
+
2001-07-13 08:26 kbk
|
| 369 |
+
|
| 370 |
+
* CallTipWindow.py: py-cvs-rel2_1 (Rev 1.3) merge - whitespace
|
| 371 |
+
normalization
|
| 372 |
+
|
| 373 |
+
2001-07-13 08:13 kbk
|
| 374 |
+
|
| 375 |
+
* AutoExpand.py: py-cvs-rel1_2 (Rev 1.4) merge, "Add Alt-slash to
|
| 376 |
+
Unix keydefs (I somehow need it on RH 6.2). Get rid of assignment
|
| 377 |
+
to unused self.text.wordlist." --GvR
|
| 378 |
+
|
| 379 |
+
2001-07-12 16:54 elguavas
|
| 380 |
+
|
| 381 |
+
* ReplaceDialog.py: py-cvs merge, python 1.5.2 compatibility
|
| 382 |
+
|
| 383 |
+
2001-07-12 16:46 elguavas
|
| 384 |
+
|
| 385 |
+
* ScriptBinding.py: py-cvs merge, better error dialog
|
| 386 |
+
|
| 387 |
+
2001-07-12 16:38 elguavas
|
| 388 |
+
|
| 389 |
+
* TODO.txt: py-cvs merge, additions
|
| 390 |
+
|
| 391 |
+
2001-07-12 15:35 elguavas
|
| 392 |
+
|
| 393 |
+
* WindowList.py: py-cvs merge, correct indentation
|
| 394 |
+
|
| 395 |
+
2001-07-12 15:24 elguavas
|
| 396 |
+
|
| 397 |
+
* config.txt: py-cvs merge, correct typo
|
| 398 |
+
|
| 399 |
+
2001-07-12 15:21 elguavas
|
| 400 |
+
|
| 401 |
+
* help.txt: py-cvs merge, update colour changing info
|
| 402 |
+
|
| 403 |
+
2001-07-12 14:51 elguavas
|
| 404 |
+
|
| 405 |
+
* idle.py: py-cvs merge, idle_dir loading changed
|
| 406 |
+
|
| 407 |
+
2001-07-12 14:44 elguavas
|
| 408 |
+
|
| 409 |
+
* idlever.py: py-cvs merge, version update
|
| 410 |
+
|
| 411 |
+
2001-07-11 12:53 kbk
|
| 412 |
+
|
| 413 |
+
* BrowserControl.py: Initial revision
|
| 414 |
+
|
| 415 |
+
2001-07-11 12:53 kbk
|
| 416 |
+
|
| 417 |
+
* AutoExpand.py, BrowserControl.py, CallTipWindow.py, CallTips.py,
|
| 418 |
+
ClassBrowser.py, ColorDelegator.py, Debugger.py, Delegator.py,
|
| 419 |
+
EditorWindow.py, FileList.py, FormatParagraph.py, IOBinding.py,
|
| 420 |
+
IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 421 |
+
MultiStatusBar.py, ObjectBrowser.py, OutputWindow.py,
|
| 422 |
+
ParenMatch.py, PathBrowser.py, Percolator.py, PyParse.py,
|
| 423 |
+
PyShell.py, RemoteInterp.py, ReplaceDialog.py, ScriptBinding.py,
|
| 424 |
+
ScrolledList.py, Separator.py, StackViewer.py, TODO.txt,
|
| 425 |
+
ToolTip.py, WindowList.py, config.txt, help.txt, idle, idle.bat,
|
| 426 |
+
idle.py, idlever.py, setup.py, Icons/minusnode.gif,
|
| 427 |
+
Icons/python.gif: Import the release 2.1 version of Python CVS IDLE
|
| 428 |
+
on the existing 1.1.3 vendor branch named py-cvs-vendor-branch,
|
| 429 |
+
with release tag py-cvs-rel2_1.
|
| 430 |
+
|
| 431 |
+
2001-07-11 12:34 kbk
|
| 432 |
+
|
| 433 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 434 |
+
CallTips.py, ChangeLog, ClassBrowser.py, ColorDelegator.py,
|
| 435 |
+
Debugger.py, Delegator.py, EditorWindow.py, FileList.py,
|
| 436 |
+
FormatParagraph.py, FrameViewer.py, GrepDialog.py, IOBinding.py,
|
| 437 |
+
IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 438 |
+
MultiStatusBar.py, NEWS.txt, ObjectBrowser.py, OldStackViewer.py,
|
| 439 |
+
OutputWindow.py, ParenMatch.py, PathBrowser.py, Percolator.py,
|
| 440 |
+
PyParse.py, PyShell.py, README.txt, RemoteInterp.py,
|
| 441 |
+
ReplaceDialog.py, ScriptBinding.py, ScrolledList.py,
|
| 442 |
+
SearchBinding.py, SearchDialog.py, SearchDialogBase.py,
|
| 443 |
+
SearchEngine.py, Separator.py, StackViewer.py, TODO.txt,
|
| 444 |
+
ToolTip.py, TreeWidget.py, UndoDelegator.py, WidgetRedirector.py,
|
| 445 |
+
WindowList.py, ZoomHeight.py, __init__.py, config-unix.txt,
|
| 446 |
+
config-win.txt, config.txt, eventparse.py, extend.txt, help.txt,
|
| 447 |
+
idle.bat, idle.py, idle.pyw, idlever.py, keydefs.py, pyclbr.py,
|
| 448 |
+
tabnanny.py, testcode.py, Icons/folder.gif, Icons/minusnode.gif,
|
| 449 |
+
Icons/openfolder.gif, Icons/plusnode.gif, Icons/python.gif,
|
| 450 |
+
Icons/tk.gif: Import the 9 March 2000 version of Python CVS IDLE as
|
| 451 |
+
1.1.3 vendor branch named py-cvs-vendor-branch.
|
| 452 |
+
|
| 453 |
+
2001-07-04 13:43 kbk
|
| 454 |
+
|
| 455 |
+
* Icons/: folder.gif, minusnode.gif, openfolder.gif, plusnode.gif,
|
| 456 |
+
python.gif, tk.gif: Null commit with -f option to force an uprev
|
| 457 |
+
and put HEADs firmly on the trunk.
|
| 458 |
+
|
| 459 |
+
2001-07-04 13:15 kbk
|
| 460 |
+
|
| 461 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 462 |
+
CallTips.py, ChangeLog, ClassBrowser.py, ColorDelegator.py,
|
| 463 |
+
ConfigParser.py, Debugger.py, Delegator.py, EditorWindow.py,
|
| 464 |
+
ExecBinding.py, FileList.py, FormatParagraph.py, FrameViewer.py,
|
| 465 |
+
GrepDialog.py, IDLEFORK.html, IOBinding.py, IdleConf.py,
|
| 466 |
+
IdleHistory.py, MultiScrolledLists.py, MultiStatusBar.py, NEWS.txt,
|
| 467 |
+
ObjectBrowser.py, OldStackViewer.py, OutputWindow.py,
|
| 468 |
+
ParenMatch.py, PathBrowser.py, Percolator.py, PyParse.py,
|
| 469 |
+
PyShell.py, README.txt, Remote.py, RemoteInterp.py,
|
| 470 |
+
ReplaceDialog.py, ScriptBinding.py, ScrolledList.py,
|
| 471 |
+
SearchBinding.py, SearchDialog.py, SearchDialogBase.py,
|
| 472 |
+
SearchEngine.py, Separator.py, StackViewer.py, TODO.txt,
|
| 473 |
+
ToolTip.py, TreeWidget.py, UndoDelegator.py, WidgetRedirector.py,
|
| 474 |
+
WindowList.py, ZoomHeight.py, __init__.py, config-unix.txt,
|
| 475 |
+
config-win.txt, config.txt, eventparse.py, extend.txt, help.txt,
|
| 476 |
+
idle, idle.bat, idle.py, idle.pyw, idlever.py, keydefs.py,
|
| 477 |
+
loader.py, protocol.py, pyclbr.py, setup.py, spawn.py, tabnanny.py,
|
| 478 |
+
testcode.py: Null commit with -f option to force an uprev and put
|
| 479 |
+
HEADs firmly on the trunk.
|
| 480 |
+
|
| 481 |
+
2001-06-27 10:24 elguavas
|
| 482 |
+
|
| 483 |
+
* IDLEFORK.html: updated contact details
|
| 484 |
+
|
| 485 |
+
2001-06-25 17:23 elguavas
|
| 486 |
+
|
| 487 |
+
* idle, RemoteInterp.py, setup.py: Initial revision
|
| 488 |
+
|
| 489 |
+
2001-06-25 17:23 elguavas
|
| 490 |
+
|
| 491 |
+
* idle, RemoteInterp.py, setup.py: import current python cvs idle
|
| 492 |
+
as a vendor branch
|
| 493 |
+
|
| 494 |
+
2001-06-24 15:10 elguavas
|
| 495 |
+
|
| 496 |
+
* IDLEFORK.html: tiny change to test new syncmail setup
|
| 497 |
+
|
| 498 |
+
2001-06-24 14:41 elguavas
|
| 499 |
+
|
| 500 |
+
* IDLEFORK.html: change to new developer contact, also a test
|
| 501 |
+
commit for new syncmail setup
|
| 502 |
+
|
| 503 |
+
2001-06-23 18:15 elguavas
|
| 504 |
+
|
| 505 |
+
* IDLEFORK.html: tiny test update for revitalised idle-fork
|
| 506 |
+
|
| 507 |
+
2000-09-24 17:29 nriley
|
| 508 |
+
|
| 509 |
+
* protocol.py: Fixes for Python 1.6 compatibility - socket bind and
|
| 510 |
+
connect get a tuple instead two arguments.
|
| 511 |
+
|
| 512 |
+
2000-09-24 17:28 nriley
|
| 513 |
+
|
| 514 |
+
* spawn.py: Change for Python 1.6 compatibility - UNIX's 'os'
|
| 515 |
+
module defines 'spawnv' now, so we check for 'fork' first.
|
| 516 |
+
|
| 517 |
+
2000-08-15 22:51 nowonder
|
| 518 |
+
|
| 519 |
+
* IDLEFORK.html:
|
| 520 |
+
corrected email address
|
| 521 |
+
|
| 522 |
+
2000-08-15 22:47 nowonder
|
| 523 |
+
|
| 524 |
+
* IDLEFORK.html:
|
| 525 |
+
added .html file for http://idlefork.sourceforge.net
|
| 526 |
+
|
| 527 |
+
2000-08-15 11:13 dscherer
|
| 528 |
+
|
| 529 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 530 |
+
CallTips.py, __init__.py, ChangeLog, ClassBrowser.py,
|
| 531 |
+
ColorDelegator.py, ConfigParser.py, Debugger.py, Delegator.py,
|
| 532 |
+
FileList.py, FormatParagraph.py, FrameViewer.py, GrepDialog.py,
|
| 533 |
+
IOBinding.py, IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 534 |
+
MultiStatusBar.py, NEWS.txt, ObjectBrowser.py, OldStackViewer.py,
|
| 535 |
+
OutputWindow.py, ParenMatch.py, PathBrowser.py, Percolator.py,
|
| 536 |
+
PyParse.py, PyShell.py, README.txt, ReplaceDialog.py,
|
| 537 |
+
ScriptBinding.py, ScrolledList.py, SearchBinding.py,
|
| 538 |
+
SearchDialog.py, SearchDialogBase.py, SearchEngine.py,
|
| 539 |
+
Separator.py, StackViewer.py, TODO.txt, ToolTip.py, TreeWidget.py,
|
| 540 |
+
UndoDelegator.py, WidgetRedirector.py, WindowList.py, help.txt,
|
| 541 |
+
ZoomHeight.py, config-unix.txt, config-win.txt, config.txt,
|
| 542 |
+
eventparse.py, extend.txt, idle.bat, idle.py, idle.pyw, idlever.py,
|
| 543 |
+
keydefs.py, loader.py, pyclbr.py, tabnanny.py, testcode.py,
|
| 544 |
+
EditorWindow.py, ExecBinding.py, Remote.py, protocol.py, spawn.py,
|
| 545 |
+
Icons/folder.gif, Icons/minusnode.gif, Icons/openfolder.gif,
|
| 546 |
+
Icons/plusnode.gif, Icons/python.gif, Icons/tk.gif: Initial
|
| 547 |
+
revision
|
| 548 |
+
|
| 549 |
+
2000-08-15 11:13 dscherer
|
| 550 |
+
|
| 551 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 552 |
+
CallTips.py, __init__.py, ChangeLog, ClassBrowser.py,
|
| 553 |
+
ColorDelegator.py, ConfigParser.py, Debugger.py, Delegator.py,
|
| 554 |
+
FileList.py, FormatParagraph.py, FrameViewer.py, GrepDialog.py,
|
| 555 |
+
IOBinding.py, IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 556 |
+
MultiStatusBar.py, NEWS.txt, ObjectBrowser.py, OldStackViewer.py,
|
| 557 |
+
OutputWindow.py, ParenMatch.py, PathBrowser.py, Percolator.py,
|
| 558 |
+
PyParse.py, PyShell.py, README.txt, ReplaceDialog.py,
|
| 559 |
+
ScriptBinding.py, ScrolledList.py, SearchBinding.py,
|
| 560 |
+
SearchDialog.py, SearchDialogBase.py, SearchEngine.py,
|
| 561 |
+
Separator.py, StackViewer.py, TODO.txt, ToolTip.py, TreeWidget.py,
|
| 562 |
+
UndoDelegator.py, WidgetRedirector.py, WindowList.py, help.txt,
|
| 563 |
+
ZoomHeight.py, config-unix.txt, config-win.txt, config.txt,
|
| 564 |
+
eventparse.py, extend.txt, idle.bat, idle.py, idle.pyw, idlever.py,
|
| 565 |
+
keydefs.py, loader.py, pyclbr.py, tabnanny.py, testcode.py,
|
| 566 |
+
EditorWindow.py, ExecBinding.py, Remote.py, protocol.py, spawn.py,
|
| 567 |
+
Icons/folder.gif, Icons/minusnode.gif, Icons/openfolder.gif,
|
| 568 |
+
Icons/plusnode.gif, Icons/python.gif, Icons/tk.gif: Modified IDLE
|
| 569 |
+
from VPython 0.2
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
original IDLE ChangeLog:
|
| 573 |
+
========================
|
| 574 |
+
|
| 575 |
+
Tue Feb 15 18:08:19 2000 Guido van Rossum <[email protected]>
|
| 576 |
+
|
| 577 |
+
* NEWS.txt: Notice status bar and stack viewer.
|
| 578 |
+
|
| 579 |
+
* EditorWindow.py: Support for Moshe's status bar.
|
| 580 |
+
|
| 581 |
+
* MultiStatusBar.py: Status bar code -- by Moshe Zadka.
|
| 582 |
+
|
| 583 |
+
* OldStackViewer.py:
|
| 584 |
+
Adding the old stack viewer implementation back, for the debugger.
|
| 585 |
+
|
| 586 |
+
* StackViewer.py: New stack viewer, uses a tree widget.
|
| 587 |
+
(XXX: the debugger doesn't yet use this.)
|
| 588 |
+
|
| 589 |
+
* WindowList.py:
|
| 590 |
+
Correct a typo and remove an unqualified except that was hiding the error.
|
| 591 |
+
|
| 592 |
+
* ClassBrowser.py: Add an XXX comment about the ClassBrowser AIP.
|
| 593 |
+
|
| 594 |
+
* ChangeLog: Updated change log.
|
| 595 |
+
|
| 596 |
+
* NEWS.txt: News update. Probably incomplete; what else is new?
|
| 597 |
+
|
| 598 |
+
* README.txt:
|
| 599 |
+
Updated for pending IDLE 0.5 release (still very rough -- just getting
|
| 600 |
+
it out in a more convenient format than CVS).
|
| 601 |
+
|
| 602 |
+
* TODO.txt: Tiny addition.
|
| 603 |
+
|
| 604 |
+
Thu Sep 9 14:16:02 1999 Guido van Rossum <[email protected]>
|
| 605 |
+
|
| 606 |
+
* TODO.txt: A few new TODO entries.
|
| 607 |
+
|
| 608 |
+
Thu Aug 26 23:06:22 1999 Guido van Rossum <[email protected]>
|
| 609 |
+
|
| 610 |
+
* Bindings.py: Add Python Documentation entry to Help menu.
|
| 611 |
+
|
| 612 |
+
* EditorWindow.py:
|
| 613 |
+
Find the help.txt file relative to __file__ or ".", not in sys.path.
|
| 614 |
+
(Suggested by Moshe Zadka, but implemented differently.)
|
| 615 |
+
|
| 616 |
+
Add <<python-docs>> event which, on Unix, brings up Netscape pointing
|
| 617 |
+
to http://www.python.doc/current/ (a local copy would be nice but its
|
| 618 |
+
location can't be predicted). Windows solution TBD.
|
| 619 |
+
|
| 620 |
+
Wed Aug 11 14:55:43 1999 Guido van Rossum <[email protected]>
|
| 621 |
+
|
| 622 |
+
* TreeWidget.py:
|
| 623 |
+
Moshe noticed an inconsistency in his comment, so I'm rephrasing it to
|
| 624 |
+
be clearer.
|
| 625 |
+
|
| 626 |
+
* TreeWidget.py:
|
| 627 |
+
Patch inspired by Moshe Zadka to search for the Icons directory in the
|
| 628 |
+
same directory as __file__, rather than searching for it along sys.path.
|
| 629 |
+
This works better when idle is a package.
|
| 630 |
+
|
| 631 |
+
Thu Jul 15 13:11:02 1999 Guido van Rossum <[email protected]>
|
| 632 |
+
|
| 633 |
+
* TODO.txt: New wishes.
|
| 634 |
+
|
| 635 |
+
Sat Jul 10 13:17:35 1999 Guido van Rossum <[email protected]>
|
| 636 |
+
|
| 637 |
+
* IdlePrefs.py:
|
| 638 |
+
Make the color for stderr red (i.e. the standard warning/danger/stop
|
| 639 |
+
color) rather than green. Suggested by Sam Schulenburg.
|
| 640 |
+
|
| 641 |
+
Fri Jun 25 17:26:34 1999 Guido van Rossum <[email protected]>
|
| 642 |
+
|
| 643 |
+
* PyShell.py: Close debugger when closing. This may break a cycle.
|
| 644 |
+
|
| 645 |
+
* Debugger.py: Break cycle on close.
|
| 646 |
+
|
| 647 |
+
* ClassBrowser.py: Destroy the tree when closing.
|
| 648 |
+
|
| 649 |
+
* TreeWidget.py: Add destroy() method to recursively destroy a tree.
|
| 650 |
+
|
| 651 |
+
* PyShell.py: Extend _close() to break cycles.
|
| 652 |
+
Break some other cycles too (and destroy the root when done).
|
| 653 |
+
|
| 654 |
+
* EditorWindow.py:
|
| 655 |
+
Add _close() method that does the actual cleanup (close() asks the
|
| 656 |
+
user what they want first if there's unsaved stuff, and may cancel).
|
| 657 |
+
It closes more than before.
|
| 658 |
+
|
| 659 |
+
Add unload_extensions() method to unload all extensions; called from
|
| 660 |
+
_close(). It calls an extension's close() method if it has one.
|
| 661 |
+
|
| 662 |
+
* Percolator.py: Add close() method that breaks cycles.
|
| 663 |
+
|
| 664 |
+
* WidgetRedirector.py: Add unregister() method.
|
| 665 |
+
Unregister everything at closing.
|
| 666 |
+
Don't call close() in __del__, rely on explicit call to close().
|
| 667 |
+
|
| 668 |
+
* IOBinding.py, FormatParagraph.py, CallTips.py:
|
| 669 |
+
Add close() method that breaks a cycle.
|
| 670 |
+
|
| 671 |
+
Fri Jun 11 15:03:00 1999 Guido van Rossum <[email protected]>
|
| 672 |
+
|
| 673 |
+
* AutoIndent.py, EditorWindow.py, FormatParagraph.py:
|
| 674 |
+
Tim Peters smart.patch:
|
| 675 |
+
|
| 676 |
+
EditorWindow.py:
|
| 677 |
+
|
| 678 |
+
+ Added get_tabwidth & set_tabwidth "virtual text" methods, that get/set the
|
| 679 |
+
widget's view of what a tab means.
|
| 680 |
+
|
| 681 |
+
+ Moved TK_TABWIDTH_DEFAULT here from AutoIndent.
|
| 682 |
+
|
| 683 |
+
+ Renamed Mark's get_selection_index to get_selection_indices (sorry, Mark,
|
| 684 |
+
but the name was plain wrong <wink>).
|
| 685 |
+
|
| 686 |
+
FormatParagraph.py: renamed use of get_selection_index.
|
| 687 |
+
|
| 688 |
+
AutoIndent.py:
|
| 689 |
+
|
| 690 |
+
+ Moved TK_TABWIDTH_DEFAULT to EditorWindow.
|
| 691 |
+
|
| 692 |
+
+ Rewrote set_indentation_params to use new VTW get/set_tabwidth methods.
|
| 693 |
+
|
| 694 |
+
+ Changed smart_backspace_event to delete whitespace back to closest
|
| 695 |
+
preceding virtual tab stop or real character (note that this may require
|
| 696 |
+
inserting characters if backspacing over a tab!).
|
| 697 |
+
|
| 698 |
+
+ Nuked almost references to the selection tag, in favor of using
|
| 699 |
+
get_selection_indices. The sole exception is in set_region, for which no
|
| 700 |
+
"set_selection" abstraction has yet been agreed upon.
|
| 701 |
+
|
| 702 |
+
+ Had too much fun using the spiffy new features of the format-paragraph
|
| 703 |
+
cmd.
|
| 704 |
+
|
| 705 |
+
Thu Jun 10 17:48:02 1999 Guido van Rossum <[email protected]>
|
| 706 |
+
|
| 707 |
+
* FormatParagraph.py:
|
| 708 |
+
Code by Mark Hammond to format paragraphs embedded in comments.
|
| 709 |
+
Read the comments (which I reformatted using the new feature :-)
|
| 710 |
+
for some limitations.
|
| 711 |
+
|
| 712 |
+
* EditorWindow.py:
|
| 713 |
+
Added abstraction get_selection_index() (Mark Hammond). Also
|
| 714 |
+
reformatted some comment blocks to show off a cool feature I'm about
|
| 715 |
+
to check in next.
|
| 716 |
+
|
| 717 |
+
* ClassBrowser.py:
|
| 718 |
+
Adapt to the new pyclbr's support of listing top-level functions. If
|
| 719 |
+
this functionality is not present (e.g. when used with a vintage
|
| 720 |
+
Python 1.5.2 installation) top-level functions are not listed.
|
| 721 |
+
|
| 722 |
+
(Hmm... Any distribution of IDLE 0.5 should probably include a copy
|
| 723 |
+
of the new pyclbr.py!)
|
| 724 |
+
|
| 725 |
+
* AutoIndent.py:
|
| 726 |
+
Fix off-by-one error in Tim's recent change to comment_region(): the
|
| 727 |
+
list of lines returned by get_region() contains an empty line at the
|
| 728 |
+
end representing the start of the next line, and this shouldn't be
|
| 729 |
+
commented out!
|
| 730 |
+
|
| 731 |
+
* CallTips.py:
|
| 732 |
+
Mark Hammond writes: Here is another change that allows it to work for
|
| 733 |
+
class creation - tries to locate an __init__ function. Also updated
|
| 734 |
+
the test code to reflect your new "***" change.
|
| 735 |
+
|
| 736 |
+
* CallTipWindow.py:
|
| 737 |
+
Mark Hammond writes: Tim's suggestion of copying the font for the
|
| 738 |
+
CallTipWindow from the text control makes sense, and actually makes
|
| 739 |
+
the control look better IMO.
|
| 740 |
+
|
| 741 |
+
Wed Jun 9 20:34:57 1999 Guido van Rossum <[email protected]>
|
| 742 |
+
|
| 743 |
+
* CallTips.py:
|
| 744 |
+
Append "..." if the appropriate flag (for varargs) in co_flags is set.
|
| 745 |
+
Ditto "***" for kwargs.
|
| 746 |
+
|
| 747 |
+
Tue Jun 8 13:06:07 1999 Guido van Rossum <[email protected]>
|
| 748 |
+
|
| 749 |
+
* ReplaceDialog.py:
|
| 750 |
+
Hmm... Tim didn't turn "replace all" into a single undo block.
|
| 751 |
+
I think I like it better if it os, so here.
|
| 752 |
+
|
| 753 |
+
* ReplaceDialog.py: Tim Peters: made replacement atomic for undo/redo.
|
| 754 |
+
|
| 755 |
+
* AutoIndent.py: Tim Peters:
|
| 756 |
+
|
| 757 |
+
+ Set usetabs=1. Editing pyclbr.py was driving me nuts <0.6 wink>.
|
| 758 |
+
usetabs=1 is the Emacs pymode default too, and thanks to indentwidth !=
|
| 759 |
+
tabwidth magical usetabs disabling, new files are still created with tabs
|
| 760 |
+
turned off. The only implication is that if you open a file whose first
|
| 761 |
+
indent is a single tab, IDLE will now magically use tabs for that file (and
|
| 762 |
+
set indentwidth to 8). Note that the whole scheme doesn't work right for
|
| 763 |
+
PythonWin, though, since Windows users typically set tabwidth to 4; Mark
|
| 764 |
+
probably has to hide the IDLE algorithm from them (which he already knows).
|
| 765 |
+
|
| 766 |
+
+ Changed comment_region_event to stick "##" in front of every line. The
|
| 767 |
+
"holes" previously left on blank lines were visually confusing (made it
|
| 768 |
+
needlessly hard to figure out what to uncomment later).
|
| 769 |
+
|
| 770 |
+
Mon Jun 7 15:38:40 1999 Guido van Rossum <[email protected]>
|
| 771 |
+
|
| 772 |
+
* TreeWidget.py, ObjectBrowser.py:
|
| 773 |
+
Remove unnecessary reference to pyclbr from test() code.
|
| 774 |
+
|
| 775 |
+
* PyParse.py: Tim Peters:
|
| 776 |
+
|
| 777 |
+
Smarter logic for finding a parse synch point.
|
| 778 |
+
|
| 779 |
+
Does a half to a fifth the work in normal cases; don't notice the speedup,
|
| 780 |
+
but makes more breathing room for other extensions.
|
| 781 |
+
|
| 782 |
+
Speeds terrible cases by at least a factor of 10. "Terrible" == e.g. you put
|
| 783 |
+
""" at the start of Tkinter.py, undo it, zoom to the bottom, and start
|
| 784 |
+
typing in code. Used to take about 8 seconds for ENTER to respond, now some
|
| 785 |
+
large fraction of a second. The new code gets indented correctly, despite
|
| 786 |
+
that it all remains "string colored" until the colorizer catches up (after
|
| 787 |
+
which, ENTER appears instantaneous again).
|
| 788 |
+
|
| 789 |
+
Fri Jun 4 19:21:19 1999 Guido van Rossum <[email protected]>
|
| 790 |
+
|
| 791 |
+
* extend.py: Might as well enable CallTips by default.
|
| 792 |
+
If there are too many complaints I'll remove it again or fix it.
|
| 793 |
+
|
| 794 |
+
Thu Jun 3 14:32:16 1999 Guido van Rossum <[email protected]>
|
| 795 |
+
|
| 796 |
+
* AutoIndent.py, EditorWindow.py, PyParse.py:
|
| 797 |
+
New offerings by Tim Peters; he writes:
|
| 798 |
+
|
| 799 |
+
IDLE is now the first Python editor in the Universe not confused by my
|
| 800 |
+
doctest.py <wink>.
|
| 801 |
+
|
| 802 |
+
As threatened, this defines IDLE's is_char_in_string function as a
|
| 803 |
+
method of EditorWindow. You just need to define one similarly in
|
| 804 |
+
whatever it is you pass as editwin to AutoIndent; looking at the
|
| 805 |
+
EditorWindow.py part of the patch should make this clear.
|
| 806 |
+
|
| 807 |
+
* GrepDialog.py: Enclose pattern in quotes in status message.
|
| 808 |
+
|
| 809 |
+
* CallTips.py:
|
| 810 |
+
Mark Hammond fixed some comments and improved the way the tip text is
|
| 811 |
+
constructed.
|
| 812 |
+
|
| 813 |
+
Wed Jun 2 18:18:57 1999 Guido van Rossum <[email protected]>
|
| 814 |
+
|
| 815 |
+
* CallTips.py:
|
| 816 |
+
My fix to Mark's code: restore the universal check on <KeyRelease>.
|
| 817 |
+
Always cancel on <Key-Escape> or <ButtonPress>.
|
| 818 |
+
|
| 819 |
+
* CallTips.py:
|
| 820 |
+
A version that Mark Hammond posted to the newsgroup. Has some newer
|
| 821 |
+
stuff for getting the tip. Had to fix the Key-( and Key-) events
|
| 822 |
+
for Unix. Will have to re-apply my patch for catching KeyRelease and
|
| 823 |
+
ButtonRelease events.
|
| 824 |
+
|
| 825 |
+
* CallTipWindow.py, CallTips.py:
|
| 826 |
+
Call tips by Mark Hammond (plus tiny fix by me.)
|
| 827 |
+
|
| 828 |
+
* IdleHistory.py:
|
| 829 |
+
Changes by Mark Hammond: (1) support optional output_sep argument to
|
| 830 |
+
the constructor so he can eliminate the sys.ps2 that PythonWin leaves
|
| 831 |
+
in the source; (2) remove duplicate history items.
|
| 832 |
+
|
| 833 |
+
* AutoIndent.py:
|
| 834 |
+
Changes by Mark Hammond to allow using IDLE extensions in PythonWin as
|
| 835 |
+
well: make three dialog routines instance variables.
|
| 836 |
+
|
| 837 |
+
* EditorWindow.py:
|
| 838 |
+
Change by Mark Hammond to allow using IDLE extensions in PythonWin as
|
| 839 |
+
well: make three dialog routines instance variables.
|
| 840 |
+
|
| 841 |
+
Tue Jun 1 20:06:44 1999 Guido van Rossum <[email protected]>
|
| 842 |
+
|
| 843 |
+
* AutoIndent.py: Hah! A fix of my own to Tim's code!
|
| 844 |
+
Unix bindings for <<toggle-tabs>> and <<change-indentwidth>> were
|
| 845 |
+
missing, and somehow that meant the events were never generated,
|
| 846 |
+
even though they were in the menu. The new Unix bindings are now
|
| 847 |
+
the same as the Windows bindings (M-t and M-u).
|
| 848 |
+
|
| 849 |
+
* AutoIndent.py, PyParse.py, PyShell.py: Tim Peters again:
|
| 850 |
+
|
| 851 |
+
The new version (attached) is fast enough all the time in every real module
|
| 852 |
+
I have <whew!>. You can make it slow by, e.g., creating an open list with
|
| 853 |
+
5,000 90-character identifiers (+ trailing comma) each on its own line, then
|
| 854 |
+
adding an item to the end -- but that still consumes less than a second on
|
| 855 |
+
my P5-166. Response time in real code appears instantaneous.
|
| 856 |
+
|
| 857 |
+
Fixed some bugs.
|
| 858 |
+
|
| 859 |
+
New feature: when hitting ENTER and the cursor is beyond the line's leading
|
| 860 |
+
indentation, whitespace is removed on both sides of the cursor; before
|
| 861 |
+
whitespace was removed only on the left; e.g., assuming the cursor is
|
| 862 |
+
between the comma and the space:
|
| 863 |
+
|
| 864 |
+
def something(arg1, arg2):
|
| 865 |
+
^ cursor to the left of here, and hit ENTER
|
| 866 |
+
arg2): # new line used to end up here
|
| 867 |
+
arg2): # but now lines up the way you expect
|
| 868 |
+
|
| 869 |
+
New hack: AutoIndent has grown a context_use_ps1 Boolean config option,
|
| 870 |
+
defaulting to 0 (false) and set to 1 (only) by PyShell. Reason: handling
|
| 871 |
+
the fancy stuff requires looking backward for a parsing synch point; ps1
|
| 872 |
+
lines are the only sensible thing to look for in a shell window, but are a
|
| 873 |
+
bad thing to look for in a file window (ps1 lines show up in my module
|
| 874 |
+
docstrings often). PythonWin's shell should set this true too.
|
| 875 |
+
|
| 876 |
+
Persistent problem: strings containing def/class can still screw things up
|
| 877 |
+
completely. No improvement. Simplest workaround is on the user's head, and
|
| 878 |
+
consists of inserting e.g.
|
| 879 |
+
|
| 880 |
+
def _(): pass
|
| 881 |
+
|
| 882 |
+
(or any other def/class) after the end of the multiline string that's
|
| 883 |
+
screwing them up. This is especially irksome because IDLE's syntax coloring
|
| 884 |
+
is *not* confused, so when this happens the colors don't match the
|
| 885 |
+
indentation behavior they see.
|
| 886 |
+
|
| 887 |
+
* AutoIndent.py: Tim Peters again:
|
| 888 |
+
|
| 889 |
+
[Tim, after adding some bracket smarts to AutoIndent.py]
|
| 890 |
+
> ...
|
| 891 |
+
> What it can't possibly do without reparsing large gobs of text is
|
| 892 |
+
> suggest a reasonable indent level after you've *closed* a bracket
|
| 893 |
+
> left open on some previous line.
|
| 894 |
+
> ...
|
| 895 |
+
|
| 896 |
+
The attached can, and actually fast enough to use -- most of the time. The
|
| 897 |
+
code is tricky beyond belief to achieve that, but it works so far; e.g.,
|
| 898 |
+
|
| 899 |
+
return len(string.expandtabs(str[self.stmt_start :
|
| 900 |
+
^ indents to caret
|
| 901 |
+
i],
|
| 902 |
+
^ indents to caret
|
| 903 |
+
self.tabwidth)) + 1
|
| 904 |
+
^ indents to caret
|
| 905 |
+
|
| 906 |
+
It's about as smart as pymode now, wrt both bracket and backslash
|
| 907 |
+
continuation rules. It does require reparsing large gobs of text, and if it
|
| 908 |
+
happens to find something that looks like a "def" or "class" or sys.ps1
|
| 909 |
+
buried in a multiline string, but didn't suck up enough preceding text to
|
| 910 |
+
see the start of the string, it's completely hosed. I can't repair that --
|
| 911 |
+
it's just too slow to reparse from the start of the file all the time.
|
| 912 |
+
|
| 913 |
+
AutoIndent has grown a new num_context_lines tuple attribute that controls
|
| 914 |
+
how far to look back, and-- like other params --this could/should be made
|
| 915 |
+
user-overridable at startup and per-file on the fly.
|
| 916 |
+
|
| 917 |
+
* PyParse.py: New file by Tim Peters:
|
| 918 |
+
|
| 919 |
+
One new file in the attached, PyParse.py. The LineStudier (whatever it was
|
| 920 |
+
called <wink>) class was removed from AutoIndent; PyParse subsumes its
|
| 921 |
+
functionality.
|
| 922 |
+
|
| 923 |
+
* AutoIndent.py: Tim Peters keeps revising this module (more to come):
|
| 924 |
+
|
| 925 |
+
Removed "New tabwidth" menu binding.
|
| 926 |
+
|
| 927 |
+
Added "a tab means how many spaces?" dialog to block tabify and untabify. I
|
| 928 |
+
think prompting for this is good now: they're usually at-most-once-per-file
|
| 929 |
+
commands, and IDLE can't let them change tabwidth from the Tk default
|
| 930 |
+
anymore, so IDLE can no longer presume to have any idea what a tab means.
|
| 931 |
+
|
| 932 |
+
Irony: for the purpose of keeping comments aligned via tabs, Tk's
|
| 933 |
+
non-default approach is much nicer than the Emacs/Notepad/Codewright/vi/etc
|
| 934 |
+
approach.
|
| 935 |
+
|
| 936 |
+
* EditorWindow.py:
|
| 937 |
+
1. Catch NameError on import (could be raised by case mismatch on Windows).
|
| 938 |
+
2. No longer need to reset pyclbr cache and show watch cursor when calling
|
| 939 |
+
ClassBrowser -- the ClassBrowser takes care of pyclbr and the TreeWidget
|
| 940 |
+
takes care of the watch cursor.
|
| 941 |
+
3. Reset the focus to the current window after error message about class
|
| 942 |
+
browser on buffer without filename.
|
| 943 |
+
|
| 944 |
+
* Icons/minusnode.gif, Icons/plusnode.gif: Missed a few.
|
| 945 |
+
|
| 946 |
+
* ClassBrowser.py, PathBrowser.py: Rewritten based on TreeWidget.py
|
| 947 |
+
|
| 948 |
+
* ObjectBrowser.py: Object browser, based on TreeWidget.py.
|
| 949 |
+
|
| 950 |
+
* TreeWidget.py: Tree widget done right.
|
| 951 |
+
|
| 952 |
+
* ToolTip.py: As yet unused code for tool tips.
|
| 953 |
+
|
| 954 |
+
* ScriptBinding.py:
|
| 955 |
+
Ensure sys.argv[0] is the script name on Run Script.
|
| 956 |
+
|
| 957 |
+
* ZoomHeight.py: Move zoom height functionality to separate function.
|
| 958 |
+
|
| 959 |
+
* Icons/folder.gif, Icons/openfolder.gif, Icons/python.gif, Icons/tk.gif:
|
| 960 |
+
A few icons used by ../TreeWidget.py and its callers.
|
| 961 |
+
|
| 962 |
+
* AutoIndent.py: New version by Tim Peters improves block opening test.
|
| 963 |
+
|
| 964 |
+
Fri May 21 04:46:17 1999 Guido van Rossum <[email protected]>
|
| 965 |
+
|
| 966 |
+
* Attic/History.py, PyShell.py: Rename History to IdleHistory.
|
| 967 |
+
Add isatty() to pseudo files.
|
| 968 |
+
|
| 969 |
+
* StackViewer.py: Make initial stack viewer wider
|
| 970 |
+
|
| 971 |
+
* TODO.txt: New wishes
|
| 972 |
+
|
| 973 |
+
* AutoIndent.py, EditorWindow.py, PyShell.py:
|
| 974 |
+
Much improved autoindent and handling of tabs,
|
| 975 |
+
by Tim Peters.
|
| 976 |
+
|
| 977 |
+
Mon May 3 15:49:52 1999 Guido van Rossum <[email protected]>
|
| 978 |
+
|
| 979 |
+
* AutoIndent.py, EditorWindow.py, FormatParagraph.py, UndoDelegator.py:
|
| 980 |
+
Tim Peters writes:
|
| 981 |
+
|
| 982 |
+
I'm still unsure, but couldn't stand the virtual event trickery so tried a
|
| 983 |
+
different sin (adding undo_block_start/stop methods to the Text instance in
|
| 984 |
+
EditorWindow.py). Like it or not, it's efficient and works <wink>. Better
|
| 985 |
+
idea?
|
| 986 |
+
|
| 987 |
+
Give the attached a whirl. Even if you hate the implementation, I think
|
| 988 |
+
you'll like the results. Think I caught all the "block edit" cmds,
|
| 989 |
+
including Format Paragraph, plus subtler ones involving smart indents and
|
| 990 |
+
backspacing.
|
| 991 |
+
|
| 992 |
+
* WidgetRedirector.py: Tim Peters writes:
|
| 993 |
+
|
| 994 |
+
[W]hile trying to dope out how redirection works, stumbled into two
|
| 995 |
+
possible glitches. In the first, it doesn't appear to make sense to try to
|
| 996 |
+
rename a command that's already been destroyed; in the second, the name
|
| 997 |
+
"previous" doesn't really bring to mind "ignore the previous value" <wink>.
|
| 998 |
+
|
| 999 |
+
Fri Apr 30 19:39:25 1999 Guido van Rossum <[email protected]>
|
| 1000 |
+
|
| 1001 |
+
* __init__.py: Support for using idle as a package.
|
| 1002 |
+
|
| 1003 |
+
* PathBrowser.py:
|
| 1004 |
+
Avoid listing files more than once (e.g. foomodule.so has two hits:
|
| 1005 |
+
once for foo + module.so, once for foomodule + .so).
|
| 1006 |
+
|
| 1007 |
+
Mon Apr 26 22:20:38 1999 Guido van Rossum <[email protected]>
|
| 1008 |
+
|
| 1009 |
+
* ChangeLog, ColorDelegator.py, PyShell.py: Tim Peters strikes again:
|
| 1010 |
+
|
| 1011 |
+
Ho ho ho -- that's trickier than it sounded! The colorizer is working with
|
| 1012 |
+
"line.col" strings instead of Text marks, and the absolute coordinates of
|
| 1013 |
+
the point of interest can change across the self.update call (voice of
|
| 1014 |
+
baffled experience, when two quick backspaces no longer fooled it, but a
|
| 1015 |
+
backspace followed by a quick ENTER did <wink>).
|
| 1016 |
+
|
| 1017 |
+
Anyway, the attached appears to do the trick. CPU usage goes way up when
|
| 1018 |
+
typing quickly into a long triple-quoted string, but the latency is fine for
|
| 1019 |
+
me (a relatively fast typist on a relatively slow machine). Most of the
|
| 1020 |
+
changes here are left over from reducing the # of vrbl names to help me
|
| 1021 |
+
reason about the logic better; I hope the code is a *little* easier to
|
| 1022 |
+
|
| 1023 |
+
Fri Apr 23 14:01:25 1999 Guido van Rossum <[email protected]>
|
| 1024 |
+
|
| 1025 |
+
* EditorWindow.py:
|
| 1026 |
+
Provide full arguments to __import__ so it works in packagized IDLE.
|
| 1027 |
+
|
| 1028 |
+
Thu Apr 22 23:20:17 1999 Guido van Rossum <[email protected]>
|
| 1029 |
+
|
| 1030 |
+
* help.txt:
|
| 1031 |
+
Bunch of updates necessary due to recent changes; added docs for File
|
| 1032 |
+
menu, command line and color preferences.
|
| 1033 |
+
|
| 1034 |
+
* Bindings.py: Remove obsolete 'script' menu.
|
| 1035 |
+
|
| 1036 |
+
* TODO.txt: Several wishes fulfilled.
|
| 1037 |
+
|
| 1038 |
+
* OutputWindow.py:
|
| 1039 |
+
Moved classes OnDemandOutputWindow and PseudoFile here,
|
| 1040 |
+
from ScriptBinding.py where they are no longer needed.
|
| 1041 |
+
|
| 1042 |
+
* ScriptBinding.py:
|
| 1043 |
+
Mostly rewritten. Instead of the old Run module and Debug module,
|
| 1044 |
+
there are two new commands:
|
| 1045 |
+
|
| 1046 |
+
Import module (F5) imports or reloads the module and also adds its
|
| 1047 |
+
name to the __main__ namespace. This gets executed in the PyShell
|
| 1048 |
+
window under control of its debug settings.
|
| 1049 |
+
|
| 1050 |
+
Run script (Control-F5) is similar but executes the contents of the
|
| 1051 |
+
file directly in the __main__ namespace.
|
| 1052 |
+
|
| 1053 |
+
* PyShell.py: Nits: document use of $IDLESTARTUP; display idle version
|
| 1054 |
+
|
| 1055 |
+
* idlever.py: New version to celebrate new command line
|
| 1056 |
+
|
| 1057 |
+
* OutputWindow.py: Added flush(), for completeness.
|
| 1058 |
+
|
| 1059 |
+
* PyShell.py:
|
| 1060 |
+
A lot of changes to make the command line more useful. You can now do:
|
| 1061 |
+
idle.py -e file ... -- to edit files
|
| 1062 |
+
idle.py script arg ... -- to run a script
|
| 1063 |
+
idle.py -c cmd arg ... -- to run a command
|
| 1064 |
+
Other options, see also the usage message (also new!) for more details:
|
| 1065 |
+
-d -- enable debugger
|
| 1066 |
+
-s -- run $IDLESTARTUP or $PYTHONSTARTUP
|
| 1067 |
+
-t title -- set Python Shell window's title
|
| 1068 |
+
sys.argv is set accordingly, unless -e is used.
|
| 1069 |
+
sys.path is absolutized, and all relevant paths are inserted into it.
|
| 1070 |
+
|
| 1071 |
+
Other changes:
|
| 1072 |
+
- the environment in which commands are executed is now the
|
| 1073 |
+
__main__ module
|
| 1074 |
+
- explicitly save sys.stdout etc., don't restore from sys.__stdout__
|
| 1075 |
+
- new interpreter methods execsource(), execfile(), stuffsource()
|
| 1076 |
+
- a few small nits
|
| 1077 |
+
|
| 1078 |
+
* TODO.txt:
|
| 1079 |
+
Some more TODO items. Made up my mind about command line args,
|
| 1080 |
+
Run/Import, __main__.
|
| 1081 |
+
|
| 1082 |
+
* ColorDelegator.py:
|
| 1083 |
+
Super-elegant patch by Tim Peters that speeds up colorization
|
| 1084 |
+
dramatically (up to 15 times he claims). Works by reading more than
|
| 1085 |
+
one line at a time, up to 100-line chunks (starting with one line and
|
| 1086 |
+
then doubling up to the limit). On a typical machine (e.g. Tim's
|
| 1087 |
+
P5-166) this doesn't reduce interactive responsiveness in a noticeable
|
| 1088 |
+
way.
|
| 1089 |
+
|
| 1090 |
+
Wed Apr 21 15:49:34 1999 Guido van Rossum <[email protected]>
|
| 1091 |
+
|
| 1092 |
+
* ColorDelegator.py:
|
| 1093 |
+
Patch by Tim Peters to speed up colorizing of big multiline strings.
|
| 1094 |
+
|
| 1095 |
+
Tue Apr 20 17:32:52 1999 Guido van Rossum <[email protected]>
|
| 1096 |
+
|
| 1097 |
+
* extend.txt:
|
| 1098 |
+
For an event 'foo-bar', the corresponding method must be called
|
| 1099 |
+
foo_bar_event(). Therefore, fix the references to zoom_height() in
|
| 1100 |
+
the example.
|
| 1101 |
+
|
| 1102 |
+
* IdlePrefs.py: Restored the original IDLE color scheme.
|
| 1103 |
+
|
| 1104 |
+
* PyShell.py, IdlePrefs.py, ColorDelegator.py, EditorWindow.py:
|
| 1105 |
+
Color preferences code by Loren Luke (massaged by me somewhat)
|
| 1106 |
+
|
| 1107 |
+
* SearchEngine.py:
|
| 1108 |
+
Patch by Mark Favas: it fixes the search engine behaviour where an
|
| 1109 |
+
unsuccessful search wraps around and re-searches that part of the file
|
| 1110 |
+
between the start of the search and the end of the file - only really
|
| 1111 |
+
an issue for very large files, but... (also removes a redundant
|
| 1112 |
+
m.span() call).
|
| 1113 |
+
|
| 1114 |
+
Mon Apr 19 16:26:02 1999 Guido van Rossum <[email protected]>
|
| 1115 |
+
|
| 1116 |
+
* TODO.txt: A few wishes are now fulfilled.
|
| 1117 |
+
|
| 1118 |
+
* AutoIndent.py: Tim Peters implements some of my wishes:
|
| 1119 |
+
|
| 1120 |
+
o Makes the tab key intelligently insert spaces when appropriate
|
| 1121 |
+
(see Help list banter twixt David Ascher and me; idea stolen from
|
| 1122 |
+
every other editor on earth <wink>).
|
| 1123 |
+
|
| 1124 |
+
o newline_and_indent_event trims trailing whitespace on the old
|
| 1125 |
+
line (pymode and Codewright).
|
| 1126 |
+
|
| 1127 |
+
o newline_and_indent_event no longer fooled by trailing whitespace or
|
| 1128 |
+
comment after ":" (pymode, PTUI).
|
| 1129 |
+
|
| 1130 |
+
o newline_and_indent_event now reduces the new line's indentation after
|
| 1131 |
+
return, break, continue, raise and pass stmts (pymode).
|
| 1132 |
+
|
| 1133 |
+
The last two are easy to fool in the presence of strings &
|
| 1134 |
+
continuations, but pymode requires Emacs's high-powered C parsing
|
| 1135 |
+
functions to avoid that in finite time.
|
| 1136 |
+
|
| 1137 |
+
======================================================================
|
| 1138 |
+
Python release 1.5.2c1, IDLE version 0.4
|
| 1139 |
+
======================================================================
|
| 1140 |
+
|
| 1141 |
+
Wed Apr 7 18:41:59 1999 Guido van Rossum <[email protected]>
|
| 1142 |
+
|
| 1143 |
+
* README.txt, NEWS.txt: New version.
|
| 1144 |
+
|
| 1145 |
+
* idlever.py: Version bump awaiting impending new release.
|
| 1146 |
+
(Not much has changed :-( )
|
| 1147 |
+
|
| 1148 |
+
Mon Mar 29 14:52:28 1999 Guido van Rossum <[email protected]>
|
| 1149 |
+
|
| 1150 |
+
* ScriptBinding.py, PyShell.py:
|
| 1151 |
+
At Tim Peters' recommendation, add a dummy flush() method to
|
| 1152 |
+
PseudoFile.
|
| 1153 |
+
|
| 1154 |
+
Thu Mar 11 23:21:23 1999 Guido van Rossum <[email protected]>
|
| 1155 |
+
|
| 1156 |
+
* PathBrowser.py: Don't crash when sys.path contains an empty string.
|
| 1157 |
+
|
| 1158 |
+
* Attic/Outline.py: This file was never supposed to be part of IDLE.
|
| 1159 |
+
|
| 1160 |
+
* PathBrowser.py:
|
| 1161 |
+
- Don't crash in the case where a superclass is a string instead of a
|
| 1162 |
+
pyclbr.Class object; this can happen when the superclass is
|
| 1163 |
+
unrecognizable (to pyclbr), e.g. when module renaming is used.
|
| 1164 |
+
|
| 1165 |
+
- Show a watch cursor when calling pyclbr (since it may take a while
|
| 1166 |
+
recursively parsing imported modules!).
|
| 1167 |
+
|
| 1168 |
+
Wed Mar 10 05:18:02 1999 Guido van Rossum <[email protected]>
|
| 1169 |
+
|
| 1170 |
+
* EditorWindow.py, Bindings.py: Add PathBrowser to File module
|
| 1171 |
+
|
| 1172 |
+
* PathBrowser.py: "Path browser" - 4 scrolled lists displaying:
|
| 1173 |
+
directories on sys.path
|
| 1174 |
+
modules in selected directory
|
| 1175 |
+
classes in selected module
|
| 1176 |
+
methods of selected class
|
| 1177 |
+
|
| 1178 |
+
Single clicking in a directory, module or class item updates the next
|
| 1179 |
+
column with info about the selected item. Double clicking in a
|
| 1180 |
+
module, class or method item opens the file (and selects the clicked
|
| 1181 |
+
item if it is a class or method).
|
| 1182 |
+
|
| 1183 |
+
I guess eventually I should be using a tree widget for this, but the
|
| 1184 |
+
ones I've seen don't work well enough, so for now I use the old
|
| 1185 |
+
Smalltalk or NeXT style multi-column hierarchical browser.
|
| 1186 |
+
|
| 1187 |
+
* MultiScrolledLists.py:
|
| 1188 |
+
New utility: multiple scrolled lists in parallel
|
| 1189 |
+
|
| 1190 |
+
* ScrolledList.py: - White background.
|
| 1191 |
+
- Display "(None)" (or text of your choosing) when empty.
|
| 1192 |
+
- Don't set the focus.
|
| 1193 |
+
|
| 1194 |
+
======================================================================
|
| 1195 |
+
Python release 1.5.2b2, IDLE version 0.3
|
| 1196 |
+
======================================================================
|
| 1197 |
+
|
| 1198 |
+
Wed Feb 17 22:47:41 1999 Guido van Rossum <[email protected]>
|
| 1199 |
+
|
| 1200 |
+
* NEWS.txt: News in 0.3.
|
| 1201 |
+
|
| 1202 |
+
* README.txt, idlever.py: Bump version to 0.3.
|
| 1203 |
+
|
| 1204 |
+
* EditorWindow.py:
|
| 1205 |
+
After all, we don't need to call the callbacks ourselves!
|
| 1206 |
+
|
| 1207 |
+
* WindowList.py:
|
| 1208 |
+
When deleting, call the callbacks *after* deleting the window from our list!
|
| 1209 |
+
|
| 1210 |
+
* EditorWindow.py:
|
| 1211 |
+
Fix up the Windows menu via the new callback mechanism instead of
|
| 1212 |
+
depending on menu post commands (which don't work when the menu is
|
| 1213 |
+
torn off).
|
| 1214 |
+
|
| 1215 |
+
* WindowList.py:
|
| 1216 |
+
Support callbacks to patch up Windows menus everywhere.
|
| 1217 |
+
|
| 1218 |
+
* ChangeLog: Oh, why not. Checking in the Emacs-generated change log.
|
| 1219 |
+
|
| 1220 |
+
Tue Feb 16 22:34:17 1999 Guido van Rossum <[email protected]>
|
| 1221 |
+
|
| 1222 |
+
* ScriptBinding.py:
|
| 1223 |
+
Only pop up the stack viewer when requested in the Debug menu.
|
| 1224 |
+
|
| 1225 |
+
Mon Feb 8 22:27:49 1999 Guido van Rossum <[email protected]>
|
| 1226 |
+
|
| 1227 |
+
* WindowList.py: Don't crash if a window no longer exists.
|
| 1228 |
+
|
| 1229 |
+
* TODO.txt: Restructured a bit.
|
| 1230 |
+
|
| 1231 |
+
Mon Feb 1 23:06:17 1999 Guido van Rossum <[email protected]>
|
| 1232 |
+
|
| 1233 |
+
* PyShell.py: Add current dir or paths of file args to sys.path.
|
| 1234 |
+
|
| 1235 |
+
* Debugger.py: Add canonic() function -- for brand new bdb.py feature.
|
| 1236 |
+
|
| 1237 |
+
* StackViewer.py: Protect against accessing an empty stack.
|
| 1238 |
+
|
| 1239 |
+
Fri Jan 29 20:44:45 1999 Guido van Rossum <[email protected]>
|
| 1240 |
+
|
| 1241 |
+
* ZoomHeight.py:
|
| 1242 |
+
Use only the height to decide whether to zoom in or out.
|
| 1243 |
+
|
| 1244 |
+
Thu Jan 28 22:24:30 1999 Guido van Rossum <[email protected]>
|
| 1245 |
+
|
| 1246 |
+
* EditorWindow.py, FileList.py:
|
| 1247 |
+
Make sure the Tcl variables are shared between windows.
|
| 1248 |
+
|
| 1249 |
+
* PyShell.py, EditorWindow.py, Bindings.py:
|
| 1250 |
+
Move menu/key binding code from Bindings.py to EditorWindow.py,
|
| 1251 |
+
with changed APIs -- it makes much more sense there.
|
| 1252 |
+
Also add a new feature: if the first character of a menu label is
|
| 1253 |
+
a '!', it gets a checkbox. Checkboxes are bound to Boolean Tcl variables
|
| 1254 |
+
that can be accessed through the new getvar/setvar/getrawvar API;
|
| 1255 |
+
the variable is named after the event to which the menu is bound.
|
| 1256 |
+
|
| 1257 |
+
* Debugger.py: Add Quit button to the debugger window.
|
| 1258 |
+
|
| 1259 |
+
* SearchDialog.py:
|
| 1260 |
+
When find_again() finds exactly the current selection, it's a failure.
|
| 1261 |
+
|
| 1262 |
+
* idle.py, Attic/idle: Rename idle -> idle.py
|
| 1263 |
+
|
| 1264 |
+
Mon Jan 18 15:18:57 1999 Guido van Rossum <[email protected]>
|
| 1265 |
+
|
| 1266 |
+
* EditorWindow.py, WindowList.py: Only deiconify when iconic.
|
| 1267 |
+
|
| 1268 |
+
* TODO.txt: Misc
|
| 1269 |
+
|
| 1270 |
+
Tue Jan 12 22:14:34 1999 Guido van Rossum <[email protected]>
|
| 1271 |
+
|
| 1272 |
+
* testcode.py, Attic/test.py:
|
| 1273 |
+
Renamed test.py to testcode.py so one can import Python's
|
| 1274 |
+
test package from inside IDLE. (Suggested by Jack Jansen.)
|
| 1275 |
+
|
| 1276 |
+
* EditorWindow.py, ColorDelegator.py:
|
| 1277 |
+
Hack to close a window that is colorizing.
|
| 1278 |
+
|
| 1279 |
+
* Separator.py: Vladimir Marangozov's patch:
|
| 1280 |
+
The separator dances too much and seems to jump by arbitrary amounts
|
| 1281 |
+
in arbitrary directions when I try to move it for resizing the frames.
|
| 1282 |
+
This patch makes it more quiet.
|
| 1283 |
+
|
| 1284 |
+
Mon Jan 11 14:52:40 1999 Guido van Rossum <[email protected]>
|
| 1285 |
+
|
| 1286 |
+
* TODO.txt: Some requests have been fulfilled.
|
| 1287 |
+
|
| 1288 |
+
* EditorWindow.py:
|
| 1289 |
+
Set the cursor to a watch when opening the class browser (which may
|
| 1290 |
+
take quite a while, browsing multiple files).
|
| 1291 |
+
|
| 1292 |
+
Newer, better center() -- but assumes no wrapping.
|
| 1293 |
+
|
| 1294 |
+
* SearchBinding.py:
|
| 1295 |
+
Got rid of debug print statement in goto_line_event().
|
| 1296 |
+
|
| 1297 |
+
* ScriptBinding.py:
|
| 1298 |
+
I think I like it better if it prints the traceback even when it displays
|
| 1299 |
+
the stack viewer.
|
| 1300 |
+
|
| 1301 |
+
* Debugger.py: Bind ESC to close-window.
|
| 1302 |
+
|
| 1303 |
+
* ClassBrowser.py: Use a HSeparator between the classes and the items.
|
| 1304 |
+
Make the list of classes wider by default (40 chars).
|
| 1305 |
+
Bind ESC to close-window.
|
| 1306 |
+
|
| 1307 |
+
* Separator.py:
|
| 1308 |
+
Separator classes (draggable divider between two panes).
|
| 1309 |
+
|
| 1310 |
+
Sat Jan 9 22:01:33 1999 Guido van Rossum <[email protected]>
|
| 1311 |
+
|
| 1312 |
+
* WindowList.py:
|
| 1313 |
+
Don't traceback when wakeup() is called when the window has been destroyed.
|
| 1314 |
+
This can happen when a torn-of Windows menu references closed windows.
|
| 1315 |
+
And Tim Peters claims that the Windows menu is his favorite to tear off...
|
| 1316 |
+
|
| 1317 |
+
* EditorWindow.py: Allow tearing off of the Windows menu.
|
| 1318 |
+
|
| 1319 |
+
* StackViewer.py: Close on ESC.
|
| 1320 |
+
|
| 1321 |
+
* help.txt: Updated a bunch of things (it was mostly still 0.1!)
|
| 1322 |
+
|
| 1323 |
+
* extend.py: Added ScriptBinding to standard bindings.
|
| 1324 |
+
|
| 1325 |
+
* ScriptBinding.py:
|
| 1326 |
+
This now actually works. See doc string. It can run a module (i.e.
|
| 1327 |
+
import or reload) or debug it (same with debugger control). Output
|
| 1328 |
+
goes to a fresh output window, only created when needed.
|
| 1329 |
+
|
| 1330 |
+
======================================================================
|
| 1331 |
+
Python release 1.5.2b1, IDLE version 0.2
|
| 1332 |
+
======================================================================
|
| 1333 |
+
|
| 1334 |
+
Fri Jan 8 17:26:02 1999 Guido van Rossum <[email protected]>
|
| 1335 |
+
|
| 1336 |
+
* README.txt, NEWS.txt: What's new in this release.
|
| 1337 |
+
|
| 1338 |
+
* Bindings.py, PyShell.py:
|
| 1339 |
+
Paul Prescod's patches to allow the stack viewer to pop up when a
|
| 1340 |
+
traceback is printed.
|
| 1341 |
+
|
| 1342 |
+
Thu Jan 7 00:12:15 1999 Guido van Rossum <[email protected]>
|
| 1343 |
+
|
| 1344 |
+
* FormatParagraph.py:
|
| 1345 |
+
Change paragraph width limit to 70 (like Emacs M-Q).
|
| 1346 |
+
|
| 1347 |
+
* README.txt:
|
| 1348 |
+
Separating TODO from README. Slight reformulation of features. No
|
| 1349 |
+
exact release date.
|
| 1350 |
+
|
| 1351 |
+
* TODO.txt: Separating TODO from README.
|
| 1352 |
+
|
| 1353 |
+
Mon Jan 4 21:19:09 1999 Guido van Rossum <[email protected]>
|
| 1354 |
+
|
| 1355 |
+
* FormatParagraph.py:
|
| 1356 |
+
Hm. There was a boundary condition error at the end of the file too.
|
| 1357 |
+
|
| 1358 |
+
* SearchBinding.py: Hm. Add Unix binding for replace, too.
|
| 1359 |
+
|
| 1360 |
+
* keydefs.py: Ran eventparse.py again.
|
| 1361 |
+
|
| 1362 |
+
* FormatParagraph.py: Added Unix Meta-q key binding;
|
| 1363 |
+
fix find_paragraph when at start of file.
|
| 1364 |
+
|
| 1365 |
+
* AutoExpand.py: Added Meta-/ binding for Unix as alt for Alt-/.
|
| 1366 |
+
|
| 1367 |
+
* SearchBinding.py:
|
| 1368 |
+
Add unix binding for grep (otherwise the menu entry doesn't work!)
|
| 1369 |
+
|
| 1370 |
+
* ZoomHeight.py: Adjusted Unix height to work with fvwm96. :=(
|
| 1371 |
+
|
| 1372 |
+
* GrepDialog.py: Need to import sys!
|
| 1373 |
+
|
| 1374 |
+
* help.txt, extend.txt, README.txt: Formatted some paragraphs
|
| 1375 |
+
|
| 1376 |
+
* extend.py, FormatParagraph.py:
|
| 1377 |
+
Add new extension to reformat a (text) paragraph.
|
| 1378 |
+
|
| 1379 |
+
* ZoomHeight.py: Typo in Win specific height setting.
|
| 1380 |
+
|
| 1381 |
+
Sun Jan 3 00:47:35 1999 Guido van Rossum <[email protected]>
|
| 1382 |
+
|
| 1383 |
+
* AutoIndent.py: Added something like Tim Peters' backspace patch.
|
| 1384 |
+
|
| 1385 |
+
* ZoomHeight.py: Adapted to Unix (i.e., more hardcoded constants).
|
| 1386 |
+
|
| 1387 |
+
Sat Jan 2 21:28:54 1999 Guido van Rossum <[email protected]>
|
| 1388 |
+
|
| 1389 |
+
* keydefs.py, idlever.py, idle.pyw, idle.bat, help.txt, extend.txt, extend.py, eventparse.py, ZoomHeight.py, WindowList.py, UndoDelegator.py, StackViewer.py, SearchEngine.py, SearchDialogBase.py, SearchDialog.py, ScrolledList.py, SearchBinding.py, ScriptBinding.py, ReplaceDialog.py, Attic/README, README.txt, PyShell.py, Attic/PopupMenu.py, OutputWindow.py, IOBinding.py, Attic/HelpWindow.py, History.py, GrepDialog.py, FileList.py, FrameViewer.py, EditorWindow.py, Debugger.py, Delegator.py, ColorDelegator.py, Bindings.py, ClassBrowser.py, AutoExpand.py, AutoIndent.py:
|
| 1390 |
+
Checking in IDLE 0.2.
|
| 1391 |
+
|
| 1392 |
+
Much has changed -- too much, in fact, to write down.
|
| 1393 |
+
The big news is that there's a standard way to write IDLE extensions;
|
| 1394 |
+
see extend.txt. Some sample extensions have been provided, and
|
| 1395 |
+
some existing code has been converted to extensions. Probably the
|
| 1396 |
+
biggest new user feature is a new search dialog with more options,
|
| 1397 |
+
search and replace, and even search in files (grep).
|
| 1398 |
+
|
| 1399 |
+
This is exactly as downloaded from my laptop after returning
|
| 1400 |
+
from the holidays -- it hasn't even been tested on Unix yet.
|
| 1401 |
+
|
| 1402 |
+
Fri Dec 18 15:52:54 1998 Guido van Rossum <[email protected]>
|
| 1403 |
+
|
| 1404 |
+
* FileList.py, ClassBrowser.py:
|
| 1405 |
+
Fix the class browser to work even when the file is not on sys.path.
|
| 1406 |
+
|
| 1407 |
+
Tue Dec 8 20:39:36 1998 Guido van Rossum <[email protected]>
|
| 1408 |
+
|
| 1409 |
+
* Attic/turtle.py: Moved to Python 1.5.2/Lib
|
| 1410 |
+
|
| 1411 |
+
Fri Nov 27 03:19:20 1998 Guido van Rossum <[email protected]>
|
| 1412 |
+
|
| 1413 |
+
* help.txt: Typo
|
| 1414 |
+
|
| 1415 |
+
* EditorWindow.py, FileList.py: Support underlining of menu labels
|
| 1416 |
+
|
| 1417 |
+
* Bindings.py:
|
| 1418 |
+
New approach, separate tables for menus (platform-independent) and key
|
| 1419 |
+
definitions (platform-specific), and generating accelerator strings
|
| 1420 |
+
automatically from the key definitions.
|
| 1421 |
+
|
| 1422 |
+
Mon Nov 16 18:37:42 1998 Guido van Rossum <[email protected]>
|
| 1423 |
+
|
| 1424 |
+
* Attic/README: Clarify portability and main program.
|
| 1425 |
+
|
| 1426 |
+
* Attic/README: Added intro for 0.1 release and append Grail notes.
|
| 1427 |
+
|
| 1428 |
+
Mon Oct 26 18:49:00 1998 Guido van Rossum <[email protected]>
|
| 1429 |
+
|
| 1430 |
+
* Attic/turtle.py: root is now a global called _root
|
| 1431 |
+
|
| 1432 |
+
Sat Oct 24 16:38:38 1998 Guido van Rossum <[email protected]>
|
| 1433 |
+
|
| 1434 |
+
* Attic/turtle.py: Raise the root window on reset().
|
| 1435 |
+
Different action on WM_DELETE_WINDOW is more likely to do the right thing,
|
| 1436 |
+
allowing us to destroy old windows.
|
| 1437 |
+
|
| 1438 |
+
* Attic/turtle.py:
|
| 1439 |
+
Split the goto() function in two: _goto() is the internal one,
|
| 1440 |
+
using Canvas coordinates, and goto() uses turtle coordinates
|
| 1441 |
+
and accepts variable argument lists.
|
| 1442 |
+
|
| 1443 |
+
* Attic/turtle.py: Cope with destruction of the window
|
| 1444 |
+
|
| 1445 |
+
* Attic/turtle.py: Turtle graphics
|
| 1446 |
+
|
| 1447 |
+
* Debugger.py: Use of Breakpoint class should be bdb.Breakpoint.
|
| 1448 |
+
|
| 1449 |
+
Mon Oct 19 03:33:40 1998 Guido van Rossum <[email protected]>
|
| 1450 |
+
|
| 1451 |
+
* SearchBinding.py:
|
| 1452 |
+
Speed up the search a bit -- don't drag a mark around...
|
| 1453 |
+
|
| 1454 |
+
* PyShell.py:
|
| 1455 |
+
Change our special entries from <console#N> to <pyshell#N>.
|
| 1456 |
+
Patch linecache.checkcache() to keep our special entries alive.
|
| 1457 |
+
Add popup menu to all editor windows to set a breakpoint.
|
| 1458 |
+
|
| 1459 |
+
* Debugger.py:
|
| 1460 |
+
Use and pass through the 'force' flag to set_dict() where appropriate.
|
| 1461 |
+
Default source and globals checkboxes to false.
|
| 1462 |
+
Don't interact in user_return().
|
| 1463 |
+
Add primitive set_breakpoint() method.
|
| 1464 |
+
|
| 1465 |
+
* ColorDelegator.py:
|
| 1466 |
+
Raise priority of 'sel' tag so its foreground (on Windows) will take
|
| 1467 |
+
priority over text colorization (which on Windows is almost the
|
| 1468 |
+
same color as the selection background).
|
| 1469 |
+
|
| 1470 |
+
Define a tag and color for breakpoints ("BREAK").
|
| 1471 |
+
|
| 1472 |
+
* Attic/PopupMenu.py: Disable "Open stack viewer" and "help" commands.
|
| 1473 |
+
|
| 1474 |
+
* StackViewer.py:
|
| 1475 |
+
Add optional 'force' argument (default 0) to load_dict().
|
| 1476 |
+
If set, redo the display even if it's the same dict.
|
| 1477 |
+
|
| 1478 |
+
Fri Oct 16 21:10:12 1998 Guido van Rossum <[email protected]>
|
| 1479 |
+
|
| 1480 |
+
* StackViewer.py: Do nothing when loading the same dict as before.
|
| 1481 |
+
|
| 1482 |
+
* PyShell.py: Details for debugger interface.
|
| 1483 |
+
|
| 1484 |
+
* Debugger.py:
|
| 1485 |
+
Restructured and more consistent. Save checkboxes across instantiations.
|
| 1486 |
+
|
| 1487 |
+
* EditorWindow.py, Attic/README, Bindings.py:
|
| 1488 |
+
Get rid of conflicting ^X binding. Use ^W.
|
| 1489 |
+
|
| 1490 |
+
* Debugger.py, StackViewer.py:
|
| 1491 |
+
Debugger can now show local and global variables.
|
| 1492 |
+
|
| 1493 |
+
* Debugger.py: Oops
|
| 1494 |
+
|
| 1495 |
+
* Debugger.py, PyShell.py: Better debugger support (show stack etc).
|
| 1496 |
+
|
| 1497 |
+
* Attic/PopupMenu.py: Follow renames in StackViewer module
|
| 1498 |
+
|
| 1499 |
+
* StackViewer.py:
|
| 1500 |
+
Rename classes to StackViewer (the widget) and StackBrowser (the toplevel).
|
| 1501 |
+
|
| 1502 |
+
* ScrolledList.py: Add close() method
|
| 1503 |
+
|
| 1504 |
+
* EditorWindow.py: Clarify 'Open Module' dialog text
|
| 1505 |
+
|
| 1506 |
+
* StackViewer.py: Restructured into a browser and a widget.
|
| 1507 |
+
|
| 1508 |
+
Thu Oct 15 23:27:08 1998 Guido van Rossum <[email protected]>
|
| 1509 |
+
|
| 1510 |
+
* ClassBrowser.py, ScrolledList.py:
|
| 1511 |
+
Generalized the scrolled list which is the base for the class and
|
| 1512 |
+
method browser into a separate class in its own module.
|
| 1513 |
+
|
| 1514 |
+
* Attic/test.py: Cosmetic change
|
| 1515 |
+
|
| 1516 |
+
* Debugger.py: Don't show function name if there is none
|
| 1517 |
+
|
| 1518 |
+
Wed Oct 14 03:43:05 1998 Guido van Rossum <[email protected]>
|
| 1519 |
+
|
| 1520 |
+
* Debugger.py, PyShell.py: Polish the Debugger GUI a bit.
|
| 1521 |
+
Closing it now also does the right thing.
|
| 1522 |
+
|
| 1523 |
+
Tue Oct 13 23:51:13 1998 Guido van Rossum <[email protected]>
|
| 1524 |
+
|
| 1525 |
+
* Debugger.py, PyShell.py, Bindings.py:
|
| 1526 |
+
Ad primitive debugger interface (so far it will step and show you the
|
| 1527 |
+
source, but it doesn't yet show the stack).
|
| 1528 |
+
|
| 1529 |
+
* Attic/README: Misc
|
| 1530 |
+
|
| 1531 |
+
* StackViewer.py: Whoops -- referenced self.top before it was set.
|
| 1532 |
+
|
| 1533 |
+
* help.txt: Added history and completion commands.
|
| 1534 |
+
|
| 1535 |
+
* help.txt: Updated
|
| 1536 |
+
|
| 1537 |
+
* FileList.py: Add class browser functionality.
|
| 1538 |
+
|
| 1539 |
+
* StackViewer.py:
|
| 1540 |
+
Add a close() method and bind to WM_DELETE_WINDOW protocol
|
| 1541 |
+
|
| 1542 |
+
* PyShell.py: Clear the linecache before printing a traceback
|
| 1543 |
+
|
| 1544 |
+
* Bindings.py: Added class browser binding.
|
| 1545 |
+
|
| 1546 |
+
* ClassBrowser.py: Much improved, much left to do.
|
| 1547 |
+
|
| 1548 |
+
* PyShell.py: Make the return key do what I mean more often.
|
| 1549 |
+
|
| 1550 |
+
* ClassBrowser.py:
|
| 1551 |
+
Adding the beginnings of a Class browser. Incomplete, yet.
|
| 1552 |
+
|
| 1553 |
+
* EditorWindow.py, Bindings.py:
|
| 1554 |
+
Add new command, "Open module". You select or type a module name,
|
| 1555 |
+
and it opens the source.
|
| 1556 |
+
|
| 1557 |
+
Mon Oct 12 23:59:27 1998 Guido van Rossum <[email protected]>
|
| 1558 |
+
|
| 1559 |
+
* PyShell.py: Subsume functionality from Popup menu in Debug menu.
|
| 1560 |
+
Other stuff so the PyShell window can be resurrected from the Windows menu.
|
| 1561 |
+
|
| 1562 |
+
* FileList.py: Get rid of PopUp menu.
|
| 1563 |
+
Create a simple Windows menu. (Imperfect when Untitled windows exist.)
|
| 1564 |
+
Add wakeup() method: deiconify, raise, focus.
|
| 1565 |
+
|
| 1566 |
+
* EditorWindow.py: Generalize menu creation.
|
| 1567 |
+
|
| 1568 |
+
* Bindings.py: Add Debug and Help menu items.
|
| 1569 |
+
|
| 1570 |
+
* EditorWindow.py: Added a menu bar to every window.
|
| 1571 |
+
|
| 1572 |
+
* Bindings.py: Add menu configuration to the event configuration.
|
| 1573 |
+
|
| 1574 |
+
* Attic/PopupMenu.py: Pass a root to the help window.
|
| 1575 |
+
|
| 1576 |
+
* SearchBinding.py:
|
| 1577 |
+
Add parent argument to 'go to line number' dialog box.
|
| 1578 |
+
|
| 1579 |
+
Sat Oct 10 19:15:32 1998 Guido van Rossum <[email protected]>
|
| 1580 |
+
|
| 1581 |
+
* StackViewer.py:
|
| 1582 |
+
Add a label at the top showing (very basic) help for the stack viewer.
|
| 1583 |
+
Add a label at the bottom showing the exception info.
|
| 1584 |
+
|
| 1585 |
+
* Attic/test.py, Attic/idle: Add Unix main script and test program.
|
| 1586 |
+
|
| 1587 |
+
* idle.pyw, help.txt, WidgetRedirector.py, UndoDelegator.py, StackViewer.py, SearchBinding.py, Attic/README, PyShell.py, Attic/PopupMenu.py, Percolator.py, Outline.py, IOBinding.py, History.py, Attic/HelpWindow.py, FrameViewer.py, FileList.py, EditorWindow.py, Delegator.py, ColorDelegator.py, Bindings.py, AutoIndent.py, AutoExpand.py:
|
| 1588 |
+
Initial checking of Tk-based Python IDE.
|
| 1589 |
+
Features: text editor with syntax coloring and undo;
|
| 1590 |
+
subclassed into interactive Python shell which adds history.
|
| 1591 |
+
|
evalkit_cambrian/lib/python3.10/idlelib/HISTORY.txt
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
IDLE History
|
| 2 |
+
============
|
| 3 |
+
|
| 4 |
+
This file contains the release messages for previous IDLE releases.
|
| 5 |
+
As you read on you go back to the dark ages of IDLE's history.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
What's New in IDLEfork 0.8.1?
|
| 9 |
+
=============================
|
| 10 |
+
|
| 11 |
+
*Release date: 22-Jul-2001*
|
| 12 |
+
|
| 13 |
+
- New tarball released as a result of the 'revitalisation' of the IDLEfork
|
| 14 |
+
project.
|
| 15 |
+
|
| 16 |
+
- This release requires python 2.1 or better. Compatibility with earlier
|
| 17 |
+
versions of python (especially ancient ones like 1.5x) is no longer a
|
| 18 |
+
priority in IDLEfork development.
|
| 19 |
+
|
| 20 |
+
- This release is based on a merging of the earlier IDLE fork work with current
|
| 21 |
+
cvs IDLE (post IDLE version 0.8), with some minor additional coding by Kurt
|
| 22 |
+
B. Kaiser and Stephen M. Gava.
|
| 23 |
+
|
| 24 |
+
- This release is basically functional but also contains some known breakages,
|
| 25 |
+
particularly with running things from the shell window. Also the debugger is
|
| 26 |
+
not working, but I believe this was the case with the previous IDLE fork
|
| 27 |
+
release (0.7.1) as well.
|
| 28 |
+
|
| 29 |
+
- This release is being made now to mark the point at which IDLEfork is
|
| 30 |
+
launching into a new stage of development.
|
| 31 |
+
|
| 32 |
+
- IDLEfork CVS will now be branched to enable further development and
|
| 33 |
+
exploration of the two "execution in a remote process" patches submitted by
|
| 34 |
+
David Scherer (David's is currently in IDLEfork) and GvR, while stabilisation
|
| 35 |
+
and development of less heavyweight improvements (like user customisation)
|
| 36 |
+
can continue on the trunk.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
What's New in IDLEfork 0.7.1?
|
| 40 |
+
==============================
|
| 41 |
+
|
| 42 |
+
*Release date: 15-Aug-2000*
|
| 43 |
+
|
| 44 |
+
- First project tarball released.
|
| 45 |
+
|
| 46 |
+
- This was the first release of IDLE fork, which at this stage was a
|
| 47 |
+
combination of IDLE 0.5 and the VPython idle fork, with additional changes
|
| 48 |
+
coded by David Scherer, Peter Schneider-Kamp and Nicholas Riley.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
IDLEfork 0.7.1 - 29 May 2000
|
| 53 |
+
-----------------------------
|
| 54 |
+
|
| 55 |
+
David Scherer <[email protected]>
|
| 56 |
+
|
| 57 |
+
- This is a modification of the CVS version of IDLE 0.5, updated as of
|
| 58 |
+
2000-03-09. It is alpha software and might be unstable. If it breaks, you
|
| 59 |
+
get to keep both pieces.
|
| 60 |
+
|
| 61 |
+
- If you have problems or suggestions, you should either contact me or post to
|
| 62 |
+
the list at http://www.python.org/mailman/listinfo/idle-dev (making it clear
|
| 63 |
+
that you are using this modified version of IDLE).
|
| 64 |
+
|
| 65 |
+
- Changes:
|
| 66 |
+
|
| 67 |
+
- The ExecBinding module, a replacement for ScriptBinding, executes programs
|
| 68 |
+
in a separate process, piping standard I/O through an RPC mechanism to an
|
| 69 |
+
OnDemandOutputWindow in IDLE. It supports executing unnamed programs
|
| 70 |
+
(through a temporary file). It does not yet support debugging.
|
| 71 |
+
|
| 72 |
+
- When running programs with ExecBinding, tracebacks will be clipped to
|
| 73 |
+
exclude system modules. If, however, a system module calls back into the
|
| 74 |
+
user program, that part of the traceback will be shown.
|
| 75 |
+
|
| 76 |
+
- The OnDemandOutputWindow class has been improved. In particular, it now
|
| 77 |
+
supports a readline() function used to implement user input, and a
|
| 78 |
+
scroll_clear() operation which is used to hide the output of a previous run
|
| 79 |
+
by scrolling it out of the window.
|
| 80 |
+
|
| 81 |
+
- Startup behavior has been changed. By default IDLE starts up with just a
|
| 82 |
+
blank editor window, rather than an interactive window. Opening a file in
|
| 83 |
+
such a blank window replaces the (nonexistent) contents of that window
|
| 84 |
+
instead of creating another window. Because of the need to have a
|
| 85 |
+
well-known port for the ExecBinding protocol, only one copy of IDLE can be
|
| 86 |
+
running. Additional invocations use the RPC mechanism to report their
|
| 87 |
+
command line arguments to the copy already running.
|
| 88 |
+
|
| 89 |
+
- The menus have been reorganized. In particular, the excessively large
|
| 90 |
+
'edit' menu has been split up into 'edit', 'format', and 'run'.
|
| 91 |
+
|
| 92 |
+
- 'Python Documentation' now works on Windows, if the win32api module is
|
| 93 |
+
present.
|
| 94 |
+
|
| 95 |
+
- A few key bindings have been changed: F1 now loads Python Documentation
|
| 96 |
+
instead of the IDLE help; shift-TAB is now a synonym for unindent.
|
| 97 |
+
|
| 98 |
+
- New modules:
|
| 99 |
+
|
| 100 |
+
ExecBinding.py Executes program through loader
|
| 101 |
+
loader.py Bootstraps user program
|
| 102 |
+
protocol.py RPC protocol
|
| 103 |
+
Remote.py User-process interpreter
|
| 104 |
+
spawn.py OS-specific code to start programs
|
| 105 |
+
|
| 106 |
+
- Files modified:
|
| 107 |
+
|
| 108 |
+
autoindent.py ( bindings tweaked )
|
| 109 |
+
bindings.py ( menus reorganized )
|
| 110 |
+
config.txt ( execbinding enabled )
|
| 111 |
+
editorwindow.py ( new menus, fixed 'Python Documentation' )
|
| 112 |
+
filelist.py ( hook for "open in same window" )
|
| 113 |
+
formatparagraph.py ( bindings tweaked )
|
| 114 |
+
idle.bat ( removed absolute pathname )
|
| 115 |
+
idle.pyw ( weird bug due to import with same name? )
|
| 116 |
+
iobinding.py ( open in same window, EOL convention )
|
| 117 |
+
keydefs.py ( bindings tweaked )
|
| 118 |
+
outputwindow.py ( readline, scroll_clear, etc )
|
| 119 |
+
pyshell.py ( changed startup behavior )
|
| 120 |
+
readme.txt ( <Recursion on file with id=1234567> )
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
IDLE 0.5 - February 2000 - Release Notes
|
| 125 |
+
----------------------------------------
|
| 126 |
+
|
| 127 |
+
This is an early release of IDLE, my own attempt at a Tkinter-based
|
| 128 |
+
IDE for Python.
|
| 129 |
+
|
| 130 |
+
(For a more detailed change log, see the file ChangeLog.)
|
| 131 |
+
|
| 132 |
+
FEATURES
|
| 133 |
+
|
| 134 |
+
IDLE has the following features:
|
| 135 |
+
|
| 136 |
+
- coded in 100% pure Python, using the Tkinter GUI toolkit (i.e. Tcl/Tk)
|
| 137 |
+
|
| 138 |
+
- cross-platform: works on Windows and Unix (on the Mac, there are
|
| 139 |
+
currently problems with Tcl/Tk)
|
| 140 |
+
|
| 141 |
+
- multi-window text editor with multiple undo, Python colorizing
|
| 142 |
+
and many other features, e.g. smart indent and call tips
|
| 143 |
+
|
| 144 |
+
- Python shell window (a.k.a. interactive interpreter)
|
| 145 |
+
|
| 146 |
+
- debugger (not complete, but you can set breakpoints, view and step)
|
| 147 |
+
|
| 148 |
+
USAGE
|
| 149 |
+
|
| 150 |
+
The main program is in the file "idle.py"; on Unix, you should be able
|
| 151 |
+
to run it by typing "./idle.py" to your shell. On Windows, you can
|
| 152 |
+
run it by double-clicking it; you can use idle.pyw to avoid popping up
|
| 153 |
+
a DOS console. If you want to pass command line arguments on Windows,
|
| 154 |
+
use the batch file idle.bat.
|
| 155 |
+
|
| 156 |
+
Command line arguments: files passed on the command line are executed,
|
| 157 |
+
not opened for editing, unless you give the -e command line option.
|
| 158 |
+
Try "./idle.py -h" to see other command line options.
|
| 159 |
+
|
| 160 |
+
IDLE requires Python 1.5.2, so it is currently only usable with a
|
| 161 |
+
Python 1.5.2 distribution. (An older version of IDLE is distributed
|
| 162 |
+
with Python 1.5.2; you can drop this version on top of it.)
|
| 163 |
+
|
| 164 |
+
COPYRIGHT
|
| 165 |
+
|
| 166 |
+
IDLE is covered by the standard Python copyright notice
|
| 167 |
+
(http://www.python.org/doc/Copyright.html).
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
New in IDLE 0.5 (2/15/2000)
|
| 171 |
+
---------------------------
|
| 172 |
+
|
| 173 |
+
Tons of stuff, much of it contributed by Tim Peters and Mark Hammond:
|
| 174 |
+
|
| 175 |
+
- Status bar, displaying current line/column (Moshe Zadka).
|
| 176 |
+
|
| 177 |
+
- Better stack viewer, using tree widget. (XXX Only used by Stack
|
| 178 |
+
Viewer menu, not by the debugger.)
|
| 179 |
+
|
| 180 |
+
- Format paragraph now recognizes Python block comments and reformats
|
| 181 |
+
them correctly (MH)
|
| 182 |
+
|
| 183 |
+
- New version of pyclbr.py parses top-level functions and understands
|
| 184 |
+
much more of Python's syntax; this is reflected in the class and path
|
| 185 |
+
browsers (TP)
|
| 186 |
+
|
| 187 |
+
- Much better auto-indent; knows how to indent the insides of
|
| 188 |
+
multi-line statements (TP)
|
| 189 |
+
|
| 190 |
+
- Call tip window pops up when you type the name of a known function
|
| 191 |
+
followed by an open parenthesis. Hit ESC or click elsewhere in the
|
| 192 |
+
window to close the tip window (MH)
|
| 193 |
+
|
| 194 |
+
- Comment out region now inserts ## to make it stand out more (TP)
|
| 195 |
+
|
| 196 |
+
- New path and class browsers based on a tree widget that looks
|
| 197 |
+
familiar to Windows users
|
| 198 |
+
|
| 199 |
+
- Reworked script running commands to be more intuitive: I/O now
|
| 200 |
+
always goes to the *Python Shell* window, and raw_input() works
|
| 201 |
+
correctly. You use F5 to import/reload a module: this adds the module
|
| 202 |
+
name to the __main__ namespace. You use Control-F5 to run a script:
|
| 203 |
+
this runs the script *in* the __main__ namespace. The latter also
|
| 204 |
+
sets sys.argv[] to the script name
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
New in IDLE 0.4 (4/7/99)
|
| 208 |
+
------------------------
|
| 209 |
+
|
| 210 |
+
Most important change: a new menu entry "File -> Path browser", shows
|
| 211 |
+
a 4-column hierarchical browser which lets you browse sys.path,
|
| 212 |
+
directories, modules, and classes. Yes, it's a superset of the Class
|
| 213 |
+
browser menu entry. There's also a new internal module,
|
| 214 |
+
MultiScrolledLists.py, which provides the framework for this dialog.
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
New in IDLE 0.3 (2/17/99)
|
| 218 |
+
-------------------------
|
| 219 |
+
|
| 220 |
+
Most important changes:
|
| 221 |
+
|
| 222 |
+
- Enabled support for running a module, with or without the debugger.
|
| 223 |
+
Output goes to a new window. Pressing F5 in a module is effectively a
|
| 224 |
+
reload of that module; Control-F5 loads it under the debugger.
|
| 225 |
+
|
| 226 |
+
- Re-enable tearing off the Windows menu, and make a torn-off Windows
|
| 227 |
+
menu update itself whenever a window is opened or closed.
|
| 228 |
+
|
| 229 |
+
- Menu items can now be have a checkbox (when the menu label starts
|
| 230 |
+
with "!"); use this for the Debugger and "Auto-open stack viewer"
|
| 231 |
+
(was: JIT stack viewer) menu items.
|
| 232 |
+
|
| 233 |
+
- Added a Quit button to the Debugger API.
|
| 234 |
+
|
| 235 |
+
- The current directory is explicitly inserted into sys.path.
|
| 236 |
+
|
| 237 |
+
- Fix the debugger (when using Python 1.5.2b2) to use canonical
|
| 238 |
+
filenames for breakpoints, so these actually work. (There's still a
|
| 239 |
+
lot of work to be done to the management of breakpoints in the
|
| 240 |
+
debugger though.)
|
| 241 |
+
|
| 242 |
+
- Closing a window that is still colorizing now actually works.
|
| 243 |
+
|
| 244 |
+
- Allow dragging of the separator between the two list boxes in the
|
| 245 |
+
class browser.
|
| 246 |
+
|
| 247 |
+
- Bind ESC to "close window" of the debugger, stack viewer and class
|
| 248 |
+
browser. It removes the selection highlighting in regular text
|
| 249 |
+
windows. (These are standard Windows conventions.)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
New in IDLE 0.2 (1/8/99)
|
| 253 |
+
------------------------
|
| 254 |
+
|
| 255 |
+
Lots of changes; here are the highlights:
|
| 256 |
+
|
| 257 |
+
General:
|
| 258 |
+
|
| 259 |
+
- You can now write and configure your own IDLE extension modules; see
|
| 260 |
+
extend.txt.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
File menu:
|
| 264 |
+
|
| 265 |
+
The command to open the Python shell window is now in the File menu.
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
Edit menu:
|
| 269 |
+
|
| 270 |
+
New Find dialog with more options; replace dialog; find in files dialog.
|
| 271 |
+
|
| 272 |
+
Commands to tabify or untabify a region.
|
| 273 |
+
|
| 274 |
+
Command to format a paragraph.
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
Debug menu:
|
| 278 |
+
|
| 279 |
+
JIT (Just-In-Time) stack viewer toggle -- if set, the stack viewer
|
| 280 |
+
automaticall pops up when you get a traceback.
|
| 281 |
+
|
| 282 |
+
Windows menu:
|
| 283 |
+
|
| 284 |
+
Zoom height -- make the window full height.
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
Help menu:
|
| 288 |
+
|
| 289 |
+
The help text now show up in a regular window so you can search and
|
| 290 |
+
even edit it if you like.
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
IDLE 0.1 was distributed with the Python 1.5.2b1 release on 12/22/98.
|
| 295 |
+
|
| 296 |
+
======================================================================
|
evalkit_cambrian/lib/python3.10/idlelib/NEWS2x.txt
ADDED
|
@@ -0,0 +1,660 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
What's New in IDLE 2.7? (Merged into 3.1 before 2.7 release.)
|
| 2 |
+
=======================
|
| 3 |
+
*Release date: XX-XXX-2010*
|
| 4 |
+
|
| 5 |
+
- idle.py modified and simplified to better support developing experimental
|
| 6 |
+
versions of IDLE which are not installed in the standard location.
|
| 7 |
+
|
| 8 |
+
- OutputWindow/PyShell right click menu "Go to file/line" wasn't working with
|
| 9 |
+
file paths containing spaces. Bug 5559.
|
| 10 |
+
|
| 11 |
+
- Windows: Version string for the .chm help file changed, file not being
|
| 12 |
+
accessed Patch 5783 Guilherme Polo
|
| 13 |
+
|
| 14 |
+
- Allow multiple IDLE GUI/subprocess pairs to exist simultaneously. Thanks to
|
| 15 |
+
David Scherer for suggesting the use of an ephemeral port for the GUI.
|
| 16 |
+
Patch 1529142 Weeble.
|
| 17 |
+
|
| 18 |
+
- Remove port spec from run.py and fix bug where subprocess fails to
|
| 19 |
+
extract port from command line when warnings are present.
|
| 20 |
+
|
| 21 |
+
- Tk 8.5 Text widget requires 'wordprocessor' tabstyle attr to handle
|
| 22 |
+
mixed space/tab properly. Issue 5129, patch by Guilherme Polo.
|
| 23 |
+
|
| 24 |
+
- Issue #3549: On MacOS the preferences menu was not present
|
| 25 |
+
|
| 26 |
+
- IDLE would print a "Unhandled server exception!" message when internal
|
| 27 |
+
debugging is enabled.
|
| 28 |
+
|
| 29 |
+
- Issue #4455: IDLE failed to display the windows list when two windows have
|
| 30 |
+
the same title.
|
| 31 |
+
|
| 32 |
+
- Issue #4383: When IDLE cannot make the connection to its subprocess, it would
|
| 33 |
+
fail to properly display the error message.
|
| 34 |
+
|
| 35 |
+
- help() was not paging to the shell. Issue1650.
|
| 36 |
+
|
| 37 |
+
- CodeContext was not importing.
|
| 38 |
+
|
| 39 |
+
- Corrected two 3.0 compatibility errors reported by Mark Summerfield:
|
| 40 |
+
http://mail.python.org/pipermail/python-3000/2007-December/011491.html
|
| 41 |
+
|
| 42 |
+
- Shell was not colorizing due to bug introduced at r57998, Bug 1586.
|
| 43 |
+
|
| 44 |
+
- Issue #1585: IDLE uses non-existent xrange() function.
|
| 45 |
+
|
| 46 |
+
- Windows EOL sequence not converted correctly, encoding error.
|
| 47 |
+
Caused file save to fail. Bug 1130.
|
| 48 |
+
|
| 49 |
+
- IDLE converted to Python 3000 syntax.
|
| 50 |
+
|
| 51 |
+
- Strings became Unicode.
|
| 52 |
+
|
| 53 |
+
- CallTips module now uses the inspect module to produce the argspec.
|
| 54 |
+
|
| 55 |
+
- IDLE modules now use absolute import instead of implied relative import.
|
| 56 |
+
|
| 57 |
+
- atexit call replaces sys.exitfunc. The functionality of delete-exitfunc flag
|
| 58 |
+
in config-main.cfg remains unchanged: if set, registered exit functions will
|
| 59 |
+
be cleared before IDLE exits.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
What's New in IDLE 2.6
|
| 63 |
+
======================
|
| 64 |
+
*Release date: 01-Oct-2008*, merged into 3.0 releases detailed above (3.0rc2)
|
| 65 |
+
|
| 66 |
+
- Issue #2665: On Windows, an IDLE installation upgraded from an old version
|
| 67 |
+
would not start if a custom theme was defined.
|
| 68 |
+
|
| 69 |
+
- Home / Control-A toggles between left margin and end of leading white
|
| 70 |
+
space. issue1196903, patch by Jeff Shute.
|
| 71 |
+
|
| 72 |
+
- Improved AutoCompleteWindow logic. issue2062, patch by Tal Einat.
|
| 73 |
+
|
| 74 |
+
- Autocompletion of filenames now support alternate separators, e.g. the
|
| 75 |
+
'/' char on Windows. issue2061 Patch by Tal Einat.
|
| 76 |
+
|
| 77 |
+
- Configured selection highlighting colors were ignored; updating highlighting
|
| 78 |
+
in the config dialog would cause non-Python files to be colored as if they
|
| 79 |
+
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
|
| 80 |
+
|
| 81 |
+
- ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat
|
| 82 |
+
|
| 83 |
+
- There was an error on exit if no sys.exitfunc was defined. Issue 1647.
|
| 84 |
+
|
| 85 |
+
- Could not open files in .idlerc directory if latter was hidden on Windows.
|
| 86 |
+
Issue 1743, Issue 1862.
|
| 87 |
+
|
| 88 |
+
- Configure Dialog: improved layout for keybinding. Patch 1457 Tal Einat.
|
| 89 |
+
|
| 90 |
+
- tabpage.py updated: tabbedPages.py now supports multiple dynamic rows
|
| 91 |
+
of tabs. Patch 1612746 Tal Einat.
|
| 92 |
+
|
| 93 |
+
- Add confirmation dialog before printing. Patch 1717170 Tal Einat.
|
| 94 |
+
|
| 95 |
+
- Show paste position if > 80 col. Patch 1659326 Tal Einat.
|
| 96 |
+
|
| 97 |
+
- Update cursor color without restarting. Patch 1725576 Tal Einat.
|
| 98 |
+
|
| 99 |
+
- Allow keyboard interrupt only when user code is executing in subprocess.
|
| 100 |
+
Patch 1225 Tal Einat (reworked from IDLE-Spoon).
|
| 101 |
+
|
| 102 |
+
- configDialog cleanup. Patch 1730217 Tal Einat.
|
| 103 |
+
|
| 104 |
+
- textView cleanup. Patch 1718043 Tal Einat.
|
| 105 |
+
|
| 106 |
+
- Clean up EditorWindow close.
|
| 107 |
+
|
| 108 |
+
- Patch 1693258: Fix for duplicate "preferences" menu-OS X. Backport of r56204.
|
| 109 |
+
|
| 110 |
+
- OSX: Avoid crash for those versions of Tcl/Tk which don't have a console
|
| 111 |
+
|
| 112 |
+
- Bug in idlelib.MultiCall: Options dialog was crashing IDLE if there was an
|
| 113 |
+
option in config-extensions w/o a value. Patch #1672481, Tal Einat
|
| 114 |
+
|
| 115 |
+
- Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
|
| 116 |
+
mouse and cursor selection in ACWindow implemented; double Tab inserts
|
| 117 |
+
current selection and closes ACW (similar to double-click and Return); scroll
|
| 118 |
+
wheel now works in ACW. Added AutoComplete instructions to IDLE Help.
|
| 119 |
+
|
| 120 |
+
- AutoCompleteWindow moved below input line, will move above if there
|
| 121 |
+
isn't enough space. Patch 1621265 Tal Einat
|
| 122 |
+
|
| 123 |
+
- Calltips now 'handle' tuples in the argument list (display '<tuple>' :)
|
| 124 |
+
Suggested solution by Christos Georgiou, Bug 791968.
|
| 125 |
+
|
| 126 |
+
- Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
|
| 127 |
+
|
| 128 |
+
- Avoid hang when encountering a duplicate in a completion list. Bug 1571112.
|
| 129 |
+
|
| 130 |
+
- Patch #1362975: Rework CodeContext indentation algorithm to
|
| 131 |
+
avoid hard-coding pixel widths.
|
| 132 |
+
|
| 133 |
+
- Bug #813342: Start the IDLE subprocess with -Qnew if the parent
|
| 134 |
+
is started with that option.
|
| 135 |
+
|
| 136 |
+
- Honor the "Cancel" action in the save dialog (Debian bug #299092)
|
| 137 |
+
|
| 138 |
+
- Some syntax errors were being caught by tokenize during the tabnanny
|
| 139 |
+
check, resulting in obscure error messages. Do the syntax check
|
| 140 |
+
first. Bug 1562716, 1562719
|
| 141 |
+
|
| 142 |
+
- IDLE's version number takes a big jump to match the version number of
|
| 143 |
+
the Python release of which it's a part.
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
What's New in IDLE 1.2?
|
| 147 |
+
=======================
|
| 148 |
+
*Release date: 19-SEP-2006*
|
| 149 |
+
|
| 150 |
+
- File menu hotkeys: there were three 'p' assignments. Reassign the
|
| 151 |
+
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
|
| 152 |
+
Shell hotkey from 's' to 'l'.
|
| 153 |
+
|
| 154 |
+
- IDLE honors new quit() and exit() commands from site.py Quitter() object.
|
| 155 |
+
Patch 1540892, Jim Jewett
|
| 156 |
+
|
| 157 |
+
- The 'with' statement is now a Code Context block opener.
|
| 158 |
+
Patch 1540851, Jim Jewett
|
| 159 |
+
|
| 160 |
+
- Retrieval of previous shell command was not always preserving indentation
|
| 161 |
+
(since 1.2a1) Patch 1528468 Tal Einat.
|
| 162 |
+
|
| 163 |
+
- Changing tokenize (39046) to detect dedent broke tabnanny check (since 1.2a1)
|
| 164 |
+
|
| 165 |
+
- ToggleTab dialog was setting indent to 8 even if cancelled (since 1.2a1).
|
| 166 |
+
|
| 167 |
+
- When used w/o subprocess, all exceptions were preceded by an error
|
| 168 |
+
message claiming they were IDLE internal errors (since 1.2a1).
|
| 169 |
+
|
| 170 |
+
- Bug #1525817: Don't truncate short lines in IDLE's tool tips.
|
| 171 |
+
|
| 172 |
+
- Bug #1517990: IDLE keybindings on MacOS X now work correctly
|
| 173 |
+
|
| 174 |
+
- Bug #1517996: IDLE now longer shows the default Tk menu when a
|
| 175 |
+
path browser, class browser or debugger is the frontmost window on MacOS X
|
| 176 |
+
|
| 177 |
+
- EditorWindow.test() was failing. Bug 1417598
|
| 178 |
+
|
| 179 |
+
- EditorWindow failed when used stand-alone if sys.ps1 not set.
|
| 180 |
+
Bug 1010370 Dave Florek
|
| 181 |
+
|
| 182 |
+
- Tooltips failed on new-syle class __init__ args. Bug 1027566 Loren Guthrie
|
| 183 |
+
|
| 184 |
+
- Avoid occasional failure to detect closing paren properly.
|
| 185 |
+
Patch 1407280 Tal Einat
|
| 186 |
+
|
| 187 |
+
- Rebinding Tab key was inserting 'tab' instead of 'Tab'. Bug 1179168.
|
| 188 |
+
|
| 189 |
+
- Colorizer now handles #<builtin> correctly, also unicode strings and
|
| 190 |
+
'as' keyword in comment directly following import command. Closes 1325071.
|
| 191 |
+
Patch 1479219 Tal Einat
|
| 192 |
+
|
| 193 |
+
- Patch #1162825: Support non-ASCII characters in IDLE window titles.
|
| 194 |
+
|
| 195 |
+
- Source file f.flush() after writing; trying to avoid lossage if user
|
| 196 |
+
kills GUI.
|
| 197 |
+
|
| 198 |
+
- Options / Keys / Advanced dialog made functional. Also, allow binding
|
| 199 |
+
of 'movement' keys.
|
| 200 |
+
|
| 201 |
+
- 'syntax' patch adds improved calltips and a new class attribute listbox.
|
| 202 |
+
MultiCall module allows binding multiple actions to an event.
|
| 203 |
+
Patch 906702 Noam Raphael
|
| 204 |
+
|
| 205 |
+
- Better indentation after first line of string continuation.
|
| 206 |
+
IDLEfork Patch 681992, Noam Raphael
|
| 207 |
+
|
| 208 |
+
- Fixed CodeContext alignment problem, following suggestion from Tal Einat.
|
| 209 |
+
|
| 210 |
+
- Increased performance in CodeContext extension Patch 936169 Noam Raphael
|
| 211 |
+
|
| 212 |
+
- Mac line endings were incorrect when pasting code from some browsers
|
| 213 |
+
when using X11 and the Fink distribution. Python Bug 1263656.
|
| 214 |
+
|
| 215 |
+
- <Enter> when cursor is on a previous command retrieves that command. Instead
|
| 216 |
+
of replacing the input line, the previous command is now appended to the
|
| 217 |
+
input line. Indentation is preserved, and undo is enabled.
|
| 218 |
+
Patch 1196917 Jeff Shute
|
| 219 |
+
|
| 220 |
+
- Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
|
| 221 |
+
the Untabify command.
|
| 222 |
+
|
| 223 |
+
- Corrected "tab/space" Error Dialog to show correct menu for Untabify.
|
| 224 |
+
Patch 1196980 Jeff Shute
|
| 225 |
+
|
| 226 |
+
- New files are colorized by default, and colorizing is removed when
|
| 227 |
+
saving as non-Python files. Patch 1196895 Jeff Shute
|
| 228 |
+
Closes Python Bugs 775012 and 800432, partial fix IDLEfork 763524
|
| 229 |
+
|
| 230 |
+
- Improve subprocess link error notification.
|
| 231 |
+
|
| 232 |
+
- run.py: use Queue's blocking feature instead of sleeping in the main
|
| 233 |
+
loop. Patch # 1190163 Michiel de Hoon
|
| 234 |
+
|
| 235 |
+
- Add config-main option to make the 'history' feature non-cyclic.
|
| 236 |
+
Default remains cyclic. Python Patch 914546 Noam Raphael.
|
| 237 |
+
|
| 238 |
+
- Removed ability to configure tabs indent from Options dialog. This 'feature'
|
| 239 |
+
has never worked and no one has complained. It is still possible to set a
|
| 240 |
+
default tabs (v. spaces) indent 'manually' via config-main.def (or to turn on
|
| 241 |
+
tabs for the current EditorWindow via the Format menu) but IDLE will
|
| 242 |
+
encourage indentation via spaces.
|
| 243 |
+
|
| 244 |
+
- Enable setting the indentation width using the Options dialog.
|
| 245 |
+
Bug # 783877
|
| 246 |
+
|
| 247 |
+
- Add keybindings for del-word-left and del-word-right.
|
| 248 |
+
|
| 249 |
+
- Discourage using an indent width other than 8 when using tabs to indent
|
| 250 |
+
Python code.
|
| 251 |
+
|
| 252 |
+
- Restore use of EditorWindow.set_indentation_params(), was dead code since
|
| 253 |
+
Autoindent was merged into EditorWindow. This allows IDLE to conform to the
|
| 254 |
+
indentation width of a loaded file. (But it still will not switch to tabs
|
| 255 |
+
even if the file uses tabs.) Any change in indent width is local to that
|
| 256 |
+
window.
|
| 257 |
+
|
| 258 |
+
- Add Tabnanny check before Run/F5, not just when Checking module.
|
| 259 |
+
|
| 260 |
+
- If an extension can't be loaded, print warning and skip it instead of
|
| 261 |
+
erroring out.
|
| 262 |
+
|
| 263 |
+
- Improve error handling when .idlerc can't be created (warn and exit).
|
| 264 |
+
|
| 265 |
+
- The GUI was hanging if the shell window was closed while a raw_input()
|
| 266 |
+
was pending. Restored the quit() of the readline() mainloop().
|
| 267 |
+
http://mail.python.org/pipermail/idle-dev/2004-December/002307.html
|
| 268 |
+
|
| 269 |
+
- The remote procedure call module rpc.py can now access data attributes of
|
| 270 |
+
remote registered objects. Changes to these attributes are local, however.
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
What's New in IDLE 1.1?
|
| 274 |
+
=======================
|
| 275 |
+
*Release date: 30-NOV-2004*
|
| 276 |
+
|
| 277 |
+
- On OpenBSD, terminating IDLE with ctrl-c from the command line caused a
|
| 278 |
+
stuck subprocess MainThread because only the SocketThread was exiting.
|
| 279 |
+
|
| 280 |
+
- Saving a Keyset w/o making changes (by using the "Save as New Custom Key Set"
|
| 281 |
+
button) caused IDLE to fail on restart (no new keyset was created in
|
| 282 |
+
config-keys.cfg). Also true for Theme/highlights. Python Bug 1064535.
|
| 283 |
+
|
| 284 |
+
- A change to the linecache.py API caused IDLE to exit when an exception was
|
| 285 |
+
raised while running without the subprocess (-n switch). Python Bug 1063840.
|
| 286 |
+
|
| 287 |
+
- When paragraph reformat width was made configurable, a bug was
|
| 288 |
+
introduced that caused reformatting of comment blocks to ignore how
|
| 289 |
+
far the block was indented, effectively adding the indentation width
|
| 290 |
+
to the reformat width. This has been repaired, and the reformat
|
| 291 |
+
width is again a bound on the total width of reformatted lines.
|
| 292 |
+
|
| 293 |
+
- Improve keyboard focus binding, especially in Windows menu. Improve
|
| 294 |
+
window raising, especially in the Windows menu and in the debugger.
|
| 295 |
+
IDLEfork 763524.
|
| 296 |
+
|
| 297 |
+
- If user passes a non-existent filename on the commandline, just
|
| 298 |
+
open a new file, don't raise a dialog. IDLEfork 854928.
|
| 299 |
+
|
| 300 |
+
- EditorWindow.py was not finding the .chm help file on Windows. Typo
|
| 301 |
+
at Rev 1.54. Python Bug 990954
|
| 302 |
+
|
| 303 |
+
- checking sys.platform for substring 'win' was breaking IDLE docs on Mac
|
| 304 |
+
(darwin). Also, Mac Safari browser requires full file:// URIs. SF 900580.
|
| 305 |
+
|
| 306 |
+
- Redirect the warning stream to the shell during the ScriptBinding check of
|
| 307 |
+
user code and format the warning similarly to an exception for both that
|
| 308 |
+
check and for runtime warnings raised in the subprocess.
|
| 309 |
+
|
| 310 |
+
- CodeContext hint pane visibility state is now persistent across sessions.
|
| 311 |
+
The pane no longer appears in the shell window. Added capability to limit
|
| 312 |
+
extensions to shell window or editor windows. Noam Raphael addition
|
| 313 |
+
to Patch 936169.
|
| 314 |
+
|
| 315 |
+
- Paragraph reformat width is now a configurable parameter in the
|
| 316 |
+
Options GUI.
|
| 317 |
+
|
| 318 |
+
- New Extension: CodeContext. Provides block structuring hints for code
|
| 319 |
+
which has scrolled above an edit window. Patch 936169 Noam Raphael.
|
| 320 |
+
|
| 321 |
+
- If nulls somehow got into the strings in recent-files.lst
|
| 322 |
+
EditorWindow.update_recent_files_list() was failing. Python Bug 931336.
|
| 323 |
+
|
| 324 |
+
- If the normal background is changed via Configure/Highlighting, it will
|
| 325 |
+
update immediately, thanks to the previously mentioned patch by Nigel Rowe.
|
| 326 |
+
|
| 327 |
+
- Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
|
| 328 |
+
This also fixed IDLEfork bug [ 693418 ] Normal text background color not
|
| 329 |
+
refreshed and Python bug [897872 ] Unknown color name on HP-UX
|
| 330 |
+
|
| 331 |
+
- rpc.py:SocketIO - Large modules were generating large pickles when downloaded
|
| 332 |
+
to the execution server. The return of the OK response from the subprocess
|
| 333 |
+
initialization was interfering and causing the sending socket to be not
|
| 334 |
+
ready. Add an IO ready test to fix this. Moved the polling IO ready test
|
| 335 |
+
into pollpacket().
|
| 336 |
+
|
| 337 |
+
- Fix typo in rpc.py, s/b "pickle.PicklingError" not "pickle.UnpicklingError".
|
| 338 |
+
|
| 339 |
+
- Added a Tk error dialog to run.py inform the user if the subprocess can't
|
| 340 |
+
connect to the user GUI process. Added a timeout to the GUI's listening
|
| 341 |
+
socket. Added Tk error dialogs to PyShell.py to announce a failure to bind
|
| 342 |
+
the port or connect to the subprocess. Clean up error handling during
|
| 343 |
+
connection initiation phase. This is an update of Python Patch 778323.
|
| 344 |
+
|
| 345 |
+
- Print correct exception even if source file changed since shell was
|
| 346 |
+
restarted. IDLEfork Patch 869012 Noam Raphael
|
| 347 |
+
|
| 348 |
+
- Keybindings with the Shift modifier now work correctly. So do bindings which
|
| 349 |
+
use the Space key. Limit unmodified user keybindings to the function keys.
|
| 350 |
+
Python Bug 775353, IDLEfork Bugs 755647, 761557
|
| 351 |
+
|
| 352 |
+
- After an exception, run.py was not setting the exception vector. Noam
|
| 353 |
+
Raphael suggested correcting this so pdb's postmortem pm() would work.
|
| 354 |
+
IDLEfork Patch 844675
|
| 355 |
+
|
| 356 |
+
- IDLE now does not fail to save the file anymore if the Tk buffer is not a
|
| 357 |
+
Unicode string, yet eol_convention is. Python Bugs 774680, 788378
|
| 358 |
+
|
| 359 |
+
- IDLE didn't start correctly when Python was installed in "Program Files" on
|
| 360 |
+
W2K and XP. Python Bugs 780451, 784183
|
| 361 |
+
|
| 362 |
+
- config-main.def documentation incorrectly referred to idle- instead of
|
| 363 |
+
config- filenames. SF 782759 Also added note about .idlerc location.
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
What's New in IDLE 1.0?
|
| 367 |
+
=======================
|
| 368 |
+
*Release date: 29-Jul-2003*
|
| 369 |
+
|
| 370 |
+
- Added a banner to the shell discussing warnings possibly raised by personal
|
| 371 |
+
firewall software. Added same comment to README.txt.
|
| 372 |
+
|
| 373 |
+
- Calltip error when docstring was None Python Bug 775541
|
| 374 |
+
|
| 375 |
+
- Updated extend.txt, help.txt, and config-extensions.def to correctly
|
| 376 |
+
reflect the current status of the configuration system. Python Bug 768469
|
| 377 |
+
|
| 378 |
+
- Fixed: Call Tip Trimming May Loop Forever. Python Patch 769142 (Daniels)
|
| 379 |
+
|
| 380 |
+
- Replaced apply(f, args, kwds) with f(*args, **kwargs) to improve performance
|
| 381 |
+
Python Patch 768187
|
| 382 |
+
|
| 383 |
+
- Break or continue statements outside a loop were causing IDLE crash
|
| 384 |
+
Python Bug 767794
|
| 385 |
+
|
| 386 |
+
- Convert Unicode strings from readline to IOBinding.encoding. Also set
|
| 387 |
+
sys.std{in|out|err}.encoding, for both the local and the subprocess case.
|
| 388 |
+
SF IDLEfork patch 682347.
|
| 389 |
+
|
| 390 |
+
- Extend AboutDialog.ViewFile() to support file encodings. Make the CREDITS
|
| 391 |
+
file Latin-1.
|
| 392 |
+
|
| 393 |
+
- Updated the About dialog to reflect re-integration into Python. Provide
|
| 394 |
+
buttons to display Python's NEWS, License, and Credits, plus additional
|
| 395 |
+
buttons for IDLE's README and NEWS.
|
| 396 |
+
|
| 397 |
+
- TextViewer() now has a third parameter which allows inserting text into the
|
| 398 |
+
viewer instead of reading from a file.
|
| 399 |
+
|
| 400 |
+
- (Created the .../Lib/idlelib directory in the Python CVS, which is a clone of
|
| 401 |
+
IDLEfork modified to install in the Python environment. The code in the
|
| 402 |
+
interrupt module has been moved to thread.interrupt_main(). )
|
| 403 |
+
|
| 404 |
+
- Printing the Shell window was failing if it was not saved first SF 748975
|
| 405 |
+
|
| 406 |
+
- When using the Search in Files dialog, if the user had a selection
|
| 407 |
+
highlighted in his Editor window, insert it into the dialog search field.
|
| 408 |
+
|
| 409 |
+
- The Python Shell entry was disappearing from the Windows menu.
|
| 410 |
+
|
| 411 |
+
- Update the Windows file list when a file name change occurs
|
| 412 |
+
|
| 413 |
+
- Change to File / Open Module: always pop up the dialog, using the current
|
| 414 |
+
selection as the default value. This is easier to use habitually.
|
| 415 |
+
|
| 416 |
+
- Avoided a problem with starting the subprocess when 'localhost' doesn't
|
| 417 |
+
resolve to the user's loopback interface. SF 747772
|
| 418 |
+
|
| 419 |
+
- Fixed an issue with highlighted errors never de-colorizing. SF 747677. Also
|
| 420 |
+
improved notification of Tabnanny Token Error.
|
| 421 |
+
|
| 422 |
+
- File / New will by default save in the directory of the Edit window from
|
| 423 |
+
which it was initiated. SF 748973 Guido van Rossum patch.
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
What's New in IDLEfork 0.9b1?
|
| 427 |
+
=============================
|
| 428 |
+
*Release date: 02-Jun-2003*
|
| 429 |
+
|
| 430 |
+
- The current working directory of the execution environment (and shell
|
| 431 |
+
following completion of execution) is now that of the module being run.
|
| 432 |
+
|
| 433 |
+
- Added the delete-exitfunc option to config-main.def. (This option is not
|
| 434 |
+
included in the Options dialog.) Setting this to True (the default) will
|
| 435 |
+
cause IDLE to not run sys.exitfunc/atexit when the subprocess exits.
|
| 436 |
+
|
| 437 |
+
- IDLE now preserves the line ending codes when editing a file produced on
|
| 438 |
+
a different platform. SF 661759, SF 538584
|
| 439 |
+
|
| 440 |
+
- Reduced default editor font size to 10 point and increased window height
|
| 441 |
+
to provide a better initial impression on Windows.
|
| 442 |
+
|
| 443 |
+
- Options / Fonts/Tabs / Set Base Editor Font: List box was not highlighting
|
| 444 |
+
the default font when first installed on Windows. SF 661676
|
| 445 |
+
|
| 446 |
+
- Added Autosave feature: when user runs code from edit window, if the file
|
| 447 |
+
has been modified IDLE will silently save it if Autosave is enabled. The
|
| 448 |
+
option is set in the Options dialog, and the default is to prompt the
|
| 449 |
+
user to save the file. SF 661318 Bruce Sherwood patch.
|
| 450 |
+
|
| 451 |
+
- Improved the RESTART annotation in the shell window when the user restarts
|
| 452 |
+
the shell while it is generating output. Also improved annotation when user
|
| 453 |
+
repeatedly hammers the Ctrl-F6 restart.
|
| 454 |
+
|
| 455 |
+
- Allow IDLE to run when not installed and cwd is not the IDLE directory
|
| 456 |
+
SF Patch 686254 "Run IDLEfork from any directory without set-up" - Raphael
|
| 457 |
+
|
| 458 |
+
- When a module is run from an EditorWindow: if its directory is not in
|
| 459 |
+
sys.path, prepend it. This allows the module to import other modules in
|
| 460 |
+
the same directory. Do the same for a script run from the command line.
|
| 461 |
+
|
| 462 |
+
- Correctly restart the subprocess if it is running user code and the user
|
| 463 |
+
attempts to run some other module or restarts the shell. Do the same if
|
| 464 |
+
the link is broken and it is possible to restart the subprocess and re-
|
| 465 |
+
connect to the GUI. SF RFE 661321.
|
| 466 |
+
|
| 467 |
+
- Improved exception reporting when running commands or scripts from the
|
| 468 |
+
command line.
|
| 469 |
+
|
| 470 |
+
- Added a -n command line switch to start IDLE without the subprocess.
|
| 471 |
+
Removed the Shell menu when running in that mode. Updated help messages.
|
| 472 |
+
|
| 473 |
+
- Added a comment to the shell startup header to indicate when IDLE is not
|
| 474 |
+
using the subprocess.
|
| 475 |
+
|
| 476 |
+
- Restore the ability to run without the subprocess. This can be important for
|
| 477 |
+
some platforms or configurations. (Running without the subprocess allows the
|
| 478 |
+
debugger to trace through parts of IDLE itself, which may or may not be
|
| 479 |
+
desirable, depending on your point of view. In addition, the traditional
|
| 480 |
+
reload/import tricks must be use if user source code is changed.) This is
|
| 481 |
+
helpful for developing IDLE using IDLE, because one instance can be used to
|
| 482 |
+
edit the code and a separate instance run to test changes. (Multiple
|
| 483 |
+
concurrent IDLE instances with subprocesses is a future feature)
|
| 484 |
+
|
| 485 |
+
- Improve the error message a user gets when saving a file with non-ASCII
|
| 486 |
+
characters and no source encoding is specified. Done by adding a dialog
|
| 487 |
+
'EncodingMessage', which contains the line to add in a fixed-font entry
|
| 488 |
+
widget, and which has a button to add that line to the file automatically.
|
| 489 |
+
Also, add a configuration option 'EditorWindow/encoding', which has three
|
| 490 |
+
possible values: none, utf-8, and locale. None is the default: IDLE will show
|
| 491 |
+
this dialog when non-ASCII characters are encountered. utf-8 means that files
|
| 492 |
+
with non-ASCII characters are saved as utf-8-with-bom. locale means that
|
| 493 |
+
files are saved in the locale's encoding; the dialog is only displayed if the
|
| 494 |
+
source contains characters outside the locale's charset. SF 710733 - Loewis
|
| 495 |
+
|
| 496 |
+
- Improved I/O response by tweaking the wait parameter in various
|
| 497 |
+
calls to signal.signal().
|
| 498 |
+
|
| 499 |
+
- Implemented a threaded subprocess which allows interrupting a pass
|
| 500 |
+
loop in user code using the 'interrupt' extension. User code runs
|
| 501 |
+
in MainThread, while the RPCServer is handled by SockThread. This is
|
| 502 |
+
necessary because Windows doesn't support signals.
|
| 503 |
+
|
| 504 |
+
- Implemented the 'interrupt' extension module, which allows a subthread
|
| 505 |
+
to raise a KeyboardInterrupt in the main thread.
|
| 506 |
+
|
| 507 |
+
- Attempting to save the shell raised an error related to saving
|
| 508 |
+
breakpoints, which are not implemented in the shell
|
| 509 |
+
|
| 510 |
+
- Provide a correct message when 'exit' or 'quit' are entered at the
|
| 511 |
+
IDLE command prompt SF 695861
|
| 512 |
+
|
| 513 |
+
- Eliminate extra blank line in shell output caused by not flushing
|
| 514 |
+
stdout when user code ends with an unterminated print. SF 695861
|
| 515 |
+
|
| 516 |
+
- Moved responsibility for exception formatting (i.e. pruning IDLE internal
|
| 517 |
+
calls) out of rpc.py into the client and server.
|
| 518 |
+
|
| 519 |
+
- Exit IDLE cleanly even when doing subprocess I/O
|
| 520 |
+
|
| 521 |
+
- Handle subprocess interrupt with an RPC message.
|
| 522 |
+
|
| 523 |
+
- Restart the subprocess if it terminates itself. (VPython programs do that)
|
| 524 |
+
|
| 525 |
+
- Support subclassing of exceptions, including in the shell, by moving the
|
| 526 |
+
exception formatting to the subprocess.
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
What's New in IDLEfork 0.9 Alpha 2?
|
| 530 |
+
===================================
|
| 531 |
+
*Release date: 27-Jan-2003*
|
| 532 |
+
|
| 533 |
+
- Updated INSTALL.txt to claify use of the python2 rpm.
|
| 534 |
+
|
| 535 |
+
- Improved formatting in IDLE Help.
|
| 536 |
+
|
| 537 |
+
- Run menu: Replace "Run Script" with "Run Module".
|
| 538 |
+
|
| 539 |
+
- Code encountering an unhandled exception under the debugger now shows
|
| 540 |
+
the correct traceback, with IDLE internal levels pruned out.
|
| 541 |
+
|
| 542 |
+
- If an exception occurs entirely in IDLE, don't prune the IDLE internal
|
| 543 |
+
modules from the traceback displayed.
|
| 544 |
+
|
| 545 |
+
- Class Browser and Path Browser now use Alt-Key-2 for vertical zoom.
|
| 546 |
+
|
| 547 |
+
- IDLE icons will now install correctly even when setup.py is run from the
|
| 548 |
+
build directory
|
| 549 |
+
|
| 550 |
+
- Class Browser now compatible with Python2.3 version of pyclbr.py
|
| 551 |
+
|
| 552 |
+
- Left cursor move in presence of selected text now moves from left end
|
| 553 |
+
of the selection.
|
| 554 |
+
|
| 555 |
+
- Add Meta keybindings to "IDLE Classic Windows" to handle reversed
|
| 556 |
+
Alt/Meta on some Linux distros.
|
| 557 |
+
|
| 558 |
+
- Change default: IDLE now starts with Python Shell.
|
| 559 |
+
|
| 560 |
+
- Removed the File Path from the Additional Help Sources scrolled list.
|
| 561 |
+
|
| 562 |
+
- Add capability to access Additional Help Sources on the web if the
|
| 563 |
+
Help File Path begins with //http or www. (Otherwise local path is
|
| 564 |
+
validated, as before.)
|
| 565 |
+
|
| 566 |
+
- Additional Help Sources were not being posted on the Help menu in the
|
| 567 |
+
order entered. Implement sorting the list by [HelpFiles] 'option'
|
| 568 |
+
number.
|
| 569 |
+
|
| 570 |
+
- Add Browse button to New Help Source dialog. Arrange to start in
|
| 571 |
+
Python/Doc if platform is Windows, otherwise start in current directory.
|
| 572 |
+
|
| 573 |
+
- Put the Additional Help Sources directly on the Help menu instead of in
|
| 574 |
+
an Extra Help cascade menu. Rearrange the Help menu so the Additional
|
| 575 |
+
Help Sources come last. Update help.txt appropriately.
|
| 576 |
+
|
| 577 |
+
- Fix Tk root pop-ups in configSectionNameDialog.py and configDialog.py
|
| 578 |
+
|
| 579 |
+
- Uniform capitalization in General tab of ConfigDialog, update the doc string.
|
| 580 |
+
|
| 581 |
+
- Fix bug in ConfigDialog where SaveAllChangedConfig() was unexpectedly
|
| 582 |
+
deleting Additional Help Sources from the user's config file.
|
| 583 |
+
|
| 584 |
+
- Make configHelpSourceEdit OK button the default and bind <Return>
|
| 585 |
+
|
| 586 |
+
- Fix Tk root pop-ups in configHelpSourceEdit: error dialogs not attached
|
| 587 |
+
to parents.
|
| 588 |
+
|
| 589 |
+
- Use os.startfile() to open both Additional Help and Python Help on the
|
| 590 |
+
Windows platform. The application associated with the file type will act as
|
| 591 |
+
the viewer. Windows help files (.chm) are now supported via the
|
| 592 |
+
Settings/General/Additional Help facility.
|
| 593 |
+
|
| 594 |
+
- If Python Help files are installed locally on Linux, use them instead of
|
| 595 |
+
accessing python.org.
|
| 596 |
+
|
| 597 |
+
- Make the methods for finding the Python help docs more robust, and make
|
| 598 |
+
them work in the installed configuration, also.
|
| 599 |
+
|
| 600 |
+
- On the Save Before Run dialog, make the OK button the default. One
|
| 601 |
+
less mouse action!
|
| 602 |
+
|
| 603 |
+
- Add a method: EditorWindow.get_geometry() for future use in implementing
|
| 604 |
+
window location persistence.
|
| 605 |
+
|
| 606 |
+
- Removed the "Help/Advice" menu entry. Thanks, David! We'll remember!
|
| 607 |
+
|
| 608 |
+
- Change the "Classic Windows" theme's paste key to be <ctrl-v>.
|
| 609 |
+
|
| 610 |
+
- Rearrange the Shell menu to put Stack Viewer entries adjacent.
|
| 611 |
+
|
| 612 |
+
- Add the ability to restart the subprocess interpreter from the shell window;
|
| 613 |
+
add an associated menu entry "Shell/Restart" with binding Control-F6. Update
|
| 614 |
+
IDLE help.
|
| 615 |
+
|
| 616 |
+
- Upon a restart, annotate the shell window with a "restart boundary". Add a
|
| 617 |
+
shell window menu "Shell/View Restart" with binding F6 to jump to the most
|
| 618 |
+
recent restart boundary.
|
| 619 |
+
|
| 620 |
+
- Add Shell menu to Python Shell; change "Settings" to "Options".
|
| 621 |
+
|
| 622 |
+
- Remove incorrect comment in setup.py: IDLEfork is now installed as a package.
|
| 623 |
+
|
| 624 |
+
- Add INSTALL.txt, HISTORY.txt, NEWS.txt to installed configuration.
|
| 625 |
+
|
| 626 |
+
- In installer text, fix reference to Visual Python, should be VPython.
|
| 627 |
+
Properly credit David Scherer.
|
| 628 |
+
|
| 629 |
+
- Modified idle, idle.py, idle.pyw to improve exception handling.
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
What's New in IDLEfork 0.9 Alpha 1?
|
| 633 |
+
===================================
|
| 634 |
+
*Release date: 31-Dec-2002*
|
| 635 |
+
|
| 636 |
+
- First release of major new functionality. For further details refer to
|
| 637 |
+
Idle-dev and/or the Sourceforge CVS.
|
| 638 |
+
|
| 639 |
+
- Adapted to the Mac platform.
|
| 640 |
+
|
| 641 |
+
- Overhauled the IDLE startup options and revised the idle -h help message,
|
| 642 |
+
which provides details of command line usage.
|
| 643 |
+
|
| 644 |
+
- Multiple bug fixes and usability enhancements.
|
| 645 |
+
|
| 646 |
+
- Introduced the new RPC implementation, which includes a debugger. The output
|
| 647 |
+
of user code is to the shell, and the shell may be used to inspect the
|
| 648 |
+
environment after the run has finished. (In version 0.8.1 the shell
|
| 649 |
+
environment was separate from the environment of the user code.)
|
| 650 |
+
|
| 651 |
+
- Introduced the configuration GUI and a new About dialog.
|
| 652 |
+
|
| 653 |
+
- Removed David Scherer's Remote Procedure Call code and replaced with Guido
|
| 654 |
+
van Rossum's. GvR code has support for the IDLE debugger and uses the shell
|
| 655 |
+
to inspect the environment of code Run from an Edit window. Files removed:
|
| 656 |
+
ExecBinding.py, loader.py, protocol.py, Remote.py, spawn.py
|
| 657 |
+
|
| 658 |
+
--------------------------------------------------------------------
|
| 659 |
+
Refer to HISTORY.txt for additional information on earlier releases.
|
| 660 |
+
--------------------------------------------------------------------
|
evalkit_cambrian/lib/python3.10/idlelib/README.txt
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
README.txt: an index to idlelib files and the IDLE menu.
|
| 2 |
+
|
| 3 |
+
IDLE is Python's Integrated Development and Learning
|
| 4 |
+
Environment. The user documentation is part of the Library Reference and
|
| 5 |
+
is available in IDLE by selecting Help => IDLE Help. This README documents
|
| 6 |
+
idlelib for IDLE developers and curious users.
|
| 7 |
+
|
| 8 |
+
IDLELIB FILES lists files alphabetically by category,
|
| 9 |
+
with a short description of each.
|
| 10 |
+
|
| 11 |
+
IDLE MENU show the menu tree, annotated with the module
|
| 12 |
+
or module object that implements the corresponding function.
|
| 13 |
+
|
| 14 |
+
This file is descriptive, not prescriptive, and may have errors
|
| 15 |
+
and omissions and lag behind changes in idlelib.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
IDLELIB FILES
|
| 19 |
+
=============
|
| 20 |
+
|
| 21 |
+
Implementation files not in IDLE MENU are marked (nim).
|
| 22 |
+
|
| 23 |
+
Startup
|
| 24 |
+
-------
|
| 25 |
+
__init__.py # import, does nothing
|
| 26 |
+
__main__.py # -m, starts IDLE
|
| 27 |
+
idle.bat
|
| 28 |
+
idle.py
|
| 29 |
+
idle.pyw
|
| 30 |
+
|
| 31 |
+
Implementation
|
| 32 |
+
--------------
|
| 33 |
+
autocomplete.py # Complete attribute names or filenames.
|
| 34 |
+
autocomplete_w.py # Display completions.
|
| 35 |
+
autoexpand.py # Expand word with previous word in file.
|
| 36 |
+
browser.py # Create module browser window.
|
| 37 |
+
calltip.py # Create calltip text.
|
| 38 |
+
calltip_w.py # Display calltip.
|
| 39 |
+
codecontext.py # Show compound statement headers otherwise not visible.
|
| 40 |
+
colorizer.py # Colorize text (nim).
|
| 41 |
+
config.py # Load, fetch, and save configuration (nim).
|
| 42 |
+
configdialog.py # Display user configuration dialogs.
|
| 43 |
+
config_key.py # Change keybindings.
|
| 44 |
+
debugger.py # Debug code run from shell or editor; show window.
|
| 45 |
+
debugger_r.py # Debug code run in remote process.
|
| 46 |
+
debugobj.py # Define class used in stackviewer.
|
| 47 |
+
debugobj_r.py # Communicate objects between processes with rpc (nim).
|
| 48 |
+
delegator.py # Define base class for delegators (nim).
|
| 49 |
+
dynoption.py # Define mutable OptionMenu widget (nim)
|
| 50 |
+
editor.py # Define most of editor and utility functions.
|
| 51 |
+
filelist.py # Open files and manage list of open windows (nim).
|
| 52 |
+
format.py # Define format menu options.
|
| 53 |
+
grep.py # Find all occurrences of pattern in multiple files.
|
| 54 |
+
help.py # Display IDLE's html doc.
|
| 55 |
+
help_about.py # Display About IDLE dialog.
|
| 56 |
+
history.py # Get previous or next user input in shell (nim)
|
| 57 |
+
hyperparser.py # Parse code around a given index.
|
| 58 |
+
iomenu.py # Open, read, and write files
|
| 59 |
+
macosx.py # Help IDLE run on Macs (nim).
|
| 60 |
+
mainmenu.py # Define most of IDLE menu.
|
| 61 |
+
multicall.py # Wrap tk widget to allow multiple calls per event (nim).
|
| 62 |
+
outwin.py # Create window for grep output.
|
| 63 |
+
parenmatch.py # Match fenceposts: (), [], and {}.
|
| 64 |
+
pathbrowser.py # Create path browser window.
|
| 65 |
+
percolator.py # Manage delegator stack (nim).
|
| 66 |
+
pyparse.py # Give information on code indentation
|
| 67 |
+
pyshell.py # Start IDLE, manage shell, complete editor window
|
| 68 |
+
query.py # Query user for information
|
| 69 |
+
redirector.py # Intercept widget subcommands (for percolator) (nim).
|
| 70 |
+
replace.py # Search and replace pattern in text.
|
| 71 |
+
rpc.py # Communicate between idle and user processes (nim).
|
| 72 |
+
run.py # Manage user code execution subprocess.
|
| 73 |
+
runscript.py # Check and run user code.
|
| 74 |
+
scrolledlist.py # Define scrolledlist widget for IDLE (nim).
|
| 75 |
+
search.py # Search for pattern in text.
|
| 76 |
+
searchbase.py # Define base for search, replace, and grep dialogs.
|
| 77 |
+
searchengine.py # Define engine for all 3 search dialogs.
|
| 78 |
+
sidebar.py # Define line number and shell prompt sidebars.
|
| 79 |
+
squeezer.py # Squeeze long shell output (nim).
|
| 80 |
+
stackviewer.py # View stack after exception.
|
| 81 |
+
statusbar.py # Define status bar for windows (nim).
|
| 82 |
+
tabbedpages.py # Define tabbed pages widget (nim).
|
| 83 |
+
textview.py # Define read-only text widget (nim).
|
| 84 |
+
tooltip.py # Define popups for calltips, squeezer (nim).
|
| 85 |
+
tree.py # Define tree widget, used in browsers (nim).
|
| 86 |
+
undo.py # Manage undo stack.
|
| 87 |
+
util.py # Define common objects imported elsewhere (nim).
|
| 88 |
+
windows.py # Manage window list and define listed top level.
|
| 89 |
+
zoomheight.py # Zoom window to full height of screen.
|
| 90 |
+
zzdummy.py # Example extension.
|
| 91 |
+
|
| 92 |
+
Configuration
|
| 93 |
+
-------------
|
| 94 |
+
config-extensions.def # Defaults for extensions
|
| 95 |
+
config-highlight.def # Defaults for colorizing
|
| 96 |
+
config-keys.def # Defaults for key bindings
|
| 97 |
+
config-main.def # Defaults for font and general tabs
|
| 98 |
+
|
| 99 |
+
Text
|
| 100 |
+
----
|
| 101 |
+
CREDITS.txt # not maintained, displayed by About IDLE
|
| 102 |
+
HISTORY.txt # NEWS up to July 2001
|
| 103 |
+
NEWS.txt # commits, displayed by About IDLE
|
| 104 |
+
NEWS2.txt # commits to Python2
|
| 105 |
+
README.txt # this file, displayed by About IDLE
|
| 106 |
+
TODO.txt # needs review
|
| 107 |
+
extend.txt # about writing extensions
|
| 108 |
+
help.html # copy of idle.html in docs, displayed by IDLE Help
|
| 109 |
+
|
| 110 |
+
Subdirectories
|
| 111 |
+
--------------
|
| 112 |
+
Icons # small image files
|
| 113 |
+
idle_test # files for human test and automated unit tests
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
IDLE MENUS
|
| 117 |
+
==========
|
| 118 |
+
|
| 119 |
+
Top level items and most submenu items are defined in mainmenu.
|
| 120 |
+
Extensions add submenu items when active. The names given are
|
| 121 |
+
found, quoted, in one of these modules, paired with a '<<pseudoevent>>'.
|
| 122 |
+
Each pseudoevent is bound to an event handler. Some event handlers
|
| 123 |
+
call another function that does the actual work. The annotations below
|
| 124 |
+
are intended to at least give the module where the actual work is done.
|
| 125 |
+
'eEW' = editor.EditorWindow
|
| 126 |
+
|
| 127 |
+
File
|
| 128 |
+
New File # eEW.new_callback
|
| 129 |
+
Open... # iomenu.open
|
| 130 |
+
Open Module # eEw.open_module
|
| 131 |
+
Recent Files
|
| 132 |
+
Class Browser # eEW.open_class_browser, browser.ClassBrowser
|
| 133 |
+
Path Browser # eEW.open_path_browser, pathbrowser
|
| 134 |
+
---
|
| 135 |
+
Save # iomenu.save
|
| 136 |
+
Save As... # iomenu.save_as
|
| 137 |
+
Save Copy As... # iomenu.save_a_copy
|
| 138 |
+
---
|
| 139 |
+
Print Window # iomenu.print_window
|
| 140 |
+
---
|
| 141 |
+
Close # eEW.close_event
|
| 142 |
+
Exit # flist.close_all_callback (bound in eEW)
|
| 143 |
+
|
| 144 |
+
Edit
|
| 145 |
+
Undo # undodelegator
|
| 146 |
+
Redo # undodelegator
|
| 147 |
+
--- # eEW.right_menu_event
|
| 148 |
+
Cut # eEW.cut
|
| 149 |
+
Copy # eEW.copy
|
| 150 |
+
Paste # eEW.past
|
| 151 |
+
Select All # eEW.select_all (+ see eEW.remove_selection)
|
| 152 |
+
--- # Next 5 items use searchengine; dialogs use searchbase
|
| 153 |
+
Find # eEW.find_event, search.SearchDialog.find
|
| 154 |
+
Find Again # eEW.find_again_event, sSD.find_again
|
| 155 |
+
Find Selection # eEW.find_selection_event, sSD.find_selection
|
| 156 |
+
Find in Files... # eEW.find_in_files_event, grep
|
| 157 |
+
Replace... # eEW.replace_event, replace.ReplaceDialog.replace
|
| 158 |
+
Go to Line # eEW.goto_line_event
|
| 159 |
+
Show Completions # autocomplete extension and autocompleteWidow (&HP)
|
| 160 |
+
Expand Word # autoexpand extension
|
| 161 |
+
Show call tip # Calltips extension and CalltipWindow (& Hyperparser)
|
| 162 |
+
Show surrounding parens # parenmatch (& Hyperparser)
|
| 163 |
+
|
| 164 |
+
Format (Editor only) [fFR = format.FormatRegion]
|
| 165 |
+
Format Paragraph # format.FormatParagraph.format_paragraph_event
|
| 166 |
+
Indent Region # fFR.indent_region_event
|
| 167 |
+
Dedent Region # fFR.dedent_region_event
|
| 168 |
+
Comment Out Reg. # fFR.comment_region_event
|
| 169 |
+
Uncomment Region # fFR.uncomment_region_event
|
| 170 |
+
Tabify Region # fFR.tabify_region_event
|
| 171 |
+
Untabify Region # fFR.untabify_region_event
|
| 172 |
+
Toggle Tabs # format.Indents.toggle_tabs_event
|
| 173 |
+
New Indent Width # format.Indents.change_indentwidth_event
|
| 174 |
+
Strip tailing whitespace # format.rstrip
|
| 175 |
+
Zin # zzdummy
|
| 176 |
+
Zout # zzdummy
|
| 177 |
+
|
| 178 |
+
Run (Editor only)
|
| 179 |
+
Run Module # runscript.ScriptBinding.run_module_event
|
| 180 |
+
Run... Customized # runscript.ScriptBinding.run_custom_event
|
| 181 |
+
Check Module # runscript.ScriptBinding.check_module_event
|
| 182 |
+
Python Shell # pyshell.Pyshell, pyshell.ModifiedInterpreter
|
| 183 |
+
|
| 184 |
+
Shell # pyshell
|
| 185 |
+
View Last Restart # pyshell.PyShell.view_restart_mark
|
| 186 |
+
Restart Shell # pyshell.PyShell.restart_shell
|
| 187 |
+
Previous History # history.History.history_prev
|
| 188 |
+
Next History # history.History.history_next
|
| 189 |
+
Interrupt Execution # pyshell.PyShell.cancel_callback
|
| 190 |
+
|
| 191 |
+
Debug (Shell only)
|
| 192 |
+
Go to File/Line # outwin.OutputWindow.goto_file_line
|
| 193 |
+
debugger # debugger, debugger_r, PyShell.toggle_debugger
|
| 194 |
+
Stack Viewer # stackviewer, PyShell.open_stack_viewer
|
| 195 |
+
Auto-open Stack Viewer # stackviewer
|
| 196 |
+
|
| 197 |
+
Options
|
| 198 |
+
Configure IDLE # eEW.config_dialog, config, configdialog (cd)
|
| 199 |
+
(Parts of the dialog)
|
| 200 |
+
Buttons # cd.ConfigDialog
|
| 201 |
+
Font tab # cd.FontPage, config-main.def
|
| 202 |
+
Highlight tab # cd.HighPage, query, config-highlight.def
|
| 203 |
+
Keys tab # cd.KeysPage, query, config_key, config_keys.def
|
| 204 |
+
Windows tab # cd.WinPage, config_main.def
|
| 205 |
+
Shell/Ed tab # cd.ShedPage, config-main.def
|
| 206 |
+
Extensions tab # config-extensions.def, corresponding .py files
|
| 207 |
+
---
|
| 208 |
+
... Code Context # codecontext
|
| 209 |
+
... Line Numbers # sidebar
|
| 210 |
+
Zoomheight # zoomheight
|
| 211 |
+
|
| 212 |
+
Window
|
| 213 |
+
<open windows> # windows
|
| 214 |
+
|
| 215 |
+
Help
|
| 216 |
+
About IDLE # eEW.about_dialog, help_about.AboutDialog
|
| 217 |
+
---
|
| 218 |
+
IDLE Help # eEW.help_dialog, help.show_idlehelp
|
| 219 |
+
Python Docs # eEW.python_docs
|
| 220 |
+
Turtle Demo # eEW.open_turtle_demo
|
| 221 |
+
---
|
| 222 |
+
<other help sources>
|
| 223 |
+
|
| 224 |
+
<Context Menu> (right click)
|
| 225 |
+
Defined in editor, PyShell.pyshell
|
| 226 |
+
Cut
|
| 227 |
+
Copy
|
| 228 |
+
Paste
|
| 229 |
+
---
|
| 230 |
+
Go to file/line (shell and output only)
|
| 231 |
+
Set Breakpoint (editor only)
|
| 232 |
+
Clear Breakpoint (editor only)
|
| 233 |
+
Defined in debugger
|
| 234 |
+
Go to source line
|
| 235 |
+
Show stack frame
|
| 236 |
+
|
| 237 |
+
<No menu>
|
| 238 |
+
Center Insert # eEW.center_insert_event
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
OTHER TOPICS
|
| 242 |
+
============
|
| 243 |
+
|
| 244 |
+
Generally use PEP 8.
|
| 245 |
+
|
| 246 |
+
import statements
|
| 247 |
+
-----------------
|
| 248 |
+
Put imports at the top, unless there is a good reason otherwise.
|
| 249 |
+
PEP 8 says to group stdlib, 3rd-party dependencies, and package imports.
|
| 250 |
+
For idlelib, the groups are general stdlib, tkinter, and idlelib.
|
| 251 |
+
Sort modules within each group, except that tkinter.ttk follows tkinter.
|
| 252 |
+
Sort 'from idlelib import mod1' and 'from idlelib.mod2 import object'
|
| 253 |
+
together by module, ignoring within module objects.
|
| 254 |
+
Put 'import __main__' after other idlelib imports.
|
| 255 |
+
|
| 256 |
+
Imports only needed for testing are put not at the top but in an
|
| 257 |
+
htest function def or "if __name__ == '__main__'" clause.
|
| 258 |
+
|
| 259 |
+
Within module imports like "from idlelib.mod import class" may cause
|
| 260 |
+
circular imports to deadlock. Even without this, circular imports may
|
| 261 |
+
require at least one of the imports to be delayed until a function call.
|
| 262 |
+
|
| 263 |
+
What's New entries
|
| 264 |
+
------------------
|
| 265 |
+
|
| 266 |
+
Repository directory Doc/whatsnew/ has a file 3.n.rst for each 3.n
|
| 267 |
+
Python version. For the first entry in each file, add subsection
|
| 268 |
+
'IDLE and idlelib', in alphabetical position, to the 'Improved Modules'
|
| 269 |
+
section. For the rest of cpython, entries to 3.(n+1).rst begin with
|
| 270 |
+
the release of 3.n.0b1. For IDLE, entries for features backported from
|
| 271 |
+
'main' to '3.n' during its beta period do not got in 3.(n+1).rst. The
|
| 272 |
+
latter usually gets its first entry during the 3.n.0 candidate period
|
| 273 |
+
or after the 3.n.0 release.
|
| 274 |
+
|
| 275 |
+
When, as per PEP 434, feature changes are backported, entries are placed
|
| 276 |
+
in the 3.n.rst file *in the main branch* for each Python version n that
|
| 277 |
+
gets the backport. (Note: the format of entries have varied between
|
| 278 |
+
versions.) Add a line "New in 3.n maintenance releases." before the
|
| 279 |
+
first back-ported feature after 3.n.0 is released. Since each older
|
| 280 |
+
version file gets a different number of backports, it is easiest to
|
| 281 |
+
make a separate PR for each file and label it with the backports
|
| 282 |
+
needed.
|
| 283 |
+
|
| 284 |
+
Github repository and issues
|
| 285 |
+
----------------------------
|
| 286 |
+
|
| 287 |
+
The CPython repository is https://github.com/python/cpython. The
|
| 288 |
+
IDLE Issues listing is https://github.com/orgs/python/projects/31.
|
| 289 |
+
The main classification is by Topic, based on the IDLE menu. View the
|
| 290 |
+
topics list by clicking the [<]] button in the upper right.
|
evalkit_cambrian/lib/python3.10/idlelib/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The idlelib package implements the Idle application.
|
| 2 |
+
|
| 3 |
+
Idle includes an interactive shell and editor.
|
| 4 |
+
Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
|
| 5 |
+
Use the files named idle.* to start Idle.
|
| 6 |
+
|
| 7 |
+
The other files are private implementations. Their details are subject to
|
| 8 |
+
change. See PEP 434 for more. Import them at your own risk.
|
| 9 |
+
"""
|
| 10 |
+
testing = False # Set True by test.test_idle.
|
evalkit_cambrian/lib/python3.10/idlelib/__main__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IDLE main entry point
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Complete either attribute names or file names.
|
| 2 |
+
|
| 3 |
+
Either on demand or after a user-selected delay after a key character,
|
| 4 |
+
pop up a list of candidates.
|
| 5 |
+
"""
|
| 6 |
+
import __main__
|
| 7 |
+
import keyword
|
| 8 |
+
import os
|
| 9 |
+
import string
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
# Modified keyword list is used in fetch_completions.
|
| 13 |
+
completion_kwds = [s for s in keyword.kwlist
|
| 14 |
+
if s not in {'True', 'False', 'None'}] # In builtins.
|
| 15 |
+
completion_kwds.extend(('match', 'case')) # Context keywords.
|
| 16 |
+
completion_kwds.sort()
|
| 17 |
+
|
| 18 |
+
# Two types of completions; defined here for autocomplete_w import below.
|
| 19 |
+
ATTRS, FILES = 0, 1
|
| 20 |
+
from idlelib import autocomplete_w
|
| 21 |
+
from idlelib.config import idleConf
|
| 22 |
+
from idlelib.hyperparser import HyperParser
|
| 23 |
+
|
| 24 |
+
# Tuples passed to open_completions.
|
| 25 |
+
# EvalFunc, Complete, WantWin, Mode
|
| 26 |
+
FORCE = True, False, True, None # Control-Space.
|
| 27 |
+
TAB = False, True, True, None # Tab.
|
| 28 |
+
TRY_A = False, False, False, ATTRS # '.' for attributes.
|
| 29 |
+
TRY_F = False, False, False, FILES # '/' in quotes for file name.
|
| 30 |
+
|
| 31 |
+
# This string includes all chars that may be in an identifier.
|
| 32 |
+
# TODO Update this here and elsewhere.
|
| 33 |
+
ID_CHARS = string.ascii_letters + string.digits + "_"
|
| 34 |
+
|
| 35 |
+
SEPS = f"{os.sep}{os.altsep if os.altsep else ''}"
|
| 36 |
+
TRIGGERS = f".{SEPS}"
|
| 37 |
+
|
| 38 |
+
class AutoComplete:
|
| 39 |
+
|
| 40 |
+
def __init__(self, editwin=None, tags=None):
|
| 41 |
+
self.editwin = editwin
|
| 42 |
+
if editwin is not None: # not in subprocess or no-gui test
|
| 43 |
+
self.text = editwin.text
|
| 44 |
+
self.tags = tags
|
| 45 |
+
self.autocompletewindow = None
|
| 46 |
+
# id of delayed call, and the index of the text insert when
|
| 47 |
+
# the delayed call was issued. If _delayed_completion_id is
|
| 48 |
+
# None, there is no delayed call.
|
| 49 |
+
self._delayed_completion_id = None
|
| 50 |
+
self._delayed_completion_index = None
|
| 51 |
+
|
| 52 |
+
@classmethod
|
| 53 |
+
def reload(cls):
|
| 54 |
+
cls.popupwait = idleConf.GetOption(
|
| 55 |
+
"extensions", "AutoComplete", "popupwait", type="int", default=0)
|
| 56 |
+
|
| 57 |
+
def _make_autocomplete_window(self): # Makes mocking easier.
|
| 58 |
+
return autocomplete_w.AutoCompleteWindow(self.text, tags=self.tags)
|
| 59 |
+
|
| 60 |
+
def _remove_autocomplete_window(self, event=None):
|
| 61 |
+
if self.autocompletewindow:
|
| 62 |
+
self.autocompletewindow.hide_window()
|
| 63 |
+
self.autocompletewindow = None
|
| 64 |
+
|
| 65 |
+
def force_open_completions_event(self, event):
|
| 66 |
+
"(^space) Open completion list, even if a function call is needed."
|
| 67 |
+
self.open_completions(FORCE)
|
| 68 |
+
return "break"
|
| 69 |
+
|
| 70 |
+
def autocomplete_event(self, event):
|
| 71 |
+
"(tab) Complete word or open list if multiple options."
|
| 72 |
+
if hasattr(event, "mc_state") and event.mc_state or\
|
| 73 |
+
not self.text.get("insert linestart", "insert").strip():
|
| 74 |
+
# A modifier was pressed along with the tab or
|
| 75 |
+
# there is only previous whitespace on this line, so tab.
|
| 76 |
+
return None
|
| 77 |
+
if self.autocompletewindow and self.autocompletewindow.is_active():
|
| 78 |
+
self.autocompletewindow.complete()
|
| 79 |
+
return "break"
|
| 80 |
+
else:
|
| 81 |
+
opened = self.open_completions(TAB)
|
| 82 |
+
return "break" if opened else None
|
| 83 |
+
|
| 84 |
+
def try_open_completions_event(self, event=None):
|
| 85 |
+
"(./) Open completion list after pause with no movement."
|
| 86 |
+
lastchar = self.text.get("insert-1c")
|
| 87 |
+
if lastchar in TRIGGERS:
|
| 88 |
+
args = TRY_A if lastchar == "." else TRY_F
|
| 89 |
+
self._delayed_completion_index = self.text.index("insert")
|
| 90 |
+
if self._delayed_completion_id is not None:
|
| 91 |
+
self.text.after_cancel(self._delayed_completion_id)
|
| 92 |
+
self._delayed_completion_id = self.text.after(
|
| 93 |
+
self.popupwait, self._delayed_open_completions, args)
|
| 94 |
+
|
| 95 |
+
def _delayed_open_completions(self, args):
|
| 96 |
+
"Call open_completions if index unchanged."
|
| 97 |
+
self._delayed_completion_id = None
|
| 98 |
+
if self.text.index("insert") == self._delayed_completion_index:
|
| 99 |
+
self.open_completions(args)
|
| 100 |
+
|
| 101 |
+
def open_completions(self, args):
|
| 102 |
+
"""Find the completions and create the AutoCompleteWindow.
|
| 103 |
+
Return True if successful (no syntax error or so found).
|
| 104 |
+
If complete is True, then if there's nothing to complete and no
|
| 105 |
+
start of completion, won't open completions and return False.
|
| 106 |
+
If mode is given, will open a completion list only in this mode.
|
| 107 |
+
"""
|
| 108 |
+
evalfuncs, complete, wantwin, mode = args
|
| 109 |
+
# Cancel another delayed call, if it exists.
|
| 110 |
+
if self._delayed_completion_id is not None:
|
| 111 |
+
self.text.after_cancel(self._delayed_completion_id)
|
| 112 |
+
self._delayed_completion_id = None
|
| 113 |
+
|
| 114 |
+
hp = HyperParser(self.editwin, "insert")
|
| 115 |
+
curline = self.text.get("insert linestart", "insert")
|
| 116 |
+
i = j = len(curline)
|
| 117 |
+
if hp.is_in_string() and (not mode or mode==FILES):
|
| 118 |
+
# Find the beginning of the string.
|
| 119 |
+
# fetch_completions will look at the file system to determine
|
| 120 |
+
# whether the string value constitutes an actual file name
|
| 121 |
+
# XXX could consider raw strings here and unescape the string
|
| 122 |
+
# value if it's not raw.
|
| 123 |
+
self._remove_autocomplete_window()
|
| 124 |
+
mode = FILES
|
| 125 |
+
# Find last separator or string start
|
| 126 |
+
while i and curline[i-1] not in "'\"" + SEPS:
|
| 127 |
+
i -= 1
|
| 128 |
+
comp_start = curline[i:j]
|
| 129 |
+
j = i
|
| 130 |
+
# Find string start
|
| 131 |
+
while i and curline[i-1] not in "'\"":
|
| 132 |
+
i -= 1
|
| 133 |
+
comp_what = curline[i:j]
|
| 134 |
+
elif hp.is_in_code() and (not mode or mode==ATTRS):
|
| 135 |
+
self._remove_autocomplete_window()
|
| 136 |
+
mode = ATTRS
|
| 137 |
+
while i and (curline[i-1] in ID_CHARS or ord(curline[i-1]) > 127):
|
| 138 |
+
i -= 1
|
| 139 |
+
comp_start = curline[i:j]
|
| 140 |
+
if i and curline[i-1] == '.': # Need object with attributes.
|
| 141 |
+
hp.set_index("insert-%dc" % (len(curline)-(i-1)))
|
| 142 |
+
comp_what = hp.get_expression()
|
| 143 |
+
if (not comp_what or
|
| 144 |
+
(not evalfuncs and comp_what.find('(') != -1)):
|
| 145 |
+
return None
|
| 146 |
+
else:
|
| 147 |
+
comp_what = ""
|
| 148 |
+
else:
|
| 149 |
+
return None
|
| 150 |
+
|
| 151 |
+
if complete and not comp_what and not comp_start:
|
| 152 |
+
return None
|
| 153 |
+
comp_lists = self.fetch_completions(comp_what, mode)
|
| 154 |
+
if not comp_lists[0]:
|
| 155 |
+
return None
|
| 156 |
+
self.autocompletewindow = self._make_autocomplete_window()
|
| 157 |
+
return not self.autocompletewindow.show_window(
|
| 158 |
+
comp_lists, "insert-%dc" % len(comp_start),
|
| 159 |
+
complete, mode, wantwin)
|
| 160 |
+
|
| 161 |
+
def fetch_completions(self, what, mode):
|
| 162 |
+
"""Return a pair of lists of completions for something. The first list
|
| 163 |
+
is a sublist of the second. Both are sorted.
|
| 164 |
+
|
| 165 |
+
If there is a Python subprocess, get the comp. list there. Otherwise,
|
| 166 |
+
either fetch_completions() is running in the subprocess itself or it
|
| 167 |
+
was called in an IDLE EditorWindow before any script had been run.
|
| 168 |
+
|
| 169 |
+
The subprocess environment is that of the most recently run script. If
|
| 170 |
+
two unrelated modules are being edited some calltips in the current
|
| 171 |
+
module may be inoperative if the module was not the last to run.
|
| 172 |
+
"""
|
| 173 |
+
try:
|
| 174 |
+
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
|
| 175 |
+
except:
|
| 176 |
+
rpcclt = None
|
| 177 |
+
if rpcclt:
|
| 178 |
+
return rpcclt.remotecall("exec", "get_the_completion_list",
|
| 179 |
+
(what, mode), {})
|
| 180 |
+
else:
|
| 181 |
+
if mode == ATTRS:
|
| 182 |
+
if what == "": # Main module names.
|
| 183 |
+
namespace = {**__main__.__builtins__.__dict__,
|
| 184 |
+
**__main__.__dict__}
|
| 185 |
+
bigl = eval("dir()", namespace)
|
| 186 |
+
bigl.extend(completion_kwds)
|
| 187 |
+
bigl.sort()
|
| 188 |
+
if "__all__" in bigl:
|
| 189 |
+
smalll = sorted(eval("__all__", namespace))
|
| 190 |
+
else:
|
| 191 |
+
smalll = [s for s in bigl if s[:1] != '_']
|
| 192 |
+
else:
|
| 193 |
+
try:
|
| 194 |
+
entity = self.get_entity(what)
|
| 195 |
+
bigl = dir(entity)
|
| 196 |
+
bigl.sort()
|
| 197 |
+
if "__all__" in bigl:
|
| 198 |
+
smalll = sorted(entity.__all__)
|
| 199 |
+
else:
|
| 200 |
+
smalll = [s for s in bigl if s[:1] != '_']
|
| 201 |
+
except:
|
| 202 |
+
return [], []
|
| 203 |
+
|
| 204 |
+
elif mode == FILES:
|
| 205 |
+
if what == "":
|
| 206 |
+
what = "."
|
| 207 |
+
try:
|
| 208 |
+
expandedpath = os.path.expanduser(what)
|
| 209 |
+
bigl = os.listdir(expandedpath)
|
| 210 |
+
bigl.sort()
|
| 211 |
+
smalll = [s for s in bigl if s[:1] != '.']
|
| 212 |
+
except OSError:
|
| 213 |
+
return [], []
|
| 214 |
+
|
| 215 |
+
if not smalll:
|
| 216 |
+
smalll = bigl
|
| 217 |
+
return smalll, bigl
|
| 218 |
+
|
| 219 |
+
def get_entity(self, name):
|
| 220 |
+
"Lookup name in a namespace spanning sys.modules and __main.dict__."
|
| 221 |
+
return eval(name, {**sys.modules, **__main__.__dict__})
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
AutoComplete.reload()
|
| 225 |
+
|
| 226 |
+
if __name__ == '__main__':
|
| 227 |
+
from unittest import main
|
| 228 |
+
main('idlelib.idle_test.test_autocomplete', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/autoexpand.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Complete the current word before the cursor with words in the editor.
|
| 2 |
+
|
| 3 |
+
Each menu selection or shortcut key selection replaces the word with a
|
| 4 |
+
different word with the same prefix. The search for matches begins
|
| 5 |
+
before the target and moves toward the top of the editor. It then starts
|
| 6 |
+
after the cursor and moves down. It then returns to the original word and
|
| 7 |
+
the cycle starts again.
|
| 8 |
+
|
| 9 |
+
Changing the current text line or leaving the cursor in a different
|
| 10 |
+
place before requesting the next selection causes AutoExpand to reset
|
| 11 |
+
its state.
|
| 12 |
+
|
| 13 |
+
There is only one instance of Autoexpand.
|
| 14 |
+
'''
|
| 15 |
+
import re
|
| 16 |
+
import string
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class AutoExpand:
|
| 20 |
+
wordchars = string.ascii_letters + string.digits + "_"
|
| 21 |
+
|
| 22 |
+
def __init__(self, editwin):
|
| 23 |
+
self.text = editwin.text
|
| 24 |
+
self.bell = self.text.bell
|
| 25 |
+
self.state = None
|
| 26 |
+
|
| 27 |
+
def expand_word_event(self, event):
|
| 28 |
+
"Replace the current word with the next expansion."
|
| 29 |
+
curinsert = self.text.index("insert")
|
| 30 |
+
curline = self.text.get("insert linestart", "insert lineend")
|
| 31 |
+
if not self.state:
|
| 32 |
+
words = self.getwords()
|
| 33 |
+
index = 0
|
| 34 |
+
else:
|
| 35 |
+
words, index, insert, line = self.state
|
| 36 |
+
if insert != curinsert or line != curline:
|
| 37 |
+
words = self.getwords()
|
| 38 |
+
index = 0
|
| 39 |
+
if not words:
|
| 40 |
+
self.bell()
|
| 41 |
+
return "break"
|
| 42 |
+
word = self.getprevword()
|
| 43 |
+
self.text.delete("insert - %d chars" % len(word), "insert")
|
| 44 |
+
newword = words[index]
|
| 45 |
+
index = (index + 1) % len(words)
|
| 46 |
+
if index == 0:
|
| 47 |
+
self.bell() # Warn we cycled around
|
| 48 |
+
self.text.insert("insert", newword)
|
| 49 |
+
curinsert = self.text.index("insert")
|
| 50 |
+
curline = self.text.get("insert linestart", "insert lineend")
|
| 51 |
+
self.state = words, index, curinsert, curline
|
| 52 |
+
return "break"
|
| 53 |
+
|
| 54 |
+
def getwords(self):
|
| 55 |
+
"Return a list of words that match the prefix before the cursor."
|
| 56 |
+
word = self.getprevword()
|
| 57 |
+
if not word:
|
| 58 |
+
return []
|
| 59 |
+
before = self.text.get("1.0", "insert wordstart")
|
| 60 |
+
wbefore = re.findall(r"\b" + word + r"\w+\b", before)
|
| 61 |
+
del before
|
| 62 |
+
after = self.text.get("insert wordend", "end")
|
| 63 |
+
wafter = re.findall(r"\b" + word + r"\w+\b", after)
|
| 64 |
+
del after
|
| 65 |
+
if not wbefore and not wafter:
|
| 66 |
+
return []
|
| 67 |
+
words = []
|
| 68 |
+
dict = {}
|
| 69 |
+
# search backwards through words before
|
| 70 |
+
wbefore.reverse()
|
| 71 |
+
for w in wbefore:
|
| 72 |
+
if dict.get(w):
|
| 73 |
+
continue
|
| 74 |
+
words.append(w)
|
| 75 |
+
dict[w] = w
|
| 76 |
+
# search onwards through words after
|
| 77 |
+
for w in wafter:
|
| 78 |
+
if dict.get(w):
|
| 79 |
+
continue
|
| 80 |
+
words.append(w)
|
| 81 |
+
dict[w] = w
|
| 82 |
+
words.append(word)
|
| 83 |
+
return words
|
| 84 |
+
|
| 85 |
+
def getprevword(self):
|
| 86 |
+
"Return the word prefix before the cursor."
|
| 87 |
+
line = self.text.get("insert linestart", "insert")
|
| 88 |
+
i = len(line)
|
| 89 |
+
while i > 0 and line[i-1] in self.wordchars:
|
| 90 |
+
i = i-1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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pop up a reminder of how to call a function.
|
| 2 |
+
|
| 3 |
+
Call Tips are floating windows which display function, class, and method
|
| 4 |
+
parameter and docstring information when you type an opening parenthesis, and
|
| 5 |
+
which disappear when you type a closing parenthesis.
|
| 6 |
+
"""
|
| 7 |
+
import __main__
|
| 8 |
+
import inspect
|
| 9 |
+
import re
|
| 10 |
+
import sys
|
| 11 |
+
import textwrap
|
| 12 |
+
import types
|
| 13 |
+
|
| 14 |
+
from idlelib import calltip_w
|
| 15 |
+
from idlelib.hyperparser import HyperParser
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Calltip:
|
| 19 |
+
|
| 20 |
+
def __init__(self, editwin=None):
|
| 21 |
+
if editwin is None: # subprocess and test
|
| 22 |
+
self.editwin = None
|
| 23 |
+
else:
|
| 24 |
+
self.editwin = editwin
|
| 25 |
+
self.text = editwin.text
|
| 26 |
+
self.active_calltip = None
|
| 27 |
+
self._calltip_window = self._make_tk_calltip_window
|
| 28 |
+
|
| 29 |
+
def close(self):
|
| 30 |
+
self._calltip_window = None
|
| 31 |
+
|
| 32 |
+
def _make_tk_calltip_window(self):
|
| 33 |
+
# See __init__ for usage
|
| 34 |
+
return calltip_w.CalltipWindow(self.text)
|
| 35 |
+
|
| 36 |
+
def remove_calltip_window(self, event=None):
|
| 37 |
+
if self.active_calltip:
|
| 38 |
+
self.active_calltip.hidetip()
|
| 39 |
+
self.active_calltip = None
|
| 40 |
+
|
| 41 |
+
def force_open_calltip_event(self, event):
|
| 42 |
+
"The user selected the menu entry or hotkey, open the tip."
|
| 43 |
+
self.open_calltip(True)
|
| 44 |
+
return "break"
|
| 45 |
+
|
| 46 |
+
def try_open_calltip_event(self, event):
|
| 47 |
+
"""Happens when it would be nice to open a calltip, but not really
|
| 48 |
+
necessary, for example after an opening bracket, so function calls
|
| 49 |
+
won't be made.
|
| 50 |
+
"""
|
| 51 |
+
self.open_calltip(False)
|
| 52 |
+
|
| 53 |
+
def refresh_calltip_event(self, event):
|
| 54 |
+
if self.active_calltip and self.active_calltip.tipwindow:
|
| 55 |
+
self.open_calltip(False)
|
| 56 |
+
|
| 57 |
+
def open_calltip(self, evalfuncs):
|
| 58 |
+
"""Maybe close an existing calltip and maybe open a new calltip.
|
| 59 |
+
|
| 60 |
+
Called from (force_open|try_open|refresh)_calltip_event functions.
|
| 61 |
+
"""
|
| 62 |
+
hp = HyperParser(self.editwin, "insert")
|
| 63 |
+
sur_paren = hp.get_surrounding_brackets('(')
|
| 64 |
+
|
| 65 |
+
# If not inside parentheses, no calltip.
|
| 66 |
+
if not sur_paren:
|
| 67 |
+
self.remove_calltip_window()
|
| 68 |
+
return
|
| 69 |
+
|
| 70 |
+
# If a calltip is shown for the current parentheses, do
|
| 71 |
+
# nothing.
|
| 72 |
+
if self.active_calltip:
|
| 73 |
+
opener_line, opener_col = map(int, sur_paren[0].split('.'))
|
| 74 |
+
if (
|
| 75 |
+
(opener_line, opener_col) ==
|
| 76 |
+
(self.active_calltip.parenline, self.active_calltip.parencol)
|
| 77 |
+
):
|
| 78 |
+
return
|
| 79 |
+
|
| 80 |
+
hp.set_index(sur_paren[0])
|
| 81 |
+
try:
|
| 82 |
+
expression = hp.get_expression()
|
| 83 |
+
except ValueError:
|
| 84 |
+
expression = None
|
| 85 |
+
if not expression:
|
| 86 |
+
# No expression before the opening parenthesis, e.g.
|
| 87 |
+
# because it's in a string or the opener for a tuple:
|
| 88 |
+
# Do nothing.
|
| 89 |
+
return
|
| 90 |
+
|
| 91 |
+
# At this point, the current index is after an opening
|
| 92 |
+
# parenthesis, in a section of code, preceded by a valid
|
| 93 |
+
# expression. If there is a calltip shown, it's not for the
|
| 94 |
+
# same index and should be closed.
|
| 95 |
+
self.remove_calltip_window()
|
| 96 |
+
|
| 97 |
+
# Simple, fast heuristic: If the preceding expression includes
|
| 98 |
+
# an opening parenthesis, it likely includes a function call.
|
| 99 |
+
if not evalfuncs and (expression.find('(') != -1):
|
| 100 |
+
return
|
| 101 |
+
|
| 102 |
+
argspec = self.fetch_tip(expression)
|
| 103 |
+
if not argspec:
|
| 104 |
+
return
|
| 105 |
+
self.active_calltip = self._calltip_window()
|
| 106 |
+
self.active_calltip.showtip(argspec, sur_paren[0], sur_paren[1])
|
| 107 |
+
|
| 108 |
+
def fetch_tip(self, expression):
|
| 109 |
+
"""Return the argument list and docstring of a function or class.
|
| 110 |
+
|
| 111 |
+
If there is a Python subprocess, get the calltip there. Otherwise,
|
| 112 |
+
either this fetch_tip() is running in the subprocess or it was
|
| 113 |
+
called in an IDLE running without the subprocess.
|
| 114 |
+
|
| 115 |
+
The subprocess environment is that of the most recently run script. If
|
| 116 |
+
two unrelated modules are being edited some calltips in the current
|
| 117 |
+
module may be inoperative if the module was not the last to run.
|
| 118 |
+
|
| 119 |
+
To find methods, fetch_tip must be fed a fully qualified name.
|
| 120 |
+
|
| 121 |
+
"""
|
| 122 |
+
try:
|
| 123 |
+
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
|
| 124 |
+
except AttributeError:
|
| 125 |
+
rpcclt = None
|
| 126 |
+
if rpcclt:
|
| 127 |
+
return rpcclt.remotecall("exec", "get_the_calltip",
|
| 128 |
+
(expression,), {})
|
| 129 |
+
else:
|
| 130 |
+
return get_argspec(get_entity(expression))
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def get_entity(expression):
|
| 134 |
+
"""Return the object corresponding to expression evaluated
|
| 135 |
+
in a namespace spanning sys.modules and __main.dict__.
|
| 136 |
+
"""
|
| 137 |
+
if expression:
|
| 138 |
+
namespace = {**sys.modules, **__main__.__dict__}
|
| 139 |
+
try:
|
| 140 |
+
return eval(expression, namespace) # Only protect user code.
|
| 141 |
+
except BaseException:
|
| 142 |
+
# An uncaught exception closes idle, and eval can raise any
|
| 143 |
+
# exception, especially if user classes are involved.
|
| 144 |
+
return None
|
| 145 |
+
|
| 146 |
+
# The following are used in get_argspec and some in tests
|
| 147 |
+
_MAX_COLS = 85
|
| 148 |
+
_MAX_LINES = 5 # enough for bytes
|
| 149 |
+
_INDENT = ' '*4 # for wrapped signatures
|
| 150 |
+
_first_param = re.compile(r'(?<=\()\w*\,?\s*')
|
| 151 |
+
_default_callable_argspec = "See source or doc"
|
| 152 |
+
_invalid_method = "invalid method signature"
|
| 153 |
+
|
| 154 |
+
def get_argspec(ob):
|
| 155 |
+
'''Return a string describing the signature of a callable object, or ''.
|
| 156 |
+
|
| 157 |
+
For Python-coded functions and methods, the first line is introspected.
|
| 158 |
+
Delete 'self' parameter for classes (.__init__) and bound methods.
|
| 159 |
+
The next lines are the first lines of the doc string up to the first
|
| 160 |
+
empty line or _MAX_LINES. For builtins, this typically includes
|
| 161 |
+
the arguments in addition to the return value.
|
| 162 |
+
'''
|
| 163 |
+
# Determine function object fob to inspect.
|
| 164 |
+
try:
|
| 165 |
+
ob_call = ob.__call__
|
| 166 |
+
except BaseException: # Buggy user object could raise anything.
|
| 167 |
+
return '' # No popup for non-callables.
|
| 168 |
+
# For Get_argspecTest.test_buggy_getattr_class, CallA() & CallB().
|
| 169 |
+
fob = ob_call if isinstance(ob_call, types.MethodType) else ob
|
| 170 |
+
|
| 171 |
+
# Initialize argspec and wrap it to get lines.
|
| 172 |
+
try:
|
| 173 |
+
argspec = str(inspect.signature(fob))
|
| 174 |
+
except Exception as err:
|
| 175 |
+
msg = str(err)
|
| 176 |
+
if msg.startswith(_invalid_method):
|
| 177 |
+
return _invalid_method
|
| 178 |
+
else:
|
| 179 |
+
argspec = ''
|
| 180 |
+
|
| 181 |
+
if isinstance(fob, type) and argspec == '()':
|
| 182 |
+
# If fob has no argument, use default callable argspec.
|
| 183 |
+
argspec = _default_callable_argspec
|
| 184 |
+
|
| 185 |
+
lines = (textwrap.wrap(argspec, _MAX_COLS, subsequent_indent=_INDENT)
|
| 186 |
+
if len(argspec) > _MAX_COLS else [argspec] if argspec else [])
|
| 187 |
+
|
| 188 |
+
# Augment lines from docstring, if any, and join to get argspec.
|
| 189 |
+
doc = inspect.getdoc(ob)
|
| 190 |
+
if doc:
|
| 191 |
+
for line in doc.split('\n', _MAX_LINES)[:_MAX_LINES]:
|
| 192 |
+
line = line.strip()
|
| 193 |
+
if not line:
|
| 194 |
+
break
|
| 195 |
+
if len(line) > _MAX_COLS:
|
| 196 |
+
line = line[: _MAX_COLS - 3] + '...'
|
| 197 |
+
lines.append(line)
|
| 198 |
+
argspec = '\n'.join(lines)
|
| 199 |
+
|
| 200 |
+
return argspec or _default_callable_argspec
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
if __name__ == '__main__':
|
| 204 |
+
from unittest import main
|
| 205 |
+
main('idlelib.idle_test.test_calltip', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/calltip_w.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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4 |
+
Used by calltip.py.
|
| 5 |
+
"""
|
| 6 |
+
from tkinter import Label, LEFT, SOLID, TclError
|
| 7 |
+
|
| 8 |
+
from idlelib.tooltip import TooltipBase
|
| 9 |
+
|
| 10 |
+
HIDE_EVENT = "<<calltipwindow-hide>>"
|
| 11 |
+
HIDE_SEQUENCES = ("<Key-Escape>", "<FocusOut>")
|
| 12 |
+
CHECKHIDE_EVENT = "<<calltipwindow-checkhide>>"
|
| 13 |
+
CHECKHIDE_SEQUENCES = ("<KeyRelease>", "<ButtonRelease>")
|
| 14 |
+
CHECKHIDE_TIME = 100 # milliseconds
|
| 15 |
+
|
| 16 |
+
MARK_RIGHT = "calltipwindowregion_right"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class CalltipWindow(TooltipBase):
|
| 20 |
+
"""A call-tip widget for tkinter text widgets."""
|
| 21 |
+
|
| 22 |
+
def __init__(self, text_widget):
|
| 23 |
+
"""Create a call-tip; shown by showtip().
|
| 24 |
+
|
| 25 |
+
text_widget: a Text widget with code for which call-tips are desired
|
| 26 |
+
"""
|
| 27 |
+
# Note: The Text widget will be accessible as self.anchor_widget
|
| 28 |
+
super(CalltipWindow, self).__init__(text_widget)
|
| 29 |
+
|
| 30 |
+
self.label = self.text = None
|
| 31 |
+
self.parenline = self.parencol = self.lastline = None
|
| 32 |
+
self.hideid = self.checkhideid = None
|
| 33 |
+
self.checkhide_after_id = None
|
| 34 |
+
|
| 35 |
+
def get_position(self):
|
| 36 |
+
"""Choose the position of the call-tip."""
|
| 37 |
+
curline = int(self.anchor_widget.index("insert").split('.')[0])
|
| 38 |
+
if curline == self.parenline:
|
| 39 |
+
anchor_index = (self.parenline, self.parencol)
|
| 40 |
+
else:
|
| 41 |
+
anchor_index = (curline, 0)
|
| 42 |
+
box = self.anchor_widget.bbox("%d.%d" % anchor_index)
|
| 43 |
+
if not box:
|
| 44 |
+
box = list(self.anchor_widget.bbox("insert"))
|
| 45 |
+
# align to left of window
|
| 46 |
+
box[0] = 0
|
| 47 |
+
box[2] = 0
|
| 48 |
+
return box[0] + 2, box[1] + box[3]
|
| 49 |
+
|
| 50 |
+
def position_window(self):
|
| 51 |
+
"Reposition the window if needed."
|
| 52 |
+
curline = int(self.anchor_widget.index("insert").split('.')[0])
|
| 53 |
+
if curline == self.lastline:
|
| 54 |
+
return
|
| 55 |
+
self.lastline = curline
|
| 56 |
+
self.anchor_widget.see("insert")
|
| 57 |
+
super(CalltipWindow, self).position_window()
|
| 58 |
+
|
| 59 |
+
def showtip(self, text, parenleft, parenright):
|
| 60 |
+
"""Show the call-tip, bind events which will close it and reposition it.
|
| 61 |
+
|
| 62 |
+
text: the text to display in the call-tip
|
| 63 |
+
parenleft: index of the opening parenthesis in the text widget
|
| 64 |
+
parenright: index of the closing parenthesis in the text widget,
|
| 65 |
+
or the end of the line if there is no closing parenthesis
|
| 66 |
+
"""
|
| 67 |
+
# Only called in calltip.Calltip, where lines are truncated
|
| 68 |
+
self.text = text
|
| 69 |
+
if self.tipwindow or not self.text:
|
| 70 |
+
return
|
| 71 |
+
|
| 72 |
+
self.anchor_widget.mark_set(MARK_RIGHT, parenright)
|
| 73 |
+
self.parenline, self.parencol = map(
|
| 74 |
+
int, self.anchor_widget.index(parenleft).split("."))
|
| 75 |
+
|
| 76 |
+
super(CalltipWindow, self).showtip()
|
| 77 |
+
|
| 78 |
+
self._bind_events()
|
| 79 |
+
|
| 80 |
+
def showcontents(self):
|
| 81 |
+
"""Create the call-tip widget."""
|
| 82 |
+
self.label = Label(self.tipwindow, text=self.text, justify=LEFT,
|
| 83 |
+
background="#ffffd0", foreground="black",
|
| 84 |
+
relief=SOLID, borderwidth=1,
|
| 85 |
+
font=self.anchor_widget['font'])
|
| 86 |
+
self.label.pack()
|
| 87 |
+
|
| 88 |
+
def checkhide_event(self, event=None):
|
| 89 |
+
"""Handle CHECK_HIDE_EVENT: call hidetip or reschedule."""
|
| 90 |
+
if not self.tipwindow:
|
| 91 |
+
# If the event was triggered by the same event that unbound
|
| 92 |
+
# this function, the function will be called nevertheless,
|
| 93 |
+
# so do nothing in this case.
|
| 94 |
+
return None
|
| 95 |
+
|
| 96 |
+
# Hide the call-tip if the insertion cursor moves outside of the
|
| 97 |
+
# parenthesis.
|
| 98 |
+
curline, curcol = map(int, self.anchor_widget.index("insert").split('.'))
|
| 99 |
+
if curline < self.parenline or \
|
| 100 |
+
(curline == self.parenline and curcol <= self.parencol) or \
|
| 101 |
+
self.anchor_widget.compare("insert", ">", MARK_RIGHT):
|
| 102 |
+
self.hidetip()
|
| 103 |
+
return "break"
|
| 104 |
+
|
| 105 |
+
# Not hiding the call-tip.
|
| 106 |
+
|
| 107 |
+
self.position_window()
|
| 108 |
+
# Re-schedule this function to be called again in a short while.
|
| 109 |
+
if self.checkhide_after_id is not None:
|
| 110 |
+
self.anchor_widget.after_cancel(self.checkhide_after_id)
|
| 111 |
+
self.checkhide_after_id = \
|
| 112 |
+
self.anchor_widget.after(CHECKHIDE_TIME, self.checkhide_event)
|
| 113 |
+
return None
|
| 114 |
+
|
| 115 |
+
def hide_event(self, event):
|
| 116 |
+
"""Handle HIDE_EVENT by calling hidetip."""
|
| 117 |
+
if not self.tipwindow:
|
| 118 |
+
# See the explanation in checkhide_event.
|
| 119 |
+
return None
|
| 120 |
+
self.hidetip()
|
| 121 |
+
return "break"
|
| 122 |
+
|
| 123 |
+
def hidetip(self):
|
| 124 |
+
"""Hide the call-tip."""
|
| 125 |
+
if not self.tipwindow:
|
| 126 |
+
return
|
| 127 |
+
|
| 128 |
+
try:
|
| 129 |
+
self.label.destroy()
|
| 130 |
+
except TclError:
|
| 131 |
+
pass
|
| 132 |
+
self.label = None
|
| 133 |
+
|
| 134 |
+
self.parenline = self.parencol = self.lastline = None
|
| 135 |
+
try:
|
| 136 |
+
self.anchor_widget.mark_unset(MARK_RIGHT)
|
| 137 |
+
except TclError:
|
| 138 |
+
pass
|
| 139 |
+
|
| 140 |
+
try:
|
| 141 |
+
self._unbind_events()
|
| 142 |
+
except (TclError, ValueError):
|
| 143 |
+
# ValueError may be raised by MultiCall
|
| 144 |
+
pass
|
| 145 |
+
|
| 146 |
+
super(CalltipWindow, self).hidetip()
|
| 147 |
+
|
| 148 |
+
def _bind_events(self):
|
| 149 |
+
"""Bind event handlers."""
|
| 150 |
+
self.checkhideid = self.anchor_widget.bind(CHECKHIDE_EVENT,
|
| 151 |
+
self.checkhide_event)
|
| 152 |
+
for seq in CHECKHIDE_SEQUENCES:
|
| 153 |
+
self.anchor_widget.event_add(CHECKHIDE_EVENT, seq)
|
| 154 |
+
self.anchor_widget.after(CHECKHIDE_TIME, self.checkhide_event)
|
| 155 |
+
self.hideid = self.anchor_widget.bind(HIDE_EVENT,
|
| 156 |
+
self.hide_event)
|
| 157 |
+
for seq in HIDE_SEQUENCES:
|
| 158 |
+
self.anchor_widget.event_add(HIDE_EVENT, seq)
|
| 159 |
+
|
| 160 |
+
def _unbind_events(self):
|
| 161 |
+
"""Unbind event handlers."""
|
| 162 |
+
for seq in CHECKHIDE_SEQUENCES:
|
| 163 |
+
self.anchor_widget.event_delete(CHECKHIDE_EVENT, seq)
|
| 164 |
+
self.anchor_widget.unbind(CHECKHIDE_EVENT, self.checkhideid)
|
| 165 |
+
self.checkhideid = None
|
| 166 |
+
for seq in HIDE_SEQUENCES:
|
| 167 |
+
self.anchor_widget.event_delete(HIDE_EVENT, seq)
|
| 168 |
+
self.anchor_widget.unbind(HIDE_EVENT, self.hideid)
|
| 169 |
+
self.hideid = None
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def _calltip_window(parent): # htest #
|
| 173 |
+
from tkinter import Toplevel, Text, LEFT, BOTH
|
| 174 |
+
|
| 175 |
+
top = Toplevel(parent)
|
| 176 |
+
top.title("Test call-tips")
|
| 177 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 178 |
+
top.geometry("250x100+%d+%d" % (x + 175, y + 150))
|
| 179 |
+
text = Text(top)
|
| 180 |
+
text.pack(side=LEFT, fill=BOTH, expand=1)
|
| 181 |
+
text.insert("insert", "string.split")
|
| 182 |
+
top.update()
|
| 183 |
+
|
| 184 |
+
calltip = CalltipWindow(text)
|
| 185 |
+
def calltip_show(event):
|
| 186 |
+
calltip.showtip("(s='Hello world')", "insert", "end")
|
| 187 |
+
def calltip_hide(event):
|
| 188 |
+
calltip.hidetip()
|
| 189 |
+
text.event_add("<<calltip-show>>", "(")
|
| 190 |
+
text.event_add("<<calltip-hide>>", ")")
|
| 191 |
+
text.bind("<<calltip-show>>", calltip_show)
|
| 192 |
+
text.bind("<<calltip-hide>>", calltip_hide)
|
| 193 |
+
|
| 194 |
+
text.focus_set()
|
| 195 |
+
|
| 196 |
+
if __name__ == '__main__':
|
| 197 |
+
from unittest import main
|
| 198 |
+
main('idlelib.idle_test.test_calltip_w', verbosity=2, exit=False)
|
| 199 |
+
|
| 200 |
+
from idlelib.idle_test.htest import run
|
| 201 |
+
run(_calltip_window)
|
evalkit_cambrian/lib/python3.10/idlelib/colorizer.py
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import builtins
|
| 2 |
+
import keyword
|
| 3 |
+
import re
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
from idlelib.config import idleConf
|
| 7 |
+
from idlelib.delegator import Delegator
|
| 8 |
+
|
| 9 |
+
DEBUG = False
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def any(name, alternates):
|
| 13 |
+
"Return a named group pattern matching list of alternates."
|
| 14 |
+
return "(?P<%s>" % name + "|".join(alternates) + ")"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def make_pat():
|
| 18 |
+
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
|
| 19 |
+
match_softkw = (
|
| 20 |
+
r"^[ \t]*" + # at beginning of line + possible indentation
|
| 21 |
+
r"(?P<MATCH_SOFTKW>match)\b" +
|
| 22 |
+
r"(?![ \t]*(?:" + "|".join([ # not followed by ...
|
| 23 |
+
r"[:,;=^&|@~)\]}]", # a character which means it can't be a
|
| 24 |
+
# pattern-matching statement
|
| 25 |
+
r"\b(?:" + r"|".join(keyword.kwlist) + r")\b", # a keyword
|
| 26 |
+
]) +
|
| 27 |
+
r"))"
|
| 28 |
+
)
|
| 29 |
+
case_default = (
|
| 30 |
+
r"^[ \t]*" + # at beginning of line + possible indentation
|
| 31 |
+
r"(?P<CASE_SOFTKW>case)" +
|
| 32 |
+
r"[ \t]+(?P<CASE_DEFAULT_UNDERSCORE>_\b)"
|
| 33 |
+
)
|
| 34 |
+
case_softkw_and_pattern = (
|
| 35 |
+
r"^[ \t]*" + # at beginning of line + possible indentation
|
| 36 |
+
r"(?P<CASE_SOFTKW2>case)\b" +
|
| 37 |
+
r"(?![ \t]*(?:" + "|".join([ # not followed by ...
|
| 38 |
+
r"_\b", # a lone underscore
|
| 39 |
+
r"[:,;=^&|@~)\]}]", # a character which means it can't be a
|
| 40 |
+
# pattern-matching case
|
| 41 |
+
r"\b(?:" + r"|".join(keyword.kwlist) + r")\b", # a keyword
|
| 42 |
+
]) +
|
| 43 |
+
r"))"
|
| 44 |
+
)
|
| 45 |
+
builtinlist = [str(name) for name in dir(builtins)
|
| 46 |
+
if not name.startswith('_') and
|
| 47 |
+
name not in keyword.kwlist]
|
| 48 |
+
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
|
| 49 |
+
comment = any("COMMENT", [r"#[^\n]*"])
|
| 50 |
+
stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb)?"
|
| 51 |
+
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
|
| 52 |
+
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
|
| 53 |
+
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
|
| 54 |
+
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
|
| 55 |
+
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
|
| 56 |
+
prog = re.compile("|".join([
|
| 57 |
+
builtin, comment, string, kw,
|
| 58 |
+
match_softkw, case_default,
|
| 59 |
+
case_softkw_and_pattern,
|
| 60 |
+
any("SYNC", [r"\n"]),
|
| 61 |
+
]),
|
| 62 |
+
re.DOTALL | re.MULTILINE)
|
| 63 |
+
return prog
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
prog = make_pat()
|
| 67 |
+
idprog = re.compile(r"\s+(\w+)")
|
| 68 |
+
prog_group_name_to_tag = {
|
| 69 |
+
"MATCH_SOFTKW": "KEYWORD",
|
| 70 |
+
"CASE_SOFTKW": "KEYWORD",
|
| 71 |
+
"CASE_DEFAULT_UNDERSCORE": "KEYWORD",
|
| 72 |
+
"CASE_SOFTKW2": "KEYWORD",
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def matched_named_groups(re_match):
|
| 77 |
+
"Get only the non-empty named groups from an re.Match object."
|
| 78 |
+
return ((k, v) for (k, v) in re_match.groupdict().items() if v)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def color_config(text):
|
| 82 |
+
"""Set color options of Text widget.
|
| 83 |
+
|
| 84 |
+
If ColorDelegator is used, this should be called first.
|
| 85 |
+
"""
|
| 86 |
+
# Called from htest, TextFrame, Editor, and Turtledemo.
|
| 87 |
+
# Not automatic because ColorDelegator does not know 'text'.
|
| 88 |
+
theme = idleConf.CurrentTheme()
|
| 89 |
+
normal_colors = idleConf.GetHighlight(theme, 'normal')
|
| 90 |
+
cursor_color = idleConf.GetHighlight(theme, 'cursor')['foreground']
|
| 91 |
+
select_colors = idleConf.GetHighlight(theme, 'hilite')
|
| 92 |
+
text.config(
|
| 93 |
+
foreground=normal_colors['foreground'],
|
| 94 |
+
background=normal_colors['background'],
|
| 95 |
+
insertbackground=cursor_color,
|
| 96 |
+
selectforeground=select_colors['foreground'],
|
| 97 |
+
selectbackground=select_colors['background'],
|
| 98 |
+
inactiveselectbackground=select_colors['background'], # new in 8.5
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class ColorDelegator(Delegator):
|
| 103 |
+
"""Delegator for syntax highlighting (text coloring).
|
| 104 |
+
|
| 105 |
+
Instance variables:
|
| 106 |
+
delegate: Delegator below this one in the stack, meaning the
|
| 107 |
+
one this one delegates to.
|
| 108 |
+
|
| 109 |
+
Used to track state:
|
| 110 |
+
after_id: Identifier for scheduled after event, which is a
|
| 111 |
+
timer for colorizing the text.
|
| 112 |
+
allow_colorizing: Boolean toggle for applying colorizing.
|
| 113 |
+
colorizing: Boolean flag when colorizing is in process.
|
| 114 |
+
stop_colorizing: Boolean flag to end an active colorizing
|
| 115 |
+
process.
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
def __init__(self):
|
| 119 |
+
Delegator.__init__(self)
|
| 120 |
+
self.init_state()
|
| 121 |
+
self.prog = prog
|
| 122 |
+
self.idprog = idprog
|
| 123 |
+
self.LoadTagDefs()
|
| 124 |
+
|
| 125 |
+
def init_state(self):
|
| 126 |
+
"Initialize variables that track colorizing state."
|
| 127 |
+
self.after_id = None
|
| 128 |
+
self.allow_colorizing = True
|
| 129 |
+
self.stop_colorizing = False
|
| 130 |
+
self.colorizing = False
|
| 131 |
+
|
| 132 |
+
def setdelegate(self, delegate):
|
| 133 |
+
"""Set the delegate for this instance.
|
| 134 |
+
|
| 135 |
+
A delegate is an instance of a Delegator class and each
|
| 136 |
+
delegate points to the next delegator in the stack. This
|
| 137 |
+
allows multiple delegators to be chained together for a
|
| 138 |
+
widget. The bottom delegate for a colorizer is a Text
|
| 139 |
+
widget.
|
| 140 |
+
|
| 141 |
+
If there is a delegate, also start the colorizing process.
|
| 142 |
+
"""
|
| 143 |
+
if self.delegate is not None:
|
| 144 |
+
self.unbind("<<toggle-auto-coloring>>")
|
| 145 |
+
Delegator.setdelegate(self, delegate)
|
| 146 |
+
if delegate is not None:
|
| 147 |
+
self.config_colors()
|
| 148 |
+
self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
|
| 149 |
+
self.notify_range("1.0", "end")
|
| 150 |
+
else:
|
| 151 |
+
# No delegate - stop any colorizing.
|
| 152 |
+
self.stop_colorizing = True
|
| 153 |
+
self.allow_colorizing = False
|
| 154 |
+
|
| 155 |
+
def config_colors(self):
|
| 156 |
+
"Configure text widget tags with colors from tagdefs."
|
| 157 |
+
for tag, cnf in self.tagdefs.items():
|
| 158 |
+
self.tag_configure(tag, **cnf)
|
| 159 |
+
self.tag_raise('sel')
|
| 160 |
+
|
| 161 |
+
def LoadTagDefs(self):
|
| 162 |
+
"Create dictionary of tag names to text colors."
|
| 163 |
+
theme = idleConf.CurrentTheme()
|
| 164 |
+
self.tagdefs = {
|
| 165 |
+
"COMMENT": idleConf.GetHighlight(theme, "comment"),
|
| 166 |
+
"KEYWORD": idleConf.GetHighlight(theme, "keyword"),
|
| 167 |
+
"BUILTIN": idleConf.GetHighlight(theme, "builtin"),
|
| 168 |
+
"STRING": idleConf.GetHighlight(theme, "string"),
|
| 169 |
+
"DEFINITION": idleConf.GetHighlight(theme, "definition"),
|
| 170 |
+
"SYNC": {'background': None, 'foreground': None},
|
| 171 |
+
"TODO": {'background': None, 'foreground': None},
|
| 172 |
+
"ERROR": idleConf.GetHighlight(theme, "error"),
|
| 173 |
+
# "hit" is used by ReplaceDialog to mark matches. It shouldn't be changed by Colorizer, but
|
| 174 |
+
# that currently isn't technically possible. This should be moved elsewhere in the future
|
| 175 |
+
# when fixing the "hit" tag's visibility, or when the replace dialog is replaced with a
|
| 176 |
+
# non-modal alternative.
|
| 177 |
+
"hit": idleConf.GetHighlight(theme, "hit"),
|
| 178 |
+
}
|
| 179 |
+
if DEBUG: print('tagdefs', self.tagdefs)
|
| 180 |
+
|
| 181 |
+
def insert(self, index, chars, tags=None):
|
| 182 |
+
"Insert chars into widget at index and mark for colorizing."
|
| 183 |
+
index = self.index(index)
|
| 184 |
+
self.delegate.insert(index, chars, tags)
|
| 185 |
+
self.notify_range(index, index + "+%dc" % len(chars))
|
| 186 |
+
|
| 187 |
+
def delete(self, index1, index2=None):
|
| 188 |
+
"Delete chars between indexes and mark for colorizing."
|
| 189 |
+
index1 = self.index(index1)
|
| 190 |
+
self.delegate.delete(index1, index2)
|
| 191 |
+
self.notify_range(index1)
|
| 192 |
+
|
| 193 |
+
def notify_range(self, index1, index2=None):
|
| 194 |
+
"Mark text changes for processing and restart colorizing, if active."
|
| 195 |
+
self.tag_add("TODO", index1, index2)
|
| 196 |
+
if self.after_id:
|
| 197 |
+
if DEBUG: print("colorizing already scheduled")
|
| 198 |
+
return
|
| 199 |
+
if self.colorizing:
|
| 200 |
+
self.stop_colorizing = True
|
| 201 |
+
if DEBUG: print("stop colorizing")
|
| 202 |
+
if self.allow_colorizing:
|
| 203 |
+
if DEBUG: print("schedule colorizing")
|
| 204 |
+
self.after_id = self.after(1, self.recolorize)
|
| 205 |
+
return
|
| 206 |
+
|
| 207 |
+
def close(self):
|
| 208 |
+
if self.after_id:
|
| 209 |
+
after_id = self.after_id
|
| 210 |
+
self.after_id = None
|
| 211 |
+
if DEBUG: print("cancel scheduled recolorizer")
|
| 212 |
+
self.after_cancel(after_id)
|
| 213 |
+
self.allow_colorizing = False
|
| 214 |
+
self.stop_colorizing = True
|
| 215 |
+
|
| 216 |
+
def toggle_colorize_event(self, event=None):
|
| 217 |
+
"""Toggle colorizing on and off.
|
| 218 |
+
|
| 219 |
+
When toggling off, if colorizing is scheduled or is in
|
| 220 |
+
process, it will be cancelled and/or stopped.
|
| 221 |
+
|
| 222 |
+
When toggling on, colorizing will be scheduled.
|
| 223 |
+
"""
|
| 224 |
+
if self.after_id:
|
| 225 |
+
after_id = self.after_id
|
| 226 |
+
self.after_id = None
|
| 227 |
+
if DEBUG: print("cancel scheduled recolorizer")
|
| 228 |
+
self.after_cancel(after_id)
|
| 229 |
+
if self.allow_colorizing and self.colorizing:
|
| 230 |
+
if DEBUG: print("stop colorizing")
|
| 231 |
+
self.stop_colorizing = True
|
| 232 |
+
self.allow_colorizing = not self.allow_colorizing
|
| 233 |
+
if self.allow_colorizing and not self.colorizing:
|
| 234 |
+
self.after_id = self.after(1, self.recolorize)
|
| 235 |
+
if DEBUG:
|
| 236 |
+
print("auto colorizing turned",
|
| 237 |
+
"on" if self.allow_colorizing else "off")
|
| 238 |
+
return "break"
|
| 239 |
+
|
| 240 |
+
def recolorize(self):
|
| 241 |
+
"""Timer event (every 1ms) to colorize text.
|
| 242 |
+
|
| 243 |
+
Colorizing is only attempted when the text widget exists,
|
| 244 |
+
when colorizing is toggled on, and when the colorizing
|
| 245 |
+
process is not already running.
|
| 246 |
+
|
| 247 |
+
After colorizing is complete, some cleanup is done to
|
| 248 |
+
make sure that all the text has been colorized.
|
| 249 |
+
"""
|
| 250 |
+
self.after_id = None
|
| 251 |
+
if not self.delegate:
|
| 252 |
+
if DEBUG: print("no delegate")
|
| 253 |
+
return
|
| 254 |
+
if not self.allow_colorizing:
|
| 255 |
+
if DEBUG: print("auto colorizing is off")
|
| 256 |
+
return
|
| 257 |
+
if self.colorizing:
|
| 258 |
+
if DEBUG: print("already colorizing")
|
| 259 |
+
return
|
| 260 |
+
try:
|
| 261 |
+
self.stop_colorizing = False
|
| 262 |
+
self.colorizing = True
|
| 263 |
+
if DEBUG: print("colorizing...")
|
| 264 |
+
t0 = time.perf_counter()
|
| 265 |
+
self.recolorize_main()
|
| 266 |
+
t1 = time.perf_counter()
|
| 267 |
+
if DEBUG: print("%.3f seconds" % (t1-t0))
|
| 268 |
+
finally:
|
| 269 |
+
self.colorizing = False
|
| 270 |
+
if self.allow_colorizing and self.tag_nextrange("TODO", "1.0"):
|
| 271 |
+
if DEBUG: print("reschedule colorizing")
|
| 272 |
+
self.after_id = self.after(1, self.recolorize)
|
| 273 |
+
|
| 274 |
+
def recolorize_main(self):
|
| 275 |
+
"Evaluate text and apply colorizing tags."
|
| 276 |
+
next = "1.0"
|
| 277 |
+
while todo_tag_range := self.tag_nextrange("TODO", next):
|
| 278 |
+
self.tag_remove("SYNC", todo_tag_range[0], todo_tag_range[1])
|
| 279 |
+
sync_tag_range = self.tag_prevrange("SYNC", todo_tag_range[0])
|
| 280 |
+
head = sync_tag_range[1] if sync_tag_range else "1.0"
|
| 281 |
+
|
| 282 |
+
chars = ""
|
| 283 |
+
next = head
|
| 284 |
+
lines_to_get = 1
|
| 285 |
+
ok = False
|
| 286 |
+
while not ok:
|
| 287 |
+
mark = next
|
| 288 |
+
next = self.index(mark + "+%d lines linestart" %
|
| 289 |
+
lines_to_get)
|
| 290 |
+
lines_to_get = min(lines_to_get * 2, 100)
|
| 291 |
+
ok = "SYNC" in self.tag_names(next + "-1c")
|
| 292 |
+
line = self.get(mark, next)
|
| 293 |
+
##print head, "get", mark, next, "->", repr(line)
|
| 294 |
+
if not line:
|
| 295 |
+
return
|
| 296 |
+
for tag in self.tagdefs:
|
| 297 |
+
self.tag_remove(tag, mark, next)
|
| 298 |
+
chars += line
|
| 299 |
+
self._add_tags_in_section(chars, head)
|
| 300 |
+
if "SYNC" in self.tag_names(next + "-1c"):
|
| 301 |
+
head = next
|
| 302 |
+
chars = ""
|
| 303 |
+
else:
|
| 304 |
+
ok = False
|
| 305 |
+
if not ok:
|
| 306 |
+
# We're in an inconsistent state, and the call to
|
| 307 |
+
# update may tell us to stop. It may also change
|
| 308 |
+
# the correct value for "next" (since this is a
|
| 309 |
+
# line.col string, not a true mark). So leave a
|
| 310 |
+
# crumb telling the next invocation to resume here
|
| 311 |
+
# in case update tells us to leave.
|
| 312 |
+
self.tag_add("TODO", next)
|
| 313 |
+
self.update()
|
| 314 |
+
if self.stop_colorizing:
|
| 315 |
+
if DEBUG: print("colorizing stopped")
|
| 316 |
+
return
|
| 317 |
+
|
| 318 |
+
def _add_tag(self, start, end, head, matched_group_name):
|
| 319 |
+
"""Add a tag to a given range in the text widget.
|
| 320 |
+
|
| 321 |
+
This is a utility function, receiving the range as `start` and
|
| 322 |
+
`end` positions, each of which is a number of characters
|
| 323 |
+
relative to the given `head` index in the text widget.
|
| 324 |
+
|
| 325 |
+
The tag to add is determined by `matched_group_name`, which is
|
| 326 |
+
the name of a regular expression "named group" as matched by
|
| 327 |
+
by the relevant highlighting regexps.
|
| 328 |
+
"""
|
| 329 |
+
tag = prog_group_name_to_tag.get(matched_group_name,
|
| 330 |
+
matched_group_name)
|
| 331 |
+
self.tag_add(tag,
|
| 332 |
+
f"{head}+{start:d}c",
|
| 333 |
+
f"{head}+{end:d}c")
|
| 334 |
+
|
| 335 |
+
def _add_tags_in_section(self, chars, head):
|
| 336 |
+
"""Parse and add highlighting tags to a given part of the text.
|
| 337 |
+
|
| 338 |
+
`chars` is a string with the text to parse and to which
|
| 339 |
+
highlighting is to be applied.
|
| 340 |
+
|
| 341 |
+
`head` is the index in the text widget where the text is found.
|
| 342 |
+
"""
|
| 343 |
+
for m in self.prog.finditer(chars):
|
| 344 |
+
for name, matched_text in matched_named_groups(m):
|
| 345 |
+
a, b = m.span(name)
|
| 346 |
+
self._add_tag(a, b, head, name)
|
| 347 |
+
if matched_text in ("def", "class"):
|
| 348 |
+
if m1 := self.idprog.match(chars, b):
|
| 349 |
+
a, b = m1.span(1)
|
| 350 |
+
self._add_tag(a, b, head, "DEFINITION")
|
| 351 |
+
|
| 352 |
+
def removecolors(self):
|
| 353 |
+
"Remove all colorizing tags."
|
| 354 |
+
for tag in self.tagdefs:
|
| 355 |
+
self.tag_remove(tag, "1.0", "end")
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def _color_delegator(parent): # htest #
|
| 359 |
+
from tkinter import Toplevel, Text
|
| 360 |
+
from idlelib.idle_test.test_colorizer import source
|
| 361 |
+
from idlelib.percolator import Percolator
|
| 362 |
+
|
| 363 |
+
top = Toplevel(parent)
|
| 364 |
+
top.title("Test ColorDelegator")
|
| 365 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 366 |
+
top.geometry("700x550+%d+%d" % (x + 20, y + 175))
|
| 367 |
+
|
| 368 |
+
text = Text(top, background="white")
|
| 369 |
+
text.pack(expand=1, fill="both")
|
| 370 |
+
text.insert("insert", source)
|
| 371 |
+
text.focus_set()
|
| 372 |
+
|
| 373 |
+
color_config(text)
|
| 374 |
+
p = Percolator(text)
|
| 375 |
+
d = ColorDelegator()
|
| 376 |
+
p.insertfilter(d)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
if __name__ == "__main__":
|
| 380 |
+
from unittest import main
|
| 381 |
+
main('idlelib.idle_test.test_colorizer', verbosity=2, exit=False)
|
| 382 |
+
|
| 383 |
+
from idlelib.idle_test.htest import run
|
| 384 |
+
run(_color_delegator)
|
evalkit_cambrian/lib/python3.10/idlelib/config-extensions.def
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# config-extensions.def
|
| 2 |
+
#
|
| 3 |
+
# The following sections are for features that are no longer extensions.
|
| 4 |
+
# Their options values are left here for back-compatibility.
|
| 5 |
+
|
| 6 |
+
[AutoComplete]
|
| 7 |
+
popupwait= 2000
|
| 8 |
+
|
| 9 |
+
[CodeContext]
|
| 10 |
+
maxlines= 15
|
| 11 |
+
|
| 12 |
+
[FormatParagraph]
|
| 13 |
+
max-width= 72
|
| 14 |
+
|
| 15 |
+
[ParenMatch]
|
| 16 |
+
style= expression
|
| 17 |
+
flash-delay= 500
|
| 18 |
+
bell= True
|
| 19 |
+
|
| 20 |
+
# IDLE reads several config files to determine user preferences. This
|
| 21 |
+
# file is the default configuration file for IDLE extensions settings.
|
| 22 |
+
#
|
| 23 |
+
# Each extension must have at least one section, named after the
|
| 24 |
+
# extension module. This section must contain an 'enable' item (=True to
|
| 25 |
+
# enable the extension, =False to disable it), it may contain
|
| 26 |
+
# 'enable_editor' or 'enable_shell' items, to apply it only to editor ir
|
| 27 |
+
# shell windows, and may also contain any other general configuration
|
| 28 |
+
# items for the extension. Other True/False values will also be
|
| 29 |
+
# recognized as boolean by the Extension Configuration dialog.
|
| 30 |
+
#
|
| 31 |
+
# Each extension must define at least one section named
|
| 32 |
+
# ExtensionName_bindings or ExtensionName_cfgBindings. If present,
|
| 33 |
+
# ExtensionName_bindings defines virtual event bindings for the
|
| 34 |
+
# extension that are not user re-configurable. If present,
|
| 35 |
+
# ExtensionName_cfgBindings defines virtual event bindings for the
|
| 36 |
+
# extension that may be sensibly re-configured.
|
| 37 |
+
#
|
| 38 |
+
# If there are no keybindings for a menus' virtual events, include lines
|
| 39 |
+
# like <<toggle-code-context>>=.
|
| 40 |
+
#
|
| 41 |
+
# Currently it is necessary to manually modify this file to change
|
| 42 |
+
# extension key bindings and default values. To customize, create
|
| 43 |
+
# ~/.idlerc/config-extensions.cfg and append the appropriate customized
|
| 44 |
+
# section(s). Those sections will override the defaults in this file.
|
| 45 |
+
#
|
| 46 |
+
# Note: If a keybinding is already in use when the extension is loaded,
|
| 47 |
+
# the extension's virtual event's keybinding will be set to ''.
|
| 48 |
+
#
|
| 49 |
+
# See config-keys.def for notes on specifying keys and extend.txt for
|
| 50 |
+
# information on creating IDLE extensions.
|
| 51 |
+
|
| 52 |
+
# A fake extension for testing and example purposes. When enabled and
|
| 53 |
+
# invoked, inserts or deletes z-text at beginning of every line.
|
| 54 |
+
[ZzDummy]
|
| 55 |
+
enable= False
|
| 56 |
+
enable_shell = False
|
| 57 |
+
enable_editor = True
|
| 58 |
+
z-text= Z
|
| 59 |
+
[ZzDummy_cfgBindings]
|
| 60 |
+
z-in= <Control-Shift-KeyRelease-Insert>
|
| 61 |
+
[ZzDummy_bindings]
|
| 62 |
+
z-out= <Control-Shift-KeyRelease-Delete>
|
evalkit_cambrian/lib/python3.10/idlelib/config-highlight.def
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle highlight theme settings.
|
| 3 |
+
|
| 4 |
+
[IDLE Classic]
|
| 5 |
+
normal-foreground= #000000
|
| 6 |
+
normal-background= #ffffff
|
| 7 |
+
keyword-foreground= #ff7700
|
| 8 |
+
keyword-background= #ffffff
|
| 9 |
+
builtin-foreground= #900090
|
| 10 |
+
builtin-background= #ffffff
|
| 11 |
+
comment-foreground= #dd0000
|
| 12 |
+
comment-background= #ffffff
|
| 13 |
+
string-foreground= #00aa00
|
| 14 |
+
string-background= #ffffff
|
| 15 |
+
definition-foreground= #0000ff
|
| 16 |
+
definition-background= #ffffff
|
| 17 |
+
hilite-foreground= #000000
|
| 18 |
+
hilite-background= gray
|
| 19 |
+
break-foreground= black
|
| 20 |
+
break-background= #ffff55
|
| 21 |
+
hit-foreground= #ffffff
|
| 22 |
+
hit-background= #000000
|
| 23 |
+
error-foreground= #000000
|
| 24 |
+
error-background= #ff7777
|
| 25 |
+
context-foreground= #000000
|
| 26 |
+
context-background= lightgray
|
| 27 |
+
linenumber-foreground= gray
|
| 28 |
+
linenumber-background= #ffffff
|
| 29 |
+
#cursor (only foreground can be set, restart IDLE)
|
| 30 |
+
cursor-foreground= black
|
| 31 |
+
#shell window
|
| 32 |
+
stdout-foreground= blue
|
| 33 |
+
stdout-background= #ffffff
|
| 34 |
+
stderr-foreground= red
|
| 35 |
+
stderr-background= #ffffff
|
| 36 |
+
console-foreground= #770000
|
| 37 |
+
console-background= #ffffff
|
| 38 |
+
|
| 39 |
+
[IDLE New]
|
| 40 |
+
normal-foreground= #000000
|
| 41 |
+
normal-background= #ffffff
|
| 42 |
+
keyword-foreground= #ff7700
|
| 43 |
+
keyword-background= #ffffff
|
| 44 |
+
builtin-foreground= #900090
|
| 45 |
+
builtin-background= #ffffff
|
| 46 |
+
comment-foreground= #dd0000
|
| 47 |
+
comment-background= #ffffff
|
| 48 |
+
string-foreground= #00aa00
|
| 49 |
+
string-background= #ffffff
|
| 50 |
+
definition-foreground= #0000ff
|
| 51 |
+
definition-background= #ffffff
|
| 52 |
+
hilite-foreground= #000000
|
| 53 |
+
hilite-background= gray
|
| 54 |
+
break-foreground= black
|
| 55 |
+
break-background= #ffff55
|
| 56 |
+
hit-foreground= #ffffff
|
| 57 |
+
hit-background= #000000
|
| 58 |
+
error-foreground= #000000
|
| 59 |
+
error-background= #ff7777
|
| 60 |
+
context-foreground= #000000
|
| 61 |
+
context-background= lightgray
|
| 62 |
+
linenumber-foreground= gray
|
| 63 |
+
linenumber-background= #ffffff
|
| 64 |
+
#cursor (only foreground can be set, restart IDLE)
|
| 65 |
+
cursor-foreground= black
|
| 66 |
+
#shell window
|
| 67 |
+
stdout-foreground= blue
|
| 68 |
+
stdout-background= #ffffff
|
| 69 |
+
stderr-foreground= red
|
| 70 |
+
stderr-background= #ffffff
|
| 71 |
+
console-foreground= #770000
|
| 72 |
+
console-background= #ffffff
|
| 73 |
+
|
| 74 |
+
[IDLE Dark]
|
| 75 |
+
comment-foreground = #dd0000
|
| 76 |
+
console-foreground = #ff4d4d
|
| 77 |
+
error-foreground = #FFFFFF
|
| 78 |
+
hilite-background = #7e7e7e
|
| 79 |
+
string-foreground = #02ff02
|
| 80 |
+
stderr-background = #002240
|
| 81 |
+
stderr-foreground = #ffb3b3
|
| 82 |
+
console-background = #002240
|
| 83 |
+
hit-background = #fbfbfb
|
| 84 |
+
string-background = #002240
|
| 85 |
+
normal-background = #002240
|
| 86 |
+
hilite-foreground = #FFFFFF
|
| 87 |
+
keyword-foreground = #ff8000
|
| 88 |
+
error-background = #c86464
|
| 89 |
+
keyword-background = #002240
|
| 90 |
+
builtin-background = #002240
|
| 91 |
+
break-background = #808000
|
| 92 |
+
builtin-foreground = #ff00ff
|
| 93 |
+
definition-foreground = #5e5eff
|
| 94 |
+
stdout-foreground = #c2d1fa
|
| 95 |
+
definition-background = #002240
|
| 96 |
+
normal-foreground = #FFFFFF
|
| 97 |
+
cursor-foreground = #ffffff
|
| 98 |
+
stdout-background = #002240
|
| 99 |
+
hit-foreground = #002240
|
| 100 |
+
comment-background = #002240
|
| 101 |
+
break-foreground = #FFFFFF
|
| 102 |
+
context-foreground= #ffffff
|
| 103 |
+
context-background= #454545
|
| 104 |
+
linenumber-foreground= gray
|
| 105 |
+
linenumber-background= #002240
|
evalkit_cambrian/lib/python3.10/idlelib/config-keys.def
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle key binding settings.
|
| 3 |
+
# Where multiple keys are specified for an action: if they are separated
|
| 4 |
+
# by a space (eg. action=<key1> <key2>) then the keys are alternatives, if
|
| 5 |
+
# there is no space (eg. action=<key1><key2>) then the keys comprise a
|
| 6 |
+
# single 'emacs style' multi-keystoke binding. The tk event specifier 'Key'
|
| 7 |
+
# is used in all cases, for consistency in auto key conflict checking in the
|
| 8 |
+
# configuration gui.
|
| 9 |
+
|
| 10 |
+
[IDLE Classic Windows]
|
| 11 |
+
copy=<Control-Key-c> <Control-Key-C>
|
| 12 |
+
cut=<Control-Key-x> <Control-Key-X>
|
| 13 |
+
paste=<Control-Key-v> <Control-Key-V>
|
| 14 |
+
beginning-of-line= <Key-Home>
|
| 15 |
+
center-insert=<Control-Key-l> <Control-Key-L>
|
| 16 |
+
close-all-windows=<Control-Key-q> <Control-Key-Q>
|
| 17 |
+
close-window=<Alt-Key-F4> <Meta-Key-F4>
|
| 18 |
+
do-nothing=<Control-Key-F12>
|
| 19 |
+
end-of-file=<Control-Key-d> <Control-Key-D>
|
| 20 |
+
python-docs=<Key-F1>
|
| 21 |
+
python-context-help=<Shift-Key-F1>
|
| 22 |
+
history-next=<Alt-Key-n> <Meta-Key-n> <Alt-Key-N> <Meta-Key-N>
|
| 23 |
+
history-previous=<Alt-Key-p> <Meta-Key-p> <Alt-Key-P> <Meta-Key-P>
|
| 24 |
+
interrupt-execution=<Control-Key-c> <Control-Key-C>
|
| 25 |
+
view-restart=<Key-F6>
|
| 26 |
+
restart-shell=<Control-Key-F6>
|
| 27 |
+
open-class-browser=<Alt-Key-c> <Meta-Key-c> <Alt-Key-C> <Meta-Key-C>
|
| 28 |
+
open-module=<Alt-Key-m> <Meta-Key-m> <Alt-Key-M> <Meta-Key-M>
|
| 29 |
+
open-new-window=<Control-Key-n> <Control-Key-N>
|
| 30 |
+
open-window-from-file=<Control-Key-o> <Control-Key-O>
|
| 31 |
+
plain-newline-and-indent=<Control-Key-j> <Control-Key-J>
|
| 32 |
+
print-window=<Control-Key-p> <Control-Key-P>
|
| 33 |
+
redo=<Control-Shift-Key-Z> <Control-Shift-Key-z>
|
| 34 |
+
remove-selection=<Key-Escape>
|
| 35 |
+
save-copy-of-window-as-file=<Alt-Shift-Key-S> <Alt-Shift-Key-s>
|
| 36 |
+
save-window-as-file=<Control-Shift-Key-S> <Control-Shift-Key-s>
|
| 37 |
+
save-window=<Control-Key-s> <Control-Key-S>
|
| 38 |
+
select-all=<Control-Key-a> <Control-Key-A>
|
| 39 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 40 |
+
undo=<Control-Key-z> <Control-Key-Z>
|
| 41 |
+
find=<Control-Key-f> <Control-Key-F>
|
| 42 |
+
find-again=<Control-Key-g> <Key-F3> <Control-Key-G>
|
| 43 |
+
find-in-files=<Alt-Key-F3> <Meta-Key-F3>
|
| 44 |
+
find-selection=<Control-Key-F3>
|
| 45 |
+
replace=<Control-Key-h> <Control-Key-H>
|
| 46 |
+
goto-line=<Alt-Key-g> <Meta-Key-g> <Alt-Key-G> <Meta-Key-G>
|
| 47 |
+
smart-backspace=<Key-BackSpace>
|
| 48 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 49 |
+
smart-indent=<Key-Tab>
|
| 50 |
+
indent-region=<Control-Key-bracketright>
|
| 51 |
+
dedent-region=<Control-Key-bracketleft>
|
| 52 |
+
comment-region=<Alt-Key-3> <Meta-Key-3>
|
| 53 |
+
uncomment-region=<Alt-Key-4> <Meta-Key-4>
|
| 54 |
+
tabify-region=<Alt-Key-5> <Meta-Key-5>
|
| 55 |
+
untabify-region=<Alt-Key-6> <Meta-Key-6>
|
| 56 |
+
toggle-tabs=<Alt-Key-t> <Meta-Key-t> <Alt-Key-T> <Meta-Key-T>
|
| 57 |
+
change-indentwidth=<Alt-Key-u> <Meta-Key-u> <Alt-Key-U> <Meta-Key-U>
|
| 58 |
+
del-word-left=<Control-Key-BackSpace>
|
| 59 |
+
del-word-right=<Control-Key-Delete>
|
| 60 |
+
force-open-completions= <Control-Key-space>
|
| 61 |
+
expand-word= <Alt-Key-slash>
|
| 62 |
+
force-open-calltip= <Control-Key-backslash>
|
| 63 |
+
format-paragraph= <Alt-Key-q>
|
| 64 |
+
flash-paren= <Control-Key-0>
|
| 65 |
+
run-module= <Key-F5>
|
| 66 |
+
run-custom= <Shift-Key-F5>
|
| 67 |
+
check-module= <Alt-Key-x>
|
| 68 |
+
zoom-height= <Alt-Key-2>
|
| 69 |
+
|
| 70 |
+
[IDLE Classic Unix]
|
| 71 |
+
copy=<Alt-Key-w> <Meta-Key-w>
|
| 72 |
+
cut=<Control-Key-w>
|
| 73 |
+
paste=<Control-Key-y>
|
| 74 |
+
beginning-of-line=<Control-Key-a> <Key-Home>
|
| 75 |
+
center-insert=<Control-Key-l>
|
| 76 |
+
close-all-windows=<Control-Key-x><Control-Key-c>
|
| 77 |
+
close-window=<Control-Key-x><Control-Key-0>
|
| 78 |
+
do-nothing=<Control-Key-x>
|
| 79 |
+
end-of-file=<Control-Key-d>
|
| 80 |
+
history-next=<Alt-Key-n> <Meta-Key-n>
|
| 81 |
+
history-previous=<Alt-Key-p> <Meta-Key-p>
|
| 82 |
+
interrupt-execution=<Control-Key-c>
|
| 83 |
+
view-restart=<Key-F6>
|
| 84 |
+
restart-shell=<Control-Key-F6>
|
| 85 |
+
open-class-browser=<Control-Key-x><Control-Key-b>
|
| 86 |
+
open-module=<Control-Key-x><Control-Key-m>
|
| 87 |
+
open-new-window=<Control-Key-x><Control-Key-n>
|
| 88 |
+
open-window-from-file=<Control-Key-x><Control-Key-f>
|
| 89 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 90 |
+
print-window=<Control-x><Control-Key-p>
|
| 91 |
+
python-docs=<Control-Key-h>
|
| 92 |
+
python-context-help=<Control-Shift-Key-H>
|
| 93 |
+
redo=<Alt-Key-z> <Meta-Key-z>
|
| 94 |
+
remove-selection=<Key-Escape>
|
| 95 |
+
save-copy-of-window-as-file=<Control-Key-x><Control-Key-y>
|
| 96 |
+
save-window-as-file=<Control-Key-x><Control-Key-w>
|
| 97 |
+
save-window=<Control-Key-x><Control-Key-s>
|
| 98 |
+
select-all=<Alt-Key-a> <Meta-Key-a>
|
| 99 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 100 |
+
undo=<Control-Key-z>
|
| 101 |
+
find=<Control-Key-u><Control-Key-u><Control-Key-s>
|
| 102 |
+
find-again=<Control-Key-u><Control-Key-s>
|
| 103 |
+
find-in-files=<Alt-Key-s> <Meta-Key-s>
|
| 104 |
+
find-selection=<Control-Key-s>
|
| 105 |
+
replace=<Control-Key-r>
|
| 106 |
+
goto-line=<Alt-Key-g> <Meta-Key-g>
|
| 107 |
+
smart-backspace=<Key-BackSpace>
|
| 108 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 109 |
+
smart-indent=<Key-Tab>
|
| 110 |
+
indent-region=<Control-Key-bracketright>
|
| 111 |
+
dedent-region=<Control-Key-bracketleft>
|
| 112 |
+
comment-region=<Alt-Key-3>
|
| 113 |
+
uncomment-region=<Alt-Key-4>
|
| 114 |
+
tabify-region=<Alt-Key-5>
|
| 115 |
+
untabify-region=<Alt-Key-6>
|
| 116 |
+
toggle-tabs=<Alt-Key-t>
|
| 117 |
+
change-indentwidth=<Alt-Key-u>
|
| 118 |
+
del-word-left=<Alt-Key-BackSpace>
|
| 119 |
+
del-word-right=<Alt-Key-d>
|
| 120 |
+
force-open-completions= <Control-Key-space>
|
| 121 |
+
expand-word= <Alt-Key-slash>
|
| 122 |
+
force-open-calltip= <Control-Key-backslash>
|
| 123 |
+
format-paragraph= <Alt-Key-q>
|
| 124 |
+
flash-paren= <Control-Key-0>
|
| 125 |
+
run-module= <Key-F5>
|
| 126 |
+
run-custom= <Shift-Key-F5>
|
| 127 |
+
check-module= <Alt-Key-x>
|
| 128 |
+
zoom-height= <Alt-Key-2>
|
| 129 |
+
|
| 130 |
+
[IDLE Modern Unix]
|
| 131 |
+
copy = <Control-Shift-Key-C> <Control-Key-Insert>
|
| 132 |
+
cut = <Control-Key-x> <Shift-Key-Delete>
|
| 133 |
+
paste = <Control-Key-v> <Shift-Key-Insert>
|
| 134 |
+
beginning-of-line = <Key-Home>
|
| 135 |
+
center-insert = <Control-Key-l>
|
| 136 |
+
close-all-windows = <Control-Key-q>
|
| 137 |
+
close-window = <Control-Key-w> <Control-Shift-Key-W>
|
| 138 |
+
do-nothing = <Control-Key-F12>
|
| 139 |
+
end-of-file = <Control-Key-d>
|
| 140 |
+
history-next = <Alt-Key-n> <Meta-Key-n>
|
| 141 |
+
history-previous = <Alt-Key-p> <Meta-Key-p>
|
| 142 |
+
interrupt-execution = <Control-Key-c>
|
| 143 |
+
view-restart = <Key-F6>
|
| 144 |
+
restart-shell = <Control-Key-F6>
|
| 145 |
+
open-class-browser = <Control-Key-b>
|
| 146 |
+
open-module = <Control-Key-m>
|
| 147 |
+
open-new-window = <Control-Key-n>
|
| 148 |
+
open-window-from-file = <Control-Key-o>
|
| 149 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 150 |
+
print-window = <Control-Key-p>
|
| 151 |
+
python-context-help = <Shift-Key-F1>
|
| 152 |
+
python-docs = <Key-F1>
|
| 153 |
+
redo = <Control-Shift-Key-Z>
|
| 154 |
+
remove-selection = <Key-Escape>
|
| 155 |
+
save-copy-of-window-as-file = <Alt-Shift-Key-S>
|
| 156 |
+
save-window-as-file = <Control-Shift-Key-S>
|
| 157 |
+
save-window = <Control-Key-s>
|
| 158 |
+
select-all = <Control-Key-a>
|
| 159 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 160 |
+
undo = <Control-Key-z>
|
| 161 |
+
find = <Control-Key-f>
|
| 162 |
+
find-again = <Key-F3>
|
| 163 |
+
find-in-files = <Control-Shift-Key-f>
|
| 164 |
+
find-selection = <Control-Key-h>
|
| 165 |
+
replace = <Control-Key-r>
|
| 166 |
+
goto-line = <Control-Key-g>
|
| 167 |
+
smart-backspace = <Key-BackSpace>
|
| 168 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 169 |
+
smart-indent = <Key-Tab>
|
| 170 |
+
indent-region = <Control-Key-bracketright>
|
| 171 |
+
dedent-region = <Control-Key-bracketleft>
|
| 172 |
+
comment-region = <Control-Key-d>
|
| 173 |
+
uncomment-region = <Control-Shift-Key-D>
|
| 174 |
+
tabify-region = <Alt-Key-5>
|
| 175 |
+
untabify-region = <Alt-Key-6>
|
| 176 |
+
toggle-tabs = <Control-Key-T>
|
| 177 |
+
change-indentwidth = <Alt-Key-u>
|
| 178 |
+
del-word-left = <Control-Key-BackSpace>
|
| 179 |
+
del-word-right = <Control-Key-Delete>
|
| 180 |
+
force-open-completions= <Control-Key-space>
|
| 181 |
+
expand-word= <Alt-Key-slash>
|
| 182 |
+
force-open-calltip= <Control-Key-backslash>
|
| 183 |
+
format-paragraph= <Alt-Key-q>
|
| 184 |
+
flash-paren= <Control-Key-0>
|
| 185 |
+
run-module= <Key-F5>
|
| 186 |
+
run-custom= <Shift-Key-F5>
|
| 187 |
+
check-module= <Alt-Key-x>
|
| 188 |
+
zoom-height= <Alt-Key-2>
|
| 189 |
+
|
| 190 |
+
[IDLE Classic Mac]
|
| 191 |
+
copy=<Command-Key-c>
|
| 192 |
+
cut=<Command-Key-x>
|
| 193 |
+
paste=<Command-Key-v>
|
| 194 |
+
beginning-of-line= <Key-Home>
|
| 195 |
+
center-insert=<Control-Key-l>
|
| 196 |
+
close-all-windows=<Command-Key-q>
|
| 197 |
+
close-window=<Command-Key-w>
|
| 198 |
+
do-nothing=<Control-Key-F12>
|
| 199 |
+
end-of-file=<Control-Key-d>
|
| 200 |
+
python-docs=<Key-F1>
|
| 201 |
+
python-context-help=<Shift-Key-F1>
|
| 202 |
+
history-next=<Control-Key-n>
|
| 203 |
+
history-previous=<Control-Key-p>
|
| 204 |
+
interrupt-execution=<Control-Key-c>
|
| 205 |
+
view-restart=<Key-F6>
|
| 206 |
+
restart-shell=<Control-Key-F6>
|
| 207 |
+
open-class-browser=<Command-Key-b>
|
| 208 |
+
open-module=<Command-Key-m>
|
| 209 |
+
open-new-window=<Command-Key-n>
|
| 210 |
+
open-window-from-file=<Command-Key-o>
|
| 211 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 212 |
+
print-window=<Command-Key-p>
|
| 213 |
+
redo=<Shift-Command-Key-Z>
|
| 214 |
+
remove-selection=<Key-Escape>
|
| 215 |
+
save-window-as-file=<Shift-Command-Key-S>
|
| 216 |
+
save-window=<Command-Key-s>
|
| 217 |
+
save-copy-of-window-as-file=<Option-Command-Key-s>
|
| 218 |
+
select-all=<Command-Key-a>
|
| 219 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 220 |
+
undo=<Command-Key-z>
|
| 221 |
+
find=<Command-Key-f>
|
| 222 |
+
find-again=<Command-Key-g> <Key-F3>
|
| 223 |
+
find-in-files=<Command-Key-F3>
|
| 224 |
+
find-selection=<Shift-Command-Key-F3>
|
| 225 |
+
replace=<Command-Key-r>
|
| 226 |
+
goto-line=<Command-Key-j>
|
| 227 |
+
smart-backspace=<Key-BackSpace>
|
| 228 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 229 |
+
smart-indent=<Key-Tab>
|
| 230 |
+
indent-region=<Command-Key-bracketright>
|
| 231 |
+
dedent-region=<Command-Key-bracketleft>
|
| 232 |
+
comment-region=<Control-Key-3>
|
| 233 |
+
uncomment-region=<Control-Key-4>
|
| 234 |
+
tabify-region=<Control-Key-5>
|
| 235 |
+
untabify-region=<Control-Key-6>
|
| 236 |
+
toggle-tabs=<Control-Key-t>
|
| 237 |
+
change-indentwidth=<Control-Key-u>
|
| 238 |
+
del-word-left=<Control-Key-BackSpace>
|
| 239 |
+
del-word-right=<Control-Key-Delete>
|
| 240 |
+
force-open-completions= <Control-Key-space>
|
| 241 |
+
expand-word= <Option-Key-slash>
|
| 242 |
+
force-open-calltip= <Control-Key-backslash>
|
| 243 |
+
format-paragraph= <Option-Key-q>
|
| 244 |
+
flash-paren= <Control-Key-0>
|
| 245 |
+
run-module= <Key-F5>
|
| 246 |
+
run-custom= <Shift-Key-F5>
|
| 247 |
+
check-module= <Option-Key-x>
|
| 248 |
+
zoom-height= <Option-Key-0>
|
| 249 |
+
|
| 250 |
+
[IDLE Classic OSX]
|
| 251 |
+
toggle-tabs = <Control-Key-t>
|
| 252 |
+
interrupt-execution = <Control-Key-c>
|
| 253 |
+
untabify-region = <Control-Key-6>
|
| 254 |
+
remove-selection = <Key-Escape>
|
| 255 |
+
print-window = <Command-Key-p>
|
| 256 |
+
replace = <Command-Key-r>
|
| 257 |
+
goto-line = <Command-Key-j>
|
| 258 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 259 |
+
history-previous = <Control-Key-p>
|
| 260 |
+
beginning-of-line = <Control-Key-Left>
|
| 261 |
+
end-of-line = <Control-Key-Right>
|
| 262 |
+
comment-region = <Control-Key-3>
|
| 263 |
+
redo = <Shift-Command-Key-Z>
|
| 264 |
+
close-window = <Command-Key-w>
|
| 265 |
+
restart-shell = <Control-Key-F6>
|
| 266 |
+
save-window-as-file = <Shift-Command-Key-S>
|
| 267 |
+
close-all-windows = <Command-Key-q>
|
| 268 |
+
view-restart = <Key-F6>
|
| 269 |
+
tabify-region = <Control-Key-5>
|
| 270 |
+
find-again = <Command-Key-g> <Key-F3>
|
| 271 |
+
find = <Command-Key-f>
|
| 272 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 273 |
+
select-all = <Command-Key-a>
|
| 274 |
+
smart-backspace = <Key-BackSpace>
|
| 275 |
+
change-indentwidth = <Control-Key-u>
|
| 276 |
+
do-nothing = <Control-Key-F12>
|
| 277 |
+
smart-indent = <Key-Tab>
|
| 278 |
+
center-insert = <Control-Key-l>
|
| 279 |
+
history-next = <Control-Key-n>
|
| 280 |
+
del-word-right = <Option-Key-Delete>
|
| 281 |
+
undo = <Command-Key-z>
|
| 282 |
+
save-window = <Command-Key-s>
|
| 283 |
+
uncomment-region = <Control-Key-4>
|
| 284 |
+
cut = <Command-Key-x>
|
| 285 |
+
find-in-files = <Command-Key-F3>
|
| 286 |
+
dedent-region = <Command-Key-bracketleft>
|
| 287 |
+
copy = <Command-Key-c>
|
| 288 |
+
paste = <Command-Key-v>
|
| 289 |
+
indent-region = <Command-Key-bracketright>
|
| 290 |
+
del-word-left = <Option-Key-BackSpace> <Option-Command-Key-BackSpace>
|
| 291 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 292 |
+
end-of-file = <Control-Key-d>
|
| 293 |
+
open-class-browser = <Command-Key-b>
|
| 294 |
+
open-new-window = <Command-Key-n>
|
| 295 |
+
open-module = <Command-Key-m>
|
| 296 |
+
find-selection = <Shift-Command-Key-F3>
|
| 297 |
+
python-context-help = <Shift-Key-F1>
|
| 298 |
+
save-copy-of-window-as-file = <Option-Command-Key-s>
|
| 299 |
+
open-window-from-file = <Command-Key-o>
|
| 300 |
+
python-docs = <Key-F1>
|
| 301 |
+
force-open-completions= <Control-Key-space>
|
| 302 |
+
expand-word= <Option-Key-slash>
|
| 303 |
+
force-open-calltip= <Control-Key-backslash>
|
| 304 |
+
format-paragraph= <Option-Key-q>
|
| 305 |
+
flash-paren= <Control-Key-0>
|
| 306 |
+
run-module= <Key-F5>
|
| 307 |
+
run-custom= <Shift-Key-F5>
|
| 308 |
+
check-module= <Option-Key-x>
|
| 309 |
+
zoom-height= <Option-Key-0>
|
evalkit_cambrian/lib/python3.10/idlelib/config-main.def
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for general idle settings.
|
| 3 |
+
#
|
| 4 |
+
# When IDLE starts, it will look in
|
| 5 |
+
# the following two sets of files, in order:
|
| 6 |
+
#
|
| 7 |
+
# default configuration files in idlelib
|
| 8 |
+
# --------------------------------------
|
| 9 |
+
# config-main.def default general config file
|
| 10 |
+
# config-extensions.def default extension config file
|
| 11 |
+
# config-highlight.def default highlighting config file
|
| 12 |
+
# config-keys.def default keybinding config file
|
| 13 |
+
#
|
| 14 |
+
# user configuration files in ~/.idlerc
|
| 15 |
+
# -------------------------------------
|
| 16 |
+
# config-main.cfg user general config file
|
| 17 |
+
# config-extensions.cfg user extension config file
|
| 18 |
+
# config-highlight.cfg user highlighting config file
|
| 19 |
+
# config-keys.cfg user keybinding config file
|
| 20 |
+
#
|
| 21 |
+
# On Windows, the default location of the home directory ('~' above)
|
| 22 |
+
# depends on the version. For Windows 10, it is C:\Users\<username>.
|
| 23 |
+
#
|
| 24 |
+
# Any options the user saves through the config dialog will be saved to
|
| 25 |
+
# the relevant user config file. Reverting any general or extension
|
| 26 |
+
# setting to the default causes that entry to be wiped from the user
|
| 27 |
+
# file and re-read from the default file. This rule applies to each
|
| 28 |
+
# item, except that the three editor font items are saved as a group.
|
| 29 |
+
#
|
| 30 |
+
# User highlighting themes and keybinding sets must have (section) names
|
| 31 |
+
# distinct from the default names. All items are added and saved as a
|
| 32 |
+
# group. They are retained unless specifically deleted within the config
|
| 33 |
+
# dialog. Choosing one of the default themes or keysets just applies the
|
| 34 |
+
# relevant settings from the default file.
|
| 35 |
+
#
|
| 36 |
+
# Additional help sources are listed in the [HelpFiles] section below
|
| 37 |
+
# and should be viewable by a web browser (or the Windows Help viewer in
|
| 38 |
+
# the case of .chm files). These sources will be listed on the Help
|
| 39 |
+
# menu. The pattern, and two examples, are:
|
| 40 |
+
#
|
| 41 |
+
# <sequence_number = menu item;/path/to/help/source>
|
| 42 |
+
# 1 = IDLE;C:/Programs/Python36/Lib/idlelib/help.html
|
| 43 |
+
# 2 = Pillow;https://pillow.readthedocs.io/en/latest/
|
| 44 |
+
#
|
| 45 |
+
# You can't use a semi-colon in a menu item or path. The path will be
|
| 46 |
+
# platform specific because of path separators, drive specs etc.
|
| 47 |
+
#
|
| 48 |
+
# The default files should not be edited except to add new sections to
|
| 49 |
+
# config-extensions.def for added extensions. The user files should be
|
| 50 |
+
# modified through the Settings dialog.
|
| 51 |
+
|
| 52 |
+
[General]
|
| 53 |
+
editor-on-startup= 0
|
| 54 |
+
autosave= 0
|
| 55 |
+
print-command-posix=lpr %%s
|
| 56 |
+
print-command-win=start /min notepad /p %%s
|
| 57 |
+
delete-exitfunc= 1
|
| 58 |
+
|
| 59 |
+
[EditorWindow]
|
| 60 |
+
width= 80
|
| 61 |
+
height= 40
|
| 62 |
+
cursor-blink= 1
|
| 63 |
+
font= TkFixedFont
|
| 64 |
+
# For TkFixedFont, the actual size and boldness are obtained from tk
|
| 65 |
+
# and override 10 and 0. See idlelib.config.IdleConf.GetFont
|
| 66 |
+
font-size= 10
|
| 67 |
+
font-bold= 0
|
| 68 |
+
encoding= none
|
| 69 |
+
line-numbers-default= 0
|
| 70 |
+
|
| 71 |
+
[PyShell]
|
| 72 |
+
auto-squeeze-min-lines= 50
|
| 73 |
+
|
| 74 |
+
[Indent]
|
| 75 |
+
use-spaces= 1
|
| 76 |
+
num-spaces= 4
|
| 77 |
+
|
| 78 |
+
[Theme]
|
| 79 |
+
default= 1
|
| 80 |
+
name= IDLE Classic
|
| 81 |
+
name2=
|
| 82 |
+
# name2 set in user config-main.cfg for themes added after 2015 Oct 1
|
| 83 |
+
|
| 84 |
+
[Keys]
|
| 85 |
+
default= 1
|
| 86 |
+
name=
|
| 87 |
+
name2=
|
| 88 |
+
# name2 set in user config-main.cfg for keys added after 2016 July 1
|
| 89 |
+
|
| 90 |
+
[History]
|
| 91 |
+
cyclic=1
|
| 92 |
+
|
| 93 |
+
[HelpFiles]
|
evalkit_cambrian/lib/python3.10/idlelib/config_key.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Dialog for building Tkinter accelerator key bindings
|
| 3 |
+
"""
|
| 4 |
+
from tkinter import Toplevel, Listbox, StringVar, TclError
|
| 5 |
+
from tkinter.ttk import Frame, Button, Checkbutton, Entry, Label, Scrollbar
|
| 6 |
+
from tkinter import messagebox
|
| 7 |
+
from tkinter.simpledialog import _setup_dialog
|
| 8 |
+
import string
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
FUNCTION_KEYS = ('F1', 'F2' ,'F3' ,'F4' ,'F5' ,'F6',
|
| 13 |
+
'F7', 'F8' ,'F9' ,'F10' ,'F11' ,'F12')
|
| 14 |
+
ALPHANUM_KEYS = tuple(string.ascii_lowercase + string.digits)
|
| 15 |
+
PUNCTUATION_KEYS = tuple('~!@#%^&*()_-+={}[]|;:,.<>/?')
|
| 16 |
+
WHITESPACE_KEYS = ('Tab', 'Space', 'Return')
|
| 17 |
+
EDIT_KEYS = ('BackSpace', 'Delete', 'Insert')
|
| 18 |
+
MOVE_KEYS = ('Home', 'End', 'Page Up', 'Page Down', 'Left Arrow',
|
| 19 |
+
'Right Arrow', 'Up Arrow', 'Down Arrow')
|
| 20 |
+
AVAILABLE_KEYS = (ALPHANUM_KEYS + PUNCTUATION_KEYS + FUNCTION_KEYS +
|
| 21 |
+
WHITESPACE_KEYS + EDIT_KEYS + MOVE_KEYS)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def translate_key(key, modifiers):
|
| 25 |
+
"Translate from keycap symbol to the Tkinter keysym."
|
| 26 |
+
mapping = {'Space':'space',
|
| 27 |
+
'~':'asciitilde', '!':'exclam', '@':'at', '#':'numbersign',
|
| 28 |
+
'%':'percent', '^':'asciicircum', '&':'ampersand',
|
| 29 |
+
'*':'asterisk', '(':'parenleft', ')':'parenright',
|
| 30 |
+
'_':'underscore', '-':'minus', '+':'plus', '=':'equal',
|
| 31 |
+
'{':'braceleft', '}':'braceright',
|
| 32 |
+
'[':'bracketleft', ']':'bracketright', '|':'bar',
|
| 33 |
+
';':'semicolon', ':':'colon', ',':'comma', '.':'period',
|
| 34 |
+
'<':'less', '>':'greater', '/':'slash', '?':'question',
|
| 35 |
+
'Page Up':'Prior', 'Page Down':'Next',
|
| 36 |
+
'Left Arrow':'Left', 'Right Arrow':'Right',
|
| 37 |
+
'Up Arrow':'Up', 'Down Arrow': 'Down', 'Tab':'Tab'}
|
| 38 |
+
key = mapping.get(key, key)
|
| 39 |
+
if 'Shift' in modifiers and key in string.ascii_lowercase:
|
| 40 |
+
key = key.upper()
|
| 41 |
+
return f'Key-{key}'
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class GetKeysFrame(Frame):
|
| 45 |
+
|
| 46 |
+
# Dialog title for invalid key sequence
|
| 47 |
+
keyerror_title = 'Key Sequence Error'
|
| 48 |
+
|
| 49 |
+
def __init__(self, parent, action, current_key_sequences):
|
| 50 |
+
"""
|
| 51 |
+
parent - parent of this dialog
|
| 52 |
+
action - the name of the virtual event these keys will be
|
| 53 |
+
mapped to
|
| 54 |
+
current_key_sequences - a list of all key sequence lists
|
| 55 |
+
currently mapped to virtual events, for overlap checking
|
| 56 |
+
"""
|
| 57 |
+
super().__init__(parent)
|
| 58 |
+
self['borderwidth'] = 2
|
| 59 |
+
self['relief'] = 'sunken'
|
| 60 |
+
self.parent = parent
|
| 61 |
+
self.action = action
|
| 62 |
+
self.current_key_sequences = current_key_sequences
|
| 63 |
+
self.result = ''
|
| 64 |
+
self.key_string = StringVar(self)
|
| 65 |
+
self.key_string.set('')
|
| 66 |
+
# Set self.modifiers, self.modifier_label.
|
| 67 |
+
self.set_modifiers_for_platform()
|
| 68 |
+
self.modifier_vars = []
|
| 69 |
+
for modifier in self.modifiers:
|
| 70 |
+
variable = StringVar(self)
|
| 71 |
+
variable.set('')
|
| 72 |
+
self.modifier_vars.append(variable)
|
| 73 |
+
self.advanced = False
|
| 74 |
+
self.create_widgets()
|
| 75 |
+
|
| 76 |
+
def showerror(self, *args, **kwargs):
|
| 77 |
+
# Make testing easier. Replace in #30751.
|
| 78 |
+
messagebox.showerror(*args, **kwargs)
|
| 79 |
+
|
| 80 |
+
def create_widgets(self):
|
| 81 |
+
# Basic entry key sequence.
|
| 82 |
+
self.frame_keyseq_basic = Frame(self, name='keyseq_basic')
|
| 83 |
+
self.frame_keyseq_basic.grid(row=0, column=0, sticky='nsew',
|
| 84 |
+
padx=5, pady=5)
|
| 85 |
+
basic_title = Label(self.frame_keyseq_basic,
|
| 86 |
+
text=f"New keys for '{self.action}' :")
|
| 87 |
+
basic_title.pack(anchor='w')
|
| 88 |
+
|
| 89 |
+
basic_keys = Label(self.frame_keyseq_basic, justify='left',
|
| 90 |
+
textvariable=self.key_string, relief='groove',
|
| 91 |
+
borderwidth=2)
|
| 92 |
+
basic_keys.pack(ipadx=5, ipady=5, fill='x')
|
| 93 |
+
|
| 94 |
+
# Basic entry controls.
|
| 95 |
+
self.frame_controls_basic = Frame(self)
|
| 96 |
+
self.frame_controls_basic.grid(row=1, column=0, sticky='nsew', padx=5)
|
| 97 |
+
|
| 98 |
+
# Basic entry modifiers.
|
| 99 |
+
self.modifier_checkbuttons = {}
|
| 100 |
+
column = 0
|
| 101 |
+
for modifier, variable in zip(self.modifiers, self.modifier_vars):
|
| 102 |
+
label = self.modifier_label.get(modifier, modifier)
|
| 103 |
+
check = Checkbutton(self.frame_controls_basic,
|
| 104 |
+
command=self.build_key_string, text=label,
|
| 105 |
+
variable=variable, onvalue=modifier, offvalue='')
|
| 106 |
+
check.grid(row=0, column=column, padx=2, sticky='w')
|
| 107 |
+
self.modifier_checkbuttons[modifier] = check
|
| 108 |
+
column += 1
|
| 109 |
+
|
| 110 |
+
# Basic entry help text.
|
| 111 |
+
help_basic = Label(self.frame_controls_basic, justify='left',
|
| 112 |
+
text="Select the desired modifier keys\n"+
|
| 113 |
+
"above, and the final key from the\n"+
|
| 114 |
+
"list on the right.\n\n" +
|
| 115 |
+
"Use upper case Symbols when using\n" +
|
| 116 |
+
"the Shift modifier. (Letters will be\n" +
|
| 117 |
+
"converted automatically.)")
|
| 118 |
+
help_basic.grid(row=1, column=0, columnspan=4, padx=2, sticky='w')
|
| 119 |
+
|
| 120 |
+
# Basic entry key list.
|
| 121 |
+
self.list_keys_final = Listbox(self.frame_controls_basic, width=15,
|
| 122 |
+
height=10, selectmode='single')
|
| 123 |
+
self.list_keys_final.insert('end', *AVAILABLE_KEYS)
|
| 124 |
+
self.list_keys_final.bind('<ButtonRelease-1>', self.final_key_selected)
|
| 125 |
+
self.list_keys_final.grid(row=0, column=4, rowspan=4, sticky='ns')
|
| 126 |
+
scroll_keys_final = Scrollbar(self.frame_controls_basic,
|
| 127 |
+
orient='vertical',
|
| 128 |
+
command=self.list_keys_final.yview)
|
| 129 |
+
self.list_keys_final.config(yscrollcommand=scroll_keys_final.set)
|
| 130 |
+
scroll_keys_final.grid(row=0, column=5, rowspan=4, sticky='ns')
|
| 131 |
+
self.button_clear = Button(self.frame_controls_basic,
|
| 132 |
+
text='Clear Keys',
|
| 133 |
+
command=self.clear_key_seq)
|
| 134 |
+
self.button_clear.grid(row=2, column=0, columnspan=4)
|
| 135 |
+
|
| 136 |
+
# Advanced entry key sequence.
|
| 137 |
+
self.frame_keyseq_advanced = Frame(self, name='keyseq_advanced')
|
| 138 |
+
self.frame_keyseq_advanced.grid(row=0, column=0, sticky='nsew',
|
| 139 |
+
padx=5, pady=5)
|
| 140 |
+
advanced_title = Label(self.frame_keyseq_advanced, justify='left',
|
| 141 |
+
text=f"Enter new binding(s) for '{self.action}' :\n" +
|
| 142 |
+
"(These bindings will not be checked for validity!)")
|
| 143 |
+
advanced_title.pack(anchor='w')
|
| 144 |
+
self.advanced_keys = Entry(self.frame_keyseq_advanced,
|
| 145 |
+
textvariable=self.key_string)
|
| 146 |
+
self.advanced_keys.pack(fill='x')
|
| 147 |
+
|
| 148 |
+
# Advanced entry help text.
|
| 149 |
+
self.frame_help_advanced = Frame(self)
|
| 150 |
+
self.frame_help_advanced.grid(row=1, column=0, sticky='nsew', padx=5)
|
| 151 |
+
help_advanced = Label(self.frame_help_advanced, justify='left',
|
| 152 |
+
text="Key bindings are specified using Tkinter keysyms as\n"+
|
| 153 |
+
"in these samples: <Control-f>, <Shift-F2>, <F12>,\n"
|
| 154 |
+
"<Control-space>, <Meta-less>, <Control-Alt-Shift-X>.\n"
|
| 155 |
+
"Upper case is used when the Shift modifier is present!\n\n" +
|
| 156 |
+
"'Emacs style' multi-keystroke bindings are specified as\n" +
|
| 157 |
+
"follows: <Control-x><Control-y>, where the first key\n" +
|
| 158 |
+
"is the 'do-nothing' keybinding.\n\n" +
|
| 159 |
+
"Multiple separate bindings for one action should be\n"+
|
| 160 |
+
"separated by a space, eg., <Alt-v> <Meta-v>." )
|
| 161 |
+
help_advanced.grid(row=0, column=0, sticky='nsew')
|
| 162 |
+
|
| 163 |
+
# Switch between basic and advanced.
|
| 164 |
+
self.button_level = Button(self, command=self.toggle_level,
|
| 165 |
+
text='<< Basic Key Binding Entry')
|
| 166 |
+
self.button_level.grid(row=2, column=0, stick='ew', padx=5, pady=5)
|
| 167 |
+
self.toggle_level()
|
| 168 |
+
|
| 169 |
+
def set_modifiers_for_platform(self):
|
| 170 |
+
"""Determine list of names of key modifiers for this platform.
|
| 171 |
+
|
| 172 |
+
The names are used to build Tk bindings -- it doesn't matter if the
|
| 173 |
+
keyboard has these keys; it matters if Tk understands them. The
|
| 174 |
+
order is also important: key binding equality depends on it, so
|
| 175 |
+
config-keys.def must use the same ordering.
|
| 176 |
+
"""
|
| 177 |
+
if sys.platform == "darwin":
|
| 178 |
+
self.modifiers = ['Shift', 'Control', 'Option', 'Command']
|
| 179 |
+
else:
|
| 180 |
+
self.modifiers = ['Control', 'Alt', 'Shift']
|
| 181 |
+
self.modifier_label = {'Control': 'Ctrl'} # Short name.
|
| 182 |
+
|
| 183 |
+
def toggle_level(self):
|
| 184 |
+
"Toggle between basic and advanced keys."
|
| 185 |
+
if self.button_level.cget('text').startswith('Advanced'):
|
| 186 |
+
self.clear_key_seq()
|
| 187 |
+
self.button_level.config(text='<< Basic Key Binding Entry')
|
| 188 |
+
self.frame_keyseq_advanced.lift()
|
| 189 |
+
self.frame_help_advanced.lift()
|
| 190 |
+
self.advanced_keys.focus_set()
|
| 191 |
+
self.advanced = True
|
| 192 |
+
else:
|
| 193 |
+
self.clear_key_seq()
|
| 194 |
+
self.button_level.config(text='Advanced Key Binding Entry >>')
|
| 195 |
+
self.frame_keyseq_basic.lift()
|
| 196 |
+
self.frame_controls_basic.lift()
|
| 197 |
+
self.advanced = False
|
| 198 |
+
|
| 199 |
+
def final_key_selected(self, event=None):
|
| 200 |
+
"Handler for clicking on key in basic settings list."
|
| 201 |
+
self.build_key_string()
|
| 202 |
+
|
| 203 |
+
def build_key_string(self):
|
| 204 |
+
"Create formatted string of modifiers plus the key."
|
| 205 |
+
keylist = modifiers = self.get_modifiers()
|
| 206 |
+
final_key = self.list_keys_final.get('anchor')
|
| 207 |
+
if final_key:
|
| 208 |
+
final_key = translate_key(final_key, modifiers)
|
| 209 |
+
keylist.append(final_key)
|
| 210 |
+
self.key_string.set(f"<{'-'.join(keylist)}>")
|
| 211 |
+
|
| 212 |
+
def get_modifiers(self):
|
| 213 |
+
"Return ordered list of modifiers that have been selected."
|
| 214 |
+
mod_list = [variable.get() for variable in self.modifier_vars]
|
| 215 |
+
return [mod for mod in mod_list if mod]
|
| 216 |
+
|
| 217 |
+
def clear_key_seq(self):
|
| 218 |
+
"Clear modifiers and keys selection."
|
| 219 |
+
self.list_keys_final.select_clear(0, 'end')
|
| 220 |
+
self.list_keys_final.yview('moveto', '0.0')
|
| 221 |
+
for variable in self.modifier_vars:
|
| 222 |
+
variable.set('')
|
| 223 |
+
self.key_string.set('')
|
| 224 |
+
|
| 225 |
+
def ok(self):
|
| 226 |
+
self.result = ''
|
| 227 |
+
keys = self.key_string.get().strip()
|
| 228 |
+
if not keys:
|
| 229 |
+
self.showerror(title=self.keyerror_title, parent=self,
|
| 230 |
+
message="No key specified.")
|
| 231 |
+
return
|
| 232 |
+
if (self.advanced or self.keys_ok(keys)) and self.bind_ok(keys):
|
| 233 |
+
self.result = keys
|
| 234 |
+
return
|
| 235 |
+
|
| 236 |
+
def keys_ok(self, keys):
|
| 237 |
+
"""Validity check on user's 'basic' keybinding selection.
|
| 238 |
+
|
| 239 |
+
Doesn't check the string produced by the advanced dialog because
|
| 240 |
+
'modifiers' isn't set.
|
| 241 |
+
"""
|
| 242 |
+
final_key = self.list_keys_final.get('anchor')
|
| 243 |
+
modifiers = self.get_modifiers()
|
| 244 |
+
title = self.keyerror_title
|
| 245 |
+
key_sequences = [key for keylist in self.current_key_sequences
|
| 246 |
+
for key in keylist]
|
| 247 |
+
if not keys.endswith('>'):
|
| 248 |
+
self.showerror(title, parent=self,
|
| 249 |
+
message='Missing the final Key')
|
| 250 |
+
elif (not modifiers
|
| 251 |
+
and final_key not in FUNCTION_KEYS + MOVE_KEYS):
|
| 252 |
+
self.showerror(title=title, parent=self,
|
| 253 |
+
message='No modifier key(s) specified.')
|
| 254 |
+
elif (modifiers == ['Shift']) \
|
| 255 |
+
and (final_key not in
|
| 256 |
+
FUNCTION_KEYS + MOVE_KEYS + ('Tab', 'Space')):
|
| 257 |
+
msg = 'The shift modifier by itself may not be used with'\
|
| 258 |
+
' this key symbol.'
|
| 259 |
+
self.showerror(title=title, parent=self, message=msg)
|
| 260 |
+
elif keys in key_sequences:
|
| 261 |
+
msg = 'This key combination is already in use.'
|
| 262 |
+
self.showerror(title=title, parent=self, message=msg)
|
| 263 |
+
else:
|
| 264 |
+
return True
|
| 265 |
+
return False
|
| 266 |
+
|
| 267 |
+
def bind_ok(self, keys):
|
| 268 |
+
"Return True if Tcl accepts the new keys else show message."
|
| 269 |
+
try:
|
| 270 |
+
binding = self.bind(keys, lambda: None)
|
| 271 |
+
except TclError as err:
|
| 272 |
+
self.showerror(
|
| 273 |
+
title=self.keyerror_title, parent=self,
|
| 274 |
+
message=(f'The entered key sequence is not accepted.\n\n'
|
| 275 |
+
f'Error: {err}'))
|
| 276 |
+
return False
|
| 277 |
+
else:
|
| 278 |
+
self.unbind(keys, binding)
|
| 279 |
+
return True
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class GetKeysWindow(Toplevel):
|
| 283 |
+
|
| 284 |
+
def __init__(self, parent, title, action, current_key_sequences,
|
| 285 |
+
*, _htest=False, _utest=False):
|
| 286 |
+
"""
|
| 287 |
+
parent - parent of this dialog
|
| 288 |
+
title - string which is the title of the popup dialog
|
| 289 |
+
action - string, the name of the virtual event these keys will be
|
| 290 |
+
mapped to
|
| 291 |
+
current_key_sequences - list, a list of all key sequence lists
|
| 292 |
+
currently mapped to virtual events, for overlap checking
|
| 293 |
+
_htest - bool, change box location when running htest
|
| 294 |
+
_utest - bool, do not wait when running unittest
|
| 295 |
+
"""
|
| 296 |
+
super().__init__(parent)
|
| 297 |
+
self.withdraw() # Hide while setting geometry.
|
| 298 |
+
self['borderwidth'] = 5
|
| 299 |
+
self.resizable(height=False, width=False)
|
| 300 |
+
# Needed for winfo_reqwidth().
|
| 301 |
+
self.update_idletasks()
|
| 302 |
+
# Center dialog over parent (or below htest box).
|
| 303 |
+
x = (parent.winfo_rootx() +
|
| 304 |
+
(parent.winfo_width()//2 - self.winfo_reqwidth()//2))
|
| 305 |
+
y = (parent.winfo_rooty() +
|
| 306 |
+
((parent.winfo_height()//2 - self.winfo_reqheight()//2)
|
| 307 |
+
if not _htest else 150))
|
| 308 |
+
self.geometry(f"+{x}+{y}")
|
| 309 |
+
|
| 310 |
+
self.title(title)
|
| 311 |
+
self.frame = frame = GetKeysFrame(self, action, current_key_sequences)
|
| 312 |
+
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
| 313 |
+
frame_buttons = Frame(self)
|
| 314 |
+
self.button_ok = Button(frame_buttons, text='OK',
|
| 315 |
+
width=8, command=self.ok)
|
| 316 |
+
self.button_cancel = Button(frame_buttons, text='Cancel',
|
| 317 |
+
width=8, command=self.cancel)
|
| 318 |
+
self.button_ok.grid(row=0, column=0, padx=5, pady=5)
|
| 319 |
+
self.button_cancel.grid(row=0, column=1, padx=5, pady=5)
|
| 320 |
+
frame.pack(side='top', expand=True, fill='both')
|
| 321 |
+
frame_buttons.pack(side='bottom', fill='x')
|
| 322 |
+
|
| 323 |
+
self.transient(parent)
|
| 324 |
+
_setup_dialog(self)
|
| 325 |
+
self.grab_set()
|
| 326 |
+
if not _utest:
|
| 327 |
+
self.deiconify() # Geometry set, unhide.
|
| 328 |
+
self.wait_window()
|
| 329 |
+
|
| 330 |
+
@property
|
| 331 |
+
def result(self):
|
| 332 |
+
return self.frame.result
|
| 333 |
+
|
| 334 |
+
@result.setter
|
| 335 |
+
def result(self, value):
|
| 336 |
+
self.frame.result = value
|
| 337 |
+
|
| 338 |
+
def ok(self, event=None):
|
| 339 |
+
self.frame.ok()
|
| 340 |
+
self.grab_release()
|
| 341 |
+
self.destroy()
|
| 342 |
+
|
| 343 |
+
def cancel(self, event=None):
|
| 344 |
+
self.result = ''
|
| 345 |
+
self.grab_release()
|
| 346 |
+
self.destroy()
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
if __name__ == '__main__':
|
| 350 |
+
from unittest import main
|
| 351 |
+
main('idlelib.idle_test.test_config_key', verbosity=2, exit=False)
|
| 352 |
+
|
| 353 |
+
from idlelib.idle_test.htest import run
|
| 354 |
+
run(GetKeysDialog)
|
evalkit_cambrian/lib/python3.10/idlelib/configdialog.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
evalkit_cambrian/lib/python3.10/idlelib/debugger.py
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import bdb
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from tkinter import *
|
| 5 |
+
from tkinter.ttk import Frame, Scrollbar
|
| 6 |
+
|
| 7 |
+
from idlelib import macosx
|
| 8 |
+
from idlelib.scrolledlist import ScrolledList
|
| 9 |
+
from idlelib.window import ListedToplevel
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Idb(bdb.Bdb):
|
| 13 |
+
|
| 14 |
+
def __init__(self, gui):
|
| 15 |
+
self.gui = gui # An instance of Debugger or proxy of remote.
|
| 16 |
+
bdb.Bdb.__init__(self)
|
| 17 |
+
|
| 18 |
+
def user_line(self, frame):
|
| 19 |
+
if self.in_rpc_code(frame):
|
| 20 |
+
self.set_step()
|
| 21 |
+
return
|
| 22 |
+
message = self.__frame2message(frame)
|
| 23 |
+
try:
|
| 24 |
+
self.gui.interaction(message, frame)
|
| 25 |
+
except TclError: # When closing debugger window with [x] in 3.x
|
| 26 |
+
pass
|
| 27 |
+
|
| 28 |
+
def user_exception(self, frame, info):
|
| 29 |
+
if self.in_rpc_code(frame):
|
| 30 |
+
self.set_step()
|
| 31 |
+
return
|
| 32 |
+
message = self.__frame2message(frame)
|
| 33 |
+
self.gui.interaction(message, frame, info)
|
| 34 |
+
|
| 35 |
+
def in_rpc_code(self, frame):
|
| 36 |
+
if frame.f_code.co_filename.count('rpc.py'):
|
| 37 |
+
return True
|
| 38 |
+
else:
|
| 39 |
+
prev_frame = frame.f_back
|
| 40 |
+
prev_name = prev_frame.f_code.co_filename
|
| 41 |
+
if 'idlelib' in prev_name and 'debugger' in prev_name:
|
| 42 |
+
# catch both idlelib/debugger.py and idlelib/debugger_r.py
|
| 43 |
+
# on both Posix and Windows
|
| 44 |
+
return False
|
| 45 |
+
return self.in_rpc_code(prev_frame)
|
| 46 |
+
|
| 47 |
+
def __frame2message(self, frame):
|
| 48 |
+
code = frame.f_code
|
| 49 |
+
filename = code.co_filename
|
| 50 |
+
lineno = frame.f_lineno
|
| 51 |
+
basename = os.path.basename(filename)
|
| 52 |
+
message = "%s:%s" % (basename, lineno)
|
| 53 |
+
if code.co_name != "?":
|
| 54 |
+
message = "%s: %s()" % (message, code.co_name)
|
| 55 |
+
return message
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class Debugger:
|
| 59 |
+
|
| 60 |
+
vstack = vsource = vlocals = vglobals = None
|
| 61 |
+
|
| 62 |
+
def __init__(self, pyshell, idb=None):
|
| 63 |
+
if idb is None:
|
| 64 |
+
idb = Idb(self)
|
| 65 |
+
self.pyshell = pyshell
|
| 66 |
+
self.idb = idb # If passed, a proxy of remote instance.
|
| 67 |
+
self.frame = None
|
| 68 |
+
self.make_gui()
|
| 69 |
+
self.interacting = 0
|
| 70 |
+
self.nesting_level = 0
|
| 71 |
+
|
| 72 |
+
def run(self, *args):
|
| 73 |
+
# Deal with the scenario where we've already got a program running
|
| 74 |
+
# in the debugger and we want to start another. If that is the case,
|
| 75 |
+
# our second 'run' was invoked from an event dispatched not from
|
| 76 |
+
# the main event loop, but from the nested event loop in 'interaction'
|
| 77 |
+
# below. So our stack looks something like this:
|
| 78 |
+
# outer main event loop
|
| 79 |
+
# run()
|
| 80 |
+
# <running program with traces>
|
| 81 |
+
# callback to debugger's interaction()
|
| 82 |
+
# nested event loop
|
| 83 |
+
# run() for second command
|
| 84 |
+
#
|
| 85 |
+
# This kind of nesting of event loops causes all kinds of problems
|
| 86 |
+
# (see e.g. issue #24455) especially when dealing with running as a
|
| 87 |
+
# subprocess, where there's all kinds of extra stuff happening in
|
| 88 |
+
# there - insert a traceback.print_stack() to check it out.
|
| 89 |
+
#
|
| 90 |
+
# By this point, we've already called restart_subprocess() in
|
| 91 |
+
# ScriptBinding. However, we also need to unwind the stack back to
|
| 92 |
+
# that outer event loop. To accomplish this, we:
|
| 93 |
+
# - return immediately from the nested run()
|
| 94 |
+
# - abort_loop ensures the nested event loop will terminate
|
| 95 |
+
# - the debugger's interaction routine completes normally
|
| 96 |
+
# - the restart_subprocess() will have taken care of stopping
|
| 97 |
+
# the running program, which will also let the outer run complete
|
| 98 |
+
#
|
| 99 |
+
# That leaves us back at the outer main event loop, at which point our
|
| 100 |
+
# after event can fire, and we'll come back to this routine with a
|
| 101 |
+
# clean stack.
|
| 102 |
+
if self.nesting_level > 0:
|
| 103 |
+
self.abort_loop()
|
| 104 |
+
self.root.after(100, lambda: self.run(*args))
|
| 105 |
+
return
|
| 106 |
+
try:
|
| 107 |
+
self.interacting = 1
|
| 108 |
+
return self.idb.run(*args)
|
| 109 |
+
finally:
|
| 110 |
+
self.interacting = 0
|
| 111 |
+
|
| 112 |
+
def close(self, event=None):
|
| 113 |
+
try:
|
| 114 |
+
self.quit()
|
| 115 |
+
except Exception:
|
| 116 |
+
pass
|
| 117 |
+
if self.interacting:
|
| 118 |
+
self.top.bell()
|
| 119 |
+
return
|
| 120 |
+
if self.stackviewer:
|
| 121 |
+
self.stackviewer.close(); self.stackviewer = None
|
| 122 |
+
# Clean up pyshell if user clicked debugger control close widget.
|
| 123 |
+
# (Causes a harmless extra cycle through close_debugger() if user
|
| 124 |
+
# toggled debugger from pyshell Debug menu)
|
| 125 |
+
self.pyshell.close_debugger()
|
| 126 |
+
# Now close the debugger control window....
|
| 127 |
+
self.top.destroy()
|
| 128 |
+
|
| 129 |
+
def make_gui(self):
|
| 130 |
+
pyshell = self.pyshell
|
| 131 |
+
self.flist = pyshell.flist
|
| 132 |
+
self.root = root = pyshell.root
|
| 133 |
+
self.top = top = ListedToplevel(root)
|
| 134 |
+
self.top.wm_title("Debug Control")
|
| 135 |
+
self.top.wm_iconname("Debug")
|
| 136 |
+
top.wm_protocol("WM_DELETE_WINDOW", self.close)
|
| 137 |
+
self.top.bind("<Escape>", self.close)
|
| 138 |
+
#
|
| 139 |
+
self.bframe = bframe = Frame(top)
|
| 140 |
+
self.bframe.pack(anchor="w")
|
| 141 |
+
self.buttons = bl = []
|
| 142 |
+
#
|
| 143 |
+
self.bcont = b = Button(bframe, text="Go", command=self.cont)
|
| 144 |
+
bl.append(b)
|
| 145 |
+
self.bstep = b = Button(bframe, text="Step", command=self.step)
|
| 146 |
+
bl.append(b)
|
| 147 |
+
self.bnext = b = Button(bframe, text="Over", command=self.next)
|
| 148 |
+
bl.append(b)
|
| 149 |
+
self.bret = b = Button(bframe, text="Out", command=self.ret)
|
| 150 |
+
bl.append(b)
|
| 151 |
+
self.bret = b = Button(bframe, text="Quit", command=self.quit)
|
| 152 |
+
bl.append(b)
|
| 153 |
+
#
|
| 154 |
+
for b in bl:
|
| 155 |
+
b.configure(state="disabled")
|
| 156 |
+
b.pack(side="left")
|
| 157 |
+
#
|
| 158 |
+
self.cframe = cframe = Frame(bframe)
|
| 159 |
+
self.cframe.pack(side="left")
|
| 160 |
+
#
|
| 161 |
+
if not self.vstack:
|
| 162 |
+
self.__class__.vstack = BooleanVar(top)
|
| 163 |
+
self.vstack.set(1)
|
| 164 |
+
self.bstack = Checkbutton(cframe,
|
| 165 |
+
text="Stack", command=self.show_stack, variable=self.vstack)
|
| 166 |
+
self.bstack.grid(row=0, column=0)
|
| 167 |
+
if not self.vsource:
|
| 168 |
+
self.__class__.vsource = BooleanVar(top)
|
| 169 |
+
self.bsource = Checkbutton(cframe,
|
| 170 |
+
text="Source", command=self.show_source, variable=self.vsource)
|
| 171 |
+
self.bsource.grid(row=0, column=1)
|
| 172 |
+
if not self.vlocals:
|
| 173 |
+
self.__class__.vlocals = BooleanVar(top)
|
| 174 |
+
self.vlocals.set(1)
|
| 175 |
+
self.blocals = Checkbutton(cframe,
|
| 176 |
+
text="Locals", command=self.show_locals, variable=self.vlocals)
|
| 177 |
+
self.blocals.grid(row=1, column=0)
|
| 178 |
+
if not self.vglobals:
|
| 179 |
+
self.__class__.vglobals = BooleanVar(top)
|
| 180 |
+
self.bglobals = Checkbutton(cframe,
|
| 181 |
+
text="Globals", command=self.show_globals, variable=self.vglobals)
|
| 182 |
+
self.bglobals.grid(row=1, column=1)
|
| 183 |
+
#
|
| 184 |
+
self.status = Label(top, anchor="w")
|
| 185 |
+
self.status.pack(anchor="w")
|
| 186 |
+
self.error = Label(top, anchor="w")
|
| 187 |
+
self.error.pack(anchor="w", fill="x")
|
| 188 |
+
self.errorbg = self.error.cget("background")
|
| 189 |
+
#
|
| 190 |
+
self.fstack = Frame(top, height=1)
|
| 191 |
+
self.fstack.pack(expand=1, fill="both")
|
| 192 |
+
self.flocals = Frame(top)
|
| 193 |
+
self.flocals.pack(expand=1, fill="both")
|
| 194 |
+
self.fglobals = Frame(top, height=1)
|
| 195 |
+
self.fglobals.pack(expand=1, fill="both")
|
| 196 |
+
#
|
| 197 |
+
if self.vstack.get():
|
| 198 |
+
self.show_stack()
|
| 199 |
+
if self.vlocals.get():
|
| 200 |
+
self.show_locals()
|
| 201 |
+
if self.vglobals.get():
|
| 202 |
+
self.show_globals()
|
| 203 |
+
|
| 204 |
+
def interaction(self, message, frame, info=None):
|
| 205 |
+
self.frame = frame
|
| 206 |
+
self.status.configure(text=message)
|
| 207 |
+
#
|
| 208 |
+
if info:
|
| 209 |
+
type, value, tb = info
|
| 210 |
+
try:
|
| 211 |
+
m1 = type.__name__
|
| 212 |
+
except AttributeError:
|
| 213 |
+
m1 = "%s" % str(type)
|
| 214 |
+
if value is not None:
|
| 215 |
+
try:
|
| 216 |
+
m1 = "%s: %s" % (m1, str(value))
|
| 217 |
+
except:
|
| 218 |
+
pass
|
| 219 |
+
bg = "yellow"
|
| 220 |
+
else:
|
| 221 |
+
m1 = ""
|
| 222 |
+
tb = None
|
| 223 |
+
bg = self.errorbg
|
| 224 |
+
self.error.configure(text=m1, background=bg)
|
| 225 |
+
#
|
| 226 |
+
sv = self.stackviewer
|
| 227 |
+
if sv:
|
| 228 |
+
stack, i = self.idb.get_stack(self.frame, tb)
|
| 229 |
+
sv.load_stack(stack, i)
|
| 230 |
+
#
|
| 231 |
+
self.show_variables(1)
|
| 232 |
+
#
|
| 233 |
+
if self.vsource.get():
|
| 234 |
+
self.sync_source_line()
|
| 235 |
+
#
|
| 236 |
+
for b in self.buttons:
|
| 237 |
+
b.configure(state="normal")
|
| 238 |
+
#
|
| 239 |
+
self.top.wakeup()
|
| 240 |
+
# Nested main loop: Tkinter's main loop is not reentrant, so use
|
| 241 |
+
# Tcl's vwait facility, which reenters the event loop until an
|
| 242 |
+
# event handler sets the variable we're waiting on
|
| 243 |
+
self.nesting_level += 1
|
| 244 |
+
self.root.tk.call('vwait', '::idledebugwait')
|
| 245 |
+
self.nesting_level -= 1
|
| 246 |
+
#
|
| 247 |
+
for b in self.buttons:
|
| 248 |
+
b.configure(state="disabled")
|
| 249 |
+
self.status.configure(text="")
|
| 250 |
+
self.error.configure(text="", background=self.errorbg)
|
| 251 |
+
self.frame = None
|
| 252 |
+
|
| 253 |
+
def sync_source_line(self):
|
| 254 |
+
frame = self.frame
|
| 255 |
+
if not frame:
|
| 256 |
+
return
|
| 257 |
+
filename, lineno = self.__frame2fileline(frame)
|
| 258 |
+
if filename[:1] + filename[-1:] != "<>" and os.path.exists(filename):
|
| 259 |
+
self.flist.gotofileline(filename, lineno)
|
| 260 |
+
|
| 261 |
+
def __frame2fileline(self, frame):
|
| 262 |
+
code = frame.f_code
|
| 263 |
+
filename = code.co_filename
|
| 264 |
+
lineno = frame.f_lineno
|
| 265 |
+
return filename, lineno
|
| 266 |
+
|
| 267 |
+
def cont(self):
|
| 268 |
+
self.idb.set_continue()
|
| 269 |
+
self.abort_loop()
|
| 270 |
+
|
| 271 |
+
def step(self):
|
| 272 |
+
self.idb.set_step()
|
| 273 |
+
self.abort_loop()
|
| 274 |
+
|
| 275 |
+
def next(self):
|
| 276 |
+
self.idb.set_next(self.frame)
|
| 277 |
+
self.abort_loop()
|
| 278 |
+
|
| 279 |
+
def ret(self):
|
| 280 |
+
self.idb.set_return(self.frame)
|
| 281 |
+
self.abort_loop()
|
| 282 |
+
|
| 283 |
+
def quit(self):
|
| 284 |
+
self.idb.set_quit()
|
| 285 |
+
self.abort_loop()
|
| 286 |
+
|
| 287 |
+
def abort_loop(self):
|
| 288 |
+
self.root.tk.call('set', '::idledebugwait', '1')
|
| 289 |
+
|
| 290 |
+
stackviewer = None
|
| 291 |
+
|
| 292 |
+
def show_stack(self):
|
| 293 |
+
if not self.stackviewer and self.vstack.get():
|
| 294 |
+
self.stackviewer = sv = StackViewer(self.fstack, self.flist, self)
|
| 295 |
+
if self.frame:
|
| 296 |
+
stack, i = self.idb.get_stack(self.frame, None)
|
| 297 |
+
sv.load_stack(stack, i)
|
| 298 |
+
else:
|
| 299 |
+
sv = self.stackviewer
|
| 300 |
+
if sv and not self.vstack.get():
|
| 301 |
+
self.stackviewer = None
|
| 302 |
+
sv.close()
|
| 303 |
+
self.fstack['height'] = 1
|
| 304 |
+
|
| 305 |
+
def show_source(self):
|
| 306 |
+
if self.vsource.get():
|
| 307 |
+
self.sync_source_line()
|
| 308 |
+
|
| 309 |
+
def show_frame(self, stackitem):
|
| 310 |
+
self.frame = stackitem[0] # lineno is stackitem[1]
|
| 311 |
+
self.show_variables()
|
| 312 |
+
|
| 313 |
+
localsviewer = None
|
| 314 |
+
globalsviewer = None
|
| 315 |
+
|
| 316 |
+
def show_locals(self):
|
| 317 |
+
lv = self.localsviewer
|
| 318 |
+
if self.vlocals.get():
|
| 319 |
+
if not lv:
|
| 320 |
+
self.localsviewer = NamespaceViewer(self.flocals, "Locals")
|
| 321 |
+
else:
|
| 322 |
+
if lv:
|
| 323 |
+
self.localsviewer = None
|
| 324 |
+
lv.close()
|
| 325 |
+
self.flocals['height'] = 1
|
| 326 |
+
self.show_variables()
|
| 327 |
+
|
| 328 |
+
def show_globals(self):
|
| 329 |
+
gv = self.globalsviewer
|
| 330 |
+
if self.vglobals.get():
|
| 331 |
+
if not gv:
|
| 332 |
+
self.globalsviewer = NamespaceViewer(self.fglobals, "Globals")
|
| 333 |
+
else:
|
| 334 |
+
if gv:
|
| 335 |
+
self.globalsviewer = None
|
| 336 |
+
gv.close()
|
| 337 |
+
self.fglobals['height'] = 1
|
| 338 |
+
self.show_variables()
|
| 339 |
+
|
| 340 |
+
def show_variables(self, force=0):
|
| 341 |
+
lv = self.localsviewer
|
| 342 |
+
gv = self.globalsviewer
|
| 343 |
+
frame = self.frame
|
| 344 |
+
if not frame:
|
| 345 |
+
ldict = gdict = None
|
| 346 |
+
else:
|
| 347 |
+
ldict = frame.f_locals
|
| 348 |
+
gdict = frame.f_globals
|
| 349 |
+
if lv and gv and ldict is gdict:
|
| 350 |
+
ldict = None
|
| 351 |
+
if lv:
|
| 352 |
+
lv.load_dict(ldict, force, self.pyshell.interp.rpcclt)
|
| 353 |
+
if gv:
|
| 354 |
+
gv.load_dict(gdict, force, self.pyshell.interp.rpcclt)
|
| 355 |
+
|
| 356 |
+
def set_breakpoint_here(self, filename, lineno):
|
| 357 |
+
self.idb.set_break(filename, lineno)
|
| 358 |
+
|
| 359 |
+
def clear_breakpoint_here(self, filename, lineno):
|
| 360 |
+
self.idb.clear_break(filename, lineno)
|
| 361 |
+
|
| 362 |
+
def clear_file_breaks(self, filename):
|
| 363 |
+
self.idb.clear_all_file_breaks(filename)
|
| 364 |
+
|
| 365 |
+
def load_breakpoints(self):
|
| 366 |
+
"Load PyShellEditorWindow breakpoints into subprocess debugger"
|
| 367 |
+
for editwin in self.pyshell.flist.inversedict:
|
| 368 |
+
filename = editwin.io.filename
|
| 369 |
+
try:
|
| 370 |
+
for lineno in editwin.breakpoints:
|
| 371 |
+
self.set_breakpoint_here(filename, lineno)
|
| 372 |
+
except AttributeError:
|
| 373 |
+
continue
|
| 374 |
+
|
| 375 |
+
class StackViewer(ScrolledList):
|
| 376 |
+
|
| 377 |
+
def __init__(self, master, flist, gui):
|
| 378 |
+
if macosx.isAquaTk():
|
| 379 |
+
# At least on with the stock AquaTk version on OSX 10.4 you'll
|
| 380 |
+
# get a shaking GUI that eventually kills IDLE if the width
|
| 381 |
+
# argument is specified.
|
| 382 |
+
ScrolledList.__init__(self, master)
|
| 383 |
+
else:
|
| 384 |
+
ScrolledList.__init__(self, master, width=80)
|
| 385 |
+
self.flist = flist
|
| 386 |
+
self.gui = gui
|
| 387 |
+
self.stack = []
|
| 388 |
+
|
| 389 |
+
def load_stack(self, stack, index=None):
|
| 390 |
+
self.stack = stack
|
| 391 |
+
self.clear()
|
| 392 |
+
for i in range(len(stack)):
|
| 393 |
+
frame, lineno = stack[i]
|
| 394 |
+
try:
|
| 395 |
+
modname = frame.f_globals["__name__"]
|
| 396 |
+
except:
|
| 397 |
+
modname = "?"
|
| 398 |
+
code = frame.f_code
|
| 399 |
+
filename = code.co_filename
|
| 400 |
+
funcname = code.co_name
|
| 401 |
+
import linecache
|
| 402 |
+
sourceline = linecache.getline(filename, lineno)
|
| 403 |
+
sourceline = sourceline.strip()
|
| 404 |
+
if funcname in ("?", "", None):
|
| 405 |
+
item = "%s, line %d: %s" % (modname, lineno, sourceline)
|
| 406 |
+
else:
|
| 407 |
+
item = "%s.%s(), line %d: %s" % (modname, funcname,
|
| 408 |
+
lineno, sourceline)
|
| 409 |
+
if i == index:
|
| 410 |
+
item = "> " + item
|
| 411 |
+
self.append(item)
|
| 412 |
+
if index is not None:
|
| 413 |
+
self.select(index)
|
| 414 |
+
|
| 415 |
+
def popup_event(self, event):
|
| 416 |
+
"override base method"
|
| 417 |
+
if self.stack:
|
| 418 |
+
return ScrolledList.popup_event(self, event)
|
| 419 |
+
|
| 420 |
+
def fill_menu(self):
|
| 421 |
+
"override base method"
|
| 422 |
+
menu = self.menu
|
| 423 |
+
menu.add_command(label="Go to source line",
|
| 424 |
+
command=self.goto_source_line)
|
| 425 |
+
menu.add_command(label="Show stack frame",
|
| 426 |
+
command=self.show_stack_frame)
|
| 427 |
+
|
| 428 |
+
def on_select(self, index):
|
| 429 |
+
"override base method"
|
| 430 |
+
if 0 <= index < len(self.stack):
|
| 431 |
+
self.gui.show_frame(self.stack[index])
|
| 432 |
+
|
| 433 |
+
def on_double(self, index):
|
| 434 |
+
"override base method"
|
| 435 |
+
self.show_source(index)
|
| 436 |
+
|
| 437 |
+
def goto_source_line(self):
|
| 438 |
+
index = self.listbox.index("active")
|
| 439 |
+
self.show_source(index)
|
| 440 |
+
|
| 441 |
+
def show_stack_frame(self):
|
| 442 |
+
index = self.listbox.index("active")
|
| 443 |
+
if 0 <= index < len(self.stack):
|
| 444 |
+
self.gui.show_frame(self.stack[index])
|
| 445 |
+
|
| 446 |
+
def show_source(self, index):
|
| 447 |
+
if not (0 <= index < len(self.stack)):
|
| 448 |
+
return
|
| 449 |
+
frame, lineno = self.stack[index]
|
| 450 |
+
code = frame.f_code
|
| 451 |
+
filename = code.co_filename
|
| 452 |
+
if os.path.isfile(filename):
|
| 453 |
+
edit = self.flist.open(filename)
|
| 454 |
+
if edit:
|
| 455 |
+
edit.gotoline(lineno)
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
class NamespaceViewer:
|
| 459 |
+
|
| 460 |
+
def __init__(self, master, title, dict=None):
|
| 461 |
+
width = 0
|
| 462 |
+
height = 40
|
| 463 |
+
if dict:
|
| 464 |
+
height = 20*len(dict) # XXX 20 == observed height of Entry widget
|
| 465 |
+
self.master = master
|
| 466 |
+
self.title = title
|
| 467 |
+
import reprlib
|
| 468 |
+
self.repr = reprlib.Repr()
|
| 469 |
+
self.repr.maxstring = 60
|
| 470 |
+
self.repr.maxother = 60
|
| 471 |
+
self.frame = frame = Frame(master)
|
| 472 |
+
self.frame.pack(expand=1, fill="both")
|
| 473 |
+
self.label = Label(frame, text=title, borderwidth=2, relief="groove")
|
| 474 |
+
self.label.pack(fill="x")
|
| 475 |
+
self.vbar = vbar = Scrollbar(frame, name="vbar")
|
| 476 |
+
vbar.pack(side="right", fill="y")
|
| 477 |
+
self.canvas = canvas = Canvas(frame,
|
| 478 |
+
height=min(300, max(40, height)),
|
| 479 |
+
scrollregion=(0, 0, width, height))
|
| 480 |
+
canvas.pack(side="left", fill="both", expand=1)
|
| 481 |
+
vbar["command"] = canvas.yview
|
| 482 |
+
canvas["yscrollcommand"] = vbar.set
|
| 483 |
+
self.subframe = subframe = Frame(canvas)
|
| 484 |
+
self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw")
|
| 485 |
+
self.load_dict(dict)
|
| 486 |
+
|
| 487 |
+
dict = -1
|
| 488 |
+
|
| 489 |
+
def load_dict(self, dict, force=0, rpc_client=None):
|
| 490 |
+
if dict is self.dict and not force:
|
| 491 |
+
return
|
| 492 |
+
subframe = self.subframe
|
| 493 |
+
frame = self.frame
|
| 494 |
+
for c in list(subframe.children.values()):
|
| 495 |
+
c.destroy()
|
| 496 |
+
self.dict = None
|
| 497 |
+
if not dict:
|
| 498 |
+
l = Label(subframe, text="None")
|
| 499 |
+
l.grid(row=0, column=0)
|
| 500 |
+
else:
|
| 501 |
+
#names = sorted(dict)
|
| 502 |
+
###
|
| 503 |
+
# Because of (temporary) limitations on the dict_keys type (not yet
|
| 504 |
+
# public or pickleable), have the subprocess to send a list of
|
| 505 |
+
# keys, not a dict_keys object. sorted() will take a dict_keys
|
| 506 |
+
# (no subprocess) or a list.
|
| 507 |
+
#
|
| 508 |
+
# There is also an obscure bug in sorted(dict) where the
|
| 509 |
+
# interpreter gets into a loop requesting non-existing dict[0],
|
| 510 |
+
# dict[1], dict[2], etc from the debugger_r.DictProxy.
|
| 511 |
+
###
|
| 512 |
+
keys_list = dict.keys()
|
| 513 |
+
names = sorted(keys_list)
|
| 514 |
+
###
|
| 515 |
+
row = 0
|
| 516 |
+
for name in names:
|
| 517 |
+
value = dict[name]
|
| 518 |
+
svalue = self.repr.repr(value) # repr(value)
|
| 519 |
+
# Strip extra quotes caused by calling repr on the (already)
|
| 520 |
+
# repr'd value sent across the RPC interface:
|
| 521 |
+
if rpc_client:
|
| 522 |
+
svalue = svalue[1:-1]
|
| 523 |
+
l = Label(subframe, text=name)
|
| 524 |
+
l.grid(row=row, column=0, sticky="nw")
|
| 525 |
+
l = Entry(subframe, width=0, borderwidth=0)
|
| 526 |
+
l.insert(0, svalue)
|
| 527 |
+
l.grid(row=row, column=1, sticky="nw")
|
| 528 |
+
row = row+1
|
| 529 |
+
self.dict = dict
|
| 530 |
+
# XXX Could we use a <Configure> callback for the following?
|
| 531 |
+
subframe.update_idletasks() # Alas!
|
| 532 |
+
width = subframe.winfo_reqwidth()
|
| 533 |
+
height = subframe.winfo_reqheight()
|
| 534 |
+
canvas = self.canvas
|
| 535 |
+
self.canvas["scrollregion"] = (0, 0, width, height)
|
| 536 |
+
if height > 300:
|
| 537 |
+
canvas["height"] = 300
|
| 538 |
+
frame.pack(expand=1)
|
| 539 |
+
else:
|
| 540 |
+
canvas["height"] = height
|
| 541 |
+
frame.pack(expand=0)
|
| 542 |
+
|
| 543 |
+
def close(self):
|
| 544 |
+
self.frame.destroy()
|
| 545 |
+
|
| 546 |
+
if __name__ == "__main__":
|
| 547 |
+
from unittest import main
|
| 548 |
+
main('idlelib.idle_test.test_debugger', verbosity=2, exit=False)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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support for remote Python debugging.
|
| 2 |
+
|
| 3 |
+
Some ASCII art to describe the structure:
|
| 4 |
+
|
| 5 |
+
IN PYTHON SUBPROCESS # IN IDLE PROCESS
|
| 6 |
+
#
|
| 7 |
+
# oid='gui_adapter'
|
| 8 |
+
+----------+ # +------------+ +-----+
|
| 9 |
+
| GUIProxy |--remote#call-->| GUIAdapter |--calls-->| GUI |
|
| 10 |
+
+-----+--calls-->+----------+ # +------------+ +-----+
|
| 11 |
+
| Idb | # /
|
| 12 |
+
+-----+<-calls--+------------+ # +----------+<--calls-/
|
| 13 |
+
| IdbAdapter |<--remote#call--| IdbProxy |
|
| 14 |
+
+------------+ # +----------+
|
| 15 |
+
oid='idb_adapter' #
|
| 16 |
+
|
| 17 |
+
The purpose of the Proxy and Adapter classes is to translate certain
|
| 18 |
+
arguments and return values that cannot be transported through the RPC
|
| 19 |
+
barrier, in particular frame and traceback objects.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
import reprlib
|
| 23 |
+
import types
|
| 24 |
+
from idlelib import debugger
|
| 25 |
+
|
| 26 |
+
debugging = 0
|
| 27 |
+
|
| 28 |
+
idb_adap_oid = "idb_adapter"
|
| 29 |
+
gui_adap_oid = "gui_adapter"
|
| 30 |
+
|
| 31 |
+
#=======================================
|
| 32 |
+
#
|
| 33 |
+
# In the PYTHON subprocess:
|
| 34 |
+
|
| 35 |
+
frametable = {}
|
| 36 |
+
dicttable = {}
|
| 37 |
+
codetable = {}
|
| 38 |
+
tracebacktable = {}
|
| 39 |
+
|
| 40 |
+
def wrap_frame(frame):
|
| 41 |
+
fid = id(frame)
|
| 42 |
+
frametable[fid] = frame
|
| 43 |
+
return fid
|
| 44 |
+
|
| 45 |
+
def wrap_info(info):
|
| 46 |
+
"replace info[2], a traceback instance, by its ID"
|
| 47 |
+
if info is None:
|
| 48 |
+
return None
|
| 49 |
+
else:
|
| 50 |
+
traceback = info[2]
|
| 51 |
+
assert isinstance(traceback, types.TracebackType)
|
| 52 |
+
traceback_id = id(traceback)
|
| 53 |
+
tracebacktable[traceback_id] = traceback
|
| 54 |
+
modified_info = (info[0], info[1], traceback_id)
|
| 55 |
+
return modified_info
|
| 56 |
+
|
| 57 |
+
class GUIProxy:
|
| 58 |
+
|
| 59 |
+
def __init__(self, conn, gui_adap_oid):
|
| 60 |
+
self.conn = conn
|
| 61 |
+
self.oid = gui_adap_oid
|
| 62 |
+
|
| 63 |
+
def interaction(self, message, frame, info=None):
|
| 64 |
+
# calls rpc.SocketIO.remotecall() via run.MyHandler instance
|
| 65 |
+
# pass frame and traceback object IDs instead of the objects themselves
|
| 66 |
+
self.conn.remotecall(self.oid, "interaction",
|
| 67 |
+
(message, wrap_frame(frame), wrap_info(info)),
|
| 68 |
+
{})
|
| 69 |
+
|
| 70 |
+
class IdbAdapter:
|
| 71 |
+
|
| 72 |
+
def __init__(self, idb):
|
| 73 |
+
self.idb = idb
|
| 74 |
+
|
| 75 |
+
#----------called by an IdbProxy----------
|
| 76 |
+
|
| 77 |
+
def set_step(self):
|
| 78 |
+
self.idb.set_step()
|
| 79 |
+
|
| 80 |
+
def set_quit(self):
|
| 81 |
+
self.idb.set_quit()
|
| 82 |
+
|
| 83 |
+
def set_continue(self):
|
| 84 |
+
self.idb.set_continue()
|
| 85 |
+
|
| 86 |
+
def set_next(self, fid):
|
| 87 |
+
frame = frametable[fid]
|
| 88 |
+
self.idb.set_next(frame)
|
| 89 |
+
|
| 90 |
+
def set_return(self, fid):
|
| 91 |
+
frame = frametable[fid]
|
| 92 |
+
self.idb.set_return(frame)
|
| 93 |
+
|
| 94 |
+
def get_stack(self, fid, tbid):
|
| 95 |
+
frame = frametable[fid]
|
| 96 |
+
if tbid is None:
|
| 97 |
+
tb = None
|
| 98 |
+
else:
|
| 99 |
+
tb = tracebacktable[tbid]
|
| 100 |
+
stack, i = self.idb.get_stack(frame, tb)
|
| 101 |
+
stack = [(wrap_frame(frame2), k) for frame2, k in stack]
|
| 102 |
+
return stack, i
|
| 103 |
+
|
| 104 |
+
def run(self, cmd):
|
| 105 |
+
import __main__
|
| 106 |
+
self.idb.run(cmd, __main__.__dict__)
|
| 107 |
+
|
| 108 |
+
def set_break(self, filename, lineno):
|
| 109 |
+
msg = self.idb.set_break(filename, lineno)
|
| 110 |
+
return msg
|
| 111 |
+
|
| 112 |
+
def clear_break(self, filename, lineno):
|
| 113 |
+
msg = self.idb.clear_break(filename, lineno)
|
| 114 |
+
return msg
|
| 115 |
+
|
| 116 |
+
def clear_all_file_breaks(self, filename):
|
| 117 |
+
msg = self.idb.clear_all_file_breaks(filename)
|
| 118 |
+
return msg
|
| 119 |
+
|
| 120 |
+
#----------called by a FrameProxy----------
|
| 121 |
+
|
| 122 |
+
def frame_attr(self, fid, name):
|
| 123 |
+
frame = frametable[fid]
|
| 124 |
+
return getattr(frame, name)
|
| 125 |
+
|
| 126 |
+
def frame_globals(self, fid):
|
| 127 |
+
frame = frametable[fid]
|
| 128 |
+
dict = frame.f_globals
|
| 129 |
+
did = id(dict)
|
| 130 |
+
dicttable[did] = dict
|
| 131 |
+
return did
|
| 132 |
+
|
| 133 |
+
def frame_locals(self, fid):
|
| 134 |
+
frame = frametable[fid]
|
| 135 |
+
dict = frame.f_locals
|
| 136 |
+
did = id(dict)
|
| 137 |
+
dicttable[did] = dict
|
| 138 |
+
return did
|
| 139 |
+
|
| 140 |
+
def frame_code(self, fid):
|
| 141 |
+
frame = frametable[fid]
|
| 142 |
+
code = frame.f_code
|
| 143 |
+
cid = id(code)
|
| 144 |
+
codetable[cid] = code
|
| 145 |
+
return cid
|
| 146 |
+
|
| 147 |
+
#----------called by a CodeProxy----------
|
| 148 |
+
|
| 149 |
+
def code_name(self, cid):
|
| 150 |
+
code = codetable[cid]
|
| 151 |
+
return code.co_name
|
| 152 |
+
|
| 153 |
+
def code_filename(self, cid):
|
| 154 |
+
code = codetable[cid]
|
| 155 |
+
return code.co_filename
|
| 156 |
+
|
| 157 |
+
#----------called by a DictProxy----------
|
| 158 |
+
|
| 159 |
+
def dict_keys(self, did):
|
| 160 |
+
raise NotImplementedError("dict_keys not public or pickleable")
|
| 161 |
+
## dict = dicttable[did]
|
| 162 |
+
## return dict.keys()
|
| 163 |
+
|
| 164 |
+
### Needed until dict_keys is type is finished and pickealable.
|
| 165 |
+
### Will probably need to extend rpc.py:SocketIO._proxify at that time.
|
| 166 |
+
def dict_keys_list(self, did):
|
| 167 |
+
dict = dicttable[did]
|
| 168 |
+
return list(dict.keys())
|
| 169 |
+
|
| 170 |
+
def dict_item(self, did, key):
|
| 171 |
+
dict = dicttable[did]
|
| 172 |
+
value = dict[key]
|
| 173 |
+
value = reprlib.repr(value) ### can't pickle module 'builtins'
|
| 174 |
+
return value
|
| 175 |
+
|
| 176 |
+
#----------end class IdbAdapter----------
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def start_debugger(rpchandler, gui_adap_oid):
|
| 180 |
+
"""Start the debugger and its RPC link in the Python subprocess
|
| 181 |
+
|
| 182 |
+
Start the subprocess side of the split debugger and set up that side of the
|
| 183 |
+
RPC link by instantiating the GUIProxy, Idb debugger, and IdbAdapter
|
| 184 |
+
objects and linking them together. Register the IdbAdapter with the
|
| 185 |
+
RPCServer to handle RPC requests from the split debugger GUI via the
|
| 186 |
+
IdbProxy.
|
| 187 |
+
|
| 188 |
+
"""
|
| 189 |
+
gui_proxy = GUIProxy(rpchandler, gui_adap_oid)
|
| 190 |
+
idb = debugger.Idb(gui_proxy)
|
| 191 |
+
idb_adap = IdbAdapter(idb)
|
| 192 |
+
rpchandler.register(idb_adap_oid, idb_adap)
|
| 193 |
+
return idb_adap_oid
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
#=======================================
|
| 197 |
+
#
|
| 198 |
+
# In the IDLE process:
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class FrameProxy:
|
| 202 |
+
|
| 203 |
+
def __init__(self, conn, fid):
|
| 204 |
+
self._conn = conn
|
| 205 |
+
self._fid = fid
|
| 206 |
+
self._oid = "idb_adapter"
|
| 207 |
+
self._dictcache = {}
|
| 208 |
+
|
| 209 |
+
def __getattr__(self, name):
|
| 210 |
+
if name[:1] == "_":
|
| 211 |
+
raise AttributeError(name)
|
| 212 |
+
if name == "f_code":
|
| 213 |
+
return self._get_f_code()
|
| 214 |
+
if name == "f_globals":
|
| 215 |
+
return self._get_f_globals()
|
| 216 |
+
if name == "f_locals":
|
| 217 |
+
return self._get_f_locals()
|
| 218 |
+
return self._conn.remotecall(self._oid, "frame_attr",
|
| 219 |
+
(self._fid, name), {})
|
| 220 |
+
|
| 221 |
+
def _get_f_code(self):
|
| 222 |
+
cid = self._conn.remotecall(self._oid, "frame_code", (self._fid,), {})
|
| 223 |
+
return CodeProxy(self._conn, self._oid, cid)
|
| 224 |
+
|
| 225 |
+
def _get_f_globals(self):
|
| 226 |
+
did = self._conn.remotecall(self._oid, "frame_globals",
|
| 227 |
+
(self._fid,), {})
|
| 228 |
+
return self._get_dict_proxy(did)
|
| 229 |
+
|
| 230 |
+
def _get_f_locals(self):
|
| 231 |
+
did = self._conn.remotecall(self._oid, "frame_locals",
|
| 232 |
+
(self._fid,), {})
|
| 233 |
+
return self._get_dict_proxy(did)
|
| 234 |
+
|
| 235 |
+
def _get_dict_proxy(self, did):
|
| 236 |
+
if did in self._dictcache:
|
| 237 |
+
return self._dictcache[did]
|
| 238 |
+
dp = DictProxy(self._conn, self._oid, did)
|
| 239 |
+
self._dictcache[did] = dp
|
| 240 |
+
return dp
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
class CodeProxy:
|
| 244 |
+
|
| 245 |
+
def __init__(self, conn, oid, cid):
|
| 246 |
+
self._conn = conn
|
| 247 |
+
self._oid = oid
|
| 248 |
+
self._cid = cid
|
| 249 |
+
|
| 250 |
+
def __getattr__(self, name):
|
| 251 |
+
if name == "co_name":
|
| 252 |
+
return self._conn.remotecall(self._oid, "code_name",
|
| 253 |
+
(self._cid,), {})
|
| 254 |
+
if name == "co_filename":
|
| 255 |
+
return self._conn.remotecall(self._oid, "code_filename",
|
| 256 |
+
(self._cid,), {})
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
class DictProxy:
|
| 260 |
+
|
| 261 |
+
def __init__(self, conn, oid, did):
|
| 262 |
+
self._conn = conn
|
| 263 |
+
self._oid = oid
|
| 264 |
+
self._did = did
|
| 265 |
+
|
| 266 |
+
## def keys(self):
|
| 267 |
+
## return self._conn.remotecall(self._oid, "dict_keys", (self._did,), {})
|
| 268 |
+
|
| 269 |
+
# 'temporary' until dict_keys is a pickleable built-in type
|
| 270 |
+
def keys(self):
|
| 271 |
+
return self._conn.remotecall(self._oid,
|
| 272 |
+
"dict_keys_list", (self._did,), {})
|
| 273 |
+
|
| 274 |
+
def __getitem__(self, key):
|
| 275 |
+
return self._conn.remotecall(self._oid, "dict_item",
|
| 276 |
+
(self._did, key), {})
|
| 277 |
+
|
| 278 |
+
def __getattr__(self, name):
|
| 279 |
+
##print("*** Failed DictProxy.__getattr__:", name)
|
| 280 |
+
raise AttributeError(name)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class GUIAdapter:
|
| 284 |
+
|
| 285 |
+
def __init__(self, conn, gui):
|
| 286 |
+
self.conn = conn
|
| 287 |
+
self.gui = gui
|
| 288 |
+
|
| 289 |
+
def interaction(self, message, fid, modified_info):
|
| 290 |
+
##print("*** Interaction: (%s, %s, %s)" % (message, fid, modified_info))
|
| 291 |
+
frame = FrameProxy(self.conn, fid)
|
| 292 |
+
self.gui.interaction(message, frame, modified_info)
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
class IdbProxy:
|
| 296 |
+
|
| 297 |
+
def __init__(self, conn, shell, oid):
|
| 298 |
+
self.oid = oid
|
| 299 |
+
self.conn = conn
|
| 300 |
+
self.shell = shell
|
| 301 |
+
|
| 302 |
+
def call(self, methodname, /, *args, **kwargs):
|
| 303 |
+
##print("*** IdbProxy.call %s %s %s" % (methodname, args, kwargs))
|
| 304 |
+
value = self.conn.remotecall(self.oid, methodname, args, kwargs)
|
| 305 |
+
##print("*** IdbProxy.call %s returns %r" % (methodname, value))
|
| 306 |
+
return value
|
| 307 |
+
|
| 308 |
+
def run(self, cmd, locals):
|
| 309 |
+
# Ignores locals on purpose!
|
| 310 |
+
seq = self.conn.asyncqueue(self.oid, "run", (cmd,), {})
|
| 311 |
+
self.shell.interp.active_seq = seq
|
| 312 |
+
|
| 313 |
+
def get_stack(self, frame, tbid):
|
| 314 |
+
# passing frame and traceback IDs, not the objects themselves
|
| 315 |
+
stack, i = self.call("get_stack", frame._fid, tbid)
|
| 316 |
+
stack = [(FrameProxy(self.conn, fid), k) for fid, k in stack]
|
| 317 |
+
return stack, i
|
| 318 |
+
|
| 319 |
+
def set_continue(self):
|
| 320 |
+
self.call("set_continue")
|
| 321 |
+
|
| 322 |
+
def set_step(self):
|
| 323 |
+
self.call("set_step")
|
| 324 |
+
|
| 325 |
+
def set_next(self, frame):
|
| 326 |
+
self.call("set_next", frame._fid)
|
| 327 |
+
|
| 328 |
+
def set_return(self, frame):
|
| 329 |
+
self.call("set_return", frame._fid)
|
| 330 |
+
|
| 331 |
+
def set_quit(self):
|
| 332 |
+
self.call("set_quit")
|
| 333 |
+
|
| 334 |
+
def set_break(self, filename, lineno):
|
| 335 |
+
msg = self.call("set_break", filename, lineno)
|
| 336 |
+
return msg
|
| 337 |
+
|
| 338 |
+
def clear_break(self, filename, lineno):
|
| 339 |
+
msg = self.call("clear_break", filename, lineno)
|
| 340 |
+
return msg
|
| 341 |
+
|
| 342 |
+
def clear_all_file_breaks(self, filename):
|
| 343 |
+
msg = self.call("clear_all_file_breaks", filename)
|
| 344 |
+
return msg
|
| 345 |
+
|
| 346 |
+
def start_remote_debugger(rpcclt, pyshell):
|
| 347 |
+
"""Start the subprocess debugger, initialize the debugger GUI and RPC link
|
| 348 |
+
|
| 349 |
+
Request the RPCServer start the Python subprocess debugger and link. Set
|
| 350 |
+
up the Idle side of the split debugger by instantiating the IdbProxy,
|
| 351 |
+
debugger GUI, and debugger GUIAdapter objects and linking them together.
|
| 352 |
+
|
| 353 |
+
Register the GUIAdapter with the RPCClient to handle debugger GUI
|
| 354 |
+
interaction requests coming from the subprocess debugger via the GUIProxy.
|
| 355 |
+
|
| 356 |
+
The IdbAdapter will pass execution and environment requests coming from the
|
| 357 |
+
Idle debugger GUI to the subprocess debugger via the IdbProxy.
|
| 358 |
+
|
| 359 |
+
"""
|
| 360 |
+
global idb_adap_oid
|
| 361 |
+
|
| 362 |
+
idb_adap_oid = rpcclt.remotecall("exec", "start_the_debugger",\
|
| 363 |
+
(gui_adap_oid,), {})
|
| 364 |
+
idb_proxy = IdbProxy(rpcclt, pyshell, idb_adap_oid)
|
| 365 |
+
gui = debugger.Debugger(pyshell, idb_proxy)
|
| 366 |
+
gui_adap = GUIAdapter(rpcclt, gui)
|
| 367 |
+
rpcclt.register(gui_adap_oid, gui_adap)
|
| 368 |
+
return gui
|
| 369 |
+
|
| 370 |
+
def close_remote_debugger(rpcclt):
|
| 371 |
+
"""Shut down subprocess debugger and Idle side of debugger RPC link
|
| 372 |
+
|
| 373 |
+
Request that the RPCServer shut down the subprocess debugger and link.
|
| 374 |
+
Unregister the GUIAdapter, which will cause a GC on the Idle process
|
| 375 |
+
debugger and RPC link objects. (The second reference to the debugger GUI
|
| 376 |
+
is deleted in pyshell.close_remote_debugger().)
|
| 377 |
+
|
| 378 |
+
"""
|
| 379 |
+
close_subprocess_debugger(rpcclt)
|
| 380 |
+
rpcclt.unregister(gui_adap_oid)
|
| 381 |
+
|
| 382 |
+
def close_subprocess_debugger(rpcclt):
|
| 383 |
+
rpcclt.remotecall("exec", "stop_the_debugger", (idb_adap_oid,), {})
|
| 384 |
+
|
| 385 |
+
def restart_subprocess_debugger(rpcclt):
|
| 386 |
+
idb_adap_oid_ret = rpcclt.remotecall("exec", "start_the_debugger",\
|
| 387 |
+
(gui_adap_oid,), {})
|
| 388 |
+
assert idb_adap_oid_ret == idb_adap_oid, 'Idb restarted with different oid'
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
if __name__ == "__main__":
|
| 392 |
+
from unittest import main
|
| 393 |
+
main('idlelib.idle_test.test_debugger_r', verbosity=2, exit=False)
|
evalkit_cambrian/lib/python3.10/idlelib/delegator.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Delegator:
|
| 2 |
+
|
| 3 |
+
def __init__(self, delegate=None):
|
| 4 |
+
self.delegate = delegate
|
| 5 |
+
self.__cache = set()
|
| 6 |
+
# Cache is used to only remove added attributes
|
| 7 |
+
# when changing the delegate.
|
| 8 |
+
|
| 9 |
+
def __getattr__(self, name):
|
| 10 |
+
attr = getattr(self.delegate, name) # May raise AttributeError
|
| 11 |
+
setattr(self, name, attr)
|
| 12 |
+
self.__cache.add(name)
|
| 13 |
+
return attr
|
| 14 |
+
|
| 15 |
+
def resetcache(self):
|
| 16 |
+
"Removes added attributes while leaving original attributes."
|
| 17 |
+
# Function is really about resetting delegator dict
|
| 18 |
+
# to original state. Cache is just a means
|
| 19 |
+
for key in self.__cache:
|
| 20 |
+
try:
|
| 21 |
+
delattr(self, key)
|
| 22 |
+
except AttributeError:
|
| 23 |
+
pass
|
| 24 |
+
self.__cache.clear()
|
| 25 |
+
|
| 26 |
+
def setdelegate(self, delegate):
|
| 27 |
+
"Reset attributes and change delegate."
|
| 28 |
+
self.resetcache()
|
| 29 |
+
self.delegate = delegate
|
| 30 |
+
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
from unittest import main
|
| 33 |
+
main('idlelib.idle_test.test_delegator', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/dynoption.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
OptionMenu widget modified to allow dynamic menu reconfiguration
|
| 3 |
+
and setting of highlightthickness
|
| 4 |
+
"""
|
| 5 |
+
from tkinter import OptionMenu, _setit, StringVar, Button
|
| 6 |
+
|
| 7 |
+
class DynOptionMenu(OptionMenu):
|
| 8 |
+
"""Add SetMenu and highlightthickness to OptionMenu.
|
| 9 |
+
|
| 10 |
+
Highlightthickness adds space around menu button.
|
| 11 |
+
"""
|
| 12 |
+
def __init__(self, master, variable, value, *values, **kwargs):
|
| 13 |
+
highlightthickness = kwargs.pop('highlightthickness', None)
|
| 14 |
+
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
|
| 15 |
+
self['highlightthickness'] = highlightthickness
|
| 16 |
+
self.variable = variable
|
| 17 |
+
self.command = kwargs.get('command')
|
| 18 |
+
|
| 19 |
+
def SetMenu(self,valueList,value=None):
|
| 20 |
+
"""
|
| 21 |
+
clear and reload the menu with a new set of options.
|
| 22 |
+
valueList - list of new options
|
| 23 |
+
value - initial value to set the optionmenu's menubutton to
|
| 24 |
+
"""
|
| 25 |
+
self['menu'].delete(0,'end')
|
| 26 |
+
for item in valueList:
|
| 27 |
+
self['menu'].add_command(label=item,
|
| 28 |
+
command=_setit(self.variable,item,self.command))
|
| 29 |
+
if value:
|
| 30 |
+
self.variable.set(value)
|
| 31 |
+
|
| 32 |
+
def _dyn_option_menu(parent): # htest #
|
| 33 |
+
from tkinter import Toplevel # + StringVar, Button
|
| 34 |
+
|
| 35 |
+
top = Toplevel(parent)
|
| 36 |
+
top.title("Test dynamic option menu")
|
| 37 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 38 |
+
top.geometry("200x100+%d+%d" % (x + 250, y + 175))
|
| 39 |
+
top.focus_set()
|
| 40 |
+
|
| 41 |
+
var = StringVar(top)
|
| 42 |
+
var.set("Old option set") #Set the default value
|
| 43 |
+
dyn = DynOptionMenu(top, var, "old1","old2","old3","old4",
|
| 44 |
+
highlightthickness=5)
|
| 45 |
+
dyn.pack()
|
| 46 |
+
|
| 47 |
+
def update():
|
| 48 |
+
dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
|
| 49 |
+
button = Button(top, text="Change option set", command=update)
|
| 50 |
+
button.pack()
|
| 51 |
+
|
| 52 |
+
if __name__ == '__main__':
|
| 53 |
+
# Only module without unittests because of intention to replace.
|
| 54 |
+
from idlelib.idle_test.htest import run
|
| 55 |
+
run(_dyn_option_menu)
|
evalkit_cambrian/lib/python3.10/idlelib/editor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
+
import tokenize
|
| 9 |
+
import traceback
|
| 10 |
+
import webbrowser
|
| 11 |
+
|
| 12 |
+
from tkinter import *
|
| 13 |
+
from tkinter.font import Font
|
| 14 |
+
from tkinter.ttk import Scrollbar
|
| 15 |
+
from tkinter import simpledialog
|
| 16 |
+
from tkinter import messagebox
|
| 17 |
+
|
| 18 |
+
from idlelib.config import idleConf
|
| 19 |
+
from idlelib import configdialog
|
| 20 |
+
from idlelib import grep
|
| 21 |
+
from idlelib import help
|
| 22 |
+
from idlelib import help_about
|
| 23 |
+
from idlelib import macosx
|
| 24 |
+
from idlelib.multicall import MultiCallCreator
|
| 25 |
+
from idlelib import pyparse
|
| 26 |
+
from idlelib import query
|
| 27 |
+
from idlelib import replace
|
| 28 |
+
from idlelib import search
|
| 29 |
+
from idlelib.tree import wheel_event
|
| 30 |
+
from idlelib.util import py_extensions
|
| 31 |
+
from idlelib import window
|
| 32 |
+
|
| 33 |
+
# The default tab setting for a Text widget, in average-width characters.
|
| 34 |
+
TK_TABWIDTH_DEFAULT = 8
|
| 35 |
+
_py_version = ' (%s)' % platform.python_version()
|
| 36 |
+
darwin = sys.platform == 'darwin'
|
| 37 |
+
|
| 38 |
+
def _sphinx_version():
|
| 39 |
+
"Format sys.version_info to produce the Sphinx version string used to install the chm docs"
|
| 40 |
+
major, minor, micro, level, serial = sys.version_info
|
| 41 |
+
release = '%s%s' % (major, minor)
|
| 42 |
+
release += '%s' % (micro,)
|
| 43 |
+
if level == 'candidate':
|
| 44 |
+
release += 'rc%s' % (serial,)
|
| 45 |
+
elif level != 'final':
|
| 46 |
+
release += '%s%s' % (level[0], serial)
|
| 47 |
+
return release
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class EditorWindow:
|
| 51 |
+
from idlelib.percolator import Percolator
|
| 52 |
+
from idlelib.colorizer import ColorDelegator, color_config
|
| 53 |
+
from idlelib.undo import UndoDelegator
|
| 54 |
+
from idlelib.iomenu import IOBinding, encoding
|
| 55 |
+
from idlelib import mainmenu
|
| 56 |
+
from idlelib.statusbar import MultiStatusBar
|
| 57 |
+
from idlelib.autocomplete import AutoComplete
|
| 58 |
+
from idlelib.autoexpand import AutoExpand
|
| 59 |
+
from idlelib.calltip import Calltip
|
| 60 |
+
from idlelib.codecontext import CodeContext
|
| 61 |
+
from idlelib.sidebar import LineNumbers
|
| 62 |
+
from idlelib.format import FormatParagraph, FormatRegion, Indents, Rstrip
|
| 63 |
+
from idlelib.parenmatch import ParenMatch
|
| 64 |
+
from idlelib.zoomheight import ZoomHeight
|
| 65 |
+
|
| 66 |
+
filesystemencoding = sys.getfilesystemencoding() # for file names
|
| 67 |
+
help_url = None
|
| 68 |
+
|
| 69 |
+
allow_code_context = True
|
| 70 |
+
allow_line_numbers = True
|
| 71 |
+
user_input_insert_tags = None
|
| 72 |
+
|
| 73 |
+
def __init__(self, flist=None, filename=None, key=None, root=None):
|
| 74 |
+
# Delay import: runscript imports pyshell imports EditorWindow.
|
| 75 |
+
from idlelib.runscript import ScriptBinding
|
| 76 |
+
|
| 77 |
+
if EditorWindow.help_url is None:
|
| 78 |
+
dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html')
|
| 79 |
+
if sys.platform.count('linux'):
|
| 80 |
+
# look for html docs in a couple of standard places
|
| 81 |
+
pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3]
|
| 82 |
+
if os.path.isdir('/var/www/html/python/'): # "python2" rpm
|
| 83 |
+
dochome = '/var/www/html/python/index.html'
|
| 84 |
+
else:
|
| 85 |
+
basepath = '/usr/share/doc/' # standard location
|
| 86 |
+
dochome = os.path.join(basepath, pyver,
|
| 87 |
+
'Doc', 'index.html')
|
| 88 |
+
elif sys.platform[:3] == 'win':
|
| 89 |
+
import winreg # Windows only, block only executed once.
|
| 90 |
+
docfile = ''
|
| 91 |
+
KEY = (rf"Software\Python\PythonCore\{sys.winver}"
|
| 92 |
+
r"\Help\Main Python Documentation")
|
| 93 |
+
try:
|
| 94 |
+
docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY)
|
| 95 |
+
except FileNotFoundError:
|
| 96 |
+
try:
|
| 97 |
+
docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
|
| 98 |
+
KEY)
|
| 99 |
+
except FileNotFoundError:
|
| 100 |
+
pass
|
| 101 |
+
if os.path.isfile(docfile):
|
| 102 |
+
dochome = docfile
|
| 103 |
+
elif sys.platform == 'darwin':
|
| 104 |
+
# documentation may be stored inside a python framework
|
| 105 |
+
dochome = os.path.join(sys.base_prefix,
|
| 106 |
+
'Resources/English.lproj/Documentation/index.html')
|
| 107 |
+
dochome = os.path.normpath(dochome)
|
| 108 |
+
if os.path.isfile(dochome):
|
| 109 |
+
EditorWindow.help_url = dochome
|
| 110 |
+
if sys.platform == 'darwin':
|
| 111 |
+
# Safari requires real file:-URLs
|
| 112 |
+
EditorWindow.help_url = 'file://' + EditorWindow.help_url
|
| 113 |
+
else:
|
| 114 |
+
EditorWindow.help_url = ("https://docs.python.org/%d.%d/"
|
| 115 |
+
% sys.version_info[:2])
|
| 116 |
+
self.flist = flist
|
| 117 |
+
root = root or flist.root
|
| 118 |
+
self.root = root
|
| 119 |
+
self.menubar = Menu(root)
|
| 120 |
+
self.top = top = window.ListedToplevel(root, menu=self.menubar)
|
| 121 |
+
if flist:
|
| 122 |
+
self.tkinter_vars = flist.vars
|
| 123 |
+
#self.top.instance_dict makes flist.inversedict available to
|
| 124 |
+
#configdialog.py so it can access all EditorWindow instances
|
| 125 |
+
self.top.instance_dict = flist.inversedict
|
| 126 |
+
else:
|
| 127 |
+
self.tkinter_vars = {} # keys: Tkinter event names
|
| 128 |
+
# values: Tkinter variable instances
|
| 129 |
+
self.top.instance_dict = {}
|
| 130 |
+
self.recent_files_path = idleConf.userdir and os.path.join(
|
| 131 |
+
idleConf.userdir, 'recent-files.lst')
|
| 132 |
+
|
| 133 |
+
self.prompt_last_line = '' # Override in PyShell
|
| 134 |
+
self.text_frame = text_frame = Frame(top)
|
| 135 |
+
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
|
| 136 |
+
width = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 137 |
+
text_options = {
|
| 138 |
+
'name': 'text',
|
| 139 |
+
'padx': 5,
|
| 140 |
+
'wrap': 'none',
|
| 141 |
+
'highlightthickness': 0,
|
| 142 |
+
'width': width,
|
| 143 |
+
'tabstyle': 'wordprocessor', # new in 8.5
|
| 144 |
+
'height': idleConf.GetOption(
|
| 145 |
+
'main', 'EditorWindow', 'height', type='int'),
|
| 146 |
+
}
|
| 147 |
+
self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
|
| 148 |
+
self.top.focused_widget = self.text
|
| 149 |
+
|
| 150 |
+
self.createmenubar()
|
| 151 |
+
self.apply_bindings()
|
| 152 |
+
|
| 153 |
+
self.top.protocol("WM_DELETE_WINDOW", self.close)
|
| 154 |
+
self.top.bind("<<close-window>>", self.close_event)
|
| 155 |
+
if macosx.isAquaTk():
|
| 156 |
+
# Command-W on editor windows doesn't work without this.
|
| 157 |
+
text.bind('<<close-window>>', self.close_event)
|
| 158 |
+
# Some OS X systems have only one mouse button, so use
|
| 159 |
+
# control-click for popup context menus there. For two
|
| 160 |
+
# buttons, AquaTk defines <2> as the right button, not <3>.
|
| 161 |
+
text.bind("<Control-Button-1>",self.right_menu_event)
|
| 162 |
+
text.bind("<2>", self.right_menu_event)
|
| 163 |
+
else:
|
| 164 |
+
# Elsewhere, use right-click for popup menus.
|
| 165 |
+
text.bind("<3>",self.right_menu_event)
|
| 166 |
+
|
| 167 |
+
text.bind('<MouseWheel>', wheel_event)
|
| 168 |
+
text.bind('<Button-4>', wheel_event)
|
| 169 |
+
text.bind('<Button-5>', wheel_event)
|
| 170 |
+
text.bind('<Configure>', self.handle_winconfig)
|
| 171 |
+
text.bind("<<cut>>", self.cut)
|
| 172 |
+
text.bind("<<copy>>", self.copy)
|
| 173 |
+
text.bind("<<paste>>", self.paste)
|
| 174 |
+
text.bind("<<center-insert>>", self.center_insert_event)
|
| 175 |
+
text.bind("<<help>>", self.help_dialog)
|
| 176 |
+
text.bind("<<python-docs>>", self.python_docs)
|
| 177 |
+
text.bind("<<about-idle>>", self.about_dialog)
|
| 178 |
+
text.bind("<<open-config-dialog>>", self.config_dialog)
|
| 179 |
+
text.bind("<<open-module>>", self.open_module_event)
|
| 180 |
+
text.bind("<<do-nothing>>", lambda event: "break")
|
| 181 |
+
text.bind("<<select-all>>", self.select_all)
|
| 182 |
+
text.bind("<<remove-selection>>", self.remove_selection)
|
| 183 |
+
text.bind("<<find>>", self.find_event)
|
| 184 |
+
text.bind("<<find-again>>", self.find_again_event)
|
| 185 |
+
text.bind("<<find-in-files>>", self.find_in_files_event)
|
| 186 |
+
text.bind("<<find-selection>>", self.find_selection_event)
|
| 187 |
+
text.bind("<<replace>>", self.replace_event)
|
| 188 |
+
text.bind("<<goto-line>>", self.goto_line_event)
|
| 189 |
+
text.bind("<<smart-backspace>>",self.smart_backspace_event)
|
| 190 |
+
text.bind("<<newline-and-indent>>",self.newline_and_indent_event)
|
| 191 |
+
text.bind("<<smart-indent>>",self.smart_indent_event)
|
| 192 |
+
self.fregion = fregion = self.FormatRegion(self)
|
| 193 |
+
# self.fregion used in smart_indent_event to access indent_region.
|
| 194 |
+
text.bind("<<indent-region>>", fregion.indent_region_event)
|
| 195 |
+
text.bind("<<dedent-region>>", fregion.dedent_region_event)
|
| 196 |
+
text.bind("<<comment-region>>", fregion.comment_region_event)
|
| 197 |
+
text.bind("<<uncomment-region>>", fregion.uncomment_region_event)
|
| 198 |
+
text.bind("<<tabify-region>>", fregion.tabify_region_event)
|
| 199 |
+
text.bind("<<untabify-region>>", fregion.untabify_region_event)
|
| 200 |
+
indents = self.Indents(self)
|
| 201 |
+
text.bind("<<toggle-tabs>>", indents.toggle_tabs_event)
|
| 202 |
+
text.bind("<<change-indentwidth>>", indents.change_indentwidth_event)
|
| 203 |
+
text.bind("<Left>", self.move_at_edge_if_selection(0))
|
| 204 |
+
text.bind("<Right>", self.move_at_edge_if_selection(1))
|
| 205 |
+
text.bind("<<del-word-left>>", self.del_word_left)
|
| 206 |
+
text.bind("<<del-word-right>>", self.del_word_right)
|
| 207 |
+
text.bind("<<beginning-of-line>>", self.home_callback)
|
| 208 |
+
|
| 209 |
+
if flist:
|
| 210 |
+
flist.inversedict[self] = key
|
| 211 |
+
if key:
|
| 212 |
+
flist.dict[key] = self
|
| 213 |
+
text.bind("<<open-new-window>>", self.new_callback)
|
| 214 |
+
text.bind("<<close-all-windows>>", self.flist.close_all_callback)
|
| 215 |
+
text.bind("<<open-class-browser>>", self.open_module_browser)
|
| 216 |
+
text.bind("<<open-path-browser>>", self.open_path_browser)
|
| 217 |
+
text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
|
| 218 |
+
|
| 219 |
+
self.set_status_bar()
|
| 220 |
+
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
|
| 221 |
+
text_frame.rowconfigure(1, weight=1)
|
| 222 |
+
text_frame.columnconfigure(1, weight=1)
|
| 223 |
+
vbar['command'] = self.handle_yview
|
| 224 |
+
vbar.grid(row=1, column=2, sticky=NSEW)
|
| 225 |
+
text['yscrollcommand'] = vbar.set
|
| 226 |
+
text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow')
|
| 227 |
+
text.grid(row=1, column=1, sticky=NSEW)
|
| 228 |
+
text.focus_set()
|
| 229 |
+
self.set_width()
|
| 230 |
+
|
| 231 |
+
# usetabs true -> literal tab characters are used by indent and
|
| 232 |
+
# dedent cmds, possibly mixed with spaces if
|
| 233 |
+
# indentwidth is not a multiple of tabwidth,
|
| 234 |
+
# which will cause Tabnanny to nag!
|
| 235 |
+
# false -> tab characters are converted to spaces by indent
|
| 236 |
+
# and dedent cmds, and ditto TAB keystrokes
|
| 237 |
+
# Although use-spaces=0 can be configured manually in config-main.def,
|
| 238 |
+
# configuration of tabs v. spaces is not supported in the configuration
|
| 239 |
+
# dialog. IDLE promotes the preferred Python indentation: use spaces!
|
| 240 |
+
usespaces = idleConf.GetOption('main', 'Indent',
|
| 241 |
+
'use-spaces', type='bool')
|
| 242 |
+
self.usetabs = not usespaces
|
| 243 |
+
|
| 244 |
+
# tabwidth is the display width of a literal tab character.
|
| 245 |
+
# CAUTION: telling Tk to use anything other than its default
|
| 246 |
+
# tab setting causes it to use an entirely different tabbing algorithm,
|
| 247 |
+
# treating tab stops as fixed distances from the left margin.
|
| 248 |
+
# Nobody expects this, so for now tabwidth should never be changed.
|
| 249 |
+
self.tabwidth = 8 # must remain 8 until Tk is fixed.
|
| 250 |
+
|
| 251 |
+
# indentwidth is the number of screen characters per indent level.
|
| 252 |
+
# The recommended Python indentation is four spaces.
|
| 253 |
+
self.indentwidth = self.tabwidth
|
| 254 |
+
self.set_notabs_indentwidth()
|
| 255 |
+
|
| 256 |
+
# Store the current value of the insertofftime now so we can restore
|
| 257 |
+
# it if needed.
|
| 258 |
+
if not hasattr(idleConf, 'blink_off_time'):
|
| 259 |
+
idleConf.blink_off_time = self.text['insertofftime']
|
| 260 |
+
self.update_cursor_blink()
|
| 261 |
+
|
| 262 |
+
# When searching backwards for a reliable place to begin parsing,
|
| 263 |
+
# first start num_context_lines[0] lines back, then
|
| 264 |
+
# num_context_lines[1] lines back if that didn't work, and so on.
|
| 265 |
+
# The last value should be huge (larger than the # of lines in a
|
| 266 |
+
# conceivable file).
|
| 267 |
+
# Making the initial values larger slows things down more often.
|
| 268 |
+
self.num_context_lines = 50, 500, 5000000
|
| 269 |
+
self.per = per = self.Percolator(text)
|
| 270 |
+
self.undo = undo = self.UndoDelegator()
|
| 271 |
+
per.insertfilter(undo)
|
| 272 |
+
text.undo_block_start = undo.undo_block_start
|
| 273 |
+
text.undo_block_stop = undo.undo_block_stop
|
| 274 |
+
undo.set_saved_change_hook(self.saved_change_hook)
|
| 275 |
+
# IOBinding implements file I/O and printing functionality
|
| 276 |
+
self.io = io = self.IOBinding(self)
|
| 277 |
+
io.set_filename_change_hook(self.filename_change_hook)
|
| 278 |
+
self.good_load = False
|
| 279 |
+
self.set_indentation_params(False)
|
| 280 |
+
self.color = None # initialized below in self.ResetColorizer
|
| 281 |
+
self.code_context = None # optionally initialized later below
|
| 282 |
+
self.line_numbers = None # optionally initialized later below
|
| 283 |
+
if filename:
|
| 284 |
+
if os.path.exists(filename) and not os.path.isdir(filename):
|
| 285 |
+
if io.loadfile(filename):
|
| 286 |
+
self.good_load = True
|
| 287 |
+
is_py_src = self.ispythonsource(filename)
|
| 288 |
+
self.set_indentation_params(is_py_src)
|
| 289 |
+
else:
|
| 290 |
+
io.set_filename(filename)
|
| 291 |
+
self.good_load = True
|
| 292 |
+
|
| 293 |
+
self.ResetColorizer()
|
| 294 |
+
self.saved_change_hook()
|
| 295 |
+
self.update_recent_files_list()
|
| 296 |
+
self.load_extensions()
|
| 297 |
+
menu = self.menudict.get('window')
|
| 298 |
+
if menu:
|
| 299 |
+
end = menu.index("end")
|
| 300 |
+
if end is None:
|
| 301 |
+
end = -1
|
| 302 |
+
if end >= 0:
|
| 303 |
+
menu.add_separator()
|
| 304 |
+
end = end + 1
|
| 305 |
+
self.wmenu_end = end
|
| 306 |
+
window.register_callback(self.postwindowsmenu)
|
| 307 |
+
|
| 308 |
+
# Some abstractions so IDLE extensions are cross-IDE
|
| 309 |
+
self.askinteger = simpledialog.askinteger
|
| 310 |
+
self.askyesno = messagebox.askyesno
|
| 311 |
+
self.showerror = messagebox.showerror
|
| 312 |
+
|
| 313 |
+
# Add pseudoevents for former extension fixed keys.
|
| 314 |
+
# (This probably needs to be done once in the process.)
|
| 315 |
+
text.event_add('<<autocomplete>>', '<Key-Tab>')
|
| 316 |
+
text.event_add('<<try-open-completions>>', '<KeyRelease-period>',
|
| 317 |
+
'<KeyRelease-slash>', '<KeyRelease-backslash>')
|
| 318 |
+
text.event_add('<<try-open-calltip>>', '<KeyRelease-parenleft>')
|
| 319 |
+
text.event_add('<<refresh-calltip>>', '<KeyRelease-parenright>')
|
| 320 |
+
text.event_add('<<paren-closed>>', '<KeyRelease-parenright>',
|
| 321 |
+
'<KeyRelease-bracketright>', '<KeyRelease-braceright>')
|
| 322 |
+
|
| 323 |
+
# Former extension bindings depends on frame.text being packed
|
| 324 |
+
# (called from self.ResetColorizer()).
|
| 325 |
+
autocomplete = self.AutoComplete(self, self.user_input_insert_tags)
|
| 326 |
+
text.bind("<<autocomplete>>", autocomplete.autocomplete_event)
|
| 327 |
+
text.bind("<<try-open-completions>>",
|
| 328 |
+
autocomplete.try_open_completions_event)
|
| 329 |
+
text.bind("<<force-open-completions>>",
|
| 330 |
+
autocomplete.force_open_completions_event)
|
| 331 |
+
text.bind("<<expand-word>>", self.AutoExpand(self).expand_word_event)
|
| 332 |
+
text.bind("<<format-paragraph>>",
|
| 333 |
+
self.FormatParagraph(self).format_paragraph_event)
|
| 334 |
+
parenmatch = self.ParenMatch(self)
|
| 335 |
+
text.bind("<<flash-paren>>", parenmatch.flash_paren_event)
|
| 336 |
+
text.bind("<<paren-closed>>", parenmatch.paren_closed_event)
|
| 337 |
+
scriptbinding = ScriptBinding(self)
|
| 338 |
+
text.bind("<<check-module>>", scriptbinding.check_module_event)
|
| 339 |
+
text.bind("<<run-module>>", scriptbinding.run_module_event)
|
| 340 |
+
text.bind("<<run-custom>>", scriptbinding.run_custom_event)
|
| 341 |
+
text.bind("<<do-rstrip>>", self.Rstrip(self).do_rstrip)
|
| 342 |
+
self.ctip = ctip = self.Calltip(self)
|
| 343 |
+
text.bind("<<try-open-calltip>>", ctip.try_open_calltip_event)
|
| 344 |
+
#refresh-calltip must come after paren-closed to work right
|
| 345 |
+
text.bind("<<refresh-calltip>>", ctip.refresh_calltip_event)
|
| 346 |
+
text.bind("<<force-open-calltip>>", ctip.force_open_calltip_event)
|
| 347 |
+
text.bind("<<zoom-height>>", self.ZoomHeight(self).zoom_height_event)
|
| 348 |
+
if self.allow_code_context:
|
| 349 |
+
self.code_context = self.CodeContext(self)
|
| 350 |
+
text.bind("<<toggle-code-context>>",
|
| 351 |
+
self.code_context.toggle_code_context_event)
|
| 352 |
+
else:
|
| 353 |
+
self.update_menu_state('options', '*ode*ontext', 'disabled')
|
| 354 |
+
if self.allow_line_numbers:
|
| 355 |
+
self.line_numbers = self.LineNumbers(self)
|
| 356 |
+
if idleConf.GetOption('main', 'EditorWindow',
|
| 357 |
+
'line-numbers-default', type='bool'):
|
| 358 |
+
self.toggle_line_numbers_event()
|
| 359 |
+
text.bind("<<toggle-line-numbers>>", self.toggle_line_numbers_event)
|
| 360 |
+
else:
|
| 361 |
+
self.update_menu_state('options', '*ine*umbers', 'disabled')
|
| 362 |
+
|
| 363 |
+
def handle_winconfig(self, event=None):
|
| 364 |
+
self.set_width()
|
| 365 |
+
|
| 366 |
+
def set_width(self):
|
| 367 |
+
text = self.text
|
| 368 |
+
inner_padding = sum(map(text.tk.getint, [text.cget('border'),
|
| 369 |
+
text.cget('padx')]))
|
| 370 |
+
pixel_width = text.winfo_width() - 2 * inner_padding
|
| 371 |
+
|
| 372 |
+
# Divide the width of the Text widget by the font width,
|
| 373 |
+
# which is taken to be the width of '0' (zero).
|
| 374 |
+
# http://www.tcl.tk/man/tcl8.6/TkCmd/text.htm#M21
|
| 375 |
+
zero_char_width = \
|
| 376 |
+
Font(text, font=text.cget('font')).measure('0')
|
| 377 |
+
self.width = pixel_width // zero_char_width
|
| 378 |
+
|
| 379 |
+
def new_callback(self, event):
|
| 380 |
+
dirname, basename = self.io.defaultfilename()
|
| 381 |
+
self.flist.new(dirname)
|
| 382 |
+
return "break"
|
| 383 |
+
|
| 384 |
+
def home_callback(self, event):
|
| 385 |
+
if (event.state & 4) != 0 and event.keysym == "Home":
|
| 386 |
+
# state&4==Control. If <Control-Home>, use the Tk binding.
|
| 387 |
+
return None
|
| 388 |
+
if self.text.index("iomark") and \
|
| 389 |
+
self.text.compare("iomark", "<=", "insert lineend") and \
|
| 390 |
+
self.text.compare("insert linestart", "<=", "iomark"):
|
| 391 |
+
# In Shell on input line, go to just after prompt
|
| 392 |
+
insertpt = int(self.text.index("iomark").split(".")[1])
|
| 393 |
+
else:
|
| 394 |
+
line = self.text.get("insert linestart", "insert lineend")
|
| 395 |
+
for insertpt in range(len(line)):
|
| 396 |
+
if line[insertpt] not in (' ','\t'):
|
| 397 |
+
break
|
| 398 |
+
else:
|
| 399 |
+
insertpt=len(line)
|
| 400 |
+
lineat = int(self.text.index("insert").split('.')[1])
|
| 401 |
+
if insertpt == lineat:
|
| 402 |
+
insertpt = 0
|
| 403 |
+
dest = "insert linestart+"+str(insertpt)+"c"
|
| 404 |
+
if (event.state&1) == 0:
|
| 405 |
+
# shift was not pressed
|
| 406 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 407 |
+
else:
|
| 408 |
+
if not self.text.index("sel.first"):
|
| 409 |
+
# there was no previous selection
|
| 410 |
+
self.text.mark_set("my_anchor", "insert")
|
| 411 |
+
else:
|
| 412 |
+
if self.text.compare(self.text.index("sel.first"), "<",
|
| 413 |
+
self.text.index("insert")):
|
| 414 |
+
self.text.mark_set("my_anchor", "sel.first") # extend back
|
| 415 |
+
else:
|
| 416 |
+
self.text.mark_set("my_anchor", "sel.last") # extend forward
|
| 417 |
+
first = self.text.index(dest)
|
| 418 |
+
last = self.text.index("my_anchor")
|
| 419 |
+
if self.text.compare(first,">",last):
|
| 420 |
+
first,last = last,first
|
| 421 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 422 |
+
self.text.tag_add("sel", first, last)
|
| 423 |
+
self.text.mark_set("insert", dest)
|
| 424 |
+
self.text.see("insert")
|
| 425 |
+
return "break"
|
| 426 |
+
|
| 427 |
+
def set_status_bar(self):
|
| 428 |
+
self.status_bar = self.MultiStatusBar(self.top)
|
| 429 |
+
sep = Frame(self.top, height=1, borderwidth=1, background='grey75')
|
| 430 |
+
if sys.platform == "darwin":
|
| 431 |
+
# Insert some padding to avoid obscuring some of the statusbar
|
| 432 |
+
# by the resize widget.
|
| 433 |
+
self.status_bar.set_label('_padding1', ' ', side=RIGHT)
|
| 434 |
+
self.status_bar.set_label('column', 'Col: ?', side=RIGHT)
|
| 435 |
+
self.status_bar.set_label('line', 'Ln: ?', side=RIGHT)
|
| 436 |
+
self.status_bar.pack(side=BOTTOM, fill=X)
|
| 437 |
+
sep.pack(side=BOTTOM, fill=X)
|
| 438 |
+
self.text.bind("<<set-line-and-column>>", self.set_line_and_column)
|
| 439 |
+
self.text.event_add("<<set-line-and-column>>",
|
| 440 |
+
"<KeyRelease>", "<ButtonRelease>")
|
| 441 |
+
self.text.after_idle(self.set_line_and_column)
|
| 442 |
+
|
| 443 |
+
def set_line_and_column(self, event=None):
|
| 444 |
+
line, column = self.text.index(INSERT).split('.')
|
| 445 |
+
self.status_bar.set_label('column', 'Col: %s' % column)
|
| 446 |
+
self.status_bar.set_label('line', 'Ln: %s' % line)
|
| 447 |
+
|
| 448 |
+
menu_specs = [
|
| 449 |
+
("file", "_File"),
|
| 450 |
+
("edit", "_Edit"),
|
| 451 |
+
("format", "F_ormat"),
|
| 452 |
+
("run", "_Run"),
|
| 453 |
+
("options", "_Options"),
|
| 454 |
+
("window", "_Window"),
|
| 455 |
+
("help", "_Help"),
|
| 456 |
+
]
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
def createmenubar(self):
|
| 460 |
+
mbar = self.menubar
|
| 461 |
+
self.menudict = menudict = {}
|
| 462 |
+
for name, label in self.menu_specs:
|
| 463 |
+
underline, label = prepstr(label)
|
| 464 |
+
postcommand = getattr(self, f'{name}_menu_postcommand', None)
|
| 465 |
+
menudict[name] = menu = Menu(mbar, name=name, tearoff=0,
|
| 466 |
+
postcommand=postcommand)
|
| 467 |
+
mbar.add_cascade(label=label, menu=menu, underline=underline)
|
| 468 |
+
if macosx.isCarbonTk():
|
| 469 |
+
# Insert the application menu
|
| 470 |
+
menudict['application'] = menu = Menu(mbar, name='apple',
|
| 471 |
+
tearoff=0)
|
| 472 |
+
mbar.add_cascade(label='IDLE', menu=menu)
|
| 473 |
+
self.fill_menus()
|
| 474 |
+
self.recent_files_menu = Menu(self.menubar, tearoff=0)
|
| 475 |
+
self.menudict['file'].insert_cascade(3, label='Recent Files',
|
| 476 |
+
underline=0,
|
| 477 |
+
menu=self.recent_files_menu)
|
| 478 |
+
self.base_helpmenu_length = self.menudict['help'].index(END)
|
| 479 |
+
self.reset_help_menu_entries()
|
| 480 |
+
|
| 481 |
+
def postwindowsmenu(self):
|
| 482 |
+
# Only called when Window menu exists
|
| 483 |
+
menu = self.menudict['window']
|
| 484 |
+
end = menu.index("end")
|
| 485 |
+
if end is None:
|
| 486 |
+
end = -1
|
| 487 |
+
if end > self.wmenu_end:
|
| 488 |
+
menu.delete(self.wmenu_end+1, end)
|
| 489 |
+
window.add_windows_to_menu(menu)
|
| 490 |
+
|
| 491 |
+
def update_menu_label(self, menu, index, label):
|
| 492 |
+
"Update label for menu item at index."
|
| 493 |
+
menuitem = self.menudict[menu]
|
| 494 |
+
menuitem.entryconfig(index, label=label)
|
| 495 |
+
|
| 496 |
+
def update_menu_state(self, menu, index, state):
|
| 497 |
+
"Update state for menu item at index."
|
| 498 |
+
menuitem = self.menudict[menu]
|
| 499 |
+
menuitem.entryconfig(index, state=state)
|
| 500 |
+
|
| 501 |
+
def handle_yview(self, event, *args):
|
| 502 |
+
"Handle scrollbar."
|
| 503 |
+
if event == 'moveto':
|
| 504 |
+
fraction = float(args[0])
|
| 505 |
+
lines = (round(self.getlineno('end') * fraction) -
|
| 506 |
+
self.getlineno('@0,0'))
|
| 507 |
+
event = 'scroll'
|
| 508 |
+
args = (lines, 'units')
|
| 509 |
+
self.text.yview(event, *args)
|
| 510 |
+
return 'break'
|
| 511 |
+
|
| 512 |
+
rmenu = None
|
| 513 |
+
|
| 514 |
+
def right_menu_event(self, event):
|
| 515 |
+
text = self.text
|
| 516 |
+
newdex = text.index(f'@{event.x},{event.y}')
|
| 517 |
+
try:
|
| 518 |
+
in_selection = (text.compare('sel.first', '<=', newdex) and
|
| 519 |
+
text.compare(newdex, '<=', 'sel.last'))
|
| 520 |
+
except TclError:
|
| 521 |
+
in_selection = False
|
| 522 |
+
if not in_selection:
|
| 523 |
+
text.tag_remove("sel", "1.0", "end")
|
| 524 |
+
text.mark_set("insert", newdex)
|
| 525 |
+
if not self.rmenu:
|
| 526 |
+
self.make_rmenu()
|
| 527 |
+
rmenu = self.rmenu
|
| 528 |
+
self.event = event
|
| 529 |
+
iswin = sys.platform[:3] == 'win'
|
| 530 |
+
if iswin:
|
| 531 |
+
text.config(cursor="arrow")
|
| 532 |
+
|
| 533 |
+
for item in self.rmenu_specs:
|
| 534 |
+
try:
|
| 535 |
+
label, eventname, verify_state = item
|
| 536 |
+
except ValueError: # see issue1207589
|
| 537 |
+
continue
|
| 538 |
+
|
| 539 |
+
if verify_state is None:
|
| 540 |
+
continue
|
| 541 |
+
state = getattr(self, verify_state)()
|
| 542 |
+
rmenu.entryconfigure(label, state=state)
|
| 543 |
+
|
| 544 |
+
rmenu.tk_popup(event.x_root, event.y_root)
|
| 545 |
+
if iswin:
|
| 546 |
+
self.text.config(cursor="ibeam")
|
| 547 |
+
return "break"
|
| 548 |
+
|
| 549 |
+
rmenu_specs = [
|
| 550 |
+
# ("Label", "<<virtual-event>>", "statefuncname"), ...
|
| 551 |
+
("Close", "<<close-window>>", None), # Example
|
| 552 |
+
]
|
| 553 |
+
|
| 554 |
+
def make_rmenu(self):
|
| 555 |
+
rmenu = Menu(self.text, tearoff=0)
|
| 556 |
+
for item in self.rmenu_specs:
|
| 557 |
+
label, eventname = item[0], item[1]
|
| 558 |
+
if label is not None:
|
| 559 |
+
def command(text=self.text, eventname=eventname):
|
| 560 |
+
text.event_generate(eventname)
|
| 561 |
+
rmenu.add_command(label=label, command=command)
|
| 562 |
+
else:
|
| 563 |
+
rmenu.add_separator()
|
| 564 |
+
self.rmenu = rmenu
|
| 565 |
+
|
| 566 |
+
def rmenu_check_cut(self):
|
| 567 |
+
return self.rmenu_check_copy()
|
| 568 |
+
|
| 569 |
+
def rmenu_check_copy(self):
|
| 570 |
+
try:
|
| 571 |
+
indx = self.text.index('sel.first')
|
| 572 |
+
except TclError:
|
| 573 |
+
return 'disabled'
|
| 574 |
+
else:
|
| 575 |
+
return 'normal' if indx else 'disabled'
|
| 576 |
+
|
| 577 |
+
def rmenu_check_paste(self):
|
| 578 |
+
try:
|
| 579 |
+
self.text.tk.call('tk::GetSelection', self.text, 'CLIPBOARD')
|
| 580 |
+
except TclError:
|
| 581 |
+
return 'disabled'
|
| 582 |
+
else:
|
| 583 |
+
return 'normal'
|
| 584 |
+
|
| 585 |
+
def about_dialog(self, event=None):
|
| 586 |
+
"Handle Help 'About IDLE' event."
|
| 587 |
+
# Synchronize with macosx.overrideRootMenu.about_dialog.
|
| 588 |
+
help_about.AboutDialog(self.top)
|
| 589 |
+
return "break"
|
| 590 |
+
|
| 591 |
+
def config_dialog(self, event=None):
|
| 592 |
+
"Handle Options 'Configure IDLE' event."
|
| 593 |
+
# Synchronize with macosx.overrideRootMenu.config_dialog.
|
| 594 |
+
configdialog.ConfigDialog(self.top,'Settings')
|
| 595 |
+
return "break"
|
| 596 |
+
|
| 597 |
+
def help_dialog(self, event=None):
|
| 598 |
+
"Handle Help 'IDLE Help' event."
|
| 599 |
+
# Synchronize with macosx.overrideRootMenu.help_dialog.
|
| 600 |
+
if self.root:
|
| 601 |
+
parent = self.root
|
| 602 |
+
else:
|
| 603 |
+
parent = self.top
|
| 604 |
+
help.show_idlehelp(parent)
|
| 605 |
+
return "break"
|
| 606 |
+
|
| 607 |
+
def python_docs(self, event=None):
|
| 608 |
+
if sys.platform[:3] == 'win':
|
| 609 |
+
try:
|
| 610 |
+
os.startfile(self.help_url)
|
| 611 |
+
except OSError as why:
|
| 612 |
+
messagebox.showerror(title='Document Start Failure',
|
| 613 |
+
message=str(why), parent=self.text)
|
| 614 |
+
else:
|
| 615 |
+
webbrowser.open(self.help_url)
|
| 616 |
+
return "break"
|
| 617 |
+
|
| 618 |
+
def cut(self,event):
|
| 619 |
+
self.text.event_generate("<<Cut>>")
|
| 620 |
+
return "break"
|
| 621 |
+
|
| 622 |
+
def copy(self,event):
|
| 623 |
+
if not self.text.tag_ranges("sel"):
|
| 624 |
+
# There is no selection, so do nothing and maybe interrupt.
|
| 625 |
+
return None
|
| 626 |
+
self.text.event_generate("<<Copy>>")
|
| 627 |
+
return "break"
|
| 628 |
+
|
| 629 |
+
def paste(self,event):
|
| 630 |
+
self.text.event_generate("<<Paste>>")
|
| 631 |
+
self.text.see("insert")
|
| 632 |
+
return "break"
|
| 633 |
+
|
| 634 |
+
def select_all(self, event=None):
|
| 635 |
+
self.text.tag_add("sel", "1.0", "end-1c")
|
| 636 |
+
self.text.mark_set("insert", "1.0")
|
| 637 |
+
self.text.see("insert")
|
| 638 |
+
return "break"
|
| 639 |
+
|
| 640 |
+
def remove_selection(self, event=None):
|
| 641 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 642 |
+
self.text.see("insert")
|
| 643 |
+
return "break"
|
| 644 |
+
|
| 645 |
+
def move_at_edge_if_selection(self, edge_index):
|
| 646 |
+
"""Cursor move begins at start or end of selection
|
| 647 |
+
|
| 648 |
+
When a left/right cursor key is pressed create and return to Tkinter a
|
| 649 |
+
function which causes a cursor move from the associated edge of the
|
| 650 |
+
selection.
|
| 651 |
+
|
| 652 |
+
"""
|
| 653 |
+
self_text_index = self.text.index
|
| 654 |
+
self_text_mark_set = self.text.mark_set
|
| 655 |
+
edges_table = ("sel.first+1c", "sel.last-1c")
|
| 656 |
+
def move_at_edge(event):
|
| 657 |
+
if (event.state & 5) == 0: # no shift(==1) or control(==4) pressed
|
| 658 |
+
try:
|
| 659 |
+
self_text_index("sel.first")
|
| 660 |
+
self_text_mark_set("insert", edges_table[edge_index])
|
| 661 |
+
except TclError:
|
| 662 |
+
pass
|
| 663 |
+
return move_at_edge
|
| 664 |
+
|
| 665 |
+
def del_word_left(self, event):
|
| 666 |
+
self.text.event_generate('<Meta-Delete>')
|
| 667 |
+
return "break"
|
| 668 |
+
|
| 669 |
+
def del_word_right(self, event):
|
| 670 |
+
self.text.event_generate('<Meta-d>')
|
| 671 |
+
return "break"
|
| 672 |
+
|
| 673 |
+
def find_event(self, event):
|
| 674 |
+
search.find(self.text)
|
| 675 |
+
return "break"
|
| 676 |
+
|
| 677 |
+
def find_again_event(self, event):
|
| 678 |
+
search.find_again(self.text)
|
| 679 |
+
return "break"
|
| 680 |
+
|
| 681 |
+
def find_selection_event(self, event):
|
| 682 |
+
search.find_selection(self.text)
|
| 683 |
+
return "break"
|
| 684 |
+
|
| 685 |
+
def find_in_files_event(self, event):
|
| 686 |
+
grep.grep(self.text, self.io, self.flist)
|
| 687 |
+
return "break"
|
| 688 |
+
|
| 689 |
+
def replace_event(self, event):
|
| 690 |
+
replace.replace(self.text)
|
| 691 |
+
return "break"
|
| 692 |
+
|
| 693 |
+
def goto_line_event(self, event):
|
| 694 |
+
text = self.text
|
| 695 |
+
lineno = query.Goto(
|
| 696 |
+
text, "Go To Line",
|
| 697 |
+
"Enter a positive integer\n"
|
| 698 |
+
"('big' = end of file):"
|
| 699 |
+
).result
|
| 700 |
+
if lineno is not None:
|
| 701 |
+
text.tag_remove("sel", "1.0", "end")
|
| 702 |
+
text.mark_set("insert", f'{lineno}.0')
|
| 703 |
+
text.see("insert")
|
| 704 |
+
self.set_line_and_column()
|
| 705 |
+
return "break"
|
| 706 |
+
|
| 707 |
+
def open_module(self):
|
| 708 |
+
"""Get module name from user and open it.
|
| 709 |
+
|
| 710 |
+
Return module path or None for calls by open_module_browser
|
| 711 |
+
when latter is not invoked in named editor window.
|
| 712 |
+
"""
|
| 713 |
+
# XXX This, open_module_browser, and open_path_browser
|
| 714 |
+
# would fit better in iomenu.IOBinding.
|
| 715 |
+
try:
|
| 716 |
+
name = self.text.get("sel.first", "sel.last").strip()
|
| 717 |
+
except TclError:
|
| 718 |
+
name = ''
|
| 719 |
+
file_path = query.ModuleName(
|
| 720 |
+
self.text, "Open Module",
|
| 721 |
+
"Enter the name of a Python module\n"
|
| 722 |
+
"to search on sys.path and open:",
|
| 723 |
+
name).result
|
| 724 |
+
if file_path is not None:
|
| 725 |
+
if self.flist:
|
| 726 |
+
self.flist.open(file_path)
|
| 727 |
+
else:
|
| 728 |
+
self.io.loadfile(file_path)
|
| 729 |
+
return file_path
|
| 730 |
+
|
| 731 |
+
def open_module_event(self, event):
|
| 732 |
+
self.open_module()
|
| 733 |
+
return "break"
|
| 734 |
+
|
| 735 |
+
def open_module_browser(self, event=None):
|
| 736 |
+
filename = self.io.filename
|
| 737 |
+
if not (self.__class__.__name__ == 'PyShellEditorWindow'
|
| 738 |
+
and filename):
|
| 739 |
+
filename = self.open_module()
|
| 740 |
+
if filename is None:
|
| 741 |
+
return "break"
|
| 742 |
+
from idlelib import browser
|
| 743 |
+
browser.ModuleBrowser(self.root, filename)
|
| 744 |
+
return "break"
|
| 745 |
+
|
| 746 |
+
def open_path_browser(self, event=None):
|
| 747 |
+
from idlelib import pathbrowser
|
| 748 |
+
pathbrowser.PathBrowser(self.root)
|
| 749 |
+
return "break"
|
| 750 |
+
|
| 751 |
+
def open_turtle_demo(self, event = None):
|
| 752 |
+
import subprocess
|
| 753 |
+
|
| 754 |
+
cmd = [sys.executable,
|
| 755 |
+
'-c',
|
| 756 |
+
'from turtledemo.__main__ import main; main()']
|
| 757 |
+
subprocess.Popen(cmd, shell=False)
|
| 758 |
+
return "break"
|
| 759 |
+
|
| 760 |
+
def gotoline(self, lineno):
|
| 761 |
+
if lineno is not None and lineno > 0:
|
| 762 |
+
self.text.mark_set("insert", "%d.0" % lineno)
|
| 763 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 764 |
+
self.text.tag_add("sel", "insert", "insert +1l")
|
| 765 |
+
self.center()
|
| 766 |
+
|
| 767 |
+
def ispythonsource(self, filename):
|
| 768 |
+
if not filename or os.path.isdir(filename):
|
| 769 |
+
return True
|
| 770 |
+
base, ext = os.path.splitext(os.path.basename(filename))
|
| 771 |
+
if os.path.normcase(ext) in py_extensions:
|
| 772 |
+
return True
|
| 773 |
+
line = self.text.get('1.0', '1.0 lineend')
|
| 774 |
+
return line.startswith('#!') and 'python' in line
|
| 775 |
+
|
| 776 |
+
def close_hook(self):
|
| 777 |
+
if self.flist:
|
| 778 |
+
self.flist.unregister_maybe_terminate(self)
|
| 779 |
+
self.flist = None
|
| 780 |
+
|
| 781 |
+
def set_close_hook(self, close_hook):
|
| 782 |
+
self.close_hook = close_hook
|
| 783 |
+
|
| 784 |
+
def filename_change_hook(self):
|
| 785 |
+
if self.flist:
|
| 786 |
+
self.flist.filename_changed_edit(self)
|
| 787 |
+
self.saved_change_hook()
|
| 788 |
+
self.top.update_windowlist_registry(self)
|
| 789 |
+
self.ResetColorizer()
|
| 790 |
+
|
| 791 |
+
def _addcolorizer(self):
|
| 792 |
+
if self.color:
|
| 793 |
+
return
|
| 794 |
+
if self.ispythonsource(self.io.filename):
|
| 795 |
+
self.color = self.ColorDelegator()
|
| 796 |
+
# can add more colorizers here...
|
| 797 |
+
if self.color:
|
| 798 |
+
self.per.insertfilterafter(filter=self.color, after=self.undo)
|
| 799 |
+
|
| 800 |
+
def _rmcolorizer(self):
|
| 801 |
+
if not self.color:
|
| 802 |
+
return
|
| 803 |
+
self.color.removecolors()
|
| 804 |
+
self.per.removefilter(self.color)
|
| 805 |
+
self.color = None
|
| 806 |
+
|
| 807 |
+
def ResetColorizer(self):
|
| 808 |
+
"Update the color theme"
|
| 809 |
+
# Called from self.filename_change_hook and from configdialog.py
|
| 810 |
+
self._rmcolorizer()
|
| 811 |
+
self._addcolorizer()
|
| 812 |
+
EditorWindow.color_config(self.text)
|
| 813 |
+
|
| 814 |
+
if self.code_context is not None:
|
| 815 |
+
self.code_context.update_highlight_colors()
|
| 816 |
+
|
| 817 |
+
if self.line_numbers is not None:
|
| 818 |
+
self.line_numbers.update_colors()
|
| 819 |
+
|
| 820 |
+
IDENTCHARS = string.ascii_letters + string.digits + "_"
|
| 821 |
+
|
| 822 |
+
def colorize_syntax_error(self, text, pos):
|
| 823 |
+
text.tag_add("ERROR", pos)
|
| 824 |
+
char = text.get(pos)
|
| 825 |
+
if char and char in self.IDENTCHARS:
|
| 826 |
+
text.tag_add("ERROR", pos + " wordstart", pos)
|
| 827 |
+
if '\n' == text.get(pos): # error at line end
|
| 828 |
+
text.mark_set("insert", pos)
|
| 829 |
+
else:
|
| 830 |
+
text.mark_set("insert", pos + "+1c")
|
| 831 |
+
text.see(pos)
|
| 832 |
+
|
| 833 |
+
def update_cursor_blink(self):
|
| 834 |
+
"Update the cursor blink configuration."
|
| 835 |
+
cursorblink = idleConf.GetOption(
|
| 836 |
+
'main', 'EditorWindow', 'cursor-blink', type='bool')
|
| 837 |
+
if not cursorblink:
|
| 838 |
+
self.text['insertofftime'] = 0
|
| 839 |
+
else:
|
| 840 |
+
# Restore the original value
|
| 841 |
+
self.text['insertofftime'] = idleConf.blink_off_time
|
| 842 |
+
|
| 843 |
+
def ResetFont(self):
|
| 844 |
+
"Update the text widgets' font if it is changed"
|
| 845 |
+
# Called from configdialog.py
|
| 846 |
+
|
| 847 |
+
# Update the code context widget first, since its height affects
|
| 848 |
+
# the height of the text widget. This avoids double re-rendering.
|
| 849 |
+
if self.code_context is not None:
|
| 850 |
+
self.code_context.update_font()
|
| 851 |
+
# Next, update the line numbers widget, since its width affects
|
| 852 |
+
# the width of the text widget.
|
| 853 |
+
if self.line_numbers is not None:
|
| 854 |
+
self.line_numbers.update_font()
|
| 855 |
+
# Finally, update the main text widget.
|
| 856 |
+
new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow')
|
| 857 |
+
self.text['font'] = new_font
|
| 858 |
+
self.set_width()
|
| 859 |
+
|
| 860 |
+
def RemoveKeybindings(self):
|
| 861 |
+
"Remove the keybindings before they are changed."
|
| 862 |
+
# Called from configdialog.py
|
| 863 |
+
self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
|
| 864 |
+
for event, keylist in keydefs.items():
|
| 865 |
+
self.text.event_delete(event, *keylist)
|
| 866 |
+
for extensionName in self.get_standard_extension_names():
|
| 867 |
+
xkeydefs = idleConf.GetExtensionBindings(extensionName)
|
| 868 |
+
if xkeydefs:
|
| 869 |
+
for event, keylist in xkeydefs.items():
|
| 870 |
+
self.text.event_delete(event, *keylist)
|
| 871 |
+
|
| 872 |
+
def ApplyKeybindings(self):
|
| 873 |
+
"Update the keybindings after they are changed"
|
| 874 |
+
# Called from configdialog.py
|
| 875 |
+
self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
|
| 876 |
+
self.apply_bindings()
|
| 877 |
+
for extensionName in self.get_standard_extension_names():
|
| 878 |
+
xkeydefs = idleConf.GetExtensionBindings(extensionName)
|
| 879 |
+
if xkeydefs:
|
| 880 |
+
self.apply_bindings(xkeydefs)
|
| 881 |
+
#update menu accelerators
|
| 882 |
+
menuEventDict = {}
|
| 883 |
+
for menu in self.mainmenu.menudefs:
|
| 884 |
+
menuEventDict[menu[0]] = {}
|
| 885 |
+
for item in menu[1]:
|
| 886 |
+
if item:
|
| 887 |
+
menuEventDict[menu[0]][prepstr(item[0])[1]] = item[1]
|
| 888 |
+
for menubarItem in self.menudict:
|
| 889 |
+
menu = self.menudict[menubarItem]
|
| 890 |
+
end = menu.index(END)
|
| 891 |
+
if end is None:
|
| 892 |
+
# Skip empty menus
|
| 893 |
+
continue
|
| 894 |
+
end += 1
|
| 895 |
+
for index in range(0, end):
|
| 896 |
+
if menu.type(index) == 'command':
|
| 897 |
+
accel = menu.entrycget(index, 'accelerator')
|
| 898 |
+
if accel:
|
| 899 |
+
itemName = menu.entrycget(index, 'label')
|
| 900 |
+
event = ''
|
| 901 |
+
if menubarItem in menuEventDict:
|
| 902 |
+
if itemName in menuEventDict[menubarItem]:
|
| 903 |
+
event = menuEventDict[menubarItem][itemName]
|
| 904 |
+
if event:
|
| 905 |
+
accel = get_accelerator(keydefs, event)
|
| 906 |
+
menu.entryconfig(index, accelerator=accel)
|
| 907 |
+
|
| 908 |
+
def set_notabs_indentwidth(self):
|
| 909 |
+
"Update the indentwidth if changed and not using tabs in this window"
|
| 910 |
+
# Called from configdialog.py
|
| 911 |
+
if not self.usetabs:
|
| 912 |
+
self.indentwidth = idleConf.GetOption('main', 'Indent','num-spaces',
|
| 913 |
+
type='int')
|
| 914 |
+
|
| 915 |
+
def reset_help_menu_entries(self):
|
| 916 |
+
"Update the additional help entries on the Help menu"
|
| 917 |
+
help_list = idleConf.GetAllExtraHelpSourcesList()
|
| 918 |
+
helpmenu = self.menudict['help']
|
| 919 |
+
# first delete the extra help entries, if any
|
| 920 |
+
helpmenu_length = helpmenu.index(END)
|
| 921 |
+
if helpmenu_length > self.base_helpmenu_length:
|
| 922 |
+
helpmenu.delete((self.base_helpmenu_length + 1), helpmenu_length)
|
| 923 |
+
# then rebuild them
|
| 924 |
+
if help_list:
|
| 925 |
+
helpmenu.add_separator()
|
| 926 |
+
for entry in help_list:
|
| 927 |
+
cmd = self.__extra_help_callback(entry[1])
|
| 928 |
+
helpmenu.add_command(label=entry[0], command=cmd)
|
| 929 |
+
# and update the menu dictionary
|
| 930 |
+
self.menudict['help'] = helpmenu
|
| 931 |
+
|
| 932 |
+
def __extra_help_callback(self, helpfile):
|
| 933 |
+
"Create a callback with the helpfile value frozen at definition time"
|
| 934 |
+
def display_extra_help(helpfile=helpfile):
|
| 935 |
+
if not helpfile.startswith(('www', 'http')):
|
| 936 |
+
helpfile = os.path.normpath(helpfile)
|
| 937 |
+
if sys.platform[:3] == 'win':
|
| 938 |
+
try:
|
| 939 |
+
os.startfile(helpfile)
|
| 940 |
+
except OSError as why:
|
| 941 |
+
messagebox.showerror(title='Document Start Failure',
|
| 942 |
+
message=str(why), parent=self.text)
|
| 943 |
+
else:
|
| 944 |
+
webbrowser.open(helpfile)
|
| 945 |
+
return display_extra_help
|
| 946 |
+
|
| 947 |
+
def update_recent_files_list(self, new_file=None):
|
| 948 |
+
"Load and update the recent files list and menus"
|
| 949 |
+
# TODO: move to iomenu.
|
| 950 |
+
rf_list = []
|
| 951 |
+
file_path = self.recent_files_path
|
| 952 |
+
if file_path and os.path.exists(file_path):
|
| 953 |
+
with open(file_path, 'r',
|
| 954 |
+
encoding='utf_8', errors='replace') as rf_list_file:
|
| 955 |
+
rf_list = rf_list_file.readlines()
|
| 956 |
+
if new_file:
|
| 957 |
+
new_file = os.path.abspath(new_file) + '\n'
|
| 958 |
+
if new_file in rf_list:
|
| 959 |
+
rf_list.remove(new_file) # move to top
|
| 960 |
+
rf_list.insert(0, new_file)
|
| 961 |
+
# clean and save the recent files list
|
| 962 |
+
bad_paths = []
|
| 963 |
+
for path in rf_list:
|
| 964 |
+
if '\0' in path or not os.path.exists(path[0:-1]):
|
| 965 |
+
bad_paths.append(path)
|
| 966 |
+
rf_list = [path for path in rf_list if path not in bad_paths]
|
| 967 |
+
ulchars = "1234567890ABCDEFGHIJK"
|
| 968 |
+
rf_list = rf_list[0:len(ulchars)]
|
| 969 |
+
if file_path:
|
| 970 |
+
try:
|
| 971 |
+
with open(file_path, 'w',
|
| 972 |
+
encoding='utf_8', errors='replace') as rf_file:
|
| 973 |
+
rf_file.writelines(rf_list)
|
| 974 |
+
except OSError as err:
|
| 975 |
+
if not getattr(self.root, "recentfiles_message", False):
|
| 976 |
+
self.root.recentfiles_message = True
|
| 977 |
+
messagebox.showwarning(title='IDLE Warning',
|
| 978 |
+
message="Cannot save Recent Files list to disk.\n"
|
| 979 |
+
f" {err}\n"
|
| 980 |
+
"Select OK to continue.",
|
| 981 |
+
parent=self.text)
|
| 982 |
+
# for each edit window instance, construct the recent files menu
|
| 983 |
+
for instance in self.top.instance_dict:
|
| 984 |
+
menu = instance.recent_files_menu
|
| 985 |
+
menu.delete(0, END) # clear, and rebuild:
|
| 986 |
+
for i, file_name in enumerate(rf_list):
|
| 987 |
+
file_name = file_name.rstrip() # zap \n
|
| 988 |
+
callback = instance.__recent_file_callback(file_name)
|
| 989 |
+
menu.add_command(label=ulchars[i] + " " + file_name,
|
| 990 |
+
command=callback,
|
| 991 |
+
underline=0)
|
| 992 |
+
|
| 993 |
+
def __recent_file_callback(self, file_name):
|
| 994 |
+
def open_recent_file(fn_closure=file_name):
|
| 995 |
+
self.io.open(editFile=fn_closure)
|
| 996 |
+
return open_recent_file
|
| 997 |
+
|
| 998 |
+
def saved_change_hook(self):
|
| 999 |
+
short = self.short_title()
|
| 1000 |
+
long = self.long_title()
|
| 1001 |
+
if short and long:
|
| 1002 |
+
title = short + " - " + long + _py_version
|
| 1003 |
+
elif short:
|
| 1004 |
+
title = short
|
| 1005 |
+
elif long:
|
| 1006 |
+
title = long
|
| 1007 |
+
else:
|
| 1008 |
+
title = "untitled"
|
| 1009 |
+
icon = short or long or title
|
| 1010 |
+
if not self.get_saved():
|
| 1011 |
+
title = "*%s*" % title
|
| 1012 |
+
icon = "*%s" % icon
|
| 1013 |
+
self.top.wm_title(title)
|
| 1014 |
+
self.top.wm_iconname(icon)
|
| 1015 |
+
|
| 1016 |
+
def get_saved(self):
|
| 1017 |
+
return self.undo.get_saved()
|
| 1018 |
+
|
| 1019 |
+
def set_saved(self, flag):
|
| 1020 |
+
self.undo.set_saved(flag)
|
| 1021 |
+
|
| 1022 |
+
def reset_undo(self):
|
| 1023 |
+
self.undo.reset_undo()
|
| 1024 |
+
|
| 1025 |
+
def short_title(self):
|
| 1026 |
+
filename = self.io.filename
|
| 1027 |
+
return os.path.basename(filename) if filename else "untitled"
|
| 1028 |
+
|
| 1029 |
+
def long_title(self):
|
| 1030 |
+
return self.io.filename or ""
|
| 1031 |
+
|
| 1032 |
+
def center_insert_event(self, event):
|
| 1033 |
+
self.center()
|
| 1034 |
+
return "break"
|
| 1035 |
+
|
| 1036 |
+
def center(self, mark="insert"):
|
| 1037 |
+
text = self.text
|
| 1038 |
+
top, bot = self.getwindowlines()
|
| 1039 |
+
lineno = self.getlineno(mark)
|
| 1040 |
+
height = bot - top
|
| 1041 |
+
newtop = max(1, lineno - height//2)
|
| 1042 |
+
text.yview(float(newtop))
|
| 1043 |
+
|
| 1044 |
+
def getwindowlines(self):
|
| 1045 |
+
text = self.text
|
| 1046 |
+
top = self.getlineno("@0,0")
|
| 1047 |
+
bot = self.getlineno("@0,65535")
|
| 1048 |
+
if top == bot and text.winfo_height() == 1:
|
| 1049 |
+
# Geometry manager hasn't run yet
|
| 1050 |
+
height = int(text['height'])
|
| 1051 |
+
bot = top + height - 1
|
| 1052 |
+
return top, bot
|
| 1053 |
+
|
| 1054 |
+
def getlineno(self, mark="insert"):
|
| 1055 |
+
text = self.text
|
| 1056 |
+
return int(float(text.index(mark)))
|
| 1057 |
+
|
| 1058 |
+
def get_geometry(self):
|
| 1059 |
+
"Return (width, height, x, y)"
|
| 1060 |
+
geom = self.top.wm_geometry()
|
| 1061 |
+
m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
|
| 1062 |
+
return list(map(int, m.groups()))
|
| 1063 |
+
|
| 1064 |
+
def close_event(self, event):
|
| 1065 |
+
self.close()
|
| 1066 |
+
return "break"
|
| 1067 |
+
|
| 1068 |
+
def maybesave(self):
|
| 1069 |
+
if self.io:
|
| 1070 |
+
if not self.get_saved():
|
| 1071 |
+
if self.top.state()!='normal':
|
| 1072 |
+
self.top.deiconify()
|
| 1073 |
+
self.top.lower()
|
| 1074 |
+
self.top.lift()
|
| 1075 |
+
return self.io.maybesave()
|
| 1076 |
+
|
| 1077 |
+
def close(self):
|
| 1078 |
+
try:
|
| 1079 |
+
reply = self.maybesave()
|
| 1080 |
+
if str(reply) != "cancel":
|
| 1081 |
+
self._close()
|
| 1082 |
+
return reply
|
| 1083 |
+
except AttributeError: # bpo-35379: close called twice
|
| 1084 |
+
pass
|
| 1085 |
+
|
| 1086 |
+
def _close(self):
|
| 1087 |
+
if self.io.filename:
|
| 1088 |
+
self.update_recent_files_list(new_file=self.io.filename)
|
| 1089 |
+
window.unregister_callback(self.postwindowsmenu)
|
| 1090 |
+
self.unload_extensions()
|
| 1091 |
+
self.io.close()
|
| 1092 |
+
self.io = None
|
| 1093 |
+
self.undo = None
|
| 1094 |
+
if self.color:
|
| 1095 |
+
self.color.close()
|
| 1096 |
+
self.color = None
|
| 1097 |
+
self.text = None
|
| 1098 |
+
self.tkinter_vars = None
|
| 1099 |
+
self.per.close()
|
| 1100 |
+
self.per = None
|
| 1101 |
+
self.top.destroy()
|
| 1102 |
+
if self.close_hook:
|
| 1103 |
+
# unless override: unregister from flist, terminate if last window
|
| 1104 |
+
self.close_hook()
|
| 1105 |
+
|
| 1106 |
+
def load_extensions(self):
|
| 1107 |
+
self.extensions = {}
|
| 1108 |
+
self.load_standard_extensions()
|
| 1109 |
+
|
| 1110 |
+
def unload_extensions(self):
|
| 1111 |
+
for ins in list(self.extensions.values()):
|
| 1112 |
+
if hasattr(ins, "close"):
|
| 1113 |
+
ins.close()
|
| 1114 |
+
self.extensions = {}
|
| 1115 |
+
|
| 1116 |
+
def load_standard_extensions(self):
|
| 1117 |
+
for name in self.get_standard_extension_names():
|
| 1118 |
+
try:
|
| 1119 |
+
self.load_extension(name)
|
| 1120 |
+
except:
|
| 1121 |
+
print("Failed to load extension", repr(name))
|
| 1122 |
+
traceback.print_exc()
|
| 1123 |
+
|
| 1124 |
+
def get_standard_extension_names(self):
|
| 1125 |
+
return idleConf.GetExtensions(editor_only=True)
|
| 1126 |
+
|
| 1127 |
+
extfiles = { # Map built-in config-extension section names to file names.
|
| 1128 |
+
'ZzDummy': 'zzdummy',
|
| 1129 |
+
}
|
| 1130 |
+
|
| 1131 |
+
def load_extension(self, name):
|
| 1132 |
+
fname = self.extfiles.get(name, name)
|
| 1133 |
+
try:
|
| 1134 |
+
try:
|
| 1135 |
+
mod = importlib.import_module('.' + fname, package=__package__)
|
| 1136 |
+
except (ImportError, TypeError):
|
| 1137 |
+
mod = importlib.import_module(fname)
|
| 1138 |
+
except ImportError:
|
| 1139 |
+
print("\nFailed to import extension: ", name)
|
| 1140 |
+
raise
|
| 1141 |
+
cls = getattr(mod, name)
|
| 1142 |
+
keydefs = idleConf.GetExtensionBindings(name)
|
| 1143 |
+
if hasattr(cls, "menudefs"):
|
| 1144 |
+
self.fill_menus(cls.menudefs, keydefs)
|
| 1145 |
+
ins = cls(self)
|
| 1146 |
+
self.extensions[name] = ins
|
| 1147 |
+
if keydefs:
|
| 1148 |
+
self.apply_bindings(keydefs)
|
| 1149 |
+
for vevent in keydefs:
|
| 1150 |
+
methodname = vevent.replace("-", "_")
|
| 1151 |
+
while methodname[:1] == '<':
|
| 1152 |
+
methodname = methodname[1:]
|
| 1153 |
+
while methodname[-1:] == '>':
|
| 1154 |
+
methodname = methodname[:-1]
|
| 1155 |
+
methodname = methodname + "_event"
|
| 1156 |
+
if hasattr(ins, methodname):
|
| 1157 |
+
self.text.bind(vevent, getattr(ins, methodname))
|
| 1158 |
+
|
| 1159 |
+
def apply_bindings(self, keydefs=None):
|
| 1160 |
+
if keydefs is None:
|
| 1161 |
+
keydefs = self.mainmenu.default_keydefs
|
| 1162 |
+
text = self.text
|
| 1163 |
+
text.keydefs = keydefs
|
| 1164 |
+
for event, keylist in keydefs.items():
|
| 1165 |
+
if keylist:
|
| 1166 |
+
text.event_add(event, *keylist)
|
| 1167 |
+
|
| 1168 |
+
def fill_menus(self, menudefs=None, keydefs=None):
|
| 1169 |
+
"""Add appropriate entries to the menus and submenus
|
| 1170 |
+
|
| 1171 |
+
Menus that are absent or None in self.menudict are ignored.
|
| 1172 |
+
"""
|
| 1173 |
+
if menudefs is None:
|
| 1174 |
+
menudefs = self.mainmenu.menudefs
|
| 1175 |
+
if keydefs is None:
|
| 1176 |
+
keydefs = self.mainmenu.default_keydefs
|
| 1177 |
+
menudict = self.menudict
|
| 1178 |
+
text = self.text
|
| 1179 |
+
for mname, entrylist in menudefs:
|
| 1180 |
+
menu = menudict.get(mname)
|
| 1181 |
+
if not menu:
|
| 1182 |
+
continue
|
| 1183 |
+
for entry in entrylist:
|
| 1184 |
+
if not entry:
|
| 1185 |
+
menu.add_separator()
|
| 1186 |
+
else:
|
| 1187 |
+
label, eventname = entry
|
| 1188 |
+
checkbutton = (label[:1] == '!')
|
| 1189 |
+
if checkbutton:
|
| 1190 |
+
label = label[1:]
|
| 1191 |
+
underline, label = prepstr(label)
|
| 1192 |
+
accelerator = get_accelerator(keydefs, eventname)
|
| 1193 |
+
def command(text=text, eventname=eventname):
|
| 1194 |
+
text.event_generate(eventname)
|
| 1195 |
+
if checkbutton:
|
| 1196 |
+
var = self.get_var_obj(eventname, BooleanVar)
|
| 1197 |
+
menu.add_checkbutton(label=label, underline=underline,
|
| 1198 |
+
command=command, accelerator=accelerator,
|
| 1199 |
+
variable=var)
|
| 1200 |
+
else:
|
| 1201 |
+
menu.add_command(label=label, underline=underline,
|
| 1202 |
+
command=command,
|
| 1203 |
+
accelerator=accelerator)
|
| 1204 |
+
|
| 1205 |
+
def getvar(self, name):
|
| 1206 |
+
var = self.get_var_obj(name)
|
| 1207 |
+
if var:
|
| 1208 |
+
value = var.get()
|
| 1209 |
+
return value
|
| 1210 |
+
else:
|
| 1211 |
+
raise NameError(name)
|
| 1212 |
+
|
| 1213 |
+
def setvar(self, name, value, vartype=None):
|
| 1214 |
+
var = self.get_var_obj(name, vartype)
|
| 1215 |
+
if var:
|
| 1216 |
+
var.set(value)
|
| 1217 |
+
else:
|
| 1218 |
+
raise NameError(name)
|
| 1219 |
+
|
| 1220 |
+
def get_var_obj(self, name, vartype=None):
|
| 1221 |
+
var = self.tkinter_vars.get(name)
|
| 1222 |
+
if not var and vartype:
|
| 1223 |
+
# create a Tkinter variable object with self.text as master:
|
| 1224 |
+
self.tkinter_vars[name] = var = vartype(self.text)
|
| 1225 |
+
return var
|
| 1226 |
+
|
| 1227 |
+
# Tk implementations of "virtual text methods" -- each platform
|
| 1228 |
+
# reusing IDLE's support code needs to define these for its GUI's
|
| 1229 |
+
# flavor of widget.
|
| 1230 |
+
|
| 1231 |
+
# Is character at text_index in a Python string? Return 0 for
|
| 1232 |
+
# "guaranteed no", true for anything else. This info is expensive
|
| 1233 |
+
# to compute ab initio, but is probably already known by the
|
| 1234 |
+
# platform's colorizer.
|
| 1235 |
+
|
| 1236 |
+
def is_char_in_string(self, text_index):
|
| 1237 |
+
if self.color:
|
| 1238 |
+
# Return true iff colorizer hasn't (re)gotten this far
|
| 1239 |
+
# yet, or the character is tagged as being in a string
|
| 1240 |
+
return self.text.tag_prevrange("TODO", text_index) or \
|
| 1241 |
+
"STRING" in self.text.tag_names(text_index)
|
| 1242 |
+
else:
|
| 1243 |
+
# The colorizer is missing: assume the worst
|
| 1244 |
+
return 1
|
| 1245 |
+
|
| 1246 |
+
# If a selection is defined in the text widget, return (start,
|
| 1247 |
+
# end) as Tkinter text indices, otherwise return (None, None)
|
| 1248 |
+
def get_selection_indices(self):
|
| 1249 |
+
try:
|
| 1250 |
+
first = self.text.index("sel.first")
|
| 1251 |
+
last = self.text.index("sel.last")
|
| 1252 |
+
return first, last
|
| 1253 |
+
except TclError:
|
| 1254 |
+
return None, None
|
| 1255 |
+
|
| 1256 |
+
# Return the text widget's current view of what a tab stop means
|
| 1257 |
+
# (equivalent width in spaces).
|
| 1258 |
+
|
| 1259 |
+
def get_tk_tabwidth(self):
|
| 1260 |
+
current = self.text['tabs'] or TK_TABWIDTH_DEFAULT
|
| 1261 |
+
return int(current)
|
| 1262 |
+
|
| 1263 |
+
# Set the text widget's current view of what a tab stop means.
|
| 1264 |
+
|
| 1265 |
+
def set_tk_tabwidth(self, newtabwidth):
|
| 1266 |
+
text = self.text
|
| 1267 |
+
if self.get_tk_tabwidth() != newtabwidth:
|
| 1268 |
+
# Set text widget tab width
|
| 1269 |
+
pixels = text.tk.call("font", "measure", text["font"],
|
| 1270 |
+
"-displayof", text.master,
|
| 1271 |
+
"n" * newtabwidth)
|
| 1272 |
+
text.configure(tabs=pixels)
|
| 1273 |
+
|
| 1274 |
+
### begin autoindent code ### (configuration was moved to beginning of class)
|
| 1275 |
+
|
| 1276 |
+
def set_indentation_params(self, is_py_src, guess=True):
|
| 1277 |
+
if is_py_src and guess:
|
| 1278 |
+
i = self.guess_indent()
|
| 1279 |
+
if 2 <= i <= 8:
|
| 1280 |
+
self.indentwidth = i
|
| 1281 |
+
if self.indentwidth != self.tabwidth:
|
| 1282 |
+
self.usetabs = False
|
| 1283 |
+
self.set_tk_tabwidth(self.tabwidth)
|
| 1284 |
+
|
| 1285 |
+
def smart_backspace_event(self, event):
|
| 1286 |
+
text = self.text
|
| 1287 |
+
first, last = self.get_selection_indices()
|
| 1288 |
+
if first and last:
|
| 1289 |
+
text.delete(first, last)
|
| 1290 |
+
text.mark_set("insert", first)
|
| 1291 |
+
return "break"
|
| 1292 |
+
# Delete whitespace left, until hitting a real char or closest
|
| 1293 |
+
# preceding virtual tab stop.
|
| 1294 |
+
chars = text.get("insert linestart", "insert")
|
| 1295 |
+
if chars == '':
|
| 1296 |
+
if text.compare("insert", ">", "1.0"):
|
| 1297 |
+
# easy: delete preceding newline
|
| 1298 |
+
text.delete("insert-1c")
|
| 1299 |
+
else:
|
| 1300 |
+
text.bell() # at start of buffer
|
| 1301 |
+
return "break"
|
| 1302 |
+
if chars[-1] not in " \t":
|
| 1303 |
+
# easy: delete preceding real char
|
| 1304 |
+
text.delete("insert-1c")
|
| 1305 |
+
return "break"
|
| 1306 |
+
# Ick. It may require *inserting* spaces if we back up over a
|
| 1307 |
+
# tab character! This is written to be clear, not fast.
|
| 1308 |
+
tabwidth = self.tabwidth
|
| 1309 |
+
have = len(chars.expandtabs(tabwidth))
|
| 1310 |
+
assert have > 0
|
| 1311 |
+
want = ((have - 1) // self.indentwidth) * self.indentwidth
|
| 1312 |
+
# Debug prompt is multilined....
|
| 1313 |
+
ncharsdeleted = 0
|
| 1314 |
+
while True:
|
| 1315 |
+
chars = chars[:-1]
|
| 1316 |
+
ncharsdeleted = ncharsdeleted + 1
|
| 1317 |
+
have = len(chars.expandtabs(tabwidth))
|
| 1318 |
+
if have <= want or chars[-1] not in " \t":
|
| 1319 |
+
break
|
| 1320 |
+
text.undo_block_start()
|
| 1321 |
+
text.delete("insert-%dc" % ncharsdeleted, "insert")
|
| 1322 |
+
if have < want:
|
| 1323 |
+
text.insert("insert", ' ' * (want - have),
|
| 1324 |
+
self.user_input_insert_tags)
|
| 1325 |
+
text.undo_block_stop()
|
| 1326 |
+
return "break"
|
| 1327 |
+
|
| 1328 |
+
def smart_indent_event(self, event):
|
| 1329 |
+
# if intraline selection:
|
| 1330 |
+
# delete it
|
| 1331 |
+
# elif multiline selection:
|
| 1332 |
+
# do indent-region
|
| 1333 |
+
# else:
|
| 1334 |
+
# indent one level
|
| 1335 |
+
text = self.text
|
| 1336 |
+
first, last = self.get_selection_indices()
|
| 1337 |
+
text.undo_block_start()
|
| 1338 |
+
try:
|
| 1339 |
+
if first and last:
|
| 1340 |
+
if index2line(first) != index2line(last):
|
| 1341 |
+
return self.fregion.indent_region_event(event)
|
| 1342 |
+
text.delete(first, last)
|
| 1343 |
+
text.mark_set("insert", first)
|
| 1344 |
+
prefix = text.get("insert linestart", "insert")
|
| 1345 |
+
raw, effective = get_line_indent(prefix, self.tabwidth)
|
| 1346 |
+
if raw == len(prefix):
|
| 1347 |
+
# only whitespace to the left
|
| 1348 |
+
self.reindent_to(effective + self.indentwidth)
|
| 1349 |
+
else:
|
| 1350 |
+
# tab to the next 'stop' within or to right of line's text:
|
| 1351 |
+
if self.usetabs:
|
| 1352 |
+
pad = '\t'
|
| 1353 |
+
else:
|
| 1354 |
+
effective = len(prefix.expandtabs(self.tabwidth))
|
| 1355 |
+
n = self.indentwidth
|
| 1356 |
+
pad = ' ' * (n - effective % n)
|
| 1357 |
+
text.insert("insert", pad, self.user_input_insert_tags)
|
| 1358 |
+
text.see("insert")
|
| 1359 |
+
return "break"
|
| 1360 |
+
finally:
|
| 1361 |
+
text.undo_block_stop()
|
| 1362 |
+
|
| 1363 |
+
def newline_and_indent_event(self, event):
|
| 1364 |
+
"""Insert a newline and indentation after Enter keypress event.
|
| 1365 |
+
|
| 1366 |
+
Properly position the cursor on the new line based on information
|
| 1367 |
+
from the current line. This takes into account if the current line
|
| 1368 |
+
is a shell prompt, is empty, has selected text, contains a block
|
| 1369 |
+
opener, contains a block closer, is a continuation line, or
|
| 1370 |
+
is inside a string.
|
| 1371 |
+
"""
|
| 1372 |
+
text = self.text
|
| 1373 |
+
first, last = self.get_selection_indices()
|
| 1374 |
+
text.undo_block_start()
|
| 1375 |
+
try: # Close undo block and expose new line in finally clause.
|
| 1376 |
+
if first and last:
|
| 1377 |
+
text.delete(first, last)
|
| 1378 |
+
text.mark_set("insert", first)
|
| 1379 |
+
line = text.get("insert linestart", "insert")
|
| 1380 |
+
|
| 1381 |
+
# Count leading whitespace for indent size.
|
| 1382 |
+
i, n = 0, len(line)
|
| 1383 |
+
while i < n and line[i] in " \t":
|
| 1384 |
+
i += 1
|
| 1385 |
+
if i == n:
|
| 1386 |
+
# The cursor is in or at leading indentation in a continuation
|
| 1387 |
+
# line; just inject an empty line at the start.
|
| 1388 |
+
text.insert("insert linestart", '\n',
|
| 1389 |
+
self.user_input_insert_tags)
|
| 1390 |
+
return "break"
|
| 1391 |
+
indent = line[:i]
|
| 1392 |
+
|
| 1393 |
+
# Strip whitespace before insert point unless it's in the prompt.
|
| 1394 |
+
i = 0
|
| 1395 |
+
while line and line[-1] in " \t":
|
| 1396 |
+
line = line[:-1]
|
| 1397 |
+
i += 1
|
| 1398 |
+
if i:
|
| 1399 |
+
text.delete("insert - %d chars" % i, "insert")
|
| 1400 |
+
|
| 1401 |
+
# Strip whitespace after insert point.
|
| 1402 |
+
while text.get("insert") in " \t":
|
| 1403 |
+
text.delete("insert")
|
| 1404 |
+
|
| 1405 |
+
# Insert new line.
|
| 1406 |
+
text.insert("insert", '\n', self.user_input_insert_tags)
|
| 1407 |
+
|
| 1408 |
+
# Adjust indentation for continuations and block open/close.
|
| 1409 |
+
# First need to find the last statement.
|
| 1410 |
+
lno = index2line(text.index('insert'))
|
| 1411 |
+
y = pyparse.Parser(self.indentwidth, self.tabwidth)
|
| 1412 |
+
if not self.prompt_last_line:
|
| 1413 |
+
for context in self.num_context_lines:
|
| 1414 |
+
startat = max(lno - context, 1)
|
| 1415 |
+
startatindex = repr(startat) + ".0"
|
| 1416 |
+
rawtext = text.get(startatindex, "insert")
|
| 1417 |
+
y.set_code(rawtext)
|
| 1418 |
+
bod = y.find_good_parse_start(
|
| 1419 |
+
self._build_char_in_string_func(startatindex))
|
| 1420 |
+
if bod is not None or startat == 1:
|
| 1421 |
+
break
|
| 1422 |
+
y.set_lo(bod or 0)
|
| 1423 |
+
else:
|
| 1424 |
+
r = text.tag_prevrange("console", "insert")
|
| 1425 |
+
if r:
|
| 1426 |
+
startatindex = r[1]
|
| 1427 |
+
else:
|
| 1428 |
+
startatindex = "1.0"
|
| 1429 |
+
rawtext = text.get(startatindex, "insert")
|
| 1430 |
+
y.set_code(rawtext)
|
| 1431 |
+
y.set_lo(0)
|
| 1432 |
+
|
| 1433 |
+
c = y.get_continuation_type()
|
| 1434 |
+
if c != pyparse.C_NONE:
|
| 1435 |
+
# The current statement hasn't ended yet.
|
| 1436 |
+
if c == pyparse.C_STRING_FIRST_LINE:
|
| 1437 |
+
# After the first line of a string do not indent at all.
|
| 1438 |
+
pass
|
| 1439 |
+
elif c == pyparse.C_STRING_NEXT_LINES:
|
| 1440 |
+
# Inside a string which started before this line;
|
| 1441 |
+
# just mimic the current indent.
|
| 1442 |
+
text.insert("insert", indent, self.user_input_insert_tags)
|
| 1443 |
+
elif c == pyparse.C_BRACKET:
|
| 1444 |
+
# Line up with the first (if any) element of the
|
| 1445 |
+
# last open bracket structure; else indent one
|
| 1446 |
+
# level beyond the indent of the line with the
|
| 1447 |
+
# last open bracket.
|
| 1448 |
+
self.reindent_to(y.compute_bracket_indent())
|
| 1449 |
+
elif c == pyparse.C_BACKSLASH:
|
| 1450 |
+
# If more than one line in this statement already, just
|
| 1451 |
+
# mimic the current indent; else if initial line
|
| 1452 |
+
# has a start on an assignment stmt, indent to
|
| 1453 |
+
# beyond leftmost =; else to beyond first chunk of
|
| 1454 |
+
# non-whitespace on initial line.
|
| 1455 |
+
if y.get_num_lines_in_stmt() > 1:
|
| 1456 |
+
text.insert("insert", indent,
|
| 1457 |
+
self.user_input_insert_tags)
|
| 1458 |
+
else:
|
| 1459 |
+
self.reindent_to(y.compute_backslash_indent())
|
| 1460 |
+
else:
|
| 1461 |
+
assert 0, "bogus continuation type %r" % (c,)
|
| 1462 |
+
return "break"
|
| 1463 |
+
|
| 1464 |
+
# This line starts a brand new statement; indent relative to
|
| 1465 |
+
# indentation of initial line of closest preceding
|
| 1466 |
+
# interesting statement.
|
| 1467 |
+
indent = y.get_base_indent_string()
|
| 1468 |
+
text.insert("insert", indent, self.user_input_insert_tags)
|
| 1469 |
+
if y.is_block_opener():
|
| 1470 |
+
self.smart_indent_event(event)
|
| 1471 |
+
elif indent and y.is_block_closer():
|
| 1472 |
+
self.smart_backspace_event(event)
|
| 1473 |
+
return "break"
|
| 1474 |
+
finally:
|
| 1475 |
+
text.see("insert")
|
| 1476 |
+
text.undo_block_stop()
|
| 1477 |
+
|
| 1478 |
+
# Our editwin provides an is_char_in_string function that works
|
| 1479 |
+
# with a Tk text index, but PyParse only knows about offsets into
|
| 1480 |
+
# a string. This builds a function for PyParse that accepts an
|
| 1481 |
+
# offset.
|
| 1482 |
+
|
| 1483 |
+
def _build_char_in_string_func(self, startindex):
|
| 1484 |
+
def inner(offset, _startindex=startindex,
|
| 1485 |
+
_icis=self.is_char_in_string):
|
| 1486 |
+
return _icis(_startindex + "+%dc" % offset)
|
| 1487 |
+
return inner
|
| 1488 |
+
|
| 1489 |
+
# XXX this isn't bound to anything -- see tabwidth comments
|
| 1490 |
+
## def change_tabwidth_event(self, event):
|
| 1491 |
+
## new = self._asktabwidth()
|
| 1492 |
+
## if new != self.tabwidth:
|
| 1493 |
+
## self.tabwidth = new
|
| 1494 |
+
## self.set_indentation_params(0, guess=0)
|
| 1495 |
+
## return "break"
|
| 1496 |
+
|
| 1497 |
+
# Make string that displays as n leading blanks.
|
| 1498 |
+
|
| 1499 |
+
def _make_blanks(self, n):
|
| 1500 |
+
if self.usetabs:
|
| 1501 |
+
ntabs, nspaces = divmod(n, self.tabwidth)
|
| 1502 |
+
return '\t' * ntabs + ' ' * nspaces
|
| 1503 |
+
else:
|
| 1504 |
+
return ' ' * n
|
| 1505 |
+
|
| 1506 |
+
# Delete from beginning of line to insert point, then reinsert
|
| 1507 |
+
# column logical (meaning use tabs if appropriate) spaces.
|
| 1508 |
+
|
| 1509 |
+
def reindent_to(self, column):
|
| 1510 |
+
text = self.text
|
| 1511 |
+
text.undo_block_start()
|
| 1512 |
+
if text.compare("insert linestart", "!=", "insert"):
|
| 1513 |
+
text.delete("insert linestart", "insert")
|
| 1514 |
+
if column:
|
| 1515 |
+
text.insert("insert", self._make_blanks(column),
|
| 1516 |
+
self.user_input_insert_tags)
|
| 1517 |
+
text.undo_block_stop()
|
| 1518 |
+
|
| 1519 |
+
# Guess indentwidth from text content.
|
| 1520 |
+
# Return guessed indentwidth. This should not be believed unless
|
| 1521 |
+
# it's in a reasonable range (e.g., it will be 0 if no indented
|
| 1522 |
+
# blocks are found).
|
| 1523 |
+
|
| 1524 |
+
def guess_indent(self):
|
| 1525 |
+
opener, indented = IndentSearcher(self.text, self.tabwidth).run()
|
| 1526 |
+
if opener and indented:
|
| 1527 |
+
raw, indentsmall = get_line_indent(opener, self.tabwidth)
|
| 1528 |
+
raw, indentlarge = get_line_indent(indented, self.tabwidth)
|
| 1529 |
+
else:
|
| 1530 |
+
indentsmall = indentlarge = 0
|
| 1531 |
+
return indentlarge - indentsmall
|
| 1532 |
+
|
| 1533 |
+
def toggle_line_numbers_event(self, event=None):
|
| 1534 |
+
if self.line_numbers is None:
|
| 1535 |
+
return
|
| 1536 |
+
|
| 1537 |
+
if self.line_numbers.is_shown:
|
| 1538 |
+
self.line_numbers.hide_sidebar()
|
| 1539 |
+
menu_label = "Show"
|
| 1540 |
+
else:
|
| 1541 |
+
self.line_numbers.show_sidebar()
|
| 1542 |
+
menu_label = "Hide"
|
| 1543 |
+
self.update_menu_label(menu='options', index='*ine*umbers',
|
| 1544 |
+
label=f'{menu_label} Line Numbers')
|
| 1545 |
+
|
| 1546 |
+
# "line.col" -> line, as an int
|
| 1547 |
+
def index2line(index):
|
| 1548 |
+
return int(float(index))
|
| 1549 |
+
|
| 1550 |
+
|
| 1551 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 1552 |
+
def get_line_indent(line, tabwidth):
|
| 1553 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 1554 |
+
|
| 1555 |
+
The effective # of spaces is the length after properly "expanding"
|
| 1556 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 1557 |
+
"""
|
| 1558 |
+
m = _line_indent_re.match(line)
|
| 1559 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 1560 |
+
|
| 1561 |
+
|
| 1562 |
+
class IndentSearcher:
|
| 1563 |
+
|
| 1564 |
+
# .run() chews over the Text widget, looking for a block opener
|
| 1565 |
+
# and the stmt following it. Returns a pair,
|
| 1566 |
+
# (line containing block opener, line containing stmt)
|
| 1567 |
+
# Either or both may be None.
|
| 1568 |
+
|
| 1569 |
+
def __init__(self, text, tabwidth):
|
| 1570 |
+
self.text = text
|
| 1571 |
+
self.tabwidth = tabwidth
|
| 1572 |
+
self.i = self.finished = 0
|
| 1573 |
+
self.blkopenline = self.indentedline = None
|
| 1574 |
+
|
| 1575 |
+
def readline(self):
|
| 1576 |
+
if self.finished:
|
| 1577 |
+
return ""
|
| 1578 |
+
i = self.i = self.i + 1
|
| 1579 |
+
mark = repr(i) + ".0"
|
| 1580 |
+
if self.text.compare(mark, ">=", "end"):
|
| 1581 |
+
return ""
|
| 1582 |
+
return self.text.get(mark, mark + " lineend+1c")
|
| 1583 |
+
|
| 1584 |
+
def tokeneater(self, type, token, start, end, line,
|
| 1585 |
+
INDENT=tokenize.INDENT,
|
| 1586 |
+
NAME=tokenize.NAME,
|
| 1587 |
+
OPENERS=('class', 'def', 'for', 'if', 'try', 'while')):
|
| 1588 |
+
if self.finished:
|
| 1589 |
+
pass
|
| 1590 |
+
elif type == NAME and token in OPENERS:
|
| 1591 |
+
self.blkopenline = line
|
| 1592 |
+
elif type == INDENT and self.blkopenline:
|
| 1593 |
+
self.indentedline = line
|
| 1594 |
+
self.finished = 1
|
| 1595 |
+
|
| 1596 |
+
def run(self):
|
| 1597 |
+
save_tabsize = tokenize.tabsize
|
| 1598 |
+
tokenize.tabsize = self.tabwidth
|
| 1599 |
+
try:
|
| 1600 |
+
try:
|
| 1601 |
+
tokens = tokenize.generate_tokens(self.readline)
|
| 1602 |
+
for token in tokens:
|
| 1603 |
+
self.tokeneater(*token)
|
| 1604 |
+
except (tokenize.TokenError, SyntaxError):
|
| 1605 |
+
# since we cut off the tokenizer early, we can trigger
|
| 1606 |
+
# spurious errors
|
| 1607 |
+
pass
|
| 1608 |
+
finally:
|
| 1609 |
+
tokenize.tabsize = save_tabsize
|
| 1610 |
+
return self.blkopenline, self.indentedline
|
| 1611 |
+
|
| 1612 |
+
### end autoindent code ###
|
| 1613 |
+
|
| 1614 |
+
def prepstr(s):
|
| 1615 |
+
# Helper to extract the underscore from a string, e.g.
|
| 1616 |
+
# prepstr("Co_py") returns (2, "Copy").
|
| 1617 |
+
i = s.find('_')
|
| 1618 |
+
if i >= 0:
|
| 1619 |
+
s = s[:i] + s[i+1:]
|
| 1620 |
+
return i, s
|
| 1621 |
+
|
| 1622 |
+
|
| 1623 |
+
keynames = {
|
| 1624 |
+
'bracketleft': '[',
|
| 1625 |
+
'bracketright': ']',
|
| 1626 |
+
'slash': '/',
|
| 1627 |
+
}
|
| 1628 |
+
|
| 1629 |
+
def get_accelerator(keydefs, eventname):
|
| 1630 |
+
keylist = keydefs.get(eventname)
|
| 1631 |
+
# issue10940: temporary workaround to prevent hang with OS X Cocoa Tk 8.5
|
| 1632 |
+
# if not keylist:
|
| 1633 |
+
if (not keylist) or (macosx.isCocoaTk() and eventname in {
|
| 1634 |
+
"<<open-module>>",
|
| 1635 |
+
"<<goto-line>>",
|
| 1636 |
+
"<<change-indentwidth>>"}):
|
| 1637 |
+
return ""
|
| 1638 |
+
s = keylist[0]
|
| 1639 |
+
s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
|
| 1640 |
+
s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
|
| 1641 |
+
s = re.sub("Key-", "", s)
|
| 1642 |
+
s = re.sub("Cancel","Ctrl-Break",s) # [email protected]
|
| 1643 |
+
s = re.sub("Control-", "Ctrl-", s)
|
| 1644 |
+
s = re.sub("-", "+", s)
|
| 1645 |
+
s = re.sub("><", " ", s)
|
| 1646 |
+
s = re.sub("<", "", s)
|
| 1647 |
+
s = re.sub(">", "", s)
|
| 1648 |
+
return s
|
| 1649 |
+
|
| 1650 |
+
|
| 1651 |
+
def fixwordbreaks(root):
|
| 1652 |
+
# On Windows, tcl/tk breaks 'words' only on spaces, as in Command Prompt.
|
| 1653 |
+
# We want Motif style everywhere. See #21474, msg218992 and followup.
|
| 1654 |
+
tk = root.tk
|
| 1655 |
+
tk.call('tcl_wordBreakAfter', 'a b', 0) # make sure word.tcl is loaded
|
| 1656 |
+
tk.call('set', 'tcl_wordchars', r'\w')
|
| 1657 |
+
tk.call('set', 'tcl_nonwordchars', r'\W')
|
| 1658 |
+
|
| 1659 |
+
|
| 1660 |
+
def _editor_window(parent): # htest #
|
| 1661 |
+
# error if close master window first - timer event, after script
|
| 1662 |
+
root = parent
|
| 1663 |
+
fixwordbreaks(root)
|
| 1664 |
+
if sys.argv[1:]:
|
| 1665 |
+
filename = sys.argv[1]
|
| 1666 |
+
else:
|
| 1667 |
+
filename = None
|
| 1668 |
+
macosx.setupApp(root, None)
|
| 1669 |
+
edit = EditorWindow(root=root, filename=filename)
|
| 1670 |
+
text = edit.text
|
| 1671 |
+
text['height'] = 10
|
| 1672 |
+
for i in range(20):
|
| 1673 |
+
text.insert('insert', ' '*i + str(i) + '\n')
|
| 1674 |
+
# text.bind("<<close-all-windows>>", edit.close_event)
|
| 1675 |
+
# Does not stop error, neither does following
|
| 1676 |
+
# edit.text.bind("<<close-window>>", edit.close_event)
|
| 1677 |
+
|
| 1678 |
+
if __name__ == '__main__':
|
| 1679 |
+
from unittest import main
|
| 1680 |
+
main('idlelib.idle_test.test_editor', verbosity=2, exit=False)
|
| 1681 |
+
|
| 1682 |
+
from idlelib.idle_test.htest import run
|
| 1683 |
+
run(_editor_window)
|
evalkit_cambrian/lib/python3.10/idlelib/format.py
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Format all or a selected region (line slice) of text.
|
| 2 |
+
|
| 3 |
+
Region formatting options: paragraph, comment block, indent, deindent,
|
| 4 |
+
comment, uncomment, tabify, and untabify.
|
| 5 |
+
|
| 6 |
+
File renamed from paragraph.py with functions added from editor.py.
|
| 7 |
+
"""
|
| 8 |
+
import re
|
| 9 |
+
from tkinter.messagebox import askyesno
|
| 10 |
+
from tkinter.simpledialog import askinteger
|
| 11 |
+
from idlelib.config import idleConf
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class FormatParagraph:
|
| 15 |
+
"""Format a paragraph, comment block, or selection to a max width.
|
| 16 |
+
|
| 17 |
+
Does basic, standard text formatting, and also understands Python
|
| 18 |
+
comment blocks. Thus, for editing Python source code, this
|
| 19 |
+
extension is really only suitable for reformatting these comment
|
| 20 |
+
blocks or triple-quoted strings.
|
| 21 |
+
|
| 22 |
+
Known problems with comment reformatting:
|
| 23 |
+
* If there is a selection marked, and the first line of the
|
| 24 |
+
selection is not complete, the block will probably not be detected
|
| 25 |
+
as comments, and will have the normal "text formatting" rules
|
| 26 |
+
applied.
|
| 27 |
+
* If a comment block has leading whitespace that mixes tabs and
|
| 28 |
+
spaces, they will not be considered part of the same block.
|
| 29 |
+
* Fancy comments, like this bulleted list, aren't handled :-)
|
| 30 |
+
"""
|
| 31 |
+
def __init__(self, editwin):
|
| 32 |
+
self.editwin = editwin
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def reload(cls):
|
| 36 |
+
cls.max_width = idleConf.GetOption('extensions', 'FormatParagraph',
|
| 37 |
+
'max-width', type='int', default=72)
|
| 38 |
+
|
| 39 |
+
def close(self):
|
| 40 |
+
self.editwin = None
|
| 41 |
+
|
| 42 |
+
def format_paragraph_event(self, event, limit=None):
|
| 43 |
+
"""Formats paragraph to a max width specified in idleConf.
|
| 44 |
+
|
| 45 |
+
If text is selected, format_paragraph_event will start breaking lines
|
| 46 |
+
at the max width, starting from the beginning selection.
|
| 47 |
+
|
| 48 |
+
If no text is selected, format_paragraph_event uses the current
|
| 49 |
+
cursor location to determine the paragraph (lines of text surrounded
|
| 50 |
+
by blank lines) and formats it.
|
| 51 |
+
|
| 52 |
+
The length limit parameter is for testing with a known value.
|
| 53 |
+
"""
|
| 54 |
+
limit = self.max_width if limit is None else limit
|
| 55 |
+
text = self.editwin.text
|
| 56 |
+
first, last = self.editwin.get_selection_indices()
|
| 57 |
+
if first and last:
|
| 58 |
+
data = text.get(first, last)
|
| 59 |
+
comment_header = get_comment_header(data)
|
| 60 |
+
else:
|
| 61 |
+
first, last, comment_header, data = \
|
| 62 |
+
find_paragraph(text, text.index("insert"))
|
| 63 |
+
if comment_header:
|
| 64 |
+
newdata = reformat_comment(data, limit, comment_header)
|
| 65 |
+
else:
|
| 66 |
+
newdata = reformat_paragraph(data, limit)
|
| 67 |
+
text.tag_remove("sel", "1.0", "end")
|
| 68 |
+
|
| 69 |
+
if newdata != data:
|
| 70 |
+
text.mark_set("insert", first)
|
| 71 |
+
text.undo_block_start()
|
| 72 |
+
text.delete(first, last)
|
| 73 |
+
text.insert(first, newdata)
|
| 74 |
+
text.undo_block_stop()
|
| 75 |
+
else:
|
| 76 |
+
text.mark_set("insert", last)
|
| 77 |
+
text.see("insert")
|
| 78 |
+
return "break"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
FormatParagraph.reload()
|
| 82 |
+
|
| 83 |
+
def find_paragraph(text, mark):
|
| 84 |
+
"""Returns the start/stop indices enclosing the paragraph that mark is in.
|
| 85 |
+
|
| 86 |
+
Also returns the comment format string, if any, and paragraph of text
|
| 87 |
+
between the start/stop indices.
|
| 88 |
+
"""
|
| 89 |
+
lineno, col = map(int, mark.split("."))
|
| 90 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 91 |
+
|
| 92 |
+
# Look for start of next paragraph if the index passed in is a blank line
|
| 93 |
+
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
|
| 94 |
+
lineno = lineno + 1
|
| 95 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 96 |
+
first_lineno = lineno
|
| 97 |
+
comment_header = get_comment_header(line)
|
| 98 |
+
comment_header_len = len(comment_header)
|
| 99 |
+
|
| 100 |
+
# Once start line found, search for end of paragraph (a blank line)
|
| 101 |
+
while get_comment_header(line)==comment_header and \
|
| 102 |
+
not is_all_white(line[comment_header_len:]):
|
| 103 |
+
lineno = lineno + 1
|
| 104 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 105 |
+
last = "%d.0" % lineno
|
| 106 |
+
|
| 107 |
+
# Search back to beginning of paragraph (first blank line before)
|
| 108 |
+
lineno = first_lineno - 1
|
| 109 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 110 |
+
while lineno > 0 and \
|
| 111 |
+
get_comment_header(line)==comment_header and \
|
| 112 |
+
not is_all_white(line[comment_header_len:]):
|
| 113 |
+
lineno = lineno - 1
|
| 114 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 115 |
+
first = "%d.0" % (lineno+1)
|
| 116 |
+
|
| 117 |
+
return first, last, comment_header, text.get(first, last)
|
| 118 |
+
|
| 119 |
+
# This should perhaps be replaced with textwrap.wrap
|
| 120 |
+
def reformat_paragraph(data, limit):
|
| 121 |
+
"""Return data reformatted to specified width (limit)."""
|
| 122 |
+
lines = data.split("\n")
|
| 123 |
+
i = 0
|
| 124 |
+
n = len(lines)
|
| 125 |
+
while i < n and is_all_white(lines[i]):
|
| 126 |
+
i = i+1
|
| 127 |
+
if i >= n:
|
| 128 |
+
return data
|
| 129 |
+
indent1 = get_indent(lines[i])
|
| 130 |
+
if i+1 < n and not is_all_white(lines[i+1]):
|
| 131 |
+
indent2 = get_indent(lines[i+1])
|
| 132 |
+
else:
|
| 133 |
+
indent2 = indent1
|
| 134 |
+
new = lines[:i]
|
| 135 |
+
partial = indent1
|
| 136 |
+
while i < n and not is_all_white(lines[i]):
|
| 137 |
+
# XXX Should take double space after period (etc.) into account
|
| 138 |
+
words = re.split(r"(\s+)", lines[i])
|
| 139 |
+
for j in range(0, len(words), 2):
|
| 140 |
+
word = words[j]
|
| 141 |
+
if not word:
|
| 142 |
+
continue # Can happen when line ends in whitespace
|
| 143 |
+
if len((partial + word).expandtabs()) > limit and \
|
| 144 |
+
partial != indent1:
|
| 145 |
+
new.append(partial.rstrip())
|
| 146 |
+
partial = indent2
|
| 147 |
+
partial = partial + word + " "
|
| 148 |
+
if j+1 < len(words) and words[j+1] != " ":
|
| 149 |
+
partial = partial + " "
|
| 150 |
+
i = i+1
|
| 151 |
+
new.append(partial.rstrip())
|
| 152 |
+
# XXX Should reformat remaining paragraphs as well
|
| 153 |
+
new.extend(lines[i:])
|
| 154 |
+
return "\n".join(new)
|
| 155 |
+
|
| 156 |
+
def reformat_comment(data, limit, comment_header):
|
| 157 |
+
"""Return data reformatted to specified width with comment header."""
|
| 158 |
+
|
| 159 |
+
# Remove header from the comment lines
|
| 160 |
+
lc = len(comment_header)
|
| 161 |
+
data = "\n".join(line[lc:] for line in data.split("\n"))
|
| 162 |
+
# Reformat to maxformatwidth chars or a 20 char width,
|
| 163 |
+
# whichever is greater.
|
| 164 |
+
format_width = max(limit - len(comment_header), 20)
|
| 165 |
+
newdata = reformat_paragraph(data, format_width)
|
| 166 |
+
# re-split and re-insert the comment header.
|
| 167 |
+
newdata = newdata.split("\n")
|
| 168 |
+
# If the block ends in a \n, we don't want the comment prefix
|
| 169 |
+
# inserted after it. (Im not sure it makes sense to reformat a
|
| 170 |
+
# comment block that is not made of complete lines, but whatever!)
|
| 171 |
+
# Can't think of a clean solution, so we hack away
|
| 172 |
+
block_suffix = ""
|
| 173 |
+
if not newdata[-1]:
|
| 174 |
+
block_suffix = "\n"
|
| 175 |
+
newdata = newdata[:-1]
|
| 176 |
+
return '\n'.join(comment_header+line for line in newdata) + block_suffix
|
| 177 |
+
|
| 178 |
+
def is_all_white(line):
|
| 179 |
+
"""Return True if line is empty or all whitespace."""
|
| 180 |
+
|
| 181 |
+
return re.match(r"^\s*$", line) is not None
|
| 182 |
+
|
| 183 |
+
def get_indent(line):
|
| 184 |
+
"""Return the initial space or tab indent of line."""
|
| 185 |
+
return re.match(r"^([ \t]*)", line).group()
|
| 186 |
+
|
| 187 |
+
def get_comment_header(line):
|
| 188 |
+
"""Return string with leading whitespace and '#' from line or ''.
|
| 189 |
+
|
| 190 |
+
A null return indicates that the line is not a comment line. A non-
|
| 191 |
+
null return, such as ' #', will be used to find the other lines of
|
| 192 |
+
a comment block with the same indent.
|
| 193 |
+
"""
|
| 194 |
+
m = re.match(r"^([ \t]*#*)", line)
|
| 195 |
+
if m is None: return ""
|
| 196 |
+
return m.group(1)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Copied from editor.py; importing it would cause an import cycle.
|
| 200 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 201 |
+
|
| 202 |
+
def get_line_indent(line, tabwidth):
|
| 203 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 204 |
+
|
| 205 |
+
The effective # of spaces is the length after properly "expanding"
|
| 206 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 207 |
+
"""
|
| 208 |
+
m = _line_indent_re.match(line)
|
| 209 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class FormatRegion:
|
| 213 |
+
"Format selected text (region)."
|
| 214 |
+
|
| 215 |
+
def __init__(self, editwin):
|
| 216 |
+
self.editwin = editwin
|
| 217 |
+
|
| 218 |
+
def get_region(self):
|
| 219 |
+
"""Return line information about the selected text region.
|
| 220 |
+
|
| 221 |
+
If text is selected, the first and last indices will be
|
| 222 |
+
for the selection. If there is no text selected, the
|
| 223 |
+
indices will be the current cursor location.
|
| 224 |
+
|
| 225 |
+
Return a tuple containing (first index, last index,
|
| 226 |
+
string representation of text, list of text lines).
|
| 227 |
+
"""
|
| 228 |
+
text = self.editwin.text
|
| 229 |
+
first, last = self.editwin.get_selection_indices()
|
| 230 |
+
if first and last:
|
| 231 |
+
head = text.index(first + " linestart")
|
| 232 |
+
tail = text.index(last + "-1c lineend +1c")
|
| 233 |
+
else:
|
| 234 |
+
head = text.index("insert linestart")
|
| 235 |
+
tail = text.index("insert lineend +1c")
|
| 236 |
+
chars = text.get(head, tail)
|
| 237 |
+
lines = chars.split("\n")
|
| 238 |
+
return head, tail, chars, lines
|
| 239 |
+
|
| 240 |
+
def set_region(self, head, tail, chars, lines):
|
| 241 |
+
"""Replace the text between the given indices.
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
head: Starting index of text to replace.
|
| 245 |
+
tail: Ending index of text to replace.
|
| 246 |
+
chars: Expected to be string of current text
|
| 247 |
+
between head and tail.
|
| 248 |
+
lines: List of new lines to insert between head
|
| 249 |
+
and tail.
|
| 250 |
+
"""
|
| 251 |
+
text = self.editwin.text
|
| 252 |
+
newchars = "\n".join(lines)
|
| 253 |
+
if newchars == chars:
|
| 254 |
+
text.bell()
|
| 255 |
+
return
|
| 256 |
+
text.tag_remove("sel", "1.0", "end")
|
| 257 |
+
text.mark_set("insert", head)
|
| 258 |
+
text.undo_block_start()
|
| 259 |
+
text.delete(head, tail)
|
| 260 |
+
text.insert(head, newchars)
|
| 261 |
+
text.undo_block_stop()
|
| 262 |
+
text.tag_add("sel", head, "insert")
|
| 263 |
+
|
| 264 |
+
def indent_region_event(self, event=None):
|
| 265 |
+
"Indent region by indentwidth spaces."
|
| 266 |
+
head, tail, chars, lines = self.get_region()
|
| 267 |
+
for pos in range(len(lines)):
|
| 268 |
+
line = lines[pos]
|
| 269 |
+
if line:
|
| 270 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 271 |
+
effective = effective + self.editwin.indentwidth
|
| 272 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 273 |
+
self.set_region(head, tail, chars, lines)
|
| 274 |
+
return "break"
|
| 275 |
+
|
| 276 |
+
def dedent_region_event(self, event=None):
|
| 277 |
+
"Dedent region by indentwidth spaces."
|
| 278 |
+
head, tail, chars, lines = self.get_region()
|
| 279 |
+
for pos in range(len(lines)):
|
| 280 |
+
line = lines[pos]
|
| 281 |
+
if line:
|
| 282 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 283 |
+
effective = max(effective - self.editwin.indentwidth, 0)
|
| 284 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 285 |
+
self.set_region(head, tail, chars, lines)
|
| 286 |
+
return "break"
|
| 287 |
+
|
| 288 |
+
def comment_region_event(self, event=None):
|
| 289 |
+
"""Comment out each line in region.
|
| 290 |
+
|
| 291 |
+
## is appended to the beginning of each line to comment it out.
|
| 292 |
+
"""
|
| 293 |
+
head, tail, chars, lines = self.get_region()
|
| 294 |
+
for pos in range(len(lines) - 1):
|
| 295 |
+
line = lines[pos]
|
| 296 |
+
lines[pos] = '##' + line
|
| 297 |
+
self.set_region(head, tail, chars, lines)
|
| 298 |
+
return "break"
|
| 299 |
+
|
| 300 |
+
def uncomment_region_event(self, event=None):
|
| 301 |
+
"""Uncomment each line in region.
|
| 302 |
+
|
| 303 |
+
Remove ## or # in the first positions of a line. If the comment
|
| 304 |
+
is not in the beginning position, this command will have no effect.
|
| 305 |
+
"""
|
| 306 |
+
head, tail, chars, lines = self.get_region()
|
| 307 |
+
for pos in range(len(lines)):
|
| 308 |
+
line = lines[pos]
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if line[:2] == '##':
|
| 312 |
+
line = line[2:]
|
| 313 |
+
elif line[:1] == '#':
|
| 314 |
+
line = line[1:]
|
| 315 |
+
lines[pos] = line
|
| 316 |
+
self.set_region(head, tail, chars, lines)
|
| 317 |
+
return "break"
|
| 318 |
+
|
| 319 |
+
def tabify_region_event(self, event=None):
|
| 320 |
+
"Convert leading spaces to tabs for each line in selected region."
|
| 321 |
+
head, tail, chars, lines = self.get_region()
|
| 322 |
+
tabwidth = self._asktabwidth()
|
| 323 |
+
if tabwidth is None:
|
| 324 |
+
return
|
| 325 |
+
for pos in range(len(lines)):
|
| 326 |
+
line = lines[pos]
|
| 327 |
+
if line:
|
| 328 |
+
raw, effective = get_line_indent(line, tabwidth)
|
| 329 |
+
ntabs, nspaces = divmod(effective, tabwidth)
|
| 330 |
+
lines[pos] = '\t' * ntabs + ' ' * nspaces + line[raw:]
|
| 331 |
+
self.set_region(head, tail, chars, lines)
|
| 332 |
+
return "break"
|
| 333 |
+
|
| 334 |
+
def untabify_region_event(self, event=None):
|
| 335 |
+
"Expand tabs to spaces for each line in region."
|
| 336 |
+
head, tail, chars, lines = self.get_region()
|
| 337 |
+
tabwidth = self._asktabwidth()
|
| 338 |
+
if tabwidth is None:
|
| 339 |
+
return
|
| 340 |
+
for pos in range(len(lines)):
|
| 341 |
+
lines[pos] = lines[pos].expandtabs(tabwidth)
|
| 342 |
+
self.set_region(head, tail, chars, lines)
|
| 343 |
+
return "break"
|
| 344 |
+
|
| 345 |
+
def _asktabwidth(self):
|
| 346 |
+
"Return value for tab width."
|
| 347 |
+
return askinteger(
|
| 348 |
+
"Tab width",
|
| 349 |
+
"Columns per tab? (2-16)",
|
| 350 |
+
parent=self.editwin.text,
|
| 351 |
+
initialvalue=self.editwin.indentwidth,
|
| 352 |
+
minvalue=2,
|
| 353 |
+
maxvalue=16)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
class Indents:
|
| 357 |
+
"Change future indents."
|
| 358 |
+
|
| 359 |
+
def __init__(self, editwin):
|
| 360 |
+
self.editwin = editwin
|
| 361 |
+
|
| 362 |
+
def toggle_tabs_event(self, event):
|
| 363 |
+
editwin = self.editwin
|
| 364 |
+
usetabs = editwin.usetabs
|
| 365 |
+
if askyesno(
|
| 366 |
+
"Toggle tabs",
|
| 367 |
+
"Turn tabs " + ("on", "off")[usetabs] +
|
| 368 |
+
"?\nIndent width " +
|
| 369 |
+
("will be", "remains at")[usetabs] + " 8." +
|
| 370 |
+
"\n Note: a tab is always 8 columns",
|
| 371 |
+
parent=editwin.text):
|
| 372 |
+
editwin.usetabs = not usetabs
|
| 373 |
+
# Try to prevent inconsistent indentation.
|
| 374 |
+
# User must change indent width manually after using tabs.
|
| 375 |
+
editwin.indentwidth = 8
|
| 376 |
+
return "break"
|
| 377 |
+
|
| 378 |
+
def change_indentwidth_event(self, event):
|
| 379 |
+
editwin = self.editwin
|
| 380 |
+
new = askinteger(
|
| 381 |
+
"Indent width",
|
| 382 |
+
"New indent width (2-16)\n(Always use 8 when using tabs)",
|
| 383 |
+
parent=editwin.text,
|
| 384 |
+
initialvalue=editwin.indentwidth,
|
| 385 |
+
minvalue=2,
|
| 386 |
+
maxvalue=16)
|
| 387 |
+
if new and new != editwin.indentwidth and not editwin.usetabs:
|
| 388 |
+
editwin.indentwidth = new
|
| 389 |
+
return "break"
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
class Rstrip: # 'Strip Trailing Whitespace" on "Format" menu.
|
| 393 |
+
def __init__(self, editwin):
|
| 394 |
+
self.editwin = editwin
|
| 395 |
+
|
| 396 |
+
def do_rstrip(self, event=None):
|
| 397 |
+
text = self.editwin.text
|
| 398 |
+
undo = self.editwin.undo
|
| 399 |
+
undo.undo_block_start()
|
| 400 |
+
|
| 401 |
+
end_line = int(float(text.index('end')))
|
| 402 |
+
for cur in range(1, end_line):
|
| 403 |
+
txt = text.get('%i.0' % cur, '%i.end' % cur)
|
| 404 |
+
raw = len(txt)
|
| 405 |
+
cut = len(txt.rstrip())
|
| 406 |
+
# Since text.delete() marks file as changed, even if not,
|
| 407 |
+
# only call it when needed to actually delete something.
|
| 408 |
+
if cut < raw:
|
| 409 |
+
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
|
| 410 |
+
|
| 411 |
+
if (text.get('end-2c') == '\n' # File ends with at least 1 newline;
|
| 412 |
+
and not hasattr(self.editwin, 'interp')): # & is not Shell.
|
| 413 |
+
# Delete extra user endlines.
|
| 414 |
+
while (text.index('end-1c') > '1.0' # Stop if file empty.
|
| 415 |
+
and text.get('end-3c') == '\n'):
|
| 416 |
+
text.delete('end-3c')
|
| 417 |
+
# Because tk indexes are slice indexes and never raise,
|
| 418 |
+
# a file with only newlines will be emptied.
|
| 419 |
+
# patchcheck.py does the same.
|
| 420 |
+
|
| 421 |
+
undo.undo_block_stop()
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
if __name__ == "__main__":
|
| 425 |
+
from unittest import main
|
| 426 |
+
main('idlelib.idle_test.test_format', verbosity=2, exit=False)
|
evalkit_cambrian/lib/python3.10/idlelib/help.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+
<head>
|
| 6 |
+
<meta charset="utf-8" />
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
|
| 8 |
+
|
| 9 |
+
<title>IDLE — Python 3.12.0a0 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 10 |
+
|
| 11 |
+
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
|
| 12 |
+
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?2022.1" />
|
| 13 |
+
|
| 14 |
+
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
|
| 15 |
+
<script src="../_static/jquery.js"></script>
|
| 16 |
+
<script src="../_static/underscore.js"></script>
|
| 17 |
+
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
|
| 18 |
+
<script src="../_static/doctools.js"></script>
|
| 19 |
+
|
| 20 |
+
<script src="../_static/sidebar.js"></script>
|
| 21 |
+
|
| 22 |
+
<link rel="search" type="application/opensearchdescription+xml"
|
| 23 |
+
title="Search within Python 3.12.0a0 documentation"
|
| 24 |
+
href="../_static/opensearch.xml"/>
|
| 25 |
+
<link rel="author" title="About these documents" href="../about.html" />
|
| 26 |
+
<link rel="index" title="Index" href="../genindex.html" />
|
| 27 |
+
<link rel="search" title="Search" href="../search.html" />
|
| 28 |
+
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
| 29 |
+
<link rel="next" title="Development Tools" href="development.html" />
|
| 30 |
+
<link rel="prev" title="tkinter.tix — Extension widgets for Tk" href="tkinter.tix.html" />
|
| 31 |
+
<link rel="canonical" href="https://docs.python.org/3/library/idle.html" />
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
<style>
|
| 38 |
+
@media only screen {
|
| 39 |
+
table.full-width-table {
|
| 40 |
+
width: 100%;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
</style>
|
| 44 |
+
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
| 45 |
+
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
| 46 |
+
<script type="text/javascript" src="../_static/menu.js"></script>
|
| 47 |
+
|
| 48 |
+
</head>
|
| 49 |
+
<body>
|
| 50 |
+
<div class="mobile-nav">
|
| 51 |
+
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
| 52 |
+
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
| 53 |
+
<label for="menuToggler" class="toggler__label">
|
| 54 |
+
<span></span>
|
| 55 |
+
</label>
|
| 56 |
+
<nav class="nav-content" role="navigation">
|
| 57 |
+
<a href="https://www.python.org/" class="nav-logo">
|
| 58 |
+
<img src="../_static/py.svg" alt="Logo"/>
|
| 59 |
+
</a>
|
| 60 |
+
<div class="version_switcher_placeholder"></div>
|
| 61 |
+
<form role="search" class="search" action="../search.html" method="get">
|
| 62 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
| 63 |
+
<path fill-rule="nonzero"
|
| 64 |
+
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
| 65 |
+
</svg>
|
| 66 |
+
<input type="text" name="q" aria-label="Quick search"/>
|
| 67 |
+
<input type="submit" value="Go"/>
|
| 68 |
+
</form>
|
| 69 |
+
</nav>
|
| 70 |
+
<div class="menu-wrapper">
|
| 71 |
+
<nav class="menu" role="navigation" aria-label="main navigation">
|
| 72 |
+
<div class="language_switcher_placeholder"></div>
|
| 73 |
+
<div>
|
| 74 |
+
<h3><a href="../contents.html">Table of Contents</a></h3>
|
| 75 |
+
<ul>
|
| 76 |
+
<li><a class="reference internal" href="#">IDLE</a><ul>
|
| 77 |
+
<li><a class="reference internal" href="#menus">Menus</a><ul>
|
| 78 |
+
<li><a class="reference internal" href="#file-menu-shell-and-editor">File menu (Shell and Editor)</a></li>
|
| 79 |
+
<li><a class="reference internal" href="#edit-menu-shell-and-editor">Edit menu (Shell and Editor)</a></li>
|
| 80 |
+
<li><a class="reference internal" href="#format-menu-editor-window-only">Format menu (Editor window only)</a></li>
|
| 81 |
+
<li><a class="reference internal" href="#run-menu-editor-window-only">Run menu (Editor window only)</a></li>
|
| 82 |
+
<li><a class="reference internal" href="#shell-menu-shell-window-only">Shell menu (Shell window only)</a></li>
|
| 83 |
+
<li><a class="reference internal" href="#debug-menu-shell-window-only">Debug menu (Shell window only)</a></li>
|
| 84 |
+
<li><a class="reference internal" href="#options-menu-shell-and-editor">Options menu (Shell and Editor)</a></li>
|
| 85 |
+
<li><a class="reference internal" href="#window-menu-shell-and-editor">Window menu (Shell and Editor)</a></li>
|
| 86 |
+
<li><a class="reference internal" href="#help-menu-shell-and-editor">Help menu (Shell and Editor)</a></li>
|
| 87 |
+
<li><a class="reference internal" href="#context-menus">Context menus</a></li>
|
| 88 |
+
</ul>
|
| 89 |
+
</li>
|
| 90 |
+
<li><a class="reference internal" href="#editing-and-navigation">Editing and Navigation</a><ul>
|
| 91 |
+
<li><a class="reference internal" href="#editor-windows">Editor windows</a></li>
|
| 92 |
+
<li><a class="reference internal" href="#key-bindings">Key bindings</a></li>
|
| 93 |
+
<li><a class="reference internal" href="#automatic-indentation">Automatic indentation</a></li>
|
| 94 |
+
<li><a class="reference internal" href="#search-and-replace">Search and Replace</a></li>
|
| 95 |
+
<li><a class="reference internal" href="#completions">Completions</a></li>
|
| 96 |
+
<li><a class="reference internal" href="#calltips">Calltips</a></li>
|
| 97 |
+
<li><a class="reference internal" href="#code-context">Code Context</a></li>
|
| 98 |
+
<li><a class="reference internal" href="#shell-window">Shell window</a></li>
|
| 99 |
+
<li><a class="reference internal" href="#text-colors">Text colors</a></li>
|
| 100 |
+
</ul>
|
| 101 |
+
</li>
|
| 102 |
+
<li><a class="reference internal" href="#startup-and-code-execution">Startup and Code Execution</a><ul>
|
| 103 |
+
<li><a class="reference internal" href="#command-line-usage">Command line usage</a></li>
|
| 104 |
+
<li><a class="reference internal" href="#startup-failure">Startup failure</a></li>
|
| 105 |
+
<li><a class="reference internal" href="#running-user-code">Running user code</a></li>
|
| 106 |
+
<li><a class="reference internal" href="#user-output-in-shell">User output in Shell</a></li>
|
| 107 |
+
<li><a class="reference internal" href="#developing-tkinter-applications">Developing tkinter applications</a></li>
|
| 108 |
+
<li><a class="reference internal" href="#running-without-a-subprocess">Running without a subprocess</a></li>
|
| 109 |
+
</ul>
|
| 110 |
+
</li>
|
| 111 |
+
<li><a class="reference internal" href="#help-and-preferences">Help and Preferences</a><ul>
|
| 112 |
+
<li><a class="reference internal" href="#help-sources">Help sources</a></li>
|
| 113 |
+
<li><a class="reference internal" href="#setting-preferences">Setting preferences</a></li>
|
| 114 |
+
<li><a class="reference internal" href="#idle-on-macos">IDLE on macOS</a></li>
|
| 115 |
+
<li><a class="reference internal" href="#extensions">Extensions</a></li>
|
| 116 |
+
</ul>
|
| 117 |
+
</li>
|
| 118 |
+
<li><a class="reference internal" href="#module-idlelib">idlelib</a></li>
|
| 119 |
+
</ul>
|
| 120 |
+
</li>
|
| 121 |
+
</ul>
|
| 122 |
+
|
| 123 |
+
</div>
|
| 124 |
+
<div>
|
| 125 |
+
<h4>Previous topic</h4>
|
| 126 |
+
<p class="topless"><a href="tkinter.tix.html"
|
| 127 |
+
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code> — Extension widgets for Tk</a></p>
|
| 128 |
+
</div>
|
| 129 |
+
<div>
|
| 130 |
+
<h4>Next topic</h4>
|
| 131 |
+
<p class="topless"><a href="development.html"
|
| 132 |
+
title="next chapter">Development Tools</a></p>
|
| 133 |
+
</div>
|
| 134 |
+
<div role="note" aria-label="source link">
|
| 135 |
+
<h3>This Page</h3>
|
| 136 |
+
<ul class="this-page-menu">
|
| 137 |
+
<li><a href="../bugs.html">Report a Bug</a></li>
|
| 138 |
+
<li>
|
| 139 |
+
<a href="https://github.com/python/cpython/blob/main/Doc/library/idle.rst"
|
| 140 |
+
rel="nofollow">Show Source
|
| 141 |
+
</a>
|
| 142 |
+
</li>
|
| 143 |
+
</ul>
|
| 144 |
+
</div>
|
| 145 |
+
</nav>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
<div class="related" role="navigation" aria-label="related navigation">
|
| 151 |
+
<h3>Navigation</h3>
|
| 152 |
+
<ul>
|
| 153 |
+
<li class="right" style="margin-right: 10px">
|
| 154 |
+
<a href="../genindex.html" title="General Index"
|
| 155 |
+
accesskey="I">index</a></li>
|
| 156 |
+
<li class="right" >
|
| 157 |
+
<a href="../py-modindex.html" title="Python Module Index"
|
| 158 |
+
>modules</a> |</li>
|
| 159 |
+
<li class="right" >
|
| 160 |
+
<a href="development.html" title="Development Tools"
|
| 161 |
+
accesskey="N">next</a> |</li>
|
| 162 |
+
<li class="right" >
|
| 163 |
+
<a href="tkinter.tix.html" title="tkinter.tix — Extension widgets for Tk"
|
| 164 |
+
accesskey="P">previous</a> |</li>
|
| 165 |
+
|
| 166 |
+
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
| 167 |
+
<li><a href="https://www.python.org/">Python</a> »</li>
|
| 168 |
+
<li class="switchers">
|
| 169 |
+
<div class="language_switcher_placeholder"></div>
|
| 170 |
+
<div class="version_switcher_placeholder"></div>
|
| 171 |
+
</li>
|
| 172 |
+
<li>
|
| 173 |
+
|
| 174 |
+
</li>
|
| 175 |
+
<li id="cpython-language-and-version">
|
| 176 |
+
<a href="../index.html">3.12.0a0 Documentation</a> »
|
| 177 |
+
</li>
|
| 178 |
+
|
| 179 |
+
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
| 180 |
+
<li class="nav-item nav-item-2"><a href="tk.html" accesskey="U">Graphical User Interfaces with Tk</a> »</li>
|
| 181 |
+
<li class="nav-item nav-item-this"><a href="">IDLE</a></li>
|
| 182 |
+
<li class="right">
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
<div class="inline-search" role="search">
|
| 186 |
+
<form class="inline-search" action="../search.html" method="get">
|
| 187 |
+
<input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
|
| 188 |
+
<input type="submit" value="Go" />
|
| 189 |
+
<input type="hidden" name="check_keywords" value="yes" />
|
| 190 |
+
<input type="hidden" name="area" value="default" />
|
| 191 |
+
</form>
|
| 192 |
+
</div>
|
| 193 |
+
|
|
| 194 |
+
</li>
|
| 195 |
+
|
| 196 |
+
</ul>
|
| 197 |
+
</div>
|
| 198 |
+
|
| 199 |
+
<div class="document">
|
| 200 |
+
<div class="documentwrapper">
|
| 201 |
+
<div class="bodywrapper">
|
| 202 |
+
<div class="body" role="main">
|
| 203 |
+
|
| 204 |
+
<section id="idle">
|
| 205 |
+
<span id="id1"></span><h1>IDLE<a class="headerlink" href="#idle" title="Permalink to this heading">¶</a></h1>
|
| 206 |
+
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib/">Lib/idlelib/</a></p>
|
| 207 |
+
<hr class="docutils" id="index-0" />
|
| 208 |
+
<p>IDLE is Python’s Integrated Development and Learning Environment.</p>
|
| 209 |
+
<p>IDLE has the following features:</p>
|
| 210 |
+
<ul class="simple">
|
| 211 |
+
<li><p>coded in 100% pure Python, using the <a class="reference internal" href="tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> GUI toolkit</p></li>
|
| 212 |
+
<li><p>cross-platform: works mostly the same on Windows, Unix, and macOS</p></li>
|
| 213 |
+
<li><p>Python shell window (interactive interpreter) with colorizing
|
| 214 |
+
of code input, output, and error messages</p></li>
|
| 215 |
+
<li><p>multi-window text editor with multiple undo, Python colorizing,
|
| 216 |
+
smart indent, call tips, auto completion, and other features</p></li>
|
| 217 |
+
<li><p>search within any window, replace within editor windows, and search
|
| 218 |
+
through multiple files (grep)</p></li>
|
| 219 |
+
<li><p>debugger with persistent breakpoints, stepping, and viewing
|
| 220 |
+
of global and local namespaces</p></li>
|
| 221 |
+
<li><p>configuration, browsers, and other dialogs</p></li>
|
| 222 |
+
</ul>
|
| 223 |
+
<section id="menus">
|
| 224 |
+
<h2>Menus<a class="headerlink" href="#menus" title="Permalink to this heading">¶</a></h2>
|
| 225 |
+
<p>IDLE has two main window types, the Shell window and the Editor window. It is
|
| 226 |
+
possible to have multiple editor windows simultaneously. On Windows and
|
| 227 |
+
Linux, each has its own top menu. Each menu documented below indicates
|
| 228 |
+
which window type it is associated with.</p>
|
| 229 |
+
<p>Output windows, such as used for Edit => Find in Files, are a subtype of editor
|
| 230 |
+
window. They currently have the same top menu but a different
|
| 231 |
+
default title and context menu.</p>
|
| 232 |
+
<p>On macOS, there is one application menu. It dynamically changes according
|
| 233 |
+
to the window currently selected. It has an IDLE menu, and some entries
|
| 234 |
+
described below are moved around to conform to Apple guidelines.</p>
|
| 235 |
+
<section id="file-menu-shell-and-editor">
|
| 236 |
+
<h3>File menu (Shell and Editor)<a class="headerlink" href="#file-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 237 |
+
<dl class="simple">
|
| 238 |
+
<dt>New File</dt><dd><p>Create a new file editing window.</p>
|
| 239 |
+
</dd>
|
| 240 |
+
<dt>Open…</dt><dd><p>Open an existing file with an Open dialog.</p>
|
| 241 |
+
</dd>
|
| 242 |
+
<dt>Open Module…</dt><dd><p>Open an existing module (searches sys.path).</p>
|
| 243 |
+
</dd>
|
| 244 |
+
<dt>Recent Files</dt><dd><p>Open a list of recent files. Click one to open it.</p>
|
| 245 |
+
</dd>
|
| 246 |
+
</dl>
|
| 247 |
+
<dl class="simple" id="index-1">
|
| 248 |
+
<dt>Module Browser</dt><dd><p>Show functions, classes, and methods in the current Editor file in a
|
| 249 |
+
tree structure. In the shell, open a module first.</p>
|
| 250 |
+
</dd>
|
| 251 |
+
<dt>Path Browser</dt><dd><p>Show sys.path directories, modules, functions, classes and methods in a
|
| 252 |
+
tree structure.</p>
|
| 253 |
+
</dd>
|
| 254 |
+
<dt>Save</dt><dd><p>Save the current window to the associated file, if there is one. Windows
|
| 255 |
+
that have been changed since being opened or last saved have a * before
|
| 256 |
+
and after the window title. If there is no associated file,
|
| 257 |
+
do Save As instead.</p>
|
| 258 |
+
</dd>
|
| 259 |
+
<dt>Save As…</dt><dd><p>Save the current window with a Save As dialog. The file saved becomes the
|
| 260 |
+
new associated file for the window. (If your file namager is set to hide
|
| 261 |
+
extensions, the current extension will be omitted in the file name box.
|
| 262 |
+
If the new filename has no ‘.’, ‘.py’ and ‘.txt’ will be added for Python
|
| 263 |
+
and text files, except that on macOS Aqua,’.py’ is added for all files.)</p>
|
| 264 |
+
</dd>
|
| 265 |
+
<dt>Save Copy As…</dt><dd><p>Save the current window to different file without changing the associated
|
| 266 |
+
file. (See Save As note above about filename extensions.)</p>
|
| 267 |
+
</dd>
|
| 268 |
+
<dt>Print Window</dt><dd><p>Print the current window to the default printer.</p>
|
| 269 |
+
</dd>
|
| 270 |
+
<dt>Close Window</dt><dd><p>Close the current window (if an unsaved editor, ask to save; if an unsaved
|
| 271 |
+
Shell, ask to quit execution). Calling <code class="docutils literal notranslate"><span class="pre">exit()</span></code> or <code class="docutils literal notranslate"><span class="pre">close()</span></code> in the Shell
|
| 272 |
+
window also closes Shell. If this is the only window, also exit IDLE.</p>
|
| 273 |
+
</dd>
|
| 274 |
+
<dt>Exit IDLE</dt><dd><p>Close all windows and quit IDLE (ask to save unsaved edit windows).</p>
|
| 275 |
+
</dd>
|
| 276 |
+
</dl>
|
| 277 |
+
</section>
|
| 278 |
+
<section id="edit-menu-shell-and-editor">
|
| 279 |
+
<h3>Edit menu (Shell and Editor)<a class="headerlink" href="#edit-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 280 |
+
<dl class="simple">
|
| 281 |
+
<dt>Undo</dt><dd><p>Undo the last change to the current window. A maximum of 1000 changes may
|
| 282 |
+
be undone.</p>
|
| 283 |
+
</dd>
|
| 284 |
+
<dt>Redo</dt><dd><p>Redo the last undone change to the current window.</p>
|
| 285 |
+
</dd>
|
| 286 |
+
<dt>Select All</dt><dd><p>Select the entire contents of the current window.</p>
|
| 287 |
+
</dd>
|
| 288 |
+
<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>
|
| 289 |
+
</dd>
|
| 290 |
+
<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>
|
| 291 |
+
</dd>
|
| 292 |
+
<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>
|
| 293 |
+
</dd>
|
| 294 |
+
</dl>
|
| 295 |
+
<p>The clipboard functions are also available in context menus.</p>
|
| 296 |
+
<dl class="simple">
|
| 297 |
+
<dt>Find…</dt><dd><p>Open a search dialog with many options</p>
|
| 298 |
+
</dd>
|
| 299 |
+
<dt>Find Again</dt><dd><p>Repeat the last search, if there is one.</p>
|
| 300 |
+
</dd>
|
| 301 |
+
<dt>Find Selection</dt><dd><p>Search for the currently selected string, if there is one.</p>
|
| 302 |
+
</dd>
|
| 303 |
+
<dt>Find in Files…</dt><dd><p>Open a file search dialog. Put results in a new output window.</p>
|
| 304 |
+
</dd>
|
| 305 |
+
<dt>Replace…</dt><dd><p>Open a search-and-replace dialog.</p>
|
| 306 |
+
</dd>
|
| 307 |
+
<dt>Go to Line</dt><dd><p>Move the cursor to the beginning of the line requested and make that
|
| 308 |
+
line visible. A request past the end of the file goes to the end.
|
| 309 |
+
Clear any selection and update the line and column status.</p>
|
| 310 |
+
</dd>
|
| 311 |
+
<dt>Show Completions</dt><dd><p>Open a scrollable list allowing selection of existing names. See
|
| 312 |
+
<a class="reference internal" href="#completions"><span class="std std-ref">Completions</span></a> in the Editing and navigation section below.</p>
|
| 313 |
+
</dd>
|
| 314 |
+
<dt>Expand Word</dt><dd><p>Expand a prefix you have typed to match a full word in the same window;
|
| 315 |
+
repeat to get a different expansion.</p>
|
| 316 |
+
</dd>
|
| 317 |
+
<dt>Show Call Tip</dt><dd><p>After an unclosed parenthesis for a function, open a small window with
|
| 318 |
+
function parameter hints. See <a class="reference internal" href="#calltips"><span class="std std-ref">Calltips</span></a> in the
|
| 319 |
+
Editing and navigation section below.</p>
|
| 320 |
+
</dd>
|
| 321 |
+
<dt>Show Surrounding Parens</dt><dd><p>Highlight the surrounding parenthesis.</p>
|
| 322 |
+
</dd>
|
| 323 |
+
</dl>
|
| 324 |
+
</section>
|
| 325 |
+
<section id="format-menu-editor-window-only">
|
| 326 |
+
<span id="format-menu"></span><h3>Format menu (Editor window only)<a class="headerlink" href="#format-menu-editor-window-only" title="Permalink to this heading">¶</a></h3>
|
| 327 |
+
<dl class="simple">
|
| 328 |
+
<dt>Format Paragraph</dt><dd><p>Reformat the current blank-line-delimited paragraph in comment block or
|
| 329 |
+
multiline string or selected line in a string. All lines in the
|
| 330 |
+
paragraph will be formatted to less than N columns, where N defaults to 72.</p>
|
| 331 |
+
</dd>
|
| 332 |
+
<dt>Indent Region</dt><dd><p>Shift selected lines right by the indent width (default 4 spaces).</p>
|
| 333 |
+
</dd>
|
| 334 |
+
<dt>Dedent Region</dt><dd><p>Shift selected lines left by the indent width (default 4 spaces).</p>
|
| 335 |
+
</dd>
|
| 336 |
+
<dt>Comment Out Region</dt><dd><p>Insert ## in front of selected lines.</p>
|
| 337 |
+
</dd>
|
| 338 |
+
<dt>Uncomment Region</dt><dd><p>Remove leading # or ## from selected lines.</p>
|
| 339 |
+
</dd>
|
| 340 |
+
<dt>Tabify Region</dt><dd><p>Turn <em>leading</em> stretches of spaces into tabs. (Note: We recommend using
|
| 341 |
+
4 space blocks to indent Python code.)</p>
|
| 342 |
+
</dd>
|
| 343 |
+
<dt>Untabify Region</dt><dd><p>Turn <em>all</em> tabs into the correct number of spaces.</p>
|
| 344 |
+
</dd>
|
| 345 |
+
<dt>Toggle Tabs</dt><dd><p>Open a dialog to switch between indenting with spaces and tabs.</p>
|
| 346 |
+
</dd>
|
| 347 |
+
<dt>New Indent Width</dt><dd><p>Open a dialog to change indent width. The accepted default by the Python
|
| 348 |
+
community is 4 spaces.</p>
|
| 349 |
+
</dd>
|
| 350 |
+
<dt>Strip Trailing Chitespace</dt><dd><p>Remove trailing space and other whitespace characters after the last
|
| 351 |
+
non-whitespace character of a line by applying str.rstrip to each line,
|
| 352 |
+
including lines within multiline strings. Except for Shell windows,
|
| 353 |
+
remove extra newlines at the end of the file.</p>
|
| 354 |
+
</dd>
|
| 355 |
+
</dl>
|
| 356 |
+
</section>
|
| 357 |
+
<section id="run-menu-editor-window-only">
|
| 358 |
+
<span id="index-2"></span><h3>Run menu (Editor window only)<a class="headerlink" href="#run-menu-editor-window-only" title="Permalink to this heading">¶</a></h3>
|
| 359 |
+
<dl class="simple" id="run-module">
|
| 360 |
+
<dt>Run Module</dt><dd><p>Do <a class="reference internal" href="#check-module"><span class="std std-ref">Check Module</span></a>. If no error, restart the shell to clean the
|
| 361 |
+
environment, then execute the module. Output is displayed in the Shell
|
| 362 |
+
window. Note that output requires use of <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code>.
|
| 363 |
+
When execution is complete, the Shell retains focus and displays a prompt.
|
| 364 |
+
At this point, one may interactively explore the result of execution.
|
| 365 |
+
This is similar to executing a file with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span> <span class="pre">file</span></code> at a command
|
| 366 |
+
line.</p>
|
| 367 |
+
</dd>
|
| 368 |
+
</dl>
|
| 369 |
+
<dl class="simple" id="run-custom">
|
| 370 |
+
<dt>Run… Customized</dt><dd><p>Same as <a class="reference internal" href="#run-module"><span class="std std-ref">Run Module</span></a>, but run the module with customized
|
| 371 |
+
settings. <em>Command Line Arguments</em> extend <a class="reference internal" href="sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> as if passed
|
| 372 |
+
on a command line. The module can be run in the Shell without restarting.</p>
|
| 373 |
+
</dd>
|
| 374 |
+
</dl>
|
| 375 |
+
<dl class="simple" id="check-module">
|
| 376 |
+
<dt>Check Module</dt><dd><p>Check the syntax of the module currently open in the Editor window. If the
|
| 377 |
+
module has not been saved IDLE will either prompt the user to save or
|
| 378 |
+
autosave, as selected in the General tab of the Idle Settings dialog. If
|
| 379 |
+
there is a syntax error, the approximate location is indicated in the
|
| 380 |
+
Editor window.</p>
|
| 381 |
+
</dd>
|
| 382 |
+
</dl>
|
| 383 |
+
<dl class="simple" id="python-shell">
|
| 384 |
+
<dt>Python Shell</dt><dd><p>Open or wake up the Python Shell window.</p>
|
| 385 |
+
</dd>
|
| 386 |
+
</dl>
|
| 387 |
+
</section>
|
| 388 |
+
<section id="shell-menu-shell-window-only">
|
| 389 |
+
<h3>Shell menu (Shell window only)<a class="headerlink" href="#shell-menu-shell-window-only" title="Permalink to this heading">¶</a></h3>
|
| 390 |
+
<dl class="simple">
|
| 391 |
+
<dt>View Last Restart</dt><dd><p>Scroll the shell window to the last Shell restart.</p>
|
| 392 |
+
</dd>
|
| 393 |
+
<dt>Restart Shell</dt><dd><p>Restart the shell to clean the environment and reset display and exception handling.</p>
|
| 394 |
+
</dd>
|
| 395 |
+
<dt>Previous History</dt><dd><p>Cycle through earlier commands in history which match the current entry.</p>
|
| 396 |
+
</dd>
|
| 397 |
+
<dt>Next History</dt><dd><p>Cycle through later commands in history which match the current entry.</p>
|
| 398 |
+
</dd>
|
| 399 |
+
<dt>Interrupt Execution</dt><dd><p>Stop a running program.</p>
|
| 400 |
+
</dd>
|
| 401 |
+
</dl>
|
| 402 |
+
</section>
|
| 403 |
+
<section id="debug-menu-shell-window-only">
|
| 404 |
+
<h3>Debug menu (Shell window only)<a class="headerlink" href="#debug-menu-shell-window-only" title="Permalink to this heading">¶</a></h3>
|
| 405 |
+
<dl class="simple">
|
| 406 |
+
<dt>Go to File/Line</dt><dd><p>Look on the current line. with the cursor, and the line above for a filename
|
| 407 |
+
and line number. If found, open the file if not already open, and show the
|
| 408 |
+
line. Use this to view source lines referenced in an exception traceback
|
| 409 |
+
and lines found by Find in Files. Also available in the context menu of
|
| 410 |
+
the Shell window and Output windows.</p>
|
| 411 |
+
</dd>
|
| 412 |
+
</dl>
|
| 413 |
+
<dl class="simple" id="index-3">
|
| 414 |
+
<dt>Debugger (toggle)</dt><dd><p>When activated, code entered in the Shell or run from an Editor will run
|
| 415 |
+
under the debugger. In the Editor, breakpoints can be set with the context
|
| 416 |
+
menu. This feature is still incomplete and somewhat experimental.</p>
|
| 417 |
+
</dd>
|
| 418 |
+
<dt>Stack Viewer</dt><dd><p>Show the stack traceback of the last exception in a tree widget, with
|
| 419 |
+
access to locals and globals.</p>
|
| 420 |
+
</dd>
|
| 421 |
+
<dt>Auto-open Stack Viewer</dt><dd><p>Toggle automatically opening the stack viewer on an unhandled exception.</p>
|
| 422 |
+
</dd>
|
| 423 |
+
</dl>
|
| 424 |
+
</section>
|
| 425 |
+
<section id="options-menu-shell-and-editor">
|
| 426 |
+
<h3>Options menu (Shell and Editor)<a class="headerlink" href="#options-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 427 |
+
<dl class="simple">
|
| 428 |
+
<dt>Configure IDLE</dt><dd><p>Open a configuration dialog and change preferences for the following:
|
| 429 |
+
fonts, indentation, keybindings, text color themes, startup windows and
|
| 430 |
+
size, additional help sources, and extensions. On macOS, open the
|
| 431 |
+
configuration dialog by selecting Preferences in the application
|
| 432 |
+
menu. For more details, see
|
| 433 |
+
<a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a> under Help and preferences.</p>
|
| 434 |
+
</dd>
|
| 435 |
+
</dl>
|
| 436 |
+
<p>Most configuration options apply to all windows or all future windows.
|
| 437 |
+
The option items below only apply to the active window.</p>
|
| 438 |
+
<dl class="simple">
|
| 439 |
+
<dt>Show/Hide Code Context (Editor Window only)</dt><dd><p>Open a pane at the top of the edit window which shows the block context
|
| 440 |
+
of the code which has scrolled above the top of the window. See
|
| 441 |
+
<a class="reference internal" href="#code-context"><span class="std std-ref">Code Context</span></a> in the Editing and Navigation section
|
| 442 |
+
below.</p>
|
| 443 |
+
</dd>
|
| 444 |
+
<dt>Show/Hide Line Numbers (Editor Window only)</dt><dd><p>Open a column to the left of the edit window which shows the number
|
| 445 |
+
of each line of text. The default is off, which may be changed in the
|
| 446 |
+
preferences (see <a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a>).</p>
|
| 447 |
+
</dd>
|
| 448 |
+
<dt>Zoom/Restore Height</dt><dd><p>Toggles the window between normal size and maximum height. The initial size
|
| 449 |
+
defaults to 40 lines by 80 chars unless changed on the General tab of the
|
| 450 |
+
Configure IDLE dialog. The maximum height for a screen is determined by
|
| 451 |
+
momentarily maximizing a window the first time one is zoomed on the screen.
|
| 452 |
+
Changing screen settings may invalidate the saved height. This toggle has
|
| 453 |
+
no effect when a window is maximized.</p>
|
| 454 |
+
</dd>
|
| 455 |
+
</dl>
|
| 456 |
+
</section>
|
| 457 |
+
<section id="window-menu-shell-and-editor">
|
| 458 |
+
<h3>Window menu (Shell and Editor)<a class="headerlink" href="#window-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 459 |
+
<p>Lists the names of all open windows; select one to bring it to the foreground
|
| 460 |
+
(deiconifying it if necessary).</p>
|
| 461 |
+
</section>
|
| 462 |
+
<section id="help-menu-shell-and-editor">
|
| 463 |
+
<h3>Help menu (Shell and Editor)<a class="headerlink" href="#help-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 464 |
+
<dl class="simple">
|
| 465 |
+
<dt>About IDLE</dt><dd><p>Display version, copyright, license, credits, and more.</p>
|
| 466 |
+
</dd>
|
| 467 |
+
<dt>IDLE Help</dt><dd><p>Display this IDLE document, detailing the menu options, basic editing and
|
| 468 |
+
navigation, and other tips.</p>
|
| 469 |
+
</dd>
|
| 470 |
+
<dt>Python Docs</dt><dd><p>Access local Python documentation, if installed, or start a web browser
|
| 471 |
+
and open docs.python.org showing the latest Python documentation.</p>
|
| 472 |
+
</dd>
|
| 473 |
+
<dt>Turtle Demo</dt><dd><p>Run the turtledemo module with example Python code and turtle drawings.</p>
|
| 474 |
+
</dd>
|
| 475 |
+
</dl>
|
| 476 |
+
<p>Additional help sources may be added here with the Configure IDLE dialog under
|
| 477 |
+
the General tab. See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below
|
| 478 |
+
for more on Help menu choices.</p>
|
| 479 |
+
</section>
|
| 480 |
+
<section id="context-menus">
|
| 481 |
+
<span id="index-4"></span><h3>Context menus<a class="headerlink" href="#context-menus" title="Permalink to this heading">¶</a></h3>
|
| 482 |
+
<p>Open a context menu by right-clicking in a window (Control-click on macOS).
|
| 483 |
+
Context menus have the standard clipboard functions also on the Edit menu.</p>
|
| 484 |
+
<dl class="simple">
|
| 485 |
+
<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>
|
| 486 |
+
</dd>
|
| 487 |
+
<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>
|
| 488 |
+
</dd>
|
| 489 |
+
<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>
|
| 490 |
+
</dd>
|
| 491 |
+
</dl>
|
| 492 |
+
<p>Editor windows also have breakpoint functions. Lines with a breakpoint set are
|
| 493 |
+
specially marked. Breakpoints only have an effect when running under the
|
| 494 |
+
debugger. Breakpoints for a file are saved in the user’s <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>
|
| 495 |
+
directory.</p>
|
| 496 |
+
<dl class="simple">
|
| 497 |
+
<dt>Set Breakpoint</dt><dd><p>Set a breakpoint on the current line.</p>
|
| 498 |
+
</dd>
|
| 499 |
+
<dt>Clear Breakpoint</dt><dd><p>Clear the breakpoint on that line.</p>
|
| 500 |
+
</dd>
|
| 501 |
+
</dl>
|
| 502 |
+
<p>Shell and Output windows also have the following.</p>
|
| 503 |
+
<dl class="simple">
|
| 504 |
+
<dt>Go to file/line</dt><dd><p>Same as in Debug menu.</p>
|
| 505 |
+
</dd>
|
| 506 |
+
</dl>
|
| 507 |
+
<p>The Shell window also has an output squeezing facility explained in the <em>Python
|
| 508 |
+
Shell window</em> subsection below.</p>
|
| 509 |
+
<dl class="simple">
|
| 510 |
+
<dt>Squeeze</dt><dd><p>If the cursor is over an output line, squeeze all the output between
|
| 511 |
+
the code above and the prompt below down to a ‘Squeezed text’ label.</p>
|
| 512 |
+
</dd>
|
| 513 |
+
</dl>
|
| 514 |
+
</section>
|
| 515 |
+
</section>
|
| 516 |
+
<section id="editing-and-navigation">
|
| 517 |
+
<span id="id2"></span><h2>Editing and Navigation<a class="headerlink" href="#editing-and-navigation" title="Permalink to this heading">¶</a></h2>
|
| 518 |
+
<section id="editor-windows">
|
| 519 |
+
<h3>Editor windows<a class="headerlink" href="#editor-windows" title="Permalink to this heading">¶</a></h3>
|
| 520 |
+
<p>IDLE may open editor windows when it starts, depending on settings
|
| 521 |
+
and how you start IDLE. Thereafter, use the File menu. There can be only
|
| 522 |
+
one open editor window for a given file.</p>
|
| 523 |
+
<p>The title bar contains the name of the file, the full path, and the version
|
| 524 |
+
of Python and IDLE running the window. The status bar contains the line
|
| 525 |
+
number (‘Ln’) and column number (‘Col’). Line numbers start with 1;
|
| 526 |
+
column numbers with 0.</p>
|
| 527 |
+
<p>IDLE assumes that files with a known .py* extension contain Python code
|
| 528 |
+
and that other files do not. Run Python code with the Run menu.</p>
|
| 529 |
+
</section>
|
| 530 |
+
<section id="key-bindings">
|
| 531 |
+
<h3>Key bindings<a class="headerlink" href="#key-bindings" title="Permalink to this heading">¶</a></h3>
|
| 532 |
+
<p>In this section, ‘C’ refers to the <kbd class="kbd docutils literal notranslate">Control</kbd> key on Windows and Unix and
|
| 533 |
+
the <kbd class="kbd docutils literal notranslate">Command</kbd> key on macOS.</p>
|
| 534 |
+
<ul>
|
| 535 |
+
<li><p><kbd class="kbd docutils literal notranslate">Backspace</kbd> deletes to the left; <kbd class="kbd docutils literal notranslate">Del</kbd> deletes to the right</p></li>
|
| 536 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Backspace</kbd></kbd> delete word left; <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Del</kbd></kbd> delete word to the right</p></li>
|
| 537 |
+
<li><p>Arrow keys and <kbd class="kbd docutils literal notranslate">Page Up</kbd>/<kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Page</kbd> <kbd class="kbd docutils literal notranslate">Down</kbd></kbd> to move around</p></li>
|
| 538 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">LeftArrow</kbd></kbd> and <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">RightArrow</kbd></kbd> moves by words</p></li>
|
| 539 |
+
<li><p><kbd class="kbd docutils literal notranslate">Home</kbd>/<kbd class="kbd docutils literal notranslate">End</kbd> go to begin/end of line</p></li>
|
| 540 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Home</kbd></kbd>/<kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">End</kbd></kbd> go to begin/end of file</p></li>
|
| 541 |
+
<li><p>Some useful Emacs bindings are inherited from Tcl/Tk:</p>
|
| 542 |
+
<blockquote>
|
| 543 |
+
<div><ul class="simple">
|
| 544 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">a</kbd></kbd> beginning of line</p></li>
|
| 545 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">e</kbd></kbd> end of line</p></li>
|
| 546 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">k</kbd></kbd> kill line (but doesn’t put it in clipboard)</p></li>
|
| 547 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">l</kbd></kbd> center window around the insertion point</p></li>
|
| 548 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">b</kbd></kbd> go backward one character without deleting (usually you can
|
| 549 |
+
also use the cursor key for this)</p></li>
|
| 550 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">f</kbd></kbd> go forward one character without deleting (usually you can
|
| 551 |
+
also use the cursor key for this)</p></li>
|
| 552 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd></kbd> go up one line (usually you can also use the cursor key for
|
| 553 |
+
this)</p></li>
|
| 554 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd></kbd> delete next character</p></li>
|
| 555 |
+
</ul>
|
| 556 |
+
</div></blockquote>
|
| 557 |
+
</li>
|
| 558 |
+
</ul>
|
| 559 |
+
<p>Standard keybindings (like <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd></kbd> to copy and <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">v</kbd></kbd> to paste)
|
| 560 |
+
may work. Keybindings are selected in the Configure IDLE dialog.</p>
|
| 561 |
+
</section>
|
| 562 |
+
<section id="automatic-indentation">
|
| 563 |
+
<h3>Automatic indentation<a class="headerlink" href="#automatic-indentation" title="Permalink to this heading">¶</a></h3>
|
| 564 |
+
<p>After a block-opening statement, the next line is indented by 4 spaces (in the
|
| 565 |
+
Python Shell window by one tab). After certain keywords (break, return etc.)
|
| 566 |
+
the next line is dedented. In leading indentation, <kbd class="kbd docutils literal notranslate">Backspace</kbd> deletes up
|
| 567 |
+
to 4 spaces if they are there. <kbd class="kbd docutils literal notranslate">Tab</kbd> inserts spaces (in the Python
|
| 568 |
+
Shell window one tab), number depends on Indent width. Currently, tabs
|
| 569 |
+
are restricted to four spaces due to Tcl/Tk limitations.</p>
|
| 570 |
+
<p>See also the indent/dedent region commands on the
|
| 571 |
+
<a class="reference internal" href="#format-menu"><span class="std std-ref">Format menu</span></a>.</p>
|
| 572 |
+
</section>
|
| 573 |
+
<section id="search-and-replace">
|
| 574 |
+
<h3>Search and Replace<a class="headerlink" href="#search-and-replace" title="Permalink to this heading">¶</a></h3>
|
| 575 |
+
<p>Any selection becomes a search target. However, only selections within
|
| 576 |
+
a line work because searches are only performed within lines with the
|
| 577 |
+
terminal newline removed. If <code class="docutils literal notranslate"><span class="pre">[x]</span> <span class="pre">Regular</span> <span class="pre">expresion</span></code> is checked, the
|
| 578 |
+
target is interpreted according to the Python re module.</p>
|
| 579 |
+
</section>
|
| 580 |
+
<section id="completions">
|
| 581 |
+
<span id="id3"></span><h3>Completions<a class="headerlink" href="#completions" title="Permalink to this heading">¶</a></h3>
|
| 582 |
+
<p>Completions are supplied, when requested and available, for module
|
| 583 |
+
names, attributes of classes or functions, or filenames. Each request
|
| 584 |
+
method displays a completion box with existing names. (See tab
|
| 585 |
+
completions below for an exception.) For any box, change the name
|
| 586 |
+
being completed and the item highlighted in the box by
|
| 587 |
+
typing and deleting characters; by hitting <kbd class="kbd docutils literal notranslate">Up</kbd>, <kbd class="kbd docutils literal notranslate">Down</kbd>,
|
| 588 |
+
<kbd class="kbd docutils literal notranslate">PageUp</kbd>, <kbd class="kbd docutils literal notranslate">PageDown</kbd>, <kbd class="kbd docutils literal notranslate">Home</kbd>, and <kbd class="kbd docutils literal notranslate">End</kbd> keys;
|
| 589 |
+
and by a single click within the box. Close the box with <kbd class="kbd docutils literal notranslate">Escape</kbd>,
|
| 590 |
+
<kbd class="kbd docutils literal notranslate">Enter</kbd>, and double <kbd class="kbd docutils literal notranslate">Tab</kbd> keys or clicks outside the box.
|
| 591 |
+
A double click within the box selects and closes.</p>
|
| 592 |
+
<p>One way to open a box is to type a key character and wait for a
|
| 593 |
+
predefined interval. This defaults to 2 seconds; customize it
|
| 594 |
+
in the settings dialog. (To prevent auto popups, set the delay to a
|
| 595 |
+
large number of milliseconds, such as 100000000.) For imported module
|
| 596 |
+
names or class or function attributes, type ‘.’.
|
| 597 |
+
For filenames in the root directory, type <a class="reference internal" href="os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.sep</span></code></a> or
|
| 598 |
+
<a class="reference internal" href="os.html#os.altsep" title="os.altsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.altsep</span></code></a> immediately after an opening quote. (On Windows,
|
| 599 |
+
one can specify a drive first.) Move into subdirectories by typing a
|
| 600 |
+
directory name and a separator.</p>
|
| 601 |
+
<p>Instead of waiting, or after a box is closed, open a completion box
|
| 602 |
+
immediately with Show Completions on the Edit menu. The default hot
|
| 603 |
+
key is <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">space</kbd></kbd>. If one types a prefix for the desired name
|
| 604 |
+
before opening the box, the first match or near miss is made visible.
|
| 605 |
+
The result is the same as if one enters a prefix
|
| 606 |
+
after the box is displayed. Show Completions after a quote completes
|
| 607 |
+
filenames in the current directory instead of a root directory.</p>
|
| 608 |
+
<p>Hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix usually has the same effect as Show
|
| 609 |
+
Completions. (With no prefix, it indents.) However, if there is only
|
| 610 |
+
one match to the prefix, that match is immediately added to the editor
|
| 611 |
+
text without opening a box.</p>
|
| 612 |
+
<p>Invoking ‘Show Completions’, or hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix,
|
| 613 |
+
outside of a string and without a preceding ‘.’ opens a box with
|
| 614 |
+
keywords, builtin names, and available module-level names.</p>
|
| 615 |
+
<p>When editing code in an editor (as oppose to Shell), increase the
|
| 616 |
+
available module-level names by running your code
|
| 617 |
+
and not restarting the Shell thereafter. This is especially useful
|
| 618 |
+
after adding imports at the top of a file. This also increases
|
| 619 |
+
possible attribute completions.</p>
|
| 620 |
+
<p>Completion boxes initially exclude names beginning with ‘_’ or, for
|
| 621 |
+
modules, not included in ‘__all__’. The hidden names can be accessed
|
| 622 |
+
by typing ‘_’ after ‘.’, either before or after the box is opened.</p>
|
| 623 |
+
</section>
|
| 624 |
+
<section id="calltips">
|
| 625 |
+
<span id="id4"></span><h3>Calltips<a class="headerlink" href="#calltips" title="Permalink to this heading">¶</a></h3>
|
| 626 |
+
<p>A calltip is shown automatically when one types <kbd class="kbd docutils literal notranslate">(</kbd> after the name
|
| 627 |
+
of an <em>accessible</em> function. A function name expression may include
|
| 628 |
+
dots and subscripts. A calltip remains until it is clicked, the cursor
|
| 629 |
+
is moved out of the argument area, or <kbd class="kbd docutils literal notranslate">)</kbd> is typed. Whenever the
|
| 630 |
+
cursor is in the argument part of a definition, select Edit and “Show
|
| 631 |
+
Call Tip” on the menu or enter its shortcut to display a calltip.</p>
|
| 632 |
+
<p>The calltip consists of the function’s signature and docstring up to
|
| 633 |
+
the latter’s first blank line or the fifth non-blank line. (Some builtin
|
| 634 |
+
functions lack an accessible signature.) A ‘/’ or ‘*’ in the signature
|
| 635 |
+
indicates that the preceding or following arguments are passed by
|
| 636 |
+
position or name (keyword) only. Details are subject to change.</p>
|
| 637 |
+
<p>In Shell, the accessible functions depends on what modules have been
|
| 638 |
+
imported into the user process, including those imported by Idle itself,
|
| 639 |
+
and which definitions have been run, all since the last restart.</p>
|
| 640 |
+
<p>For example, restart the Shell and enter <code class="docutils literal notranslate"><span class="pre">itertools.count(</span></code>. A calltip
|
| 641 |
+
appears because Idle imports itertools into the user process for its own
|
| 642 |
+
use. (This could change.) Enter <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code> and nothing appears.
|
| 643 |
+
Idle does not itself import turtle. The menu entry and shortcut also do
|
| 644 |
+
nothing. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">turtle</span></code>. Thereafter, <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code>
|
| 645 |
+
will display a calltip.</p>
|
| 646 |
+
<p>In an editor, import statements have no effect until one runs the file.
|
| 647 |
+
One might want to run a file after writing import statements, after
|
| 648 |
+
adding function definitions, or after opening an existing file.</p>
|
| 649 |
+
</section>
|
| 650 |
+
<section id="code-context">
|
| 651 |
+
<span id="id5"></span><h3>Code Context<a class="headerlink" href="#code-context" title="Permalink to this heading">¶</a></h3>
|
| 652 |
+
<p>Within an editor window containing Python code, code context can be toggled
|
| 653 |
+
in order to show or hide a pane at the top of the window. When shown, this
|
| 654 |
+
pane freezes the opening lines for block code, such as those beginning with
|
| 655 |
+
<code class="docutils literal notranslate"><span class="pre">class</span></code>, <code class="docutils literal notranslate"><span class="pre">def</span></code>, or <code class="docutils literal notranslate"><span class="pre">if</span></code> keywords, that would have otherwise scrolled
|
| 656 |
+
out of view. The size of the pane will be expanded and contracted as needed
|
| 657 |
+
to show the all current levels of context, up to the maximum number of
|
| 658 |
+
lines defined in the Configure IDLE dialog (which defaults to 15). If there
|
| 659 |
+
are no current context lines and the feature is toggled on, a single blank
|
| 660 |
+
line will display. Clicking on a line in the context pane will move that
|
| 661 |
+
line to the top of the editor.</p>
|
| 662 |
+
<p>The text and background colors for the context pane can be configured under
|
| 663 |
+
the Highlights tab in the Configure IDLE dialog.</p>
|
| 664 |
+
</section>
|
| 665 |
+
<section id="shell-window">
|
| 666 |
+
<h3>Shell window<a class="headerlink" href="#shell-window" title="Permalink to this heading">¶</a></h3>
|
| 667 |
+
<p>In IDLE’s Shell, enter, edit, and recall complete statements. (Most
|
| 668 |
+
consoles and terminals only work with a single physical line at a time).</p>
|
| 669 |
+
<p>Submit a single-line statement for execution by hitting <kbd class="kbd docutils literal notranslate">Return</kbd>
|
| 670 |
+
with the cursor anywhere on the line. If a line is extended with
|
| 671 |
+
Backslash (<kbd class="kbd docutils literal notranslate">\</kbd>), the cursor must be on the last physical line.
|
| 672 |
+
Submit a multi-line compound statement by entering a blank line after
|
| 673 |
+
the statement.</p>
|
| 674 |
+
<p>When one pastes code into Shell, it is not compiled and possibly executed
|
| 675 |
+
until one hits <kbd class="kbd docutils literal notranslate">Return</kbd>, as specified above.
|
| 676 |
+
One may edit pasted code first.
|
| 677 |
+
If one pastes more than one statement into Shell, the result will be a
|
| 678 |
+
<a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> when multiple statements are compiled as if they were one.</p>
|
| 679 |
+
<p>Lines containing <code class="docutils literal notranslate"><span class="pre">RESTART</span></code> mean that the user execution process has been
|
| 680 |
+
re-started. This occurs when the user execution process has crashed,
|
| 681 |
+
when one requests a restart on the Shell menu, or when one runs code
|
| 682 |
+
in an editor window.</p>
|
| 683 |
+
<p>The editing features described in previous subsections work when entering
|
| 684 |
+
code interactively. IDLE’s Shell window also responds to the following keys.</p>
|
| 685 |
+
<ul>
|
| 686 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd></kbd> interrupts executing command</p></li>
|
| 687 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd></kbd> sends end-of-file; closes window if typed at a <code class="docutils literal notranslate"><span class="pre">>>></span></code> prompt</p></li>
|
| 688 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">/</kbd></kbd> (Expand word) is also useful to reduce typing</p>
|
| 689 |
+
<p>Command history</p>
|
| 690 |
+
<ul class="simple">
|
| 691 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd></kbd> retrieves previous command matching what you have typed. On
|
| 692 |
+
macOS use <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd></kbd>.</p></li>
|
| 693 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd></kbd> retrieves next. On macOS use <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd></kbd>.</p></li>
|
| 694 |
+
<li><p><kbd class="kbd docutils literal notranslate">Return</kbd> while the cursor is on any previous command
|
| 695 |
+
retrieves that command</p></li>
|
| 696 |
+
</ul>
|
| 697 |
+
</li>
|
| 698 |
+
</ul>
|
| 699 |
+
</section>
|
| 700 |
+
<section id="text-colors">
|
| 701 |
+
<h3>Text colors<a class="headerlink" href="#text-colors" title="Permalink to this heading">¶</a></h3>
|
| 702 |
+
<p>Idle defaults to black on white text, but colors text with special meanings.
|
| 703 |
+
For the shell, these are shell output, shell error, user output, and
|
| 704 |
+
user error. For Python code, at the shell prompt or in an editor, these are
|
| 705 |
+
keywords, builtin class and function names, names following <code class="docutils literal notranslate"><span class="pre">class</span></code> and
|
| 706 |
+
<code class="docutils literal notranslate"><span class="pre">def</span></code>, strings, and comments. For any text window, these are the cursor (when
|
| 707 |
+
present), found text (when possible), and selected text.</p>
|
| 708 |
+
<p>IDLE also highlights the <a class="reference internal" href="../reference/lexical_analysis.html#soft-keywords"><span class="std std-ref">soft keywords</span></a> <a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">match</span></code></a>,
|
| 709 |
+
<a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">case</span></code></a>, and <a class="reference internal" href="../reference/compound_stmts.html#wildcard-patterns"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">_</span></code></a> in
|
| 710 |
+
pattern-matching statements. However, this highlighting is not perfect and
|
| 711 |
+
will be incorrect in some rare cases, including some <code class="docutils literal notranslate"><span class="pre">_</span></code>-s in <code class="docutils literal notranslate"><span class="pre">case</span></code>
|
| 712 |
+
patterns.</p>
|
| 713 |
+
<p>Text coloring is done in the background, so uncolorized text is occasionally
|
| 714 |
+
visible. To change the color scheme, use the Configure IDLE dialog
|
| 715 |
+
Highlighting tab. The marking of debugger breakpoint lines in the editor and
|
| 716 |
+
text in popups and dialogs is not user-configurable.</p>
|
| 717 |
+
</section>
|
| 718 |
+
</section>
|
| 719 |
+
<section id="startup-and-code-execution">
|
| 720 |
+
<h2>Startup and Code Execution<a class="headerlink" href="#startup-and-code-execution" title="Permalink to this heading">¶</a></h2>
|
| 721 |
+
<p>Upon startup with the <code class="docutils literal notranslate"><span class="pre">-s</span></code> option, IDLE will execute the file referenced by
|
| 722 |
+
the environment variables <span class="target" id="index-5"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> or <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>.
|
| 723 |
+
IDLE first checks for <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code>; if <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is present the file
|
| 724 |
+
referenced is run. If <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is not present, IDLE checks for
|
| 725 |
+
<code class="docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code>. Files referenced by these environment variables are
|
| 726 |
+
convenient places to store functions that are used frequently from the IDLE
|
| 727 |
+
shell, or for executing import statements to import common modules.</p>
|
| 728 |
+
<p>In addition, <code class="docutils literal notranslate"><span class="pre">Tk</span></code> also loads a startup file if it is present. Note that the
|
| 729 |
+
Tk file is loaded unconditionally. This additional file is <code class="docutils literal notranslate"><span class="pre">.Idle.py</span></code> and is
|
| 730 |
+
looked for in the user’s home directory. Statements in this file will be
|
| 731 |
+
executed in the Tk namespace, so this file is not useful for importing
|
| 732 |
+
functions to be used from IDLE’s Python shell.</p>
|
| 733 |
+
<section id="command-line-usage">
|
| 734 |
+
<h3>Command line usage<a class="headerlink" href="#command-line-usage" title="Permalink to this heading">¶</a></h3>
|
| 735 |
+
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
|
| 736 |
+
|
| 737 |
+
-c command run command in the shell window
|
| 738 |
+
-d enable debugger and open shell window
|
| 739 |
+
-e open editor window
|
| 740 |
+
-h print help message with legal combinations and exit
|
| 741 |
+
-i open shell window
|
| 742 |
+
-r file run file in shell window
|
| 743 |
+
-s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
|
| 744 |
+
-t title set title of shell window
|
| 745 |
+
- run stdin in shell (- must be last option before args)
|
| 746 |
+
</pre></div>
|
| 747 |
+
</div>
|
| 748 |
+
<p>If there are arguments:</p>
|
| 749 |
+
<ul class="simple">
|
| 750 |
+
<li><p>If <code class="docutils literal notranslate"><span class="pre">-</span></code>, <code class="docutils literal notranslate"><span class="pre">-c</span></code>, or <code class="docutils literal notranslate"><span class="pre">r</span></code> is used, all arguments are placed in
|
| 751 |
+
<code class="docutils literal notranslate"><span class="pre">sys.argv[1:...]</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> is set to <code class="docutils literal notranslate"><span class="pre">''</span></code>, <code class="docutils literal notranslate"><span class="pre">'-c'</span></code>,
|
| 752 |
+
or <code class="docutils literal notranslate"><span class="pre">'-r'</span></code>. No editor window is opened, even if that is the default
|
| 753 |
+
set in the Options dialog.</p></li>
|
| 754 |
+
<li><p>Otherwise, arguments are files opened for editing and
|
| 755 |
+
<code class="docutils literal notranslate"><span class="pre">sys.argv</span></code> reflects the arguments passed to IDLE itself.</p></li>
|
| 756 |
+
</ul>
|
| 757 |
+
</section>
|
| 758 |
+
<section id="startup-failure">
|
| 759 |
+
<h3>Startup failure<a class="headerlink" href="#startup-failure" title="Permalink to this heading">¶</a></h3>
|
| 760 |
+
<p>IDLE uses a socket to communicate between the IDLE GUI process and the user
|
| 761 |
+
code execution process. A connection must be established whenever the Shell
|
| 762 |
+
starts or restarts. (The latter is indicated by a divider line that says
|
| 763 |
+
‘RESTART’). If the user process fails to connect to the GUI process, it
|
| 764 |
+
usually displays a <code class="docutils literal notranslate"><span class="pre">Tk</span></code> error box with a ‘cannot connect’ message
|
| 765 |
+
that directs the user here. It then exits.</p>
|
| 766 |
+
<p>One specific connection failure on Unix systems results from
|
| 767 |
+
misconfigured masquerading rules somewhere in a system’s network setup.
|
| 768 |
+
When IDLE is started from a terminal, one will see a message starting
|
| 769 |
+
with <code class="docutils literal notranslate"><span class="pre">**</span> <span class="pre">Invalid</span> <span class="pre">host:</span></code>.
|
| 770 |
+
The valid value is <code class="docutils literal notranslate"><span class="pre">127.0.0.1</span> <span class="pre">(idlelib.rpc.LOCALHOST)</span></code>.
|
| 771 |
+
One can diagnose with <code class="docutils literal notranslate"><span class="pre">tcpconnect</span> <span class="pre">-irv</span> <span class="pre">127.0.0.1</span> <span class="pre">6543</span></code> in one
|
| 772 |
+
terminal window and <code class="docutils literal notranslate"><span class="pre">tcplisten</span> <span class="pre"><same</span> <span class="pre">args></span></code> in another.</p>
|
| 773 |
+
<p>A common cause of failure is a user-written file with the same name as a
|
| 774 |
+
standard library module, such as <em>random.py</em> and <em>tkinter.py</em>. When such a
|
| 775 |
+
file is located in the same directory as a file that is about to be run,
|
| 776 |
+
IDLE cannot import the stdlib file. The current fix is to rename the
|
| 777 |
+
user file.</p>
|
| 778 |
+
<p>Though less common than in the past, an antivirus or firewall program may
|
| 779 |
+
stop the connection. If the program cannot be taught to allow the
|
| 780 |
+
connection, then it must be turned off for IDLE to work. It is safe to
|
| 781 |
+
allow this internal connection because no data is visible on external
|
| 782 |
+
ports. A similar problem is a network mis-configuration that blocks
|
| 783 |
+
connections.</p>
|
| 784 |
+
<p>Python installation issues occasionally stop IDLE: multiple versions can
|
| 785 |
+
clash, or a single installation might need admin access. If one undo the
|
| 786 |
+
clash, or cannot or does not want to run as admin, it might be easiest to
|
| 787 |
+
completely remove Python and start over.</p>
|
| 788 |
+
<p>A zombie pythonw.exe process could be a problem. On Windows, use Task
|
| 789 |
+
Manager to check for one and stop it if there is. Sometimes a restart
|
| 790 |
+
initiated by a program crash or Keyboard Interrupt (control-C) may fail
|
| 791 |
+
to connect. Dismissing the error box or using Restart Shell on the Shell
|
| 792 |
+
menu may fix a temporary problem.</p>
|
| 793 |
+
<p>When IDLE first starts, it attempts to read user configuration files in
|
| 794 |
+
<code class="docutils literal notranslate"><span class="pre">~/.idlerc/</span></code> (~ is one’s home directory). If there is a problem, an error
|
| 795 |
+
message should be displayed. Leaving aside random disk glitches, this can
|
| 796 |
+
be prevented by never editing the files by hand. Instead, use the
|
| 797 |
+
configuration dialog, under Options. Once there is an error in a user
|
| 798 |
+
configuration file, the best solution may be to delete it and start over
|
| 799 |
+
with the settings dialog.</p>
|
| 800 |
+
<p>If IDLE quits with no message, and it was not started from a console, try
|
| 801 |
+
starting it from a console or terminal (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">idlelib</span></code>) and see if
|
| 802 |
+
this results in an error message.</p>
|
| 803 |
+
<p>On Unix-based systems with tcl/tk older than <code class="docutils literal notranslate"><span class="pre">8.6.11</span></code> (see
|
| 804 |
+
<code class="docutils literal notranslate"><span class="pre">About</span> <span class="pre">IDLE</span></code>) certain characters of certain fonts can cause
|
| 805 |
+
a tk failure with a message to the terminal. This can happen either
|
| 806 |
+
if one starts IDLE to edit a file with such a character or later
|
| 807 |
+
when entering such a character. If one cannot upgrade tcl/tk,
|
| 808 |
+
then re-configure IDLE to use a font that works better.</p>
|
| 809 |
+
</section>
|
| 810 |
+
<section id="running-user-code">
|
| 811 |
+
<h3>Running user code<a class="headerlink" href="#running-user-code" title="Permalink to this heading">¶</a></h3>
|
| 812 |
+
<p>With rare exceptions, the result of executing Python code with IDLE is
|
| 813 |
+
intended to be the same as executing the same code by the default method,
|
| 814 |
+
directly with Python in a text-mode system console or terminal window.
|
| 815 |
+
However, the different interface and operation occasionally affect
|
| 816 |
+
visible results. For instance, <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> starts with more entries,
|
| 817 |
+
and <code class="docutils literal notranslate"><span class="pre">threading.active_count()</span></code> returns 2 instead of 1.</p>
|
| 818 |
+
<p>By default, IDLE runs user code in a separate OS process rather than in
|
| 819 |
+
the user interface process that runs the shell and editor. In the execution
|
| 820 |
+
process, it replaces <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>
|
| 821 |
+
with objects that get input from and send output to the Shell window.
|
| 822 |
+
The original values stored in <code class="docutils literal notranslate"><span class="pre">sys.__stdin__</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.__stdout__</span></code>, and
|
| 823 |
+
<code class="docutils literal notranslate"><span class="pre">sys.__stderr__</span></code> are not touched, but may be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
|
| 824 |
+
<p>Sending print output from one process to a text widget in another is
|
| 825 |
+
slower than printing to a system terminal in the same process.
|
| 826 |
+
This has the most effect when printing multiple arguments, as the string
|
| 827 |
+
for each argument, each separator, the newline are sent separately.
|
| 828 |
+
For development, this is usually not a problem, but if one wants to
|
| 829 |
+
print faster in IDLE, format and join together everything one wants
|
| 830 |
+
displayed together and then print a single string. Both format strings
|
| 831 |
+
and <a class="reference internal" href="stdtypes.html#str.join" title="str.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.join()</span></code></a> can help combine fields and lines.</p>
|
| 832 |
+
<p>IDLE’s standard stream replacements are not inherited by subprocesses
|
| 833 |
+
created in the execution process, whether directly by user code or by
|
| 834 |
+
modules such as multiprocessing. If such subprocess use <code class="docutils literal notranslate"><span class="pre">input</span></code> from
|
| 835 |
+
sys.stdin or <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code> to sys.stdout or sys.stderr,
|
| 836 |
+
IDLE should be started in a command line window. (On Windows,
|
| 837 |
+
use <code class="docutils literal notranslate"><span class="pre">python</span></code> or <code class="docutils literal notranslate"><span class="pre">py</span></code> rather than <code class="docutils literal notranslate"><span class="pre">pythonw</span></code> or <code class="docutils literal notranslate"><span class="pre">pyw</span></code>.)
|
| 838 |
+
The secondary subprocess
|
| 839 |
+
will then be attached to that window for input and output.</p>
|
| 840 |
+
<p>If <code class="docutils literal notranslate"><span class="pre">sys</span></code> is reset by user code, such as with <code class="docutils literal notranslate"><span class="pre">importlib.reload(sys)</span></code>,
|
| 841 |
+
IDLE’s changes are lost and input from the keyboard and output to the screen
|
| 842 |
+
will not work correctly.</p>
|
| 843 |
+
<p>When Shell has the focus, it controls the keyboard and screen. This is
|
| 844 |
+
normally transparent, but functions that directly access the keyboard
|
| 845 |
+
and screen will not work. These include system-specific functions that
|
| 846 |
+
determine whether a key has been pressed and if so, which.</p>
|
| 847 |
+
<p>The IDLE code running in the execution process adds frames to the call stack
|
| 848 |
+
that would not be there otherwise. IDLE wraps <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit</span></code> and
|
| 849 |
+
<code class="docutils literal notranslate"><span class="pre">sys.setrecursionlimit</span></code> to reduce the effect of the additional stack
|
| 850 |
+
frames.</p>
|
| 851 |
+
<p>When user code raises SystemExit either directly or by calling sys.exit,
|
| 852 |
+
IDLE returns to a Shell prompt instead of exiting.</p>
|
| 853 |
+
</section>
|
| 854 |
+
<section id="user-output-in-shell">
|
| 855 |
+
<h3>User output in Shell<a class="headerlink" href="#user-output-in-shell" title="Permalink to this heading">¶</a></h3>
|
| 856 |
+
<p>When a program outputs text, the result is determined by the
|
| 857 |
+
corresponding output device. When IDLE executes user code, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>
|
| 858 |
+
and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> are connected to the display area of IDLE’s Shell. Some of
|
| 859 |
+
its features are inherited from the underlying Tk Text widget. Others
|
| 860 |
+
are programmed additions. Where it matters, Shell is designed for development
|
| 861 |
+
rather than production runs.</p>
|
| 862 |
+
<p>For instance, Shell never throws away output. A program that sends unlimited
|
| 863 |
+
output to Shell will eventually fill memory, resulting in a memory error.
|
| 864 |
+
In contrast, some system text windows only keep the last n lines of output.
|
| 865 |
+
A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
|
| 866 |
+
with 300 the default.</p>
|
| 867 |
+
<p>A Tk Text widget, and hence IDLE’s Shell, displays characters (codepoints) in
|
| 868 |
+
the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
|
| 869 |
+
displayed with a proper glyph and which with a replacement box depends on the
|
| 870 |
+
operating system and installed fonts. Tab characters cause the following text
|
| 871 |
+
to begin after the next tab stop. (They occur every 8 ‘characters’). Newline
|
| 872 |
+
characters cause following text to appear on a new line. Other control
|
| 873 |
+
characters are ignored or displayed as a space, box, or something else,
|
| 874 |
+
depending on the operating system and font. (Moving the text cursor through
|
| 875 |
+
such output with arrow keys may exhibit some surprising spacing behavior.)</p>
|
| 876 |
+
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="s1">'a</span><span class="se">\t</span><span class="s1">b</span><span class="se">\a</span><span class="s1"><</span><span class="se">\x02</span><span class="s1">><</span><span class="se">\r</span><span class="s1">></span><span class="se">\b</span><span class="s1">c</span><span class="se">\n</span><span class="s1">d'</span> <span class="c1"># Enter 22 chars.</span>
|
| 877 |
+
<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
|
| 878 |
+
<span class="go">14</span>
|
| 879 |
+
<span class="gp">>>> </span><span class="n">s</span> <span class="c1"># Display repr(s)</span>
|
| 880 |
+
<span class="go">'a\tb\x07<\x02><\r>\x08c\nd'</span>
|
| 881 |
+
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> <span class="c1"># Display s as is.</span>
|
| 882 |
+
<span class="go"># Result varies by OS and font. Try it.</span>
|
| 883 |
+
</pre></div>
|
| 884 |
+
</div>
|
| 885 |
+
<p>The <code class="docutils literal notranslate"><span class="pre">repr</span></code> function is used for interactive echo of expression
|
| 886 |
+
values. It returns an altered version of the input string in which
|
| 887 |
+
control codes, some BMP codepoints, and all non-BMP codepoints are
|
| 888 |
+
replaced with escape codes. As demonstrated above, it allows one to
|
| 889 |
+
identify the characters in a string, regardless of how they are displayed.</p>
|
| 890 |
+
<p>Normal and error output are generally kept separate (on separate lines)
|
| 891 |
+
from code input and each other. They each get different highlight colors.</p>
|
| 892 |
+
<p>For SyntaxError tracebacks, the normal ‘^’ marking where the error was
|
| 893 |
+
detected is replaced by coloring the text with an error highlight.
|
| 894 |
+
When code run from a file causes other exceptions, one may right click
|
| 895 |
+
on a traceback line to jump to the corresponding line in an IDLE editor.
|
| 896 |
+
The file will be opened if necessary.</p>
|
| 897 |
+
<p>Shell has a special facility for squeezing output lines down to a
|
| 898 |
+
‘Squeezed text’ label. This is done automatically
|
| 899 |
+
for output over N lines (N = 50 by default).
|
| 900 |
+
N can be changed in the PyShell section of the General
|
| 901 |
+
page of the Settings dialog. Output with fewer lines can be squeezed by
|
| 902 |
+
right clicking on the output. This can be useful lines long enough to slow
|
| 903 |
+
down scrolling.</p>
|
| 904 |
+
<p>Squeezed output is expanded in place by double-clicking the label.
|
| 905 |
+
It can also be sent to the clipboard or a separate view window by
|
| 906 |
+
right-clicking the label.</p>
|
| 907 |
+
</section>
|
| 908 |
+
<section id="developing-tkinter-applications">
|
| 909 |
+
<h3>Developing tkinter applications<a class="headerlink" href="#developing-tkinter-applications" title="Permalink to this heading">¶</a></h3>
|
| 910 |
+
<p>IDLE is intentionally different from standard Python in order to
|
| 911 |
+
facilitate development of tkinter programs. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">tkinter</span> <span class="pre">as</span> <span class="pre">tk;</span>
|
| 912 |
+
<span class="pre">root</span> <span class="pre">=</span> <span class="pre">tk.Tk()</span></code> in standard Python and nothing appears. Enter the same
|
| 913 |
+
in IDLE and a tk window appears. In standard Python, one must also enter
|
| 914 |
+
<code class="docutils literal notranslate"><span class="pre">root.update()</span></code> to see the window. IDLE does the equivalent in the
|
| 915 |
+
background, about 20 times a second, which is about every 50 milliseconds.
|
| 916 |
+
Next enter <code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">=</span> <span class="pre">tk.Button(root,</span> <span class="pre">text='button');</span> <span class="pre">b.pack()</span></code>. Again,
|
| 917 |
+
nothing visibly changes in standard Python until one enters <code class="docutils literal notranslate"><span class="pre">root.update()</span></code>.</p>
|
| 918 |
+
<p>Most tkinter programs run <code class="docutils literal notranslate"><span class="pre">root.mainloop()</span></code>, which usually does not
|
| 919 |
+
return until the tk app is destroyed. If the program is run with
|
| 920 |
+
<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span></code> or from an IDLE editor, a <code class="docutils literal notranslate"><span class="pre">>>></span></code> shell prompt does not
|
| 921 |
+
appear until <code class="docutils literal notranslate"><span class="pre">mainloop()</span></code> returns, at which time there is nothing left
|
| 922 |
+
to interact with.</p>
|
| 923 |
+
<p>When running a tkinter program from an IDLE editor, one can comment out
|
| 924 |
+
the mainloop call. One then gets a shell prompt immediately and can
|
| 925 |
+
interact with the live application. One just has to remember to
|
| 926 |
+
re-enable the mainloop call when running in standard Python.</p>
|
| 927 |
+
</section>
|
| 928 |
+
<section id="running-without-a-subprocess">
|
| 929 |
+
<h3>Running without a subprocess<a class="headerlink" href="#running-without-a-subprocess" title="Permalink to this heading">¶</a></h3>
|
| 930 |
+
<p>By default, IDLE executes user code in a separate subprocess via a socket,
|
| 931 |
+
which uses the internal loopback interface. This connection is not
|
| 932 |
+
externally visible and no data is sent to or received from the internet.
|
| 933 |
+
If firewall software complains anyway, you can ignore it.</p>
|
| 934 |
+
<p>If the attempt to make the socket connection fails, Idle will notify you.
|
| 935 |
+
Such failures are sometimes transient, but if persistent, the problem
|
| 936 |
+
may be either a firewall blocking the connection or misconfiguration of
|
| 937 |
+
a particular system. Until the problem is fixed, one can run Idle with
|
| 938 |
+
the -n command line switch.</p>
|
| 939 |
+
<p>If IDLE is started with the -n command line switch it will run in a
|
| 940 |
+
single process and will not create the subprocess which runs the RPC
|
| 941 |
+
Python execution server. This can be useful if Python cannot create
|
| 942 |
+
the subprocess or the RPC socket interface on your platform. However,
|
| 943 |
+
in this mode user code is not isolated from IDLE itself. Also, the
|
| 944 |
+
environment is not restarted when Run/Run Module (F5) is selected. If
|
| 945 |
+
your code has been modified, you must reload() the affected modules and
|
| 946 |
+
re-import any specific items (e.g. from foo import baz) if the changes
|
| 947 |
+
are to take effect. For these reasons, it is preferable to run IDLE
|
| 948 |
+
with the default subprocess if at all possible.</p>
|
| 949 |
+
<div class="deprecated">
|
| 950 |
+
<p><span class="versionmodified deprecated">Deprecated since version 3.4.</span></p>
|
| 951 |
+
</div>
|
| 952 |
+
</section>
|
| 953 |
+
</section>
|
| 954 |
+
<section id="help-and-preferences">
|
| 955 |
+
<h2>Help and Preferences<a class="headerlink" href="#help-and-preferences" title="Permalink to this heading">¶</a></h2>
|
| 956 |
+
<section id="help-sources">
|
| 957 |
+
<span id="id6"></span><h3>Help sources<a class="headerlink" href="#help-sources" title="Permalink to this heading">¶</a></h3>
|
| 958 |
+
<p>Help menu entry “IDLE Help” displays a formatted html version of the
|
| 959 |
+
IDLE chapter of the Library Reference. The result, in a read-only
|
| 960 |
+
tkinter text window, is close to what one sees in a web browser.
|
| 961 |
+
Navigate through the text with a mousewheel,
|
| 962 |
+
the scrollbar, or up and down arrow keys held down.
|
| 963 |
+
Or click the TOC (Table of Contents) button and select a section
|
| 964 |
+
header in the opened box.</p>
|
| 965 |
+
<p>Help menu entry “Python Docs” opens the extensive sources of help,
|
| 966 |
+
including tutorials, available at <code class="docutils literal notranslate"><span class="pre">docs.python.org/x.y</span></code>, where ‘x.y’
|
| 967 |
+
is the currently running Python version. If your system
|
| 968 |
+
has an off-line copy of the docs (this may be an installation option),
|
| 969 |
+
that will be opened instead.</p>
|
| 970 |
+
<p>Selected URLs can be added or removed from the help menu at any time using the
|
| 971 |
+
General tab of the Configure IDLE dialog.</p>
|
| 972 |
+
</section>
|
| 973 |
+
<section id="setting-preferences">
|
| 974 |
+
<span id="preferences"></span><h3>Setting preferences<a class="headerlink" href="#setting-preferences" title="Permalink to this heading">¶</a></h3>
|
| 975 |
+
<p>The font preferences, highlighting, keys, and general preferences can be
|
| 976 |
+
changed via Configure IDLE on the Option menu.
|
| 977 |
+
Non-default user settings are saved in a <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code> directory in the user’s
|
| 978 |
+
home directory. Problems caused by bad user configuration files are solved
|
| 979 |
+
by editing or deleting one or more of the files in <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>.</p>
|
| 980 |
+
<p>On the Font tab, see the text sample for the effect of font face and size
|
| 981 |
+
on multiple characters in multiple languages. Edit the sample to add
|
| 982 |
+
other characters of personal interest. Use the sample to select
|
| 983 |
+
monospaced fonts. If particular characters have problems in Shell or an
|
| 984 |
+
editor, add them to the top of the sample and try changing first size
|
| 985 |
+
and then font.</p>
|
| 986 |
+
<p>On the Highlights and Keys tab, select a built-in or custom color theme
|
| 987 |
+
and key set. To use a newer built-in color theme or key set with older
|
| 988 |
+
IDLEs, save it as a new custom theme or key set and it well be accessible
|
| 989 |
+
to older IDLEs.</p>
|
| 990 |
+
</section>
|
| 991 |
+
<section id="idle-on-macos">
|
| 992 |
+
<h3>IDLE on macOS<a class="headerlink" href="#idle-on-macos" title="Permalink to this heading">¶</a></h3>
|
| 993 |
+
<p>Under System Preferences: Dock, one can set “Prefer tabs when opening
|
| 994 |
+
documents” to “Always”. This setting is not compatible with the tk/tkinter
|
| 995 |
+
GUI framework used by IDLE, and it breaks a few IDLE features.</p>
|
| 996 |
+
</section>
|
| 997 |
+
<section id="extensions">
|
| 998 |
+
<h3>Extensions<a class="headerlink" href="#extensions" title="Permalink to this heading">¶</a></h3>
|
| 999 |
+
<p>IDLE contains an extension facility. Preferences for extensions can be
|
| 1000 |
+
changed with the Extensions tab of the preferences dialog. See the
|
| 1001 |
+
beginning of config-extensions.def in the idlelib directory for further
|
| 1002 |
+
information. The only current default extension is zzdummy, an example
|
| 1003 |
+
also used for testing.</p>
|
| 1004 |
+
</section>
|
| 1005 |
+
</section>
|
| 1006 |
+
<section id="module-idlelib">
|
| 1007 |
+
<span id="idlelib"></span><h2>idlelib<a class="headerlink" href="#module-idlelib" title="Permalink to this heading">¶</a></h2>
|
| 1008 |
+
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib">Lib/idlelib</a></p>
|
| 1009 |
+
<hr class="docutils" />
|
| 1010 |
+
<p>The Lib/idlelib package implements the IDLE application. See the rest
|
| 1011 |
+
of this page for how to use IDLE.</p>
|
| 1012 |
+
<p>The files in idlelib are described in idlelib/README.txt. Access it
|
| 1013 |
+
either in idlelib or click Help => About IDLE on the IDLE menu. This
|
| 1014 |
+
file also maps IDLE menu items to the code that implements the item.
|
| 1015 |
+
Except for files listed under ‘Startup’, the idlelib code is ‘private’ in
|
| 1016 |
+
sense that feature changes can be backported (see <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0434/"><strong>PEP 434</strong></a>).</p>
|
| 1017 |
+
</section>
|
| 1018 |
+
</section>
|
| 1019 |
+
|
| 1020 |
+
|
| 1021 |
+
<div class="clearer"></div>
|
| 1022 |
+
</div>
|
| 1023 |
+
</div>
|
| 1024 |
+
</div>
|
| 1025 |
+
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
| 1026 |
+
<div class="sphinxsidebarwrapper">
|
| 1027 |
+
<div>
|
| 1028 |
+
<h3><a href="../contents.html">Table of Contents</a></h3>
|
| 1029 |
+
<ul>
|
| 1030 |
+
<li><a class="reference internal" href="#">IDLE</a><ul>
|
| 1031 |
+
<li><a class="reference internal" href="#menus">Menus</a><ul>
|
| 1032 |
+
<li><a class="reference internal" href="#file-menu-shell-and-editor">File menu (Shell and Editor)</a></li>
|
| 1033 |
+
<li><a class="reference internal" href="#edit-menu-shell-and-editor">Edit menu (Shell and Editor)</a></li>
|
| 1034 |
+
<li><a class="reference internal" href="#format-menu-editor-window-only">Format menu (Editor window only)</a></li>
|
| 1035 |
+
<li><a class="reference internal" href="#run-menu-editor-window-only">Run menu (Editor window only)</a></li>
|
| 1036 |
+
<li><a class="reference internal" href="#shell-menu-shell-window-only">Shell menu (Shell window only)</a></li>
|
| 1037 |
+
<li><a class="reference internal" href="#debug-menu-shell-window-only">Debug menu (Shell window only)</a></li>
|
| 1038 |
+
<li><a class="reference internal" href="#options-menu-shell-and-editor">Options menu (Shell and Editor)</a></li>
|
| 1039 |
+
<li><a class="reference internal" href="#window-menu-shell-and-editor">Window menu (Shell and Editor)</a></li>
|
| 1040 |
+
<li><a class="reference internal" href="#help-menu-shell-and-editor">Help menu (Shell and Editor)</a></li>
|
| 1041 |
+
<li><a class="reference internal" href="#context-menus">Context menus</a></li>
|
| 1042 |
+
</ul>
|
| 1043 |
+
</li>
|
| 1044 |
+
<li><a class="reference internal" href="#editing-and-navigation">Editing and Navigation</a><ul>
|
| 1045 |
+
<li><a class="reference internal" href="#editor-windows">Editor windows</a></li>
|
| 1046 |
+
<li><a class="reference internal" href="#key-bindings">Key bindings</a></li>
|
| 1047 |
+
<li><a class="reference internal" href="#automatic-indentation">Automatic indentation</a></li>
|
| 1048 |
+
<li><a class="reference internal" href="#search-and-replace">Search and Replace</a></li>
|
| 1049 |
+
<li><a class="reference internal" href="#completions">Completions</a></li>
|
| 1050 |
+
<li><a class="reference internal" href="#calltips">Calltips</a></li>
|
| 1051 |
+
<li><a class="reference internal" href="#code-context">Code Context</a></li>
|
| 1052 |
+
<li><a class="reference internal" href="#shell-window">Shell window</a></li>
|
| 1053 |
+
<li><a class="reference internal" href="#text-colors">Text colors</a></li>
|
| 1054 |
+
</ul>
|
| 1055 |
+
</li>
|
| 1056 |
+
<li><a class="reference internal" href="#startup-and-code-execution">Startup and Code Execution</a><ul>
|
| 1057 |
+
<li><a class="reference internal" href="#command-line-usage">Command line usage</a></li>
|
| 1058 |
+
<li><a class="reference internal" href="#startup-failure">Startup failure</a></li>
|
| 1059 |
+
<li><a class="reference internal" href="#running-user-code">Running user code</a></li>
|
| 1060 |
+
<li><a class="reference internal" href="#user-output-in-shell">User output in Shell</a></li>
|
| 1061 |
+
<li><a class="reference internal" href="#developing-tkinter-applications">Developing tkinter applications</a></li>
|
| 1062 |
+
<li><a class="reference internal" href="#running-without-a-subprocess">Running without a subprocess</a></li>
|
| 1063 |
+
</ul>
|
| 1064 |
+
</li>
|
| 1065 |
+
<li><a class="reference internal" href="#help-and-preferences">Help and Preferences</a><ul>
|
| 1066 |
+
<li><a class="reference internal" href="#help-sources">Help sources</a></li>
|
| 1067 |
+
<li><a class="reference internal" href="#setting-preferences">Setting preferences</a></li>
|
| 1068 |
+
<li><a class="reference internal" href="#idle-on-macos">IDLE on macOS</a></li>
|
| 1069 |
+
<li><a class="reference internal" href="#extensions">Extensions</a></li>
|
| 1070 |
+
</ul>
|
| 1071 |
+
</li>
|
| 1072 |
+
<li><a class="reference internal" href="#module-idlelib">idlelib</a></li>
|
| 1073 |
+
</ul>
|
| 1074 |
+
</li>
|
| 1075 |
+
</ul>
|
| 1076 |
+
|
| 1077 |
+
</div>
|
| 1078 |
+
<div>
|
| 1079 |
+
<h4>Previous topic</h4>
|
| 1080 |
+
<p class="topless"><a href="tkinter.tix.html"
|
| 1081 |
+
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code> — Extension widgets for Tk</a></p>
|
| 1082 |
+
</div>
|
| 1083 |
+
<div>
|
| 1084 |
+
<h4>Next topic</h4>
|
| 1085 |
+
<p class="topless"><a href="development.html"
|
| 1086 |
+
title="next chapter">Development Tools</a></p>
|
| 1087 |
+
</div>
|
| 1088 |
+
<div role="note" aria-label="source link">
|
| 1089 |
+
<h3>This Page</h3>
|
| 1090 |
+
<ul class="this-page-menu">
|
| 1091 |
+
<li><a href="../bugs.html">Report a Bug</a></li>
|
| 1092 |
+
<li>
|
| 1093 |
+
<a href="https://github.com/python/cpython/blob/main/Doc/library/idle.rst"
|
| 1094 |
+
rel="nofollow">Show Source
|
| 1095 |
+
</a>
|
| 1096 |
+
</li>
|
| 1097 |
+
</ul>
|
| 1098 |
+
</div>
|
| 1099 |
+
</div>
|
| 1100 |
+
<div id="sidebarbutton" title="Collapse sidebar">
|
| 1101 |
+
<span>«</span>
|
| 1102 |
+
</div>
|
| 1103 |
+
|
| 1104 |
+
</div>
|
| 1105 |
+
<div class="clearer"></div>
|
| 1106 |
+
</div>
|
| 1107 |
+
<div class="related" role="navigation" aria-label="related navigation">
|
| 1108 |
+
<h3>Navigation</h3>
|
| 1109 |
+
<ul>
|
| 1110 |
+
<li class="right" style="margin-right: 10px">
|
| 1111 |
+
<a href="../genindex.html" title="General Index"
|
| 1112 |
+
>index</a></li>
|
| 1113 |
+
<li class="right" >
|
| 1114 |
+
<a href="../py-modindex.html" title="Python Module Index"
|
| 1115 |
+
>modules</a> |</li>
|
| 1116 |
+
<li class="right" >
|
| 1117 |
+
<a href="development.html" title="Development Tools"
|
| 1118 |
+
>next</a> |</li>
|
| 1119 |
+
<li class="right" >
|
| 1120 |
+
<a href="tkinter.tix.html" title="tkinter.tix — Extension widgets for Tk"
|
| 1121 |
+
>previous</a> |</li>
|
| 1122 |
+
|
| 1123 |
+
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
| 1124 |
+
<li><a href="https://www.python.org/">Python</a> »</li>
|
| 1125 |
+
<li class="switchers">
|
| 1126 |
+
<div class="language_switcher_placeholder"></div>
|
| 1127 |
+
<div class="version_switcher_placeholder"></div>
|
| 1128 |
+
</li>
|
| 1129 |
+
<li>
|
| 1130 |
+
|
| 1131 |
+
</li>
|
| 1132 |
+
<li id="cpython-language-and-version">
|
| 1133 |
+
<a href="../index.html">3.12.0a0 Documentation</a> »
|
| 1134 |
+
</li>
|
| 1135 |
+
|
| 1136 |
+
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
| 1137 |
+
<li class="nav-item nav-item-2"><a href="tk.html" >Graphical User Interfaces with Tk</a> »</li>
|
| 1138 |
+
<li class="nav-item nav-item-this"><a href="">IDLE</a></li>
|
| 1139 |
+
<li class="right">
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
<div class="inline-search" role="search">
|
| 1143 |
+
<form class="inline-search" action="../search.html" method="get">
|
| 1144 |
+
<input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
|
| 1145 |
+
<input type="submit" value="Go" />
|
| 1146 |
+
<input type="hidden" name="check_keywords" value="yes" />
|
| 1147 |
+
<input type="hidden" name="area" value="default" />
|
| 1148 |
+
</form>
|
| 1149 |
+
</div>
|
| 1150 |
+
|
|
| 1151 |
+
</li>
|
| 1152 |
+
|
| 1153 |
+
</ul>
|
| 1154 |
+
</div>
|
| 1155 |
+
<div class="footer">
|
| 1156 |
+
© <a href="../copyright.html">Copyright</a> 2001-2022, Python Software Foundation.
|
| 1157 |
+
<br />
|
| 1158 |
+
This page is licensed under the Python Software Foundation License Version 2.
|
| 1159 |
+
<br />
|
| 1160 |
+
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
| 1161 |
+
<br />
|
| 1162 |
+
See <a href="/license.html">History and License</a> for more information.<br />
|
| 1163 |
+
<br />
|
| 1164 |
+
|
| 1165 |
+
The Python Software Foundation is a non-profit corporation.
|
| 1166 |
+
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
| 1167 |
+
<br />
|
| 1168 |
+
<br />
|
| 1169 |
+
|
| 1170 |
+
Last updated on Sep 03, 2022.
|
| 1171 |
+
<a href="/bugs.html">Found a bug</a>?
|
| 1172 |
+
<br />
|
| 1173 |
+
|
| 1174 |
+
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.0.2.
|
| 1175 |
+
</div>
|
| 1176 |
+
|
| 1177 |
+
</body>
|
| 1178 |
+
</html>
|
evalkit_cambrian/lib/python3.10/idlelib/help.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" help.py: Implement the Idle help menu.
|
| 2 |
+
Contents are subject to revision at any time, without notice.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
Help => About IDLE: display About Idle dialog
|
| 6 |
+
|
| 7 |
+
<to be moved here from help_about.py>
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Help => IDLE Help: Display help.html with proper formatting.
|
| 11 |
+
Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html
|
| 12 |
+
(help.copy_strip)=> Lib/idlelib/help.html
|
| 13 |
+
|
| 14 |
+
HelpParser - Parse help.html and render to tk Text.
|
| 15 |
+
|
| 16 |
+
HelpText - Display formatted help.html.
|
| 17 |
+
|
| 18 |
+
HelpFrame - Contain text, scrollbar, and table-of-contents.
|
| 19 |
+
(This will be needed for display in a future tabbed window.)
|
| 20 |
+
|
| 21 |
+
HelpWindow - Display HelpFrame in a standalone window.
|
| 22 |
+
|
| 23 |
+
copy_strip - Copy idle.html to help.html, rstripping each line.
|
| 24 |
+
|
| 25 |
+
show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
|
| 26 |
+
"""
|
| 27 |
+
from html.parser import HTMLParser
|
| 28 |
+
from os.path import abspath, dirname, isfile, join
|
| 29 |
+
from platform import python_version
|
| 30 |
+
|
| 31 |
+
from tkinter import Toplevel, Text, Menu
|
| 32 |
+
from tkinter.ttk import Frame, Menubutton, Scrollbar, Style
|
| 33 |
+
from tkinter import font as tkfont
|
| 34 |
+
|
| 35 |
+
from idlelib.config import idleConf
|
| 36 |
+
|
| 37 |
+
## About IDLE ##
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## IDLE Help ##
|
| 41 |
+
|
| 42 |
+
class HelpParser(HTMLParser):
|
| 43 |
+
"""Render help.html into a text widget.
|
| 44 |
+
|
| 45 |
+
The overridden handle_xyz methods handle a subset of html tags.
|
| 46 |
+
The supplied text should have the needed tag configurations.
|
| 47 |
+
The behavior for unsupported tags, such as table, is undefined.
|
| 48 |
+
If the tags generated by Sphinx change, this class, especially
|
| 49 |
+
the handle_starttag and handle_endtags methods, might have to also.
|
| 50 |
+
"""
|
| 51 |
+
def __init__(self, text):
|
| 52 |
+
HTMLParser.__init__(self, convert_charrefs=True)
|
| 53 |
+
self.text = text # Text widget we're rendering into.
|
| 54 |
+
self.tags = '' # Current block level text tags to apply.
|
| 55 |
+
self.chartags = '' # Current character level text tags.
|
| 56 |
+
self.show = False # Exclude html page navigation.
|
| 57 |
+
self.hdrlink = False # Exclude html header links.
|
| 58 |
+
self.level = 0 # Track indentation level.
|
| 59 |
+
self.pre = False # Displaying preformatted text?
|
| 60 |
+
self.hprefix = '' # Heading prefix (like '25.5'?) to remove.
|
| 61 |
+
self.nested_dl = False # In a nested <dl>?
|
| 62 |
+
self.simplelist = False # In a simple list (no double spacing)?
|
| 63 |
+
self.toc = [] # Pair headers with text indexes for toc.
|
| 64 |
+
self.header = '' # Text within header tags for toc.
|
| 65 |
+
self.prevtag = None # Previous tag info (opener?, tag).
|
| 66 |
+
|
| 67 |
+
def indent(self, amt=1):
|
| 68 |
+
"Change indent (+1, 0, -1) and tags."
|
| 69 |
+
self.level += amt
|
| 70 |
+
self.tags = '' if self.level == 0 else 'l'+str(self.level)
|
| 71 |
+
|
| 72 |
+
def handle_starttag(self, tag, attrs):
|
| 73 |
+
"Handle starttags in help.html."
|
| 74 |
+
class_ = ''
|
| 75 |
+
for a, v in attrs:
|
| 76 |
+
if a == 'class':
|
| 77 |
+
class_ = v
|
| 78 |
+
s = ''
|
| 79 |
+
if tag == 'section' and attrs == [('id', 'idle')]:
|
| 80 |
+
self.show = True # Start main content.
|
| 81 |
+
elif tag == 'div' and class_ == 'clearer':
|
| 82 |
+
self.show = False # End main content.
|
| 83 |
+
elif tag == 'p' and self.prevtag and not self.prevtag[0]:
|
| 84 |
+
# Begin a new block for <p> tags after a closed tag.
|
| 85 |
+
# Avoid extra lines, e.g. after <pre> tags.
|
| 86 |
+
lastline = self.text.get('end-1c linestart', 'end-1c')
|
| 87 |
+
s = '\n\n' if lastline and not lastline.isspace() else '\n'
|
| 88 |
+
elif tag == 'span' and class_ == 'pre':
|
| 89 |
+
self.chartags = 'pre'
|
| 90 |
+
elif tag == 'span' and class_ == 'versionmodified':
|
| 91 |
+
self.chartags = 'em'
|
| 92 |
+
elif tag == 'em':
|
| 93 |
+
self.chartags = 'em'
|
| 94 |
+
elif tag in ['ul', 'ol']:
|
| 95 |
+
if class_.find('simple') != -1:
|
| 96 |
+
s = '\n'
|
| 97 |
+
self.simplelist = True
|
| 98 |
+
else:
|
| 99 |
+
self.simplelist = False
|
| 100 |
+
self.indent()
|
| 101 |
+
elif tag == 'dl':
|
| 102 |
+
if self.level > 0:
|
| 103 |
+
self.nested_dl = True
|
| 104 |
+
elif tag == 'li':
|
| 105 |
+
s = '\n* ' if self.simplelist else '\n\n* '
|
| 106 |
+
elif tag == 'dt':
|
| 107 |
+
s = '\n\n' if not self.nested_dl else '\n' # Avoid extra line.
|
| 108 |
+
self.nested_dl = False
|
| 109 |
+
elif tag == 'dd':
|
| 110 |
+
self.indent()
|
| 111 |
+
s = '\n'
|
| 112 |
+
elif tag == 'pre':
|
| 113 |
+
self.pre = True
|
| 114 |
+
if self.show:
|
| 115 |
+
self.text.insert('end', '\n\n')
|
| 116 |
+
self.tags = 'preblock'
|
| 117 |
+
elif tag == 'a' and class_ == 'headerlink':
|
| 118 |
+
self.hdrlink = True
|
| 119 |
+
elif tag == 'h1':
|
| 120 |
+
self.tags = tag
|
| 121 |
+
elif tag in ['h2', 'h3']:
|
| 122 |
+
if self.show:
|
| 123 |
+
self.header = ''
|
| 124 |
+
self.text.insert('end', '\n\n')
|
| 125 |
+
self.tags = tag
|
| 126 |
+
if self.show:
|
| 127 |
+
self.text.insert('end', s, (self.tags, self.chartags))
|
| 128 |
+
self.prevtag = (True, tag)
|
| 129 |
+
|
| 130 |
+
def handle_endtag(self, tag):
|
| 131 |
+
"Handle endtags in help.html."
|
| 132 |
+
if tag in ['h1', 'h2', 'h3']:
|
| 133 |
+
assert self.level == 0
|
| 134 |
+
if self.show:
|
| 135 |
+
indent = (' ' if tag == 'h3' else
|
| 136 |
+
' ' if tag == 'h2' else
|
| 137 |
+
'')
|
| 138 |
+
self.toc.append((indent+self.header, self.text.index('insert')))
|
| 139 |
+
self.tags = ''
|
| 140 |
+
elif tag in ['span', 'em']:
|
| 141 |
+
self.chartags = ''
|
| 142 |
+
elif tag == 'a':
|
| 143 |
+
self.hdrlink = False
|
| 144 |
+
elif tag == 'pre':
|
| 145 |
+
self.pre = False
|
| 146 |
+
self.tags = ''
|
| 147 |
+
elif tag in ['ul', 'dd', 'ol']:
|
| 148 |
+
self.indent(-1)
|
| 149 |
+
self.prevtag = (False, tag)
|
| 150 |
+
|
| 151 |
+
def handle_data(self, data):
|
| 152 |
+
"Handle date segments in help.html."
|
| 153 |
+
if self.show and not self.hdrlink:
|
| 154 |
+
d = data if self.pre else data.replace('\n', ' ')
|
| 155 |
+
if self.tags == 'h1':
|
| 156 |
+
try:
|
| 157 |
+
self.hprefix = d[0:d.index(' ')]
|
| 158 |
+
except ValueError:
|
| 159 |
+
self.hprefix = ''
|
| 160 |
+
if self.tags in ['h1', 'h2', 'h3']:
|
| 161 |
+
if (self.hprefix != '' and
|
| 162 |
+
d[0:len(self.hprefix)] == self.hprefix):
|
| 163 |
+
d = d[len(self.hprefix):]
|
| 164 |
+
self.header += d.strip()
|
| 165 |
+
self.text.insert('end', d, (self.tags, self.chartags))
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class HelpText(Text):
|
| 169 |
+
"Display help.html."
|
| 170 |
+
def __init__(self, parent, filename):
|
| 171 |
+
"Configure tags and feed file to parser."
|
| 172 |
+
uwide = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 173 |
+
uhigh = idleConf.GetOption('main', 'EditorWindow', 'height', type='int')
|
| 174 |
+
uhigh = 3 * uhigh // 4 # Lines average 4/3 of editor line height.
|
| 175 |
+
Text.__init__(self, parent, wrap='word', highlightthickness=0,
|
| 176 |
+
padx=5, borderwidth=0, width=uwide, height=uhigh)
|
| 177 |
+
|
| 178 |
+
normalfont = self.findfont(['TkDefaultFont', 'arial', 'helvetica'])
|
| 179 |
+
fixedfont = self.findfont(['TkFixedFont', 'monaco', 'courier'])
|
| 180 |
+
self['font'] = (normalfont, 12)
|
| 181 |
+
self.tag_configure('em', font=(normalfont, 12, 'italic'))
|
| 182 |
+
self.tag_configure('h1', font=(normalfont, 20, 'bold'))
|
| 183 |
+
self.tag_configure('h2', font=(normalfont, 18, 'bold'))
|
| 184 |
+
self.tag_configure('h3', font=(normalfont, 15, 'bold'))
|
| 185 |
+
self.tag_configure('pre', font=(fixedfont, 12), background='#f6f6ff')
|
| 186 |
+
self.tag_configure('preblock', font=(fixedfont, 10), lmargin1=25,
|
| 187 |
+
borderwidth=1, relief='solid', background='#eeffcc')
|
| 188 |
+
self.tag_configure('l1', lmargin1=25, lmargin2=25)
|
| 189 |
+
self.tag_configure('l2', lmargin1=50, lmargin2=50)
|
| 190 |
+
self.tag_configure('l3', lmargin1=75, lmargin2=75)
|
| 191 |
+
self.tag_configure('l4', lmargin1=100, lmargin2=100)
|
| 192 |
+
|
| 193 |
+
self.parser = HelpParser(self)
|
| 194 |
+
with open(filename, encoding='utf-8') as f:
|
| 195 |
+
contents = f.read()
|
| 196 |
+
self.parser.feed(contents)
|
| 197 |
+
self['state'] = 'disabled'
|
| 198 |
+
|
| 199 |
+
def findfont(self, names):
|
| 200 |
+
"Return name of first font family derived from names."
|
| 201 |
+
for name in names:
|
| 202 |
+
if name.lower() in (x.lower() for x in tkfont.names(root=self)):
|
| 203 |
+
font = tkfont.Font(name=name, exists=True, root=self)
|
| 204 |
+
return font.actual()['family']
|
| 205 |
+
elif name.lower() in (x.lower()
|
| 206 |
+
for x in tkfont.families(root=self)):
|
| 207 |
+
return name
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
class HelpFrame(Frame):
|
| 211 |
+
"Display html text, scrollbar, and toc."
|
| 212 |
+
def __init__(self, parent, filename):
|
| 213 |
+
Frame.__init__(self, parent)
|
| 214 |
+
self.text = text = HelpText(self, filename)
|
| 215 |
+
self.style = Style(parent)
|
| 216 |
+
self['style'] = 'helpframe.TFrame'
|
| 217 |
+
self.style.configure('helpframe.TFrame', background=text['background'])
|
| 218 |
+
self.toc = toc = self.toc_menu(text)
|
| 219 |
+
self.scroll = scroll = Scrollbar(self, command=text.yview)
|
| 220 |
+
text['yscrollcommand'] = scroll.set
|
| 221 |
+
|
| 222 |
+
self.rowconfigure(0, weight=1)
|
| 223 |
+
self.columnconfigure(1, weight=1) # Only expand the text widget.
|
| 224 |
+
toc.grid(row=0, column=0, sticky='nw')
|
| 225 |
+
text.grid(row=0, column=1, sticky='nsew')
|
| 226 |
+
scroll.grid(row=0, column=2, sticky='ns')
|
| 227 |
+
|
| 228 |
+
def toc_menu(self, text):
|
| 229 |
+
"Create table of contents as drop-down menu."
|
| 230 |
+
toc = Menubutton(self, text='TOC')
|
| 231 |
+
drop = Menu(toc, tearoff=False)
|
| 232 |
+
for lbl, dex in text.parser.toc:
|
| 233 |
+
drop.add_command(label=lbl, command=lambda dex=dex:text.yview(dex))
|
| 234 |
+
toc['menu'] = drop
|
| 235 |
+
return toc
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
class HelpWindow(Toplevel):
|
| 239 |
+
"Display frame with rendered html."
|
| 240 |
+
def __init__(self, parent, filename, title):
|
| 241 |
+
Toplevel.__init__(self, parent)
|
| 242 |
+
self.wm_title(title)
|
| 243 |
+
self.protocol("WM_DELETE_WINDOW", self.destroy)
|
| 244 |
+
HelpFrame(self, filename).grid(column=0, row=0, sticky='nsew')
|
| 245 |
+
self.grid_columnconfigure(0, weight=1)
|
| 246 |
+
self.grid_rowconfigure(0, weight=1)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def copy_strip():
|
| 250 |
+
"""Copy idle.html to idlelib/help.html, stripping trailing whitespace.
|
| 251 |
+
|
| 252 |
+
Files with trailing whitespace cannot be pushed to the git cpython
|
| 253 |
+
repository. For 3.x (on Windows), help.html is generated, after
|
| 254 |
+
editing idle.rst on the master branch, with
|
| 255 |
+
sphinx-build -bhtml . build/html
|
| 256 |
+
python_d.exe -c "from idlelib.help import copy_strip; copy_strip()"
|
| 257 |
+
Check build/html/library/idle.html, the help.html diff, and the text
|
| 258 |
+
displayed by Help => IDLE Help. Add a blurb and create a PR.
|
| 259 |
+
|
| 260 |
+
It can be worthwhile to occasionally generate help.html without
|
| 261 |
+
touching idle.rst. Changes to the master version and to the doc
|
| 262 |
+
build system may result in changes that should not changed
|
| 263 |
+
the displayed text, but might break HelpParser.
|
| 264 |
+
|
| 265 |
+
As long as master and maintenance versions of idle.rst remain the
|
| 266 |
+
same, help.html can be backported. The internal Python version
|
| 267 |
+
number is not displayed. If maintenance idle.rst diverges from
|
| 268 |
+
the master version, then instead of backporting help.html from
|
| 269 |
+
master, repeat the procedure above to generate a maintenance
|
| 270 |
+
version.
|
| 271 |
+
"""
|
| 272 |
+
src = join(abspath(dirname(dirname(dirname(__file__)))),
|
| 273 |
+
'Doc', 'build', 'html', 'library', 'idle.html')
|
| 274 |
+
dst = join(abspath(dirname(__file__)), 'help.html')
|
| 275 |
+
with open(src, 'rb') as inn,\
|
| 276 |
+
open(dst, 'wb') as out:
|
| 277 |
+
for line in inn:
|
| 278 |
+
out.write(line.rstrip() + b'\n')
|
| 279 |
+
print(f'{src} copied to {dst}')
|
| 280 |
+
|
| 281 |
+
def show_idlehelp(parent):
|
| 282 |
+
"Create HelpWindow; called from Idle Help event handler."
|
| 283 |
+
filename = join(abspath(dirname(__file__)), 'help.html')
|
| 284 |
+
if not isfile(filename):
|
| 285 |
+
# Try copy_strip, present message.
|
| 286 |
+
return
|
| 287 |
+
HelpWindow(parent, filename, 'IDLE Help (%s)' % python_version())
|
| 288 |
+
|
| 289 |
+
if __name__ == '__main__':
|
| 290 |
+
from unittest import main
|
| 291 |
+
main('idlelib.idle_test.test_help', verbosity=2, exit=False)
|
| 292 |
+
|
| 293 |
+
from idlelib.idle_test.htest import run
|
| 294 |
+
run(show_idlehelp)
|
evalkit_cambrian/lib/python3.10/idlelib/help_about.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""About Dialog for IDLE
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import webbrowser
|
| 7 |
+
from platform import python_version, architecture
|
| 8 |
+
|
| 9 |
+
from tkinter import Toplevel, Frame, Label, Button, PhotoImage
|
| 10 |
+
from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E
|
| 11 |
+
|
| 12 |
+
from idlelib import textview
|
| 13 |
+
|
| 14 |
+
version = python_version()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def build_bits():
|
| 18 |
+
"Return bits for platform."
|
| 19 |
+
if sys.platform == 'darwin':
|
| 20 |
+
return '64' if sys.maxsize > 2**32 else '32'
|
| 21 |
+
else:
|
| 22 |
+
return architecture()[0][:2]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class AboutDialog(Toplevel):
|
| 26 |
+
"""Modal about dialog for idle
|
| 27 |
+
|
| 28 |
+
"""
|
| 29 |
+
def __init__(self, parent, title=None, *, _htest=False, _utest=False):
|
| 30 |
+
"""Create popup, do not return until tk widget destroyed.
|
| 31 |
+
|
| 32 |
+
parent - parent of this dialog
|
| 33 |
+
title - string which is title of popup dialog
|
| 34 |
+
_htest - bool, change box location when running htest
|
| 35 |
+
_utest - bool, don't wait_window when running unittest
|
| 36 |
+
"""
|
| 37 |
+
Toplevel.__init__(self, parent)
|
| 38 |
+
self.configure(borderwidth=5)
|
| 39 |
+
# place dialog below parent if running htest
|
| 40 |
+
self.geometry("+%d+%d" % (
|
| 41 |
+
parent.winfo_rootx()+30,
|
| 42 |
+
parent.winfo_rooty()+(30 if not _htest else 100)))
|
| 43 |
+
self.bg = "#bbbbbb"
|
| 44 |
+
self.fg = "#000000"
|
| 45 |
+
self.create_widgets()
|
| 46 |
+
self.resizable(height=False, width=False)
|
| 47 |
+
self.title(title or
|
| 48 |
+
f'About IDLE {version} ({build_bits()} bit)')
|
| 49 |
+
self.transient(parent)
|
| 50 |
+
self.grab_set()
|
| 51 |
+
self.protocol("WM_DELETE_WINDOW", self.ok)
|
| 52 |
+
self.parent = parent
|
| 53 |
+
self.button_ok.focus_set()
|
| 54 |
+
self.bind('<Return>', self.ok) # dismiss dialog
|
| 55 |
+
self.bind('<Escape>', self.ok) # dismiss dialog
|
| 56 |
+
self._current_textview = None
|
| 57 |
+
self._utest = _utest
|
| 58 |
+
|
| 59 |
+
if not _utest:
|
| 60 |
+
self.deiconify()
|
| 61 |
+
self.wait_window()
|
| 62 |
+
|
| 63 |
+
def create_widgets(self):
|
| 64 |
+
frame = Frame(self, borderwidth=2, relief=SUNKEN)
|
| 65 |
+
frame_buttons = Frame(self)
|
| 66 |
+
frame_buttons.pack(side=BOTTOM, fill=X)
|
| 67 |
+
frame.pack(side=TOP, expand=True, fill=BOTH)
|
| 68 |
+
self.button_ok = Button(frame_buttons, text='Close',
|
| 69 |
+
command=self.ok)
|
| 70 |
+
self.button_ok.pack(padx=5, pady=5)
|
| 71 |
+
|
| 72 |
+
frame_background = Frame(frame, bg=self.bg)
|
| 73 |
+
frame_background.pack(expand=True, fill=BOTH)
|
| 74 |
+
|
| 75 |
+
header = Label(frame_background, text='IDLE', fg=self.fg,
|
| 76 |
+
bg=self.bg, font=('courier', 24, 'bold'))
|
| 77 |
+
header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
|
| 78 |
+
|
| 79 |
+
tk_patchlevel = self.tk.call('info', 'patchlevel')
|
| 80 |
+
ext = '.png' if tk_patchlevel >= '8.6' else '.gif'
|
| 81 |
+
icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
| 82 |
+
'Icons', f'idle_48{ext}')
|
| 83 |
+
self.icon_image = PhotoImage(master=self._root(), file=icon)
|
| 84 |
+
logo = Label(frame_background, image=self.icon_image, bg=self.bg)
|
| 85 |
+
logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
|
| 86 |
+
|
| 87 |
+
byline_text = "Python's Integrated Development\nand Learning Environment" + 5*'\n'
|
| 88 |
+
byline = Label(frame_background, text=byline_text, justify=LEFT,
|
| 89 |
+
fg=self.fg, bg=self.bg)
|
| 90 |
+
byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
|
| 91 |
+
email = Label(frame_background, text='email: [email protected]',
|
| 92 |
+
justify=LEFT, fg=self.fg, bg=self.bg)
|
| 93 |
+
email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
|
| 94 |
+
docs_url = ("https://docs.python.org/%d.%d/library/idle.html" %
|
| 95 |
+
sys.version_info[:2])
|
| 96 |
+
docs = Label(frame_background, text=docs_url,
|
| 97 |
+
justify=LEFT, fg=self.fg, bg=self.bg)
|
| 98 |
+
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
|
| 99 |
+
docs.bind("<Button-1>", lambda event: webbrowser.open(docs['text']))
|
| 100 |
+
|
| 101 |
+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
| 102 |
+
height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
|
| 103 |
+
columnspan=3, padx=5, pady=5)
|
| 104 |
+
|
| 105 |
+
pyver = Label(frame_background,
|
| 106 |
+
text='Python version: ' + version,
|
| 107 |
+
fg=self.fg, bg=self.bg)
|
| 108 |
+
pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0)
|
| 109 |
+
tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel,
|
| 110 |
+
fg=self.fg, bg=self.bg)
|
| 111 |
+
tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0)
|
| 112 |
+
py_buttons = Frame(frame_background, bg=self.bg)
|
| 113 |
+
py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
|
| 114 |
+
self.py_license = Button(py_buttons, text='License', width=8,
|
| 115 |
+
highlightbackground=self.bg,
|
| 116 |
+
command=self.show_py_license)
|
| 117 |
+
self.py_license.pack(side=LEFT, padx=10, pady=10)
|
| 118 |
+
self.py_copyright = Button(py_buttons, text='Copyright', width=8,
|
| 119 |
+
highlightbackground=self.bg,
|
| 120 |
+
command=self.show_py_copyright)
|
| 121 |
+
self.py_copyright.pack(side=LEFT, padx=10, pady=10)
|
| 122 |
+
self.py_credits = Button(py_buttons, text='Credits', width=8,
|
| 123 |
+
highlightbackground=self.bg,
|
| 124 |
+
command=self.show_py_credits)
|
| 125 |
+
self.py_credits.pack(side=LEFT, padx=10, pady=10)
|
| 126 |
+
|
| 127 |
+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
| 128 |
+
height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
|
| 129 |
+
columnspan=3, padx=5, pady=5)
|
| 130 |
+
|
| 131 |
+
idlever = Label(frame_background,
|
| 132 |
+
text='IDLE version: ' + version,
|
| 133 |
+
fg=self.fg, bg=self.bg)
|
| 134 |
+
idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
|
| 135 |
+
idle_buttons = Frame(frame_background, bg=self.bg)
|
| 136 |
+
idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
|
| 137 |
+
self.readme = Button(idle_buttons, text='README', width=8,
|
| 138 |
+
highlightbackground=self.bg,
|
| 139 |
+
command=self.show_readme)
|
| 140 |
+
self.readme.pack(side=LEFT, padx=10, pady=10)
|
| 141 |
+
self.idle_news = Button(idle_buttons, text='NEWS', width=8,
|
| 142 |
+
highlightbackground=self.bg,
|
| 143 |
+
command=self.show_idle_news)
|
| 144 |
+
self.idle_news.pack(side=LEFT, padx=10, pady=10)
|
| 145 |
+
self.idle_credits = Button(idle_buttons, text='Credits', width=8,
|
| 146 |
+
highlightbackground=self.bg,
|
| 147 |
+
command=self.show_idle_credits)
|
| 148 |
+
self.idle_credits.pack(side=LEFT, padx=10, pady=10)
|
| 149 |
+
|
| 150 |
+
# License, copyright, and credits are of type _sitebuiltins._Printer
|
| 151 |
+
def show_py_license(self):
|
| 152 |
+
"Handle License button event."
|
| 153 |
+
self.display_printer_text('About - License', license)
|
| 154 |
+
|
| 155 |
+
def show_py_copyright(self):
|
| 156 |
+
"Handle Copyright button event."
|
| 157 |
+
self.display_printer_text('About - Copyright', copyright)
|
| 158 |
+
|
| 159 |
+
def show_py_credits(self):
|
| 160 |
+
"Handle Python Credits button event."
|
| 161 |
+
self.display_printer_text('About - Python Credits', credits)
|
| 162 |
+
|
| 163 |
+
# Encode CREDITS.txt to utf-8 for proper version of Loewis.
|
| 164 |
+
# Specify others as ascii until need utf-8, so catch errors.
|
| 165 |
+
def show_idle_credits(self):
|
| 166 |
+
"Handle Idle Credits button event."
|
| 167 |
+
self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
|
| 168 |
+
|
| 169 |
+
def show_readme(self):
|
| 170 |
+
"Handle Readme button event."
|
| 171 |
+
self.display_file_text('About - Readme', 'README.txt', 'ascii')
|
| 172 |
+
|
| 173 |
+
def show_idle_news(self):
|
| 174 |
+
"Handle News button event."
|
| 175 |
+
self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
|
| 176 |
+
|
| 177 |
+
def display_printer_text(self, title, printer):
|
| 178 |
+
"""Create textview for built-in constants.
|
| 179 |
+
|
| 180 |
+
Built-in constants have type _sitebuiltins._Printer. The
|
| 181 |
+
text is extracted from the built-in and then sent to a text
|
| 182 |
+
viewer with self as the parent and title as the title of
|
| 183 |
+
the popup.
|
| 184 |
+
"""
|
| 185 |
+
printer._Printer__setup()
|
| 186 |
+
text = '\n'.join(printer._Printer__lines)
|
| 187 |
+
self._current_textview = textview.view_text(
|
| 188 |
+
self, title, text, _utest=self._utest)
|
| 189 |
+
|
| 190 |
+
def display_file_text(self, title, filename, encoding=None):
|
| 191 |
+
"""Create textview for filename.
|
| 192 |
+
|
| 193 |
+
The filename needs to be in the current directory. The path
|
| 194 |
+
is sent to a text viewer with self as the parent, title as
|
| 195 |
+
the title of the popup, and the file encoding.
|
| 196 |
+
"""
|
| 197 |
+
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
|
| 198 |
+
self._current_textview = textview.view_file(
|
| 199 |
+
self, title, fn, encoding, _utest=self._utest)
|
| 200 |
+
|
| 201 |
+
def ok(self, event=None):
|
| 202 |
+
"Dismiss help_about dialog."
|
| 203 |
+
self.grab_release()
|
| 204 |
+
self.destroy()
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
if __name__ == '__main__':
|
| 208 |
+
from unittest import main
|
| 209 |
+
main('idlelib.idle_test.test_help_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 |
+
|
| 3 |
+
HyperParser uses PyParser. PyParser mostly gives information on the
|
| 4 |
+
proper indentation of code. HyperParser gives additional information on
|
| 5 |
+
the structure of code.
|
| 6 |
+
"""
|
| 7 |
+
from keyword import iskeyword
|
| 8 |
+
import string
|
| 9 |
+
|
| 10 |
+
from idlelib import pyparse
|
| 11 |
+
|
| 12 |
+
# all ASCII chars that may be in an identifier
|
| 13 |
+
_ASCII_ID_CHARS = frozenset(string.ascii_letters + string.digits + "_")
|
| 14 |
+
# all ASCII chars that may be the first char of an identifier
|
| 15 |
+
_ASCII_ID_FIRST_CHARS = frozenset(string.ascii_letters + "_")
|
| 16 |
+
|
| 17 |
+
# lookup table for whether 7-bit ASCII chars are valid in a Python identifier
|
| 18 |
+
_IS_ASCII_ID_CHAR = [(chr(x) in _ASCII_ID_CHARS) for x in range(128)]
|
| 19 |
+
# lookup table for whether 7-bit ASCII chars are valid as the first
|
| 20 |
+
# char in a Python identifier
|
| 21 |
+
_IS_ASCII_ID_FIRST_CHAR = \
|
| 22 |
+
[(chr(x) in _ASCII_ID_FIRST_CHARS) for x in range(128)]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class HyperParser:
|
| 26 |
+
def __init__(self, editwin, index):
|
| 27 |
+
"To initialize, analyze the surroundings of the given index."
|
| 28 |
+
|
| 29 |
+
self.editwin = editwin
|
| 30 |
+
self.text = text = editwin.text
|
| 31 |
+
|
| 32 |
+
parser = pyparse.Parser(editwin.indentwidth, editwin.tabwidth)
|
| 33 |
+
|
| 34 |
+
def index2line(index):
|
| 35 |
+
return int(float(index))
|
| 36 |
+
lno = index2line(text.index(index))
|
| 37 |
+
|
| 38 |
+
if not editwin.prompt_last_line:
|
| 39 |
+
for context in editwin.num_context_lines:
|
| 40 |
+
startat = max(lno - context, 1)
|
| 41 |
+
startatindex = repr(startat) + ".0"
|
| 42 |
+
stopatindex = "%d.end" % lno
|
| 43 |
+
# We add the newline because PyParse requires a newline
|
| 44 |
+
# at end. We add a space so that index won't be at end
|
| 45 |
+
# of line, so that its status will be the same as the
|
| 46 |
+
# char before it, if should.
|
| 47 |
+
parser.set_code(text.get(startatindex, stopatindex)+' \n')
|
| 48 |
+
bod = parser.find_good_parse_start(
|
| 49 |
+
editwin._build_char_in_string_func(startatindex))
|
| 50 |
+
if bod is not None or startat == 1:
|
| 51 |
+
break
|
| 52 |
+
parser.set_lo(bod or 0)
|
| 53 |
+
else:
|
| 54 |
+
r = text.tag_prevrange("console", index)
|
| 55 |
+
if r:
|
| 56 |
+
startatindex = r[1]
|
| 57 |
+
else:
|
| 58 |
+
startatindex = "1.0"
|
| 59 |
+
stopatindex = "%d.end" % lno
|
| 60 |
+
# We add the newline because PyParse requires it. We add a
|
| 61 |
+
# space so that index won't be at end of line, so that its
|
| 62 |
+
# status will be the same as the char before it, if should.
|
| 63 |
+
parser.set_code(text.get(startatindex, stopatindex)+' \n')
|
| 64 |
+
parser.set_lo(0)
|
| 65 |
+
|
| 66 |
+
# We want what the parser has, minus the last newline and space.
|
| 67 |
+
self.rawtext = parser.code[:-2]
|
| 68 |
+
# Parser.code apparently preserves the statement we are in, so
|
| 69 |
+
# that stopatindex can be used to synchronize the string with
|
| 70 |
+
# the text box indices.
|
| 71 |
+
self.stopatindex = stopatindex
|
| 72 |
+
self.bracketing = parser.get_last_stmt_bracketing()
|
| 73 |
+
# find which pairs of bracketing are openers. These always
|
| 74 |
+
# correspond to a character of rawtext.
|
| 75 |
+
self.isopener = [i>0 and self.bracketing[i][1] >
|
| 76 |
+
self.bracketing[i-1][1]
|
| 77 |
+
for i in range(len(self.bracketing))]
|
| 78 |
+
|
| 79 |
+
self.set_index(index)
|
| 80 |
+
|
| 81 |
+
def set_index(self, index):
|
| 82 |
+
"""Set the index to which the functions relate.
|
| 83 |
+
|
| 84 |
+
The index must be in the same statement.
|
| 85 |
+
"""
|
| 86 |
+
indexinrawtext = (len(self.rawtext) -
|
| 87 |
+
len(self.text.get(index, self.stopatindex)))
|
| 88 |
+
if indexinrawtext < 0:
|
| 89 |
+
raise ValueError("Index %s precedes the analyzed statement"
|
| 90 |
+
% index)
|
| 91 |
+
self.indexinrawtext = indexinrawtext
|
| 92 |
+
# find the rightmost bracket to which index belongs
|
| 93 |
+
self.indexbracket = 0
|
| 94 |
+
while (self.indexbracket < len(self.bracketing)-1 and
|
| 95 |
+
self.bracketing[self.indexbracket+1][0] < self.indexinrawtext):
|
| 96 |
+
self.indexbracket += 1
|
| 97 |
+
if (self.indexbracket < len(self.bracketing)-1 and
|
| 98 |
+
self.bracketing[self.indexbracket+1][0] == self.indexinrawtext and
|
| 99 |
+
not self.isopener[self.indexbracket+1]):
|
| 100 |
+
self.indexbracket += 1
|
| 101 |
+
|
| 102 |
+
def is_in_string(self):
|
| 103 |
+
"""Is the index given to the HyperParser in a string?"""
|
| 104 |
+
# The bracket to which we belong should be an opener.
|
| 105 |
+
# If it's an opener, it has to have a character.
|
| 106 |
+
return (self.isopener[self.indexbracket] and
|
| 107 |
+
self.rawtext[self.bracketing[self.indexbracket][0]]
|
| 108 |
+
in ('"', "'"))
|
| 109 |
+
|
| 110 |
+
def is_in_code(self):
|
| 111 |
+
"""Is the index given to the HyperParser in normal code?"""
|
| 112 |
+
return (not self.isopener[self.indexbracket] or
|
| 113 |
+
self.rawtext[self.bracketing[self.indexbracket][0]]
|
| 114 |
+
not in ('#', '"', "'"))
|
| 115 |
+
|
| 116 |
+
def get_surrounding_brackets(self, openers='([{', mustclose=False):
|
| 117 |
+
"""Return bracket indexes or None.
|
| 118 |
+
|
| 119 |
+
If the index given to the HyperParser is surrounded by a
|
| 120 |
+
bracket defined in openers (or at least has one before it),
|
| 121 |
+
return the indices of the opening bracket and the closing
|
| 122 |
+
bracket (or the end of line, whichever comes first).
|
| 123 |
+
|
| 124 |
+
If it is not surrounded by brackets, or the end of line comes
|
| 125 |
+
before the closing bracket and mustclose is True, returns None.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
bracketinglevel = self.bracketing[self.indexbracket][1]
|
| 129 |
+
before = self.indexbracket
|
| 130 |
+
while (not self.isopener[before] or
|
| 131 |
+
self.rawtext[self.bracketing[before][0]] not in openers or
|
| 132 |
+
self.bracketing[before][1] > bracketinglevel):
|
| 133 |
+
before -= 1
|
| 134 |
+
if before < 0:
|
| 135 |
+
return None
|
| 136 |
+
bracketinglevel = min(bracketinglevel, self.bracketing[before][1])
|
| 137 |
+
after = self.indexbracket + 1
|
| 138 |
+
while (after < len(self.bracketing) and
|
| 139 |
+
self.bracketing[after][1] >= bracketinglevel):
|
| 140 |
+
after += 1
|
| 141 |
+
|
| 142 |
+
beforeindex = self.text.index("%s-%dc" %
|
| 143 |
+
(self.stopatindex, len(self.rawtext)-self.bracketing[before][0]))
|
| 144 |
+
if (after >= len(self.bracketing) or
|
| 145 |
+
self.bracketing[after][0] > len(self.rawtext)):
|
| 146 |
+
if mustclose:
|
| 147 |
+
return None
|
| 148 |
+
afterindex = self.stopatindex
|
| 149 |
+
else:
|
| 150 |
+
# We are after a real char, so it is a ')' and we give the
|
| 151 |
+
# index before it.
|
| 152 |
+
afterindex = self.text.index(
|
| 153 |
+
"%s-%dc" % (self.stopatindex,
|
| 154 |
+
len(self.rawtext)-(self.bracketing[after][0]-1)))
|
| 155 |
+
|
| 156 |
+
return beforeindex, afterindex
|
| 157 |
+
|
| 158 |
+
# the set of built-in identifiers which are also keywords,
|
| 159 |
+
# i.e. keyword.iskeyword() returns True for them
|
| 160 |
+
_ID_KEYWORDS = frozenset({"True", "False", "None"})
|
| 161 |
+
|
| 162 |
+
@classmethod
|
| 163 |
+
def _eat_identifier(cls, str, limit, pos):
|
| 164 |
+
"""Given a string and pos, return the number of chars in the
|
| 165 |
+
identifier which ends at pos, or 0 if there is no such one.
|
| 166 |
+
|
| 167 |
+
This ignores non-identifier eywords are not identifiers.
|
| 168 |
+
"""
|
| 169 |
+
is_ascii_id_char = _IS_ASCII_ID_CHAR
|
| 170 |
+
|
| 171 |
+
# Start at the end (pos) and work backwards.
|
| 172 |
+
i = pos
|
| 173 |
+
|
| 174 |
+
# Go backwards as long as the characters are valid ASCII
|
| 175 |
+
# identifier characters. This is an optimization, since it
|
| 176 |
+
# is faster in the common case where most of the characters
|
| 177 |
+
# are ASCII.
|
| 178 |
+
while i > limit and (
|
| 179 |
+
ord(str[i - 1]) < 128 and
|
| 180 |
+
is_ascii_id_char[ord(str[i - 1])]
|
| 181 |
+
):
|
| 182 |
+
i -= 1
|
| 183 |
+
|
| 184 |
+
# If the above loop ended due to reaching a non-ASCII
|
| 185 |
+
# character, continue going backwards using the most generic
|
| 186 |
+
# test for whether a string contains only valid identifier
|
| 187 |
+
# characters.
|
| 188 |
+
if i > limit and ord(str[i - 1]) >= 128:
|
| 189 |
+
while i - 4 >= limit and ('a' + str[i - 4:pos]).isidentifier():
|
| 190 |
+
i -= 4
|
| 191 |
+
if i - 2 >= limit and ('a' + str[i - 2:pos]).isidentifier():
|
| 192 |
+
i -= 2
|
| 193 |
+
if i - 1 >= limit and ('a' + str[i - 1:pos]).isidentifier():
|
| 194 |
+
i -= 1
|
| 195 |
+
|
| 196 |
+
# The identifier candidate starts here. If it isn't a valid
|
| 197 |
+
# identifier, don't eat anything. At this point that is only
|
| 198 |
+
# possible if the first character isn't a valid first
|
| 199 |
+
# character for an identifier.
|
| 200 |
+
if not str[i:pos].isidentifier():
|
| 201 |
+
return 0
|
| 202 |
+
elif i < pos:
|
| 203 |
+
# All characters in str[i:pos] are valid ASCII identifier
|
| 204 |
+
# characters, so it is enough to check that the first is
|
| 205 |
+
# valid as the first character of an identifier.
|
| 206 |
+
if not _IS_ASCII_ID_FIRST_CHAR[ord(str[i])]:
|
| 207 |
+
return 0
|
| 208 |
+
|
| 209 |
+
# All keywords are valid identifiers, but should not be
|
| 210 |
+
# considered identifiers here, except for True, False and None.
|
| 211 |
+
if i < pos and (
|
| 212 |
+
iskeyword(str[i:pos]) and
|
| 213 |
+
str[i:pos] not in cls._ID_KEYWORDS
|
| 214 |
+
):
|
| 215 |
+
return 0
|
| 216 |
+
|
| 217 |
+
return pos - i
|
| 218 |
+
|
| 219 |
+
# This string includes all chars that may be in a white space
|
| 220 |
+
_whitespace_chars = " \t\n\\"
|
| 221 |
+
|
| 222 |
+
def get_expression(self):
|
| 223 |
+
"""Return a string with the Python expression which ends at the
|
| 224 |
+
given index, which is empty if there is no real one.
|
| 225 |
+
"""
|
| 226 |
+
if not self.is_in_code():
|
| 227 |
+
raise ValueError("get_expression should only be called "
|
| 228 |
+
"if index is inside a code.")
|
| 229 |
+
|
| 230 |
+
rawtext = self.rawtext
|
| 231 |
+
bracketing = self.bracketing
|
| 232 |
+
|
| 233 |
+
brck_index = self.indexbracket
|
| 234 |
+
brck_limit = bracketing[brck_index][0]
|
| 235 |
+
pos = self.indexinrawtext
|
| 236 |
+
|
| 237 |
+
last_identifier_pos = pos
|
| 238 |
+
postdot_phase = True
|
| 239 |
+
|
| 240 |
+
while True:
|
| 241 |
+
# Eat whitespaces, comments, and if postdot_phase is False - a dot
|
| 242 |
+
while True:
|
| 243 |
+
if pos>brck_limit and rawtext[pos-1] in self._whitespace_chars:
|
| 244 |
+
# Eat a whitespace
|
| 245 |
+
pos -= 1
|
| 246 |
+
elif (not postdot_phase and
|
| 247 |
+
pos > brck_limit and rawtext[pos-1] == '.'):
|
| 248 |
+
# Eat a dot
|
| 249 |
+
pos -= 1
|
| 250 |
+
postdot_phase = True
|
| 251 |
+
# The next line will fail if we are *inside* a comment,
|
| 252 |
+
# but we shouldn't be.
|
| 253 |
+
elif (pos == brck_limit and brck_index > 0 and
|
| 254 |
+
rawtext[bracketing[brck_index-1][0]] == '#'):
|
| 255 |
+
# Eat a comment
|
| 256 |
+
brck_index -= 2
|
| 257 |
+
brck_limit = bracketing[brck_index][0]
|
| 258 |
+
pos = bracketing[brck_index+1][0]
|
| 259 |
+
else:
|
| 260 |
+
# If we didn't eat anything, quit.
|
| 261 |
+
break
|
| 262 |
+
|
| 263 |
+
if not postdot_phase:
|
| 264 |
+
# We didn't find a dot, so the expression end at the
|
| 265 |
+
# last identifier pos.
|
| 266 |
+
break
|
| 267 |
+
|
| 268 |
+
ret = self._eat_identifier(rawtext, brck_limit, pos)
|
| 269 |
+
if ret:
|
| 270 |
+
# There is an identifier to eat
|
| 271 |
+
pos = pos - ret
|
| 272 |
+
last_identifier_pos = pos
|
| 273 |
+
# Now, to continue the search, we must find a dot.
|
| 274 |
+
postdot_phase = False
|
| 275 |
+
# (the loop continues now)
|
| 276 |
+
|
| 277 |
+
elif pos == brck_limit:
|
| 278 |
+
# We are at a bracketing limit. If it is a closing
|
| 279 |
+
# bracket, eat the bracket, otherwise, stop the search.
|
| 280 |
+
level = bracketing[brck_index][1]
|
| 281 |
+
while brck_index > 0 and bracketing[brck_index-1][1] > level:
|
| 282 |
+
brck_index -= 1
|
| 283 |
+
if bracketing[brck_index][0] == brck_limit:
|
| 284 |
+
# We were not at the end of a closing bracket
|
| 285 |
+
break
|
| 286 |
+
pos = bracketing[brck_index][0]
|
| 287 |
+
brck_index -= 1
|
| 288 |
+
brck_limit = bracketing[brck_index][0]
|
| 289 |
+
last_identifier_pos = pos
|
| 290 |
+
if rawtext[pos] in "([":
|
| 291 |
+
# [] and () may be used after an identifier, so we
|
| 292 |
+
# continue. postdot_phase is True, so we don't allow a dot.
|
| 293 |
+
pass
|
| 294 |
+
else:
|
| 295 |
+
# We can't continue after other types of brackets
|
| 296 |
+
if rawtext[pos] in "'\"":
|
| 297 |
+
# Scan a string prefix
|
| 298 |
+
while pos > 0 and rawtext[pos - 1] in "rRbBuU":
|
| 299 |
+
pos -= 1
|
| 300 |
+
last_identifier_pos = pos
|
| 301 |
+
break
|
| 302 |
+
|
| 303 |
+
else:
|
| 304 |
+
# We've found an operator or something.
|
| 305 |
+
break
|
| 306 |
+
|
| 307 |
+
return rawtext[last_identifier_pos:self.indexinrawtext]
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
if __name__ == '__main__':
|
| 311 |
+
from unittest import main
|
| 312 |
+
main('idlelib.idle_test.test_hyperparser', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/idle.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os.path
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Enable running IDLE with idlelib in a non-standard location.
|
| 6 |
+
# This was once used to run development versions of IDLE.
|
| 7 |
+
# Because PEP 434 declared idle.py a public interface,
|
| 8 |
+
# removal should require deprecation.
|
| 9 |
+
idlelib_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 10 |
+
if idlelib_dir not in sys.path:
|
| 11 |
+
sys.path.insert(0, idlelib_dir)
|
| 12 |
+
|
| 13 |
+
from idlelib.pyshell import main # This is subject to change
|
| 14 |
+
main()
|
evalkit_cambrian/lib/python3.10/idlelib/macosx.py
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A number of functions that enhance IDLE on macOS.
|
| 3 |
+
"""
|
| 4 |
+
from os.path import expanduser
|
| 5 |
+
import plistlib
|
| 6 |
+
from sys import platform # Used in _init_tk_type, changed by test.
|
| 7 |
+
|
| 8 |
+
import tkinter
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
## Define functions that query the Mac graphics type.
|
| 12 |
+
## _tk_type and its initializer are private to this section.
|
| 13 |
+
|
| 14 |
+
_tk_type = None
|
| 15 |
+
|
| 16 |
+
def _init_tk_type():
|
| 17 |
+
""" Initialize _tk_type for isXyzTk functions.
|
| 18 |
+
|
| 19 |
+
This function is only called once, when _tk_type is still None.
|
| 20 |
+
"""
|
| 21 |
+
global _tk_type
|
| 22 |
+
if platform == 'darwin':
|
| 23 |
+
|
| 24 |
+
# When running IDLE, GUI is present, test/* may not be.
|
| 25 |
+
# When running tests, test/* is present, GUI may not be.
|
| 26 |
+
# If not, guess most common. Does not matter for testing.
|
| 27 |
+
from idlelib.__init__ import testing
|
| 28 |
+
if testing:
|
| 29 |
+
from test.support import requires, ResourceDenied
|
| 30 |
+
try:
|
| 31 |
+
requires('gui')
|
| 32 |
+
except ResourceDenied:
|
| 33 |
+
_tk_type = "cocoa"
|
| 34 |
+
return
|
| 35 |
+
|
| 36 |
+
root = tkinter.Tk()
|
| 37 |
+
ws = root.tk.call('tk', 'windowingsystem')
|
| 38 |
+
if 'x11' in ws:
|
| 39 |
+
_tk_type = "xquartz"
|
| 40 |
+
elif 'aqua' not in ws:
|
| 41 |
+
_tk_type = "other"
|
| 42 |
+
elif 'AppKit' in root.tk.call('winfo', 'server', '.'):
|
| 43 |
+
_tk_type = "cocoa"
|
| 44 |
+
else:
|
| 45 |
+
_tk_type = "carbon"
|
| 46 |
+
root.destroy()
|
| 47 |
+
else:
|
| 48 |
+
_tk_type = "other"
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
def isAquaTk():
|
| 52 |
+
"""
|
| 53 |
+
Returns True if IDLE is using a native OS X Tk (Cocoa or Carbon).
|
| 54 |
+
"""
|
| 55 |
+
if not _tk_type:
|
| 56 |
+
_init_tk_type()
|
| 57 |
+
return _tk_type == "cocoa" or _tk_type == "carbon"
|
| 58 |
+
|
| 59 |
+
def isCarbonTk():
|
| 60 |
+
"""
|
| 61 |
+
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
|
| 62 |
+
newer Cocoa Aqua Tk).
|
| 63 |
+
"""
|
| 64 |
+
if not _tk_type:
|
| 65 |
+
_init_tk_type()
|
| 66 |
+
return _tk_type == "carbon"
|
| 67 |
+
|
| 68 |
+
def isCocoaTk():
|
| 69 |
+
"""
|
| 70 |
+
Returns True if IDLE is using a Cocoa Aqua Tk.
|
| 71 |
+
"""
|
| 72 |
+
if not _tk_type:
|
| 73 |
+
_init_tk_type()
|
| 74 |
+
return _tk_type == "cocoa"
|
| 75 |
+
|
| 76 |
+
def isXQuartz():
|
| 77 |
+
"""
|
| 78 |
+
Returns True if IDLE is using an OS X X11 Tk.
|
| 79 |
+
"""
|
| 80 |
+
if not _tk_type:
|
| 81 |
+
_init_tk_type()
|
| 82 |
+
return _tk_type == "xquartz"
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def tkVersionWarning(root):
|
| 86 |
+
"""
|
| 87 |
+
Returns a string warning message if the Tk version in use appears to
|
| 88 |
+
be one known to cause problems with IDLE.
|
| 89 |
+
1. Apple Cocoa-based Tk 8.5.7 shipped with Mac OS X 10.6 is unusable.
|
| 90 |
+
2. Apple Cocoa-based Tk 8.5.9 in OS X 10.7 and 10.8 is better but
|
| 91 |
+
can still crash unexpectedly.
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
if isCocoaTk():
|
| 95 |
+
patchlevel = root.tk.call('info', 'patchlevel')
|
| 96 |
+
if patchlevel not in ('8.5.7', '8.5.9'):
|
| 97 |
+
return False
|
| 98 |
+
return ("WARNING: The version of Tcl/Tk ({0}) in use may"
|
| 99 |
+
" be unstable.\n"
|
| 100 |
+
"Visit https://www.python.org/download/mac/tcltk/"
|
| 101 |
+
" for current information.".format(patchlevel))
|
| 102 |
+
else:
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def readSystemPreferences():
|
| 107 |
+
"""
|
| 108 |
+
Fetch the macOS system preferences.
|
| 109 |
+
"""
|
| 110 |
+
if platform != 'darwin':
|
| 111 |
+
return None
|
| 112 |
+
|
| 113 |
+
plist_path = expanduser('~/Library/Preferences/.GlobalPreferences.plist')
|
| 114 |
+
try:
|
| 115 |
+
with open(plist_path, 'rb') as plist_file:
|
| 116 |
+
return plistlib.load(plist_file)
|
| 117 |
+
except OSError:
|
| 118 |
+
return None
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def preferTabsPreferenceWarning():
|
| 122 |
+
"""
|
| 123 |
+
Warn if "Prefer tabs when opening documents" is set to "Always".
|
| 124 |
+
"""
|
| 125 |
+
if platform != 'darwin':
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
+
prefs = readSystemPreferences()
|
| 129 |
+
if prefs and prefs.get('AppleWindowTabbingMode') == 'always':
|
| 130 |
+
return (
|
| 131 |
+
'WARNING: The system preference "Prefer tabs when opening'
|
| 132 |
+
' documents" is set to "Always". This will cause various problems'
|
| 133 |
+
' with IDLE. For the best experience, change this setting when'
|
| 134 |
+
' running IDLE (via System Preferences -> Dock).'
|
| 135 |
+
)
|
| 136 |
+
return None
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
## Fix the menu and related functions.
|
| 140 |
+
|
| 141 |
+
def addOpenEventSupport(root, flist):
|
| 142 |
+
"""
|
| 143 |
+
This ensures that the application will respond to open AppleEvents, which
|
| 144 |
+
makes is feasible to use IDLE as the default application for python files.
|
| 145 |
+
"""
|
| 146 |
+
def doOpenFile(*args):
|
| 147 |
+
for fn in args:
|
| 148 |
+
flist.open(fn)
|
| 149 |
+
|
| 150 |
+
# The command below is a hook in aquatk that is called whenever the app
|
| 151 |
+
# receives a file open event. The callback can have multiple arguments,
|
| 152 |
+
# one for every file that should be opened.
|
| 153 |
+
root.createcommand("::tk::mac::OpenDocument", doOpenFile)
|
| 154 |
+
|
| 155 |
+
def hideTkConsole(root):
|
| 156 |
+
try:
|
| 157 |
+
root.tk.call('console', 'hide')
|
| 158 |
+
except tkinter.TclError:
|
| 159 |
+
# Some versions of the Tk framework don't have a console object
|
| 160 |
+
pass
|
| 161 |
+
|
| 162 |
+
def overrideRootMenu(root, flist):
|
| 163 |
+
"""
|
| 164 |
+
Replace the Tk root menu by something that is more appropriate for
|
| 165 |
+
IDLE with an Aqua Tk.
|
| 166 |
+
"""
|
| 167 |
+
# The menu that is attached to the Tk root (".") is also used by AquaTk for
|
| 168 |
+
# all windows that don't specify a menu of their own. The default menubar
|
| 169 |
+
# contains a number of menus, none of which are appropriate for IDLE. The
|
| 170 |
+
# Most annoying of those is an 'About Tck/Tk...' menu in the application
|
| 171 |
+
# menu.
|
| 172 |
+
#
|
| 173 |
+
# This function replaces the default menubar by a mostly empty one, it
|
| 174 |
+
# should only contain the correct application menu and the window menu.
|
| 175 |
+
#
|
| 176 |
+
# Due to a (mis-)feature of TkAqua the user will also see an empty Help
|
| 177 |
+
# menu.
|
| 178 |
+
from tkinter import Menu
|
| 179 |
+
from idlelib import mainmenu
|
| 180 |
+
from idlelib import window
|
| 181 |
+
|
| 182 |
+
closeItem = mainmenu.menudefs[0][1][-2]
|
| 183 |
+
|
| 184 |
+
# Remove the last 3 items of the file menu: a separator, close window and
|
| 185 |
+
# quit. Close window will be reinserted just above the save item, where
|
| 186 |
+
# it should be according to the HIG. Quit is in the application menu.
|
| 187 |
+
del mainmenu.menudefs[0][1][-3:]
|
| 188 |
+
mainmenu.menudefs[0][1].insert(6, closeItem)
|
| 189 |
+
|
| 190 |
+
# Remove the 'About' entry from the help menu, it is in the application
|
| 191 |
+
# menu
|
| 192 |
+
del mainmenu.menudefs[-1][1][0:2]
|
| 193 |
+
# Remove the 'Configure Idle' entry from the options menu, it is in the
|
| 194 |
+
# application menu as 'Preferences'
|
| 195 |
+
del mainmenu.menudefs[-3][1][0:2]
|
| 196 |
+
menubar = Menu(root)
|
| 197 |
+
root.configure(menu=menubar)
|
| 198 |
+
menudict = {}
|
| 199 |
+
|
| 200 |
+
menudict['window'] = menu = Menu(menubar, name='window', tearoff=0)
|
| 201 |
+
menubar.add_cascade(label='Window', menu=menu, underline=0)
|
| 202 |
+
|
| 203 |
+
def postwindowsmenu(menu=menu):
|
| 204 |
+
end = menu.index('end')
|
| 205 |
+
if end is None:
|
| 206 |
+
end = -1
|
| 207 |
+
|
| 208 |
+
if end > 0:
|
| 209 |
+
menu.delete(0, end)
|
| 210 |
+
window.add_windows_to_menu(menu)
|
| 211 |
+
window.register_callback(postwindowsmenu)
|
| 212 |
+
|
| 213 |
+
def about_dialog(event=None):
|
| 214 |
+
"Handle Help 'About IDLE' event."
|
| 215 |
+
# Synchronize with editor.EditorWindow.about_dialog.
|
| 216 |
+
from idlelib import help_about
|
| 217 |
+
help_about.AboutDialog(root)
|
| 218 |
+
|
| 219 |
+
def config_dialog(event=None):
|
| 220 |
+
"Handle Options 'Configure IDLE' event."
|
| 221 |
+
# Synchronize with editor.EditorWindow.config_dialog.
|
| 222 |
+
from idlelib import configdialog
|
| 223 |
+
|
| 224 |
+
# Ensure that the root object has an instance_dict attribute,
|
| 225 |
+
# mirrors code in EditorWindow (although that sets the attribute
|
| 226 |
+
# on an EditorWindow instance that is then passed as the first
|
| 227 |
+
# argument to ConfigDialog)
|
| 228 |
+
root.instance_dict = flist.inversedict
|
| 229 |
+
configdialog.ConfigDialog(root, 'Settings')
|
| 230 |
+
|
| 231 |
+
def help_dialog(event=None):
|
| 232 |
+
"Handle Help 'IDLE Help' event."
|
| 233 |
+
# Synchronize with editor.EditorWindow.help_dialog.
|
| 234 |
+
from idlelib import help
|
| 235 |
+
help.show_idlehelp(root)
|
| 236 |
+
|
| 237 |
+
root.bind('<<about-idle>>', about_dialog)
|
| 238 |
+
root.bind('<<open-config-dialog>>', config_dialog)
|
| 239 |
+
root.createcommand('::tk::mac::ShowPreferences', config_dialog)
|
| 240 |
+
if flist:
|
| 241 |
+
root.bind('<<close-all-windows>>', flist.close_all_callback)
|
| 242 |
+
|
| 243 |
+
# The binding above doesn't reliably work on all versions of Tk
|
| 244 |
+
# on macOS. Adding command definition below does seem to do the
|
| 245 |
+
# right thing for now.
|
| 246 |
+
root.createcommand('exit', flist.close_all_callback)
|
| 247 |
+
|
| 248 |
+
if isCarbonTk():
|
| 249 |
+
# for Carbon AquaTk, replace the default Tk apple menu
|
| 250 |
+
menudict['application'] = menu = Menu(menubar, name='apple',
|
| 251 |
+
tearoff=0)
|
| 252 |
+
menubar.add_cascade(label='IDLE', menu=menu)
|
| 253 |
+
mainmenu.menudefs.insert(0,
|
| 254 |
+
('application', [
|
| 255 |
+
('About IDLE', '<<about-idle>>'),
|
| 256 |
+
None,
|
| 257 |
+
]))
|
| 258 |
+
if isCocoaTk():
|
| 259 |
+
# replace default About dialog with About IDLE one
|
| 260 |
+
root.createcommand('tkAboutDialog', about_dialog)
|
| 261 |
+
# replace default "Help" item in Help menu
|
| 262 |
+
root.createcommand('::tk::mac::ShowHelp', help_dialog)
|
| 263 |
+
# remove redundant "IDLE Help" from menu
|
| 264 |
+
del mainmenu.menudefs[-1][1][0]
|
| 265 |
+
|
| 266 |
+
def fixb2context(root):
|
| 267 |
+
'''Removed bad AquaTk Button-2 (right) and Paste bindings.
|
| 268 |
+
|
| 269 |
+
They prevent context menu access and seem to be gone in AquaTk8.6.
|
| 270 |
+
See issue #24801.
|
| 271 |
+
'''
|
| 272 |
+
root.unbind_class('Text', '<B2>')
|
| 273 |
+
root.unbind_class('Text', '<B2-Motion>')
|
| 274 |
+
root.unbind_class('Text', '<<PasteSelection>>')
|
| 275 |
+
|
| 276 |
+
def setupApp(root, flist):
|
| 277 |
+
"""
|
| 278 |
+
Perform initial OS X customizations if needed.
|
| 279 |
+
Called from pyshell.main() after initial calls to Tk()
|
| 280 |
+
|
| 281 |
+
There are currently three major versions of Tk in use on OS X:
|
| 282 |
+
1. Aqua Cocoa Tk (native default since OS X 10.6)
|
| 283 |
+
2. Aqua Carbon Tk (original native, 32-bit only, deprecated)
|
| 284 |
+
3. X11 (supported by some third-party distributors, deprecated)
|
| 285 |
+
There are various differences among the three that affect IDLE
|
| 286 |
+
behavior, primarily with menus, mouse key events, and accelerators.
|
| 287 |
+
Some one-time customizations are performed here.
|
| 288 |
+
Others are dynamically tested throughout idlelib by calls to the
|
| 289 |
+
isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
|
| 290 |
+
are initialized here as well.
|
| 291 |
+
"""
|
| 292 |
+
if isAquaTk():
|
| 293 |
+
hideTkConsole(root)
|
| 294 |
+
overrideRootMenu(root, flist)
|
| 295 |
+
addOpenEventSupport(root, flist)
|
| 296 |
+
fixb2context(root)
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
if __name__ == '__main__':
|
| 300 |
+
from unittest import main
|
| 301 |
+
main('idlelib.idle_test.test_macosx', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/multicall.py
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MultiCall - a class which inherits its methods from a Tkinter widget (Text, for
|
| 3 |
+
example), but enables multiple calls of functions per virtual event - all
|
| 4 |
+
matching events will be called, not only the most specific one. This is done
|
| 5 |
+
by wrapping the event functions - event_add, event_delete and event_info.
|
| 6 |
+
MultiCall recognizes only a subset of legal event sequences. Sequences which
|
| 7 |
+
are not recognized are treated by the original Tk handling mechanism. A
|
| 8 |
+
more-specific event will be called before a less-specific event.
|
| 9 |
+
|
| 10 |
+
The recognized sequences are complete one-event sequences (no emacs-style
|
| 11 |
+
Ctrl-X Ctrl-C, no shortcuts like <3>), for all types of events.
|
| 12 |
+
Key/Button Press/Release events can have modifiers.
|
| 13 |
+
The recognized modifiers are Shift, Control, Option and Command for Mac, and
|
| 14 |
+
Control, Alt, Shift, Meta/M for other platforms.
|
| 15 |
+
|
| 16 |
+
For all events which were handled by MultiCall, a new member is added to the
|
| 17 |
+
event instance passed to the binded functions - mc_type. This is one of the
|
| 18 |
+
event type constants defined in this module (such as MC_KEYPRESS).
|
| 19 |
+
For Key/Button events (which are handled by MultiCall and may receive
|
| 20 |
+
modifiers), another member is added - mc_state. This member gives the state
|
| 21 |
+
of the recognized modifiers, as a combination of the modifier constants
|
| 22 |
+
also defined in this module (for example, MC_SHIFT).
|
| 23 |
+
Using these members is absolutely portable.
|
| 24 |
+
|
| 25 |
+
The order by which events are called is defined by these rules:
|
| 26 |
+
1. A more-specific event will be called before a less-specific event.
|
| 27 |
+
2. A recently-binded event will be called before a previously-binded event,
|
| 28 |
+
unless this conflicts with the first rule.
|
| 29 |
+
Each function will be called at most once for each event.
|
| 30 |
+
"""
|
| 31 |
+
import re
|
| 32 |
+
import sys
|
| 33 |
+
|
| 34 |
+
import tkinter
|
| 35 |
+
|
| 36 |
+
# the event type constants, which define the meaning of mc_type
|
| 37 |
+
MC_KEYPRESS=0; MC_KEYRELEASE=1; MC_BUTTONPRESS=2; MC_BUTTONRELEASE=3;
|
| 38 |
+
MC_ACTIVATE=4; MC_CIRCULATE=5; MC_COLORMAP=6; MC_CONFIGURE=7;
|
| 39 |
+
MC_DEACTIVATE=8; MC_DESTROY=9; MC_ENTER=10; MC_EXPOSE=11; MC_FOCUSIN=12;
|
| 40 |
+
MC_FOCUSOUT=13; MC_GRAVITY=14; MC_LEAVE=15; MC_MAP=16; MC_MOTION=17;
|
| 41 |
+
MC_MOUSEWHEEL=18; MC_PROPERTY=19; MC_REPARENT=20; MC_UNMAP=21; MC_VISIBILITY=22;
|
| 42 |
+
# the modifier state constants, which define the meaning of mc_state
|
| 43 |
+
MC_SHIFT = 1<<0; MC_CONTROL = 1<<2; MC_ALT = 1<<3; MC_META = 1<<5
|
| 44 |
+
MC_OPTION = 1<<6; MC_COMMAND = 1<<7
|
| 45 |
+
|
| 46 |
+
# define the list of modifiers, to be used in complex event types.
|
| 47 |
+
if sys.platform == "darwin":
|
| 48 |
+
_modifiers = (("Shift",), ("Control",), ("Option",), ("Command",))
|
| 49 |
+
_modifier_masks = (MC_SHIFT, MC_CONTROL, MC_OPTION, MC_COMMAND)
|
| 50 |
+
else:
|
| 51 |
+
_modifiers = (("Control",), ("Alt",), ("Shift",), ("Meta", "M"))
|
| 52 |
+
_modifier_masks = (MC_CONTROL, MC_ALT, MC_SHIFT, MC_META)
|
| 53 |
+
|
| 54 |
+
# a dictionary to map a modifier name into its number
|
| 55 |
+
_modifier_names = dict([(name, number)
|
| 56 |
+
for number in range(len(_modifiers))
|
| 57 |
+
for name in _modifiers[number]])
|
| 58 |
+
|
| 59 |
+
# In 3.4, if no shell window is ever open, the underlying Tk widget is
|
| 60 |
+
# destroyed before .__del__ methods here are called. The following
|
| 61 |
+
# is used to selectively ignore shutdown exceptions to avoid
|
| 62 |
+
# 'Exception ignored' messages. See http://bugs.python.org/issue20167
|
| 63 |
+
APPLICATION_GONE = "application has been destroyed"
|
| 64 |
+
|
| 65 |
+
# A binder is a class which binds functions to one type of event. It has two
|
| 66 |
+
# methods: bind and unbind, which get a function and a parsed sequence, as
|
| 67 |
+
# returned by _parse_sequence(). There are two types of binders:
|
| 68 |
+
# _SimpleBinder handles event types with no modifiers and no detail.
|
| 69 |
+
# No Python functions are called when no events are binded.
|
| 70 |
+
# _ComplexBinder handles event types with modifiers and a detail.
|
| 71 |
+
# A Python function is called each time an event is generated.
|
| 72 |
+
|
| 73 |
+
class _SimpleBinder:
|
| 74 |
+
def __init__(self, type, widget, widgetinst):
|
| 75 |
+
self.type = type
|
| 76 |
+
self.sequence = '<'+_types[type][0]+'>'
|
| 77 |
+
self.widget = widget
|
| 78 |
+
self.widgetinst = widgetinst
|
| 79 |
+
self.bindedfuncs = []
|
| 80 |
+
self.handlerid = None
|
| 81 |
+
|
| 82 |
+
def bind(self, triplet, func):
|
| 83 |
+
if not self.handlerid:
|
| 84 |
+
def handler(event, l = self.bindedfuncs, mc_type = self.type):
|
| 85 |
+
event.mc_type = mc_type
|
| 86 |
+
wascalled = {}
|
| 87 |
+
for i in range(len(l)-1, -1, -1):
|
| 88 |
+
func = l[i]
|
| 89 |
+
if func not in wascalled:
|
| 90 |
+
wascalled[func] = True
|
| 91 |
+
r = func(event)
|
| 92 |
+
if r:
|
| 93 |
+
return r
|
| 94 |
+
self.handlerid = self.widget.bind(self.widgetinst,
|
| 95 |
+
self.sequence, handler)
|
| 96 |
+
self.bindedfuncs.append(func)
|
| 97 |
+
|
| 98 |
+
def unbind(self, triplet, func):
|
| 99 |
+
self.bindedfuncs.remove(func)
|
| 100 |
+
if not self.bindedfuncs:
|
| 101 |
+
self.widget.unbind(self.widgetinst, self.sequence, self.handlerid)
|
| 102 |
+
self.handlerid = None
|
| 103 |
+
|
| 104 |
+
def __del__(self):
|
| 105 |
+
if self.handlerid:
|
| 106 |
+
try:
|
| 107 |
+
self.widget.unbind(self.widgetinst, self.sequence,
|
| 108 |
+
self.handlerid)
|
| 109 |
+
except tkinter.TclError as e:
|
| 110 |
+
if not APPLICATION_GONE in e.args[0]:
|
| 111 |
+
raise
|
| 112 |
+
|
| 113 |
+
# An int in range(1 << len(_modifiers)) represents a combination of modifiers
|
| 114 |
+
# (if the least significant bit is on, _modifiers[0] is on, and so on).
|
| 115 |
+
# _state_subsets gives for each combination of modifiers, or *state*,
|
| 116 |
+
# a list of the states which are a subset of it. This list is ordered by the
|
| 117 |
+
# number of modifiers is the state - the most specific state comes first.
|
| 118 |
+
_states = range(1 << len(_modifiers))
|
| 119 |
+
_state_names = [''.join(m[0]+'-'
|
| 120 |
+
for i, m in enumerate(_modifiers)
|
| 121 |
+
if (1 << i) & s)
|
| 122 |
+
for s in _states]
|
| 123 |
+
|
| 124 |
+
def expand_substates(states):
|
| 125 |
+
'''For each item of states return a list containing all combinations of
|
| 126 |
+
that item with individual bits reset, sorted by the number of set bits.
|
| 127 |
+
'''
|
| 128 |
+
def nbits(n):
|
| 129 |
+
"number of bits set in n base 2"
|
| 130 |
+
nb = 0
|
| 131 |
+
while n:
|
| 132 |
+
n, rem = divmod(n, 2)
|
| 133 |
+
nb += rem
|
| 134 |
+
return nb
|
| 135 |
+
statelist = []
|
| 136 |
+
for state in states:
|
| 137 |
+
substates = list(set(state & x for x in states))
|
| 138 |
+
substates.sort(key=nbits, reverse=True)
|
| 139 |
+
statelist.append(substates)
|
| 140 |
+
return statelist
|
| 141 |
+
|
| 142 |
+
_state_subsets = expand_substates(_states)
|
| 143 |
+
|
| 144 |
+
# _state_codes gives for each state, the portable code to be passed as mc_state
|
| 145 |
+
_state_codes = []
|
| 146 |
+
for s in _states:
|
| 147 |
+
r = 0
|
| 148 |
+
for i in range(len(_modifiers)):
|
| 149 |
+
if (1 << i) & s:
|
| 150 |
+
r |= _modifier_masks[i]
|
| 151 |
+
_state_codes.append(r)
|
| 152 |
+
|
| 153 |
+
class _ComplexBinder:
|
| 154 |
+
# This class binds many functions, and only unbinds them when it is deleted.
|
| 155 |
+
# self.handlerids is the list of seqs and ids of binded handler functions.
|
| 156 |
+
# The binded functions sit in a dictionary of lists of lists, which maps
|
| 157 |
+
# a detail (or None) and a state into a list of functions.
|
| 158 |
+
# When a new detail is discovered, handlers for all the possible states
|
| 159 |
+
# are binded.
|
| 160 |
+
|
| 161 |
+
def __create_handler(self, lists, mc_type, mc_state):
|
| 162 |
+
def handler(event, lists = lists,
|
| 163 |
+
mc_type = mc_type, mc_state = mc_state,
|
| 164 |
+
ishandlerrunning = self.ishandlerrunning,
|
| 165 |
+
doafterhandler = self.doafterhandler):
|
| 166 |
+
ishandlerrunning[:] = [True]
|
| 167 |
+
event.mc_type = mc_type
|
| 168 |
+
event.mc_state = mc_state
|
| 169 |
+
wascalled = {}
|
| 170 |
+
r = None
|
| 171 |
+
for l in lists:
|
| 172 |
+
for i in range(len(l)-1, -1, -1):
|
| 173 |
+
func = l[i]
|
| 174 |
+
if func not in wascalled:
|
| 175 |
+
wascalled[func] = True
|
| 176 |
+
r = l[i](event)
|
| 177 |
+
if r:
|
| 178 |
+
break
|
| 179 |
+
if r:
|
| 180 |
+
break
|
| 181 |
+
ishandlerrunning[:] = []
|
| 182 |
+
# Call all functions in doafterhandler and remove them from list
|
| 183 |
+
for f in doafterhandler:
|
| 184 |
+
f()
|
| 185 |
+
doafterhandler[:] = []
|
| 186 |
+
if r:
|
| 187 |
+
return r
|
| 188 |
+
return handler
|
| 189 |
+
|
| 190 |
+
def __init__(self, type, widget, widgetinst):
|
| 191 |
+
self.type = type
|
| 192 |
+
self.typename = _types[type][0]
|
| 193 |
+
self.widget = widget
|
| 194 |
+
self.widgetinst = widgetinst
|
| 195 |
+
self.bindedfuncs = {None: [[] for s in _states]}
|
| 196 |
+
self.handlerids = []
|
| 197 |
+
# we don't want to change the lists of functions while a handler is
|
| 198 |
+
# running - it will mess up the loop and anyway, we usually want the
|
| 199 |
+
# change to happen from the next event. So we have a list of functions
|
| 200 |
+
# for the handler to run after it finishes calling the binded functions.
|
| 201 |
+
# It calls them only once.
|
| 202 |
+
# ishandlerrunning is a list. An empty one means no, otherwise - yes.
|
| 203 |
+
# this is done so that it would be mutable.
|
| 204 |
+
self.ishandlerrunning = []
|
| 205 |
+
self.doafterhandler = []
|
| 206 |
+
for s in _states:
|
| 207 |
+
lists = [self.bindedfuncs[None][i] for i in _state_subsets[s]]
|
| 208 |
+
handler = self.__create_handler(lists, type, _state_codes[s])
|
| 209 |
+
seq = '<'+_state_names[s]+self.typename+'>'
|
| 210 |
+
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
|
| 211 |
+
seq, handler)))
|
| 212 |
+
|
| 213 |
+
def bind(self, triplet, func):
|
| 214 |
+
if triplet[2] not in self.bindedfuncs:
|
| 215 |
+
self.bindedfuncs[triplet[2]] = [[] for s in _states]
|
| 216 |
+
for s in _states:
|
| 217 |
+
lists = [ self.bindedfuncs[detail][i]
|
| 218 |
+
for detail in (triplet[2], None)
|
| 219 |
+
for i in _state_subsets[s] ]
|
| 220 |
+
handler = self.__create_handler(lists, self.type,
|
| 221 |
+
_state_codes[s])
|
| 222 |
+
seq = "<%s%s-%s>"% (_state_names[s], self.typename, triplet[2])
|
| 223 |
+
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
|
| 224 |
+
seq, handler)))
|
| 225 |
+
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].append(func)
|
| 226 |
+
if not self.ishandlerrunning:
|
| 227 |
+
doit()
|
| 228 |
+
else:
|
| 229 |
+
self.doafterhandler.append(doit)
|
| 230 |
+
|
| 231 |
+
def unbind(self, triplet, func):
|
| 232 |
+
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func)
|
| 233 |
+
if not self.ishandlerrunning:
|
| 234 |
+
doit()
|
| 235 |
+
else:
|
| 236 |
+
self.doafterhandler.append(doit)
|
| 237 |
+
|
| 238 |
+
def __del__(self):
|
| 239 |
+
for seq, id in self.handlerids:
|
| 240 |
+
try:
|
| 241 |
+
self.widget.unbind(self.widgetinst, seq, id)
|
| 242 |
+
except tkinter.TclError as e:
|
| 243 |
+
if not APPLICATION_GONE in e.args[0]:
|
| 244 |
+
raise
|
| 245 |
+
|
| 246 |
+
# define the list of event types to be handled by MultiEvent. the order is
|
| 247 |
+
# compatible with the definition of event type constants.
|
| 248 |
+
_types = (
|
| 249 |
+
("KeyPress", "Key"), ("KeyRelease",), ("ButtonPress", "Button"),
|
| 250 |
+
("ButtonRelease",), ("Activate",), ("Circulate",), ("Colormap",),
|
| 251 |
+
("Configure",), ("Deactivate",), ("Destroy",), ("Enter",), ("Expose",),
|
| 252 |
+
("FocusIn",), ("FocusOut",), ("Gravity",), ("Leave",), ("Map",),
|
| 253 |
+
("Motion",), ("MouseWheel",), ("Property",), ("Reparent",), ("Unmap",),
|
| 254 |
+
("Visibility",),
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
# which binder should be used for every event type?
|
| 258 |
+
_binder_classes = (_ComplexBinder,) * 4 + (_SimpleBinder,) * (len(_types)-4)
|
| 259 |
+
|
| 260 |
+
# A dictionary to map a type name into its number
|
| 261 |
+
_type_names = dict([(name, number)
|
| 262 |
+
for number in range(len(_types))
|
| 263 |
+
for name in _types[number]])
|
| 264 |
+
|
| 265 |
+
_keysym_re = re.compile(r"^\w+$")
|
| 266 |
+
_button_re = re.compile(r"^[1-5]$")
|
| 267 |
+
def _parse_sequence(sequence):
|
| 268 |
+
"""Get a string which should describe an event sequence. If it is
|
| 269 |
+
successfully parsed as one, return a tuple containing the state (as an int),
|
| 270 |
+
the event type (as an index of _types), and the detail - None if none, or a
|
| 271 |
+
string if there is one. If the parsing is unsuccessful, return None.
|
| 272 |
+
"""
|
| 273 |
+
if not sequence or sequence[0] != '<' or sequence[-1] != '>':
|
| 274 |
+
return None
|
| 275 |
+
words = sequence[1:-1].split('-')
|
| 276 |
+
modifiers = 0
|
| 277 |
+
while words and words[0] in _modifier_names:
|
| 278 |
+
modifiers |= 1 << _modifier_names[words[0]]
|
| 279 |
+
del words[0]
|
| 280 |
+
if words and words[0] in _type_names:
|
| 281 |
+
type = _type_names[words[0]]
|
| 282 |
+
del words[0]
|
| 283 |
+
else:
|
| 284 |
+
return None
|
| 285 |
+
if _binder_classes[type] is _SimpleBinder:
|
| 286 |
+
if modifiers or words:
|
| 287 |
+
return None
|
| 288 |
+
else:
|
| 289 |
+
detail = None
|
| 290 |
+
else:
|
| 291 |
+
# _ComplexBinder
|
| 292 |
+
if type in [_type_names[s] for s in ("KeyPress", "KeyRelease")]:
|
| 293 |
+
type_re = _keysym_re
|
| 294 |
+
else:
|
| 295 |
+
type_re = _button_re
|
| 296 |
+
|
| 297 |
+
if not words:
|
| 298 |
+
detail = None
|
| 299 |
+
elif len(words) == 1 and type_re.match(words[0]):
|
| 300 |
+
detail = words[0]
|
| 301 |
+
else:
|
| 302 |
+
return None
|
| 303 |
+
|
| 304 |
+
return modifiers, type, detail
|
| 305 |
+
|
| 306 |
+
def _triplet_to_sequence(triplet):
|
| 307 |
+
if triplet[2]:
|
| 308 |
+
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'-'+ \
|
| 309 |
+
triplet[2]+'>'
|
| 310 |
+
else:
|
| 311 |
+
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'>'
|
| 312 |
+
|
| 313 |
+
_multicall_dict = {}
|
| 314 |
+
def MultiCallCreator(widget):
|
| 315 |
+
"""Return a MultiCall class which inherits its methods from the
|
| 316 |
+
given widget class (for example, Tkinter.Text). This is used
|
| 317 |
+
instead of a templating mechanism.
|
| 318 |
+
"""
|
| 319 |
+
if widget in _multicall_dict:
|
| 320 |
+
return _multicall_dict[widget]
|
| 321 |
+
|
| 322 |
+
class MultiCall (widget):
|
| 323 |
+
assert issubclass(widget, tkinter.Misc)
|
| 324 |
+
|
| 325 |
+
def __init__(self, *args, **kwargs):
|
| 326 |
+
widget.__init__(self, *args, **kwargs)
|
| 327 |
+
# a dictionary which maps a virtual event to a tuple with:
|
| 328 |
+
# 0. the function binded
|
| 329 |
+
# 1. a list of triplets - the sequences it is binded to
|
| 330 |
+
self.__eventinfo = {}
|
| 331 |
+
self.__binders = [_binder_classes[i](i, widget, self)
|
| 332 |
+
for i in range(len(_types))]
|
| 333 |
+
|
| 334 |
+
def bind(self, sequence=None, func=None, add=None):
|
| 335 |
+
#print("bind(%s, %s, %s)" % (sequence, func, add),
|
| 336 |
+
# file=sys.__stderr__)
|
| 337 |
+
if type(sequence) is str and len(sequence) > 2 and \
|
| 338 |
+
sequence[:2] == "<<" and sequence[-2:] == ">>":
|
| 339 |
+
if sequence in self.__eventinfo:
|
| 340 |
+
ei = self.__eventinfo[sequence]
|
| 341 |
+
if ei[0] is not None:
|
| 342 |
+
for triplet in ei[1]:
|
| 343 |
+
self.__binders[triplet[1]].unbind(triplet, ei[0])
|
| 344 |
+
ei[0] = func
|
| 345 |
+
if ei[0] is not None:
|
| 346 |
+
for triplet in ei[1]:
|
| 347 |
+
self.__binders[triplet[1]].bind(triplet, func)
|
| 348 |
+
else:
|
| 349 |
+
self.__eventinfo[sequence] = [func, []]
|
| 350 |
+
return widget.bind(self, sequence, func, add)
|
| 351 |
+
|
| 352 |
+
def unbind(self, sequence, funcid=None):
|
| 353 |
+
if type(sequence) is str and len(sequence) > 2 and \
|
| 354 |
+
sequence[:2] == "<<" and sequence[-2:] == ">>" and \
|
| 355 |
+
sequence in self.__eventinfo:
|
| 356 |
+
func, triplets = self.__eventinfo[sequence]
|
| 357 |
+
if func is not None:
|
| 358 |
+
for triplet in triplets:
|
| 359 |
+
self.__binders[triplet[1]].unbind(triplet, func)
|
| 360 |
+
self.__eventinfo[sequence][0] = None
|
| 361 |
+
return widget.unbind(self, sequence, funcid)
|
| 362 |
+
|
| 363 |
+
def event_add(self, virtual, *sequences):
|
| 364 |
+
#print("event_add(%s, %s)" % (repr(virtual), repr(sequences)),
|
| 365 |
+
# file=sys.__stderr__)
|
| 366 |
+
if virtual not in self.__eventinfo:
|
| 367 |
+
self.__eventinfo[virtual] = [None, []]
|
| 368 |
+
|
| 369 |
+
func, triplets = self.__eventinfo[virtual]
|
| 370 |
+
for seq in sequences:
|
| 371 |
+
triplet = _parse_sequence(seq)
|
| 372 |
+
if triplet is None:
|
| 373 |
+
#print("Tkinter event_add(%s)" % seq, file=sys.__stderr__)
|
| 374 |
+
widget.event_add(self, virtual, seq)
|
| 375 |
+
else:
|
| 376 |
+
if func is not None:
|
| 377 |
+
self.__binders[triplet[1]].bind(triplet, func)
|
| 378 |
+
triplets.append(triplet)
|
| 379 |
+
|
| 380 |
+
def event_delete(self, virtual, *sequences):
|
| 381 |
+
if virtual not in self.__eventinfo:
|
| 382 |
+
return
|
| 383 |
+
func, triplets = self.__eventinfo[virtual]
|
| 384 |
+
for seq in sequences:
|
| 385 |
+
triplet = _parse_sequence(seq)
|
| 386 |
+
if triplet is None:
|
| 387 |
+
#print("Tkinter event_delete: %s" % seq, file=sys.__stderr__)
|
| 388 |
+
widget.event_delete(self, virtual, seq)
|
| 389 |
+
else:
|
| 390 |
+
if func is not None:
|
| 391 |
+
self.__binders[triplet[1]].unbind(triplet, func)
|
| 392 |
+
triplets.remove(triplet)
|
| 393 |
+
|
| 394 |
+
def event_info(self, virtual=None):
|
| 395 |
+
if virtual is None or virtual not in self.__eventinfo:
|
| 396 |
+
return widget.event_info(self, virtual)
|
| 397 |
+
else:
|
| 398 |
+
return tuple(map(_triplet_to_sequence,
|
| 399 |
+
self.__eventinfo[virtual][1])) + \
|
| 400 |
+
widget.event_info(self, virtual)
|
| 401 |
+
|
| 402 |
+
def __del__(self):
|
| 403 |
+
for virtual in self.__eventinfo:
|
| 404 |
+
func, triplets = self.__eventinfo[virtual]
|
| 405 |
+
if func:
|
| 406 |
+
for triplet in triplets:
|
| 407 |
+
try:
|
| 408 |
+
self.__binders[triplet[1]].unbind(triplet, func)
|
| 409 |
+
except tkinter.TclError as e:
|
| 410 |
+
if not APPLICATION_GONE in e.args[0]:
|
| 411 |
+
raise
|
| 412 |
+
|
| 413 |
+
_multicall_dict[widget] = MultiCall
|
| 414 |
+
return MultiCall
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def _multi_call(parent): # htest #
|
| 418 |
+
top = tkinter.Toplevel(parent)
|
| 419 |
+
top.title("Test MultiCall")
|
| 420 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 421 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 422 |
+
text = MultiCallCreator(tkinter.Text)(top)
|
| 423 |
+
text.pack()
|
| 424 |
+
def bindseq(seq, n=[0]):
|
| 425 |
+
def handler(event):
|
| 426 |
+
print(seq)
|
| 427 |
+
text.bind("<<handler%d>>"%n[0], handler)
|
| 428 |
+
text.event_add("<<handler%d>>"%n[0], seq)
|
| 429 |
+
n[0] += 1
|
| 430 |
+
bindseq("<Key>")
|
| 431 |
+
bindseq("<Control-Key>")
|
| 432 |
+
bindseq("<Alt-Key-a>")
|
| 433 |
+
bindseq("<Control-Key-a>")
|
| 434 |
+
bindseq("<Alt-Control-Key-a>")
|
| 435 |
+
bindseq("<Key-b>")
|
| 436 |
+
bindseq("<Control-Button-1>")
|
| 437 |
+
bindseq("<Button-2>")
|
| 438 |
+
bindseq("<Alt-Button-1>")
|
| 439 |
+
bindseq("<FocusOut>")
|
| 440 |
+
bindseq("<Enter>")
|
| 441 |
+
bindseq("<Leave>")
|
| 442 |
+
|
| 443 |
+
if __name__ == "__main__":
|
| 444 |
+
from unittest import main
|
| 445 |
+
main('idlelib.idle_test.test_mainmenu', verbosity=2, exit=False)
|
| 446 |
+
|
| 447 |
+
from idlelib.idle_test.htest import run
|
| 448 |
+
run(_multi_call)
|
evalkit_cambrian/lib/python3.10/idlelib/parenmatch.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ParenMatch -- for parenthesis matching.
|
| 2 |
+
|
| 3 |
+
When you hit a right paren, the cursor should move briefly to the left
|
| 4 |
+
paren. Paren here is used generically; the matching applies to
|
| 5 |
+
parentheses, square brackets, and curly braces.
|
| 6 |
+
"""
|
| 7 |
+
from idlelib.hyperparser import HyperParser
|
| 8 |
+
from idlelib.config import idleConf
|
| 9 |
+
|
| 10 |
+
_openers = {')':'(',']':'[','}':'{'}
|
| 11 |
+
CHECK_DELAY = 100 # milliseconds
|
| 12 |
+
|
| 13 |
+
class ParenMatch:
|
| 14 |
+
"""Highlight matching openers and closers, (), [], and {}.
|
| 15 |
+
|
| 16 |
+
There are three supported styles of paren matching. When a right
|
| 17 |
+
paren (opener) is typed:
|
| 18 |
+
|
| 19 |
+
opener -- highlight the matching left paren (closer);
|
| 20 |
+
parens -- highlight the left and right parens (opener and closer);
|
| 21 |
+
expression -- highlight the entire expression from opener to closer.
|
| 22 |
+
(For back compatibility, 'default' is a synonym for 'opener').
|
| 23 |
+
|
| 24 |
+
Flash-delay is the maximum milliseconds the highlighting remains.
|
| 25 |
+
Any cursor movement (key press or click) before that removes the
|
| 26 |
+
highlight. If flash-delay is 0, there is no maximum.
|
| 27 |
+
|
| 28 |
+
TODO:
|
| 29 |
+
- Augment bell() with mismatch warning in status window.
|
| 30 |
+
- Highlight when cursor is moved to the right of a closer.
|
| 31 |
+
This might be too expensive to check.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
RESTORE_VIRTUAL_EVENT_NAME = "<<parenmatch-check-restore>>"
|
| 35 |
+
# We want the restore event be called before the usual return and
|
| 36 |
+
# backspace events.
|
| 37 |
+
RESTORE_SEQUENCES = ("<KeyPress>", "<ButtonPress>",
|
| 38 |
+
"<Key-Return>", "<Key-BackSpace>")
|
| 39 |
+
|
| 40 |
+
def __init__(self, editwin):
|
| 41 |
+
self.editwin = editwin
|
| 42 |
+
self.text = editwin.text
|
| 43 |
+
# Bind the check-restore event to the function restore_event,
|
| 44 |
+
# so that we can then use activate_restore (which calls event_add)
|
| 45 |
+
# and deactivate_restore (which calls event_delete).
|
| 46 |
+
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
|
| 47 |
+
self.restore_event)
|
| 48 |
+
self.counter = 0
|
| 49 |
+
self.is_restore_active = 0
|
| 50 |
+
|
| 51 |
+
@classmethod
|
| 52 |
+
def reload(cls):
|
| 53 |
+
cls.STYLE = idleConf.GetOption(
|
| 54 |
+
'extensions','ParenMatch','style', default='opener')
|
| 55 |
+
cls.FLASH_DELAY = idleConf.GetOption(
|
| 56 |
+
'extensions','ParenMatch','flash-delay', type='int',default=500)
|
| 57 |
+
cls.BELL = idleConf.GetOption(
|
| 58 |
+
'extensions','ParenMatch','bell', type='bool', default=1)
|
| 59 |
+
cls.HILITE_CONFIG = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 60 |
+
'hilite')
|
| 61 |
+
|
| 62 |
+
def activate_restore(self):
|
| 63 |
+
"Activate mechanism to restore text from highlighting."
|
| 64 |
+
if not self.is_restore_active:
|
| 65 |
+
for seq in self.RESTORE_SEQUENCES:
|
| 66 |
+
self.text.event_add(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
|
| 67 |
+
self.is_restore_active = True
|
| 68 |
+
|
| 69 |
+
def deactivate_restore(self):
|
| 70 |
+
"Remove restore event bindings."
|
| 71 |
+
if self.is_restore_active:
|
| 72 |
+
for seq in self.RESTORE_SEQUENCES:
|
| 73 |
+
self.text.event_delete(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
|
| 74 |
+
self.is_restore_active = False
|
| 75 |
+
|
| 76 |
+
def flash_paren_event(self, event):
|
| 77 |
+
"Handle editor 'show surrounding parens' event (menu or shortcut)."
|
| 78 |
+
indices = (HyperParser(self.editwin, "insert")
|
| 79 |
+
.get_surrounding_brackets())
|
| 80 |
+
self.finish_paren_event(indices)
|
| 81 |
+
return "break"
|
| 82 |
+
|
| 83 |
+
def paren_closed_event(self, event):
|
| 84 |
+
"Handle user input of closer."
|
| 85 |
+
# If user bound non-closer to <<paren-closed>>, quit.
|
| 86 |
+
closer = self.text.get("insert-1c")
|
| 87 |
+
if closer not in _openers:
|
| 88 |
+
return
|
| 89 |
+
hp = HyperParser(self.editwin, "insert-1c")
|
| 90 |
+
if not hp.is_in_code():
|
| 91 |
+
return
|
| 92 |
+
indices = hp.get_surrounding_brackets(_openers[closer], True)
|
| 93 |
+
self.finish_paren_event(indices)
|
| 94 |
+
return # Allow calltips to see ')'
|
| 95 |
+
|
| 96 |
+
def finish_paren_event(self, indices):
|
| 97 |
+
if indices is None and self.BELL:
|
| 98 |
+
self.text.bell()
|
| 99 |
+
return
|
| 100 |
+
self.activate_restore()
|
| 101 |
+
# self.create_tag(indices)
|
| 102 |
+
self.tagfuncs.get(self.STYLE, self.create_tag_expression)(self, indices)
|
| 103 |
+
# self.set_timeout()
|
| 104 |
+
(self.set_timeout_last if self.FLASH_DELAY else
|
| 105 |
+
self.set_timeout_none)()
|
| 106 |
+
|
| 107 |
+
def restore_event(self, event=None):
|
| 108 |
+
"Remove effect of doing match."
|
| 109 |
+
self.text.tag_delete("paren")
|
| 110 |
+
self.deactivate_restore()
|
| 111 |
+
self.counter += 1 # disable the last timer, if there is one.
|
| 112 |
+
|
| 113 |
+
def handle_restore_timer(self, timer_count):
|
| 114 |
+
if timer_count == self.counter:
|
| 115 |
+
self.restore_event()
|
| 116 |
+
|
| 117 |
+
# any one of the create_tag_XXX methods can be used depending on
|
| 118 |
+
# the style
|
| 119 |
+
|
| 120 |
+
def create_tag_opener(self, indices):
|
| 121 |
+
"""Highlight the single paren that matches"""
|
| 122 |
+
self.text.tag_add("paren", indices[0])
|
| 123 |
+
self.text.tag_config("paren", self.HILITE_CONFIG)
|
| 124 |
+
|
| 125 |
+
def create_tag_parens(self, indices):
|
| 126 |
+
"""Highlight the left and right parens"""
|
| 127 |
+
if self.text.get(indices[1]) in (')', ']', '}'):
|
| 128 |
+
rightindex = indices[1]+"+1c"
|
| 129 |
+
else:
|
| 130 |
+
rightindex = indices[1]
|
| 131 |
+
self.text.tag_add("paren", indices[0], indices[0]+"+1c", rightindex+"-1c", rightindex)
|
| 132 |
+
self.text.tag_config("paren", self.HILITE_CONFIG)
|
| 133 |
+
|
| 134 |
+
def create_tag_expression(self, indices):
|
| 135 |
+
"""Highlight the entire expression"""
|
| 136 |
+
if self.text.get(indices[1]) in (')', ']', '}'):
|
| 137 |
+
rightindex = indices[1]+"+1c"
|
| 138 |
+
else:
|
| 139 |
+
rightindex = indices[1]
|
| 140 |
+
self.text.tag_add("paren", indices[0], rightindex)
|
| 141 |
+
self.text.tag_config("paren", self.HILITE_CONFIG)
|
| 142 |
+
|
| 143 |
+
tagfuncs = {
|
| 144 |
+
'opener': create_tag_opener,
|
| 145 |
+
'default': create_tag_opener,
|
| 146 |
+
'parens': create_tag_parens,
|
| 147 |
+
'expression': create_tag_expression,
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
# any one of the set_timeout_XXX methods can be used depending on
|
| 151 |
+
# the style
|
| 152 |
+
|
| 153 |
+
def set_timeout_none(self):
|
| 154 |
+
"""Highlight will remain until user input turns it off
|
| 155 |
+
or the insert has moved"""
|
| 156 |
+
# After CHECK_DELAY, call a function which disables the "paren" tag
|
| 157 |
+
# if the event is for the most recent timer and the insert has changed,
|
| 158 |
+
# or schedules another call for itself.
|
| 159 |
+
self.counter += 1
|
| 160 |
+
def callme(callme, self=self, c=self.counter,
|
| 161 |
+
index=self.text.index("insert")):
|
| 162 |
+
if index != self.text.index("insert"):
|
| 163 |
+
self.handle_restore_timer(c)
|
| 164 |
+
else:
|
| 165 |
+
self.editwin.text_frame.after(CHECK_DELAY, callme, callme)
|
| 166 |
+
self.editwin.text_frame.after(CHECK_DELAY, callme, callme)
|
| 167 |
+
|
| 168 |
+
def set_timeout_last(self):
|
| 169 |
+
"""The last highlight created will be removed after FLASH_DELAY millisecs"""
|
| 170 |
+
# associate a counter with an event; only disable the "paren"
|
| 171 |
+
# tag if the event is for the most recent timer.
|
| 172 |
+
self.counter += 1
|
| 173 |
+
self.editwin.text_frame.after(
|
| 174 |
+
self.FLASH_DELAY,
|
| 175 |
+
lambda self=self, c=self.counter: self.handle_restore_timer(c))
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
ParenMatch.reload()
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
from unittest import main
|
| 183 |
+
main('idlelib.idle_test.test_parenmatch', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/pathbrowser.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.machinery
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
from idlelib.browser import ModuleBrowser, ModuleBrowserTreeItem
|
| 6 |
+
from idlelib.tree import TreeItem
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class PathBrowser(ModuleBrowser):
|
| 10 |
+
|
| 11 |
+
def __init__(self, master, *, _htest=False, _utest=False):
|
| 12 |
+
"""
|
| 13 |
+
_htest - bool, change box location when running htest
|
| 14 |
+
"""
|
| 15 |
+
self.master = master
|
| 16 |
+
self._htest = _htest
|
| 17 |
+
self._utest = _utest
|
| 18 |
+
self.init()
|
| 19 |
+
|
| 20 |
+
def settitle(self):
|
| 21 |
+
"Set window titles."
|
| 22 |
+
self.top.wm_title("Path Browser")
|
| 23 |
+
self.top.wm_iconname("Path Browser")
|
| 24 |
+
|
| 25 |
+
def rootnode(self):
|
| 26 |
+
return PathBrowserTreeItem()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class PathBrowserTreeItem(TreeItem):
|
| 30 |
+
|
| 31 |
+
def GetText(self):
|
| 32 |
+
return "sys.path"
|
| 33 |
+
|
| 34 |
+
def GetSubList(self):
|
| 35 |
+
sublist = []
|
| 36 |
+
for dir in sys.path:
|
| 37 |
+
item = DirBrowserTreeItem(dir)
|
| 38 |
+
sublist.append(item)
|
| 39 |
+
return sublist
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class DirBrowserTreeItem(TreeItem):
|
| 43 |
+
|
| 44 |
+
def __init__(self, dir, packages=[]):
|
| 45 |
+
self.dir = dir
|
| 46 |
+
self.packages = packages
|
| 47 |
+
|
| 48 |
+
def GetText(self):
|
| 49 |
+
if not self.packages:
|
| 50 |
+
return self.dir
|
| 51 |
+
else:
|
| 52 |
+
return self.packages[-1] + ": package"
|
| 53 |
+
|
| 54 |
+
def GetSubList(self):
|
| 55 |
+
try:
|
| 56 |
+
names = os.listdir(self.dir or os.curdir)
|
| 57 |
+
except OSError:
|
| 58 |
+
return []
|
| 59 |
+
packages = []
|
| 60 |
+
for name in names:
|
| 61 |
+
file = os.path.join(self.dir, name)
|
| 62 |
+
if self.ispackagedir(file):
|
| 63 |
+
nn = os.path.normcase(name)
|
| 64 |
+
packages.append((nn, name, file))
|
| 65 |
+
packages.sort()
|
| 66 |
+
sublist = []
|
| 67 |
+
for nn, name, file in packages:
|
| 68 |
+
item = DirBrowserTreeItem(file, self.packages + [name])
|
| 69 |
+
sublist.append(item)
|
| 70 |
+
for nn, name in self.listmodules(names):
|
| 71 |
+
item = ModuleBrowserTreeItem(os.path.join(self.dir, name))
|
| 72 |
+
sublist.append(item)
|
| 73 |
+
return sublist
|
| 74 |
+
|
| 75 |
+
def ispackagedir(self, file):
|
| 76 |
+
" Return true for directories that are packages."
|
| 77 |
+
if not os.path.isdir(file):
|
| 78 |
+
return False
|
| 79 |
+
init = os.path.join(file, "__init__.py")
|
| 80 |
+
return os.path.exists(init)
|
| 81 |
+
|
| 82 |
+
def listmodules(self, allnames):
|
| 83 |
+
modules = {}
|
| 84 |
+
suffixes = importlib.machinery.EXTENSION_SUFFIXES[:]
|
| 85 |
+
suffixes += importlib.machinery.SOURCE_SUFFIXES
|
| 86 |
+
suffixes += importlib.machinery.BYTECODE_SUFFIXES
|
| 87 |
+
sorted = []
|
| 88 |
+
for suff in suffixes:
|
| 89 |
+
i = -len(suff)
|
| 90 |
+
for name in allnames[:]:
|
| 91 |
+
normed_name = os.path.normcase(name)
|
| 92 |
+
if normed_name[i:] == suff:
|
| 93 |
+
mod_name = name[:i]
|
| 94 |
+
if mod_name not in modules:
|
| 95 |
+
modules[mod_name] = None
|
| 96 |
+
sorted.append((normed_name, name))
|
| 97 |
+
allnames.remove(name)
|
| 98 |
+
sorted.sort()
|
| 99 |
+
return sorted
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _path_browser(parent): # htest #
|
| 103 |
+
PathBrowser(parent, _htest=True)
|
| 104 |
+
parent.mainloop()
|
| 105 |
+
|
| 106 |
+
if __name__ == "__main__":
|
| 107 |
+
from unittest import main
|
| 108 |
+
main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False)
|
| 109 |
+
|
| 110 |
+
from idlelib.idle_test.htest import run
|
| 111 |
+
run(_path_browser)
|
evalkit_cambrian/lib/python3.10/idlelib/percolator.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from idlelib.delegator import Delegator
|
| 2 |
+
from idlelib.redirector import WidgetRedirector
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class Percolator:
|
| 6 |
+
|
| 7 |
+
def __init__(self, text):
|
| 8 |
+
# XXX would be nice to inherit from Delegator
|
| 9 |
+
self.text = text
|
| 10 |
+
self.redir = WidgetRedirector(text)
|
| 11 |
+
self.top = self.bottom = Delegator(text)
|
| 12 |
+
self.bottom.insert = self.redir.register("insert", self.insert)
|
| 13 |
+
self.bottom.delete = self.redir.register("delete", self.delete)
|
| 14 |
+
self.filters = []
|
| 15 |
+
|
| 16 |
+
def close(self):
|
| 17 |
+
while self.top is not self.bottom:
|
| 18 |
+
self.removefilter(self.top)
|
| 19 |
+
self.top = None
|
| 20 |
+
self.bottom.setdelegate(None)
|
| 21 |
+
self.bottom = None
|
| 22 |
+
self.redir.close()
|
| 23 |
+
self.redir = None
|
| 24 |
+
self.text = None
|
| 25 |
+
|
| 26 |
+
def insert(self, index, chars, tags=None):
|
| 27 |
+
# Could go away if inheriting from Delegator
|
| 28 |
+
self.top.insert(index, chars, tags)
|
| 29 |
+
|
| 30 |
+
def delete(self, index1, index2=None):
|
| 31 |
+
# Could go away if inheriting from Delegator
|
| 32 |
+
self.top.delete(index1, index2)
|
| 33 |
+
|
| 34 |
+
def insertfilter(self, filter):
|
| 35 |
+
# Perhaps rename to pushfilter()?
|
| 36 |
+
assert isinstance(filter, Delegator)
|
| 37 |
+
assert filter.delegate is None
|
| 38 |
+
filter.setdelegate(self.top)
|
| 39 |
+
self.top = filter
|
| 40 |
+
|
| 41 |
+
def insertfilterafter(self, filter, after):
|
| 42 |
+
assert isinstance(filter, Delegator)
|
| 43 |
+
assert isinstance(after, Delegator)
|
| 44 |
+
assert filter.delegate is None
|
| 45 |
+
|
| 46 |
+
f = self.top
|
| 47 |
+
f.resetcache()
|
| 48 |
+
while f is not after:
|
| 49 |
+
assert f is not self.bottom
|
| 50 |
+
f = f.delegate
|
| 51 |
+
f.resetcache()
|
| 52 |
+
|
| 53 |
+
filter.setdelegate(f.delegate)
|
| 54 |
+
f.setdelegate(filter)
|
| 55 |
+
|
| 56 |
+
def removefilter(self, filter):
|
| 57 |
+
# XXX Perhaps should only support popfilter()?
|
| 58 |
+
assert isinstance(filter, Delegator)
|
| 59 |
+
assert filter.delegate is not None
|
| 60 |
+
f = self.top
|
| 61 |
+
if f is filter:
|
| 62 |
+
self.top = filter.delegate
|
| 63 |
+
filter.setdelegate(None)
|
| 64 |
+
else:
|
| 65 |
+
while f.delegate is not filter:
|
| 66 |
+
assert f is not self.bottom
|
| 67 |
+
f.resetcache()
|
| 68 |
+
f = f.delegate
|
| 69 |
+
f.setdelegate(filter.delegate)
|
| 70 |
+
filter.setdelegate(None)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _percolator(parent): # htest #
|
| 74 |
+
import tkinter as tk
|
| 75 |
+
|
| 76 |
+
class Tracer(Delegator):
|
| 77 |
+
def __init__(self, name):
|
| 78 |
+
self.name = name
|
| 79 |
+
Delegator.__init__(self, None)
|
| 80 |
+
|
| 81 |
+
def insert(self, *args):
|
| 82 |
+
print(self.name, ": insert", args)
|
| 83 |
+
self.delegate.insert(*args)
|
| 84 |
+
|
| 85 |
+
def delete(self, *args):
|
| 86 |
+
print(self.name, ": delete", args)
|
| 87 |
+
self.delegate.delete(*args)
|
| 88 |
+
|
| 89 |
+
box = tk.Toplevel(parent)
|
| 90 |
+
box.title("Test Percolator")
|
| 91 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 92 |
+
box.geometry("+%d+%d" % (x, y + 175))
|
| 93 |
+
text = tk.Text(box)
|
| 94 |
+
p = Percolator(text)
|
| 95 |
+
pin = p.insertfilter
|
| 96 |
+
pout = p.removefilter
|
| 97 |
+
t1 = Tracer("t1")
|
| 98 |
+
t2 = Tracer("t2")
|
| 99 |
+
|
| 100 |
+
def toggle1():
|
| 101 |
+
(pin if var1.get() else pout)(t1)
|
| 102 |
+
def toggle2():
|
| 103 |
+
(pin if var2.get() else pout)(t2)
|
| 104 |
+
|
| 105 |
+
text.pack()
|
| 106 |
+
var1 = tk.IntVar(parent)
|
| 107 |
+
cb1 = tk.Checkbutton(box, text="Tracer1", command=toggle1, variable=var1)
|
| 108 |
+
cb1.pack()
|
| 109 |
+
var2 = tk.IntVar(parent)
|
| 110 |
+
cb2 = tk.Checkbutton(box, text="Tracer2", command=toggle2, variable=var2)
|
| 111 |
+
cb2.pack()
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
from unittest import main
|
| 115 |
+
main('idlelib.idle_test.test_percolator', verbosity=2, exit=False)
|
| 116 |
+
|
| 117 |
+
from idlelib.idle_test.htest import run
|
| 118 |
+
run(_percolator)
|
evalkit_cambrian/lib/python3.10/idlelib/pyparse.py
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define partial Python code Parser used by editor and hyperparser.
|
| 2 |
+
|
| 3 |
+
Instances of ParseMap are used with str.translate.
|
| 4 |
+
|
| 5 |
+
The following bound search and match functions are defined:
|
| 6 |
+
_synchre - start of popular statement;
|
| 7 |
+
_junkre - whitespace or comment line;
|
| 8 |
+
_match_stringre: string, possibly without closer;
|
| 9 |
+
_itemre - line that may have bracket structure start;
|
| 10 |
+
_closere - line that must be followed by dedent.
|
| 11 |
+
_chew_ordinaryre - non-special characters.
|
| 12 |
+
"""
|
| 13 |
+
import re
|
| 14 |
+
|
| 15 |
+
# Reason last statement is continued (or C_NONE if it's not).
|
| 16 |
+
(C_NONE, C_BACKSLASH, C_STRING_FIRST_LINE,
|
| 17 |
+
C_STRING_NEXT_LINES, C_BRACKET) = range(5)
|
| 18 |
+
|
| 19 |
+
# Find what looks like the start of a popular statement.
|
| 20 |
+
|
| 21 |
+
_synchre = re.compile(r"""
|
| 22 |
+
^
|
| 23 |
+
[ \t]*
|
| 24 |
+
(?: while
|
| 25 |
+
| else
|
| 26 |
+
| def
|
| 27 |
+
| return
|
| 28 |
+
| assert
|
| 29 |
+
| break
|
| 30 |
+
| class
|
| 31 |
+
| continue
|
| 32 |
+
| elif
|
| 33 |
+
| try
|
| 34 |
+
| except
|
| 35 |
+
| raise
|
| 36 |
+
| import
|
| 37 |
+
| yield
|
| 38 |
+
)
|
| 39 |
+
\b
|
| 40 |
+
""", re.VERBOSE | re.MULTILINE).search
|
| 41 |
+
|
| 42 |
+
# Match blank line or non-indenting comment line.
|
| 43 |
+
|
| 44 |
+
_junkre = re.compile(r"""
|
| 45 |
+
[ \t]*
|
| 46 |
+
(?: \# \S .* )?
|
| 47 |
+
\n
|
| 48 |
+
""", re.VERBOSE).match
|
| 49 |
+
|
| 50 |
+
# Match any flavor of string; the terminating quote is optional
|
| 51 |
+
# so that we're robust in the face of incomplete program text.
|
| 52 |
+
|
| 53 |
+
_match_stringre = re.compile(r"""
|
| 54 |
+
\""" [^"\\]* (?:
|
| 55 |
+
(?: \\. | "(?!"") )
|
| 56 |
+
[^"\\]*
|
| 57 |
+
)*
|
| 58 |
+
(?: \""" )?
|
| 59 |
+
|
| 60 |
+
| " [^"\\\n]* (?: \\. [^"\\\n]* )* "?
|
| 61 |
+
|
| 62 |
+
| ''' [^'\\]* (?:
|
| 63 |
+
(?: \\. | '(?!'') )
|
| 64 |
+
[^'\\]*
|
| 65 |
+
)*
|
| 66 |
+
(?: ''' )?
|
| 67 |
+
|
| 68 |
+
| ' [^'\\\n]* (?: \\. [^'\\\n]* )* '?
|
| 69 |
+
""", re.VERBOSE | re.DOTALL).match
|
| 70 |
+
|
| 71 |
+
# Match a line that starts with something interesting;
|
| 72 |
+
# used to find the first item of a bracket structure.
|
| 73 |
+
|
| 74 |
+
_itemre = re.compile(r"""
|
| 75 |
+
[ \t]*
|
| 76 |
+
[^\s#\\] # if we match, m.end()-1 is the interesting char
|
| 77 |
+
""", re.VERBOSE).match
|
| 78 |
+
|
| 79 |
+
# Match start of statements that should be followed by a dedent.
|
| 80 |
+
|
| 81 |
+
_closere = re.compile(r"""
|
| 82 |
+
\s*
|
| 83 |
+
(?: return
|
| 84 |
+
| break
|
| 85 |
+
| continue
|
| 86 |
+
| raise
|
| 87 |
+
| pass
|
| 88 |
+
)
|
| 89 |
+
\b
|
| 90 |
+
""", re.VERBOSE).match
|
| 91 |
+
|
| 92 |
+
# Chew up non-special chars as quickly as possible. If match is
|
| 93 |
+
# successful, m.end() less 1 is the index of the last boring char
|
| 94 |
+
# matched. If match is unsuccessful, the string starts with an
|
| 95 |
+
# interesting char.
|
| 96 |
+
|
| 97 |
+
_chew_ordinaryre = re.compile(r"""
|
| 98 |
+
[^[\](){}#'"\\]+
|
| 99 |
+
""", re.VERBOSE).match
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class ParseMap(dict):
|
| 103 |
+
r"""Dict subclass that maps anything not in dict to 'x'.
|
| 104 |
+
|
| 105 |
+
This is designed to be used with str.translate in study1.
|
| 106 |
+
Anything not specifically mapped otherwise becomes 'x'.
|
| 107 |
+
Example: replace everything except whitespace with 'x'.
|
| 108 |
+
|
| 109 |
+
>>> keepwhite = ParseMap((ord(c), ord(c)) for c in ' \t\n\r')
|
| 110 |
+
>>> "a + b\tc\nd".translate(keepwhite)
|
| 111 |
+
'x x x\tx\nx'
|
| 112 |
+
"""
|
| 113 |
+
# Calling this triples access time; see bpo-32940
|
| 114 |
+
def __missing__(self, key):
|
| 115 |
+
return 120 # ord('x')
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Map all ascii to 120 to avoid __missing__ call, then replace some.
|
| 119 |
+
trans = ParseMap.fromkeys(range(128), 120)
|
| 120 |
+
trans.update((ord(c), ord('(')) for c in "({[") # open brackets => '(';
|
| 121 |
+
trans.update((ord(c), ord(')')) for c in ")}]") # close brackets => ')'.
|
| 122 |
+
trans.update((ord(c), ord(c)) for c in "\"'\\\n#") # Keep these.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class Parser:
|
| 126 |
+
|
| 127 |
+
def __init__(self, indentwidth, tabwidth):
|
| 128 |
+
self.indentwidth = indentwidth
|
| 129 |
+
self.tabwidth = tabwidth
|
| 130 |
+
|
| 131 |
+
def set_code(self, s):
|
| 132 |
+
assert len(s) == 0 or s[-1] == '\n'
|
| 133 |
+
self.code = s
|
| 134 |
+
self.study_level = 0
|
| 135 |
+
|
| 136 |
+
def find_good_parse_start(self, is_char_in_string):
|
| 137 |
+
"""
|
| 138 |
+
Return index of a good place to begin parsing, as close to the
|
| 139 |
+
end of the string as possible. This will be the start of some
|
| 140 |
+
popular stmt like "if" or "def". Return None if none found:
|
| 141 |
+
the caller should pass more prior context then, if possible, or
|
| 142 |
+
if not (the entire program text up until the point of interest
|
| 143 |
+
has already been tried) pass 0 to set_lo().
|
| 144 |
+
|
| 145 |
+
This will be reliable iff given a reliable is_char_in_string()
|
| 146 |
+
function, meaning that when it says "no", it's absolutely
|
| 147 |
+
guaranteed that the char is not in a string.
|
| 148 |
+
"""
|
| 149 |
+
code, pos = self.code, None
|
| 150 |
+
|
| 151 |
+
# Peek back from the end for a good place to start,
|
| 152 |
+
# but don't try too often; pos will be left None, or
|
| 153 |
+
# bumped to a legitimate synch point.
|
| 154 |
+
limit = len(code)
|
| 155 |
+
for tries in range(5):
|
| 156 |
+
i = code.rfind(":\n", 0, limit)
|
| 157 |
+
if i < 0:
|
| 158 |
+
break
|
| 159 |
+
i = code.rfind('\n', 0, i) + 1 # start of colon line (-1+1=0)
|
| 160 |
+
m = _synchre(code, i, limit)
|
| 161 |
+
if m and not is_char_in_string(m.start()):
|
| 162 |
+
pos = m.start()
|
| 163 |
+
break
|
| 164 |
+
limit = i
|
| 165 |
+
if pos is None:
|
| 166 |
+
# Nothing looks like a block-opener, or stuff does
|
| 167 |
+
# but is_char_in_string keeps returning true; most likely
|
| 168 |
+
# we're in or near a giant string, the colorizer hasn't
|
| 169 |
+
# caught up enough to be helpful, or there simply *aren't*
|
| 170 |
+
# any interesting stmts. In any of these cases we're
|
| 171 |
+
# going to have to parse the whole thing to be sure, so
|
| 172 |
+
# give it one last try from the start, but stop wasting
|
| 173 |
+
# time here regardless of the outcome.
|
| 174 |
+
m = _synchre(code)
|
| 175 |
+
if m and not is_char_in_string(m.start()):
|
| 176 |
+
pos = m.start()
|
| 177 |
+
return pos
|
| 178 |
+
|
| 179 |
+
# Peeking back worked; look forward until _synchre no longer
|
| 180 |
+
# matches.
|
| 181 |
+
i = pos + 1
|
| 182 |
+
while m := _synchre(code, i):
|
| 183 |
+
s, i = m.span()
|
| 184 |
+
if not is_char_in_string(s):
|
| 185 |
+
pos = s
|
| 186 |
+
return pos
|
| 187 |
+
|
| 188 |
+
def set_lo(self, lo):
|
| 189 |
+
""" Throw away the start of the string.
|
| 190 |
+
|
| 191 |
+
Intended to be called with the result of find_good_parse_start().
|
| 192 |
+
"""
|
| 193 |
+
assert lo == 0 or self.code[lo-1] == '\n'
|
| 194 |
+
if lo > 0:
|
| 195 |
+
self.code = self.code[lo:]
|
| 196 |
+
|
| 197 |
+
def _study1(self):
|
| 198 |
+
"""Find the line numbers of non-continuation lines.
|
| 199 |
+
|
| 200 |
+
As quickly as humanly possible <wink>, find the line numbers (0-
|
| 201 |
+
based) of the non-continuation lines.
|
| 202 |
+
Creates self.{goodlines, continuation}.
|
| 203 |
+
"""
|
| 204 |
+
if self.study_level >= 1:
|
| 205 |
+
return
|
| 206 |
+
self.study_level = 1
|
| 207 |
+
|
| 208 |
+
# Map all uninteresting characters to "x", all open brackets
|
| 209 |
+
# to "(", all close brackets to ")", then collapse runs of
|
| 210 |
+
# uninteresting characters. This can cut the number of chars
|
| 211 |
+
# by a factor of 10-40, and so greatly speed the following loop.
|
| 212 |
+
code = self.code
|
| 213 |
+
code = code.translate(trans)
|
| 214 |
+
code = code.replace('xxxxxxxx', 'x')
|
| 215 |
+
code = code.replace('xxxx', 'x')
|
| 216 |
+
code = code.replace('xx', 'x')
|
| 217 |
+
code = code.replace('xx', 'x')
|
| 218 |
+
code = code.replace('\nx', '\n')
|
| 219 |
+
# Replacing x\n with \n would be incorrect because
|
| 220 |
+
# x may be preceded by a backslash.
|
| 221 |
+
|
| 222 |
+
# March over the squashed version of the program, accumulating
|
| 223 |
+
# the line numbers of non-continued stmts, and determining
|
| 224 |
+
# whether & why the last stmt is a continuation.
|
| 225 |
+
continuation = C_NONE
|
| 226 |
+
level = lno = 0 # level is nesting level; lno is line number
|
| 227 |
+
self.goodlines = goodlines = [0]
|
| 228 |
+
push_good = goodlines.append
|
| 229 |
+
i, n = 0, len(code)
|
| 230 |
+
while i < n:
|
| 231 |
+
ch = code[i]
|
| 232 |
+
i = i+1
|
| 233 |
+
|
| 234 |
+
# cases are checked in decreasing order of frequency
|
| 235 |
+
if ch == 'x':
|
| 236 |
+
continue
|
| 237 |
+
|
| 238 |
+
if ch == '\n':
|
| 239 |
+
lno = lno + 1
|
| 240 |
+
if level == 0:
|
| 241 |
+
push_good(lno)
|
| 242 |
+
# else we're in an unclosed bracket structure
|
| 243 |
+
continue
|
| 244 |
+
|
| 245 |
+
if ch == '(':
|
| 246 |
+
level = level + 1
|
| 247 |
+
continue
|
| 248 |
+
|
| 249 |
+
if ch == ')':
|
| 250 |
+
if level:
|
| 251 |
+
level = level - 1
|
| 252 |
+
# else the program is invalid, but we can't complain
|
| 253 |
+
continue
|
| 254 |
+
|
| 255 |
+
if ch == '"' or ch == "'":
|
| 256 |
+
# consume the string
|
| 257 |
+
quote = ch
|
| 258 |
+
if code[i-1:i+2] == quote * 3:
|
| 259 |
+
quote = quote * 3
|
| 260 |
+
firstlno = lno
|
| 261 |
+
w = len(quote) - 1
|
| 262 |
+
i = i+w
|
| 263 |
+
while i < n:
|
| 264 |
+
ch = code[i]
|
| 265 |
+
i = i+1
|
| 266 |
+
|
| 267 |
+
if ch == 'x':
|
| 268 |
+
continue
|
| 269 |
+
|
| 270 |
+
if code[i-1:i+w] == quote:
|
| 271 |
+
i = i+w
|
| 272 |
+
break
|
| 273 |
+
|
| 274 |
+
if ch == '\n':
|
| 275 |
+
lno = lno + 1
|
| 276 |
+
if w == 0:
|
| 277 |
+
# unterminated single-quoted string
|
| 278 |
+
if level == 0:
|
| 279 |
+
push_good(lno)
|
| 280 |
+
break
|
| 281 |
+
continue
|
| 282 |
+
|
| 283 |
+
if ch == '\\':
|
| 284 |
+
assert i < n
|
| 285 |
+
if code[i] == '\n':
|
| 286 |
+
lno = lno + 1
|
| 287 |
+
i = i+1
|
| 288 |
+
continue
|
| 289 |
+
|
| 290 |
+
# else comment char or paren inside string
|
| 291 |
+
|
| 292 |
+
else:
|
| 293 |
+
# didn't break out of the loop, so we're still
|
| 294 |
+
# inside a string
|
| 295 |
+
if (lno - 1) == firstlno:
|
| 296 |
+
# before the previous \n in code, we were in the first
|
| 297 |
+
# line of the string
|
| 298 |
+
continuation = C_STRING_FIRST_LINE
|
| 299 |
+
else:
|
| 300 |
+
continuation = C_STRING_NEXT_LINES
|
| 301 |
+
continue # with outer loop
|
| 302 |
+
|
| 303 |
+
if ch == '#':
|
| 304 |
+
# consume the comment
|
| 305 |
+
i = code.find('\n', i)
|
| 306 |
+
assert i >= 0
|
| 307 |
+
continue
|
| 308 |
+
|
| 309 |
+
assert ch == '\\'
|
| 310 |
+
assert i < n
|
| 311 |
+
if code[i] == '\n':
|
| 312 |
+
lno = lno + 1
|
| 313 |
+
if i+1 == n:
|
| 314 |
+
continuation = C_BACKSLASH
|
| 315 |
+
i = i+1
|
| 316 |
+
|
| 317 |
+
# The last stmt may be continued for all 3 reasons.
|
| 318 |
+
# String continuation takes precedence over bracket
|
| 319 |
+
# continuation, which beats backslash continuation.
|
| 320 |
+
if (continuation != C_STRING_FIRST_LINE
|
| 321 |
+
and continuation != C_STRING_NEXT_LINES and level > 0):
|
| 322 |
+
continuation = C_BRACKET
|
| 323 |
+
self.continuation = continuation
|
| 324 |
+
|
| 325 |
+
# Push the final line number as a sentinel value, regardless of
|
| 326 |
+
# whether it's continued.
|
| 327 |
+
assert (continuation == C_NONE) == (goodlines[-1] == lno)
|
| 328 |
+
if goodlines[-1] != lno:
|
| 329 |
+
push_good(lno)
|
| 330 |
+
|
| 331 |
+
def get_continuation_type(self):
|
| 332 |
+
self._study1()
|
| 333 |
+
return self.continuation
|
| 334 |
+
|
| 335 |
+
def _study2(self):
|
| 336 |
+
"""
|
| 337 |
+
study1 was sufficient to determine the continuation status,
|
| 338 |
+
but doing more requires looking at every character. study2
|
| 339 |
+
does this for the last interesting statement in the block.
|
| 340 |
+
Creates:
|
| 341 |
+
self.stmt_start, stmt_end
|
| 342 |
+
slice indices of last interesting stmt
|
| 343 |
+
self.stmt_bracketing
|
| 344 |
+
the bracketing structure of the last interesting stmt; for
|
| 345 |
+
example, for the statement "say(boo) or die",
|
| 346 |
+
stmt_bracketing will be ((0, 0), (0, 1), (2, 0), (2, 1),
|
| 347 |
+
(4, 0)). Strings and comments are treated as brackets, for
|
| 348 |
+
the matter.
|
| 349 |
+
self.lastch
|
| 350 |
+
last interesting character before optional trailing comment
|
| 351 |
+
self.lastopenbracketpos
|
| 352 |
+
if continuation is C_BRACKET, index of last open bracket
|
| 353 |
+
"""
|
| 354 |
+
if self.study_level >= 2:
|
| 355 |
+
return
|
| 356 |
+
self._study1()
|
| 357 |
+
self.study_level = 2
|
| 358 |
+
|
| 359 |
+
# Set p and q to slice indices of last interesting stmt.
|
| 360 |
+
code, goodlines = self.code, self.goodlines
|
| 361 |
+
i = len(goodlines) - 1 # Index of newest line.
|
| 362 |
+
p = len(code) # End of goodlines[i]
|
| 363 |
+
while i:
|
| 364 |
+
assert p
|
| 365 |
+
# Make p be the index of the stmt at line number goodlines[i].
|
| 366 |
+
# Move p back to the stmt at line number goodlines[i-1].
|
| 367 |
+
q = p
|
| 368 |
+
for nothing in range(goodlines[i-1], goodlines[i]):
|
| 369 |
+
# tricky: sets p to 0 if no preceding newline
|
| 370 |
+
p = code.rfind('\n', 0, p-1) + 1
|
| 371 |
+
# The stmt code[p:q] isn't a continuation, but may be blank
|
| 372 |
+
# or a non-indenting comment line.
|
| 373 |
+
if _junkre(code, p):
|
| 374 |
+
i = i-1
|
| 375 |
+
else:
|
| 376 |
+
break
|
| 377 |
+
if i == 0:
|
| 378 |
+
# nothing but junk!
|
| 379 |
+
assert p == 0
|
| 380 |
+
q = p
|
| 381 |
+
self.stmt_start, self.stmt_end = p, q
|
| 382 |
+
|
| 383 |
+
# Analyze this stmt, to find the last open bracket (if any)
|
| 384 |
+
# and last interesting character (if any).
|
| 385 |
+
lastch = ""
|
| 386 |
+
stack = [] # stack of open bracket indices
|
| 387 |
+
push_stack = stack.append
|
| 388 |
+
bracketing = [(p, 0)]
|
| 389 |
+
while p < q:
|
| 390 |
+
# suck up all except ()[]{}'"#\\
|
| 391 |
+
m = _chew_ordinaryre(code, p, q)
|
| 392 |
+
if m:
|
| 393 |
+
# we skipped at least one boring char
|
| 394 |
+
newp = m.end()
|
| 395 |
+
# back up over totally boring whitespace
|
| 396 |
+
i = newp - 1 # index of last boring char
|
| 397 |
+
while i >= p and code[i] in " \t\n":
|
| 398 |
+
i = i-1
|
| 399 |
+
if i >= p:
|
| 400 |
+
lastch = code[i]
|
| 401 |
+
p = newp
|
| 402 |
+
if p >= q:
|
| 403 |
+
break
|
| 404 |
+
|
| 405 |
+
ch = code[p]
|
| 406 |
+
|
| 407 |
+
if ch in "([{":
|
| 408 |
+
push_stack(p)
|
| 409 |
+
bracketing.append((p, len(stack)))
|
| 410 |
+
lastch = ch
|
| 411 |
+
p = p+1
|
| 412 |
+
continue
|
| 413 |
+
|
| 414 |
+
if ch in ")]}":
|
| 415 |
+
if stack:
|
| 416 |
+
del stack[-1]
|
| 417 |
+
lastch = ch
|
| 418 |
+
p = p+1
|
| 419 |
+
bracketing.append((p, len(stack)))
|
| 420 |
+
continue
|
| 421 |
+
|
| 422 |
+
if ch == '"' or ch == "'":
|
| 423 |
+
# consume string
|
| 424 |
+
# Note that study1 did this with a Python loop, but
|
| 425 |
+
# we use a regexp here; the reason is speed in both
|
| 426 |
+
# cases; the string may be huge, but study1 pre-squashed
|
| 427 |
+
# strings to a couple of characters per line. study1
|
| 428 |
+
# also needed to keep track of newlines, and we don't
|
| 429 |
+
# have to.
|
| 430 |
+
bracketing.append((p, len(stack)+1))
|
| 431 |
+
lastch = ch
|
| 432 |
+
p = _match_stringre(code, p, q).end()
|
| 433 |
+
bracketing.append((p, len(stack)))
|
| 434 |
+
continue
|
| 435 |
+
|
| 436 |
+
if ch == '#':
|
| 437 |
+
# consume comment and trailing newline
|
| 438 |
+
bracketing.append((p, len(stack)+1))
|
| 439 |
+
p = code.find('\n', p, q) + 1
|
| 440 |
+
assert p > 0
|
| 441 |
+
bracketing.append((p, len(stack)))
|
| 442 |
+
continue
|
| 443 |
+
|
| 444 |
+
assert ch == '\\'
|
| 445 |
+
p = p+1 # beyond backslash
|
| 446 |
+
assert p < q
|
| 447 |
+
if code[p] != '\n':
|
| 448 |
+
# the program is invalid, but can't complain
|
| 449 |
+
lastch = ch + code[p]
|
| 450 |
+
p = p+1 # beyond escaped char
|
| 451 |
+
|
| 452 |
+
# end while p < q:
|
| 453 |
+
|
| 454 |
+
self.lastch = lastch
|
| 455 |
+
self.lastopenbracketpos = stack[-1] if stack else None
|
| 456 |
+
self.stmt_bracketing = tuple(bracketing)
|
| 457 |
+
|
| 458 |
+
def compute_bracket_indent(self):
|
| 459 |
+
"""Return number of spaces the next line should be indented.
|
| 460 |
+
|
| 461 |
+
Line continuation must be C_BRACKET.
|
| 462 |
+
"""
|
| 463 |
+
self._study2()
|
| 464 |
+
assert self.continuation == C_BRACKET
|
| 465 |
+
j = self.lastopenbracketpos
|
| 466 |
+
code = self.code
|
| 467 |
+
n = len(code)
|
| 468 |
+
origi = i = code.rfind('\n', 0, j) + 1
|
| 469 |
+
j = j+1 # one beyond open bracket
|
| 470 |
+
# find first list item; set i to start of its line
|
| 471 |
+
while j < n:
|
| 472 |
+
m = _itemre(code, j)
|
| 473 |
+
if m:
|
| 474 |
+
j = m.end() - 1 # index of first interesting char
|
| 475 |
+
extra = 0
|
| 476 |
+
break
|
| 477 |
+
else:
|
| 478 |
+
# this line is junk; advance to next line
|
| 479 |
+
i = j = code.find('\n', j) + 1
|
| 480 |
+
else:
|
| 481 |
+
# nothing interesting follows the bracket;
|
| 482 |
+
# reproduce the bracket line's indentation + a level
|
| 483 |
+
j = i = origi
|
| 484 |
+
while code[j] in " \t":
|
| 485 |
+
j = j+1
|
| 486 |
+
extra = self.indentwidth
|
| 487 |
+
return len(code[i:j].expandtabs(self.tabwidth)) + extra
|
| 488 |
+
|
| 489 |
+
def get_num_lines_in_stmt(self):
|
| 490 |
+
"""Return number of physical lines in last stmt.
|
| 491 |
+
|
| 492 |
+
The statement doesn't have to be an interesting statement. This is
|
| 493 |
+
intended to be called when continuation is C_BACKSLASH.
|
| 494 |
+
"""
|
| 495 |
+
self._study1()
|
| 496 |
+
goodlines = self.goodlines
|
| 497 |
+
return goodlines[-1] - goodlines[-2]
|
| 498 |
+
|
| 499 |
+
def compute_backslash_indent(self):
|
| 500 |
+
"""Return number of spaces the next line should be indented.
|
| 501 |
+
|
| 502 |
+
Line continuation must be C_BACKSLASH. Also assume that the new
|
| 503 |
+
line is the first one following the initial line of the stmt.
|
| 504 |
+
"""
|
| 505 |
+
self._study2()
|
| 506 |
+
assert self.continuation == C_BACKSLASH
|
| 507 |
+
code = self.code
|
| 508 |
+
i = self.stmt_start
|
| 509 |
+
while code[i] in " \t":
|
| 510 |
+
i = i+1
|
| 511 |
+
startpos = i
|
| 512 |
+
|
| 513 |
+
# See whether the initial line starts an assignment stmt; i.e.,
|
| 514 |
+
# look for an = operator
|
| 515 |
+
endpos = code.find('\n', startpos) + 1
|
| 516 |
+
found = level = 0
|
| 517 |
+
while i < endpos:
|
| 518 |
+
ch = code[i]
|
| 519 |
+
if ch in "([{":
|
| 520 |
+
level = level + 1
|
| 521 |
+
i = i+1
|
| 522 |
+
elif ch in ")]}":
|
| 523 |
+
if level:
|
| 524 |
+
level = level - 1
|
| 525 |
+
i = i+1
|
| 526 |
+
elif ch == '"' or ch == "'":
|
| 527 |
+
i = _match_stringre(code, i, endpos).end()
|
| 528 |
+
elif ch == '#':
|
| 529 |
+
# This line is unreachable because the # makes a comment of
|
| 530 |
+
# everything after it.
|
| 531 |
+
break
|
| 532 |
+
elif level == 0 and ch == '=' and \
|
| 533 |
+
(i == 0 or code[i-1] not in "=<>!") and \
|
| 534 |
+
code[i+1] != '=':
|
| 535 |
+
found = 1
|
| 536 |
+
break
|
| 537 |
+
else:
|
| 538 |
+
i = i+1
|
| 539 |
+
|
| 540 |
+
if found:
|
| 541 |
+
# found a legit =, but it may be the last interesting
|
| 542 |
+
# thing on the line
|
| 543 |
+
i = i+1 # move beyond the =
|
| 544 |
+
found = re.match(r"\s*\\", code[i:endpos]) is None
|
| 545 |
+
|
| 546 |
+
if not found:
|
| 547 |
+
# oh well ... settle for moving beyond the first chunk
|
| 548 |
+
# of non-whitespace chars
|
| 549 |
+
i = startpos
|
| 550 |
+
while code[i] not in " \t\n":
|
| 551 |
+
i = i+1
|
| 552 |
+
|
| 553 |
+
return len(code[self.stmt_start:i].expandtabs(\
|
| 554 |
+
self.tabwidth)) + 1
|
| 555 |
+
|
| 556 |
+
def get_base_indent_string(self):
|
| 557 |
+
"""Return the leading whitespace on the initial line of the last
|
| 558 |
+
interesting stmt.
|
| 559 |
+
"""
|
| 560 |
+
self._study2()
|
| 561 |
+
i, n = self.stmt_start, self.stmt_end
|
| 562 |
+
j = i
|
| 563 |
+
code = self.code
|
| 564 |
+
while j < n and code[j] in " \t":
|
| 565 |
+
j = j + 1
|
| 566 |
+
return code[i:j]
|
| 567 |
+
|
| 568 |
+
def is_block_opener(self):
|
| 569 |
+
"Return True if the last interesting statement opens a block."
|
| 570 |
+
self._study2()
|
| 571 |
+
return self.lastch == ':'
|
| 572 |
+
|
| 573 |
+
def is_block_closer(self):
|
| 574 |
+
"Return True if the last interesting statement closes a block."
|
| 575 |
+
self._study2()
|
| 576 |
+
return _closere(self.code, self.stmt_start) is not None
|
| 577 |
+
|
| 578 |
+
def get_last_stmt_bracketing(self):
|
| 579 |
+
"""Return bracketing structure of the last interesting statement.
|
| 580 |
+
|
| 581 |
+
The returned tuple is in the format defined in _study2().
|
| 582 |
+
"""
|
| 583 |
+
self._study2()
|
| 584 |
+
return self.stmt_bracketing
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
if __name__ == '__main__':
|
| 588 |
+
from unittest import main
|
| 589 |
+
main('idlelib.idle_test.test_pyparse', verbosity=2)
|
evalkit_cambrian/lib/python3.10/idlelib/pyshell.py
ADDED
|
@@ -0,0 +1,1713 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 4 |
+
if __name__ == "__main__":
|
| 5 |
+
sys.modules['idlelib.pyshell'] = sys.modules['__main__']
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
from tkinter import *
|
| 9 |
+
except ImportError:
|
| 10 |
+
print("** IDLE can't import Tkinter.\n"
|
| 11 |
+
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
|
| 12 |
+
raise SystemExit(1)
|
| 13 |
+
|
| 14 |
+
# Valid arguments for the ...Awareness call below are defined in the following.
|
| 15 |
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx
|
| 16 |
+
if sys.platform == 'win32':
|
| 17 |
+
try:
|
| 18 |
+
import ctypes
|
| 19 |
+
PROCESS_SYSTEM_DPI_AWARE = 1 # Int required.
|
| 20 |
+
ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
|
| 21 |
+
except (ImportError, AttributeError, OSError):
|
| 22 |
+
pass
|
| 23 |
+
|
| 24 |
+
from tkinter import messagebox
|
| 25 |
+
if TkVersion < 8.5:
|
| 26 |
+
root = Tk() # otherwise create root in main
|
| 27 |
+
root.withdraw()
|
| 28 |
+
from idlelib.run import fix_scaling
|
| 29 |
+
fix_scaling(root)
|
| 30 |
+
messagebox.showerror("Idle Cannot Start",
|
| 31 |
+
"Idle requires tcl/tk 8.5+, not %s." % TkVersion,
|
| 32 |
+
parent=root)
|
| 33 |
+
raise SystemExit(1)
|
| 34 |
+
|
| 35 |
+
from code import InteractiveInterpreter
|
| 36 |
+
import itertools
|
| 37 |
+
import linecache
|
| 38 |
+
import os
|
| 39 |
+
import os.path
|
| 40 |
+
from platform import python_version
|
| 41 |
+
import re
|
| 42 |
+
import socket
|
| 43 |
+
import subprocess
|
| 44 |
+
from textwrap import TextWrapper
|
| 45 |
+
import threading
|
| 46 |
+
import time
|
| 47 |
+
import tokenize
|
| 48 |
+
import warnings
|
| 49 |
+
|
| 50 |
+
from idlelib.colorizer import ColorDelegator
|
| 51 |
+
from idlelib.config import idleConf
|
| 52 |
+
from idlelib.delegator import Delegator
|
| 53 |
+
from idlelib import debugger
|
| 54 |
+
from idlelib import debugger_r
|
| 55 |
+
from idlelib.editor import EditorWindow, fixwordbreaks
|
| 56 |
+
from idlelib.filelist import FileList
|
| 57 |
+
from idlelib.outwin import OutputWindow
|
| 58 |
+
from idlelib import replace
|
| 59 |
+
from idlelib import rpc
|
| 60 |
+
from idlelib.run import idle_formatwarning, StdInputFile, StdOutputFile
|
| 61 |
+
from idlelib.undo import UndoDelegator
|
| 62 |
+
|
| 63 |
+
# Default for testing; defaults to True in main() for running.
|
| 64 |
+
use_subprocess = False
|
| 65 |
+
|
| 66 |
+
HOST = '127.0.0.1' # python execution server on localhost loopback
|
| 67 |
+
PORT = 0 # someday pass in host, port for remote debug capability
|
| 68 |
+
|
| 69 |
+
try: # In case IDLE started with -n.
|
| 70 |
+
eof = 'Ctrl-D (end-of-file)'
|
| 71 |
+
exit.eof = eof
|
| 72 |
+
quit.eof = eof
|
| 73 |
+
except NameError: # In case python started with -S.
|
| 74 |
+
pass
|
| 75 |
+
|
| 76 |
+
# Override warnings module to write to warning_stream. Initialize to send IDLE
|
| 77 |
+
# internal warnings to the console. ScriptBinding.check_syntax() will
|
| 78 |
+
# temporarily redirect the stream to the shell window to display warnings when
|
| 79 |
+
# checking user's code.
|
| 80 |
+
warning_stream = sys.__stderr__ # None, at least on Windows, if no console.
|
| 81 |
+
|
| 82 |
+
def idle_showwarning(
|
| 83 |
+
message, category, filename, lineno, file=None, line=None):
|
| 84 |
+
"""Show Idle-format warning (after replacing warnings.showwarning).
|
| 85 |
+
|
| 86 |
+
The differences are the formatter called, the file=None replacement,
|
| 87 |
+
which can be None, the capture of the consequence AttributeError,
|
| 88 |
+
and the output of a hard-coded prompt.
|
| 89 |
+
"""
|
| 90 |
+
if file is None:
|
| 91 |
+
file = warning_stream
|
| 92 |
+
try:
|
| 93 |
+
file.write(idle_formatwarning(
|
| 94 |
+
message, category, filename, lineno, line=line))
|
| 95 |
+
file.write(">>> ")
|
| 96 |
+
except (AttributeError, OSError):
|
| 97 |
+
pass # if file (probably __stderr__) is invalid, skip warning.
|
| 98 |
+
|
| 99 |
+
_warnings_showwarning = None
|
| 100 |
+
|
| 101 |
+
def capture_warnings(capture):
|
| 102 |
+
"Replace warning.showwarning with idle_showwarning, or reverse."
|
| 103 |
+
|
| 104 |
+
global _warnings_showwarning
|
| 105 |
+
if capture:
|
| 106 |
+
if _warnings_showwarning is None:
|
| 107 |
+
_warnings_showwarning = warnings.showwarning
|
| 108 |
+
warnings.showwarning = idle_showwarning
|
| 109 |
+
else:
|
| 110 |
+
if _warnings_showwarning is not None:
|
| 111 |
+
warnings.showwarning = _warnings_showwarning
|
| 112 |
+
_warnings_showwarning = None
|
| 113 |
+
|
| 114 |
+
capture_warnings(True)
|
| 115 |
+
|
| 116 |
+
def extended_linecache_checkcache(filename=None,
|
| 117 |
+
orig_checkcache=linecache.checkcache):
|
| 118 |
+
"""Extend linecache.checkcache to preserve the <pyshell#...> entries
|
| 119 |
+
|
| 120 |
+
Rather than repeating the linecache code, patch it to save the
|
| 121 |
+
<pyshell#...> entries, call the original linecache.checkcache()
|
| 122 |
+
(skipping them), and then restore the saved entries.
|
| 123 |
+
|
| 124 |
+
orig_checkcache is bound at definition time to the original
|
| 125 |
+
method, allowing it to be patched.
|
| 126 |
+
"""
|
| 127 |
+
cache = linecache.cache
|
| 128 |
+
save = {}
|
| 129 |
+
for key in list(cache):
|
| 130 |
+
if key[:1] + key[-1:] == '<>':
|
| 131 |
+
save[key] = cache.pop(key)
|
| 132 |
+
orig_checkcache(filename)
|
| 133 |
+
cache.update(save)
|
| 134 |
+
|
| 135 |
+
# Patch linecache.checkcache():
|
| 136 |
+
linecache.checkcache = extended_linecache_checkcache
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class PyShellEditorWindow(EditorWindow):
|
| 140 |
+
"Regular text edit window in IDLE, supports breakpoints"
|
| 141 |
+
|
| 142 |
+
def __init__(self, *args):
|
| 143 |
+
self.breakpoints = []
|
| 144 |
+
EditorWindow.__init__(self, *args)
|
| 145 |
+
self.text.bind("<<set-breakpoint-here>>", self.set_breakpoint_here)
|
| 146 |
+
self.text.bind("<<clear-breakpoint-here>>", self.clear_breakpoint_here)
|
| 147 |
+
self.text.bind("<<open-python-shell>>", self.flist.open_shell)
|
| 148 |
+
|
| 149 |
+
#TODO: don't read/write this from/to .idlerc when testing
|
| 150 |
+
self.breakpointPath = os.path.join(
|
| 151 |
+
idleConf.userdir, 'breakpoints.lst')
|
| 152 |
+
# whenever a file is changed, restore breakpoints
|
| 153 |
+
def filename_changed_hook(old_hook=self.io.filename_change_hook,
|
| 154 |
+
self=self):
|
| 155 |
+
self.restore_file_breaks()
|
| 156 |
+
old_hook()
|
| 157 |
+
self.io.set_filename_change_hook(filename_changed_hook)
|
| 158 |
+
if self.io.filename:
|
| 159 |
+
self.restore_file_breaks()
|
| 160 |
+
self.color_breakpoint_text()
|
| 161 |
+
|
| 162 |
+
rmenu_specs = [
|
| 163 |
+
("Cut", "<<cut>>", "rmenu_check_cut"),
|
| 164 |
+
("Copy", "<<copy>>", "rmenu_check_copy"),
|
| 165 |
+
("Paste", "<<paste>>", "rmenu_check_paste"),
|
| 166 |
+
(None, None, None),
|
| 167 |
+
("Set Breakpoint", "<<set-breakpoint-here>>", None),
|
| 168 |
+
("Clear Breakpoint", "<<clear-breakpoint-here>>", None)
|
| 169 |
+
]
|
| 170 |
+
|
| 171 |
+
def color_breakpoint_text(self, color=True):
|
| 172 |
+
"Turn colorizing of breakpoint text on or off"
|
| 173 |
+
if self.io is None:
|
| 174 |
+
# possible due to update in restore_file_breaks
|
| 175 |
+
return
|
| 176 |
+
if color:
|
| 177 |
+
theme = idleConf.CurrentTheme()
|
| 178 |
+
cfg = idleConf.GetHighlight(theme, "break")
|
| 179 |
+
else:
|
| 180 |
+
cfg = {'foreground': '', 'background': ''}
|
| 181 |
+
self.text.tag_config('BREAK', cfg)
|
| 182 |
+
|
| 183 |
+
def set_breakpoint(self, lineno):
|
| 184 |
+
text = self.text
|
| 185 |
+
filename = self.io.filename
|
| 186 |
+
text.tag_add("BREAK", "%d.0" % lineno, "%d.0" % (lineno+1))
|
| 187 |
+
try:
|
| 188 |
+
self.breakpoints.index(lineno)
|
| 189 |
+
except ValueError: # only add if missing, i.e. do once
|
| 190 |
+
self.breakpoints.append(lineno)
|
| 191 |
+
try: # update the subprocess debugger
|
| 192 |
+
debug = self.flist.pyshell.interp.debugger
|
| 193 |
+
debug.set_breakpoint_here(filename, lineno)
|
| 194 |
+
except: # but debugger may not be active right now....
|
| 195 |
+
pass
|
| 196 |
+
|
| 197 |
+
def set_breakpoint_here(self, event=None):
|
| 198 |
+
text = self.text
|
| 199 |
+
filename = self.io.filename
|
| 200 |
+
if not filename:
|
| 201 |
+
text.bell()
|
| 202 |
+
return
|
| 203 |
+
lineno = int(float(text.index("insert")))
|
| 204 |
+
self.set_breakpoint(lineno)
|
| 205 |
+
|
| 206 |
+
def clear_breakpoint_here(self, event=None):
|
| 207 |
+
text = self.text
|
| 208 |
+
filename = self.io.filename
|
| 209 |
+
if not filename:
|
| 210 |
+
text.bell()
|
| 211 |
+
return
|
| 212 |
+
lineno = int(float(text.index("insert")))
|
| 213 |
+
try:
|
| 214 |
+
self.breakpoints.remove(lineno)
|
| 215 |
+
except:
|
| 216 |
+
pass
|
| 217 |
+
text.tag_remove("BREAK", "insert linestart",\
|
| 218 |
+
"insert lineend +1char")
|
| 219 |
+
try:
|
| 220 |
+
debug = self.flist.pyshell.interp.debugger
|
| 221 |
+
debug.clear_breakpoint_here(filename, lineno)
|
| 222 |
+
except:
|
| 223 |
+
pass
|
| 224 |
+
|
| 225 |
+
def clear_file_breaks(self):
|
| 226 |
+
if self.breakpoints:
|
| 227 |
+
text = self.text
|
| 228 |
+
filename = self.io.filename
|
| 229 |
+
if not filename:
|
| 230 |
+
text.bell()
|
| 231 |
+
return
|
| 232 |
+
self.breakpoints = []
|
| 233 |
+
text.tag_remove("BREAK", "1.0", END)
|
| 234 |
+
try:
|
| 235 |
+
debug = self.flist.pyshell.interp.debugger
|
| 236 |
+
debug.clear_file_breaks(filename)
|
| 237 |
+
except:
|
| 238 |
+
pass
|
| 239 |
+
|
| 240 |
+
def store_file_breaks(self):
|
| 241 |
+
"Save breakpoints when file is saved"
|
| 242 |
+
# XXX 13 Dec 2002 KBK Currently the file must be saved before it can
|
| 243 |
+
# be run. The breaks are saved at that time. If we introduce
|
| 244 |
+
# a temporary file save feature the save breaks functionality
|
| 245 |
+
# needs to be re-verified, since the breaks at the time the
|
| 246 |
+
# temp file is created may differ from the breaks at the last
|
| 247 |
+
# permanent save of the file. Currently, a break introduced
|
| 248 |
+
# after a save will be effective, but not persistent.
|
| 249 |
+
# This is necessary to keep the saved breaks synched with the
|
| 250 |
+
# saved file.
|
| 251 |
+
#
|
| 252 |
+
# Breakpoints are set as tagged ranges in the text.
|
| 253 |
+
# Since a modified file has to be saved before it is
|
| 254 |
+
# run, and since self.breakpoints (from which the subprocess
|
| 255 |
+
# debugger is loaded) is updated during the save, the visible
|
| 256 |
+
# breaks stay synched with the subprocess even if one of these
|
| 257 |
+
# unexpected breakpoint deletions occurs.
|
| 258 |
+
breaks = self.breakpoints
|
| 259 |
+
filename = self.io.filename
|
| 260 |
+
try:
|
| 261 |
+
with open(self.breakpointPath, "r") as fp:
|
| 262 |
+
lines = fp.readlines()
|
| 263 |
+
except OSError:
|
| 264 |
+
lines = []
|
| 265 |
+
try:
|
| 266 |
+
with open(self.breakpointPath, "w") as new_file:
|
| 267 |
+
for line in lines:
|
| 268 |
+
if not line.startswith(filename + '='):
|
| 269 |
+
new_file.write(line)
|
| 270 |
+
self.update_breakpoints()
|
| 271 |
+
breaks = self.breakpoints
|
| 272 |
+
if breaks:
|
| 273 |
+
new_file.write(filename + '=' + str(breaks) + '\n')
|
| 274 |
+
except OSError as err:
|
| 275 |
+
if not getattr(self.root, "breakpoint_error_displayed", False):
|
| 276 |
+
self.root.breakpoint_error_displayed = True
|
| 277 |
+
messagebox.showerror(title='IDLE Error',
|
| 278 |
+
message='Unable to update breakpoint list:\n%s'
|
| 279 |
+
% str(err),
|
| 280 |
+
parent=self.text)
|
| 281 |
+
|
| 282 |
+
def restore_file_breaks(self):
|
| 283 |
+
self.text.update() # this enables setting "BREAK" tags to be visible
|
| 284 |
+
if self.io is None:
|
| 285 |
+
# can happen if IDLE closes due to the .update() call
|
| 286 |
+
return
|
| 287 |
+
filename = self.io.filename
|
| 288 |
+
if filename is None:
|
| 289 |
+
return
|
| 290 |
+
if os.path.isfile(self.breakpointPath):
|
| 291 |
+
with open(self.breakpointPath, "r") as fp:
|
| 292 |
+
lines = fp.readlines()
|
| 293 |
+
for line in lines:
|
| 294 |
+
if line.startswith(filename + '='):
|
| 295 |
+
breakpoint_linenumbers = eval(line[len(filename)+1:])
|
| 296 |
+
for breakpoint_linenumber in breakpoint_linenumbers:
|
| 297 |
+
self.set_breakpoint(breakpoint_linenumber)
|
| 298 |
+
|
| 299 |
+
def update_breakpoints(self):
|
| 300 |
+
"Retrieves all the breakpoints in the current window"
|
| 301 |
+
text = self.text
|
| 302 |
+
ranges = text.tag_ranges("BREAK")
|
| 303 |
+
linenumber_list = self.ranges_to_linenumbers(ranges)
|
| 304 |
+
self.breakpoints = linenumber_list
|
| 305 |
+
|
| 306 |
+
def ranges_to_linenumbers(self, ranges):
|
| 307 |
+
lines = []
|
| 308 |
+
for index in range(0, len(ranges), 2):
|
| 309 |
+
lineno = int(float(ranges[index].string))
|
| 310 |
+
end = int(float(ranges[index+1].string))
|
| 311 |
+
while lineno < end:
|
| 312 |
+
lines.append(lineno)
|
| 313 |
+
lineno += 1
|
| 314 |
+
return lines
|
| 315 |
+
|
| 316 |
+
# XXX 13 Dec 2002 KBK Not used currently
|
| 317 |
+
# def saved_change_hook(self):
|
| 318 |
+
# "Extend base method - clear breaks if module is modified"
|
| 319 |
+
# if not self.get_saved():
|
| 320 |
+
# self.clear_file_breaks()
|
| 321 |
+
# EditorWindow.saved_change_hook(self)
|
| 322 |
+
|
| 323 |
+
def _close(self):
|
| 324 |
+
"Extend base method - clear breaks when module is closed"
|
| 325 |
+
self.clear_file_breaks()
|
| 326 |
+
EditorWindow._close(self)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
class PyShellFileList(FileList):
|
| 330 |
+
"Extend base class: IDLE supports a shell and breakpoints"
|
| 331 |
+
|
| 332 |
+
# override FileList's class variable, instances return PyShellEditorWindow
|
| 333 |
+
# instead of EditorWindow when new edit windows are created.
|
| 334 |
+
EditorWindow = PyShellEditorWindow
|
| 335 |
+
|
| 336 |
+
pyshell = None
|
| 337 |
+
|
| 338 |
+
def open_shell(self, event=None):
|
| 339 |
+
if self.pyshell:
|
| 340 |
+
self.pyshell.top.wakeup()
|
| 341 |
+
else:
|
| 342 |
+
self.pyshell = PyShell(self)
|
| 343 |
+
if self.pyshell:
|
| 344 |
+
if not self.pyshell.begin():
|
| 345 |
+
return None
|
| 346 |
+
return self.pyshell
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
class ModifiedColorDelegator(ColorDelegator):
|
| 350 |
+
"Extend base class: colorizer for the shell window itself"
|
| 351 |
+
def recolorize_main(self):
|
| 352 |
+
self.tag_remove("TODO", "1.0", "iomark")
|
| 353 |
+
self.tag_add("SYNC", "1.0", "iomark")
|
| 354 |
+
ColorDelegator.recolorize_main(self)
|
| 355 |
+
|
| 356 |
+
def removecolors(self):
|
| 357 |
+
# Don't remove shell color tags before "iomark"
|
| 358 |
+
for tag in self.tagdefs:
|
| 359 |
+
self.tag_remove(tag, "iomark", "end")
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class ModifiedUndoDelegator(UndoDelegator):
|
| 363 |
+
"Extend base class: forbid insert/delete before the I/O mark"
|
| 364 |
+
def insert(self, index, chars, tags=None):
|
| 365 |
+
try:
|
| 366 |
+
if self.delegate.compare(index, "<", "iomark"):
|
| 367 |
+
self.delegate.bell()
|
| 368 |
+
return
|
| 369 |
+
except TclError:
|
| 370 |
+
pass
|
| 371 |
+
UndoDelegator.insert(self, index, chars, tags)
|
| 372 |
+
|
| 373 |
+
def delete(self, index1, index2=None):
|
| 374 |
+
try:
|
| 375 |
+
if self.delegate.compare(index1, "<", "iomark"):
|
| 376 |
+
self.delegate.bell()
|
| 377 |
+
return
|
| 378 |
+
except TclError:
|
| 379 |
+
pass
|
| 380 |
+
UndoDelegator.delete(self, index1, index2)
|
| 381 |
+
|
| 382 |
+
def undo_event(self, event):
|
| 383 |
+
# Temporarily monkey-patch the delegate's .insert() method to
|
| 384 |
+
# always use the "stdin" tag. This is needed for undo-ing
|
| 385 |
+
# deletions to preserve the "stdin" tag, because UndoDelegator
|
| 386 |
+
# doesn't preserve tags for deleted text.
|
| 387 |
+
orig_insert = self.delegate.insert
|
| 388 |
+
self.delegate.insert = \
|
| 389 |
+
lambda index, chars: orig_insert(index, chars, "stdin")
|
| 390 |
+
try:
|
| 391 |
+
super().undo_event(event)
|
| 392 |
+
finally:
|
| 393 |
+
self.delegate.insert = orig_insert
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
class UserInputTaggingDelegator(Delegator):
|
| 397 |
+
"""Delegator used to tag user input with "stdin"."""
|
| 398 |
+
def insert(self, index, chars, tags=None):
|
| 399 |
+
if tags is None:
|
| 400 |
+
tags = "stdin"
|
| 401 |
+
self.delegate.insert(index, chars, tags)
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
class MyRPCClient(rpc.RPCClient):
|
| 405 |
+
|
| 406 |
+
def handle_EOF(self):
|
| 407 |
+
"Override the base class - just re-raise EOFError"
|
| 408 |
+
raise EOFError
|
| 409 |
+
|
| 410 |
+
def restart_line(width, filename): # See bpo-38141.
|
| 411 |
+
"""Return width long restart line formatted with filename.
|
| 412 |
+
|
| 413 |
+
Fill line with balanced '='s, with any extras and at least one at
|
| 414 |
+
the beginning. Do not end with a trailing space.
|
| 415 |
+
"""
|
| 416 |
+
tag = f"= RESTART: {filename or 'Shell'} ="
|
| 417 |
+
if width >= len(tag):
|
| 418 |
+
div, mod = divmod((width -len(tag)), 2)
|
| 419 |
+
return f"{(div+mod)*'='}{tag}{div*'='}"
|
| 420 |
+
else:
|
| 421 |
+
return tag[:-2] # Remove ' ='.
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
class ModifiedInterpreter(InteractiveInterpreter):
|
| 425 |
+
|
| 426 |
+
def __init__(self, tkconsole):
|
| 427 |
+
self.tkconsole = tkconsole
|
| 428 |
+
locals = sys.modules['__main__'].__dict__
|
| 429 |
+
InteractiveInterpreter.__init__(self, locals=locals)
|
| 430 |
+
self.restarting = False
|
| 431 |
+
self.subprocess_arglist = None
|
| 432 |
+
self.port = PORT
|
| 433 |
+
self.original_compiler_flags = self.compile.compiler.flags
|
| 434 |
+
|
| 435 |
+
_afterid = None
|
| 436 |
+
rpcclt = None
|
| 437 |
+
rpcsubproc = None
|
| 438 |
+
|
| 439 |
+
def spawn_subprocess(self):
|
| 440 |
+
if self.subprocess_arglist is None:
|
| 441 |
+
self.subprocess_arglist = self.build_subprocess_arglist()
|
| 442 |
+
self.rpcsubproc = subprocess.Popen(self.subprocess_arglist)
|
| 443 |
+
|
| 444 |
+
def build_subprocess_arglist(self):
|
| 445 |
+
assert (self.port!=0), (
|
| 446 |
+
"Socket should have been assigned a port number.")
|
| 447 |
+
w = ['-W' + s for s in sys.warnoptions]
|
| 448 |
+
# Maybe IDLE is installed and is being accessed via sys.path,
|
| 449 |
+
# or maybe it's not installed and the idle.py script is being
|
| 450 |
+
# run from the IDLE source directory.
|
| 451 |
+
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
|
| 452 |
+
default=False, type='bool')
|
| 453 |
+
command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,)
|
| 454 |
+
return [sys.executable] + w + ["-c", command, str(self.port)]
|
| 455 |
+
|
| 456 |
+
def start_subprocess(self):
|
| 457 |
+
addr = (HOST, self.port)
|
| 458 |
+
# GUI makes several attempts to acquire socket, listens for connection
|
| 459 |
+
for i in range(3):
|
| 460 |
+
time.sleep(i)
|
| 461 |
+
try:
|
| 462 |
+
self.rpcclt = MyRPCClient(addr)
|
| 463 |
+
break
|
| 464 |
+
except OSError:
|
| 465 |
+
pass
|
| 466 |
+
else:
|
| 467 |
+
self.display_port_binding_error()
|
| 468 |
+
return None
|
| 469 |
+
# if PORT was 0, system will assign an 'ephemeral' port. Find it out:
|
| 470 |
+
self.port = self.rpcclt.listening_sock.getsockname()[1]
|
| 471 |
+
# if PORT was not 0, probably working with a remote execution server
|
| 472 |
+
if PORT != 0:
|
| 473 |
+
# To allow reconnection within the 2MSL wait (cf. Stevens TCP
|
| 474 |
+
# V1, 18.6), set SO_REUSEADDR. Note that this can be problematic
|
| 475 |
+
# on Windows since the implementation allows two active sockets on
|
| 476 |
+
# the same address!
|
| 477 |
+
self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET,
|
| 478 |
+
socket.SO_REUSEADDR, 1)
|
| 479 |
+
self.spawn_subprocess()
|
| 480 |
+
#time.sleep(20) # test to simulate GUI not accepting connection
|
| 481 |
+
# Accept the connection from the Python execution server
|
| 482 |
+
self.rpcclt.listening_sock.settimeout(10)
|
| 483 |
+
try:
|
| 484 |
+
self.rpcclt.accept()
|
| 485 |
+
except TimeoutError:
|
| 486 |
+
self.display_no_subprocess_error()
|
| 487 |
+
return None
|
| 488 |
+
self.rpcclt.register("console", self.tkconsole)
|
| 489 |
+
self.rpcclt.register("stdin", self.tkconsole.stdin)
|
| 490 |
+
self.rpcclt.register("stdout", self.tkconsole.stdout)
|
| 491 |
+
self.rpcclt.register("stderr", self.tkconsole.stderr)
|
| 492 |
+
self.rpcclt.register("flist", self.tkconsole.flist)
|
| 493 |
+
self.rpcclt.register("linecache", linecache)
|
| 494 |
+
self.rpcclt.register("interp", self)
|
| 495 |
+
self.transfer_path(with_cwd=True)
|
| 496 |
+
self.poll_subprocess()
|
| 497 |
+
return self.rpcclt
|
| 498 |
+
|
| 499 |
+
def restart_subprocess(self, with_cwd=False, filename=''):
|
| 500 |
+
if self.restarting:
|
| 501 |
+
return self.rpcclt
|
| 502 |
+
self.restarting = True
|
| 503 |
+
# close only the subprocess debugger
|
| 504 |
+
debug = self.getdebugger()
|
| 505 |
+
if debug:
|
| 506 |
+
try:
|
| 507 |
+
# Only close subprocess debugger, don't unregister gui_adap!
|
| 508 |
+
debugger_r.close_subprocess_debugger(self.rpcclt)
|
| 509 |
+
except:
|
| 510 |
+
pass
|
| 511 |
+
# Kill subprocess, spawn a new one, accept connection.
|
| 512 |
+
self.rpcclt.close()
|
| 513 |
+
self.terminate_subprocess()
|
| 514 |
+
console = self.tkconsole
|
| 515 |
+
was_executing = console.executing
|
| 516 |
+
console.executing = False
|
| 517 |
+
self.spawn_subprocess()
|
| 518 |
+
try:
|
| 519 |
+
self.rpcclt.accept()
|
| 520 |
+
except TimeoutError:
|
| 521 |
+
self.display_no_subprocess_error()
|
| 522 |
+
return None
|
| 523 |
+
self.transfer_path(with_cwd=with_cwd)
|
| 524 |
+
console.stop_readline()
|
| 525 |
+
# annotate restart in shell window and mark it
|
| 526 |
+
console.text.delete("iomark", "end-1c")
|
| 527 |
+
console.write('\n')
|
| 528 |
+
console.write(restart_line(console.width, filename))
|
| 529 |
+
console.text.mark_set("restart", "end-1c")
|
| 530 |
+
console.text.mark_gravity("restart", "left")
|
| 531 |
+
if not filename:
|
| 532 |
+
console.showprompt()
|
| 533 |
+
# restart subprocess debugger
|
| 534 |
+
if debug:
|
| 535 |
+
# Restarted debugger connects to current instance of debug GUI
|
| 536 |
+
debugger_r.restart_subprocess_debugger(self.rpcclt)
|
| 537 |
+
# reload remote debugger breakpoints for all PyShellEditWindows
|
| 538 |
+
debug.load_breakpoints()
|
| 539 |
+
self.compile.compiler.flags = self.original_compiler_flags
|
| 540 |
+
self.restarting = False
|
| 541 |
+
return self.rpcclt
|
| 542 |
+
|
| 543 |
+
def __request_interrupt(self):
|
| 544 |
+
self.rpcclt.remotecall("exec", "interrupt_the_server", (), {})
|
| 545 |
+
|
| 546 |
+
def interrupt_subprocess(self):
|
| 547 |
+
threading.Thread(target=self.__request_interrupt).start()
|
| 548 |
+
|
| 549 |
+
def kill_subprocess(self):
|
| 550 |
+
if self._afterid is not None:
|
| 551 |
+
self.tkconsole.text.after_cancel(self._afterid)
|
| 552 |
+
try:
|
| 553 |
+
self.rpcclt.listening_sock.close()
|
| 554 |
+
except AttributeError: # no socket
|
| 555 |
+
pass
|
| 556 |
+
try:
|
| 557 |
+
self.rpcclt.close()
|
| 558 |
+
except AttributeError: # no socket
|
| 559 |
+
pass
|
| 560 |
+
self.terminate_subprocess()
|
| 561 |
+
self.tkconsole.executing = False
|
| 562 |
+
self.rpcclt = None
|
| 563 |
+
|
| 564 |
+
def terminate_subprocess(self):
|
| 565 |
+
"Make sure subprocess is terminated"
|
| 566 |
+
try:
|
| 567 |
+
self.rpcsubproc.kill()
|
| 568 |
+
except OSError:
|
| 569 |
+
# process already terminated
|
| 570 |
+
return
|
| 571 |
+
else:
|
| 572 |
+
try:
|
| 573 |
+
self.rpcsubproc.wait()
|
| 574 |
+
except OSError:
|
| 575 |
+
return
|
| 576 |
+
|
| 577 |
+
def transfer_path(self, with_cwd=False):
|
| 578 |
+
if with_cwd: # Issue 13506
|
| 579 |
+
path = [''] # include Current Working Directory
|
| 580 |
+
path.extend(sys.path)
|
| 581 |
+
else:
|
| 582 |
+
path = sys.path
|
| 583 |
+
|
| 584 |
+
self.runcommand("""if 1:
|
| 585 |
+
import sys as _sys
|
| 586 |
+
_sys.path = %r
|
| 587 |
+
del _sys
|
| 588 |
+
\n""" % (path,))
|
| 589 |
+
|
| 590 |
+
active_seq = None
|
| 591 |
+
|
| 592 |
+
def poll_subprocess(self):
|
| 593 |
+
clt = self.rpcclt
|
| 594 |
+
if clt is None:
|
| 595 |
+
return
|
| 596 |
+
try:
|
| 597 |
+
response = clt.pollresponse(self.active_seq, wait=0.05)
|
| 598 |
+
except (EOFError, OSError, KeyboardInterrupt):
|
| 599 |
+
# lost connection or subprocess terminated itself, restart
|
| 600 |
+
# [the KBI is from rpc.SocketIO.handle_EOF()]
|
| 601 |
+
if self.tkconsole.closing:
|
| 602 |
+
return
|
| 603 |
+
response = None
|
| 604 |
+
self.restart_subprocess()
|
| 605 |
+
if response:
|
| 606 |
+
self.tkconsole.resetoutput()
|
| 607 |
+
self.active_seq = None
|
| 608 |
+
how, what = response
|
| 609 |
+
console = self.tkconsole.console
|
| 610 |
+
if how == "OK":
|
| 611 |
+
if what is not None:
|
| 612 |
+
print(repr(what), file=console)
|
| 613 |
+
elif how == "EXCEPTION":
|
| 614 |
+
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
|
| 615 |
+
self.remote_stack_viewer()
|
| 616 |
+
elif how == "ERROR":
|
| 617 |
+
errmsg = "pyshell.ModifiedInterpreter: Subprocess ERROR:\n"
|
| 618 |
+
print(errmsg, what, file=sys.__stderr__)
|
| 619 |
+
print(errmsg, what, file=console)
|
| 620 |
+
# we received a response to the currently active seq number:
|
| 621 |
+
try:
|
| 622 |
+
self.tkconsole.endexecuting()
|
| 623 |
+
except AttributeError: # shell may have closed
|
| 624 |
+
pass
|
| 625 |
+
# Reschedule myself
|
| 626 |
+
if not self.tkconsole.closing:
|
| 627 |
+
self._afterid = self.tkconsole.text.after(
|
| 628 |
+
self.tkconsole.pollinterval, self.poll_subprocess)
|
| 629 |
+
|
| 630 |
+
debugger = None
|
| 631 |
+
|
| 632 |
+
def setdebugger(self, debugger):
|
| 633 |
+
self.debugger = debugger
|
| 634 |
+
|
| 635 |
+
def getdebugger(self):
|
| 636 |
+
return self.debugger
|
| 637 |
+
|
| 638 |
+
def open_remote_stack_viewer(self):
|
| 639 |
+
"""Initiate the remote stack viewer from a separate thread.
|
| 640 |
+
|
| 641 |
+
This method is called from the subprocess, and by returning from this
|
| 642 |
+
method we allow the subprocess to unblock. After a bit the shell
|
| 643 |
+
requests the subprocess to open the remote stack viewer which returns a
|
| 644 |
+
static object looking at the last exception. It is queried through
|
| 645 |
+
the RPC mechanism.
|
| 646 |
+
|
| 647 |
+
"""
|
| 648 |
+
self.tkconsole.text.after(300, self.remote_stack_viewer)
|
| 649 |
+
return
|
| 650 |
+
|
| 651 |
+
def remote_stack_viewer(self):
|
| 652 |
+
from idlelib import debugobj_r
|
| 653 |
+
oid = self.rpcclt.remotequeue("exec", "stackviewer", ("flist",), {})
|
| 654 |
+
if oid is None:
|
| 655 |
+
self.tkconsole.root.bell()
|
| 656 |
+
return
|
| 657 |
+
item = debugobj_r.StubObjectTreeItem(self.rpcclt, oid)
|
| 658 |
+
from idlelib.tree import ScrolledCanvas, TreeNode
|
| 659 |
+
top = Toplevel(self.tkconsole.root)
|
| 660 |
+
theme = idleConf.CurrentTheme()
|
| 661 |
+
background = idleConf.GetHighlight(theme, 'normal')['background']
|
| 662 |
+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0)
|
| 663 |
+
sc.frame.pack(expand=1, fill="both")
|
| 664 |
+
node = TreeNode(sc.canvas, None, item)
|
| 665 |
+
node.expand()
|
| 666 |
+
# XXX Should GC the remote tree when closing the window
|
| 667 |
+
|
| 668 |
+
gid = 0
|
| 669 |
+
|
| 670 |
+
def execsource(self, source):
|
| 671 |
+
"Like runsource() but assumes complete exec source"
|
| 672 |
+
filename = self.stuffsource(source)
|
| 673 |
+
self.execfile(filename, source)
|
| 674 |
+
|
| 675 |
+
def execfile(self, filename, source=None):
|
| 676 |
+
"Execute an existing file"
|
| 677 |
+
if source is None:
|
| 678 |
+
with tokenize.open(filename) as fp:
|
| 679 |
+
source = fp.read()
|
| 680 |
+
if use_subprocess:
|
| 681 |
+
source = (f"__file__ = r'''{os.path.abspath(filename)}'''\n"
|
| 682 |
+
+ source + "\ndel __file__")
|
| 683 |
+
try:
|
| 684 |
+
code = compile(source, filename, "exec")
|
| 685 |
+
except (OverflowError, SyntaxError):
|
| 686 |
+
self.tkconsole.resetoutput()
|
| 687 |
+
print('*** Error in script or command!\n'
|
| 688 |
+
'Traceback (most recent call last):',
|
| 689 |
+
file=self.tkconsole.stderr)
|
| 690 |
+
InteractiveInterpreter.showsyntaxerror(self, filename)
|
| 691 |
+
self.tkconsole.showprompt()
|
| 692 |
+
else:
|
| 693 |
+
self.runcode(code)
|
| 694 |
+
|
| 695 |
+
def runsource(self, source):
|
| 696 |
+
"Extend base class method: Stuff the source in the line cache first"
|
| 697 |
+
filename = self.stuffsource(source)
|
| 698 |
+
# at the moment, InteractiveInterpreter expects str
|
| 699 |
+
assert isinstance(source, str)
|
| 700 |
+
# InteractiveInterpreter.runsource() calls its runcode() method,
|
| 701 |
+
# which is overridden (see below)
|
| 702 |
+
return InteractiveInterpreter.runsource(self, source, filename)
|
| 703 |
+
|
| 704 |
+
def stuffsource(self, source):
|
| 705 |
+
"Stuff source in the filename cache"
|
| 706 |
+
filename = "<pyshell#%d>" % self.gid
|
| 707 |
+
self.gid = self.gid + 1
|
| 708 |
+
lines = source.split("\n")
|
| 709 |
+
linecache.cache[filename] = len(source)+1, 0, lines, filename
|
| 710 |
+
return filename
|
| 711 |
+
|
| 712 |
+
def prepend_syspath(self, filename):
|
| 713 |
+
"Prepend sys.path with file's directory if not already included"
|
| 714 |
+
self.runcommand("""if 1:
|
| 715 |
+
_filename = %r
|
| 716 |
+
import sys as _sys
|
| 717 |
+
from os.path import dirname as _dirname
|
| 718 |
+
_dir = _dirname(_filename)
|
| 719 |
+
if not _dir in _sys.path:
|
| 720 |
+
_sys.path.insert(0, _dir)
|
| 721 |
+
del _filename, _sys, _dirname, _dir
|
| 722 |
+
\n""" % (filename,))
|
| 723 |
+
|
| 724 |
+
def showsyntaxerror(self, filename=None):
|
| 725 |
+
"""Override Interactive Interpreter method: Use Colorizing
|
| 726 |
+
|
| 727 |
+
Color the offending position instead of printing it and pointing at it
|
| 728 |
+
with a caret.
|
| 729 |
+
|
| 730 |
+
"""
|
| 731 |
+
tkconsole = self.tkconsole
|
| 732 |
+
text = tkconsole.text
|
| 733 |
+
text.tag_remove("ERROR", "1.0", "end")
|
| 734 |
+
type, value, tb = sys.exc_info()
|
| 735 |
+
msg = getattr(value, 'msg', '') or value or "<no detail available>"
|
| 736 |
+
lineno = getattr(value, 'lineno', '') or 1
|
| 737 |
+
offset = getattr(value, 'offset', '') or 0
|
| 738 |
+
if offset == 0:
|
| 739 |
+
lineno += 1 #mark end of offending line
|
| 740 |
+
if lineno == 1:
|
| 741 |
+
pos = "iomark + %d chars" % (offset-1)
|
| 742 |
+
else:
|
| 743 |
+
pos = "iomark linestart + %d lines + %d chars" % \
|
| 744 |
+
(lineno-1, offset-1)
|
| 745 |
+
tkconsole.colorize_syntax_error(text, pos)
|
| 746 |
+
tkconsole.resetoutput()
|
| 747 |
+
self.write("SyntaxError: %s\n" % msg)
|
| 748 |
+
tkconsole.showprompt()
|
| 749 |
+
|
| 750 |
+
def showtraceback(self):
|
| 751 |
+
"Extend base class method to reset output properly"
|
| 752 |
+
self.tkconsole.resetoutput()
|
| 753 |
+
self.checklinecache()
|
| 754 |
+
InteractiveInterpreter.showtraceback(self)
|
| 755 |
+
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
|
| 756 |
+
self.tkconsole.open_stack_viewer()
|
| 757 |
+
|
| 758 |
+
def checklinecache(self):
|
| 759 |
+
c = linecache.cache
|
| 760 |
+
for key in list(c.keys()):
|
| 761 |
+
if key[:1] + key[-1:] != "<>":
|
| 762 |
+
del c[key]
|
| 763 |
+
|
| 764 |
+
def runcommand(self, code):
|
| 765 |
+
"Run the code without invoking the debugger"
|
| 766 |
+
# The code better not raise an exception!
|
| 767 |
+
if self.tkconsole.executing:
|
| 768 |
+
self.display_executing_dialog()
|
| 769 |
+
return 0
|
| 770 |
+
if self.rpcclt:
|
| 771 |
+
self.rpcclt.remotequeue("exec", "runcode", (code,), {})
|
| 772 |
+
else:
|
| 773 |
+
exec(code, self.locals)
|
| 774 |
+
return 1
|
| 775 |
+
|
| 776 |
+
def runcode(self, code):
|
| 777 |
+
"Override base class method"
|
| 778 |
+
if self.tkconsole.executing:
|
| 779 |
+
self.restart_subprocess()
|
| 780 |
+
self.checklinecache()
|
| 781 |
+
debugger = self.debugger
|
| 782 |
+
try:
|
| 783 |
+
self.tkconsole.beginexecuting()
|
| 784 |
+
if not debugger and self.rpcclt is not None:
|
| 785 |
+
self.active_seq = self.rpcclt.asyncqueue("exec", "runcode",
|
| 786 |
+
(code,), {})
|
| 787 |
+
elif debugger:
|
| 788 |
+
debugger.run(code, self.locals)
|
| 789 |
+
else:
|
| 790 |
+
exec(code, self.locals)
|
| 791 |
+
except SystemExit:
|
| 792 |
+
if not self.tkconsole.closing:
|
| 793 |
+
if messagebox.askyesno(
|
| 794 |
+
"Exit?",
|
| 795 |
+
"Do you want to exit altogether?",
|
| 796 |
+
default="yes",
|
| 797 |
+
parent=self.tkconsole.text):
|
| 798 |
+
raise
|
| 799 |
+
else:
|
| 800 |
+
self.showtraceback()
|
| 801 |
+
else:
|
| 802 |
+
raise
|
| 803 |
+
except:
|
| 804 |
+
if use_subprocess:
|
| 805 |
+
print("IDLE internal error in runcode()",
|
| 806 |
+
file=self.tkconsole.stderr)
|
| 807 |
+
self.showtraceback()
|
| 808 |
+
self.tkconsole.endexecuting()
|
| 809 |
+
else:
|
| 810 |
+
if self.tkconsole.canceled:
|
| 811 |
+
self.tkconsole.canceled = False
|
| 812 |
+
print("KeyboardInterrupt", file=self.tkconsole.stderr)
|
| 813 |
+
else:
|
| 814 |
+
self.showtraceback()
|
| 815 |
+
finally:
|
| 816 |
+
if not use_subprocess:
|
| 817 |
+
try:
|
| 818 |
+
self.tkconsole.endexecuting()
|
| 819 |
+
except AttributeError: # shell may have closed
|
| 820 |
+
pass
|
| 821 |
+
|
| 822 |
+
def write(self, s):
|
| 823 |
+
"Override base class method"
|
| 824 |
+
return self.tkconsole.stderr.write(s)
|
| 825 |
+
|
| 826 |
+
def display_port_binding_error(self):
|
| 827 |
+
messagebox.showerror(
|
| 828 |
+
"Port Binding Error",
|
| 829 |
+
"IDLE can't bind to a TCP/IP port, which is necessary to "
|
| 830 |
+
"communicate with its Python execution server. This might be "
|
| 831 |
+
"because no networking is installed on this computer. "
|
| 832 |
+
"Run IDLE with the -n command line switch to start without a "
|
| 833 |
+
"subprocess and refer to Help/IDLE Help 'Running without a "
|
| 834 |
+
"subprocess' for further details.",
|
| 835 |
+
parent=self.tkconsole.text)
|
| 836 |
+
|
| 837 |
+
def display_no_subprocess_error(self):
|
| 838 |
+
messagebox.showerror(
|
| 839 |
+
"Subprocess Connection Error",
|
| 840 |
+
"IDLE's subprocess didn't make connection.\n"
|
| 841 |
+
"See the 'Startup failure' section of the IDLE doc, online at\n"
|
| 842 |
+
"https://docs.python.org/3/library/idle.html#startup-failure",
|
| 843 |
+
parent=self.tkconsole.text)
|
| 844 |
+
|
| 845 |
+
def display_executing_dialog(self):
|
| 846 |
+
messagebox.showerror(
|
| 847 |
+
"Already executing",
|
| 848 |
+
"The Python Shell window is already executing a command; "
|
| 849 |
+
"please wait until it is finished.",
|
| 850 |
+
parent=self.tkconsole.text)
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
class PyShell(OutputWindow):
|
| 854 |
+
from idlelib.squeezer import Squeezer
|
| 855 |
+
|
| 856 |
+
shell_title = "IDLE Shell " + python_version()
|
| 857 |
+
|
| 858 |
+
# Override classes
|
| 859 |
+
ColorDelegator = ModifiedColorDelegator
|
| 860 |
+
UndoDelegator = ModifiedUndoDelegator
|
| 861 |
+
|
| 862 |
+
# Override menus
|
| 863 |
+
menu_specs = [
|
| 864 |
+
("file", "_File"),
|
| 865 |
+
("edit", "_Edit"),
|
| 866 |
+
("debug", "_Debug"),
|
| 867 |
+
("options", "_Options"),
|
| 868 |
+
("window", "_Window"),
|
| 869 |
+
("help", "_Help"),
|
| 870 |
+
]
|
| 871 |
+
|
| 872 |
+
# Extend right-click context menu
|
| 873 |
+
rmenu_specs = OutputWindow.rmenu_specs + [
|
| 874 |
+
("Squeeze", "<<squeeze-current-text>>"),
|
| 875 |
+
]
|
| 876 |
+
_idx = 1 + len(list(itertools.takewhile(
|
| 877 |
+
lambda rmenu_item: rmenu_item[0] != "Copy", rmenu_specs)
|
| 878 |
+
))
|
| 879 |
+
rmenu_specs.insert(_idx, ("Copy with prompts",
|
| 880 |
+
"<<copy-with-prompts>>",
|
| 881 |
+
"rmenu_check_copy"))
|
| 882 |
+
del _idx
|
| 883 |
+
|
| 884 |
+
allow_line_numbers = False
|
| 885 |
+
user_input_insert_tags = "stdin"
|
| 886 |
+
|
| 887 |
+
# New classes
|
| 888 |
+
from idlelib.history import History
|
| 889 |
+
from idlelib.sidebar import ShellSidebar
|
| 890 |
+
|
| 891 |
+
def __init__(self, flist=None):
|
| 892 |
+
if use_subprocess:
|
| 893 |
+
ms = self.menu_specs
|
| 894 |
+
if ms[2][0] != "shell":
|
| 895 |
+
ms.insert(2, ("shell", "She_ll"))
|
| 896 |
+
self.interp = ModifiedInterpreter(self)
|
| 897 |
+
if flist is None:
|
| 898 |
+
root = Tk()
|
| 899 |
+
fixwordbreaks(root)
|
| 900 |
+
root.withdraw()
|
| 901 |
+
flist = PyShellFileList(root)
|
| 902 |
+
|
| 903 |
+
self.shell_sidebar = None # initialized below
|
| 904 |
+
|
| 905 |
+
OutputWindow.__init__(self, flist, None, None)
|
| 906 |
+
|
| 907 |
+
self.usetabs = False
|
| 908 |
+
# indentwidth must be 8 when using tabs. See note in EditorWindow:
|
| 909 |
+
self.indentwidth = 4
|
| 910 |
+
|
| 911 |
+
self.sys_ps1 = sys.ps1 if hasattr(sys, 'ps1') else '>>>\n'
|
| 912 |
+
self.prompt_last_line = self.sys_ps1.split('\n')[-1]
|
| 913 |
+
self.prompt = self.sys_ps1 # Changes when debug active
|
| 914 |
+
|
| 915 |
+
text = self.text
|
| 916 |
+
text.configure(wrap="char")
|
| 917 |
+
text.bind("<<newline-and-indent>>", self.enter_callback)
|
| 918 |
+
text.bind("<<plain-newline-and-indent>>", self.linefeed_callback)
|
| 919 |
+
text.bind("<<interrupt-execution>>", self.cancel_callback)
|
| 920 |
+
text.bind("<<end-of-file>>", self.eof_callback)
|
| 921 |
+
text.bind("<<open-stack-viewer>>", self.open_stack_viewer)
|
| 922 |
+
text.bind("<<toggle-debugger>>", self.toggle_debugger)
|
| 923 |
+
text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer)
|
| 924 |
+
text.bind("<<copy-with-prompts>>", self.copy_with_prompts_callback)
|
| 925 |
+
if use_subprocess:
|
| 926 |
+
text.bind("<<view-restart>>", self.view_restart_mark)
|
| 927 |
+
text.bind("<<restart-shell>>", self.restart_shell)
|
| 928 |
+
self.squeezer = self.Squeezer(self)
|
| 929 |
+
text.bind("<<squeeze-current-text>>",
|
| 930 |
+
self.squeeze_current_text_event)
|
| 931 |
+
|
| 932 |
+
self.save_stdout = sys.stdout
|
| 933 |
+
self.save_stderr = sys.stderr
|
| 934 |
+
self.save_stdin = sys.stdin
|
| 935 |
+
from idlelib import iomenu
|
| 936 |
+
self.stdin = StdInputFile(self, "stdin",
|
| 937 |
+
iomenu.encoding, iomenu.errors)
|
| 938 |
+
self.stdout = StdOutputFile(self, "stdout",
|
| 939 |
+
iomenu.encoding, iomenu.errors)
|
| 940 |
+
self.stderr = StdOutputFile(self, "stderr",
|
| 941 |
+
iomenu.encoding, "backslashreplace")
|
| 942 |
+
self.console = StdOutputFile(self, "console",
|
| 943 |
+
iomenu.encoding, iomenu.errors)
|
| 944 |
+
if not use_subprocess:
|
| 945 |
+
sys.stdout = self.stdout
|
| 946 |
+
sys.stderr = self.stderr
|
| 947 |
+
sys.stdin = self.stdin
|
| 948 |
+
try:
|
| 949 |
+
# page help() text to shell.
|
| 950 |
+
import pydoc # import must be done here to capture i/o rebinding.
|
| 951 |
+
# XXX KBK 27Dec07 use text viewer someday, but must work w/o subproc
|
| 952 |
+
pydoc.pager = pydoc.plainpager
|
| 953 |
+
except:
|
| 954 |
+
sys.stderr = sys.__stderr__
|
| 955 |
+
raise
|
| 956 |
+
#
|
| 957 |
+
self.history = self.History(self.text)
|
| 958 |
+
#
|
| 959 |
+
self.pollinterval = 50 # millisec
|
| 960 |
+
|
| 961 |
+
self.shell_sidebar = self.ShellSidebar(self)
|
| 962 |
+
|
| 963 |
+
# Insert UserInputTaggingDelegator at the top of the percolator,
|
| 964 |
+
# but make calls to text.insert() skip it. This causes only insert
|
| 965 |
+
# events generated in Tcl/Tk to go through this delegator.
|
| 966 |
+
self.text.insert = self.per.top.insert
|
| 967 |
+
self.per.insertfilter(UserInputTaggingDelegator())
|
| 968 |
+
|
| 969 |
+
def ResetFont(self):
|
| 970 |
+
super().ResetFont()
|
| 971 |
+
|
| 972 |
+
if self.shell_sidebar is not None:
|
| 973 |
+
self.shell_sidebar.update_font()
|
| 974 |
+
|
| 975 |
+
def ResetColorizer(self):
|
| 976 |
+
super().ResetColorizer()
|
| 977 |
+
|
| 978 |
+
theme = idleConf.CurrentTheme()
|
| 979 |
+
tag_colors = {
|
| 980 |
+
"stdin": {'background': None, 'foreground': None},
|
| 981 |
+
"stdout": idleConf.GetHighlight(theme, "stdout"),
|
| 982 |
+
"stderr": idleConf.GetHighlight(theme, "stderr"),
|
| 983 |
+
"console": idleConf.GetHighlight(theme, "normal"),
|
| 984 |
+
}
|
| 985 |
+
for tag, tag_colors_config in tag_colors.items():
|
| 986 |
+
self.text.tag_configure(tag, **tag_colors_config)
|
| 987 |
+
|
| 988 |
+
if self.shell_sidebar is not None:
|
| 989 |
+
self.shell_sidebar.update_colors()
|
| 990 |
+
|
| 991 |
+
def replace_event(self, event):
|
| 992 |
+
replace.replace(self.text, insert_tags="stdin")
|
| 993 |
+
return "break"
|
| 994 |
+
|
| 995 |
+
def get_standard_extension_names(self):
|
| 996 |
+
return idleConf.GetExtensions(shell_only=True)
|
| 997 |
+
|
| 998 |
+
def get_prompt_text(self, first, last):
|
| 999 |
+
"""Return text between first and last with prompts added."""
|
| 1000 |
+
text = self.text.get(first, last)
|
| 1001 |
+
lineno_range = range(
|
| 1002 |
+
int(float(first)),
|
| 1003 |
+
int(float(last))
|
| 1004 |
+
)
|
| 1005 |
+
prompts = [
|
| 1006 |
+
self.shell_sidebar.line_prompts.get(lineno)
|
| 1007 |
+
for lineno in lineno_range
|
| 1008 |
+
]
|
| 1009 |
+
return "\n".join(
|
| 1010 |
+
line if prompt is None else f"{prompt} {line}"
|
| 1011 |
+
for prompt, line in zip(prompts, text.splitlines())
|
| 1012 |
+
) + "\n"
|
| 1013 |
+
|
| 1014 |
+
|
| 1015 |
+
def copy_with_prompts_callback(self, event=None):
|
| 1016 |
+
"""Copy selected lines to the clipboard, with prompts.
|
| 1017 |
+
|
| 1018 |
+
This makes the copied text useful for doc-tests and interactive
|
| 1019 |
+
shell code examples.
|
| 1020 |
+
|
| 1021 |
+
This always copies entire lines, even if only part of the first
|
| 1022 |
+
and/or last lines is selected.
|
| 1023 |
+
"""
|
| 1024 |
+
text = self.text
|
| 1025 |
+
selfirst = text.index('sel.first linestart')
|
| 1026 |
+
if selfirst is None: # Should not be possible.
|
| 1027 |
+
return # No selection, do nothing.
|
| 1028 |
+
sellast = text.index('sel.last')
|
| 1029 |
+
if sellast[-1] != '0':
|
| 1030 |
+
sellast = text.index("sel.last+1line linestart")
|
| 1031 |
+
text.clipboard_clear()
|
| 1032 |
+
prompt_text = self.get_prompt_text(selfirst, sellast)
|
| 1033 |
+
text.clipboard_append(prompt_text)
|
| 1034 |
+
|
| 1035 |
+
reading = False
|
| 1036 |
+
executing = False
|
| 1037 |
+
canceled = False
|
| 1038 |
+
endoffile = False
|
| 1039 |
+
closing = False
|
| 1040 |
+
_stop_readline_flag = False
|
| 1041 |
+
|
| 1042 |
+
def set_warning_stream(self, stream):
|
| 1043 |
+
global warning_stream
|
| 1044 |
+
warning_stream = stream
|
| 1045 |
+
|
| 1046 |
+
def get_warning_stream(self):
|
| 1047 |
+
return warning_stream
|
| 1048 |
+
|
| 1049 |
+
def toggle_debugger(self, event=None):
|
| 1050 |
+
if self.executing:
|
| 1051 |
+
messagebox.showerror("Don't debug now",
|
| 1052 |
+
"You can only toggle the debugger when idle",
|
| 1053 |
+
parent=self.text)
|
| 1054 |
+
self.set_debugger_indicator()
|
| 1055 |
+
return "break"
|
| 1056 |
+
else:
|
| 1057 |
+
db = self.interp.getdebugger()
|
| 1058 |
+
if db:
|
| 1059 |
+
self.close_debugger()
|
| 1060 |
+
else:
|
| 1061 |
+
self.open_debugger()
|
| 1062 |
+
|
| 1063 |
+
def set_debugger_indicator(self):
|
| 1064 |
+
db = self.interp.getdebugger()
|
| 1065 |
+
self.setvar("<<toggle-debugger>>", not not db)
|
| 1066 |
+
|
| 1067 |
+
def toggle_jit_stack_viewer(self, event=None):
|
| 1068 |
+
pass # All we need is the variable
|
| 1069 |
+
|
| 1070 |
+
def close_debugger(self):
|
| 1071 |
+
db = self.interp.getdebugger()
|
| 1072 |
+
if db:
|
| 1073 |
+
self.interp.setdebugger(None)
|
| 1074 |
+
db.close()
|
| 1075 |
+
if self.interp.rpcclt:
|
| 1076 |
+
debugger_r.close_remote_debugger(self.interp.rpcclt)
|
| 1077 |
+
self.resetoutput()
|
| 1078 |
+
self.console.write("[DEBUG OFF]\n")
|
| 1079 |
+
self.prompt = self.sys_ps1
|
| 1080 |
+
self.showprompt()
|
| 1081 |
+
self.set_debugger_indicator()
|
| 1082 |
+
|
| 1083 |
+
def open_debugger(self):
|
| 1084 |
+
if self.interp.rpcclt:
|
| 1085 |
+
dbg_gui = debugger_r.start_remote_debugger(self.interp.rpcclt,
|
| 1086 |
+
self)
|
| 1087 |
+
else:
|
| 1088 |
+
dbg_gui = debugger.Debugger(self)
|
| 1089 |
+
self.interp.setdebugger(dbg_gui)
|
| 1090 |
+
dbg_gui.load_breakpoints()
|
| 1091 |
+
self.prompt = "[DEBUG ON]\n" + self.sys_ps1
|
| 1092 |
+
self.showprompt()
|
| 1093 |
+
self.set_debugger_indicator()
|
| 1094 |
+
|
| 1095 |
+
def debug_menu_postcommand(self):
|
| 1096 |
+
state = 'disabled' if self.executing else 'normal'
|
| 1097 |
+
self.update_menu_state('debug', '*tack*iewer', state)
|
| 1098 |
+
|
| 1099 |
+
def beginexecuting(self):
|
| 1100 |
+
"Helper for ModifiedInterpreter"
|
| 1101 |
+
self.resetoutput()
|
| 1102 |
+
self.executing = True
|
| 1103 |
+
|
| 1104 |
+
def endexecuting(self):
|
| 1105 |
+
"Helper for ModifiedInterpreter"
|
| 1106 |
+
self.executing = False
|
| 1107 |
+
self.canceled = False
|
| 1108 |
+
self.showprompt()
|
| 1109 |
+
|
| 1110 |
+
def close(self):
|
| 1111 |
+
"Extend EditorWindow.close()"
|
| 1112 |
+
if self.executing:
|
| 1113 |
+
response = messagebox.askokcancel(
|
| 1114 |
+
"Kill?",
|
| 1115 |
+
"Your program is still running!\n Do you want to kill it?",
|
| 1116 |
+
default="ok",
|
| 1117 |
+
parent=self.text)
|
| 1118 |
+
if response is False:
|
| 1119 |
+
return "cancel"
|
| 1120 |
+
self.stop_readline()
|
| 1121 |
+
self.canceled = True
|
| 1122 |
+
self.closing = True
|
| 1123 |
+
return EditorWindow.close(self)
|
| 1124 |
+
|
| 1125 |
+
def _close(self):
|
| 1126 |
+
"Extend EditorWindow._close(), shut down debugger and execution server"
|
| 1127 |
+
self.close_debugger()
|
| 1128 |
+
if use_subprocess:
|
| 1129 |
+
self.interp.kill_subprocess()
|
| 1130 |
+
# Restore std streams
|
| 1131 |
+
sys.stdout = self.save_stdout
|
| 1132 |
+
sys.stderr = self.save_stderr
|
| 1133 |
+
sys.stdin = self.save_stdin
|
| 1134 |
+
# Break cycles
|
| 1135 |
+
self.interp = None
|
| 1136 |
+
self.console = None
|
| 1137 |
+
self.flist.pyshell = None
|
| 1138 |
+
self.history = None
|
| 1139 |
+
EditorWindow._close(self)
|
| 1140 |
+
|
| 1141 |
+
def ispythonsource(self, filename):
|
| 1142 |
+
"Override EditorWindow method: never remove the colorizer"
|
| 1143 |
+
return True
|
| 1144 |
+
|
| 1145 |
+
def short_title(self):
|
| 1146 |
+
return self.shell_title
|
| 1147 |
+
|
| 1148 |
+
COPYRIGHT = \
|
| 1149 |
+
'Type "help", "copyright", "credits" or "license()" for more information.'
|
| 1150 |
+
|
| 1151 |
+
def begin(self):
|
| 1152 |
+
self.text.mark_set("iomark", "insert")
|
| 1153 |
+
self.resetoutput()
|
| 1154 |
+
if use_subprocess:
|
| 1155 |
+
nosub = ''
|
| 1156 |
+
client = self.interp.start_subprocess()
|
| 1157 |
+
if not client:
|
| 1158 |
+
self.close()
|
| 1159 |
+
return False
|
| 1160 |
+
else:
|
| 1161 |
+
nosub = ("==== No Subprocess ====\n\n" +
|
| 1162 |
+
"WARNING: Running IDLE without a Subprocess is deprecated\n" +
|
| 1163 |
+
"and will be removed in a later version. See Help/IDLE Help\n" +
|
| 1164 |
+
"for details.\n\n")
|
| 1165 |
+
sys.displayhook = rpc.displayhook
|
| 1166 |
+
|
| 1167 |
+
self.write("Python %s on %s\n%s\n%s" %
|
| 1168 |
+
(sys.version, sys.platform, self.COPYRIGHT, nosub))
|
| 1169 |
+
self.text.focus_force()
|
| 1170 |
+
self.showprompt()
|
| 1171 |
+
# User code should use separate default Tk root window
|
| 1172 |
+
import tkinter
|
| 1173 |
+
tkinter._support_default_root = True
|
| 1174 |
+
tkinter._default_root = None
|
| 1175 |
+
return True
|
| 1176 |
+
|
| 1177 |
+
def stop_readline(self):
|
| 1178 |
+
if not self.reading: # no nested mainloop to exit.
|
| 1179 |
+
return
|
| 1180 |
+
self._stop_readline_flag = True
|
| 1181 |
+
self.top.quit()
|
| 1182 |
+
|
| 1183 |
+
def readline(self):
|
| 1184 |
+
save = self.reading
|
| 1185 |
+
try:
|
| 1186 |
+
self.reading = True
|
| 1187 |
+
self.top.mainloop() # nested mainloop()
|
| 1188 |
+
finally:
|
| 1189 |
+
self.reading = save
|
| 1190 |
+
if self._stop_readline_flag:
|
| 1191 |
+
self._stop_readline_flag = False
|
| 1192 |
+
return ""
|
| 1193 |
+
line = self.text.get("iomark", "end-1c")
|
| 1194 |
+
if len(line) == 0: # may be EOF if we quit our mainloop with Ctrl-C
|
| 1195 |
+
line = "\n"
|
| 1196 |
+
self.resetoutput()
|
| 1197 |
+
if self.canceled:
|
| 1198 |
+
self.canceled = False
|
| 1199 |
+
if not use_subprocess:
|
| 1200 |
+
raise KeyboardInterrupt
|
| 1201 |
+
if self.endoffile:
|
| 1202 |
+
self.endoffile = False
|
| 1203 |
+
line = ""
|
| 1204 |
+
return line
|
| 1205 |
+
|
| 1206 |
+
def isatty(self):
|
| 1207 |
+
return True
|
| 1208 |
+
|
| 1209 |
+
def cancel_callback(self, event=None):
|
| 1210 |
+
try:
|
| 1211 |
+
if self.text.compare("sel.first", "!=", "sel.last"):
|
| 1212 |
+
return # Active selection -- always use default binding
|
| 1213 |
+
except:
|
| 1214 |
+
pass
|
| 1215 |
+
if not (self.executing or self.reading):
|
| 1216 |
+
self.resetoutput()
|
| 1217 |
+
self.interp.write("KeyboardInterrupt\n")
|
| 1218 |
+
self.showprompt()
|
| 1219 |
+
return "break"
|
| 1220 |
+
self.endoffile = False
|
| 1221 |
+
self.canceled = True
|
| 1222 |
+
if (self.executing and self.interp.rpcclt):
|
| 1223 |
+
if self.interp.getdebugger():
|
| 1224 |
+
self.interp.restart_subprocess()
|
| 1225 |
+
else:
|
| 1226 |
+
self.interp.interrupt_subprocess()
|
| 1227 |
+
if self.reading:
|
| 1228 |
+
self.top.quit() # exit the nested mainloop() in readline()
|
| 1229 |
+
return "break"
|
| 1230 |
+
|
| 1231 |
+
def eof_callback(self, event):
|
| 1232 |
+
if self.executing and not self.reading:
|
| 1233 |
+
return # Let the default binding (delete next char) take over
|
| 1234 |
+
if not (self.text.compare("iomark", "==", "insert") and
|
| 1235 |
+
self.text.compare("insert", "==", "end-1c")):
|
| 1236 |
+
return # Let the default binding (delete next char) take over
|
| 1237 |
+
if not self.executing:
|
| 1238 |
+
self.resetoutput()
|
| 1239 |
+
self.close()
|
| 1240 |
+
else:
|
| 1241 |
+
self.canceled = False
|
| 1242 |
+
self.endoffile = True
|
| 1243 |
+
self.top.quit()
|
| 1244 |
+
return "break"
|
| 1245 |
+
|
| 1246 |
+
def linefeed_callback(self, event):
|
| 1247 |
+
# Insert a linefeed without entering anything (still autoindented)
|
| 1248 |
+
if self.reading:
|
| 1249 |
+
self.text.insert("insert", "\n")
|
| 1250 |
+
self.text.see("insert")
|
| 1251 |
+
else:
|
| 1252 |
+
self.newline_and_indent_event(event)
|
| 1253 |
+
return "break"
|
| 1254 |
+
|
| 1255 |
+
def enter_callback(self, event):
|
| 1256 |
+
if self.executing and not self.reading:
|
| 1257 |
+
return # Let the default binding (insert '\n') take over
|
| 1258 |
+
# If some text is selected, recall the selection
|
| 1259 |
+
# (but only if this before the I/O mark)
|
| 1260 |
+
try:
|
| 1261 |
+
sel = self.text.get("sel.first", "sel.last")
|
| 1262 |
+
if sel:
|
| 1263 |
+
if self.text.compare("sel.last", "<=", "iomark"):
|
| 1264 |
+
self.recall(sel, event)
|
| 1265 |
+
return "break"
|
| 1266 |
+
except:
|
| 1267 |
+
pass
|
| 1268 |
+
# If we're strictly before the line containing iomark, recall
|
| 1269 |
+
# the current line, less a leading prompt, less leading or
|
| 1270 |
+
# trailing whitespace
|
| 1271 |
+
if self.text.compare("insert", "<", "iomark linestart"):
|
| 1272 |
+
# Check if there's a relevant stdin range -- if so, use it.
|
| 1273 |
+
# Note: "stdin" blocks may include several successive statements,
|
| 1274 |
+
# so look for "console" tags on the newline before each statement
|
| 1275 |
+
# (and possibly on prompts).
|
| 1276 |
+
prev = self.text.tag_prevrange("stdin", "insert")
|
| 1277 |
+
if (
|
| 1278 |
+
prev and
|
| 1279 |
+
self.text.compare("insert", "<", prev[1]) and
|
| 1280 |
+
# The following is needed to handle empty statements.
|
| 1281 |
+
"console" not in self.text.tag_names("insert")
|
| 1282 |
+
):
|
| 1283 |
+
prev_cons = self.text.tag_prevrange("console", "insert")
|
| 1284 |
+
if prev_cons and self.text.compare(prev_cons[1], ">=", prev[0]):
|
| 1285 |
+
prev = (prev_cons[1], prev[1])
|
| 1286 |
+
next_cons = self.text.tag_nextrange("console", "insert")
|
| 1287 |
+
if next_cons and self.text.compare(next_cons[0], "<", prev[1]):
|
| 1288 |
+
prev = (prev[0], self.text.index(next_cons[0] + "+1c"))
|
| 1289 |
+
self.recall(self.text.get(prev[0], prev[1]), event)
|
| 1290 |
+
return "break"
|
| 1291 |
+
next = self.text.tag_nextrange("stdin", "insert")
|
| 1292 |
+
if next and self.text.compare("insert lineend", ">=", next[0]):
|
| 1293 |
+
next_cons = self.text.tag_nextrange("console", "insert lineend")
|
| 1294 |
+
if next_cons and self.text.compare(next_cons[0], "<", next[1]):
|
| 1295 |
+
next = (next[0], self.text.index(next_cons[0] + "+1c"))
|
| 1296 |
+
self.recall(self.text.get(next[0], next[1]), event)
|
| 1297 |
+
return "break"
|
| 1298 |
+
# No stdin mark -- just get the current line, less any prompt
|
| 1299 |
+
indices = self.text.tag_nextrange("console", "insert linestart")
|
| 1300 |
+
if indices and \
|
| 1301 |
+
self.text.compare(indices[0], "<=", "insert linestart"):
|
| 1302 |
+
self.recall(self.text.get(indices[1], "insert lineend"), event)
|
| 1303 |
+
else:
|
| 1304 |
+
self.recall(self.text.get("insert linestart", "insert lineend"), event)
|
| 1305 |
+
return "break"
|
| 1306 |
+
# If we're between the beginning of the line and the iomark, i.e.
|
| 1307 |
+
# in the prompt area, move to the end of the prompt
|
| 1308 |
+
if self.text.compare("insert", "<", "iomark"):
|
| 1309 |
+
self.text.mark_set("insert", "iomark")
|
| 1310 |
+
# If we're in the current input and there's only whitespace
|
| 1311 |
+
# beyond the cursor, erase that whitespace first
|
| 1312 |
+
s = self.text.get("insert", "end-1c")
|
| 1313 |
+
if s and not s.strip():
|
| 1314 |
+
self.text.delete("insert", "end-1c")
|
| 1315 |
+
# If we're in the current input before its last line,
|
| 1316 |
+
# insert a newline right at the insert point
|
| 1317 |
+
if self.text.compare("insert", "<", "end-1c linestart"):
|
| 1318 |
+
self.newline_and_indent_event(event)
|
| 1319 |
+
return "break"
|
| 1320 |
+
# We're in the last line; append a newline and submit it
|
| 1321 |
+
self.text.mark_set("insert", "end-1c")
|
| 1322 |
+
if self.reading:
|
| 1323 |
+
self.text.insert("insert", "\n")
|
| 1324 |
+
self.text.see("insert")
|
| 1325 |
+
else:
|
| 1326 |
+
self.newline_and_indent_event(event)
|
| 1327 |
+
self.text.update_idletasks()
|
| 1328 |
+
if self.reading:
|
| 1329 |
+
self.top.quit() # Break out of recursive mainloop()
|
| 1330 |
+
else:
|
| 1331 |
+
self.runit()
|
| 1332 |
+
return "break"
|
| 1333 |
+
|
| 1334 |
+
def recall(self, s, event):
|
| 1335 |
+
# remove leading and trailing empty or whitespace lines
|
| 1336 |
+
s = re.sub(r'^\s*\n', '', s)
|
| 1337 |
+
s = re.sub(r'\n\s*$', '', s)
|
| 1338 |
+
lines = s.split('\n')
|
| 1339 |
+
self.text.undo_block_start()
|
| 1340 |
+
try:
|
| 1341 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 1342 |
+
self.text.mark_set("insert", "end-1c")
|
| 1343 |
+
prefix = self.text.get("insert linestart", "insert")
|
| 1344 |
+
if prefix.rstrip().endswith(':'):
|
| 1345 |
+
self.newline_and_indent_event(event)
|
| 1346 |
+
prefix = self.text.get("insert linestart", "insert")
|
| 1347 |
+
self.text.insert("insert", lines[0].strip(),
|
| 1348 |
+
self.user_input_insert_tags)
|
| 1349 |
+
if len(lines) > 1:
|
| 1350 |
+
orig_base_indent = re.search(r'^([ \t]*)', lines[0]).group(0)
|
| 1351 |
+
new_base_indent = re.search(r'^([ \t]*)', prefix).group(0)
|
| 1352 |
+
for line in lines[1:]:
|
| 1353 |
+
if line.startswith(orig_base_indent):
|
| 1354 |
+
# replace orig base indentation with new indentation
|
| 1355 |
+
line = new_base_indent + line[len(orig_base_indent):]
|
| 1356 |
+
self.text.insert('insert', '\n' + line.rstrip(),
|
| 1357 |
+
self.user_input_insert_tags)
|
| 1358 |
+
finally:
|
| 1359 |
+
self.text.see("insert")
|
| 1360 |
+
self.text.undo_block_stop()
|
| 1361 |
+
|
| 1362 |
+
_last_newline_re = re.compile(r"[ \t]*(\n[ \t]*)?\Z")
|
| 1363 |
+
def runit(self):
|
| 1364 |
+
index_before = self.text.index("end-2c")
|
| 1365 |
+
line = self.text.get("iomark", "end-1c")
|
| 1366 |
+
# Strip off last newline and surrounding whitespace.
|
| 1367 |
+
# (To allow you to hit return twice to end a statement.)
|
| 1368 |
+
line = self._last_newline_re.sub("", line)
|
| 1369 |
+
input_is_complete = self.interp.runsource(line)
|
| 1370 |
+
if not input_is_complete:
|
| 1371 |
+
if self.text.get(index_before) == '\n':
|
| 1372 |
+
self.text.tag_remove(self.user_input_insert_tags, index_before)
|
| 1373 |
+
self.shell_sidebar.update_sidebar()
|
| 1374 |
+
|
| 1375 |
+
def open_stack_viewer(self, event=None):
|
| 1376 |
+
if self.interp.rpcclt:
|
| 1377 |
+
return self.interp.remote_stack_viewer()
|
| 1378 |
+
try:
|
| 1379 |
+
sys.last_traceback
|
| 1380 |
+
except:
|
| 1381 |
+
messagebox.showerror("No stack trace",
|
| 1382 |
+
"There is no stack trace yet.\n"
|
| 1383 |
+
"(sys.last_traceback is not defined)",
|
| 1384 |
+
parent=self.text)
|
| 1385 |
+
return
|
| 1386 |
+
from idlelib.stackviewer import StackBrowser
|
| 1387 |
+
StackBrowser(self.root, self.flist)
|
| 1388 |
+
|
| 1389 |
+
def view_restart_mark(self, event=None):
|
| 1390 |
+
self.text.see("iomark")
|
| 1391 |
+
self.text.see("restart")
|
| 1392 |
+
|
| 1393 |
+
def restart_shell(self, event=None):
|
| 1394 |
+
"Callback for Run/Restart Shell Cntl-F6"
|
| 1395 |
+
self.interp.restart_subprocess(with_cwd=True)
|
| 1396 |
+
|
| 1397 |
+
def showprompt(self):
|
| 1398 |
+
self.resetoutput()
|
| 1399 |
+
|
| 1400 |
+
prompt = self.prompt
|
| 1401 |
+
if self.sys_ps1 and prompt.endswith(self.sys_ps1):
|
| 1402 |
+
prompt = prompt[:-len(self.sys_ps1)]
|
| 1403 |
+
self.text.tag_add("console", "iomark-1c")
|
| 1404 |
+
self.console.write(prompt)
|
| 1405 |
+
|
| 1406 |
+
self.shell_sidebar.update_sidebar()
|
| 1407 |
+
self.text.mark_set("insert", "end-1c")
|
| 1408 |
+
self.set_line_and_column()
|
| 1409 |
+
self.io.reset_undo()
|
| 1410 |
+
|
| 1411 |
+
def show_warning(self, msg):
|
| 1412 |
+
width = self.interp.tkconsole.width
|
| 1413 |
+
wrapper = TextWrapper(width=width, tabsize=8, expand_tabs=True)
|
| 1414 |
+
wrapped_msg = '\n'.join(wrapper.wrap(msg))
|
| 1415 |
+
if not wrapped_msg.endswith('\n'):
|
| 1416 |
+
wrapped_msg += '\n'
|
| 1417 |
+
self.per.bottom.insert("iomark linestart", wrapped_msg, "stderr")
|
| 1418 |
+
|
| 1419 |
+
def resetoutput(self):
|
| 1420 |
+
source = self.text.get("iomark", "end-1c")
|
| 1421 |
+
if self.history:
|
| 1422 |
+
self.history.store(source)
|
| 1423 |
+
if self.text.get("end-2c") != "\n":
|
| 1424 |
+
self.text.insert("end-1c", "\n")
|
| 1425 |
+
self.text.mark_set("iomark", "end-1c")
|
| 1426 |
+
self.set_line_and_column()
|
| 1427 |
+
self.ctip.remove_calltip_window()
|
| 1428 |
+
|
| 1429 |
+
def write(self, s, tags=()):
|
| 1430 |
+
try:
|
| 1431 |
+
self.text.mark_gravity("iomark", "right")
|
| 1432 |
+
count = OutputWindow.write(self, s, tags, "iomark")
|
| 1433 |
+
self.text.mark_gravity("iomark", "left")
|
| 1434 |
+
except:
|
| 1435 |
+
raise ###pass # ### 11Aug07 KBK if we are expecting exceptions
|
| 1436 |
+
# let's find out what they are and be specific.
|
| 1437 |
+
if self.canceled:
|
| 1438 |
+
self.canceled = False
|
| 1439 |
+
if not use_subprocess:
|
| 1440 |
+
raise KeyboardInterrupt
|
| 1441 |
+
return count
|
| 1442 |
+
|
| 1443 |
+
def rmenu_check_cut(self):
|
| 1444 |
+
try:
|
| 1445 |
+
if self.text.compare('sel.first', '<', 'iomark'):
|
| 1446 |
+
return 'disabled'
|
| 1447 |
+
except TclError: # no selection, so the index 'sel.first' doesn't exist
|
| 1448 |
+
return 'disabled'
|
| 1449 |
+
return super().rmenu_check_cut()
|
| 1450 |
+
|
| 1451 |
+
def rmenu_check_paste(self):
|
| 1452 |
+
if self.text.compare('insert','<','iomark'):
|
| 1453 |
+
return 'disabled'
|
| 1454 |
+
return super().rmenu_check_paste()
|
| 1455 |
+
|
| 1456 |
+
def squeeze_current_text_event(self, event=None):
|
| 1457 |
+
self.squeezer.squeeze_current_text()
|
| 1458 |
+
self.shell_sidebar.update_sidebar()
|
| 1459 |
+
|
| 1460 |
+
def on_squeezed_expand(self, index, text, tags):
|
| 1461 |
+
self.shell_sidebar.update_sidebar()
|
| 1462 |
+
|
| 1463 |
+
|
| 1464 |
+
def fix_x11_paste(root):
|
| 1465 |
+
"Make paste replace selection on x11. See issue #5124."
|
| 1466 |
+
if root._windowingsystem == 'x11':
|
| 1467 |
+
for cls in 'Text', 'Entry', 'Spinbox':
|
| 1468 |
+
root.bind_class(
|
| 1469 |
+
cls,
|
| 1470 |
+
'<<Paste>>',
|
| 1471 |
+
'catch {%W delete sel.first sel.last}\n' +
|
| 1472 |
+
root.bind_class(cls, '<<Paste>>'))
|
| 1473 |
+
|
| 1474 |
+
|
| 1475 |
+
usage_msg = """\
|
| 1476 |
+
|
| 1477 |
+
USAGE: idle [-deins] [-t title] [file]*
|
| 1478 |
+
idle [-dns] [-t title] (-c cmd | -r file) [arg]*
|
| 1479 |
+
idle [-dns] [-t title] - [arg]*
|
| 1480 |
+
|
| 1481 |
+
-h print this help message and exit
|
| 1482 |
+
-n run IDLE without a subprocess (DEPRECATED,
|
| 1483 |
+
see Help/IDLE Help for details)
|
| 1484 |
+
|
| 1485 |
+
The following options will override the IDLE 'settings' configuration:
|
| 1486 |
+
|
| 1487 |
+
-e open an edit window
|
| 1488 |
+
-i open a shell window
|
| 1489 |
+
|
| 1490 |
+
The following options imply -i and will open a shell:
|
| 1491 |
+
|
| 1492 |
+
-c cmd run the command in a shell, or
|
| 1493 |
+
-r file run script from file
|
| 1494 |
+
|
| 1495 |
+
-d enable the debugger
|
| 1496 |
+
-s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
|
| 1497 |
+
-t title set title of shell window
|
| 1498 |
+
|
| 1499 |
+
A default edit window will be bypassed when -c, -r, or - are used.
|
| 1500 |
+
|
| 1501 |
+
[arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].
|
| 1502 |
+
|
| 1503 |
+
Examples:
|
| 1504 |
+
|
| 1505 |
+
idle
|
| 1506 |
+
Open an edit window or shell depending on IDLE's configuration.
|
| 1507 |
+
|
| 1508 |
+
idle foo.py foobar.py
|
| 1509 |
+
Edit the files, also open a shell if configured to start with shell.
|
| 1510 |
+
|
| 1511 |
+
idle -est "Baz" foo.py
|
| 1512 |
+
Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
|
| 1513 |
+
window with the title "Baz".
|
| 1514 |
+
|
| 1515 |
+
idle -c "import sys; print(sys.argv)" "foo"
|
| 1516 |
+
Open a shell window and run the command, passing "-c" in sys.argv[0]
|
| 1517 |
+
and "foo" in sys.argv[1].
|
| 1518 |
+
|
| 1519 |
+
idle -d -s -r foo.py "Hello World"
|
| 1520 |
+
Open a shell window, run a startup script, enable the debugger, and
|
| 1521 |
+
run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
|
| 1522 |
+
sys.argv[1].
|
| 1523 |
+
|
| 1524 |
+
echo "import sys; print(sys.argv)" | idle - "foobar"
|
| 1525 |
+
Open a shell window, run the script piped in, passing '' in sys.argv[0]
|
| 1526 |
+
and "foobar" in sys.argv[1].
|
| 1527 |
+
"""
|
| 1528 |
+
|
| 1529 |
+
def main():
|
| 1530 |
+
import getopt
|
| 1531 |
+
from platform import system
|
| 1532 |
+
from idlelib import testing # bool value
|
| 1533 |
+
from idlelib import macosx
|
| 1534 |
+
|
| 1535 |
+
global flist, root, use_subprocess
|
| 1536 |
+
|
| 1537 |
+
capture_warnings(True)
|
| 1538 |
+
use_subprocess = True
|
| 1539 |
+
enable_shell = False
|
| 1540 |
+
enable_edit = False
|
| 1541 |
+
debug = False
|
| 1542 |
+
cmd = None
|
| 1543 |
+
script = None
|
| 1544 |
+
startup = False
|
| 1545 |
+
try:
|
| 1546 |
+
opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:")
|
| 1547 |
+
except getopt.error as msg:
|
| 1548 |
+
print("Error: %s\n%s" % (msg, usage_msg), file=sys.stderr)
|
| 1549 |
+
sys.exit(2)
|
| 1550 |
+
for o, a in opts:
|
| 1551 |
+
if o == '-c':
|
| 1552 |
+
cmd = a
|
| 1553 |
+
enable_shell = True
|
| 1554 |
+
if o == '-d':
|
| 1555 |
+
debug = True
|
| 1556 |
+
enable_shell = True
|
| 1557 |
+
if o == '-e':
|
| 1558 |
+
enable_edit = True
|
| 1559 |
+
if o == '-h':
|
| 1560 |
+
sys.stdout.write(usage_msg)
|
| 1561 |
+
sys.exit()
|
| 1562 |
+
if o == '-i':
|
| 1563 |
+
enable_shell = True
|
| 1564 |
+
if o == '-n':
|
| 1565 |
+
print(" Warning: running IDLE without a subprocess is deprecated.",
|
| 1566 |
+
file=sys.stderr)
|
| 1567 |
+
use_subprocess = False
|
| 1568 |
+
if o == '-r':
|
| 1569 |
+
script = a
|
| 1570 |
+
if os.path.isfile(script):
|
| 1571 |
+
pass
|
| 1572 |
+
else:
|
| 1573 |
+
print("No script file: ", script)
|
| 1574 |
+
sys.exit()
|
| 1575 |
+
enable_shell = True
|
| 1576 |
+
if o == '-s':
|
| 1577 |
+
startup = True
|
| 1578 |
+
enable_shell = True
|
| 1579 |
+
if o == '-t':
|
| 1580 |
+
PyShell.shell_title = a
|
| 1581 |
+
enable_shell = True
|
| 1582 |
+
if args and args[0] == '-':
|
| 1583 |
+
cmd = sys.stdin.read()
|
| 1584 |
+
enable_shell = True
|
| 1585 |
+
# process sys.argv and sys.path:
|
| 1586 |
+
for i in range(len(sys.path)):
|
| 1587 |
+
sys.path[i] = os.path.abspath(sys.path[i])
|
| 1588 |
+
if args and args[0] == '-':
|
| 1589 |
+
sys.argv = [''] + args[1:]
|
| 1590 |
+
elif cmd:
|
| 1591 |
+
sys.argv = ['-c'] + args
|
| 1592 |
+
elif script:
|
| 1593 |
+
sys.argv = [script] + args
|
| 1594 |
+
elif args:
|
| 1595 |
+
enable_edit = True
|
| 1596 |
+
pathx = []
|
| 1597 |
+
for filename in args:
|
| 1598 |
+
pathx.append(os.path.dirname(filename))
|
| 1599 |
+
for dir in pathx:
|
| 1600 |
+
dir = os.path.abspath(dir)
|
| 1601 |
+
if not dir in sys.path:
|
| 1602 |
+
sys.path.insert(0, dir)
|
| 1603 |
+
else:
|
| 1604 |
+
dir = os.getcwd()
|
| 1605 |
+
if dir not in sys.path:
|
| 1606 |
+
sys.path.insert(0, dir)
|
| 1607 |
+
# check the IDLE settings configuration (but command line overrides)
|
| 1608 |
+
edit_start = idleConf.GetOption('main', 'General',
|
| 1609 |
+
'editor-on-startup', type='bool')
|
| 1610 |
+
enable_edit = enable_edit or edit_start
|
| 1611 |
+
enable_shell = enable_shell or not enable_edit
|
| 1612 |
+
|
| 1613 |
+
# Setup root. Don't break user code run in IDLE process.
|
| 1614 |
+
# Don't change environment when testing.
|
| 1615 |
+
if use_subprocess and not testing:
|
| 1616 |
+
NoDefaultRoot()
|
| 1617 |
+
root = Tk(className="Idle")
|
| 1618 |
+
root.withdraw()
|
| 1619 |
+
from idlelib.run import fix_scaling
|
| 1620 |
+
fix_scaling(root)
|
| 1621 |
+
|
| 1622 |
+
# set application icon
|
| 1623 |
+
icondir = os.path.join(os.path.dirname(__file__), 'Icons')
|
| 1624 |
+
if system() == 'Windows':
|
| 1625 |
+
iconfile = os.path.join(icondir, 'idle.ico')
|
| 1626 |
+
root.wm_iconbitmap(default=iconfile)
|
| 1627 |
+
elif not macosx.isAquaTk():
|
| 1628 |
+
if TkVersion >= 8.6:
|
| 1629 |
+
ext = '.png'
|
| 1630 |
+
sizes = (16, 32, 48, 256)
|
| 1631 |
+
else:
|
| 1632 |
+
ext = '.gif'
|
| 1633 |
+
sizes = (16, 32, 48)
|
| 1634 |
+
iconfiles = [os.path.join(icondir, 'idle_%d%s' % (size, ext))
|
| 1635 |
+
for size in sizes]
|
| 1636 |
+
icons = [PhotoImage(master=root, file=iconfile)
|
| 1637 |
+
for iconfile in iconfiles]
|
| 1638 |
+
root.wm_iconphoto(True, *icons)
|
| 1639 |
+
|
| 1640 |
+
# start editor and/or shell windows:
|
| 1641 |
+
fixwordbreaks(root)
|
| 1642 |
+
fix_x11_paste(root)
|
| 1643 |
+
flist = PyShellFileList(root)
|
| 1644 |
+
macosx.setupApp(root, flist)
|
| 1645 |
+
|
| 1646 |
+
if enable_edit:
|
| 1647 |
+
if not (cmd or script):
|
| 1648 |
+
for filename in args[:]:
|
| 1649 |
+
if flist.open(filename) is None:
|
| 1650 |
+
# filename is a directory actually, disconsider it
|
| 1651 |
+
args.remove(filename)
|
| 1652 |
+
if not args:
|
| 1653 |
+
flist.new()
|
| 1654 |
+
|
| 1655 |
+
if enable_shell:
|
| 1656 |
+
shell = flist.open_shell()
|
| 1657 |
+
if not shell:
|
| 1658 |
+
return # couldn't open shell
|
| 1659 |
+
if macosx.isAquaTk() and flist.dict:
|
| 1660 |
+
# On OSX: when the user has double-clicked on a file that causes
|
| 1661 |
+
# IDLE to be launched the shell window will open just in front of
|
| 1662 |
+
# the file she wants to see. Lower the interpreter window when
|
| 1663 |
+
# there are open files.
|
| 1664 |
+
shell.top.lower()
|
| 1665 |
+
else:
|
| 1666 |
+
shell = flist.pyshell
|
| 1667 |
+
|
| 1668 |
+
# Handle remaining options. If any of these are set, enable_shell
|
| 1669 |
+
# was set also, so shell must be true to reach here.
|
| 1670 |
+
if debug:
|
| 1671 |
+
shell.open_debugger()
|
| 1672 |
+
if startup:
|
| 1673 |
+
filename = os.environ.get("IDLESTARTUP") or \
|
| 1674 |
+
os.environ.get("PYTHONSTARTUP")
|
| 1675 |
+
if filename and os.path.isfile(filename):
|
| 1676 |
+
shell.interp.execfile(filename)
|
| 1677 |
+
if cmd or script:
|
| 1678 |
+
shell.interp.runcommand("""if 1:
|
| 1679 |
+
import sys as _sys
|
| 1680 |
+
_sys.argv = %r
|
| 1681 |
+
del _sys
|
| 1682 |
+
\n""" % (sys.argv,))
|
| 1683 |
+
if cmd:
|
| 1684 |
+
shell.interp.execsource(cmd)
|
| 1685 |
+
elif script:
|
| 1686 |
+
shell.interp.prepend_syspath(script)
|
| 1687 |
+
shell.interp.execfile(script)
|
| 1688 |
+
elif shell:
|
| 1689 |
+
# If there is a shell window and no cmd or script in progress,
|
| 1690 |
+
# check for problematic issues and print warning message(s) in
|
| 1691 |
+
# the IDLE shell window; this is less intrusive than always
|
| 1692 |
+
# opening a separate window.
|
| 1693 |
+
|
| 1694 |
+
# Warn if using a problematic OS X Tk version.
|
| 1695 |
+
tkversionwarning = macosx.tkVersionWarning(root)
|
| 1696 |
+
if tkversionwarning:
|
| 1697 |
+
shell.show_warning(tkversionwarning)
|
| 1698 |
+
|
| 1699 |
+
# Warn if the "Prefer tabs when opening documents" system
|
| 1700 |
+
# preference is set to "Always".
|
| 1701 |
+
prefer_tabs_preference_warning = macosx.preferTabsPreferenceWarning()
|
| 1702 |
+
if prefer_tabs_preference_warning:
|
| 1703 |
+
shell.show_warning(prefer_tabs_preference_warning)
|
| 1704 |
+
|
| 1705 |
+
while flist.inversedict: # keep IDLE running while files are open.
|
| 1706 |
+
root.mainloop()
|
| 1707 |
+
root.destroy()
|
| 1708 |
+
capture_warnings(False)
|
| 1709 |
+
|
| 1710 |
+
if __name__ == "__main__":
|
| 1711 |
+
main()
|
| 1712 |
+
|
| 1713 |
+
capture_warnings(False) # Make sure turned off; see issue 18081
|
evalkit_cambrian/lib/python3.10/idlelib/query.py
ADDED
|
@@ -0,0 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Dialogs that query users and verify the answer before accepting.
|
| 3 |
+
|
| 4 |
+
Query is the generic base class for a popup dialog.
|
| 5 |
+
The user must either enter a valid answer or close the dialog.
|
| 6 |
+
Entries are validated when <Return> is entered or [Ok] is clicked.
|
| 7 |
+
Entries are ignored when [Cancel] or [X] are clicked.
|
| 8 |
+
The 'return value' is .result set to either a valid answer or None.
|
| 9 |
+
|
| 10 |
+
Subclass SectionName gets a name for a new config file section.
|
| 11 |
+
Configdialog uses it for new highlight theme and keybinding set names.
|
| 12 |
+
Subclass ModuleName gets a name for File => Open Module.
|
| 13 |
+
Subclass HelpSource gets menu item and path for additions to Help menu.
|
| 14 |
+
"""
|
| 15 |
+
# Query and Section name result from splitting GetCfgSectionNameDialog
|
| 16 |
+
# of configSectionNameDialog.py (temporarily config_sec.py) into
|
| 17 |
+
# generic and specific parts. 3.6 only, July 2016.
|
| 18 |
+
# ModuleName.entry_ok came from editor.EditorWindow.load_module.
|
| 19 |
+
# HelpSource was extracted from configHelpSourceEdit.py (temporarily
|
| 20 |
+
# config_help.py), with darwin code moved from ok to path_ok.
|
| 21 |
+
|
| 22 |
+
import importlib.util, importlib.abc
|
| 23 |
+
import os
|
| 24 |
+
import shlex
|
| 25 |
+
from sys import executable, platform # Platform is set for one test.
|
| 26 |
+
|
| 27 |
+
from tkinter import Toplevel, StringVar, BooleanVar, W, E, S
|
| 28 |
+
from tkinter.ttk import Frame, Button, Entry, Label, Checkbutton
|
| 29 |
+
from tkinter import filedialog
|
| 30 |
+
from tkinter.font import Font
|
| 31 |
+
from tkinter.simpledialog import _setup_dialog
|
| 32 |
+
|
| 33 |
+
class Query(Toplevel):
|
| 34 |
+
"""Base class for getting verified answer from a user.
|
| 35 |
+
|
| 36 |
+
For this base class, accept any non-blank string.
|
| 37 |
+
"""
|
| 38 |
+
def __init__(self, parent, title, message, *, text0='', used_names={},
|
| 39 |
+
_htest=False, _utest=False):
|
| 40 |
+
"""Create modal popup, return when destroyed.
|
| 41 |
+
|
| 42 |
+
Additional subclass init must be done before this unless
|
| 43 |
+
_utest=True is passed to suppress wait_window().
|
| 44 |
+
|
| 45 |
+
title - string, title of popup dialog
|
| 46 |
+
message - string, informational message to display
|
| 47 |
+
text0 - initial value for entry
|
| 48 |
+
used_names - names already in use
|
| 49 |
+
_htest - bool, change box location when running htest
|
| 50 |
+
_utest - bool, leave window hidden and not modal
|
| 51 |
+
"""
|
| 52 |
+
self.parent = parent # Needed for Font call.
|
| 53 |
+
self.message = message
|
| 54 |
+
self.text0 = text0
|
| 55 |
+
self.used_names = used_names
|
| 56 |
+
|
| 57 |
+
Toplevel.__init__(self, parent)
|
| 58 |
+
self.withdraw() # Hide while configuring, especially geometry.
|
| 59 |
+
self.title(title)
|
| 60 |
+
self.transient(parent)
|
| 61 |
+
if not _utest: # Otherwise fail when directly run unittest.
|
| 62 |
+
self.grab_set()
|
| 63 |
+
|
| 64 |
+
_setup_dialog(self)
|
| 65 |
+
if self._windowingsystem == 'aqua':
|
| 66 |
+
self.bind("<Command-.>", self.cancel)
|
| 67 |
+
self.bind('<Key-Escape>', self.cancel)
|
| 68 |
+
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
| 69 |
+
self.bind('<Key-Return>', self.ok)
|
| 70 |
+
self.bind("<KP_Enter>", self.ok)
|
| 71 |
+
|
| 72 |
+
self.create_widgets()
|
| 73 |
+
self.update_idletasks() # Need here for winfo_reqwidth below.
|
| 74 |
+
self.geometry( # Center dialog over parent (or below htest box).
|
| 75 |
+
"+%d+%d" % (
|
| 76 |
+
parent.winfo_rootx() +
|
| 77 |
+
(parent.winfo_width()/2 - self.winfo_reqwidth()/2),
|
| 78 |
+
parent.winfo_rooty() +
|
| 79 |
+
((parent.winfo_height()/2 - self.winfo_reqheight()/2)
|
| 80 |
+
if not _htest else 150)
|
| 81 |
+
) )
|
| 82 |
+
self.resizable(height=False, width=False)
|
| 83 |
+
|
| 84 |
+
if not _utest:
|
| 85 |
+
self.deiconify() # Unhide now that geometry set.
|
| 86 |
+
self.entry.focus_set()
|
| 87 |
+
self.wait_window()
|
| 88 |
+
|
| 89 |
+
def create_widgets(self, ok_text='OK'): # Do not replace.
|
| 90 |
+
"""Create entry (rows, extras, buttons.
|
| 91 |
+
|
| 92 |
+
Entry stuff on rows 0-2, spanning cols 0-2.
|
| 93 |
+
Buttons on row 99, cols 1, 2.
|
| 94 |
+
"""
|
| 95 |
+
# Bind to self the widgets needed for entry_ok or unittest.
|
| 96 |
+
self.frame = frame = Frame(self, padding=10)
|
| 97 |
+
frame.grid(column=0, row=0, sticky='news')
|
| 98 |
+
frame.grid_columnconfigure(0, weight=1)
|
| 99 |
+
|
| 100 |
+
entrylabel = Label(frame, anchor='w', justify='left',
|
| 101 |
+
text=self.message)
|
| 102 |
+
self.entryvar = StringVar(self, self.text0)
|
| 103 |
+
self.entry = Entry(frame, width=30, textvariable=self.entryvar)
|
| 104 |
+
self.error_font = Font(name='TkCaptionFont',
|
| 105 |
+
exists=True, root=self.parent)
|
| 106 |
+
self.entry_error = Label(frame, text=' ', foreground='red',
|
| 107 |
+
font=self.error_font)
|
| 108 |
+
# Display or blank error by setting ['text'] =.
|
| 109 |
+
entrylabel.grid(column=0, row=0, columnspan=3, padx=5, sticky=W)
|
| 110 |
+
self.entry.grid(column=0, row=1, columnspan=3, padx=5, sticky=W+E,
|
| 111 |
+
pady=[10,0])
|
| 112 |
+
self.entry_error.grid(column=0, row=2, columnspan=3, padx=5,
|
| 113 |
+
sticky=W+E)
|
| 114 |
+
|
| 115 |
+
self.create_extra()
|
| 116 |
+
|
| 117 |
+
self.button_ok = Button(
|
| 118 |
+
frame, text=ok_text, default='active', command=self.ok)
|
| 119 |
+
self.button_cancel = Button(
|
| 120 |
+
frame, text='Cancel', command=self.cancel)
|
| 121 |
+
|
| 122 |
+
self.button_ok.grid(column=1, row=99, padx=5)
|
| 123 |
+
self.button_cancel.grid(column=2, row=99, padx=5)
|
| 124 |
+
|
| 125 |
+
def create_extra(self): pass # Override to add widgets.
|
| 126 |
+
|
| 127 |
+
def showerror(self, message, widget=None):
|
| 128 |
+
#self.bell(displayof=self)
|
| 129 |
+
(widget or self.entry_error)['text'] = 'ERROR: ' + message
|
| 130 |
+
|
| 131 |
+
def entry_ok(self): # Example: usually replace.
|
| 132 |
+
"Return non-blank entry or None."
|
| 133 |
+
entry = self.entry.get().strip()
|
| 134 |
+
if not entry:
|
| 135 |
+
self.showerror('blank line.')
|
| 136 |
+
return None
|
| 137 |
+
return entry
|
| 138 |
+
|
| 139 |
+
def ok(self, event=None): # Do not replace.
|
| 140 |
+
'''If entry is valid, bind it to 'result' and destroy tk widget.
|
| 141 |
+
|
| 142 |
+
Otherwise leave dialog open for user to correct entry or cancel.
|
| 143 |
+
'''
|
| 144 |
+
self.entry_error['text'] = ''
|
| 145 |
+
entry = self.entry_ok()
|
| 146 |
+
if entry is not None:
|
| 147 |
+
self.result = entry
|
| 148 |
+
self.destroy()
|
| 149 |
+
else:
|
| 150 |
+
# [Ok] moves focus. (<Return> does not.) Move it back.
|
| 151 |
+
self.entry.focus_set()
|
| 152 |
+
|
| 153 |
+
def cancel(self, event=None): # Do not replace.
|
| 154 |
+
"Set dialog result to None and destroy tk widget."
|
| 155 |
+
self.result = None
|
| 156 |
+
self.destroy()
|
| 157 |
+
|
| 158 |
+
def destroy(self):
|
| 159 |
+
self.grab_release()
|
| 160 |
+
super().destroy()
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
class SectionName(Query):
|
| 164 |
+
"Get a name for a config file section name."
|
| 165 |
+
# Used in ConfigDialog.GetNewKeysName, .GetNewThemeName (837)
|
| 166 |
+
|
| 167 |
+
def __init__(self, parent, title, message, used_names,
|
| 168 |
+
*, _htest=False, _utest=False):
|
| 169 |
+
super().__init__(parent, title, message, used_names=used_names,
|
| 170 |
+
_htest=_htest, _utest=_utest)
|
| 171 |
+
|
| 172 |
+
def entry_ok(self):
|
| 173 |
+
"Return sensible ConfigParser section name or None."
|
| 174 |
+
name = self.entry.get().strip()
|
| 175 |
+
if not name:
|
| 176 |
+
self.showerror('no name specified.')
|
| 177 |
+
return None
|
| 178 |
+
elif len(name)>30:
|
| 179 |
+
self.showerror('name is longer than 30 characters.')
|
| 180 |
+
return None
|
| 181 |
+
elif name in self.used_names:
|
| 182 |
+
self.showerror('name is already in use.')
|
| 183 |
+
return None
|
| 184 |
+
return name
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
class ModuleName(Query):
|
| 188 |
+
"Get a module name for Open Module menu entry."
|
| 189 |
+
# Used in open_module (editor.EditorWindow until move to iobinding).
|
| 190 |
+
|
| 191 |
+
def __init__(self, parent, title, message, text0,
|
| 192 |
+
*, _htest=False, _utest=False):
|
| 193 |
+
super().__init__(parent, title, message, text0=text0,
|
| 194 |
+
_htest=_htest, _utest=_utest)
|
| 195 |
+
|
| 196 |
+
def entry_ok(self):
|
| 197 |
+
"Return entered module name as file path or None."
|
| 198 |
+
name = self.entry.get().strip()
|
| 199 |
+
if not name:
|
| 200 |
+
self.showerror('no name specified.')
|
| 201 |
+
return None
|
| 202 |
+
# XXX Ought to insert current file's directory in front of path.
|
| 203 |
+
try:
|
| 204 |
+
spec = importlib.util.find_spec(name)
|
| 205 |
+
except (ValueError, ImportError) as msg:
|
| 206 |
+
self.showerror(str(msg))
|
| 207 |
+
return None
|
| 208 |
+
if spec is None:
|
| 209 |
+
self.showerror("module not found.")
|
| 210 |
+
return None
|
| 211 |
+
if not isinstance(spec.loader, importlib.abc.SourceLoader):
|
| 212 |
+
self.showerror("not a source-based module.")
|
| 213 |
+
return None
|
| 214 |
+
try:
|
| 215 |
+
file_path = spec.loader.get_filename(name)
|
| 216 |
+
except AttributeError:
|
| 217 |
+
self.showerror("loader does not support get_filename.")
|
| 218 |
+
return None
|
| 219 |
+
except ImportError:
|
| 220 |
+
# Some special modules require this (e.g. os.path)
|
| 221 |
+
try:
|
| 222 |
+
file_path = spec.loader.get_filename()
|
| 223 |
+
except TypeError:
|
| 224 |
+
self.showerror("loader failed to get filename.")
|
| 225 |
+
return None
|
| 226 |
+
return file_path
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class Goto(Query):
|
| 230 |
+
"Get a positive line number for editor Go To Line."
|
| 231 |
+
# Used in editor.EditorWindow.goto_line_event.
|
| 232 |
+
|
| 233 |
+
def entry_ok(self):
|
| 234 |
+
try:
|
| 235 |
+
lineno = int(self.entry.get())
|
| 236 |
+
except ValueError:
|
| 237 |
+
self.showerror('not a base 10 integer.')
|
| 238 |
+
return None
|
| 239 |
+
if lineno <= 0:
|
| 240 |
+
self.showerror('not a positive integer.')
|
| 241 |
+
return None
|
| 242 |
+
return lineno
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
class HelpSource(Query):
|
| 246 |
+
"Get menu name and help source for Help menu."
|
| 247 |
+
# Used in ConfigDialog.HelpListItemAdd/Edit, (941/9)
|
| 248 |
+
|
| 249 |
+
def __init__(self, parent, title, *, menuitem='', filepath='',
|
| 250 |
+
used_names={}, _htest=False, _utest=False):
|
| 251 |
+
"""Get menu entry and url/local file for Additional Help.
|
| 252 |
+
|
| 253 |
+
User enters a name for the Help resource and a web url or file
|
| 254 |
+
name. The user can browse for the file.
|
| 255 |
+
"""
|
| 256 |
+
self.filepath = filepath
|
| 257 |
+
message = 'Name for item on Help menu:'
|
| 258 |
+
super().__init__(
|
| 259 |
+
parent, title, message, text0=menuitem,
|
| 260 |
+
used_names=used_names, _htest=_htest, _utest=_utest)
|
| 261 |
+
|
| 262 |
+
def create_extra(self):
|
| 263 |
+
"Add path widjets to rows 10-12."
|
| 264 |
+
frame = self.frame
|
| 265 |
+
pathlabel = Label(frame, anchor='w', justify='left',
|
| 266 |
+
text='Help File Path: Enter URL or browse for file')
|
| 267 |
+
self.pathvar = StringVar(self, self.filepath)
|
| 268 |
+
self.path = Entry(frame, textvariable=self.pathvar, width=40)
|
| 269 |
+
browse = Button(frame, text='Browse', width=8,
|
| 270 |
+
command=self.browse_file)
|
| 271 |
+
self.path_error = Label(frame, text=' ', foreground='red',
|
| 272 |
+
font=self.error_font)
|
| 273 |
+
|
| 274 |
+
pathlabel.grid(column=0, row=10, columnspan=3, padx=5, pady=[10,0],
|
| 275 |
+
sticky=W)
|
| 276 |
+
self.path.grid(column=0, row=11, columnspan=2, padx=5, sticky=W+E,
|
| 277 |
+
pady=[10,0])
|
| 278 |
+
browse.grid(column=2, row=11, padx=5, sticky=W+S)
|
| 279 |
+
self.path_error.grid(column=0, row=12, columnspan=3, padx=5,
|
| 280 |
+
sticky=W+E)
|
| 281 |
+
|
| 282 |
+
def askfilename(self, filetypes, initdir, initfile): # htest #
|
| 283 |
+
# Extracted from browse_file so can mock for unittests.
|
| 284 |
+
# Cannot unittest as cannot simulate button clicks.
|
| 285 |
+
# Test by running htest, such as by running this file.
|
| 286 |
+
return filedialog.Open(parent=self, filetypes=filetypes)\
|
| 287 |
+
.show(initialdir=initdir, initialfile=initfile)
|
| 288 |
+
|
| 289 |
+
def browse_file(self):
|
| 290 |
+
filetypes = [
|
| 291 |
+
("HTML Files", "*.htm *.html", "TEXT"),
|
| 292 |
+
("PDF Files", "*.pdf", "TEXT"),
|
| 293 |
+
("Windows Help Files", "*.chm"),
|
| 294 |
+
("Text Files", "*.txt", "TEXT"),
|
| 295 |
+
("All Files", "*")]
|
| 296 |
+
path = self.pathvar.get()
|
| 297 |
+
if path:
|
| 298 |
+
dir, base = os.path.split(path)
|
| 299 |
+
else:
|
| 300 |
+
base = None
|
| 301 |
+
if platform[:3] == 'win':
|
| 302 |
+
dir = os.path.join(os.path.dirname(executable), 'Doc')
|
| 303 |
+
if not os.path.isdir(dir):
|
| 304 |
+
dir = os.getcwd()
|
| 305 |
+
else:
|
| 306 |
+
dir = os.getcwd()
|
| 307 |
+
file = self.askfilename(filetypes, dir, base)
|
| 308 |
+
if file:
|
| 309 |
+
self.pathvar.set(file)
|
| 310 |
+
|
| 311 |
+
item_ok = SectionName.entry_ok # localize for test override
|
| 312 |
+
|
| 313 |
+
def path_ok(self):
|
| 314 |
+
"Simple validity check for menu file path"
|
| 315 |
+
path = self.path.get().strip()
|
| 316 |
+
if not path: #no path specified
|
| 317 |
+
self.showerror('no help file path specified.', self.path_error)
|
| 318 |
+
return None
|
| 319 |
+
elif not path.startswith(('www.', 'http')):
|
| 320 |
+
if path[:5] == 'file:':
|
| 321 |
+
path = path[5:]
|
| 322 |
+
if not os.path.exists(path):
|
| 323 |
+
self.showerror('help file path does not exist.',
|
| 324 |
+
self.path_error)
|
| 325 |
+
return None
|
| 326 |
+
if platform == 'darwin': # for Mac Safari
|
| 327 |
+
path = "file://" + path
|
| 328 |
+
return path
|
| 329 |
+
|
| 330 |
+
def entry_ok(self):
|
| 331 |
+
"Return apparently valid (name, path) or None"
|
| 332 |
+
self.path_error['text'] = ''
|
| 333 |
+
name = self.item_ok()
|
| 334 |
+
path = self.path_ok()
|
| 335 |
+
return None if name is None or path is None else (name, path)
|
| 336 |
+
|
| 337 |
+
class CustomRun(Query):
|
| 338 |
+
"""Get settings for custom run of module.
|
| 339 |
+
|
| 340 |
+
1. Command line arguments to extend sys.argv.
|
| 341 |
+
2. Whether to restart Shell or not.
|
| 342 |
+
"""
|
| 343 |
+
# Used in runscript.run_custom_event
|
| 344 |
+
|
| 345 |
+
def __init__(self, parent, title, *, cli_args=[],
|
| 346 |
+
_htest=False, _utest=False):
|
| 347 |
+
"""cli_args is a list of strings.
|
| 348 |
+
|
| 349 |
+
The list is assigned to the default Entry StringVar.
|
| 350 |
+
The strings are displayed joined by ' ' for display.
|
| 351 |
+
"""
|
| 352 |
+
message = 'Command Line Arguments for sys.argv:'
|
| 353 |
+
super().__init__(
|
| 354 |
+
parent, title, message, text0=cli_args,
|
| 355 |
+
_htest=_htest, _utest=_utest)
|
| 356 |
+
|
| 357 |
+
def create_extra(self):
|
| 358 |
+
"Add run mode on rows 10-12."
|
| 359 |
+
frame = self.frame
|
| 360 |
+
self.restartvar = BooleanVar(self, value=True)
|
| 361 |
+
restart = Checkbutton(frame, variable=self.restartvar, onvalue=True,
|
| 362 |
+
offvalue=False, text='Restart shell')
|
| 363 |
+
self.args_error = Label(frame, text=' ', foreground='red',
|
| 364 |
+
font=self.error_font)
|
| 365 |
+
|
| 366 |
+
restart.grid(column=0, row=10, columnspan=3, padx=5, sticky='w')
|
| 367 |
+
self.args_error.grid(column=0, row=12, columnspan=3, padx=5,
|
| 368 |
+
sticky='we')
|
| 369 |
+
|
| 370 |
+
def cli_args_ok(self):
|
| 371 |
+
"Validity check and parsing for command line arguments."
|
| 372 |
+
cli_string = self.entry.get().strip()
|
| 373 |
+
try:
|
| 374 |
+
cli_args = shlex.split(cli_string, posix=True)
|
| 375 |
+
except ValueError as err:
|
| 376 |
+
self.showerror(str(err))
|
| 377 |
+
return None
|
| 378 |
+
return cli_args
|
| 379 |
+
|
| 380 |
+
def entry_ok(self):
|
| 381 |
+
"Return apparently valid (cli_args, restart) or None."
|
| 382 |
+
cli_args = self.cli_args_ok()
|
| 383 |
+
restart = self.restartvar.get()
|
| 384 |
+
return None if cli_args is None else (cli_args, restart)
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
if __name__ == '__main__':
|
| 388 |
+
from unittest import main
|
| 389 |
+
main('idlelib.idle_test.test_query', verbosity=2, exit=False)
|
| 390 |
+
|
| 391 |
+
from idlelib.idle_test.htest import run
|
| 392 |
+
run(Query, HelpSource, CustomRun)
|
evalkit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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Replace dialog for IDLE. Inherits SearchDialogBase for GUI.
|
| 2 |
+
Uses idlelib.searchengine.SearchEngine for search capability.
|
| 3 |
+
Defines various replace related functions like replace, replace all,
|
| 4 |
+
and replace+find.
|
| 5 |
+
"""
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
from tkinter import StringVar, TclError
|
| 9 |
+
|
| 10 |
+
from idlelib.searchbase import SearchDialogBase
|
| 11 |
+
from idlelib import searchengine
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def replace(text, insert_tags=None):
|
| 15 |
+
"""Create or reuse a singleton ReplaceDialog instance.
|
| 16 |
+
|
| 17 |
+
The singleton dialog saves user entries and preferences
|
| 18 |
+
across instances.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
text: Text widget containing the text to be searched.
|
| 22 |
+
"""
|
| 23 |
+
root = text._root()
|
| 24 |
+
engine = searchengine.get(root)
|
| 25 |
+
if not hasattr(engine, "_replacedialog"):
|
| 26 |
+
engine._replacedialog = ReplaceDialog(root, engine)
|
| 27 |
+
dialog = engine._replacedialog
|
| 28 |
+
dialog.open(text, insert_tags=insert_tags)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ReplaceDialog(SearchDialogBase):
|
| 32 |
+
"Dialog for finding and replacing a pattern in text."
|
| 33 |
+
|
| 34 |
+
title = "Replace Dialog"
|
| 35 |
+
icon = "Replace"
|
| 36 |
+
|
| 37 |
+
def __init__(self, root, engine):
|
| 38 |
+
"""Create search dialog for finding and replacing text.
|
| 39 |
+
|
| 40 |
+
Uses SearchDialogBase as the basis for the GUI and a
|
| 41 |
+
searchengine instance to prepare the search.
|
| 42 |
+
|
| 43 |
+
Attributes:
|
| 44 |
+
replvar: StringVar containing 'Replace with:' value.
|
| 45 |
+
replent: Entry widget for replvar. Created in
|
| 46 |
+
create_entries().
|
| 47 |
+
ok: Boolean used in searchengine.search_text to indicate
|
| 48 |
+
whether the search includes the selection.
|
| 49 |
+
"""
|
| 50 |
+
super().__init__(root, engine)
|
| 51 |
+
self.replvar = StringVar(root)
|
| 52 |
+
self.insert_tags = None
|
| 53 |
+
|
| 54 |
+
def open(self, text, insert_tags=None):
|
| 55 |
+
"""Make dialog visible on top of others and ready to use.
|
| 56 |
+
|
| 57 |
+
Also, highlight the currently selected text and set the
|
| 58 |
+
search to include the current selection (self.ok).
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
text: Text widget being searched.
|
| 62 |
+
"""
|
| 63 |
+
SearchDialogBase.open(self, text)
|
| 64 |
+
try:
|
| 65 |
+
first = text.index("sel.first")
|
| 66 |
+
except TclError:
|
| 67 |
+
first = None
|
| 68 |
+
try:
|
| 69 |
+
last = text.index("sel.last")
|
| 70 |
+
except TclError:
|
| 71 |
+
last = None
|
| 72 |
+
first = first or text.index("insert")
|
| 73 |
+
last = last or first
|
| 74 |
+
self.show_hit(first, last)
|
| 75 |
+
self.ok = True
|
| 76 |
+
self.insert_tags = insert_tags
|
| 77 |
+
|
| 78 |
+
def create_entries(self):
|
| 79 |
+
"Create base and additional label and text entry widgets."
|
| 80 |
+
SearchDialogBase.create_entries(self)
|
| 81 |
+
self.replent = self.make_entry("Replace with:", self.replvar)[0]
|
| 82 |
+
|
| 83 |
+
def create_command_buttons(self):
|
| 84 |
+
"""Create base and additional command buttons.
|
| 85 |
+
|
| 86 |
+
The additional buttons are for Find, Replace,
|
| 87 |
+
Replace+Find, and Replace All.
|
| 88 |
+
"""
|
| 89 |
+
SearchDialogBase.create_command_buttons(self)
|
| 90 |
+
self.make_button("Find", self.find_it)
|
| 91 |
+
self.make_button("Replace", self.replace_it)
|
| 92 |
+
self.make_button("Replace+Find", self.default_command, isdef=True)
|
| 93 |
+
self.make_button("Replace All", self.replace_all)
|
| 94 |
+
|
| 95 |
+
def find_it(self, event=None):
|
| 96 |
+
"Handle the Find button."
|
| 97 |
+
self.do_find(False)
|
| 98 |
+
|
| 99 |
+
def replace_it(self, event=None):
|
| 100 |
+
"""Handle the Replace button.
|
| 101 |
+
|
| 102 |
+
If the find is successful, then perform replace.
|
| 103 |
+
"""
|
| 104 |
+
if self.do_find(self.ok):
|
| 105 |
+
self.do_replace()
|
| 106 |
+
|
| 107 |
+
def default_command(self, event=None):
|
| 108 |
+
"""Handle the Replace+Find button as the default command.
|
| 109 |
+
|
| 110 |
+
First performs a replace and then, if the replace was
|
| 111 |
+
successful, a find next.
|
| 112 |
+
"""
|
| 113 |
+
if self.do_find(self.ok):
|
| 114 |
+
if self.do_replace(): # Only find next match if replace succeeded.
|
| 115 |
+
# A bad re can cause it to fail.
|
| 116 |
+
self.do_find(False)
|
| 117 |
+
|
| 118 |
+
def _replace_expand(self, m, repl):
|
| 119 |
+
"Expand replacement text if regular expression."
|
| 120 |
+
if self.engine.isre():
|
| 121 |
+
try:
|
| 122 |
+
new = m.expand(repl)
|
| 123 |
+
except re.error:
|
| 124 |
+
self.engine.report_error(repl, 'Invalid Replace Expression')
|
| 125 |
+
new = None
|
| 126 |
+
else:
|
| 127 |
+
new = repl
|
| 128 |
+
|
| 129 |
+
return new
|
| 130 |
+
|
| 131 |
+
def replace_all(self, event=None):
|
| 132 |
+
"""Handle the Replace All button.
|
| 133 |
+
|
| 134 |
+
Search text for occurrences of the Find value and replace
|
| 135 |
+
each of them. The 'wrap around' value controls the start
|
| 136 |
+
point for searching. If wrap isn't set, then the searching
|
| 137 |
+
starts at the first occurrence after the current selection;
|
| 138 |
+
if wrap is set, the replacement starts at the first line.
|
| 139 |
+
The replacement is always done top-to-bottom in the text.
|
| 140 |
+
"""
|
| 141 |
+
prog = self.engine.getprog()
|
| 142 |
+
if not prog:
|
| 143 |
+
return
|
| 144 |
+
repl = self.replvar.get()
|
| 145 |
+
text = self.text
|
| 146 |
+
res = self.engine.search_text(text, prog)
|
| 147 |
+
if not res:
|
| 148 |
+
self.bell()
|
| 149 |
+
return
|
| 150 |
+
text.tag_remove("sel", "1.0", "end")
|
| 151 |
+
text.tag_remove("hit", "1.0", "end")
|
| 152 |
+
line = res[0]
|
| 153 |
+
col = res[1].start()
|
| 154 |
+
if self.engine.iswrap():
|
| 155 |
+
line = 1
|
| 156 |
+
col = 0
|
| 157 |
+
ok = True
|
| 158 |
+
first = last = None
|
| 159 |
+
# XXX ought to replace circular instead of top-to-bottom when wrapping
|
| 160 |
+
text.undo_block_start()
|
| 161 |
+
while res := self.engine.search_forward(
|
| 162 |
+
text, prog, line, col, wrap=False, ok=ok):
|
| 163 |
+
line, m = res
|
| 164 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 165 |
+
orig = m.group()
|
| 166 |
+
new = self._replace_expand(m, repl)
|
| 167 |
+
if new is None:
|
| 168 |
+
break
|
| 169 |
+
i, j = m.span()
|
| 170 |
+
first = "%d.%d" % (line, i)
|
| 171 |
+
last = "%d.%d" % (line, j)
|
| 172 |
+
if new == orig:
|
| 173 |
+
text.mark_set("insert", last)
|
| 174 |
+
else:
|
| 175 |
+
text.mark_set("insert", first)
|
| 176 |
+
if first != last:
|
| 177 |
+
text.delete(first, last)
|
| 178 |
+
if new:
|
| 179 |
+
text.insert(first, new, self.insert_tags)
|
| 180 |
+
col = i + len(new)
|
| 181 |
+
ok = False
|
| 182 |
+
text.undo_block_stop()
|
| 183 |
+
if first and last:
|
| 184 |
+
self.show_hit(first, last)
|
| 185 |
+
self.close()
|
| 186 |
+
|
| 187 |
+
def do_find(self, ok=False):
|
| 188 |
+
"""Search for and highlight next occurrence of pattern in text.
|
| 189 |
+
|
| 190 |
+
No text replacement is done with this option.
|
| 191 |
+
"""
|
| 192 |
+
if not self.engine.getprog():
|
| 193 |
+
return False
|
| 194 |
+
text = self.text
|
| 195 |
+
res = self.engine.search_text(text, None, ok)
|
| 196 |
+
if not res:
|
| 197 |
+
self.bell()
|
| 198 |
+
return False
|
| 199 |
+
line, m = res
|
| 200 |
+
i, j = m.span()
|
| 201 |
+
first = "%d.%d" % (line, i)
|
| 202 |
+
last = "%d.%d" % (line, j)
|
| 203 |
+
self.show_hit(first, last)
|
| 204 |
+
self.ok = True
|
| 205 |
+
return True
|
| 206 |
+
|
| 207 |
+
def do_replace(self):
|
| 208 |
+
"Replace search pattern in text with replacement value."
|
| 209 |
+
prog = self.engine.getprog()
|
| 210 |
+
if not prog:
|
| 211 |
+
return False
|
| 212 |
+
text = self.text
|
| 213 |
+
try:
|
| 214 |
+
first = pos = text.index("sel.first")
|
| 215 |
+
last = text.index("sel.last")
|
| 216 |
+
except TclError:
|
| 217 |
+
pos = None
|
| 218 |
+
if not pos:
|
| 219 |
+
first = last = pos = text.index("insert")
|
| 220 |
+
line, col = searchengine.get_line_col(pos)
|
| 221 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 222 |
+
m = prog.match(chars, col)
|
| 223 |
+
if not prog:
|
| 224 |
+
return False
|
| 225 |
+
new = self._replace_expand(m, self.replvar.get())
|
| 226 |
+
if new is None:
|
| 227 |
+
return False
|
| 228 |
+
text.mark_set("insert", first)
|
| 229 |
+
text.undo_block_start()
|
| 230 |
+
if m.group():
|
| 231 |
+
text.delete(first, last)
|
| 232 |
+
if new:
|
| 233 |
+
text.insert(first, new, self.insert_tags)
|
| 234 |
+
text.undo_block_stop()
|
| 235 |
+
self.show_hit(first, text.index("insert"))
|
| 236 |
+
self.ok = False
|
| 237 |
+
return True
|
| 238 |
+
|
| 239 |
+
def show_hit(self, first, last):
|
| 240 |
+
"""Highlight text between first and last indices.
|
| 241 |
+
|
| 242 |
+
Text is highlighted via the 'hit' tag and the marked
|
| 243 |
+
section is brought into view.
|
| 244 |
+
|
| 245 |
+
The colors from the 'hit' tag aren't currently shown
|
| 246 |
+
when the text is displayed. This is due to the 'sel'
|
| 247 |
+
tag being added first, so the colors in the 'sel'
|
| 248 |
+
config are seen instead of the colors for 'hit'.
|
| 249 |
+
"""
|
| 250 |
+
text = self.text
|
| 251 |
+
text.mark_set("insert", first)
|
| 252 |
+
text.tag_remove("sel", "1.0", "end")
|
| 253 |
+
text.tag_add("sel", first, last)
|
| 254 |
+
text.tag_remove("hit", "1.0", "end")
|
| 255 |
+
if first == last:
|
| 256 |
+
text.tag_add("hit", first)
|
| 257 |
+
else:
|
| 258 |
+
text.tag_add("hit", first, last)
|
| 259 |
+
text.see("insert")
|
| 260 |
+
text.update_idletasks()
|
| 261 |
+
|
| 262 |
+
def close(self, event=None):
|
| 263 |
+
"Close the dialog and remove hit tags."
|
| 264 |
+
SearchDialogBase.close(self, event)
|
| 265 |
+
self.text.tag_remove("hit", "1.0", "end")
|
| 266 |
+
self.insert_tags = None
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def _replace_dialog(parent): # htest #
|
| 270 |
+
from tkinter import Toplevel, Text, END, SEL
|
| 271 |
+
from tkinter.ttk import Frame, Button
|
| 272 |
+
|
| 273 |
+
top = Toplevel(parent)
|
| 274 |
+
top.title("Test ReplaceDialog")
|
| 275 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 276 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 277 |
+
|
| 278 |
+
# mock undo delegator methods
|
| 279 |
+
def undo_block_start():
|
| 280 |
+
pass
|
| 281 |
+
|
| 282 |
+
def undo_block_stop():
|
| 283 |
+
pass
|
| 284 |
+
|
| 285 |
+
frame = Frame(top)
|
| 286 |
+
frame.pack()
|
| 287 |
+
text = Text(frame, inactiveselectbackground='gray')
|
| 288 |
+
text.undo_block_start = undo_block_start
|
| 289 |
+
text.undo_block_stop = undo_block_stop
|
| 290 |
+
text.pack()
|
| 291 |
+
text.insert("insert","This is a sample sTring\nPlus MORE.")
|
| 292 |
+
text.focus_set()
|
| 293 |
+
|
| 294 |
+
def show_replace():
|
| 295 |
+
text.tag_add(SEL, "1.0", END)
|
| 296 |
+
replace(text)
|
| 297 |
+
text.tag_remove(SEL, "1.0", END)
|
| 298 |
+
|
| 299 |
+
button = Button(frame, text="Replace", command=show_replace)
|
| 300 |
+
button.pack()
|
| 301 |
+
|
| 302 |
+
if __name__ == '__main__':
|
| 303 |
+
from unittest import main
|
| 304 |
+
main('idlelib.idle_test.test_replace', verbosity=2, exit=False)
|
| 305 |
+
|
| 306 |
+
from idlelib.idle_test.htest import run
|
| 307 |
+
run(_replace_dialog)
|
evalkit_cambrian/lib/python3.10/idlelib/rpc.py
ADDED
|
@@ -0,0 +1,635 @@
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""RPC Implementation, originally written for the Python Idle IDE
|
| 2 |
+
|
| 3 |
+
For security reasons, GvR requested that Idle's Python execution server process
|
| 4 |
+
connect to the Idle process, which listens for the connection. Since Idle has
|
| 5 |
+
only one client per server, this was not a limitation.
|
| 6 |
+
|
| 7 |
+
+---------------------------------+ +-------------+
|
| 8 |
+
| socketserver.BaseRequestHandler | | SocketIO |
|
| 9 |
+
+---------------------------------+ +-------------+
|
| 10 |
+
^ | register() |
|
| 11 |
+
| | unregister()|
|
| 12 |
+
| +-------------+
|
| 13 |
+
| ^ ^
|
| 14 |
+
| | |
|
| 15 |
+
| + -------------------+ |
|
| 16 |
+
| | |
|
| 17 |
+
+-------------------------+ +-----------------+
|
| 18 |
+
| RPCHandler | | RPCClient |
|
| 19 |
+
| [attribute of RPCServer]| | |
|
| 20 |
+
+-------------------------+ +-----------------+
|
| 21 |
+
|
| 22 |
+
The RPCServer handler class is expected to provide register/unregister methods.
|
| 23 |
+
RPCHandler inherits the mix-in class SocketIO, which provides these methods.
|
| 24 |
+
|
| 25 |
+
See the Idle run.main() docstring for further information on how this was
|
| 26 |
+
accomplished in Idle.
|
| 27 |
+
|
| 28 |
+
"""
|
| 29 |
+
import builtins
|
| 30 |
+
import copyreg
|
| 31 |
+
import io
|
| 32 |
+
import marshal
|
| 33 |
+
import os
|
| 34 |
+
import pickle
|
| 35 |
+
import queue
|
| 36 |
+
import select
|
| 37 |
+
import socket
|
| 38 |
+
import socketserver
|
| 39 |
+
import struct
|
| 40 |
+
import sys
|
| 41 |
+
import threading
|
| 42 |
+
import traceback
|
| 43 |
+
import types
|
| 44 |
+
|
| 45 |
+
def unpickle_code(ms):
|
| 46 |
+
"Return code object from marshal string ms."
|
| 47 |
+
co = marshal.loads(ms)
|
| 48 |
+
assert isinstance(co, types.CodeType)
|
| 49 |
+
return co
|
| 50 |
+
|
| 51 |
+
def pickle_code(co):
|
| 52 |
+
"Return unpickle function and tuple with marshalled co code object."
|
| 53 |
+
assert isinstance(co, types.CodeType)
|
| 54 |
+
ms = marshal.dumps(co)
|
| 55 |
+
return unpickle_code, (ms,)
|
| 56 |
+
|
| 57 |
+
def dumps(obj, protocol=None):
|
| 58 |
+
"Return pickled (or marshalled) string for obj."
|
| 59 |
+
# IDLE passes 'None' to select pickle.DEFAULT_PROTOCOL.
|
| 60 |
+
f = io.BytesIO()
|
| 61 |
+
p = CodePickler(f, protocol)
|
| 62 |
+
p.dump(obj)
|
| 63 |
+
return f.getvalue()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class CodePickler(pickle.Pickler):
|
| 67 |
+
dispatch_table = {types.CodeType: pickle_code, **copyreg.dispatch_table}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
BUFSIZE = 8*1024
|
| 71 |
+
LOCALHOST = '127.0.0.1'
|
| 72 |
+
|
| 73 |
+
class RPCServer(socketserver.TCPServer):
|
| 74 |
+
|
| 75 |
+
def __init__(self, addr, handlerclass=None):
|
| 76 |
+
if handlerclass is None:
|
| 77 |
+
handlerclass = RPCHandler
|
| 78 |
+
socketserver.TCPServer.__init__(self, addr, handlerclass)
|
| 79 |
+
|
| 80 |
+
def server_bind(self):
|
| 81 |
+
"Override TCPServer method, no bind() phase for connecting entity"
|
| 82 |
+
pass
|
| 83 |
+
|
| 84 |
+
def server_activate(self):
|
| 85 |
+
"""Override TCPServer method, connect() instead of listen()
|
| 86 |
+
|
| 87 |
+
Due to the reversed connection, self.server_address is actually the
|
| 88 |
+
address of the Idle Client to which we are connecting.
|
| 89 |
+
|
| 90 |
+
"""
|
| 91 |
+
self.socket.connect(self.server_address)
|
| 92 |
+
|
| 93 |
+
def get_request(self):
|
| 94 |
+
"Override TCPServer method, return already connected socket"
|
| 95 |
+
return self.socket, self.server_address
|
| 96 |
+
|
| 97 |
+
def handle_error(self, request, client_address):
|
| 98 |
+
"""Override TCPServer method
|
| 99 |
+
|
| 100 |
+
Error message goes to __stderr__. No error message if exiting
|
| 101 |
+
normally or socket raised EOF. Other exceptions not handled in
|
| 102 |
+
server code will cause os._exit.
|
| 103 |
+
|
| 104 |
+
"""
|
| 105 |
+
try:
|
| 106 |
+
raise
|
| 107 |
+
except SystemExit:
|
| 108 |
+
raise
|
| 109 |
+
except:
|
| 110 |
+
erf = sys.__stderr__
|
| 111 |
+
print('\n' + '-'*40, file=erf)
|
| 112 |
+
print('Unhandled server exception!', file=erf)
|
| 113 |
+
print('Thread: %s' % threading.current_thread().name, file=erf)
|
| 114 |
+
print('Client Address: ', client_address, file=erf)
|
| 115 |
+
print('Request: ', repr(request), file=erf)
|
| 116 |
+
traceback.print_exc(file=erf)
|
| 117 |
+
print('\n*** Unrecoverable, server exiting!', file=erf)
|
| 118 |
+
print('-'*40, file=erf)
|
| 119 |
+
os._exit(0)
|
| 120 |
+
|
| 121 |
+
#----------------- end class RPCServer --------------------
|
| 122 |
+
|
| 123 |
+
objecttable = {}
|
| 124 |
+
request_queue = queue.Queue(0)
|
| 125 |
+
response_queue = queue.Queue(0)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class SocketIO:
|
| 129 |
+
|
| 130 |
+
nextseq = 0
|
| 131 |
+
|
| 132 |
+
def __init__(self, sock, objtable=None, debugging=None):
|
| 133 |
+
self.sockthread = threading.current_thread()
|
| 134 |
+
if debugging is not None:
|
| 135 |
+
self.debugging = debugging
|
| 136 |
+
self.sock = sock
|
| 137 |
+
if objtable is None:
|
| 138 |
+
objtable = objecttable
|
| 139 |
+
self.objtable = objtable
|
| 140 |
+
self.responses = {}
|
| 141 |
+
self.cvars = {}
|
| 142 |
+
|
| 143 |
+
def close(self):
|
| 144 |
+
sock = self.sock
|
| 145 |
+
self.sock = None
|
| 146 |
+
if sock is not None:
|
| 147 |
+
sock.close()
|
| 148 |
+
|
| 149 |
+
def exithook(self):
|
| 150 |
+
"override for specific exit action"
|
| 151 |
+
os._exit(0)
|
| 152 |
+
|
| 153 |
+
def debug(self, *args):
|
| 154 |
+
if not self.debugging:
|
| 155 |
+
return
|
| 156 |
+
s = self.location + " " + str(threading.current_thread().name)
|
| 157 |
+
for a in args:
|
| 158 |
+
s = s + " " + str(a)
|
| 159 |
+
print(s, file=sys.__stderr__)
|
| 160 |
+
|
| 161 |
+
def register(self, oid, object):
|
| 162 |
+
self.objtable[oid] = object
|
| 163 |
+
|
| 164 |
+
def unregister(self, oid):
|
| 165 |
+
try:
|
| 166 |
+
del self.objtable[oid]
|
| 167 |
+
except KeyError:
|
| 168 |
+
pass
|
| 169 |
+
|
| 170 |
+
def localcall(self, seq, request):
|
| 171 |
+
self.debug("localcall:", request)
|
| 172 |
+
try:
|
| 173 |
+
how, (oid, methodname, args, kwargs) = request
|
| 174 |
+
except TypeError:
|
| 175 |
+
return ("ERROR", "Bad request format")
|
| 176 |
+
if oid not in self.objtable:
|
| 177 |
+
return ("ERROR", "Unknown object id: %r" % (oid,))
|
| 178 |
+
obj = self.objtable[oid]
|
| 179 |
+
if methodname == "__methods__":
|
| 180 |
+
methods = {}
|
| 181 |
+
_getmethods(obj, methods)
|
| 182 |
+
return ("OK", methods)
|
| 183 |
+
if methodname == "__attributes__":
|
| 184 |
+
attributes = {}
|
| 185 |
+
_getattributes(obj, attributes)
|
| 186 |
+
return ("OK", attributes)
|
| 187 |
+
if not hasattr(obj, methodname):
|
| 188 |
+
return ("ERROR", "Unsupported method name: %r" % (methodname,))
|
| 189 |
+
method = getattr(obj, methodname)
|
| 190 |
+
try:
|
| 191 |
+
if how == 'CALL':
|
| 192 |
+
ret = method(*args, **kwargs)
|
| 193 |
+
if isinstance(ret, RemoteObject):
|
| 194 |
+
ret = remoteref(ret)
|
| 195 |
+
return ("OK", ret)
|
| 196 |
+
elif how == 'QUEUE':
|
| 197 |
+
request_queue.put((seq, (method, args, kwargs)))
|
| 198 |
+
return("QUEUED", None)
|
| 199 |
+
else:
|
| 200 |
+
return ("ERROR", "Unsupported message type: %s" % how)
|
| 201 |
+
except SystemExit:
|
| 202 |
+
raise
|
| 203 |
+
except KeyboardInterrupt:
|
| 204 |
+
raise
|
| 205 |
+
except OSError:
|
| 206 |
+
raise
|
| 207 |
+
except Exception as ex:
|
| 208 |
+
return ("CALLEXC", ex)
|
| 209 |
+
except:
|
| 210 |
+
msg = "*** Internal Error: rpc.py:SocketIO.localcall()\n\n"\
|
| 211 |
+
" Object: %s \n Method: %s \n Args: %s\n"
|
| 212 |
+
print(msg % (oid, method, args), file=sys.__stderr__)
|
| 213 |
+
traceback.print_exc(file=sys.__stderr__)
|
| 214 |
+
return ("EXCEPTION", None)
|
| 215 |
+
|
| 216 |
+
def remotecall(self, oid, methodname, args, kwargs):
|
| 217 |
+
self.debug("remotecall:asynccall: ", oid, methodname)
|
| 218 |
+
seq = self.asynccall(oid, methodname, args, kwargs)
|
| 219 |
+
return self.asyncreturn(seq)
|
| 220 |
+
|
| 221 |
+
def remotequeue(self, oid, methodname, args, kwargs):
|
| 222 |
+
self.debug("remotequeue:asyncqueue: ", oid, methodname)
|
| 223 |
+
seq = self.asyncqueue(oid, methodname, args, kwargs)
|
| 224 |
+
return self.asyncreturn(seq)
|
| 225 |
+
|
| 226 |
+
def asynccall(self, oid, methodname, args, kwargs):
|
| 227 |
+
request = ("CALL", (oid, methodname, args, kwargs))
|
| 228 |
+
seq = self.newseq()
|
| 229 |
+
if threading.current_thread() != self.sockthread:
|
| 230 |
+
cvar = threading.Condition()
|
| 231 |
+
self.cvars[seq] = cvar
|
| 232 |
+
self.debug(("asynccall:%d:" % seq), oid, methodname, args, kwargs)
|
| 233 |
+
self.putmessage((seq, request))
|
| 234 |
+
return seq
|
| 235 |
+
|
| 236 |
+
def asyncqueue(self, oid, methodname, args, kwargs):
|
| 237 |
+
request = ("QUEUE", (oid, methodname, args, kwargs))
|
| 238 |
+
seq = self.newseq()
|
| 239 |
+
if threading.current_thread() != self.sockthread:
|
| 240 |
+
cvar = threading.Condition()
|
| 241 |
+
self.cvars[seq] = cvar
|
| 242 |
+
self.debug(("asyncqueue:%d:" % seq), oid, methodname, args, kwargs)
|
| 243 |
+
self.putmessage((seq, request))
|
| 244 |
+
return seq
|
| 245 |
+
|
| 246 |
+
def asyncreturn(self, seq):
|
| 247 |
+
self.debug("asyncreturn:%d:call getresponse(): " % seq)
|
| 248 |
+
response = self.getresponse(seq, wait=0.05)
|
| 249 |
+
self.debug(("asyncreturn:%d:response: " % seq), response)
|
| 250 |
+
return self.decoderesponse(response)
|
| 251 |
+
|
| 252 |
+
def decoderesponse(self, response):
|
| 253 |
+
how, what = response
|
| 254 |
+
if how == "OK":
|
| 255 |
+
return what
|
| 256 |
+
if how == "QUEUED":
|
| 257 |
+
return None
|
| 258 |
+
if how == "EXCEPTION":
|
| 259 |
+
self.debug("decoderesponse: EXCEPTION")
|
| 260 |
+
return None
|
| 261 |
+
if how == "EOF":
|
| 262 |
+
self.debug("decoderesponse: EOF")
|
| 263 |
+
self.decode_interrupthook()
|
| 264 |
+
return None
|
| 265 |
+
if how == "ERROR":
|
| 266 |
+
self.debug("decoderesponse: Internal ERROR:", what)
|
| 267 |
+
raise RuntimeError(what)
|
| 268 |
+
if how == "CALLEXC":
|
| 269 |
+
self.debug("decoderesponse: Call Exception:", what)
|
| 270 |
+
raise what
|
| 271 |
+
raise SystemError(how, what)
|
| 272 |
+
|
| 273 |
+
def decode_interrupthook(self):
|
| 274 |
+
""
|
| 275 |
+
raise EOFError
|
| 276 |
+
|
| 277 |
+
def mainloop(self):
|
| 278 |
+
"""Listen on socket until I/O not ready or EOF
|
| 279 |
+
|
| 280 |
+
pollresponse() will loop looking for seq number None, which
|
| 281 |
+
never comes, and exit on EOFError.
|
| 282 |
+
|
| 283 |
+
"""
|
| 284 |
+
try:
|
| 285 |
+
self.getresponse(myseq=None, wait=0.05)
|
| 286 |
+
except EOFError:
|
| 287 |
+
self.debug("mainloop:return")
|
| 288 |
+
return
|
| 289 |
+
|
| 290 |
+
def getresponse(self, myseq, wait):
|
| 291 |
+
response = self._getresponse(myseq, wait)
|
| 292 |
+
if response is not None:
|
| 293 |
+
how, what = response
|
| 294 |
+
if how == "OK":
|
| 295 |
+
response = how, self._proxify(what)
|
| 296 |
+
return response
|
| 297 |
+
|
| 298 |
+
def _proxify(self, obj):
|
| 299 |
+
if isinstance(obj, RemoteProxy):
|
| 300 |
+
return RPCProxy(self, obj.oid)
|
| 301 |
+
if isinstance(obj, list):
|
| 302 |
+
return list(map(self._proxify, obj))
|
| 303 |
+
# XXX Check for other types -- not currently needed
|
| 304 |
+
return obj
|
| 305 |
+
|
| 306 |
+
def _getresponse(self, myseq, wait):
|
| 307 |
+
self.debug("_getresponse:myseq:", myseq)
|
| 308 |
+
if threading.current_thread() is self.sockthread:
|
| 309 |
+
# this thread does all reading of requests or responses
|
| 310 |
+
while True:
|
| 311 |
+
response = self.pollresponse(myseq, wait)
|
| 312 |
+
if response is not None:
|
| 313 |
+
return response
|
| 314 |
+
else:
|
| 315 |
+
# wait for notification from socket handling thread
|
| 316 |
+
cvar = self.cvars[myseq]
|
| 317 |
+
cvar.acquire()
|
| 318 |
+
while myseq not in self.responses:
|
| 319 |
+
cvar.wait()
|
| 320 |
+
response = self.responses[myseq]
|
| 321 |
+
self.debug("_getresponse:%s: thread woke up: response: %s" %
|
| 322 |
+
(myseq, response))
|
| 323 |
+
del self.responses[myseq]
|
| 324 |
+
del self.cvars[myseq]
|
| 325 |
+
cvar.release()
|
| 326 |
+
return response
|
| 327 |
+
|
| 328 |
+
def newseq(self):
|
| 329 |
+
self.nextseq = seq = self.nextseq + 2
|
| 330 |
+
return seq
|
| 331 |
+
|
| 332 |
+
def putmessage(self, message):
|
| 333 |
+
self.debug("putmessage:%d:" % message[0])
|
| 334 |
+
try:
|
| 335 |
+
s = dumps(message)
|
| 336 |
+
except pickle.PicklingError:
|
| 337 |
+
print("Cannot pickle:", repr(message), file=sys.__stderr__)
|
| 338 |
+
raise
|
| 339 |
+
s = struct.pack("<i", len(s)) + s
|
| 340 |
+
while len(s) > 0:
|
| 341 |
+
try:
|
| 342 |
+
r, w, x = select.select([], [self.sock], [])
|
| 343 |
+
n = self.sock.send(s[:BUFSIZE])
|
| 344 |
+
except (AttributeError, TypeError):
|
| 345 |
+
raise OSError("socket no longer exists")
|
| 346 |
+
s = s[n:]
|
| 347 |
+
|
| 348 |
+
buff = b''
|
| 349 |
+
bufneed = 4
|
| 350 |
+
bufstate = 0 # meaning: 0 => reading count; 1 => reading data
|
| 351 |
+
|
| 352 |
+
def pollpacket(self, wait):
|
| 353 |
+
self._stage0()
|
| 354 |
+
if len(self.buff) < self.bufneed:
|
| 355 |
+
r, w, x = select.select([self.sock.fileno()], [], [], wait)
|
| 356 |
+
if len(r) == 0:
|
| 357 |
+
return None
|
| 358 |
+
try:
|
| 359 |
+
s = self.sock.recv(BUFSIZE)
|
| 360 |
+
except OSError:
|
| 361 |
+
raise EOFError
|
| 362 |
+
if len(s) == 0:
|
| 363 |
+
raise EOFError
|
| 364 |
+
self.buff += s
|
| 365 |
+
self._stage0()
|
| 366 |
+
return self._stage1()
|
| 367 |
+
|
| 368 |
+
def _stage0(self):
|
| 369 |
+
if self.bufstate == 0 and len(self.buff) >= 4:
|
| 370 |
+
s = self.buff[:4]
|
| 371 |
+
self.buff = self.buff[4:]
|
| 372 |
+
self.bufneed = struct.unpack("<i", s)[0]
|
| 373 |
+
self.bufstate = 1
|
| 374 |
+
|
| 375 |
+
def _stage1(self):
|
| 376 |
+
if self.bufstate == 1 and len(self.buff) >= self.bufneed:
|
| 377 |
+
packet = self.buff[:self.bufneed]
|
| 378 |
+
self.buff = self.buff[self.bufneed:]
|
| 379 |
+
self.bufneed = 4
|
| 380 |
+
self.bufstate = 0
|
| 381 |
+
return packet
|
| 382 |
+
|
| 383 |
+
def pollmessage(self, wait):
|
| 384 |
+
packet = self.pollpacket(wait)
|
| 385 |
+
if packet is None:
|
| 386 |
+
return None
|
| 387 |
+
try:
|
| 388 |
+
message = pickle.loads(packet)
|
| 389 |
+
except pickle.UnpicklingError:
|
| 390 |
+
print("-----------------------", file=sys.__stderr__)
|
| 391 |
+
print("cannot unpickle packet:", repr(packet), file=sys.__stderr__)
|
| 392 |
+
traceback.print_stack(file=sys.__stderr__)
|
| 393 |
+
print("-----------------------", file=sys.__stderr__)
|
| 394 |
+
raise
|
| 395 |
+
return message
|
| 396 |
+
|
| 397 |
+
def pollresponse(self, myseq, wait):
|
| 398 |
+
"""Handle messages received on the socket.
|
| 399 |
+
|
| 400 |
+
Some messages received may be asynchronous 'call' or 'queue' requests,
|
| 401 |
+
and some may be responses for other threads.
|
| 402 |
+
|
| 403 |
+
'call' requests are passed to self.localcall() with the expectation of
|
| 404 |
+
immediate execution, during which time the socket is not serviced.
|
| 405 |
+
|
| 406 |
+
'queue' requests are used for tasks (which may block or hang) to be
|
| 407 |
+
processed in a different thread. These requests are fed into
|
| 408 |
+
request_queue by self.localcall(). Responses to queued requests are
|
| 409 |
+
taken from response_queue and sent across the link with the associated
|
| 410 |
+
sequence numbers. Messages in the queues are (sequence_number,
|
| 411 |
+
request/response) tuples and code using this module removing messages
|
| 412 |
+
from the request_queue is responsible for returning the correct
|
| 413 |
+
sequence number in the response_queue.
|
| 414 |
+
|
| 415 |
+
pollresponse() will loop until a response message with the myseq
|
| 416 |
+
sequence number is received, and will save other responses in
|
| 417 |
+
self.responses and notify the owning thread.
|
| 418 |
+
|
| 419 |
+
"""
|
| 420 |
+
while True:
|
| 421 |
+
# send queued response if there is one available
|
| 422 |
+
try:
|
| 423 |
+
qmsg = response_queue.get(0)
|
| 424 |
+
except queue.Empty:
|
| 425 |
+
pass
|
| 426 |
+
else:
|
| 427 |
+
seq, response = qmsg
|
| 428 |
+
message = (seq, ('OK', response))
|
| 429 |
+
self.putmessage(message)
|
| 430 |
+
# poll for message on link
|
| 431 |
+
try:
|
| 432 |
+
message = self.pollmessage(wait)
|
| 433 |
+
if message is None: # socket not ready
|
| 434 |
+
return None
|
| 435 |
+
except EOFError:
|
| 436 |
+
self.handle_EOF()
|
| 437 |
+
return None
|
| 438 |
+
except AttributeError:
|
| 439 |
+
return None
|
| 440 |
+
seq, resq = message
|
| 441 |
+
how = resq[0]
|
| 442 |
+
self.debug("pollresponse:%d:myseq:%s" % (seq, myseq))
|
| 443 |
+
# process or queue a request
|
| 444 |
+
if how in ("CALL", "QUEUE"):
|
| 445 |
+
self.debug("pollresponse:%d:localcall:call:" % seq)
|
| 446 |
+
response = self.localcall(seq, resq)
|
| 447 |
+
self.debug("pollresponse:%d:localcall:response:%s"
|
| 448 |
+
% (seq, response))
|
| 449 |
+
if how == "CALL":
|
| 450 |
+
self.putmessage((seq, response))
|
| 451 |
+
elif how == "QUEUE":
|
| 452 |
+
# don't acknowledge the 'queue' request!
|
| 453 |
+
pass
|
| 454 |
+
continue
|
| 455 |
+
# return if completed message transaction
|
| 456 |
+
elif seq == myseq:
|
| 457 |
+
return resq
|
| 458 |
+
# must be a response for a different thread:
|
| 459 |
+
else:
|
| 460 |
+
cv = self.cvars.get(seq, None)
|
| 461 |
+
# response involving unknown sequence number is discarded,
|
| 462 |
+
# probably intended for prior incarnation of server
|
| 463 |
+
if cv is not None:
|
| 464 |
+
cv.acquire()
|
| 465 |
+
self.responses[seq] = resq
|
| 466 |
+
cv.notify()
|
| 467 |
+
cv.release()
|
| 468 |
+
continue
|
| 469 |
+
|
| 470 |
+
def handle_EOF(self):
|
| 471 |
+
"action taken upon link being closed by peer"
|
| 472 |
+
self.EOFhook()
|
| 473 |
+
self.debug("handle_EOF")
|
| 474 |
+
for key in self.cvars:
|
| 475 |
+
cv = self.cvars[key]
|
| 476 |
+
cv.acquire()
|
| 477 |
+
self.responses[key] = ('EOF', None)
|
| 478 |
+
cv.notify()
|
| 479 |
+
cv.release()
|
| 480 |
+
# call our (possibly overridden) exit function
|
| 481 |
+
self.exithook()
|
| 482 |
+
|
| 483 |
+
def EOFhook(self):
|
| 484 |
+
"Classes using rpc client/server can override to augment EOF action"
|
| 485 |
+
pass
|
| 486 |
+
|
| 487 |
+
#----------------- end class SocketIO --------------------
|
| 488 |
+
|
| 489 |
+
class RemoteObject:
|
| 490 |
+
# Token mix-in class
|
| 491 |
+
pass
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def remoteref(obj):
|
| 495 |
+
oid = id(obj)
|
| 496 |
+
objecttable[oid] = obj
|
| 497 |
+
return RemoteProxy(oid)
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
class RemoteProxy:
|
| 501 |
+
|
| 502 |
+
def __init__(self, oid):
|
| 503 |
+
self.oid = oid
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
class RPCHandler(socketserver.BaseRequestHandler, SocketIO):
|
| 507 |
+
|
| 508 |
+
debugging = False
|
| 509 |
+
location = "#S" # Server
|
| 510 |
+
|
| 511 |
+
def __init__(self, sock, addr, svr):
|
| 512 |
+
svr.current_handler = self ## cgt xxx
|
| 513 |
+
SocketIO.__init__(self, sock)
|
| 514 |
+
socketserver.BaseRequestHandler.__init__(self, sock, addr, svr)
|
| 515 |
+
|
| 516 |
+
def handle(self):
|
| 517 |
+
"handle() method required by socketserver"
|
| 518 |
+
self.mainloop()
|
| 519 |
+
|
| 520 |
+
def get_remote_proxy(self, oid):
|
| 521 |
+
return RPCProxy(self, oid)
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
class RPCClient(SocketIO):
|
| 525 |
+
|
| 526 |
+
debugging = False
|
| 527 |
+
location = "#C" # Client
|
| 528 |
+
|
| 529 |
+
nextseq = 1 # Requests coming from the client are odd numbered
|
| 530 |
+
|
| 531 |
+
def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):
|
| 532 |
+
self.listening_sock = socket.socket(family, type)
|
| 533 |
+
self.listening_sock.bind(address)
|
| 534 |
+
self.listening_sock.listen(1)
|
| 535 |
+
|
| 536 |
+
def accept(self):
|
| 537 |
+
working_sock, address = self.listening_sock.accept()
|
| 538 |
+
if self.debugging:
|
| 539 |
+
print("****** Connection request from ", address, file=sys.__stderr__)
|
| 540 |
+
if address[0] == LOCALHOST:
|
| 541 |
+
SocketIO.__init__(self, working_sock)
|
| 542 |
+
else:
|
| 543 |
+
print("** Invalid host: ", address, file=sys.__stderr__)
|
| 544 |
+
raise OSError
|
| 545 |
+
|
| 546 |
+
def get_remote_proxy(self, oid):
|
| 547 |
+
return RPCProxy(self, oid)
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
class RPCProxy:
|
| 551 |
+
|
| 552 |
+
__methods = None
|
| 553 |
+
__attributes = None
|
| 554 |
+
|
| 555 |
+
def __init__(self, sockio, oid):
|
| 556 |
+
self.sockio = sockio
|
| 557 |
+
self.oid = oid
|
| 558 |
+
|
| 559 |
+
def __getattr__(self, name):
|
| 560 |
+
if self.__methods is None:
|
| 561 |
+
self.__getmethods()
|
| 562 |
+
if self.__methods.get(name):
|
| 563 |
+
return MethodProxy(self.sockio, self.oid, name)
|
| 564 |
+
if self.__attributes is None:
|
| 565 |
+
self.__getattributes()
|
| 566 |
+
if name in self.__attributes:
|
| 567 |
+
value = self.sockio.remotecall(self.oid, '__getattribute__',
|
| 568 |
+
(name,), {})
|
| 569 |
+
return value
|
| 570 |
+
else:
|
| 571 |
+
raise AttributeError(name)
|
| 572 |
+
|
| 573 |
+
def __getattributes(self):
|
| 574 |
+
self.__attributes = self.sockio.remotecall(self.oid,
|
| 575 |
+
"__attributes__", (), {})
|
| 576 |
+
|
| 577 |
+
def __getmethods(self):
|
| 578 |
+
self.__methods = self.sockio.remotecall(self.oid,
|
| 579 |
+
"__methods__", (), {})
|
| 580 |
+
|
| 581 |
+
def _getmethods(obj, methods):
|
| 582 |
+
# Helper to get a list of methods from an object
|
| 583 |
+
# Adds names to dictionary argument 'methods'
|
| 584 |
+
for name in dir(obj):
|
| 585 |
+
attr = getattr(obj, name)
|
| 586 |
+
if callable(attr):
|
| 587 |
+
methods[name] = 1
|
| 588 |
+
if isinstance(obj, type):
|
| 589 |
+
for super in obj.__bases__:
|
| 590 |
+
_getmethods(super, methods)
|
| 591 |
+
|
| 592 |
+
def _getattributes(obj, attributes):
|
| 593 |
+
for name in dir(obj):
|
| 594 |
+
attr = getattr(obj, name)
|
| 595 |
+
if not callable(attr):
|
| 596 |
+
attributes[name] = 1
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
class MethodProxy:
|
| 600 |
+
|
| 601 |
+
def __init__(self, sockio, oid, name):
|
| 602 |
+
self.sockio = sockio
|
| 603 |
+
self.oid = oid
|
| 604 |
+
self.name = name
|
| 605 |
+
|
| 606 |
+
def __call__(self, /, *args, **kwargs):
|
| 607 |
+
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
|
| 608 |
+
return value
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
# XXX KBK 09Sep03 We need a proper unit test for this module. Previously
|
| 612 |
+
# existing test code was removed at Rev 1.27 (r34098).
|
| 613 |
+
|
| 614 |
+
def displayhook(value):
|
| 615 |
+
"""Override standard display hook to use non-locale encoding"""
|
| 616 |
+
if value is None:
|
| 617 |
+
return
|
| 618 |
+
# Set '_' to None to avoid recursion
|
| 619 |
+
builtins._ = None
|
| 620 |
+
text = repr(value)
|
| 621 |
+
try:
|
| 622 |
+
sys.stdout.write(text)
|
| 623 |
+
except UnicodeEncodeError:
|
| 624 |
+
# let's use ascii while utf8-bmp codec doesn't present
|
| 625 |
+
encoding = 'ascii'
|
| 626 |
+
bytes = text.encode(encoding, 'backslashreplace')
|
| 627 |
+
text = bytes.decode(encoding, 'strict')
|
| 628 |
+
sys.stdout.write(text)
|
| 629 |
+
sys.stdout.write("\n")
|
| 630 |
+
builtins._ = value
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
if __name__ == '__main__':
|
| 634 |
+
from unittest import main
|
| 635 |
+
main('idlelib.idle_test.test_rpc', verbosity=2,)
|
evalkit_cambrian/lib/python3.10/idlelib/run.py
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" idlelib.run
|
| 2 |
+
|
| 3 |
+
Simplified, pyshell.ModifiedInterpreter spawns a subprocess with
|
| 4 |
+
f'''{sys.executable} -c "__import__('idlelib.run').run.main()"'''
|
| 5 |
+
'.run' is needed because __import__ returns idlelib, not idlelib.run.
|
| 6 |
+
"""
|
| 7 |
+
import contextlib
|
| 8 |
+
import functools
|
| 9 |
+
import io
|
| 10 |
+
import linecache
|
| 11 |
+
import queue
|
| 12 |
+
import sys
|
| 13 |
+
import textwrap
|
| 14 |
+
import time
|
| 15 |
+
import traceback
|
| 16 |
+
import _thread as thread
|
| 17 |
+
import threading
|
| 18 |
+
import warnings
|
| 19 |
+
|
| 20 |
+
import idlelib # testing
|
| 21 |
+
from idlelib import autocomplete # AutoComplete, fetch_encodings
|
| 22 |
+
from idlelib import calltip # Calltip
|
| 23 |
+
from idlelib import debugger_r # start_debugger
|
| 24 |
+
from idlelib import debugobj_r # remote_object_tree_item
|
| 25 |
+
from idlelib import iomenu # encoding
|
| 26 |
+
from idlelib import rpc # multiple objects
|
| 27 |
+
from idlelib import stackviewer # StackTreeItem
|
| 28 |
+
import __main__
|
| 29 |
+
|
| 30 |
+
import tkinter # Use tcl and, if startup fails, messagebox.
|
| 31 |
+
if not hasattr(sys.modules['idlelib.run'], 'firstrun'):
|
| 32 |
+
# Undo modifications of tkinter by idlelib imports; see bpo-25507.
|
| 33 |
+
for mod in ('simpledialog', 'messagebox', 'font',
|
| 34 |
+
'dialog', 'filedialog', 'commondialog',
|
| 35 |
+
'ttk'):
|
| 36 |
+
delattr(tkinter, mod)
|
| 37 |
+
del sys.modules['tkinter.' + mod]
|
| 38 |
+
# Avoid AttributeError if run again; see bpo-37038.
|
| 39 |
+
sys.modules['idlelib.run'].firstrun = False
|
| 40 |
+
|
| 41 |
+
LOCALHOST = '127.0.0.1'
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
eof = 'Ctrl-D (end-of-file)'
|
| 45 |
+
exit.eof = eof
|
| 46 |
+
quit.eof = eof
|
| 47 |
+
except NameError: # In case subprocess started with -S (maybe in future).
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def idle_formatwarning(message, category, filename, lineno, line=None):
|
| 52 |
+
"""Format warnings the IDLE way."""
|
| 53 |
+
|
| 54 |
+
s = "\nWarning (from warnings module):\n"
|
| 55 |
+
s += ' File \"%s\", line %s\n' % (filename, lineno)
|
| 56 |
+
if line is None:
|
| 57 |
+
line = linecache.getline(filename, lineno)
|
| 58 |
+
line = line.strip()
|
| 59 |
+
if line:
|
| 60 |
+
s += " %s\n" % line
|
| 61 |
+
s += "%s: %s\n" % (category.__name__, message)
|
| 62 |
+
return s
|
| 63 |
+
|
| 64 |
+
def idle_showwarning_subproc(
|
| 65 |
+
message, category, filename, lineno, file=None, line=None):
|
| 66 |
+
"""Show Idle-format warning after replacing warnings.showwarning.
|
| 67 |
+
|
| 68 |
+
The only difference is the formatter called.
|
| 69 |
+
"""
|
| 70 |
+
if file is None:
|
| 71 |
+
file = sys.stderr
|
| 72 |
+
try:
|
| 73 |
+
file.write(idle_formatwarning(
|
| 74 |
+
message, category, filename, lineno, line))
|
| 75 |
+
except OSError:
|
| 76 |
+
pass # the file (probably stderr) is invalid - this warning gets lost.
|
| 77 |
+
|
| 78 |
+
_warnings_showwarning = None
|
| 79 |
+
|
| 80 |
+
def capture_warnings(capture):
|
| 81 |
+
"Replace warning.showwarning with idle_showwarning_subproc, or reverse."
|
| 82 |
+
|
| 83 |
+
global _warnings_showwarning
|
| 84 |
+
if capture:
|
| 85 |
+
if _warnings_showwarning is None:
|
| 86 |
+
_warnings_showwarning = warnings.showwarning
|
| 87 |
+
warnings.showwarning = idle_showwarning_subproc
|
| 88 |
+
else:
|
| 89 |
+
if _warnings_showwarning is not None:
|
| 90 |
+
warnings.showwarning = _warnings_showwarning
|
| 91 |
+
_warnings_showwarning = None
|
| 92 |
+
|
| 93 |
+
capture_warnings(True)
|
| 94 |
+
tcl = tkinter.Tcl()
|
| 95 |
+
|
| 96 |
+
def handle_tk_events(tcl=tcl):
|
| 97 |
+
"""Process any tk events that are ready to be dispatched if tkinter
|
| 98 |
+
has been imported, a tcl interpreter has been created and tk has been
|
| 99 |
+
loaded."""
|
| 100 |
+
tcl.eval("update")
|
| 101 |
+
|
| 102 |
+
# Thread shared globals: Establish a queue between a subthread (which handles
|
| 103 |
+
# the socket) and the main thread (which runs user code), plus global
|
| 104 |
+
# completion, exit and interruptable (the main thread) flags:
|
| 105 |
+
|
| 106 |
+
exit_now = False
|
| 107 |
+
quitting = False
|
| 108 |
+
interruptable = False
|
| 109 |
+
|
| 110 |
+
def main(del_exitfunc=False):
|
| 111 |
+
"""Start the Python execution server in a subprocess
|
| 112 |
+
|
| 113 |
+
In the Python subprocess, RPCServer is instantiated with handlerclass
|
| 114 |
+
MyHandler, which inherits register/unregister methods from RPCHandler via
|
| 115 |
+
the mix-in class SocketIO.
|
| 116 |
+
|
| 117 |
+
When the RPCServer 'server' is instantiated, the TCPServer initialization
|
| 118 |
+
creates an instance of run.MyHandler and calls its handle() method.
|
| 119 |
+
handle() instantiates a run.Executive object, passing it a reference to the
|
| 120 |
+
MyHandler object. That reference is saved as attribute rpchandler of the
|
| 121 |
+
Executive instance. The Executive methods have access to the reference and
|
| 122 |
+
can pass it on to entities that they command
|
| 123 |
+
(e.g. debugger_r.Debugger.start_debugger()). The latter, in turn, can
|
| 124 |
+
call MyHandler(SocketIO) register/unregister methods via the reference to
|
| 125 |
+
register and unregister themselves.
|
| 126 |
+
|
| 127 |
+
"""
|
| 128 |
+
global exit_now
|
| 129 |
+
global quitting
|
| 130 |
+
global no_exitfunc
|
| 131 |
+
no_exitfunc = del_exitfunc
|
| 132 |
+
#time.sleep(15) # test subprocess not responding
|
| 133 |
+
try:
|
| 134 |
+
assert(len(sys.argv) > 1)
|
| 135 |
+
port = int(sys.argv[-1])
|
| 136 |
+
except:
|
| 137 |
+
print("IDLE Subprocess: no IP port passed in sys.argv.",
|
| 138 |
+
file=sys.__stderr__)
|
| 139 |
+
return
|
| 140 |
+
|
| 141 |
+
capture_warnings(True)
|
| 142 |
+
sys.argv[:] = [""]
|
| 143 |
+
sockthread = threading.Thread(target=manage_socket,
|
| 144 |
+
name='SockThread',
|
| 145 |
+
args=((LOCALHOST, port),))
|
| 146 |
+
sockthread.daemon = True
|
| 147 |
+
sockthread.start()
|
| 148 |
+
while True:
|
| 149 |
+
try:
|
| 150 |
+
if exit_now:
|
| 151 |
+
try:
|
| 152 |
+
exit()
|
| 153 |
+
except KeyboardInterrupt:
|
| 154 |
+
# exiting but got an extra KBI? Try again!
|
| 155 |
+
continue
|
| 156 |
+
try:
|
| 157 |
+
request = rpc.request_queue.get(block=True, timeout=0.05)
|
| 158 |
+
except queue.Empty:
|
| 159 |
+
request = None
|
| 160 |
+
# Issue 32207: calling handle_tk_events here adds spurious
|
| 161 |
+
# queue.Empty traceback to event handling exceptions.
|
| 162 |
+
if request:
|
| 163 |
+
seq, (method, args, kwargs) = request
|
| 164 |
+
ret = method(*args, **kwargs)
|
| 165 |
+
rpc.response_queue.put((seq, ret))
|
| 166 |
+
else:
|
| 167 |
+
handle_tk_events()
|
| 168 |
+
except KeyboardInterrupt:
|
| 169 |
+
if quitting:
|
| 170 |
+
exit_now = True
|
| 171 |
+
continue
|
| 172 |
+
except SystemExit:
|
| 173 |
+
capture_warnings(False)
|
| 174 |
+
raise
|
| 175 |
+
except:
|
| 176 |
+
type, value, tb = sys.exc_info()
|
| 177 |
+
try:
|
| 178 |
+
print_exception()
|
| 179 |
+
rpc.response_queue.put((seq, None))
|
| 180 |
+
except:
|
| 181 |
+
# Link didn't work, print same exception to __stderr__
|
| 182 |
+
traceback.print_exception(type, value, tb, file=sys.__stderr__)
|
| 183 |
+
exit()
|
| 184 |
+
else:
|
| 185 |
+
continue
|
| 186 |
+
|
| 187 |
+
def manage_socket(address):
|
| 188 |
+
for i in range(3):
|
| 189 |
+
time.sleep(i)
|
| 190 |
+
try:
|
| 191 |
+
server = MyRPCServer(address, MyHandler)
|
| 192 |
+
break
|
| 193 |
+
except OSError as err:
|
| 194 |
+
print("IDLE Subprocess: OSError: " + err.args[1] +
|
| 195 |
+
", retrying....", file=sys.__stderr__)
|
| 196 |
+
socket_error = err
|
| 197 |
+
else:
|
| 198 |
+
print("IDLE Subprocess: Connection to "
|
| 199 |
+
"IDLE GUI failed, exiting.", file=sys.__stderr__)
|
| 200 |
+
show_socket_error(socket_error, address)
|
| 201 |
+
global exit_now
|
| 202 |
+
exit_now = True
|
| 203 |
+
return
|
| 204 |
+
server.handle_request() # A single request only
|
| 205 |
+
|
| 206 |
+
def show_socket_error(err, address):
|
| 207 |
+
"Display socket error from manage_socket."
|
| 208 |
+
import tkinter
|
| 209 |
+
from tkinter.messagebox import showerror
|
| 210 |
+
root = tkinter.Tk()
|
| 211 |
+
fix_scaling(root)
|
| 212 |
+
root.withdraw()
|
| 213 |
+
showerror(
|
| 214 |
+
"Subprocess Connection Error",
|
| 215 |
+
f"IDLE's subprocess can't connect to {address[0]}:{address[1]}.\n"
|
| 216 |
+
f"Fatal OSError #{err.errno}: {err.strerror}.\n"
|
| 217 |
+
"See the 'Startup failure' section of the IDLE doc, online at\n"
|
| 218 |
+
"https://docs.python.org/3/library/idle.html#startup-failure",
|
| 219 |
+
parent=root)
|
| 220 |
+
root.destroy()
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def get_message_lines(typ, exc, tb):
|
| 224 |
+
"Return line composing the exception message."
|
| 225 |
+
if typ in (AttributeError, NameError):
|
| 226 |
+
# 3.10+ hints are not directly accessible from python (#44026).
|
| 227 |
+
err = io.StringIO()
|
| 228 |
+
with contextlib.redirect_stderr(err):
|
| 229 |
+
sys.__excepthook__(typ, exc, tb)
|
| 230 |
+
return [err.getvalue().split("\n")[-2] + "\n"]
|
| 231 |
+
else:
|
| 232 |
+
return traceback.format_exception_only(typ, exc)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def print_exception():
|
| 236 |
+
import linecache
|
| 237 |
+
linecache.checkcache()
|
| 238 |
+
flush_stdout()
|
| 239 |
+
efile = sys.stderr
|
| 240 |
+
typ, val, tb = excinfo = sys.exc_info()
|
| 241 |
+
sys.last_type, sys.last_value, sys.last_traceback = excinfo
|
| 242 |
+
seen = set()
|
| 243 |
+
|
| 244 |
+
def print_exc(typ, exc, tb):
|
| 245 |
+
seen.add(id(exc))
|
| 246 |
+
context = exc.__context__
|
| 247 |
+
cause = exc.__cause__
|
| 248 |
+
if cause is not None and id(cause) not in seen:
|
| 249 |
+
print_exc(type(cause), cause, cause.__traceback__)
|
| 250 |
+
print("\nThe above exception was the direct cause "
|
| 251 |
+
"of the following exception:\n", file=efile)
|
| 252 |
+
elif (context is not None and
|
| 253 |
+
not exc.__suppress_context__ and
|
| 254 |
+
id(context) not in seen):
|
| 255 |
+
print_exc(type(context), context, context.__traceback__)
|
| 256 |
+
print("\nDuring handling of the above exception, "
|
| 257 |
+
"another exception occurred:\n", file=efile)
|
| 258 |
+
if tb:
|
| 259 |
+
tbe = traceback.extract_tb(tb)
|
| 260 |
+
print('Traceback (most recent call last):', file=efile)
|
| 261 |
+
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
|
| 262 |
+
"debugger_r.py", "bdb.py")
|
| 263 |
+
cleanup_traceback(tbe, exclude)
|
| 264 |
+
traceback.print_list(tbe, file=efile)
|
| 265 |
+
lines = get_message_lines(typ, exc, tb)
|
| 266 |
+
for line in lines:
|
| 267 |
+
print(line, end='', file=efile)
|
| 268 |
+
|
| 269 |
+
print_exc(typ, val, tb)
|
| 270 |
+
|
| 271 |
+
def cleanup_traceback(tb, exclude):
|
| 272 |
+
"Remove excluded traces from beginning/end of tb; get cached lines"
|
| 273 |
+
orig_tb = tb[:]
|
| 274 |
+
while tb:
|
| 275 |
+
for rpcfile in exclude:
|
| 276 |
+
if tb[0][0].count(rpcfile):
|
| 277 |
+
break # found an exclude, break for: and delete tb[0]
|
| 278 |
+
else:
|
| 279 |
+
break # no excludes, have left RPC code, break while:
|
| 280 |
+
del tb[0]
|
| 281 |
+
while tb:
|
| 282 |
+
for rpcfile in exclude:
|
| 283 |
+
if tb[-1][0].count(rpcfile):
|
| 284 |
+
break
|
| 285 |
+
else:
|
| 286 |
+
break
|
| 287 |
+
del tb[-1]
|
| 288 |
+
if len(tb) == 0:
|
| 289 |
+
# exception was in IDLE internals, don't prune!
|
| 290 |
+
tb[:] = orig_tb[:]
|
| 291 |
+
print("** IDLE Internal Exception: ", file=sys.stderr)
|
| 292 |
+
rpchandler = rpc.objecttable['exec'].rpchandler
|
| 293 |
+
for i in range(len(tb)):
|
| 294 |
+
fn, ln, nm, line = tb[i]
|
| 295 |
+
if nm == '?':
|
| 296 |
+
nm = "-toplevel-"
|
| 297 |
+
if not line and fn.startswith("<pyshell#"):
|
| 298 |
+
line = rpchandler.remotecall('linecache', 'getline',
|
| 299 |
+
(fn, ln), {})
|
| 300 |
+
tb[i] = fn, ln, nm, line
|
| 301 |
+
|
| 302 |
+
def flush_stdout():
|
| 303 |
+
"""XXX How to do this now?"""
|
| 304 |
+
|
| 305 |
+
def exit():
|
| 306 |
+
"""Exit subprocess, possibly after first clearing exit functions.
|
| 307 |
+
|
| 308 |
+
If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
|
| 309 |
+
functions registered with atexit will be removed before exiting.
|
| 310 |
+
(VPython support)
|
| 311 |
+
|
| 312 |
+
"""
|
| 313 |
+
if no_exitfunc:
|
| 314 |
+
import atexit
|
| 315 |
+
atexit._clear()
|
| 316 |
+
capture_warnings(False)
|
| 317 |
+
sys.exit(0)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def fix_scaling(root):
|
| 321 |
+
"""Scale fonts on HiDPI displays."""
|
| 322 |
+
import tkinter.font
|
| 323 |
+
scaling = float(root.tk.call('tk', 'scaling'))
|
| 324 |
+
if scaling > 1.4:
|
| 325 |
+
for name in tkinter.font.names(root):
|
| 326 |
+
font = tkinter.font.Font(root=root, name=name, exists=True)
|
| 327 |
+
size = int(font['size'])
|
| 328 |
+
if size < 0:
|
| 329 |
+
font['size'] = round(-0.75*size)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def fixdoc(fun, text):
|
| 333 |
+
tem = (fun.__doc__ + '\n\n') if fun.__doc__ is not None else ''
|
| 334 |
+
fun.__doc__ = tem + textwrap.fill(textwrap.dedent(text))
|
| 335 |
+
|
| 336 |
+
RECURSIONLIMIT_DELTA = 30
|
| 337 |
+
|
| 338 |
+
def install_recursionlimit_wrappers():
|
| 339 |
+
"""Install wrappers to always add 30 to the recursion limit."""
|
| 340 |
+
# see: bpo-26806
|
| 341 |
+
|
| 342 |
+
@functools.wraps(sys.setrecursionlimit)
|
| 343 |
+
def setrecursionlimit(*args, **kwargs):
|
| 344 |
+
# mimic the original sys.setrecursionlimit()'s input handling
|
| 345 |
+
if kwargs:
|
| 346 |
+
raise TypeError(
|
| 347 |
+
"setrecursionlimit() takes no keyword arguments")
|
| 348 |
+
try:
|
| 349 |
+
limit, = args
|
| 350 |
+
except ValueError:
|
| 351 |
+
raise TypeError(f"setrecursionlimit() takes exactly one "
|
| 352 |
+
f"argument ({len(args)} given)")
|
| 353 |
+
if not limit > 0:
|
| 354 |
+
raise ValueError(
|
| 355 |
+
"recursion limit must be greater or equal than 1")
|
| 356 |
+
|
| 357 |
+
return setrecursionlimit.__wrapped__(limit + RECURSIONLIMIT_DELTA)
|
| 358 |
+
|
| 359 |
+
fixdoc(setrecursionlimit, f"""\
|
| 360 |
+
This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible
|
| 361 |
+
uninterruptible loops.""")
|
| 362 |
+
|
| 363 |
+
@functools.wraps(sys.getrecursionlimit)
|
| 364 |
+
def getrecursionlimit():
|
| 365 |
+
return getrecursionlimit.__wrapped__() - RECURSIONLIMIT_DELTA
|
| 366 |
+
|
| 367 |
+
fixdoc(getrecursionlimit, f"""\
|
| 368 |
+
This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate
|
| 369 |
+
for the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit.""")
|
| 370 |
+
|
| 371 |
+
# add the delta to the default recursion limit, to compensate
|
| 372 |
+
sys.setrecursionlimit(sys.getrecursionlimit() + RECURSIONLIMIT_DELTA)
|
| 373 |
+
|
| 374 |
+
sys.setrecursionlimit = setrecursionlimit
|
| 375 |
+
sys.getrecursionlimit = getrecursionlimit
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def uninstall_recursionlimit_wrappers():
|
| 379 |
+
"""Uninstall the recursion limit wrappers from the sys module.
|
| 380 |
+
|
| 381 |
+
IDLE only uses this for tests. Users can import run and call
|
| 382 |
+
this to remove the wrapping.
|
| 383 |
+
"""
|
| 384 |
+
if (
|
| 385 |
+
getattr(sys.setrecursionlimit, '__wrapped__', None) and
|
| 386 |
+
getattr(sys.getrecursionlimit, '__wrapped__', None)
|
| 387 |
+
):
|
| 388 |
+
sys.setrecursionlimit = sys.setrecursionlimit.__wrapped__
|
| 389 |
+
sys.getrecursionlimit = sys.getrecursionlimit.__wrapped__
|
| 390 |
+
sys.setrecursionlimit(sys.getrecursionlimit() - RECURSIONLIMIT_DELTA)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class MyRPCServer(rpc.RPCServer):
|
| 394 |
+
|
| 395 |
+
def handle_error(self, request, client_address):
|
| 396 |
+
"""Override RPCServer method for IDLE
|
| 397 |
+
|
| 398 |
+
Interrupt the MainThread and exit server if link is dropped.
|
| 399 |
+
|
| 400 |
+
"""
|
| 401 |
+
global quitting
|
| 402 |
+
try:
|
| 403 |
+
raise
|
| 404 |
+
except SystemExit:
|
| 405 |
+
raise
|
| 406 |
+
except EOFError:
|
| 407 |
+
global exit_now
|
| 408 |
+
exit_now = True
|
| 409 |
+
thread.interrupt_main()
|
| 410 |
+
except:
|
| 411 |
+
erf = sys.__stderr__
|
| 412 |
+
print(textwrap.dedent(f"""
|
| 413 |
+
{'-'*40}
|
| 414 |
+
Unhandled exception in user code execution server!'
|
| 415 |
+
Thread: {threading.current_thread().name}
|
| 416 |
+
IDLE Client Address: {client_address}
|
| 417 |
+
Request: {request!r}
|
| 418 |
+
"""), file=erf)
|
| 419 |
+
traceback.print_exc(limit=-20, file=erf)
|
| 420 |
+
print(textwrap.dedent(f"""
|
| 421 |
+
*** Unrecoverable, server exiting!
|
| 422 |
+
|
| 423 |
+
Users should never see this message; it is likely transient.
|
| 424 |
+
If this recurs, report this with a copy of the message
|
| 425 |
+
and an explanation of how to make it repeat.
|
| 426 |
+
{'-'*40}"""), file=erf)
|
| 427 |
+
quitting = True
|
| 428 |
+
thread.interrupt_main()
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
# Pseudofiles for shell-remote communication (also used in pyshell)
|
| 432 |
+
|
| 433 |
+
class StdioFile(io.TextIOBase):
|
| 434 |
+
|
| 435 |
+
def __init__(self, shell, tags, encoding='utf-8', errors='strict'):
|
| 436 |
+
self.shell = shell
|
| 437 |
+
self.tags = tags
|
| 438 |
+
self._encoding = encoding
|
| 439 |
+
self._errors = errors
|
| 440 |
+
|
| 441 |
+
@property
|
| 442 |
+
def encoding(self):
|
| 443 |
+
return self._encoding
|
| 444 |
+
|
| 445 |
+
@property
|
| 446 |
+
def errors(self):
|
| 447 |
+
return self._errors
|
| 448 |
+
|
| 449 |
+
@property
|
| 450 |
+
def name(self):
|
| 451 |
+
return '<%s>' % self.tags
|
| 452 |
+
|
| 453 |
+
def isatty(self):
|
| 454 |
+
return True
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
class StdOutputFile(StdioFile):
|
| 458 |
+
|
| 459 |
+
def writable(self):
|
| 460 |
+
return True
|
| 461 |
+
|
| 462 |
+
def write(self, s):
|
| 463 |
+
if self.closed:
|
| 464 |
+
raise ValueError("write to closed file")
|
| 465 |
+
s = str.encode(s, self.encoding, self.errors).decode(self.encoding, self.errors)
|
| 466 |
+
return self.shell.write(s, self.tags)
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
class StdInputFile(StdioFile):
|
| 470 |
+
_line_buffer = ''
|
| 471 |
+
|
| 472 |
+
def readable(self):
|
| 473 |
+
return True
|
| 474 |
+
|
| 475 |
+
def read(self, size=-1):
|
| 476 |
+
if self.closed:
|
| 477 |
+
raise ValueError("read from closed file")
|
| 478 |
+
if size is None:
|
| 479 |
+
size = -1
|
| 480 |
+
elif not isinstance(size, int):
|
| 481 |
+
raise TypeError('must be int, not ' + type(size).__name__)
|
| 482 |
+
result = self._line_buffer
|
| 483 |
+
self._line_buffer = ''
|
| 484 |
+
if size < 0:
|
| 485 |
+
while line := self.shell.readline():
|
| 486 |
+
result += line
|
| 487 |
+
else:
|
| 488 |
+
while len(result) < size:
|
| 489 |
+
line = self.shell.readline()
|
| 490 |
+
if not line: break
|
| 491 |
+
result += line
|
| 492 |
+
self._line_buffer = result[size:]
|
| 493 |
+
result = result[:size]
|
| 494 |
+
return result
|
| 495 |
+
|
| 496 |
+
def readline(self, size=-1):
|
| 497 |
+
if self.closed:
|
| 498 |
+
raise ValueError("read from closed file")
|
| 499 |
+
if size is None:
|
| 500 |
+
size = -1
|
| 501 |
+
elif not isinstance(size, int):
|
| 502 |
+
raise TypeError('must be int, not ' + type(size).__name__)
|
| 503 |
+
line = self._line_buffer or self.shell.readline()
|
| 504 |
+
if size < 0:
|
| 505 |
+
size = len(line)
|
| 506 |
+
eol = line.find('\n', 0, size)
|
| 507 |
+
if eol >= 0:
|
| 508 |
+
size = eol + 1
|
| 509 |
+
self._line_buffer = line[size:]
|
| 510 |
+
return line[:size]
|
| 511 |
+
|
| 512 |
+
def close(self):
|
| 513 |
+
self.shell.close()
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
class MyHandler(rpc.RPCHandler):
|
| 517 |
+
|
| 518 |
+
def handle(self):
|
| 519 |
+
"""Override base method"""
|
| 520 |
+
executive = Executive(self)
|
| 521 |
+
self.register("exec", executive)
|
| 522 |
+
self.console = self.get_remote_proxy("console")
|
| 523 |
+
sys.stdin = StdInputFile(self.console, "stdin",
|
| 524 |
+
iomenu.encoding, iomenu.errors)
|
| 525 |
+
sys.stdout = StdOutputFile(self.console, "stdout",
|
| 526 |
+
iomenu.encoding, iomenu.errors)
|
| 527 |
+
sys.stderr = StdOutputFile(self.console, "stderr",
|
| 528 |
+
iomenu.encoding, "backslashreplace")
|
| 529 |
+
|
| 530 |
+
sys.displayhook = rpc.displayhook
|
| 531 |
+
# page help() text to shell.
|
| 532 |
+
import pydoc # import must be done here to capture i/o binding
|
| 533 |
+
pydoc.pager = pydoc.plainpager
|
| 534 |
+
|
| 535 |
+
# Keep a reference to stdin so that it won't try to exit IDLE if
|
| 536 |
+
# sys.stdin gets changed from within IDLE's shell. See issue17838.
|
| 537 |
+
self._keep_stdin = sys.stdin
|
| 538 |
+
|
| 539 |
+
install_recursionlimit_wrappers()
|
| 540 |
+
|
| 541 |
+
self.interp = self.get_remote_proxy("interp")
|
| 542 |
+
rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)
|
| 543 |
+
|
| 544 |
+
def exithook(self):
|
| 545 |
+
"override SocketIO method - wait for MainThread to shut us down"
|
| 546 |
+
time.sleep(10)
|
| 547 |
+
|
| 548 |
+
def EOFhook(self):
|
| 549 |
+
"Override SocketIO method - terminate wait on callback and exit thread"
|
| 550 |
+
global quitting
|
| 551 |
+
quitting = True
|
| 552 |
+
thread.interrupt_main()
|
| 553 |
+
|
| 554 |
+
def decode_interrupthook(self):
|
| 555 |
+
"interrupt awakened thread"
|
| 556 |
+
global quitting
|
| 557 |
+
quitting = True
|
| 558 |
+
thread.interrupt_main()
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
class Executive:
|
| 562 |
+
|
| 563 |
+
def __init__(self, rpchandler):
|
| 564 |
+
self.rpchandler = rpchandler
|
| 565 |
+
if idlelib.testing is False:
|
| 566 |
+
self.locals = __main__.__dict__
|
| 567 |
+
self.calltip = calltip.Calltip()
|
| 568 |
+
self.autocomplete = autocomplete.AutoComplete()
|
| 569 |
+
else:
|
| 570 |
+
self.locals = {}
|
| 571 |
+
|
| 572 |
+
def runcode(self, code):
|
| 573 |
+
global interruptable
|
| 574 |
+
try:
|
| 575 |
+
self.user_exc_info = None
|
| 576 |
+
interruptable = True
|
| 577 |
+
try:
|
| 578 |
+
exec(code, self.locals)
|
| 579 |
+
finally:
|
| 580 |
+
interruptable = False
|
| 581 |
+
except SystemExit as e:
|
| 582 |
+
if e.args: # SystemExit called with an argument.
|
| 583 |
+
ob = e.args[0]
|
| 584 |
+
if not isinstance(ob, (type(None), int)):
|
| 585 |
+
print('SystemExit: ' + str(ob), file=sys.stderr)
|
| 586 |
+
# Return to the interactive prompt.
|
| 587 |
+
except:
|
| 588 |
+
self.user_exc_info = sys.exc_info() # For testing, hook, viewer.
|
| 589 |
+
if quitting:
|
| 590 |
+
exit()
|
| 591 |
+
if sys.excepthook is sys.__excepthook__:
|
| 592 |
+
print_exception()
|
| 593 |
+
else:
|
| 594 |
+
try:
|
| 595 |
+
sys.excepthook(*self.user_exc_info)
|
| 596 |
+
except:
|
| 597 |
+
self.user_exc_info = sys.exc_info() # For testing.
|
| 598 |
+
print_exception()
|
| 599 |
+
jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
|
| 600 |
+
if jit:
|
| 601 |
+
self.rpchandler.interp.open_remote_stack_viewer()
|
| 602 |
+
else:
|
| 603 |
+
flush_stdout()
|
| 604 |
+
|
| 605 |
+
def interrupt_the_server(self):
|
| 606 |
+
if interruptable:
|
| 607 |
+
thread.interrupt_main()
|
| 608 |
+
|
| 609 |
+
def start_the_debugger(self, gui_adap_oid):
|
| 610 |
+
return debugger_r.start_debugger(self.rpchandler, gui_adap_oid)
|
| 611 |
+
|
| 612 |
+
def stop_the_debugger(self, idb_adap_oid):
|
| 613 |
+
"Unregister the Idb Adapter. Link objects and Idb then subject to GC"
|
| 614 |
+
self.rpchandler.unregister(idb_adap_oid)
|
| 615 |
+
|
| 616 |
+
def get_the_calltip(self, name):
|
| 617 |
+
return self.calltip.fetch_tip(name)
|
| 618 |
+
|
| 619 |
+
def get_the_completion_list(self, what, mode):
|
| 620 |
+
return self.autocomplete.fetch_completions(what, mode)
|
| 621 |
+
|
| 622 |
+
def stackviewer(self, flist_oid=None):
|
| 623 |
+
if self.user_exc_info:
|
| 624 |
+
typ, val, tb = self.user_exc_info
|
| 625 |
+
else:
|
| 626 |
+
return None
|
| 627 |
+
flist = None
|
| 628 |
+
if flist_oid is not None:
|
| 629 |
+
flist = self.rpchandler.get_remote_proxy(flist_oid)
|
| 630 |
+
while tb and tb.tb_frame.f_globals["__name__"] in ["rpc", "run"]:
|
| 631 |
+
tb = tb.tb_next
|
| 632 |
+
sys.last_type = typ
|
| 633 |
+
sys.last_value = val
|
| 634 |
+
item = stackviewer.StackTreeItem(flist, tb)
|
| 635 |
+
return debugobj_r.remote_object_tree_item(item)
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
if __name__ == '__main__':
|
| 639 |
+
from unittest import main
|
| 640 |
+
main('idlelib.idle_test.test_run', verbosity=2)
|
| 641 |
+
|
| 642 |
+
capture_warnings(False) # Make sure turned off; see bpo-18081.
|
evalkit_cambrian/lib/python3.10/idlelib/runscript.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Execute code from an editor.
|
| 2 |
+
|
| 3 |
+
Check module: do a full syntax check of the current module.
|
| 4 |
+
Also run the tabnanny to catch any inconsistent tabs.
|
| 5 |
+
|
| 6 |
+
Run module: also execute the module's code in the __main__ namespace.
|
| 7 |
+
The window must have been saved previously. The module is added to
|
| 8 |
+
sys.modules, and is also added to the __main__ namespace.
|
| 9 |
+
|
| 10 |
+
TODO: Specify command line arguments in a dialog box.
|
| 11 |
+
"""
|
| 12 |
+
import os
|
| 13 |
+
import tabnanny
|
| 14 |
+
import time
|
| 15 |
+
import tokenize
|
| 16 |
+
|
| 17 |
+
from tkinter import messagebox
|
| 18 |
+
|
| 19 |
+
from idlelib.config import idleConf
|
| 20 |
+
from idlelib import macosx
|
| 21 |
+
from idlelib import pyshell
|
| 22 |
+
from idlelib.query import CustomRun
|
| 23 |
+
from idlelib import outwin
|
| 24 |
+
|
| 25 |
+
indent_message = """Error: Inconsistent indentation detected!
|
| 26 |
+
|
| 27 |
+
1) Your indentation is outright incorrect (easy to fix), OR
|
| 28 |
+
|
| 29 |
+
2) Your indentation mixes tabs and spaces.
|
| 30 |
+
|
| 31 |
+
To fix case 2, change all tabs to spaces by using Edit->Select All followed \
|
| 32 |
+
by Format->Untabify Region and specify the number of columns used by each tab.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class ScriptBinding:
|
| 37 |
+
|
| 38 |
+
def __init__(self, editwin):
|
| 39 |
+
self.editwin = editwin
|
| 40 |
+
# Provide instance variables referenced by debugger
|
| 41 |
+
# XXX This should be done differently
|
| 42 |
+
self.flist = self.editwin.flist
|
| 43 |
+
self.root = self.editwin.root
|
| 44 |
+
# cli_args is list of strings that extends sys.argv
|
| 45 |
+
self.cli_args = []
|
| 46 |
+
self.perf = 0.0 # Workaround for macOS 11 Uni2; see bpo-42508.
|
| 47 |
+
|
| 48 |
+
def check_module_event(self, event):
|
| 49 |
+
if isinstance(self.editwin, outwin.OutputWindow):
|
| 50 |
+
self.editwin.text.bell()
|
| 51 |
+
return 'break'
|
| 52 |
+
filename = self.getfilename()
|
| 53 |
+
if not filename:
|
| 54 |
+
return 'break'
|
| 55 |
+
if not self.checksyntax(filename):
|
| 56 |
+
return 'break'
|
| 57 |
+
if not self.tabnanny(filename):
|
| 58 |
+
return 'break'
|
| 59 |
+
return "break"
|
| 60 |
+
|
| 61 |
+
def tabnanny(self, filename):
|
| 62 |
+
# XXX: tabnanny should work on binary files as well
|
| 63 |
+
with tokenize.open(filename) as f:
|
| 64 |
+
try:
|
| 65 |
+
tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
|
| 66 |
+
except tokenize.TokenError as msg:
|
| 67 |
+
msgtxt, (lineno, start) = msg.args
|
| 68 |
+
self.editwin.gotoline(lineno)
|
| 69 |
+
self.errorbox("Tabnanny Tokenizing Error",
|
| 70 |
+
"Token Error: %s" % msgtxt)
|
| 71 |
+
return False
|
| 72 |
+
except tabnanny.NannyNag as nag:
|
| 73 |
+
# The error messages from tabnanny are too confusing...
|
| 74 |
+
self.editwin.gotoline(nag.get_lineno())
|
| 75 |
+
self.errorbox("Tab/space error", indent_message)
|
| 76 |
+
return False
|
| 77 |
+
return True
|
| 78 |
+
|
| 79 |
+
def checksyntax(self, filename):
|
| 80 |
+
self.shell = shell = self.flist.open_shell()
|
| 81 |
+
saved_stream = shell.get_warning_stream()
|
| 82 |
+
shell.set_warning_stream(shell.stderr)
|
| 83 |
+
with open(filename, 'rb') as f:
|
| 84 |
+
source = f.read()
|
| 85 |
+
if b'\r' in source:
|
| 86 |
+
source = source.replace(b'\r\n', b'\n')
|
| 87 |
+
source = source.replace(b'\r', b'\n')
|
| 88 |
+
if source and source[-1] != ord(b'\n'):
|
| 89 |
+
source = source + b'\n'
|
| 90 |
+
editwin = self.editwin
|
| 91 |
+
text = editwin.text
|
| 92 |
+
text.tag_remove("ERROR", "1.0", "end")
|
| 93 |
+
try:
|
| 94 |
+
# If successful, return the compiled code
|
| 95 |
+
return compile(source, filename, "exec")
|
| 96 |
+
except (SyntaxError, OverflowError, ValueError) as value:
|
| 97 |
+
msg = getattr(value, 'msg', '') or value or "<no detail available>"
|
| 98 |
+
lineno = getattr(value, 'lineno', '') or 1
|
| 99 |
+
offset = getattr(value, 'offset', '') or 0
|
| 100 |
+
if offset == 0:
|
| 101 |
+
lineno += 1 #mark end of offending line
|
| 102 |
+
pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)
|
| 103 |
+
editwin.colorize_syntax_error(text, pos)
|
| 104 |
+
self.errorbox("SyntaxError", "%-20s" % msg)
|
| 105 |
+
return False
|
| 106 |
+
finally:
|
| 107 |
+
shell.set_warning_stream(saved_stream)
|
| 108 |
+
|
| 109 |
+
def run_custom_event(self, event):
|
| 110 |
+
return self.run_module_event(event, customize=True)
|
| 111 |
+
|
| 112 |
+
def run_module_event(self, event, *, customize=False):
|
| 113 |
+
"""Run the module after setting up the environment.
|
| 114 |
+
|
| 115 |
+
First check the syntax. Next get customization. If OK, make
|
| 116 |
+
sure the shell is active and then transfer the arguments, set
|
| 117 |
+
the run environment's working directory to the directory of the
|
| 118 |
+
module being executed and also add that directory to its
|
| 119 |
+
sys.path if not already included.
|
| 120 |
+
"""
|
| 121 |
+
if macosx.isCocoaTk() and (time.perf_counter() - self.perf < .05):
|
| 122 |
+
return 'break'
|
| 123 |
+
if isinstance(self.editwin, outwin.OutputWindow):
|
| 124 |
+
self.editwin.text.bell()
|
| 125 |
+
return 'break'
|
| 126 |
+
filename = self.getfilename()
|
| 127 |
+
if not filename:
|
| 128 |
+
return 'break'
|
| 129 |
+
code = self.checksyntax(filename)
|
| 130 |
+
if not code:
|
| 131 |
+
return 'break'
|
| 132 |
+
if not self.tabnanny(filename):
|
| 133 |
+
return 'break'
|
| 134 |
+
if customize:
|
| 135 |
+
title = f"Customize {self.editwin.short_title()} Run"
|
| 136 |
+
run_args = CustomRun(self.shell.text, title,
|
| 137 |
+
cli_args=self.cli_args).result
|
| 138 |
+
if not run_args: # User cancelled.
|
| 139 |
+
return 'break'
|
| 140 |
+
self.cli_args, restart = run_args if customize else ([], True)
|
| 141 |
+
interp = self.shell.interp
|
| 142 |
+
if pyshell.use_subprocess and restart:
|
| 143 |
+
interp.restart_subprocess(
|
| 144 |
+
with_cwd=False, filename=filename)
|
| 145 |
+
dirname = os.path.dirname(filename)
|
| 146 |
+
argv = [filename]
|
| 147 |
+
if self.cli_args:
|
| 148 |
+
argv += self.cli_args
|
| 149 |
+
interp.runcommand(f"""if 1:
|
| 150 |
+
__file__ = {filename!r}
|
| 151 |
+
import sys as _sys
|
| 152 |
+
from os.path import basename as _basename
|
| 153 |
+
argv = {argv!r}
|
| 154 |
+
if (not _sys.argv or
|
| 155 |
+
_basename(_sys.argv[0]) != _basename(__file__) or
|
| 156 |
+
len(argv) > 1):
|
| 157 |
+
_sys.argv = argv
|
| 158 |
+
import os as _os
|
| 159 |
+
_os.chdir({dirname!r})
|
| 160 |
+
del _sys, argv, _basename, _os
|
| 161 |
+
\n""")
|
| 162 |
+
interp.prepend_syspath(filename)
|
| 163 |
+
# XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
|
| 164 |
+
# go to __stderr__. With subprocess, they go to the shell.
|
| 165 |
+
# Need to change streams in pyshell.ModifiedInterpreter.
|
| 166 |
+
interp.runcode(code)
|
| 167 |
+
return 'break'
|
| 168 |
+
|
| 169 |
+
def getfilename(self):
|
| 170 |
+
"""Get source filename. If not saved, offer to save (or create) file
|
| 171 |
+
|
| 172 |
+
The debugger requires a source file. Make sure there is one, and that
|
| 173 |
+
the current version of the source buffer has been saved. If the user
|
| 174 |
+
declines to save or cancels the Save As dialog, return None.
|
| 175 |
+
|
| 176 |
+
If the user has configured IDLE for Autosave, the file will be
|
| 177 |
+
silently saved if it already exists and is dirty.
|
| 178 |
+
|
| 179 |
+
"""
|
| 180 |
+
filename = self.editwin.io.filename
|
| 181 |
+
if not self.editwin.get_saved():
|
| 182 |
+
autosave = idleConf.GetOption('main', 'General',
|
| 183 |
+
'autosave', type='bool')
|
| 184 |
+
if autosave and filename:
|
| 185 |
+
self.editwin.io.save(None)
|
| 186 |
+
else:
|
| 187 |
+
confirm = self.ask_save_dialog()
|
| 188 |
+
self.editwin.text.focus_set()
|
| 189 |
+
if confirm:
|
| 190 |
+
self.editwin.io.save(None)
|
| 191 |
+
filename = self.editwin.io.filename
|
| 192 |
+
else:
|
| 193 |
+
filename = None
|
| 194 |
+
return filename
|
| 195 |
+
|
| 196 |
+
def ask_save_dialog(self):
|
| 197 |
+
msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?"
|
| 198 |
+
confirm = messagebox.askokcancel(title="Save Before Run or Check",
|
| 199 |
+
message=msg,
|
| 200 |
+
default=messagebox.OK,
|
| 201 |
+
parent=self.editwin.text)
|
| 202 |
+
return confirm
|
| 203 |
+
|
| 204 |
+
def errorbox(self, title, message):
|
| 205 |
+
# XXX This should really be a function of EditorWindow...
|
| 206 |
+
messagebox.showerror(title, message, parent=self.editwin.text)
|
| 207 |
+
self.editwin.text.focus_set()
|
| 208 |
+
self.perf = time.perf_counter()
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
if __name__ == "__main__":
|
| 212 |
+
from unittest import main
|
| 213 |
+
main('idlelib.idle_test.test_runscript', verbosity=2,)
|
evalkit_cambrian/lib/python3.10/idlelib/scrolledlist.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tkinter import *
|
| 2 |
+
from tkinter.ttk import Frame, Scrollbar
|
| 3 |
+
|
| 4 |
+
from idlelib import macosx
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ScrolledList:
|
| 8 |
+
|
| 9 |
+
default = "(None)"
|
| 10 |
+
|
| 11 |
+
def __init__(self, master, **options):
|
| 12 |
+
# Create top frame, with scrollbar and listbox
|
| 13 |
+
self.master = master
|
| 14 |
+
self.frame = frame = Frame(master)
|
| 15 |
+
self.frame.pack(fill="both", expand=1)
|
| 16 |
+
self.vbar = vbar = Scrollbar(frame, name="vbar")
|
| 17 |
+
self.vbar.pack(side="right", fill="y")
|
| 18 |
+
self.listbox = listbox = Listbox(frame, exportselection=0,
|
| 19 |
+
background="white")
|
| 20 |
+
if options:
|
| 21 |
+
listbox.configure(options)
|
| 22 |
+
listbox.pack(expand=1, fill="both")
|
| 23 |
+
# Tie listbox and scrollbar together
|
| 24 |
+
vbar["command"] = listbox.yview
|
| 25 |
+
listbox["yscrollcommand"] = vbar.set
|
| 26 |
+
# Bind events to the list box
|
| 27 |
+
listbox.bind("<ButtonRelease-1>", self.click_event)
|
| 28 |
+
listbox.bind("<Double-ButtonRelease-1>", self.double_click_event)
|
| 29 |
+
if macosx.isAquaTk():
|
| 30 |
+
listbox.bind("<ButtonPress-2>", self.popup_event)
|
| 31 |
+
listbox.bind("<Control-Button-1>", self.popup_event)
|
| 32 |
+
else:
|
| 33 |
+
listbox.bind("<ButtonPress-3>", self.popup_event)
|
| 34 |
+
listbox.bind("<Key-Up>", self.up_event)
|
| 35 |
+
listbox.bind("<Key-Down>", self.down_event)
|
| 36 |
+
# Mark as empty
|
| 37 |
+
self.clear()
|
| 38 |
+
|
| 39 |
+
def close(self):
|
| 40 |
+
self.frame.destroy()
|
| 41 |
+
|
| 42 |
+
def clear(self):
|
| 43 |
+
self.listbox.delete(0, "end")
|
| 44 |
+
self.empty = 1
|
| 45 |
+
self.listbox.insert("end", self.default)
|
| 46 |
+
|
| 47 |
+
def append(self, item):
|
| 48 |
+
if self.empty:
|
| 49 |
+
self.listbox.delete(0, "end")
|
| 50 |
+
self.empty = 0
|
| 51 |
+
self.listbox.insert("end", str(item))
|
| 52 |
+
|
| 53 |
+
def get(self, index):
|
| 54 |
+
return self.listbox.get(index)
|
| 55 |
+
|
| 56 |
+
def click_event(self, event):
|
| 57 |
+
self.listbox.activate("@%d,%d" % (event.x, event.y))
|
| 58 |
+
index = self.listbox.index("active")
|
| 59 |
+
self.select(index)
|
| 60 |
+
self.on_select(index)
|
| 61 |
+
return "break"
|
| 62 |
+
|
| 63 |
+
def double_click_event(self, event):
|
| 64 |
+
index = self.listbox.index("active")
|
| 65 |
+
self.select(index)
|
| 66 |
+
self.on_double(index)
|
| 67 |
+
return "break"
|
| 68 |
+
|
| 69 |
+
menu = None
|
| 70 |
+
|
| 71 |
+
def popup_event(self, event):
|
| 72 |
+
if not self.menu:
|
| 73 |
+
self.make_menu()
|
| 74 |
+
menu = self.menu
|
| 75 |
+
self.listbox.activate("@%d,%d" % (event.x, event.y))
|
| 76 |
+
index = self.listbox.index("active")
|
| 77 |
+
self.select(index)
|
| 78 |
+
menu.tk_popup(event.x_root, event.y_root)
|
| 79 |
+
return "break"
|
| 80 |
+
|
| 81 |
+
def make_menu(self):
|
| 82 |
+
menu = Menu(self.listbox, tearoff=0)
|
| 83 |
+
self.menu = menu
|
| 84 |
+
self.fill_menu()
|
| 85 |
+
|
| 86 |
+
def up_event(self, event):
|
| 87 |
+
index = self.listbox.index("active")
|
| 88 |
+
if self.listbox.selection_includes(index):
|
| 89 |
+
index = index - 1
|
| 90 |
+
else:
|
| 91 |
+
index = self.listbox.size() - 1
|
| 92 |
+
if index < 0:
|
| 93 |
+
self.listbox.bell()
|
| 94 |
+
else:
|
| 95 |
+
self.select(index)
|
| 96 |
+
self.on_select(index)
|
| 97 |
+
return "break"
|
| 98 |
+
|
| 99 |
+
def down_event(self, event):
|
| 100 |
+
index = self.listbox.index("active")
|
| 101 |
+
if self.listbox.selection_includes(index):
|
| 102 |
+
index = index + 1
|
| 103 |
+
else:
|
| 104 |
+
index = 0
|
| 105 |
+
if index >= self.listbox.size():
|
| 106 |
+
self.listbox.bell()
|
| 107 |
+
else:
|
| 108 |
+
self.select(index)
|
| 109 |
+
self.on_select(index)
|
| 110 |
+
return "break"
|
| 111 |
+
|
| 112 |
+
def select(self, index):
|
| 113 |
+
self.listbox.focus_set()
|
| 114 |
+
self.listbox.activate(index)
|
| 115 |
+
self.listbox.selection_clear(0, "end")
|
| 116 |
+
self.listbox.selection_set(index)
|
| 117 |
+
self.listbox.see(index)
|
| 118 |
+
|
| 119 |
+
# Methods to override for specific actions
|
| 120 |
+
|
| 121 |
+
def fill_menu(self):
|
| 122 |
+
pass
|
| 123 |
+
|
| 124 |
+
def on_select(self, index):
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
def on_double(self, index):
|
| 128 |
+
pass
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _scrolled_list(parent): # htest #
|
| 132 |
+
top = Toplevel(parent)
|
| 133 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 134 |
+
top.geometry("+%d+%d" % (x+200, y + 175))
|
| 135 |
+
class MyScrolledList(ScrolledList):
|
| 136 |
+
def fill_menu(self): self.menu.add_command(label="right click")
|
| 137 |
+
def on_select(self, index): print("select", self.get(index))
|
| 138 |
+
def on_double(self, index): print("double", self.get(index))
|
| 139 |
+
|
| 140 |
+
scrolled_list = MyScrolledList(top)
|
| 141 |
+
for i in range(30):
|
| 142 |
+
scrolled_list.append("Item %02d" % i)
|
| 143 |
+
|
| 144 |
+
if __name__ == '__main__':
|
| 145 |
+
from unittest import main
|
| 146 |
+
main('idlelib.idle_test.test_scrolledlist', verbosity=2,)
|
| 147 |
+
|
| 148 |
+
from idlelib.idle_test.htest import run
|
| 149 |
+
run(_scrolled_list)
|
evalkit_cambrian/lib/python3.10/idlelib/search.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Search dialog for Find, Find Again, and Find Selection
|
| 2 |
+
functionality.
|
| 3 |
+
|
| 4 |
+
Inherits from SearchDialogBase for GUI and uses searchengine
|
| 5 |
+
to prepare search pattern.
|
| 6 |
+
"""
|
| 7 |
+
from tkinter import TclError
|
| 8 |
+
|
| 9 |
+
from idlelib import searchengine
|
| 10 |
+
from idlelib.searchbase import SearchDialogBase
|
| 11 |
+
|
| 12 |
+
def _setup(text):
|
| 13 |
+
"""Return the new or existing singleton SearchDialog instance.
|
| 14 |
+
|
| 15 |
+
The singleton dialog saves user entries and preferences
|
| 16 |
+
across instances.
|
| 17 |
+
|
| 18 |
+
Args:
|
| 19 |
+
text: Text widget containing the text to be searched.
|
| 20 |
+
"""
|
| 21 |
+
root = text._root()
|
| 22 |
+
engine = searchengine.get(root)
|
| 23 |
+
if not hasattr(engine, "_searchdialog"):
|
| 24 |
+
engine._searchdialog = SearchDialog(root, engine)
|
| 25 |
+
return engine._searchdialog
|
| 26 |
+
|
| 27 |
+
def find(text):
|
| 28 |
+
"""Open the search dialog.
|
| 29 |
+
|
| 30 |
+
Module-level function to access the singleton SearchDialog
|
| 31 |
+
instance and open the dialog. If text is selected, it is
|
| 32 |
+
used as the search phrase; otherwise, the previous entry
|
| 33 |
+
is used. No search is done with this command.
|
| 34 |
+
"""
|
| 35 |
+
pat = text.get("sel.first", "sel.last")
|
| 36 |
+
return _setup(text).open(text, pat) # Open is inherited from SDBase.
|
| 37 |
+
|
| 38 |
+
def find_again(text):
|
| 39 |
+
"""Repeat the search for the last pattern and preferences.
|
| 40 |
+
|
| 41 |
+
Module-level function to access the singleton SearchDialog
|
| 42 |
+
instance to search again using the user entries and preferences
|
| 43 |
+
from the last dialog. If there was no prior search, open the
|
| 44 |
+
search dialog; otherwise, perform the search without showing the
|
| 45 |
+
dialog.
|
| 46 |
+
"""
|
| 47 |
+
return _setup(text).find_again(text)
|
| 48 |
+
|
| 49 |
+
def find_selection(text):
|
| 50 |
+
"""Search for the selected pattern in the text.
|
| 51 |
+
|
| 52 |
+
Module-level function to access the singleton SearchDialog
|
| 53 |
+
instance to search using the selected text. With a text
|
| 54 |
+
selection, perform the search without displaying the dialog.
|
| 55 |
+
Without a selection, use the prior entry as the search phrase
|
| 56 |
+
and don't display the dialog. If there has been no prior
|
| 57 |
+
search, open the search dialog.
|
| 58 |
+
"""
|
| 59 |
+
return _setup(text).find_selection(text)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class SearchDialog(SearchDialogBase):
|
| 63 |
+
"Dialog for finding a pattern in text."
|
| 64 |
+
|
| 65 |
+
def create_widgets(self):
|
| 66 |
+
"Create the base search dialog and add a button for Find Next."
|
| 67 |
+
SearchDialogBase.create_widgets(self)
|
| 68 |
+
# TODO - why is this here and not in a create_command_buttons?
|
| 69 |
+
self.make_button("Find Next", self.default_command, isdef=True)
|
| 70 |
+
|
| 71 |
+
def default_command(self, event=None):
|
| 72 |
+
"Handle the Find Next button as the default command."
|
| 73 |
+
if not self.engine.getprog():
|
| 74 |
+
return
|
| 75 |
+
self.find_again(self.text)
|
| 76 |
+
|
| 77 |
+
def find_again(self, text):
|
| 78 |
+
"""Repeat the last search.
|
| 79 |
+
|
| 80 |
+
If no search was previously run, open a new search dialog. In
|
| 81 |
+
this case, no search is done.
|
| 82 |
+
|
| 83 |
+
If a search was previously run, the search dialog won't be
|
| 84 |
+
shown and the options from the previous search (including the
|
| 85 |
+
search pattern) will be used to find the next occurrence
|
| 86 |
+
of the pattern. Next is relative based on direction.
|
| 87 |
+
|
| 88 |
+
Position the window to display the located occurrence in the
|
| 89 |
+
text.
|
| 90 |
+
|
| 91 |
+
Return True if the search was successful and False otherwise.
|
| 92 |
+
"""
|
| 93 |
+
if not self.engine.getpat():
|
| 94 |
+
self.open(text)
|
| 95 |
+
return False
|
| 96 |
+
if not self.engine.getprog():
|
| 97 |
+
return False
|
| 98 |
+
res = self.engine.search_text(text)
|
| 99 |
+
if res:
|
| 100 |
+
line, m = res
|
| 101 |
+
i, j = m.span()
|
| 102 |
+
first = "%d.%d" % (line, i)
|
| 103 |
+
last = "%d.%d" % (line, j)
|
| 104 |
+
try:
|
| 105 |
+
selfirst = text.index("sel.first")
|
| 106 |
+
sellast = text.index("sel.last")
|
| 107 |
+
if selfirst == first and sellast == last:
|
| 108 |
+
self.bell()
|
| 109 |
+
return False
|
| 110 |
+
except TclError:
|
| 111 |
+
pass
|
| 112 |
+
text.tag_remove("sel", "1.0", "end")
|
| 113 |
+
text.tag_add("sel", first, last)
|
| 114 |
+
text.mark_set("insert", self.engine.isback() and first or last)
|
| 115 |
+
text.see("insert")
|
| 116 |
+
return True
|
| 117 |
+
else:
|
| 118 |
+
self.bell()
|
| 119 |
+
return False
|
| 120 |
+
|
| 121 |
+
def find_selection(self, text):
|
| 122 |
+
"""Search for selected text with previous dialog preferences.
|
| 123 |
+
|
| 124 |
+
Instead of using the same pattern for searching (as Find
|
| 125 |
+
Again does), this first resets the pattern to the currently
|
| 126 |
+
selected text. If the selected text isn't changed, then use
|
| 127 |
+
the prior search phrase.
|
| 128 |
+
"""
|
| 129 |
+
pat = text.get("sel.first", "sel.last")
|
| 130 |
+
if pat:
|
| 131 |
+
self.engine.setcookedpat(pat)
|
| 132 |
+
return self.find_again(text)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _search_dialog(parent): # htest #
|
| 136 |
+
"Display search test box."
|
| 137 |
+
from tkinter import Toplevel, Text
|
| 138 |
+
from tkinter.ttk import Frame, Button
|
| 139 |
+
|
| 140 |
+
top = Toplevel(parent)
|
| 141 |
+
top.title("Test SearchDialog")
|
| 142 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 143 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 144 |
+
|
| 145 |
+
frame = Frame(top)
|
| 146 |
+
frame.pack()
|
| 147 |
+
text = Text(frame, inactiveselectbackground='gray')
|
| 148 |
+
text.pack()
|
| 149 |
+
text.insert("insert","This is a sample string.\n"*5)
|
| 150 |
+
|
| 151 |
+
def show_find():
|
| 152 |
+
text.tag_add('sel', '1.0', 'end')
|
| 153 |
+
_setup(text).open(text)
|
| 154 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 155 |
+
|
| 156 |
+
button = Button(frame, text="Search (selection ignored)", command=show_find)
|
| 157 |
+
button.pack()
|
| 158 |
+
|
| 159 |
+
if __name__ == '__main__':
|
| 160 |
+
from unittest import main
|
| 161 |
+
main('idlelib.idle_test.test_search', verbosity=2, exit=False)
|
| 162 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Define SearchDialogBase used by Search, Replace, and Grep dialogs.'''
|
| 2 |
+
|
| 3 |
+
from tkinter import Toplevel
|
| 4 |
+
from tkinter.ttk import Frame, Entry, Label, Button, Checkbutton, Radiobutton
|
| 5 |
+
from tkinter.simpledialog import _setup_dialog
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class SearchDialogBase:
|
| 9 |
+
'''Create most of a 3 or 4 row, 3 column search dialog.
|
| 10 |
+
|
| 11 |
+
The left and wide middle column contain:
|
| 12 |
+
1 or 2 labeled text entry lines (make_entry, create_entries);
|
| 13 |
+
a row of standard Checkbuttons (make_frame, create_option_buttons),
|
| 14 |
+
each of which corresponds to a search engine Variable;
|
| 15 |
+
a row of dialog-specific Check/Radiobuttons (create_other_buttons).
|
| 16 |
+
|
| 17 |
+
The narrow right column contains command buttons
|
| 18 |
+
(make_button, create_command_buttons).
|
| 19 |
+
These are bound to functions that execute the command.
|
| 20 |
+
|
| 21 |
+
Except for command buttons, this base class is not limited to items
|
| 22 |
+
common to all three subclasses. Rather, it is the Find dialog minus
|
| 23 |
+
the "Find Next" command, its execution function, and the
|
| 24 |
+
default_command attribute needed in create_widgets. The other
|
| 25 |
+
dialogs override attributes and methods, the latter to replace and
|
| 26 |
+
add widgets.
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
title = "Search Dialog" # replace in subclasses
|
| 30 |
+
icon = "Search"
|
| 31 |
+
needwrapbutton = 1 # not in Find in Files
|
| 32 |
+
|
| 33 |
+
def __init__(self, root, engine):
|
| 34 |
+
'''Initialize root, engine, and top attributes.
|
| 35 |
+
|
| 36 |
+
top (level widget): set in create_widgets() called from open().
|
| 37 |
+
frame: container for all widgets in dialog.
|
| 38 |
+
text (Text searched): set in open(), only used in subclasses().
|
| 39 |
+
ent (ry): created in make_entry() called from create_entry().
|
| 40 |
+
row (of grid): 0 in create_widgets(), +1 in make_entry/frame().
|
| 41 |
+
default_command: set in subclasses, used in create_widgets().
|
| 42 |
+
|
| 43 |
+
title (of dialog): class attribute, override in subclasses.
|
| 44 |
+
icon (of dialog): ditto, use unclear if cannot minimize dialog.
|
| 45 |
+
'''
|
| 46 |
+
self.root = root
|
| 47 |
+
self.bell = root.bell
|
| 48 |
+
self.engine = engine
|
| 49 |
+
self.top = None
|
| 50 |
+
|
| 51 |
+
def open(self, text, searchphrase=None):
|
| 52 |
+
"Make dialog visible on top of others and ready to use."
|
| 53 |
+
self.text = text
|
| 54 |
+
if not self.top:
|
| 55 |
+
self.create_widgets()
|
| 56 |
+
else:
|
| 57 |
+
self.top.deiconify()
|
| 58 |
+
self.top.tkraise()
|
| 59 |
+
self.top.transient(text.winfo_toplevel())
|
| 60 |
+
if searchphrase:
|
| 61 |
+
self.ent.delete(0,"end")
|
| 62 |
+
self.ent.insert("end",searchphrase)
|
| 63 |
+
self.ent.focus_set()
|
| 64 |
+
self.ent.selection_range(0, "end")
|
| 65 |
+
self.ent.icursor(0)
|
| 66 |
+
self.top.grab_set()
|
| 67 |
+
|
| 68 |
+
def close(self, event=None):
|
| 69 |
+
"Put dialog away for later use."
|
| 70 |
+
if self.top:
|
| 71 |
+
self.top.grab_release()
|
| 72 |
+
self.top.transient('')
|
| 73 |
+
self.top.withdraw()
|
| 74 |
+
|
| 75 |
+
def create_widgets(self):
|
| 76 |
+
'''Create basic 3 row x 3 col search (find) dialog.
|
| 77 |
+
|
| 78 |
+
Other dialogs override subsidiary create_x methods as needed.
|
| 79 |
+
Replace and Find-in-Files add another entry row.
|
| 80 |
+
'''
|
| 81 |
+
top = Toplevel(self.root)
|
| 82 |
+
top.bind("<Return>", self.default_command)
|
| 83 |
+
top.bind("<Escape>", self.close)
|
| 84 |
+
top.protocol("WM_DELETE_WINDOW", self.close)
|
| 85 |
+
top.wm_title(self.title)
|
| 86 |
+
top.wm_iconname(self.icon)
|
| 87 |
+
_setup_dialog(top)
|
| 88 |
+
self.top = top
|
| 89 |
+
self.frame = Frame(top, padding="5px")
|
| 90 |
+
self.frame.grid(sticky="nwes")
|
| 91 |
+
top.grid_columnconfigure(0, weight=100)
|
| 92 |
+
top.grid_rowconfigure(0, weight=100)
|
| 93 |
+
|
| 94 |
+
self.row = 0
|
| 95 |
+
self.frame.grid_columnconfigure(0, pad=2, weight=0)
|
| 96 |
+
self.frame.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
|
| 97 |
+
|
| 98 |
+
self.create_entries() # row 0 (and maybe 1), cols 0, 1
|
| 99 |
+
self.create_option_buttons() # next row, cols 0, 1
|
| 100 |
+
self.create_other_buttons() # next row, cols 0, 1
|
| 101 |
+
self.create_command_buttons() # col 2, all rows
|
| 102 |
+
|
| 103 |
+
def make_entry(self, label_text, var):
|
| 104 |
+
'''Return (entry, label), .
|
| 105 |
+
|
| 106 |
+
entry - gridded labeled Entry for text entry.
|
| 107 |
+
label - Label widget, returned for testing.
|
| 108 |
+
'''
|
| 109 |
+
label = Label(self.frame, text=label_text)
|
| 110 |
+
label.grid(row=self.row, column=0, sticky="nw")
|
| 111 |
+
entry = Entry(self.frame, textvariable=var, exportselection=0)
|
| 112 |
+
entry.grid(row=self.row, column=1, sticky="nwe")
|
| 113 |
+
self.row = self.row + 1
|
| 114 |
+
return entry, label
|
| 115 |
+
|
| 116 |
+
def create_entries(self):
|
| 117 |
+
"Create one or more entry lines with make_entry."
|
| 118 |
+
self.ent = self.make_entry("Find:", self.engine.patvar)[0]
|
| 119 |
+
|
| 120 |
+
def make_frame(self,labeltext=None):
|
| 121 |
+
'''Return (frame, label).
|
| 122 |
+
|
| 123 |
+
frame - gridded labeled Frame for option or other buttons.
|
| 124 |
+
label - Label widget, returned for testing.
|
| 125 |
+
'''
|
| 126 |
+
if labeltext:
|
| 127 |
+
label = Label(self.frame, text=labeltext)
|
| 128 |
+
label.grid(row=self.row, column=0, sticky="nw")
|
| 129 |
+
else:
|
| 130 |
+
label = ''
|
| 131 |
+
frame = Frame(self.frame)
|
| 132 |
+
frame.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
|
| 133 |
+
self.row = self.row + 1
|
| 134 |
+
return frame, label
|
| 135 |
+
|
| 136 |
+
def create_option_buttons(self):
|
| 137 |
+
'''Return (filled frame, options) for testing.
|
| 138 |
+
|
| 139 |
+
Options is a list of searchengine booleanvar, label pairs.
|
| 140 |
+
A gridded frame from make_frame is filled with a Checkbutton
|
| 141 |
+
for each pair, bound to the var, with the corresponding label.
|
| 142 |
+
'''
|
| 143 |
+
frame = self.make_frame("Options")[0]
|
| 144 |
+
engine = self.engine
|
| 145 |
+
options = [(engine.revar, "Regular expression"),
|
| 146 |
+
(engine.casevar, "Match case"),
|
| 147 |
+
(engine.wordvar, "Whole word")]
|
| 148 |
+
if self.needwrapbutton:
|
| 149 |
+
options.append((engine.wrapvar, "Wrap around"))
|
| 150 |
+
for var, label in options:
|
| 151 |
+
btn = Checkbutton(frame, variable=var, text=label)
|
| 152 |
+
btn.pack(side="left", fill="both")
|
| 153 |
+
return frame, options
|
| 154 |
+
|
| 155 |
+
def create_other_buttons(self):
|
| 156 |
+
'''Return (frame, others) for testing.
|
| 157 |
+
|
| 158 |
+
Others is a list of value, label pairs.
|
| 159 |
+
A gridded frame from make_frame is filled with radio buttons.
|
| 160 |
+
'''
|
| 161 |
+
frame = self.make_frame("Direction")[0]
|
| 162 |
+
var = self.engine.backvar
|
| 163 |
+
others = [(1, 'Up'), (0, 'Down')]
|
| 164 |
+
for val, label in others:
|
| 165 |
+
btn = Radiobutton(frame, variable=var, value=val, text=label)
|
| 166 |
+
btn.pack(side="left", fill="both")
|
| 167 |
+
return frame, others
|
| 168 |
+
|
| 169 |
+
def make_button(self, label, command, isdef=0):
|
| 170 |
+
"Return command button gridded in command frame."
|
| 171 |
+
b = Button(self.buttonframe,
|
| 172 |
+
text=label, command=command,
|
| 173 |
+
default=isdef and "active" or "normal")
|
| 174 |
+
cols,rows=self.buttonframe.grid_size()
|
| 175 |
+
b.grid(pady=1,row=rows,column=0,sticky="ew")
|
| 176 |
+
self.buttonframe.grid(rowspan=rows+1)
|
| 177 |
+
return b
|
| 178 |
+
|
| 179 |
+
def create_command_buttons(self):
|
| 180 |
+
"Place buttons in vertical command frame gridded on right."
|
| 181 |
+
f = self.buttonframe = Frame(self.frame)
|
| 182 |
+
f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)
|
| 183 |
+
|
| 184 |
+
b = self.make_button("Close", self.close)
|
| 185 |
+
b.lower()
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class _searchbase(SearchDialogBase): # htest #
|
| 189 |
+
"Create auto-opening dialog with no text connection."
|
| 190 |
+
|
| 191 |
+
def __init__(self, parent):
|
| 192 |
+
import re
|
| 193 |
+
from idlelib import searchengine
|
| 194 |
+
|
| 195 |
+
self.root = parent
|
| 196 |
+
self.engine = searchengine.get(parent)
|
| 197 |
+
self.create_widgets()
|
| 198 |
+
print(parent.geometry())
|
| 199 |
+
width,height, x,y = list(map(int, re.split('[x+]', parent.geometry())))
|
| 200 |
+
self.top.geometry("+%d+%d" % (x + 40, y + 175))
|
| 201 |
+
|
| 202 |
+
def default_command(self, dummy): pass
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
if __name__ == '__main__':
|
| 206 |
+
from unittest import main
|
| 207 |
+
main('idlelib.idle_test.test_searchbase', verbosity=2, exit=False)
|
| 208 |
+
|
| 209 |
+
from idlel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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Define SearchEngine for search dialogs.'''
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
from tkinter import StringVar, BooleanVar, TclError
|
| 5 |
+
from tkinter import messagebox
|
| 6 |
+
|
| 7 |
+
def get(root):
|
| 8 |
+
'''Return the singleton SearchEngine instance for the process.
|
| 9 |
+
|
| 10 |
+
The single SearchEngine saves settings between dialog instances.
|
| 11 |
+
If there is not a SearchEngine already, make one.
|
| 12 |
+
'''
|
| 13 |
+
if not hasattr(root, "_searchengine"):
|
| 14 |
+
root._searchengine = SearchEngine(root)
|
| 15 |
+
# This creates a cycle that persists until root is deleted.
|
| 16 |
+
return root._searchengine
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SearchEngine:
|
| 20 |
+
"""Handles searching a text widget for Find, Replace, and Grep."""
|
| 21 |
+
|
| 22 |
+
def __init__(self, root):
|
| 23 |
+
'''Initialize Variables that save search state.
|
| 24 |
+
|
| 25 |
+
The dialogs bind these to the UI elements present in the dialogs.
|
| 26 |
+
'''
|
| 27 |
+
self.root = root # need for report_error()
|
| 28 |
+
self.patvar = StringVar(root, '') # search pattern
|
| 29 |
+
self.revar = BooleanVar(root, False) # regular expression?
|
| 30 |
+
self.casevar = BooleanVar(root, False) # match case?
|
| 31 |
+
self.wordvar = BooleanVar(root, False) # match whole word?
|
| 32 |
+
self.wrapvar = BooleanVar(root, True) # wrap around buffer?
|
| 33 |
+
self.backvar = BooleanVar(root, False) # search backwards?
|
| 34 |
+
|
| 35 |
+
# Access methods
|
| 36 |
+
|
| 37 |
+
def getpat(self):
|
| 38 |
+
return self.patvar.get()
|
| 39 |
+
|
| 40 |
+
def setpat(self, pat):
|
| 41 |
+
self.patvar.set(pat)
|
| 42 |
+
|
| 43 |
+
def isre(self):
|
| 44 |
+
return self.revar.get()
|
| 45 |
+
|
| 46 |
+
def iscase(self):
|
| 47 |
+
return self.casevar.get()
|
| 48 |
+
|
| 49 |
+
def isword(self):
|
| 50 |
+
return self.wordvar.get()
|
| 51 |
+
|
| 52 |
+
def iswrap(self):
|
| 53 |
+
return self.wrapvar.get()
|
| 54 |
+
|
| 55 |
+
def isback(self):
|
| 56 |
+
return self.backvar.get()
|
| 57 |
+
|
| 58 |
+
# Higher level access methods
|
| 59 |
+
|
| 60 |
+
def setcookedpat(self, pat):
|
| 61 |
+
"Set pattern after escaping if re."
|
| 62 |
+
# called only in search.py: 66
|
| 63 |
+
if self.isre():
|
| 64 |
+
pat = re.escape(pat)
|
| 65 |
+
self.setpat(pat)
|
| 66 |
+
|
| 67 |
+
def getcookedpat(self):
|
| 68 |
+
pat = self.getpat()
|
| 69 |
+
if not self.isre(): # if True, see setcookedpat
|
| 70 |
+
pat = re.escape(pat)
|
| 71 |
+
if self.isword():
|
| 72 |
+
pat = r"\b%s\b" % pat
|
| 73 |
+
return pat
|
| 74 |
+
|
| 75 |
+
def getprog(self):
|
| 76 |
+
"Return compiled cooked search pattern."
|
| 77 |
+
pat = self.getpat()
|
| 78 |
+
if not pat:
|
| 79 |
+
self.report_error(pat, "Empty regular expression")
|
| 80 |
+
return None
|
| 81 |
+
pat = self.getcookedpat()
|
| 82 |
+
flags = 0
|
| 83 |
+
if not self.iscase():
|
| 84 |
+
flags = flags | re.IGNORECASE
|
| 85 |
+
try:
|
| 86 |
+
prog = re.compile(pat, flags)
|
| 87 |
+
except re.error as e:
|
| 88 |
+
self.report_error(pat, e.msg, e.pos)
|
| 89 |
+
return None
|
| 90 |
+
return prog
|
| 91 |
+
|
| 92 |
+
def report_error(self, pat, msg, col=None):
|
| 93 |
+
# Derived class could override this with something fancier
|
| 94 |
+
msg = "Error: " + str(msg)
|
| 95 |
+
if pat:
|
| 96 |
+
msg = msg + "\nPattern: " + str(pat)
|
| 97 |
+
if col is not None:
|
| 98 |
+
msg = msg + "\nOffset: " + str(col)
|
| 99 |
+
messagebox.showerror("Regular expression error",
|
| 100 |
+
msg, master=self.root)
|
| 101 |
+
|
| 102 |
+
def search_text(self, text, prog=None, ok=0):
|
| 103 |
+
'''Return (lineno, matchobj) or None for forward/backward search.
|
| 104 |
+
|
| 105 |
+
This function calls the right function with the right arguments.
|
| 106 |
+
It directly return the result of that call.
|
| 107 |
+
|
| 108 |
+
Text is a text widget. Prog is a precompiled pattern.
|
| 109 |
+
The ok parameter is a bit complicated as it has two effects.
|
| 110 |
+
|
| 111 |
+
If there is a selection, the search begin at either end,
|
| 112 |
+
depending on the direction setting and ok, with ok meaning that
|
| 113 |
+
the search starts with the selection. Otherwise, search begins
|
| 114 |
+
at the insert mark.
|
| 115 |
+
|
| 116 |
+
To aid progress, the search functions do not return an empty
|
| 117 |
+
match at the starting position unless ok is True.
|
| 118 |
+
'''
|
| 119 |
+
|
| 120 |
+
if not prog:
|
| 121 |
+
prog = self.getprog()
|
| 122 |
+
if not prog:
|
| 123 |
+
return None # Compilation failed -- stop
|
| 124 |
+
wrap = self.wrapvar.get()
|
| 125 |
+
first, last = get_selection(text)
|
| 126 |
+
if self.isback():
|
| 127 |
+
if ok:
|
| 128 |
+
start = last
|
| 129 |
+
else:
|
| 130 |
+
start = first
|
| 131 |
+
line, col = get_line_col(start)
|
| 132 |
+
res = self.search_backward(text, prog, line, col, wrap, ok)
|
| 133 |
+
else:
|
| 134 |
+
if ok:
|
| 135 |
+
start = first
|
| 136 |
+
else:
|
| 137 |
+
start = last
|
| 138 |
+
line, col = get_line_col(start)
|
| 139 |
+
res = self.search_forward(text, prog, line, col, wrap, ok)
|
| 140 |
+
return res
|
| 141 |
+
|
| 142 |
+
def search_forward(self, text, prog, line, col, wrap, ok=0):
|
| 143 |
+
wrapped = 0
|
| 144 |
+
startline = line
|
| 145 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 146 |
+
while chars:
|
| 147 |
+
m = prog.search(chars[:-1], col)
|
| 148 |
+
if m:
|
| 149 |
+
if ok or m.end() > col:
|
| 150 |
+
return line, m
|
| 151 |
+
line = line + 1
|
| 152 |
+
if wrapped and line > startline:
|
| 153 |
+
break
|
| 154 |
+
col = 0
|
| 155 |
+
ok = 1
|
| 156 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 157 |
+
if not chars and wrap:
|
| 158 |
+
wrapped = 1
|
| 159 |
+
wrap = 0
|
| 160 |
+
line = 1
|
| 161 |
+
chars = text.get("1.0", "2.0")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
def search_backward(self, text, prog, line, col, wrap, ok=0):
|
| 165 |
+
wrapped = 0
|
| 166 |
+
startline = line
|
| 167 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 168 |
+
while True:
|
| 169 |
+
m = search_reverse(prog, chars[:-1], col)
|
| 170 |
+
if m:
|
| 171 |
+
if ok or m.start() < col:
|
| 172 |
+
return line, m
|
| 173 |
+
line = line - 1
|
| 174 |
+
if wrapped and line < startline:
|
| 175 |
+
break
|
| 176 |
+
ok = 1
|
| 177 |
+
if line <= 0:
|
| 178 |
+
if not wrap:
|
| 179 |
+
break
|
| 180 |
+
wrapped = 1
|
| 181 |
+
wrap = 0
|
| 182 |
+
pos = text.index("end-1c")
|
| 183 |
+
line, col = map(int, pos.split("."))
|
| 184 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 185 |
+
col = len(chars) - 1
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def search_reverse(prog, chars, col):
|
| 190 |
+
'''Search backwards and return an re match object or None.
|
| 191 |
+
|
| 192 |
+
This is done by searching forwards until there is no match.
|
| 193 |
+
Prog: compiled re object with a search method returning a match.
|
| 194 |
+
Chars: line of text, without \\n.
|
| 195 |
+
Col: stop index for the search; the limit for match.end().
|
| 196 |
+
'''
|
| 197 |
+
m = prog.search(chars)
|
| 198 |
+
if not m:
|
| 199 |
+
return None
|
| 200 |
+
found = None
|
| 201 |
+
i, j = m.span() # m.start(), m.end() == match slice indexes
|
| 202 |
+
while i < col and j <= col:
|
| 203 |
+
found = m
|
| 204 |
+
if i == j:
|
| 205 |
+
j = j+1
|
| 206 |
+
m = prog.search(chars, j)
|
| 207 |
+
if not m:
|
| 208 |
+
break
|
| 209 |
+
i, j = m.span()
|
| 210 |
+
return found
|
| 211 |
+
|
| 212 |
+
def get_selection(text):
|
| 213 |
+
'''Return tuple of 'line.col' indexes from selection or insert mark.
|
| 214 |
+
'''
|
| 215 |
+
try:
|
| 216 |
+
first = text.index("sel.first")
|
| 217 |
+
last = text.index("sel.last")
|
| 218 |
+
except TclError:
|
| 219 |
+
first = last = None
|
| 220 |
+
if not first:
|
| 221 |
+
first = text.index("insert")
|
| 222 |
+
if not last:
|
| 223 |
+
last = first
|
| 224 |
+
return first, last
|
| 225 |
+
|
| 226 |
+
def get_line_col(index):
|
| 227 |
+
'''Return (line, col) tuple of ints from 'line.col' string.'''
|
| 228 |
+
line, col = map(int, index.split(".")) # Fails on invalid index
|
| 229 |
+
return line, col
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
if __name__ == "__main__":
|
| 233 |
+
from unittest import main
|
| 234 |
+
main('idlelib.idle_test.test_searchengine', verbosity=2)
|
evalkit_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sys
|
| 4 |
+
|
| 5 |
+
import tkinter as tk
|
| 6 |
+
|
| 7 |
+
from idlelib.debugobj import ObjectTreeItem, make_objecttreeitem
|
| 8 |
+
from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
|
| 9 |
+
|
| 10 |
+
def StackBrowser(root, flist=None, tb=None, top=None):
|
| 11 |
+
global sc, item, node # For testing.
|
| 12 |
+
if top is None:
|
| 13 |
+
top = tk.Toplevel(root)
|
| 14 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0)
|
| 15 |
+
sc.frame.pack(expand=1, fill="both")
|
| 16 |
+
item = StackTreeItem(flist, tb)
|
| 17 |
+
node = TreeNode(sc.canvas, None, item)
|
| 18 |
+
node.expand()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class StackTreeItem(TreeItem):
|
| 22 |
+
|
| 23 |
+
def __init__(self, flist=None, tb=None):
|
| 24 |
+
self.flist = flist
|
| 25 |
+
self.stack = self.get_stack(tb)
|
| 26 |
+
self.text = self.get_exception()
|
| 27 |
+
|
| 28 |
+
def get_stack(self, tb):
|
| 29 |
+
if tb is None:
|
| 30 |
+
tb = sys.last_traceback
|
| 31 |
+
stack = []
|
| 32 |
+
if tb and tb.tb_frame is None:
|
| 33 |
+
tb = tb.tb_next
|
| 34 |
+
while tb is not None:
|
| 35 |
+
stack.append((tb.tb_frame, tb.tb_lineno))
|
| 36 |
+
tb = tb.tb_next
|
| 37 |
+
return stack
|
| 38 |
+
|
| 39 |
+
def get_exception(self):
|
| 40 |
+
type = sys.last_type
|
| 41 |
+
value = sys.last_value
|
| 42 |
+
if hasattr(type, "__name__"):
|
| 43 |
+
type = type.__name__
|
| 44 |
+
s = str(type)
|
| 45 |
+
if value is not None:
|
| 46 |
+
s = s + ": " + str(value)
|
| 47 |
+
return s
|
| 48 |
+
|
| 49 |
+
def GetText(self):
|
| 50 |
+
return self.text
|
| 51 |
+
|
| 52 |
+
def GetSubList(self):
|
| 53 |
+
sublist = []
|
| 54 |
+
for info in self.stack:
|
| 55 |
+
item = FrameTreeItem(info, self.flist)
|
| 56 |
+
sublist.append(item)
|
| 57 |
+
return sublist
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class FrameTreeItem(TreeItem):
|
| 61 |
+
|
| 62 |
+
def __init__(self, info, flist):
|
| 63 |
+
self.info = info
|
| 64 |
+
self.flist = flist
|
| 65 |
+
|
| 66 |
+
def GetText(self):
|
| 67 |
+
frame, lineno = self.info
|
| 68 |
+
try:
|
| 69 |
+
modname = frame.f_globals["__name__"]
|
| 70 |
+
except:
|
| 71 |
+
modname = "?"
|
| 72 |
+
code = frame.f_code
|
| 73 |
+
filename = code.co_filename
|
| 74 |
+
funcname = code.co_name
|
| 75 |
+
sourceline = linecache.getline(filename, lineno)
|
| 76 |
+
sourceline = sourceline.strip()
|
| 77 |
+
if funcname in ("?", "", None):
|
| 78 |
+
item = "%s, line %d: %s" % (modname, lineno, sourceline)
|
| 79 |
+
else:
|
| 80 |
+
item = "%s.%s(...), line %d: %s" % (modname, funcname,
|
| 81 |
+
lineno, sourceline)
|
| 82 |
+
return item
|
| 83 |
+
|
| 84 |
+
def GetSubList(self):
|
| 85 |
+
frame, lineno = self.info
|
| 86 |
+
sublist = []
|
| 87 |
+
if frame.f_globals is not frame.f_locals:
|
| 88 |
+
item = VariablesTreeItem("<locals>", frame.f_locals, self.flist)
|
| 89 |
+
sublist.append(item)
|
| 90 |
+
item = VariablesTreeItem("<globals>", frame.f_globals, self.flist)
|
| 91 |
+
sublist.append(item)
|
| 92 |
+
return sublist
|
| 93 |
+
|
| 94 |
+
def OnDoubleClick(self):
|
| 95 |
+
if self.flist:
|
| 96 |
+
frame, lineno = self.info
|
| 97 |
+
filename = frame.f_code.co_filename
|
| 98 |
+
if os.path.isfile(filename):
|
| 99 |
+
self.flist.gotofileline(filename, lineno)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class VariablesTreeItem(ObjectTreeItem):
|
| 103 |
+
|
| 104 |
+
def GetText(self):
|
| 105 |
+
return self.labeltext
|
| 106 |
+
|
| 107 |
+
def GetLabelText(self):
|
| 108 |
+
return None
|
| 109 |
+
|
| 110 |
+
def IsExpandable(self):
|
| 111 |
+
return len(self.object) > 0
|
| 112 |
+
|
| 113 |
+
def GetSubList(self):
|
| 114 |
+
sublist = []
|
| 115 |
+
for key in self.object.keys():
|
| 116 |
+
try:
|
| 117 |
+
value = self.object[key]
|
| 118 |
+
except KeyError:
|
| 119 |
+
continue
|
| 120 |
+
def setfunction(value, key=key, object=self.object):
|
| 121 |
+
object[key] = value
|
| 122 |
+
item = make_objecttreeitem(key + " =", value, setfunction)
|
| 123 |
+
sublist.append(item)
|
| 124 |
+
return sublist
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _stack_viewer(parent): # htest #
|
| 128 |
+
from idlelib.pyshell import PyShellFileList
|
| 129 |
+
top = tk.Toplevel(parent)
|
| 130 |
+
top.title("Test StackViewer")
|
| 131 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 132 |
+
top.geometry("+%d+%d" % (x + 50, y + 175))
|
| 133 |
+
flist = PyShellFileList(top)
|
| 134 |
+
try: # to obtain a traceback object
|
| 135 |
+
intentional_name_error
|
| 136 |
+
except NameError:
|
| 137 |
+
exc_type, exc_value, exc_tb = sys.exc_info()
|
| 138 |
+
# inject stack trace to sys
|
| 139 |
+
sys.last_type = exc_type
|
| 140 |
+
sys.last_value = exc_value
|
| 141 |
+
sys.last_traceback = exc_tb
|
| 142 |
+
|
| 143 |
+
StackBrowser(top, flist=flist, top=top, tb=exc_tb)
|
| 144 |
+
|
| 145 |
+
# restore sys to original state
|
| 146 |
+
del sys.last_type
|
| 147 |
+
del sys.last_value
|
| 148 |
+
del sys.last_traceback
|
| 149 |
+
|
| 150 |
+
if __name__ == '__main__':
|
| 151 |
+
from unittest import main
|
| 152 |
+
main('idlelib.idle_test.test_stackviewer', verbosity=2, exit=False)
|
| 153 |
+
|
| 154 |
+
from idlelib.idle_test.htest import run
|
| 155 |
+
run(_stack_viewer)
|
evalkit_cambrian/lib/python3.10/idlelib/statusbar.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tkinter.ttk import Label, Frame
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class MultiStatusBar(Frame):
|
| 5 |
+
|
| 6 |
+
def __init__(self, master, **kw):
|
| 7 |
+
Frame.__init__(self, master, **kw)
|
| 8 |
+
self.labels = {}
|
| 9 |
+
|
| 10 |
+
def set_label(self, name, text='', side='left', width=0):
|
| 11 |
+
if name not in self.labels:
|
| 12 |
+
label = Label(self, borderwidth=0, anchor='w')
|
| 13 |
+
label.pack(side=side, pady=0, padx=4)
|
| 14 |
+
self.labels[name] = label
|
| 15 |
+
else:
|
| 16 |
+
label = self.labels[name]
|
| 17 |
+
if width != 0:
|
| 18 |
+
label.config(width=width)
|
| 19 |
+
label.config(text=text)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _multistatus_bar(parent): # htest #
|
| 23 |
+
from tkinter import Toplevel, Text
|
| 24 |
+
from tkinter.ttk import Frame, Button
|
| 25 |
+
top = Toplevel(parent)
|
| 26 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 27 |
+
top.geometry("+%d+%d" %(x, y + 175))
|
| 28 |
+
top.title("Test multistatus bar")
|
| 29 |
+
frame = Frame(top)
|
| 30 |
+
text = Text(frame, height=5, width=40)
|
| 31 |
+
text.pack()
|
| 32 |
+
msb = MultiStatusBar(frame)
|
| 33 |
+
msb.set_label("one", "hello")
|
| 34 |
+
msb.set_label("two", "world")
|
| 35 |
+
msb.pack(side='bottom', fill='x')
|
| 36 |
+
|
| 37 |
+
def change():
|
| 38 |
+
msb.set_label("one", "foo")
|
| 39 |
+
msb.set_label("two", "bar")
|
| 40 |
+
|
| 41 |
+
button = Button(top, text="Update status", command=change)
|
| 42 |
+
button.pack(side='bottom')
|
| 43 |
+
frame.pack()
|
| 44 |
+
|
| 45 |
+
if __name__ == '__main__':
|
| 46 |
+
from unittest import main
|
| 47 |
+
main('idlelib.idle_test.test_statusbar', verbosity=2, exit=False)
|
| 48 |
+
|
| 49 |
+
from idlelib.idle_test.htest import run
|
| 50 |
+
run(_multistatus_bar)
|
evalkit_cambrian/lib/python3.10/idlelib/textview.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Simple text browser for IDLE
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
from tkinter import Toplevel, Text, TclError,\
|
| 5 |
+
HORIZONTAL, VERTICAL, NS, EW, NSEW, NONE, WORD, SUNKEN
|
| 6 |
+
from tkinter.ttk import Frame, Scrollbar, Button
|
| 7 |
+
from tkinter.messagebox import showerror
|
| 8 |
+
|
| 9 |
+
from idlelib.colorizer import color_config
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class AutoHideScrollbar(Scrollbar):
|
| 13 |
+
"""A scrollbar that is automatically hidden when not needed.
|
| 14 |
+
|
| 15 |
+
Only the grid geometry manager is supported.
|
| 16 |
+
"""
|
| 17 |
+
def set(self, lo, hi):
|
| 18 |
+
if float(lo) > 0.0 or float(hi) < 1.0:
|
| 19 |
+
self.grid()
|
| 20 |
+
else:
|
| 21 |
+
self.grid_remove()
|
| 22 |
+
super().set(lo, hi)
|
| 23 |
+
|
| 24 |
+
def pack(self, **kwargs):
|
| 25 |
+
raise TclError(f'{self.__class__.__name__} does not support "pack"')
|
| 26 |
+
|
| 27 |
+
def place(self, **kwargs):
|
| 28 |
+
raise TclError(f'{self.__class__.__name__} does not support "place"')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ScrollableTextFrame(Frame):
|
| 32 |
+
"""Display text with scrollbar(s)."""
|
| 33 |
+
|
| 34 |
+
def __init__(self, master, wrap=NONE, **kwargs):
|
| 35 |
+
"""Create a frame for Textview.
|
| 36 |
+
|
| 37 |
+
master - master widget for this frame
|
| 38 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 39 |
+
|
| 40 |
+
All parameters except for 'wrap' are passed to Frame.__init__().
|
| 41 |
+
|
| 42 |
+
The Text widget is accessible via the 'text' attribute.
|
| 43 |
+
|
| 44 |
+
Note: Changing the wrapping mode of the text widget after
|
| 45 |
+
instantiation is not supported.
|
| 46 |
+
"""
|
| 47 |
+
super().__init__(master, **kwargs)
|
| 48 |
+
|
| 49 |
+
text = self.text = Text(self, wrap=wrap)
|
| 50 |
+
text.grid(row=0, column=0, sticky=NSEW)
|
| 51 |
+
self.grid_rowconfigure(0, weight=1)
|
| 52 |
+
self.grid_columnconfigure(0, weight=1)
|
| 53 |
+
|
| 54 |
+
# vertical scrollbar
|
| 55 |
+
self.yscroll = AutoHideScrollbar(self, orient=VERTICAL,
|
| 56 |
+
takefocus=False,
|
| 57 |
+
command=text.yview)
|
| 58 |
+
self.yscroll.grid(row=0, column=1, sticky=NS)
|
| 59 |
+
text['yscrollcommand'] = self.yscroll.set
|
| 60 |
+
|
| 61 |
+
# horizontal scrollbar - only when wrap is set to NONE
|
| 62 |
+
if wrap == NONE:
|
| 63 |
+
self.xscroll = AutoHideScrollbar(self, orient=HORIZONTAL,
|
| 64 |
+
takefocus=False,
|
| 65 |
+
command=text.xview)
|
| 66 |
+
self.xscroll.grid(row=1, column=0, sticky=EW)
|
| 67 |
+
text['xscrollcommand'] = self.xscroll.set
|
| 68 |
+
else:
|
| 69 |
+
self.xscroll = None
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class ViewFrame(Frame):
|
| 73 |
+
"Display TextFrame and Close button."
|
| 74 |
+
def __init__(self, parent, contents, wrap='word'):
|
| 75 |
+
"""Create a frame for viewing text with a "Close" button.
|
| 76 |
+
|
| 77 |
+
parent - parent widget for this frame
|
| 78 |
+
contents - text to display
|
| 79 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 80 |
+
|
| 81 |
+
The Text widget is accessible via the 'text' attribute.
|
| 82 |
+
"""
|
| 83 |
+
super().__init__(parent)
|
| 84 |
+
self.parent = parent
|
| 85 |
+
self.bind('<Return>', self.ok)
|
| 86 |
+
self.bind('<Escape>', self.ok)
|
| 87 |
+
self.textframe = ScrollableTextFrame(self, relief=SUNKEN, height=700)
|
| 88 |
+
|
| 89 |
+
text = self.text = self.textframe.text
|
| 90 |
+
text.insert('1.0', contents)
|
| 91 |
+
text.configure(wrap=wrap, highlightthickness=0, state='disabled')
|
| 92 |
+
color_config(text)
|
| 93 |
+
text.focus_set()
|
| 94 |
+
|
| 95 |
+
self.button_ok = button_ok = Button(
|
| 96 |
+
self, text='Close', command=self.ok, takefocus=False)
|
| 97 |
+
self.textframe.pack(side='top', expand=True, fill='both')
|
| 98 |
+
button_ok.pack(side='bottom')
|
| 99 |
+
|
| 100 |
+
def ok(self, event=None):
|
| 101 |
+
"""Dismiss text viewer dialog."""
|
| 102 |
+
self.parent.destroy()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class ViewWindow(Toplevel):
|
| 106 |
+
"A simple text viewer dialog for IDLE."
|
| 107 |
+
|
| 108 |
+
def __init__(self, parent, title, contents, modal=True, wrap=WORD,
|
| 109 |
+
*, _htest=False, _utest=False):
|
| 110 |
+
"""Show the given text in a scrollable window with a 'close' button.
|
| 111 |
+
|
| 112 |
+
If modal is left True, users cannot interact with other windows
|
| 113 |
+
until the textview window is closed.
|
| 114 |
+
|
| 115 |
+
parent - parent of this dialog
|
| 116 |
+
title - string which is title of popup dialog
|
| 117 |
+
contents - text to display in dialog
|
| 118 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 119 |
+
_htest - bool; change box location when running htest.
|
| 120 |
+
_utest - bool; don't wait_window when running unittest.
|
| 121 |
+
"""
|
| 122 |
+
super().__init__(parent)
|
| 123 |
+
self['borderwidth'] = 5
|
| 124 |
+
# Place dialog below parent if running htest.
|
| 125 |
+
x = parent.winfo_rootx() + 10
|
| 126 |
+
y = parent.winfo_rooty() + (10 if not _htest else 100)
|
| 127 |
+
self.geometry(f'=750x500+{x}+{y}')
|
| 128 |
+
|
| 129 |
+
self.title(title)
|
| 130 |
+
self.viewframe = ViewFrame(self, contents, wrap=wrap)
|
| 131 |
+
self.protocol("WM_DELETE_WINDOW", self.ok)
|
| 132 |
+
self.button_ok = button_ok = Button(self, text='Close',
|
| 133 |
+
command=self.ok, takefocus=False)
|
| 134 |
+
self.viewframe.pack(side='top', expand=True, fill='both')
|
| 135 |
+
|
| 136 |
+
self.is_modal = modal
|
| 137 |
+
if self.is_modal:
|
| 138 |
+
self.transient(parent)
|
| 139 |
+
self.grab_set()
|
| 140 |
+
if not _utest:
|
| 141 |
+
self.wait_window()
|
| 142 |
+
|
| 143 |
+
def ok(self, event=None):
|
| 144 |
+
"""Dismiss text viewer dialog."""
|
| 145 |
+
if self.is_modal:
|
| 146 |
+
self.grab_release()
|
| 147 |
+
self.destroy()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def view_text(parent, title, contents, modal=True, wrap='word', _utest=False):
|
| 151 |
+
"""Create text viewer for given text.
|
| 152 |
+
|
| 153 |
+
parent - parent of this dialog
|
| 154 |
+
title - string which is the title of popup dialog
|
| 155 |
+
contents - text to display in this dialog
|
| 156 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 157 |
+
modal - controls if users can interact with other windows while this
|
| 158 |
+
dialog is displayed
|
| 159 |
+
_utest - bool; controls wait_window on unittest
|
| 160 |
+
"""
|
| 161 |
+
return ViewWindow(parent, title, contents, modal, wrap=wrap, _utest=_utest)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def view_file(parent, title, filename, encoding, modal=True, wrap='word',
|
| 165 |
+
_utest=False):
|
| 166 |
+
"""Create text viewer for text in filename.
|
| 167 |
+
|
| 168 |
+
Return error message if file cannot be read. Otherwise calls view_text
|
| 169 |
+
with contents of the file.
|
| 170 |
+
"""
|
| 171 |
+
try:
|
| 172 |
+
with open(filename, 'r', encoding=encoding) as file:
|
| 173 |
+
contents = file.read()
|
| 174 |
+
except OSError:
|
| 175 |
+
showerror(title='File Load Error',
|
| 176 |
+
message=f'Unable to load file {filename!r} .',
|
| 177 |
+
parent=parent)
|
| 178 |
+
except UnicodeDecodeError as err:
|
| 179 |
+
showerror(title='Unicode Decode Error',
|
| 180 |
+
message=str(err),
|
| 181 |
+
parent=parent)
|
| 182 |
+
else:
|
| 183 |
+
return view_text(parent, title, contents, modal, wrap=wrap,
|
| 184 |
+
_utest=_utest)
|
| 185 |
+
return None
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
if __name__ == '__main__':
|
| 189 |
+
from unittest import main
|
| 190 |
+
main('idlelib.idle_test.test_textview', verbosity=2, exit=False)
|
| 191 |
+
|
| 192 |
+
from idlelib.idle_test.htest import run
|
| 193 |
+
run(ViewWindow)
|
evalkit_cambrian/lib/python3.10/idlelib/tooltip.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 5 |
+
* a simple text-only Tooltip class
|
| 6 |
+
"""
|
| 7 |
+
from tkinter import *
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TooltipBase:
|
| 11 |
+
"""abstract base class for tooltips"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, anchor_widget):
|
| 14 |
+
"""Create a tooltip.
|
| 15 |
+
|
| 16 |
+
anchor_widget: the widget next to which the tooltip will be shown
|
| 17 |
+
|
| 18 |
+
Note that a widget will only be shown when showtip() is called.
|
| 19 |
+
"""
|
| 20 |
+
self.anchor_widget = anchor_widget
|
| 21 |
+
self.tipwindow = None
|
| 22 |
+
|
| 23 |
+
def __del__(self):
|
| 24 |
+
self.hidetip()
|
| 25 |
+
|
| 26 |
+
def showtip(self):
|
| 27 |
+
"""display the tooltip"""
|
| 28 |
+
if self.tipwindow:
|
| 29 |
+
return
|
| 30 |
+
self.tipwindow = tw = Toplevel(self.anchor_widget)
|
| 31 |
+
# show no border on the top level window
|
| 32 |
+
tw.wm_overrideredirect(1)
|
| 33 |
+
try:
|
| 34 |
+
# This command is only needed and available on Tk >= 8.4.0 for OSX.
|
| 35 |
+
# Without it, call tips intrude on the typing process by grabbing
|
| 36 |
+
# the focus.
|
| 37 |
+
tw.tk.call("::tk::unsupported::MacWindowStyle", "style", tw._w,
|
| 38 |
+
"help", "noActivates")
|
| 39 |
+
except TclError:
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
self.position_window()
|
| 43 |
+
self.showcontents()
|
| 44 |
+
self.tipwindow.update_idletasks() # Needed on MacOS -- see #34275.
|
| 45 |
+
self.tipwindow.lift() # work around bug in Tk 8.5.18+ (issue #24570)
|
| 46 |
+
|
| 47 |
+
def position_window(self):
|
| 48 |
+
"""(re)-set the tooltip's screen position"""
|
| 49 |
+
x, y = self.get_position()
|
| 50 |
+
root_x = self.anchor_widget.winfo_rootx() + x
|
| 51 |
+
root_y = self.anchor_widget.winfo_rooty() + y
|
| 52 |
+
self.tipwindow.wm_geometry("+%d+%d" % (root_x, root_y))
|
| 53 |
+
|
| 54 |
+
def get_position(self):
|
| 55 |
+
"""choose a screen position for the tooltip"""
|
| 56 |
+
# The tip window must be completely outside the anchor widget;
|
| 57 |
+
# otherwise when the mouse enters the tip window we get
|
| 58 |
+
# a leave event and it disappears, and then we get an enter
|
| 59 |
+
# event and it reappears, and so on forever :-(
|
| 60 |
+
#
|
| 61 |
+
# Note: This is a simplistic implementation; sub-classes will likely
|
| 62 |
+
# want to override this.
|
| 63 |
+
return 20, self.anchor_widget.winfo_height() + 1
|
| 64 |
+
|
| 65 |
+
def showcontents(self):
|
| 66 |
+
"""content display hook for sub-classes"""
|
| 67 |
+
# See ToolTip for an example
|
| 68 |
+
raise NotImplementedError
|
| 69 |
+
|
| 70 |
+
def hidetip(self):
|
| 71 |
+
"""hide the tooltip"""
|
| 72 |
+
# Note: This is called by __del__, so careful when overriding/extending
|
| 73 |
+
tw = self.tipwindow
|
| 74 |
+
self.tipwindow = None
|
| 75 |
+
if tw:
|
| 76 |
+
try:
|
| 77 |
+
tw.destroy()
|
| 78 |
+
except TclError: # pragma: no cover
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class OnHoverTooltipBase(TooltipBase):
|
| 83 |
+
"""abstract base class for tooltips, with delayed on-hover display"""
|
| 84 |
+
|
| 85 |
+
def __init__(self, anchor_widget, hover_delay=1000):
|
| 86 |
+
"""Create a tooltip with a mouse hover delay.
|
| 87 |
+
|
| 88 |
+
anchor_widget: the widget next to which the tooltip will be shown
|
| 89 |
+
hover_delay: time to delay before showing the tooltip, in milliseconds
|
| 90 |
+
|
| 91 |
+
Note that a widget will only be shown when showtip() is called,
|
| 92 |
+
e.g. after hovering over the anchor widget with the mouse for enough
|
| 93 |
+
time.
|
| 94 |
+
"""
|
| 95 |
+
super(OnHoverTooltipBase, self).__init__(anchor_widget)
|
| 96 |
+
self.hover_delay = hover_delay
|
| 97 |
+
|
| 98 |
+
self._after_id = None
|
| 99 |
+
self._id1 = self.anchor_widget.bind("<Enter>", self._show_event)
|
| 100 |
+
self._id2 = self.anchor_widget.bind("<Leave>", self._hide_event)
|
| 101 |
+
self._id3 = self.anchor_widget.bind("<Button>", self._hide_event)
|
| 102 |
+
|
| 103 |
+
def __del__(self):
|
| 104 |
+
try:
|
| 105 |
+
self.anchor_widget.unbind("<Enter>", self._id1)
|
| 106 |
+
self.anchor_widget.unbind("<Leave>", self._id2) # pragma: no cover
|
| 107 |
+
self.anchor_widget.unbind("<Button>", self._id3) # pragma: no cover
|
| 108 |
+
except TclError:
|
| 109 |
+
pass
|
| 110 |
+
super(OnHoverTooltipBase, self).__del__()
|
| 111 |
+
|
| 112 |
+
def _show_event(self, event=None):
|
| 113 |
+
"""event handler to display the tooltip"""
|
| 114 |
+
if self.hover_delay:
|
| 115 |
+
self.schedule()
|
| 116 |
+
else:
|
| 117 |
+
self.showtip()
|
| 118 |
+
|
| 119 |
+
def _hide_event(self, event=None):
|
| 120 |
+
"""event handler to hide the tooltip"""
|
| 121 |
+
self.hidetip()
|
| 122 |
+
|
| 123 |
+
def schedule(self):
|
| 124 |
+
"""schedule the future display of the tooltip"""
|
| 125 |
+
self.unschedule()
|
| 126 |
+
self._after_id = self.anchor_widget.after(self.hover_delay,
|
| 127 |
+
self.showtip)
|
| 128 |
+
|
| 129 |
+
def unschedule(self):
|
| 130 |
+
"""cancel the future display of the tooltip"""
|
| 131 |
+
after_id = self._after_id
|
| 132 |
+
self._after_id = None
|
| 133 |
+
if after_id:
|
| 134 |
+
self.anchor_widget.after_cancel(after_id)
|
| 135 |
+
|
| 136 |
+
def hidetip(self):
|
| 137 |
+
"""hide the tooltip"""
|
| 138 |
+
try:
|
| 139 |
+
self.unschedule()
|
| 140 |
+
except TclError: # pragma: no cover
|
| 141 |
+
pass
|
| 142 |
+
super(OnHoverTooltipBase, self).hidetip()
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class Hovertip(OnHoverTooltipBase):
|
| 146 |
+
"A tooltip that pops up when a mouse hovers over an anchor widget."
|
| 147 |
+
def __init__(self, anchor_widget, text, hover_delay=1000):
|
| 148 |
+
"""Create a text tooltip with a mouse hover delay.
|
| 149 |
+
|
| 150 |
+
anchor_widget: the widget next to which the tooltip will be shown
|
| 151 |
+
hover_delay: time to delay before showing the tooltip, in milliseconds
|
| 152 |
+
|
| 153 |
+
Note that a widget will only be shown when showtip() is called,
|
| 154 |
+
e.g. after hovering over the anchor widget with the mouse for enough
|
| 155 |
+
time.
|
| 156 |
+
"""
|
| 157 |
+
super(Hovertip, self).__init__(anchor_widget, hover_delay=hover_delay)
|
| 158 |
+
self.text = text
|
| 159 |
+
|
| 160 |
+
def showcontents(self):
|
| 161 |
+
label = Label(self.tipwindow, text=self.text, justify=LEFT,
|
| 162 |
+
background="#ffffe0", relief=SOLID, borderwidth=1)
|
| 163 |
+
label.pack()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _tooltip(parent): # htest #
|
| 167 |
+
top = Toplevel(parent)
|
| 168 |
+
top.title("Test tooltip")
|
| 169 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 170 |
+
top.geometry("+%d+%d" % (x, y + 150))
|
| 171 |
+
label = Label(top, text="Place your mouse over buttons")
|
| 172 |
+
label.pack()
|
| 173 |
+
button1 = Button(top, text="Button 1 -- 1/2 second hover delay")
|
| 174 |
+
button1.pack()
|
| 175 |
+
Hovertip(button1, "This is tooltip text for button1.", hover_delay=500)
|
| 176 |
+
button2 = Button(top, text="Button 2 -- no hover delay")
|
| 177 |
+
button2.pack()
|
| 178 |
+
Hovertip(button2, "This is tooltip\ntext for button2.", hover_delay=None)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
from unittest import main
|
| 183 |
+
main('idlelib.idle_test.test_tooltip', verbosity=2, exit=False)
|
| 184 |
+
|
| 185 |
+
from idlelib.idle_test.htest import run
|
| 186 |
+
run(_tooltip)
|