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
- llava/lib/python3.10/idlelib/ChangeLog +1591 -0
- llava/lib/python3.10/idlelib/Icons/README.txt +13 -0
- llava/lib/python3.10/idlelib/Icons/idle.ico +0 -0
- llava/lib/python3.10/idlelib/NEWS.txt +1321 -0
- llava/lib/python3.10/idlelib/TODO.txt +210 -0
- llava/lib/python3.10/idlelib/__main__.py +8 -0
- llava/lib/python3.10/idlelib/autocomplete_w.py +502 -0
- llava/lib/python3.10/idlelib/browser.py +258 -0
- llava/lib/python3.10/idlelib/calltip.py +205 -0
- llava/lib/python3.10/idlelib/calltip_w.py +201 -0
- llava/lib/python3.10/idlelib/codecontext.py +270 -0
- llava/lib/python3.10/idlelib/colorizer.py +384 -0
- llava/lib/python3.10/idlelib/config-extensions.def +62 -0
- llava/lib/python3.10/idlelib/config.py +911 -0
- llava/lib/python3.10/idlelib/config_key.py +354 -0
- llava/lib/python3.10/idlelib/debugger.py +550 -0
- llava/lib/python3.10/idlelib/debugger_r.py +393 -0
- llava/lib/python3.10/idlelib/debugobj.py +142 -0
- llava/lib/python3.10/idlelib/debugobj_r.py +41 -0
- llava/lib/python3.10/idlelib/delegator.py +33 -0
- llava/lib/python3.10/idlelib/extend.txt +83 -0
- llava/lib/python3.10/idlelib/filelist.py +131 -0
- llava/lib/python3.10/idlelib/grep.py +221 -0
- llava/lib/python3.10/idlelib/help_about.py +212 -0
- llava/lib/python3.10/idlelib/history.py +106 -0
- llava/lib/python3.10/idlelib/hyperparser.py +312 -0
- llava/lib/python3.10/idlelib/idle.bat +4 -0
- llava/lib/python3.10/idlelib/idle.py +14 -0
- llava/lib/python3.10/idlelib/idle.pyw +17 -0
- llava/lib/python3.10/idlelib/iomenu.py +437 -0
- llava/lib/python3.10/idlelib/macosx.py +301 -0
- llava/lib/python3.10/idlelib/mainmenu.py +126 -0
- llava/lib/python3.10/idlelib/multicall.py +448 -0
- llava/lib/python3.10/idlelib/outwin.py +187 -0
- llava/lib/python3.10/idlelib/parenmatch.py +183 -0
- llava/lib/python3.10/idlelib/pathbrowser.py +111 -0
- llava/lib/python3.10/idlelib/pyparse.py +589 -0
- llava/lib/python3.10/idlelib/pyshell.py +1713 -0
- llava/lib/python3.10/idlelib/redirector.py +174 -0
- llava/lib/python3.10/idlelib/runscript.py +213 -0
- llava/lib/python3.10/idlelib/scrolledlist.py +149 -0
- llava/lib/python3.10/idlelib/searchbase.py +210 -0
- llava/lib/python3.10/idlelib/sidebar.py +544 -0
- llava/lib/python3.10/idlelib/squeezer.py +345 -0
- llava/lib/python3.10/idlelib/statusbar.py +50 -0
- llava/lib/python3.10/idlelib/tree.py +500 -0
- llava/lib/python3.10/idlelib/undo.py +366 -0
- llava/lib/python3.10/idlelib/util.py +21 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_adaptive_avg_pool2d_backward_ops.h +39 -0
.gitattributes
CHANGED
|
@@ -438,3 +438,4 @@ llava/lib/python3.10/ensurepip/_bundled/pip-23.0.1-py3-none-any.whl filter=lfs d
|
|
| 438 |
parrot/lib/python3.10/site-packages/pyarrow/libarrow.so.1700 filter=lfs diff=lfs merge=lfs -text
|
| 439 |
llava/lib/python3.10/lib2to3/tests/__pycache__/test_fixers.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 440 |
parrot/lib/libtsan.so.0 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 438 |
parrot/lib/python3.10/site-packages/pyarrow/libarrow.so.1700 filter=lfs diff=lfs merge=lfs -text
|
| 439 |
llava/lib/python3.10/lib2to3/tests/__pycache__/test_fixers.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 440 |
parrot/lib/libtsan.so.0 filter=lfs diff=lfs merge=lfs -text
|
| 441 |
+
parrot/lib/python3.10/site-packages/torch/lib/libc10.so filter=lfs diff=lfs merge=lfs -text
|
llava/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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 605 |
+
|
| 606 |
+
* TODO.txt: A few new TODO entries.
|
| 607 |
+
|
| 608 |
+
Thu Aug 26 23:06:22 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 632 |
+
|
| 633 |
+
* TODO.txt: New wishes.
|
| 634 |
+
|
| 635 |
+
Sat Jul 10 13:17:35 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 1408 |
+
|
| 1409 |
+
* Attic/turtle.py: Moved to Python 1.5.2/Lib
|
| 1410 |
+
|
| 1411 |
+
Fri Nov 27 03:19:20 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 1429 |
+
|
| 1430 |
+
* Attic/turtle.py: root is now a global called _root
|
| 1431 |
+
|
| 1432 |
+
Sat Oct 24 16:38:38 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 <guido@cnri.reston.va.us>
|
| 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 |
+
|
llava/lib/python3.10/idlelib/Icons/README.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The IDLE icons are from https://bugs.python.org/issue1490384
|
| 2 |
+
|
| 3 |
+
Created by Andrew Clover.
|
| 4 |
+
|
| 5 |
+
The original sources are available from Andrew's website:
|
| 6 |
+
https://www.doxdesk.com/software/py/pyicons.html
|
| 7 |
+
|
| 8 |
+
Various different formats and sizes are available at this GitHub Pull Request:
|
| 9 |
+
https://github.com/python/cpython/pull/17473
|
| 10 |
+
|
| 11 |
+
The idle.ico file was created with ImageMagick:
|
| 12 |
+
|
| 13 |
+
$ convert idle_16.png idle_32.png idle_48.png idle_256.png idle.ico
|
llava/lib/python3.10/idlelib/Icons/idle.ico
ADDED
|
|
llava/lib/python3.10/idlelib/NEWS.txt
ADDED
|
@@ -0,0 +1,1321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
What's New in IDLE 3.10.z
|
| 2 |
+
after 3.10.0 until 3.10.10?
|
| 3 |
+
Released 2023-04-03?
|
| 4 |
+
=========================
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
gh-97527: Fix a bug in the previous bugfix that caused IDLE to not
|
| 8 |
+
start when run with 3.10.8, 3.12.0a1, and at least Microsoft Python
|
| 9 |
+
3.10.2288.0 installed without the Lib/test package. 3.11.0 was never
|
| 10 |
+
affected.
|
| 11 |
+
|
| 12 |
+
gh-65802: Document handling of extensions in Save As dialogs.
|
| 13 |
+
|
| 14 |
+
gh-95191: Include prompts when saving Shell (interactive input/output).
|
| 15 |
+
|
| 16 |
+
gh-95511: Fix the Shell context menu copy-with-prompts bug of copying
|
| 17 |
+
an extra line when one selects whole lines.
|
| 18 |
+
|
| 19 |
+
gh-95471: Tweak Edit menu. Move 'Select All' above 'Cut' as it is used
|
| 20 |
+
with 'Cut' and 'Copy' but not 'Paste'. Add a separator between 'Replace'
|
| 21 |
+
and 'Go to Line' to help IDLE issue triagers.
|
| 22 |
+
|
| 23 |
+
gh-95411: Enable using IDLE's module browser with .pyw files.
|
| 24 |
+
|
| 25 |
+
gh-89610: Add .pyi as a recognized extension for IDLE on macOS. This allows
|
| 26 |
+
opening stub files by double clicking on them in the Finder.
|
| 27 |
+
|
| 28 |
+
bpo-28950: Apply IDLE syntax highlighting to `.pyi` files. Add util.py
|
| 29 |
+
for common components. Patch by Alex Waygood and Terry Jan Reedy.
|
| 30 |
+
|
| 31 |
+
bpo-46630: Make query dialogs on Windows start with a cursor in the
|
| 32 |
+
entry box.
|
| 33 |
+
|
| 34 |
+
bpo-46591: Make the IDLE doc URL on the About IDLE dialog clickable.
|
| 35 |
+
|
| 36 |
+
bpo-45296: Clarify close, quit, and exit in IDLE. In the File menu,
|
| 37 |
+
'Close' and 'Exit' are now 'Close Window' (the current one) and 'Exit'
|
| 38 |
+
is now 'Exit IDLE' (by closing all windows). In Shell, 'quit()' and
|
| 39 |
+
'exit()' mean 'close Shell'. If there are no other windows,
|
| 40 |
+
this also exits IDLE.
|
| 41 |
+
|
| 42 |
+
bpo-45495: Add context keywords 'case' and 'match' to completions list.
|
| 43 |
+
|
| 44 |
+
bpo-45296: On Windows, change exit/quit message to suggest Ctrl-D, which
|
| 45 |
+
works, instead of <Ctrl-Z Return>, which does not work in IDLE.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
What's New in IDLE 3.10.0
|
| 49 |
+
(since 3.9.0)
|
| 50 |
+
Released on 2021-10-04
|
| 51 |
+
=========================
|
| 52 |
+
|
| 53 |
+
bpo-45193: Make completion boxes appear on Ubuntu again.
|
| 54 |
+
|
| 55 |
+
bpo-40128: Mostly fix completions on macOS when not using tcl/tk 8.6.11
|
| 56 |
+
(as with 3.9).
|
| 57 |
+
|
| 58 |
+
bpo-33962: Move the indent space setting from the Font tab to the new Windows
|
| 59 |
+
tab. Patch by Mark Roseman and Terry Jan Reedy.
|
| 60 |
+
|
| 61 |
+
bpo-40468: Split the settings dialog General tab into Windows and Shell/Ed
|
| 62 |
+
tabs. Move help sources, which extend the Help menu, to the Extensions tab.
|
| 63 |
+
Make space for new options and shorten the dialog. The latter makes the
|
| 64 |
+
dialog better fit small screens.
|
| 65 |
+
|
| 66 |
+
bpo-44010: Highlight the new match statement's soft keywords: match, case,
|
| 67 |
+
and _. This highlighting is not perfect and will be incorrect in some rare
|
| 68 |
+
cases, especially for some _s in case patterns.
|
| 69 |
+
|
| 70 |
+
bpo-44026: Include interpreter's typo fix suggestions in message line
|
| 71 |
+
for NameErrors and AttributeErrors. Patch by E. Paine.
|
| 72 |
+
|
| 73 |
+
bpo-41611: Avoid occasional uncaught exceptions and freezing when using
|
| 74 |
+
completions on macOS.
|
| 75 |
+
|
| 76 |
+
bpo-37903: Add mouse actions to the shell sidebar. Left click and
|
| 77 |
+
optional drag selects one or more lines of text, as with the
|
| 78 |
+
editor line number sidebar. Right click after selecting text lines
|
| 79 |
+
displays a context menu with 'copy with prompts'. This zips together
|
| 80 |
+
prompts from the sidebar with lines from the selected text. This option
|
| 81 |
+
also appears on the context menu for the text.
|
| 82 |
+
|
| 83 |
+
bpo-43981: Fix reference leaks in test_sidebar and test_squeezer.
|
| 84 |
+
Patches by Terry Jan Reedy and Pablo Galindo
|
| 85 |
+
|
| 86 |
+
bpo-37892: Change Shell input indents from tabs to spaces. Shell input
|
| 87 |
+
now 'looks right'. Making this feasible motivated the shell sidebar.
|
| 88 |
+
|
| 89 |
+
bpo-37903: Move the Shell input prompt to a side bar.
|
| 90 |
+
|
| 91 |
+
bpo-43655: Make window managers on macOS and X Window recognize
|
| 92 |
+
IDLE dialog windows as dialogs.
|
| 93 |
+
|
| 94 |
+
bpo-42225: Document that IDLE can fail on Unix either from misconfigured IP
|
| 95 |
+
masquerade rules or failure displaying complex colored (non-ascii) characters.
|
| 96 |
+
|
| 97 |
+
bpo-43283: Document why printing to IDLE's Shell is often slower than
|
| 98 |
+
printing to a system terminal and that it can be made faster by
|
| 99 |
+
pre-formatting a single string before printing.
|
| 100 |
+
|
| 101 |
+
bpo-23544: Disable Debug=>Stack Viewer when user code is running or
|
| 102 |
+
Debugger is active, to prevent hang or crash. Patch by Zackery Spytz.
|
| 103 |
+
|
| 104 |
+
bpo-43008: Make IDLE invoke :func:`sys.excepthook` in normal,
|
| 105 |
+
2-process mode. User hooks were previously ignored.
|
| 106 |
+
Patch by Ken Hilton.
|
| 107 |
+
|
| 108 |
+
bpo-33065: Fix problem debugging user classes with __repr__ method.
|
| 109 |
+
|
| 110 |
+
bpo-32631: Finish zzdummy example extension module: make menu entries
|
| 111 |
+
work; add docstrings and tests with 100% coverage.
|
| 112 |
+
|
| 113 |
+
bpo-42508: Keep IDLE running on macOS. Remove obsolete workaround
|
| 114 |
+
that prevented running files with shortcuts when using new universal2
|
| 115 |
+
installers built on macOS 11.
|
| 116 |
+
|
| 117 |
+
bpo-42426: Fix reporting offset of the RE error in searchengine.
|
| 118 |
+
|
| 119 |
+
bpo-42416: Display docstrings in IDLE calltips in more cases,
|
| 120 |
+
by using inspect.getdoc.
|
| 121 |
+
|
| 122 |
+
bpo-33987: Mostly finish using ttk widgets, mainly for editor,
|
| 123 |
+
settings, and searches. Some patches by Mark Roseman.
|
| 124 |
+
|
| 125 |
+
bpo-40511: Stop unnecessary "flashing" when typing opening and closing
|
| 126 |
+
parentheses inside the parentheses of a function call.
|
| 127 |
+
|
| 128 |
+
bpo-38439: Add a 256x256 pixel IDLE icon to the Windows .ico file. Created by
|
| 129 |
+
Andrew Clover. Remove the low-color gif variations from the .ico file.
|
| 130 |
+
|
| 131 |
+
bpo-41775: Make 'IDLE Shell' the shell title.
|
| 132 |
+
|
| 133 |
+
bpo-35764: Rewrite the Calltips doc section.
|
| 134 |
+
|
| 135 |
+
bpo-40181: In calltips, stop reminding that '/' marks the end of
|
| 136 |
+
positional-only arguments.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
What's New in IDLE 3.9.0 (since 3.8.0)
|
| 140 |
+
Released on 2020-10-05?
|
| 141 |
+
======================================
|
| 142 |
+
|
| 143 |
+
bpo-41468: Improve IDLE run crash error message (which users should
|
| 144 |
+
never see).
|
| 145 |
+
|
| 146 |
+
bpo-41373: Save files loaded with no line ending, as when blank, or
|
| 147 |
+
different line endings, by setting its line ending to the system
|
| 148 |
+
default. Fix regression in 3.8.4 and 3.9.0b4.
|
| 149 |
+
|
| 150 |
+
bpo-41300: Save files with non-ascii chars. Fix regression in
|
| 151 |
+
3.9.0b4 and 3.8.4.
|
| 152 |
+
|
| 153 |
+
bpo-37765: Add keywords to module name completion list. Rewrite
|
| 154 |
+
Completions section of IDLE doc.
|
| 155 |
+
|
| 156 |
+
bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
|
| 157 |
+
is now always UTF-8.
|
| 158 |
+
|
| 159 |
+
bpo-41144: Make Open Module open a special module such as os.path.
|
| 160 |
+
|
| 161 |
+
bpo-40723: Make test_idle pass when run after import.
|
| 162 |
+
Patch by Florian Dahlitz.
|
| 163 |
+
|
| 164 |
+
bpo-38689: IDLE will no longer freeze when inspect.signature fails
|
| 165 |
+
when fetching a calltip.
|
| 166 |
+
|
| 167 |
+
bpo-27115: For 'Go to Line', use a Query entry box subclass with
|
| 168 |
+
IDLE standard behavior and improved error checking.
|
| 169 |
+
|
| 170 |
+
bpo-39885: When a context menu is invoked by right-clicking outside
|
| 171 |
+
of a selection, clear the selection and move the cursor. Cut and
|
| 172 |
+
Copy require that the click be within the selection.
|
| 173 |
+
|
| 174 |
+
bpo-39852: Edit "Go to line" now clears any selection, preventing
|
| 175 |
+
accidental deletion. It also updates Ln and Col on the status bar.
|
| 176 |
+
|
| 177 |
+
bpo-39781: Selecting code context lines no longer causes a jump.
|
| 178 |
+
|
| 179 |
+
bpo-39663: Add tests for pyparse find_good_parse_start().
|
| 180 |
+
|
| 181 |
+
bpo-39600: Remove duplicate font names from configuration list.
|
| 182 |
+
|
| 183 |
+
bpo-38792: Close a shell calltip if a :exc:`KeyboardInterrupt`
|
| 184 |
+
or shell restart occurs. Patch by Zackery Spytz.
|
| 185 |
+
|
| 186 |
+
bpo-30780: Add remaining configdialog tests for buttons and
|
| 187 |
+
highlights and keys tabs.
|
| 188 |
+
|
| 189 |
+
bpo-39388: Settings dialog Cancel button cancels pending changes.
|
| 190 |
+
|
| 191 |
+
bpo-39050: Settings dialog Help button again displays help text.
|
| 192 |
+
|
| 193 |
+
bpo-32989: Add tests for editor newline_and_indent_event method.
|
| 194 |
+
Remove unneeded arguments and dead code from pyparse
|
| 195 |
+
find_good_parse_start method.
|
| 196 |
+
|
| 197 |
+
bpo-38943: Fix autocomplete windows not always appearing on some
|
| 198 |
+
systems. Patch by Johnny Najera.
|
| 199 |
+
|
| 200 |
+
bpo-38944: Escape key now closes IDLE completion windows. Patch by
|
| 201 |
+
Johnny Najera.
|
| 202 |
+
|
| 203 |
+
bpo-38862: 'Strip Trailing Whitespace' on the Format menu removes extra
|
| 204 |
+
newlines at the end of non-shell files.
|
| 205 |
+
|
| 206 |
+
bpo-38636: Fix IDLE Format menu tab toggle and file indent width. These
|
| 207 |
+
functions (default shortcuts Alt-T and Alt-U) were mistakenly disabled
|
| 208 |
+
in 3.7.5 and 3.8.0.
|
| 209 |
+
|
| 210 |
+
bpo-4630: Add an option to toggle IDLE's cursor blink for shell,
|
| 211 |
+
editor, and output windows. See Settings, General, Window Preferences,
|
| 212 |
+
Cursor Blink. Patch by Zackery Spytz.
|
| 213 |
+
|
| 214 |
+
bpo-26353: Stop adding newline when saving an IDLE shell window.
|
| 215 |
+
|
| 216 |
+
bpo-38598: Do not try to compile IDLE shell or output windows.
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
What's New in IDLE 3.8.0 (since 3.7.0)
|
| 220 |
+
Released on 2019-10-14
|
| 221 |
+
======================================
|
| 222 |
+
|
| 223 |
+
bpo-36698: IDLE no longer fails when writing non-encodable characters
|
| 224 |
+
to stderr. It now escapes them with a backslash, like the regular
|
| 225 |
+
Python interpreter. Add an errors field to the standard streams.
|
| 226 |
+
|
| 227 |
+
bpo-13153: Improve tkinter's handing of non-BMP (astral) unicode
|
| 228 |
+
characters, such as 'rocket \U0001f680'. Whether a proper glyph or
|
| 229 |
+
replacement char is displayed depends on the OS and font. For IDLE,
|
| 230 |
+
astral chars in code interfere with editing.
|
| 231 |
+
|
| 232 |
+
bpo-35379: When exiting IDLE, catch any AttributeError. One happens
|
| 233 |
+
when EditorWindow.close is called twice. Printing a traceback, when
|
| 234 |
+
IDLE is run from a terminal, is useless and annoying.
|
| 235 |
+
|
| 236 |
+
bpo-38183: To avoid test issues, test_idle ignores the user config
|
| 237 |
+
directory. It no longer tries to create or access .idlerc or any files
|
| 238 |
+
within. Users must run IDLE to discover problems with saving settings.
|
| 239 |
+
|
| 240 |
+
bpo-38077: IDLE no longer adds 'argv' to the user namespace when
|
| 241 |
+
initializing it. This bug only affected 3.7.4 and 3.8.0b2 to 3.8.0b4.
|
| 242 |
+
|
| 243 |
+
bpo-38401: Shell restart lines now fill the window width, always start
|
| 244 |
+
with '=', and avoid wrapping unnecessarily. The line will still wrap
|
| 245 |
+
if the included file name is long relative to the width.
|
| 246 |
+
|
| 247 |
+
bpo-37092: Add mousewheel scrolling for IDLE module, path, and stack
|
| 248 |
+
browsers. Patch by George Zhang.
|
| 249 |
+
|
| 250 |
+
bpo-35771: To avoid occasional spurious test_idle failures on slower
|
| 251 |
+
machines, increase the ``hover_delay`` in test_tooltip.
|
| 252 |
+
|
| 253 |
+
bpo-37824: Properly handle user input warnings in IDLE shell.
|
| 254 |
+
Cease turning SyntaxWarnings into SyntaxErrors.
|
| 255 |
+
|
| 256 |
+
bpo-37929: IDLE Settings dialog now closes properly when there is no
|
| 257 |
+
shell window.
|
| 258 |
+
|
| 259 |
+
bpo-37849: Fix completions list appearing too high or low when shown
|
| 260 |
+
above the current line.
|
| 261 |
+
|
| 262 |
+
bpo-36419: Refactor autocompete and improve testing.
|
| 263 |
+
|
| 264 |
+
bpo-37748: Reorder the Run menu. Put the most common choice,
|
| 265 |
+
Run Module, at the top.
|
| 266 |
+
|
| 267 |
+
bpo-37692: Improve highlight config sample with example shell
|
| 268 |
+
interaction and better labels for shell elements.
|
| 269 |
+
|
| 270 |
+
bpo-37628: Settings dialog no longer expands with font size.
|
| 271 |
+
The font and highlight sample boxes gain scrollbars instead.
|
| 272 |
+
|
| 273 |
+
bpo-17535: Add optional line numbers for IDLE editor windows.
|
| 274 |
+
|
| 275 |
+
bpo-37627: Initialize the Customize Run dialog with the command line
|
| 276 |
+
arguments most recently entered before. The user can optionally edit
|
| 277 |
+
before submitting them.
|
| 278 |
+
|
| 279 |
+
bpo-33610: Code context always shows the correct context when toggled on.
|
| 280 |
+
|
| 281 |
+
bpo-36390: Gather Format menu functions into format.py. Combine
|
| 282 |
+
paragraph.py, rstrip.py, and format methods from editor.py.
|
| 283 |
+
|
| 284 |
+
bpo-37530: Optimize code context to reduce unneeded background activity.
|
| 285 |
+
Font and highlight changes now occur along with text changes instead
|
| 286 |
+
of after a random delay.
|
| 287 |
+
|
| 288 |
+
bpo-27452: Cleanup config.py by inlining RemoveFile and simplifying
|
| 289 |
+
the handling of __file__ in CreateConfigHandlers/
|
| 290 |
+
|
| 291 |
+
bpo-26806: To compensate for stack frames added by IDLE and avoid
|
| 292 |
+
possible problems with low recursion limits, add 30 to limits in the
|
| 293 |
+
user code execution process. Subtract 30 when reporting recursion
|
| 294 |
+
limits to make this addition mostly transparent.
|
| 295 |
+
|
| 296 |
+
bpo-37325: Fix tab focus traversal order for help source and custom
|
| 297 |
+
run dialogs.
|
| 298 |
+
|
| 299 |
+
bpo-37321: Both subprocess connection error messages now refer to
|
| 300 |
+
the 'Startup failure' section of the IDLE doc.
|
| 301 |
+
|
| 302 |
+
bpo-37177: Properly attach search dialogs to their main window so
|
| 303 |
+
that they behave like other dialogs and do not get hidden behind
|
| 304 |
+
their main window.
|
| 305 |
+
|
| 306 |
+
bpo-37039: Adjust "Zoom Height" to individual screens by momentarily
|
| 307 |
+
maximizing the window on first use with a particular screen. Changing
|
| 308 |
+
screen settings may invalidate the saved height. While a window is
|
| 309 |
+
maximized, "Zoom Height" has no effect.
|
| 310 |
+
|
| 311 |
+
bpo-35763: Make calltip reminder about '/' meaning positional-only less
|
| 312 |
+
obtrusive by only adding it when there is room on the first line.
|
| 313 |
+
|
| 314 |
+
bpo-5680: Add 'Run Customized' to the Run menu to run a module with
|
| 315 |
+
customized settings. Any command line arguments entered are added
|
| 316 |
+
to sys.argv. One can suppress the normal Shell main module restart.
|
| 317 |
+
|
| 318 |
+
bpo-35610: Replace now redundant editor.context_use_ps1 with
|
| 319 |
+
.prompt_last_line. This finishes change started in bpo-31858.
|
| 320 |
+
|
| 321 |
+
bpo-32411: Stop sorting dict created with desired line order.
|
| 322 |
+
|
| 323 |
+
bpo-37038: Make idlelib.run runnable; add test clause.
|
| 324 |
+
|
| 325 |
+
bpo-36958: Print any argument other than None or int passed to
|
| 326 |
+
SystemExit or sys.exit().
|
| 327 |
+
|
| 328 |
+
bpo-36807: When saving a file, call file.flush() and os.fsync()
|
| 329 |
+
so bits are flushed to e.g. a USB drive.
|
| 330 |
+
|
| 331 |
+
bpo-36429: Fix starting IDLE with pyshell.
|
| 332 |
+
Add idlelib.pyshell alias at top; remove pyshell alias at bottom.
|
| 333 |
+
Remove obsolete __name__=='__main__' command.
|
| 334 |
+
|
| 335 |
+
bpo-30348: Increase test coverage of idlelib.autocomplete by 30%.
|
| 336 |
+
Patch by Louie Lu.
|
| 337 |
+
|
| 338 |
+
bpo-23205: Add tests and refactor grep's findfiles.
|
| 339 |
+
|
| 340 |
+
bpo-36405: Use dict unpacking in idlelib.
|
| 341 |
+
|
| 342 |
+
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
|
| 343 |
+
This param was only used twice and changed the return type.
|
| 344 |
+
|
| 345 |
+
bpo-23216: IDLE: Add docstrings to search modules.
|
| 346 |
+
|
| 347 |
+
bpo-36176: Fix IDLE autocomplete & calltip popup colors.
|
| 348 |
+
Prevent conflicts with Linux dark themes
|
| 349 |
+
(and slightly darken calltip background).
|
| 350 |
+
|
| 351 |
+
bpo-36152: Remove colorizer.ColorDelegator.close_when_done and the
|
| 352 |
+
corresponding argument of .close(). In IDLE, both have always been
|
| 353 |
+
None or False since 2007.
|
| 354 |
+
|
| 355 |
+
bpo-36096: Make colorizer state variables instance-only.
|
| 356 |
+
|
| 357 |
+
bpo-32129: Avoid blurry IDLE application icon on macOS with Tk 8.6.
|
| 358 |
+
Patch by Kevin Walzer.
|
| 359 |
+
|
| 360 |
+
bpo-24310: Document settings dialog font tab sample.
|
| 361 |
+
|
| 362 |
+
bpo-35689: Add docstrings and tests for colorizer.
|
| 363 |
+
|
| 364 |
+
bpo-35833: Revise IDLE doc for control codes sent to Shell.
|
| 365 |
+
Add a code example block.
|
| 366 |
+
|
| 367 |
+
bpo-35770: IDLE macosx deletes Options => Configure IDLE.
|
| 368 |
+
It previously deleted Window => Zoom Height by mistake.
|
| 369 |
+
(Zoom Height is now on the Options menu). On Mac, the settings
|
| 370 |
+
dialog is accessed via Preferences on the IDLE menu.
|
| 371 |
+
|
| 372 |
+
bpo-35769: Change new file name from 'Untitled' to 'untitled'.
|
| 373 |
+
|
| 374 |
+
bpo-35660: Fix imports in window module.
|
| 375 |
+
|
| 376 |
+
bpo-35641: Properly format calltip for function without docstring.
|
| 377 |
+
|
| 378 |
+
bpo-33987: Use ttk Frame for ttk widgets.
|
| 379 |
+
|
| 380 |
+
bpo-34055: Fix erroneous 'smart' indents and newlines in IDLE Shell.
|
| 381 |
+
|
| 382 |
+
bpo-28097: Add Previous/Next History entries to Shell menu.
|
| 383 |
+
|
| 384 |
+
bpo-35591: Find Selection now works when selection not found.
|
| 385 |
+
|
| 386 |
+
bpo-35598: Update config_key: use PEP 8 names and ttk widgets,
|
| 387 |
+
make some objects global, and add tests.
|
| 388 |
+
|
| 389 |
+
bpo-35196: Speed up squeezer line counting.
|
| 390 |
+
|
| 391 |
+
bpo-35208: Squeezer now counts wrapped lines before newlines.
|
| 392 |
+
|
| 393 |
+
bpo-35555: Gray out Code Context menu entry when it's not applicable.
|
| 394 |
+
|
| 395 |
+
bpo-22703: Improve the Code Context and Zoom Height menu labels.
|
| 396 |
+
The Code Context menu label now toggles between Show/Hide Code Context.
|
| 397 |
+
The Zoom Height menu now toggles between Zoom/Restore Height.
|
| 398 |
+
Zoom Height has moved from the Window menu to the Options menu.
|
| 399 |
+
|
| 400 |
+
bpo-35521: Document the editor code context feature.
|
| 401 |
+
Add some internal references within the IDLE doc.
|
| 402 |
+
|
| 403 |
+
bpo-34864: When starting IDLE on MacOS, warn if the system setting
|
| 404 |
+
"Prefer tabs when opening documents" is "Always". As previous
|
| 405 |
+
documented for this issue, running IDLE with this setting causes
|
| 406 |
+
problems. If the setting is changed while IDLE is running,
|
| 407 |
+
there will be no warning until IDLE is restarted.
|
| 408 |
+
|
| 409 |
+
bpo-35213: Where appropriate, use 'macOS' in idlelib.
|
| 410 |
+
|
| 411 |
+
bpo-34864: Document two IDLE on MacOS issues. The System Preferences
|
| 412 |
+
Dock "prefer tabs always" setting disables some IDLE features.
|
| 413 |
+
Menus are a bit different than as described for Windows and Linux.
|
| 414 |
+
|
| 415 |
+
bpo-35202: Remove unused imports in idlelib.
|
| 416 |
+
|
| 417 |
+
bpo-33000: Document that IDLE's shell has no line limit.
|
| 418 |
+
A program that runs indefinitely can overfill memory.
|
| 419 |
+
|
| 420 |
+
bpo-23220: Explain how IDLE's Shell displays output.
|
| 421 |
+
Add new subsection "User output in Shell".
|
| 422 |
+
|
| 423 |
+
bpo-35099: Improve the doc about IDLE running user code.
|
| 424 |
+
"IDLE -- console differences" is renamed "Running user code".
|
| 425 |
+
It mostly covers the implications of using custom sys.stdxxx objects.
|
| 426 |
+
|
| 427 |
+
bpo-35097: Add IDLE doc subsection explaining editor windows.
|
| 428 |
+
Topics include opening, title and status bars, .py* extension, and running.
|
| 429 |
+
|
| 430 |
+
Issue 35093: Document the IDLE document viewer in the IDLE doc.
|
| 431 |
+
Add a paragraph in "Help and preferences", "Help sources" subsection.
|
| 432 |
+
|
| 433 |
+
bpo-1529353: Explain Shell text squeezing in the IDLE doc.
|
| 434 |
+
|
| 435 |
+
bpo-35088: Update idlelib.help.copy_string docstring.
|
| 436 |
+
We now use git and backporting instead of hg and forward merging.
|
| 437 |
+
|
| 438 |
+
bpo-35087: Update idlelib help files for the current doc build.
|
| 439 |
+
The main change is the elimination of chapter-section numbers.
|
| 440 |
+
|
| 441 |
+
bpo-1529353: Output over N lines (50 by default) is squeezed down to a button.
|
| 442 |
+
N can be changed in the PyShell section of the General page of the
|
| 443 |
+
Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
|
| 444 |
+
right clicking on the output. Squeezed output can be expanded in place
|
| 445 |
+
by double-clicking the button or into the clipboard or a separate window
|
| 446 |
+
by right-clicking the button.
|
| 447 |
+
|
| 448 |
+
bpo-34548: Use configured color theme for read-only text views.
|
| 449 |
+
|
| 450 |
+
bpo-33839: Refactor ToolTip and CallTip classes; add documentation
|
| 451 |
+
and tests.
|
| 452 |
+
|
| 453 |
+
bpo-34047: Fix mouse wheel scrolling direction on macOS.
|
| 454 |
+
|
| 455 |
+
bpo-34275: Make calltips always visible on Mac.
|
| 456 |
+
Patch by Kevin Walzer.
|
| 457 |
+
|
| 458 |
+
bpo-34120: Fix freezing after closing some dialogs on Mac.
|
| 459 |
+
This is one of multiple regressions from using newer tcl/tk.
|
| 460 |
+
|
| 461 |
+
bpo-33975: Avoid small type when running htests.
|
| 462 |
+
Since part of the purpose of human-viewed tests is to determine that
|
| 463 |
+
widgets look right, it is important that they look the same for
|
| 464 |
+
testing as when running IDLE.
|
| 465 |
+
|
| 466 |
+
bpo-33905: Add test for idlelib.stackview.StackBrowser.
|
| 467 |
+
|
| 468 |
+
bpo-33924: Change mainmenu.menudefs key 'windows' to 'window'.
|
| 469 |
+
Every other menudef key is the lowercase version of the
|
| 470 |
+
corresponding main menu entry (in this case, 'Window').
|
| 471 |
+
|
| 472 |
+
bpo-33906: Rename idlelib.windows as window
|
| 473 |
+
Match Window on the main menu and remove last plural module name.
|
| 474 |
+
Change imports, test, and attribute references to match new name.
|
| 475 |
+
|
| 476 |
+
bpo-33917: Fix and document idlelib/idle_test/template.py.
|
| 477 |
+
The revised file compiles, runs, and tests OK. idle_test/README.txt
|
| 478 |
+
explains how to use it to create new IDLE test files.
|
| 479 |
+
|
| 480 |
+
bpo-33904: In rstrip module, rename class RstripExtension as Rstrip.
|
| 481 |
+
|
| 482 |
+
bpo-33907: For consistency and clarity, rename calltip objects.
|
| 483 |
+
Module calltips and its class CallTips are now calltip and Calltip.
|
| 484 |
+
In module calltip_w, class CallTip is now CalltipWindow.
|
| 485 |
+
|
| 486 |
+
bpo-33855: Minimally test all IDLE modules.
|
| 487 |
+
Standardize the test file format. Add missing test files that import
|
| 488 |
+
the tested module and perform at least one test. Check and record the
|
| 489 |
+
coverage of each test.
|
| 490 |
+
|
| 491 |
+
bpo-33856: Add 'help' to Shell's initial welcome message.
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
What's New in IDLE 3.7.0 (since 3.6.0)
|
| 495 |
+
Released on 2018-06-27
|
| 496 |
+
======================================
|
| 497 |
+
|
| 498 |
+
bpo-33656: On Windows, add API call saying that tk scales for DPI.
|
| 499 |
+
On Windows 8.1+ or 10, with DPI compatibility properties of the Python
|
| 500 |
+
binary unchanged, and a monitor resolution greater than 96 DPI, this
|
| 501 |
+
should make text and lines sharper and some colors brighter.
|
| 502 |
+
On other systems, it should have no effect. If you have a custom theme,
|
| 503 |
+
you may want to adjust a color or two. If perchance it make text worse
|
| 504 |
+
on your monitor, you can disable the ctypes.OleDLL call near the top of
|
| 505 |
+
pyshell.py and report the problem on python-list or idle-dev@python.org.
|
| 506 |
+
|
| 507 |
+
bpo-33768: Clicking on a context line moves that line to the top
|
| 508 |
+
of the editor window.
|
| 509 |
+
|
| 510 |
+
bpo-33763: Replace the code context label widget with a text widget.
|
| 511 |
+
|
| 512 |
+
bpo-33664: Scroll IDLE editor text by lines.
|
| 513 |
+
(Previously, the mouse wheel and scrollbar slider moved text by a fixed
|
| 514 |
+
number of pixels, resulting in partial lines at the top of the editor
|
| 515 |
+
box.) This change also applies to the shell and grep output windows,
|
| 516 |
+
but currently not to read-only text views.
|
| 517 |
+
|
| 518 |
+
bpo-33679: Enable theme-specific color configuration for Code Context.
|
| 519 |
+
(Previously, there was one code context foreground and background font
|
| 520 |
+
color setting, default or custom, on the extensions tab, that applied
|
| 521 |
+
to all themes.) For built-in themes, the foreground is the same as
|
| 522 |
+
normal text and the background is a contrasting gray. Context colors for
|
| 523 |
+
custom themes are set on the Hightlights tab along with other colors.
|
| 524 |
+
When one starts IDLE from a console and loads a custom theme without
|
| 525 |
+
definitions for 'context', one will see a warning message on the
|
| 526 |
+
console.
|
| 527 |
+
|
| 528 |
+
bpo-33642: Display up to maxlines non-blank lines for Code Context.
|
| 529 |
+
If there is no current context, show a single blank line. (Previously,
|
| 530 |
+
the Code Contex had numlines lines, usually with some blank.) The use
|
| 531 |
+
of a new option, 'maxlines' (default 15), avoids possible interference
|
| 532 |
+
with user settings of the old option, 'numlines' (default 3).
|
| 533 |
+
|
| 534 |
+
bpo-33628: Cleanup codecontext.py and its test.
|
| 535 |
+
|
| 536 |
+
bpo-32831: Add docstrings and tests for codecontext.py.
|
| 537 |
+
Coverage is 100%. Patch by Cheryl Sabella.
|
| 538 |
+
|
| 539 |
+
bpo-33564: Code context now recognizes async as a block opener.
|
| 540 |
+
|
| 541 |
+
bpo-21474: Update word/identifier definition from ascii to unicode.
|
| 542 |
+
In text and entry boxes, this affects selection by double-click,
|
| 543 |
+
movement left/right by control-left/right, and deletion left/right
|
| 544 |
+
by control-BACKSPACE/DEL.
|
| 545 |
+
|
| 546 |
+
bpo-33204: Consistently color invalid string prefixes.
|
| 547 |
+
A 'u' string prefix cannot be paired with either 'r' or 'f'.
|
| 548 |
+
IDLE now consistently colors as much of the prefix, starting at the
|
| 549 |
+
right, as is valid. Revise and extend colorizer test.
|
| 550 |
+
|
| 551 |
+
bpo-32984: Set __file__ while running a startup file.
|
| 552 |
+
Like Python, IDLE optionally runs 1 startup file in the Shell window
|
| 553 |
+
before presenting the first interactive input prompt. For IDLE,
|
| 554 |
+
option -s runs a file named in environmental variable IDLESTARTUP or
|
| 555 |
+
PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup
|
| 556 |
+
file name before running the file and unsets it before the first
|
| 557 |
+
prompt. IDLE now does the same when run normally, without the -n
|
| 558 |
+
option.
|
| 559 |
+
|
| 560 |
+
bpo-32940: Replace StringTranslatePseudoMapping with faster code.
|
| 561 |
+
|
| 562 |
+
bpo-32916: Change 'str' to 'code' in idlelib.pyparse and users.
|
| 563 |
+
|
| 564 |
+
bpo-32905: Remove unused code in pyparse module.
|
| 565 |
+
|
| 566 |
+
bpo-32874: IDLE - add pyparse tests with 97% coverage.
|
| 567 |
+
|
| 568 |
+
bpo-32837: IDLE - require encoding argument for textview.view_file.
|
| 569 |
+
Using the system and place-dependent default encoding for open()
|
| 570 |
+
is a bad idea for IDLE's system and location-independent files.
|
| 571 |
+
|
| 572 |
+
bpo-32826: Add "encoding=utf-8" to open() in IDLE's test_help_about.
|
| 573 |
+
GUI test test_file_buttons() only looks at initial ascii-only lines,
|
| 574 |
+
but failed on systems where open() defaults to 'ascii' because
|
| 575 |
+
readline() internally reads and decodes far enough ahead to encounter
|
| 576 |
+
a non-ascii character in CREDITS.txt.
|
| 577 |
+
|
| 578 |
+
bpo-32765: Update configdialog General tab create page docstring.
|
| 579 |
+
Add new widgets to the widget list.
|
| 580 |
+
|
| 581 |
+
bpo-32207: Improve tk event exception tracebacks in IDLE.
|
| 582 |
+
When tk event handling is driven by IDLE's run loop, a confusing
|
| 583 |
+
and distracting queue.EMPTY traceback context is no longer added
|
| 584 |
+
to tk event exception tracebacks. The traceback is now the same
|
| 585 |
+
as when event handling is driven by user code. Patch based on
|
| 586 |
+
a suggestion by Serhiy Storchaka.
|
| 587 |
+
|
| 588 |
+
bpo-32164: Delete unused file idlelib/tabbedpages.py.
|
| 589 |
+
Use of TabbedPageSet in configdialog was replaced by ttk.Notebook.
|
| 590 |
+
|
| 591 |
+
bpo-32100: Fix old and new bugs in pathbrowser; improve tests.
|
| 592 |
+
Patch mostly by Cheryl Sabella.
|
| 593 |
+
|
| 594 |
+
bpo-31860: The font sample in the settings dialog is now editable.
|
| 595 |
+
Edits persist while IDLE remains open.
|
| 596 |
+
Patch by Serhiy Storchake and Terry Jan Reedy.
|
| 597 |
+
|
| 598 |
+
bpo-31858: Restrict shell prompt manipulation to the shell.
|
| 599 |
+
Editor and output windows only see an empty last prompt line. This
|
| 600 |
+
simplifies the code and fixes a minor bug when newline is inserted.
|
| 601 |
+
Sys.ps1, if present, is read on Shell start-up, but is not set or changed.
|
| 602 |
+
Patch by Terry Jan Reedy.
|
| 603 |
+
|
| 604 |
+
bpo-28603: Fix a TypeError that caused a shell restart when printing
|
| 605 |
+
a traceback that includes an exception that is unhashable.
|
| 606 |
+
Patch by Zane Bitter.
|
| 607 |
+
|
| 608 |
+
bpo-13802: Use non-Latin characters in the Font settings sample.
|
| 609 |
+
Even if one selects a font that defines a limited subset of the unicode
|
| 610 |
+
Basic Multilingual Plane, tcl/tk will use other fonts that define a
|
| 611 |
+
character. The expanded example give users of non-Latin characters
|
| 612 |
+
a better idea of what they might see in the shell and editors.
|
| 613 |
+
|
| 614 |
+
To make room for the expanded sample, frames on the Font tab are
|
| 615 |
+
re-arranged. The Font/Tabs help explains a bit about the additions.
|
| 616 |
+
Patch by Terry Jan Reedy
|
| 617 |
+
|
| 618 |
+
bpo-31460: Simplify the API of IDLE's Module Browser.
|
| 619 |
+
Passing a widget instead of an flist with a root widget opens the
|
| 620 |
+
option of creating a browser frame that is only part of a window.
|
| 621 |
+
Passing a full file name instead of pieces assumed to come from a
|
| 622 |
+
.py file opens the possibility of browsing python files that do not
|
| 623 |
+
end in .py.
|
| 624 |
+
|
| 625 |
+
bpo-31649: Make _htest and _utest parameters keyword-only.
|
| 626 |
+
These are used to adjust code for human and unit tests.
|
| 627 |
+
|
| 628 |
+
bpo-31459: Rename module browser from Class Browser to Module Browser.
|
| 629 |
+
The original module-level class and method browser became a module
|
| 630 |
+
browser, with the addition of module-level functions, years ago.
|
| 631 |
+
Nested classes and functions were added yesterday. For back-
|
| 632 |
+
compatibility, the virtual event <<open-class-browser>>, which
|
| 633 |
+
appears on the Keys tab of the Settings dialog, is not changed.
|
| 634 |
+
Patch by Cheryl Sabella.
|
| 635 |
+
|
| 636 |
+
bpo-1612262: Module browser now shows nested classes and functions.
|
| 637 |
+
Original patches for code and tests by Guilherme Polo and
|
| 638 |
+
Cheryl Sabella, respectively. Revisions by Terry Jan Reedy.
|
| 639 |
+
|
| 640 |
+
bpo-31500: Tk's default fonts now are scaled on HiDPI displays.
|
| 641 |
+
This affects all dialogs. Patch by Serhiy Storchaka.
|
| 642 |
+
|
| 643 |
+
bpo-31493: Fix code context update and font update timers.
|
| 644 |
+
Canceling timers prevents a warning message when test_idle completes.
|
| 645 |
+
|
| 646 |
+
bpo-31488: Update non-key options in former extension classes.
|
| 647 |
+
When applying configdialog changes, call .reload for each feature class.
|
| 648 |
+
Change ParenMatch so updated options affect existing instances attached
|
| 649 |
+
to existing editor windows.
|
| 650 |
+
|
| 651 |
+
bpo-31477: Improve rstrip entry in IDLE doc.
|
| 652 |
+
Strip Trailing Whitespace strips more than blank spaces.
|
| 653 |
+
Multiline string literals are not skipped.
|
| 654 |
+
|
| 655 |
+
bpo-31480: fix tests to pass with zzdummy extension disabled. (#3590)
|
| 656 |
+
To see the example in action, enable it on options extensions tab.
|
| 657 |
+
|
| 658 |
+
bpo-31421: Document how IDLE runs tkinter programs.
|
| 659 |
+
IDLE calls tcl/tk update in the background in order to make live
|
| 660 |
+
interaction and experimentation with tkinter applications much easier.
|
| 661 |
+
|
| 662 |
+
bpo-31414: Fix tk entry box tests by deleting first.
|
| 663 |
+
Adding to an int entry is not the same as deleting and inserting
|
| 664 |
+
because int('') will fail. Patch by Terry Jan Reedy.
|
| 665 |
+
|
| 666 |
+
bpo-27099: Convert IDLE's built-in 'extensions' to regular features.
|
| 667 |
+
About 10 IDLE features were implemented as supposedly optional
|
| 668 |
+
extensions. Their different behavior could be confusing or worse for
|
| 669 |
+
users and not good for maintenance. Hence the conversion.
|
| 670 |
+
The main difference for users is that user configurable key bindings
|
| 671 |
+
for builtin features are now handled uniformly. Now, editing a binding
|
| 672 |
+
in a keyset only affects its value in the keyset. All bindings are
|
| 673 |
+
defined together in the system-specific default keysets in config-
|
| 674 |
+
extensions.def. All custom keysets are saved as a whole in config-
|
| 675 |
+
extension.cfg. All take effect as soon as one clicks Apply or Ok.
|
| 676 |
+
The affected events are '<<force-open-completions>>',
|
| 677 |
+
'<<expand-word>>', '<<force-open-calltip>>', '<<flash-paren>>',
|
| 678 |
+
'<<format-paragraph>>', '<<run-module>>', '<<check-module>>', and
|
| 679 |
+
'<<zoom-height>>'. Any (global) customizations made before 3.6.3 will
|
| 680 |
+
not affect their keyset-specific customization after 3.6.3. and vice
|
| 681 |
+
versa.
|
| 682 |
+
Initial patch by Charles Wohlganger, revised by Terry Jan Reedy.
|
| 683 |
+
|
| 684 |
+
bpo-31051: Rearrange condigdialog General tab.
|
| 685 |
+
Sort non-Help options into Window (Shell+Editor) and Editor (only).
|
| 686 |
+
Leave room for the addition of new options.
|
| 687 |
+
Patch by Terry Jan Reedy.
|
| 688 |
+
|
| 689 |
+
bpo-30617: Add docstrings and tests for outwin subclass of editor.
|
| 690 |
+
Move some data and functions from the class to module level.
|
| 691 |
+
Patch by Cheryl Sabella.
|
| 692 |
+
|
| 693 |
+
bpo-31287: Do not modify tkinter.messagebox in test_configdialog.
|
| 694 |
+
Instead, mask it with an instance mock that can be deleted.
|
| 695 |
+
Patch by Terry Jan Reedy.
|
| 696 |
+
|
| 697 |
+
bpo-30781: Use ttk widgets in ConfigDialog pages.
|
| 698 |
+
These should especially look better on MacOSX.
|
| 699 |
+
Patches by Terry Jan Reedy and Cheryl Sabella.
|
| 700 |
+
|
| 701 |
+
bpo-31206: Factor HighPage(Frame) class from ConfigDialog.
|
| 702 |
+
Patch by Cheryl Sabella.
|
| 703 |
+
|
| 704 |
+
bp0-31001: Add tests for configdialog highlight tab.
|
| 705 |
+
Patch by Cheryl Sabella.
|
| 706 |
+
|
| 707 |
+
bpo-31205: Factor KeysPage(Frame) class from ConfigDialog.
|
| 708 |
+
The slightly modified tests continue to pass.
|
| 709 |
+
Patch by Cheryl Sabella.
|
| 710 |
+
|
| 711 |
+
bpo-31002: Add tests for configdialog keys tab.
|
| 712 |
+
Patch by Cheryl Sabella.
|
| 713 |
+
|
| 714 |
+
bpo-19903: Change calltipes to use inspect.signature.
|
| 715 |
+
Idlelib.calltips.get_argspec now uses inspect.signature instead of
|
| 716 |
+
inspect.getfullargspec, like help() does. This improves the signature
|
| 717 |
+
in the call tip in a few different cases, including builtins converted
|
| 718 |
+
to provide a signature. A message is added if the object is not
|
| 719 |
+
callable, has an invalid signature, or if it has positional-only
|
| 720 |
+
parameters. Patch by Louie Lu.
|
| 721 |
+
|
| 722 |
+
bop-31083: Add an outline of a TabPage class in configdialog.
|
| 723 |
+
Add template as comment. Update existing classes to match outline.
|
| 724 |
+
Initial patch by Cheryl Sabella.
|
| 725 |
+
|
| 726 |
+
bpo-31050: Factor GenPage(Frame) class from ConfigDialog.
|
| 727 |
+
The slightly modified tests for the General tab continue to pass.
|
| 728 |
+
Patch by Cheryl Sabella.
|
| 729 |
+
|
| 730 |
+
bpo-31004: Factor FontPage(Frame) class from ConfigDialog.
|
| 731 |
+
The slightly modified tests continue to pass. The General test
|
| 732 |
+
broken by the switch to ttk.Notebook is fixed.
|
| 733 |
+
Patch mostly by Cheryl Sabella.
|
| 734 |
+
|
| 735 |
+
bpo-30781: IDLE - Use ttk Notebook in ConfigDialog.
|
| 736 |
+
This improves navigation by tabbing.
|
| 737 |
+
Patch by Terry Jan Reedy.
|
| 738 |
+
|
| 739 |
+
bpo-31060: IDLE - Finish rearranging methods of ConfigDialog.
|
| 740 |
+
Grouping methods pertaining to each tab and the buttons will aid
|
| 741 |
+
writing tests and improving the tabs and will enable splitting the
|
| 742 |
+
groups into classes.
|
| 743 |
+
Patch by Terry Jan Reedy.
|
| 744 |
+
|
| 745 |
+
bpo-30853: IDLE -- Factor a VarTrace class out of ConfigDialog.
|
| 746 |
+
Instance tracers manages pairs consisting of a tk variable and a
|
| 747 |
+
callback function. When tracing is turned on, setting the variable
|
| 748 |
+
calls the function. Test coverage for the new class is 100%.
|
| 749 |
+
Patch by Terry Jan Reedy.
|
| 750 |
+
|
| 751 |
+
bpo-31003: IDLE: Add more tests for General tab.
|
| 752 |
+
Patch by Terry Jan Reedy.
|
| 753 |
+
|
| 754 |
+
bpo-30993: IDLE - Improve configdialog font page and tests.
|
| 755 |
+
*In configdialog: Document causal pathways in create_font_tab
|
| 756 |
+
docstring. Simplify some attribute names. Move set_samples calls to
|
| 757 |
+
var_changed_font (idea from Cheryl Sabella). Move related functions to
|
| 758 |
+
positions after the create widgets function.
|
| 759 |
+
* In test_configdialog: Fix test_font_set so not order dependent. Fix
|
| 760 |
+
renamed test_indent_scale so it tests the widget. Adjust tests for
|
| 761 |
+
movement of set_samples call. Add tests for load functions. Put all
|
| 762 |
+
font tests in one class and tab indent tests in another. Except for
|
| 763 |
+
two lines, these tests completely cover the related functions.
|
| 764 |
+
Patch by Terry Jan Reedy.
|
| 765 |
+
|
| 766 |
+
bpo-30981: IDLE -- Add more configdialog font page tests.
|
| 767 |
+
|
| 768 |
+
bpo-28523: IDLE: replace 'colour' with 'color' in configdialog.
|
| 769 |
+
|
| 770 |
+
bpo-30917: Add tests for idlelib.config.IdleConf.
|
| 771 |
+
Increase coverage from 46% to 96%.
|
| 772 |
+
Patch by Louie Lu.
|
| 773 |
+
|
| 774 |
+
bpo-30913: Document ConfigDialog tk Vars, methods, and widgets in docstrings
|
| 775 |
+
This will facilitate improving the dialog and splitting up the class.
|
| 776 |
+
Original patch by Cheryl Sabella.
|
| 777 |
+
|
| 778 |
+
bpo-30899: Add tests for ConfigParser subclasses in config.
|
| 779 |
+
Coverage is 100% for those classes and ConfigChanges.
|
| 780 |
+
Patch by Louie Lu.
|
| 781 |
+
|
| 782 |
+
bpo-30881: Add docstrings to browser.py.
|
| 783 |
+
Patch by Cheryl Sabella.
|
| 784 |
+
|
| 785 |
+
bpo-30851: Remove unused tk variables in configdialog.
|
| 786 |
+
One is a duplicate, one is set but cannot be altered by users.
|
| 787 |
+
Patch by Cheryl Sabella.
|
| 788 |
+
|
| 789 |
+
bpo-30870: Select font option with Up and Down keys, as well as with mouse.
|
| 790 |
+
Added test increases configdialog coverage to 60%
|
| 791 |
+
Patches mostly by Louie Lu.
|
| 792 |
+
|
| 793 |
+
bpo-8231: Call config.IdleConf.GetUserCfgDir only once per process.
|
| 794 |
+
|
| 795 |
+
bpo-30779: Factor ConfigChanges class from configdialog, put in config; test.
|
| 796 |
+
* In config, put dump test code in a function; run it and unittest in
|
| 797 |
+
'if __name__ == '__main__'.
|
| 798 |
+
* Add class config.ConfigChanges based on changes_class_v4.py on bpo issue.
|
| 799 |
+
* Add class test_config.ChangesTest, partly using configdialog_tests_v1.py.
|
| 800 |
+
* Revise configdialog to use ConfigChanges; see tracker msg297804.
|
| 801 |
+
* Revise test_configdialog to match configdialog changes.
|
| 802 |
+
* Remove configdialog functions unused or moved to ConfigChanges.
|
| 803 |
+
Cheryl Sabella contributed parts of the patch.
|
| 804 |
+
|
| 805 |
+
bpo-30777: Configdialog - add docstrings and improve comments.
|
| 806 |
+
Patch by Cheryl Sabella.
|
| 807 |
+
|
| 808 |
+
bpo-30495: Improve textview with docstrings, PEP8 names, and more tests.
|
| 809 |
+
Split TextViewer class into ViewWindow, ViewFrame, and TextFrame classes
|
| 810 |
+
so that instances of the latter two can be placed with other widgets
|
| 811 |
+
within a multiframe window.
|
| 812 |
+
Patches by Cheryl Sabella and Terry Jan Reedy.
|
| 813 |
+
|
| 814 |
+
bpo-30723: Make several improvements to parenmatch.
|
| 815 |
+
* Add 'parens' style to highlight both opener and closer.
|
| 816 |
+
* Make 'default' style, which is not default, a synonym for 'opener'.
|
| 817 |
+
* Make time-delay work the same with all styles.
|
| 818 |
+
* Add help for config dialog extensions tab, including parenmatch.
|
| 819 |
+
* Add new tests.
|
| 820 |
+
Original patch by Charles Wohlganger. Revisions by Terry Jan Reedy
|
| 821 |
+
|
| 822 |
+
bpo-30674: Grep -- Add docstrings. Patch by Cheryl Sabella.
|
| 823 |
+
|
| 824 |
+
bpo-21519: IDLE's basic custom key entry dialog now detects
|
| 825 |
+
duplicates properly. Original patch by Saimadhav Heblikar.
|
| 826 |
+
|
| 827 |
+
bpo-29910: IDLE no longer deletes a character after commenting out a
|
| 828 |
+
region by a key shortcut. Add "return 'break'" for this and other
|
| 829 |
+
potential conflicts between IDLE and default key bindings.
|
| 830 |
+
Patch by Serhiy Storchaka.
|
| 831 |
+
|
| 832 |
+
bpo-30728: Modernize idlelib.configdialog:
|
| 833 |
+
* replace import * with specific imports;
|
| 834 |
+
* lowercase method and attribute lines.
|
| 835 |
+
Patch by Cheryl Sabella.
|
| 836 |
+
|
| 837 |
+
bpo-6739: Verify user-entered key sequences by trying to bind them
|
| 838 |
+
with to a tk widget. Add tests for all 3 validation functions.
|
| 839 |
+
Original patch by G Polo. Tests added by Cheryl Sabella.
|
| 840 |
+
Code revised and more tests added by Terry Jan Reedy
|
| 841 |
+
|
| 842 |
+
bpo-24813: Add icon to help_about and make other changes.
|
| 843 |
+
|
| 844 |
+
bpo-15786: Fix several problems with IDLE's autocompletion box.
|
| 845 |
+
The following should now work: clicking on selection box items;
|
| 846 |
+
using the scrollbar; selecting an item by hitting Return.
|
| 847 |
+
Hangs on MacOSX should no longer happen. Patch by Louie Lu.
|
| 848 |
+
|
| 849 |
+
bpo-25514: Add doc subsubsection about IDLE failure to start.
|
| 850 |
+
Popup no-connection message directs users to this section.
|
| 851 |
+
|
| 852 |
+
bpo-30642: Fix reference leaks in IDLE tests.
|
| 853 |
+
Patches by Louie Lu and Terry Jan Reedy.
|
| 854 |
+
|
| 855 |
+
bpo-30495: Add docstrings for textview.py and use PEP8 names.
|
| 856 |
+
Patches by Cheryl Sabella and Terry Jan Reedy.
|
| 857 |
+
|
| 858 |
+
bpo-30290: Help-about: use pep8 names and add tests.
|
| 859 |
+
Increase coverage to 100%.
|
| 860 |
+
Patches by Louie Lu, Cheryl Sabella, and Terry Jan Reedy.
|
| 861 |
+
|
| 862 |
+
bpo-30303: Add _utest option to textview; add new tests.
|
| 863 |
+
Increase coverage to 100%.
|
| 864 |
+
Patches by Louie Lu and Terry Jan Reedy.
|
| 865 |
+
|
| 866 |
+
Issue #29071: IDLE colors f-string prefixes but not invalid ur prefixes.
|
| 867 |
+
|
| 868 |
+
Issue #28572: Add 10% to coverage of IDLE's test_configdialog.
|
| 869 |
+
Update and augment description of the configuration system.
|
| 870 |
+
|
| 871 |
+
|
| 872 |
+
What's New in IDLE 3.6.0 (since 3.5.0)
|
| 873 |
+
Released on 2016-12-23
|
| 874 |
+
======================================
|
| 875 |
+
|
| 876 |
+
- Issue #15308: Add 'interrupt execution' (^C) to Shell menu.
|
| 877 |
+
Patch by Roger Serwy, updated by Bayard Randel.
|
| 878 |
+
|
| 879 |
+
- Issue #27922: Stop IDLE tests from 'flashing' gui widgets on the screen.
|
| 880 |
+
|
| 881 |
+
- Issue #27891: Consistently group and sort imports within idlelib modules.
|
| 882 |
+
|
| 883 |
+
- Issue #17642: add larger font sizes for classroom projection.
|
| 884 |
+
|
| 885 |
+
- Add version to title of IDLE help window.
|
| 886 |
+
|
| 887 |
+
- Issue #25564: In section on IDLE -- console differences, mention that
|
| 888 |
+
using exec means that __builtins__ is defined for each statement.
|
| 889 |
+
|
| 890 |
+
- Issue #27821: Fix 3.6.0a3 regression that prevented custom key sets
|
| 891 |
+
from being selected when no custom theme was defined.
|
| 892 |
+
|
| 893 |
+
- Issue #27714: text_textview and test_autocomplete now pass when re-run
|
| 894 |
+
in the same process. This occurs when test_idle fails when run with the
|
| 895 |
+
-w option but without -jn. Fix warning from test_config.
|
| 896 |
+
|
| 897 |
+
- Issue #27621: Put query response validation error messages in the query
|
| 898 |
+
box itself instead of in a separate messagebox. Redo tests to match.
|
| 899 |
+
Add Mac OSX refinements. Original patch by Mark Roseman.
|
| 900 |
+
|
| 901 |
+
- Issue #27620: Escape key now closes Query box as cancelled.
|
| 902 |
+
|
| 903 |
+
- Issue #27609: IDLE: tab after initial whitespace should tab, not
|
| 904 |
+
autocomplete. This fixes problem with writing docstrings at least
|
| 905 |
+
twice indented.
|
| 906 |
+
|
| 907 |
+
- Issue #27609: Explicitly return None when there are also non-None
|
| 908 |
+
returns. In a few cases, reverse a condition and eliminate a return.
|
| 909 |
+
|
| 910 |
+
- Issue #25507: IDLE no longer runs buggy code because of its tkinter imports.
|
| 911 |
+
Users must include the same imports required to run directly in Python.
|
| 912 |
+
|
| 913 |
+
- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
|
| 914 |
+
Make the default key set depend on the platform.
|
| 915 |
+
Add tests for the changes to the config module.
|
| 916 |
+
|
| 917 |
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
|
| 918 |
+
|
| 919 |
+
- Issue #27477: IDLE search dialogs now use ttk widgets.
|
| 920 |
+
|
| 921 |
+
- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
|
| 922 |
+
Make the default key set depend on the platform.
|
| 923 |
+
Add tests for the changes to the config module.
|
| 924 |
+
|
| 925 |
+
- Issue #27452: make command line "idle-test> python test_help.py" work.
|
| 926 |
+
__file__ is relative when python is started in the file's directory.
|
| 927 |
+
|
| 928 |
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
|
| 929 |
+
|
| 930 |
+
- Issue #27380: IDLE: add query.py with base Query dialog and ttk widgets.
|
| 931 |
+
Module had subclasses SectionName, ModuleName, and HelpSource, which are
|
| 932 |
+
used to get information from users by configdialog and file =>Load Module.
|
| 933 |
+
Each subclass has itw own validity checks. Using ModuleName allows users
|
| 934 |
+
to edit bad module names instead of starting over.
|
| 935 |
+
Add tests and delete the two files combined into the new one.
|
| 936 |
+
|
| 937 |
+
- Issue #27372: Test_idle no longer changes the locale.
|
| 938 |
+
|
| 939 |
+
- Issue #27365: Allow non-ascii chars in IDLE NEWS.txt, for contributor names.
|
| 940 |
+
|
| 941 |
+
- Issue #27245: IDLE: Cleanly delete custom themes and key bindings.
|
| 942 |
+
Previously, when IDLE was started from a console or by import, a cascade
|
| 943 |
+
of warnings was emitted. Patch by Serhiy Storchaka.
|
| 944 |
+
|
| 945 |
+
- Issue #24137: Run IDLE, test_idle, and htest with tkinter default root disabled.
|
| 946 |
+
Fix code and tests that fail with this restriction.
|
| 947 |
+
Fix htests to not create a second and redundant root and mainloop.
|
| 948 |
+
|
| 949 |
+
- Issue #27310: Fix IDLE.app failure to launch on OS X due to vestigial import.
|
| 950 |
+
|
| 951 |
+
- Issue #5124: Paste with text selected now replaces the selection on X11.
|
| 952 |
+
This matches how paste works on Windows, Mac, most modern Linux apps,
|
| 953 |
+
and ttk widgets. Original patch by Serhiy Storchaka.
|
| 954 |
+
|
| 955 |
+
- Issue #24750: Switch all scrollbars in IDLE to ttk versions.
|
| 956 |
+
Where needed, minimal tests are added to cover changes.
|
| 957 |
+
|
| 958 |
+
- Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
|
| 959 |
+
Delete now unneeded tk version tests and code for older versions.
|
| 960 |
+
Add test for IDLE syntax colorizer.
|
| 961 |
+
|
| 962 |
+
- Issue #27239: idlelib.macosx.isXyzTk functions initialize as needed.
|
| 963 |
+
|
| 964 |
+
- Issue #27262: move Aqua unbinding code, which enable context menus, to macosx.
|
| 965 |
+
|
| 966 |
+
- Issue #24759: Make clear in idlelib.idle_test.__init__ that the directory
|
| 967 |
+
is a private implementation of test.test_idle and tool for maintainers.
|
| 968 |
+
|
| 969 |
+
- Issue #27196: Stop 'ThemeChanged' warnings when running IDLE tests.
|
| 970 |
+
These persisted after other warnings were suppressed in #20567.
|
| 971 |
+
Apply Serhiy Storchaka's update_idletasks solution to four test files.
|
| 972 |
+
Record this additional advice in idle_test/README.txt
|
| 973 |
+
|
| 974 |
+
- Issue #20567: Revise idle_test/README.txt with advice about avoiding
|
| 975 |
+
tk warning messages from tests. Apply advice to several IDLE tests.
|
| 976 |
+
|
| 977 |
+
- Issue # 24225: Update idlelib/README.txt with new file names
|
| 978 |
+
and event handlers.
|
| 979 |
+
|
| 980 |
+
- Issue #27156: Remove obsolete code not used by IDLE. Replacements:
|
| 981 |
+
1. help.txt, replaced by help.html, is out-of-date and should not be used.
|
| 982 |
+
Its dedicated viewer has be replaced by the html viewer in help.py.
|
| 983 |
+
2. 'import idlever; I = idlever.IDLE_VERSION' is the same as
|
| 984 |
+
'import sys; I = version[:version.index(' ')]'
|
| 985 |
+
3. After 'ob = stackviewer.VariablesTreeItem(*args)',
|
| 986 |
+
'ob.keys()' == 'list(ob.object.keys).
|
| 987 |
+
4. In macosc, runningAsOSXAPP == isAquaTk; idCarbonAquaTk == isCarbonTk
|
| 988 |
+
|
| 989 |
+
- Issue #27117: Make colorizer htest and turtledemo work with dark themes.
|
| 990 |
+
Move code for configuring text widget colors to a new function.
|
| 991 |
+
|
| 992 |
+
- Issue #24225: Rename many idlelib/*.py and idle_test/test_*.py files.
|
| 993 |
+
Edit files to replace old names with new names when the old name
|
| 994 |
+
referred to the module rather than the class it contained.
|
| 995 |
+
See the issue and IDLE section in What's New in 3.6 for more.
|
| 996 |
+
|
| 997 |
+
- Issue #26673: When tk reports font size as 0, change to size 10.
|
| 998 |
+
Such fonts on Linux prevented the configuration dialog from opening.
|
| 999 |
+
|
| 1000 |
+
- Issue #21939: Add test for IDLE's percolator.
|
| 1001 |
+
Original patch by Saimadhav Heblikar.
|
| 1002 |
+
|
| 1003 |
+
- Issue #21676: Add test for IDLE's replace dialog.
|
| 1004 |
+
Original patch by Saimadhav Heblikar.
|
| 1005 |
+
|
| 1006 |
+
- Issue #18410: Add test for IDLE's search dialog.
|
| 1007 |
+
Original patch by Westley Martínez.
|
| 1008 |
+
|
| 1009 |
+
- Issue #21703: Add test for undo delegator. Patch mostly by
|
| 1010 |
+
Saimadhav Heblikar .
|
| 1011 |
+
|
| 1012 |
+
- Issue #27044: Add ConfigDialog.remove_var_callbacks to stop memory leaks.
|
| 1013 |
+
|
| 1014 |
+
- Issue #23977: Add more asserts to test_delegator.
|
| 1015 |
+
|
| 1016 |
+
- Issue #20640: Add tests for idlelib.configHelpSourceEdit.
|
| 1017 |
+
Patch by Saimadhav Heblikar.
|
| 1018 |
+
|
| 1019 |
+
- In the 'IDLE-console differences' section of the IDLE doc, clarify
|
| 1020 |
+
how running with IDLE affects sys.modules and the standard streams.
|
| 1021 |
+
|
| 1022 |
+
- Issue #25507: fix incorrect change in IOBinding that prevented printing.
|
| 1023 |
+
Augment IOBinding htest to include all major IOBinding functions.
|
| 1024 |
+
|
| 1025 |
+
- Issue #25905: Revert unwanted conversion of ' to ’ RIGHT SINGLE QUOTATION
|
| 1026 |
+
MARK in README.txt and open this and NEWS.txt with 'ascii'.
|
| 1027 |
+
Re-encode CREDITS.txt to utf-8 and open it with 'utf-8'.
|
| 1028 |
+
|
| 1029 |
+
- Issue 15348: Stop the debugger engine (normally in a user process)
|
| 1030 |
+
before closing the debugger window (running in the IDLE process).
|
| 1031 |
+
This prevents the RuntimeErrors that were being caught and ignored.
|
| 1032 |
+
|
| 1033 |
+
- Issue #24455: Prevent IDLE from hanging when a) closing the shell while the
|
| 1034 |
+
debugger is active (15347); b) closing the debugger with the [X] button
|
| 1035 |
+
(15348); and c) activating the debugger when already active (24455).
|
| 1036 |
+
The patch by Mark Roseman does this by making two changes.
|
| 1037 |
+
1. Suspend and resume the gui.interaction method with the tcl vwait
|
| 1038 |
+
mechanism intended for this purpose (instead of root.mainloop & .quit).
|
| 1039 |
+
2. In gui.run, allow any existing interaction to terminate first.
|
| 1040 |
+
|
| 1041 |
+
- Change 'The program' to 'Your program' in an IDLE 'kill program?' message
|
| 1042 |
+
to make it clearer that the program referred to is the currently running
|
| 1043 |
+
user program, not IDLE itself.
|
| 1044 |
+
|
| 1045 |
+
- Issue #24750: Improve the appearance of the IDLE editor window status bar.
|
| 1046 |
+
Patch by Mark Roseman.
|
| 1047 |
+
|
| 1048 |
+
- Issue #25313: Change the handling of new built-in text color themes to better
|
| 1049 |
+
address the compatibility problem introduced by the addition of IDLE Dark.
|
| 1050 |
+
Consistently use the revised idleConf.CurrentTheme everywhere in idlelib.
|
| 1051 |
+
|
| 1052 |
+
- Issue #24782: Extension configuration is now a tab in the IDLE Preferences
|
| 1053 |
+
dialog rather than a separate dialog. The former tabs are now a sorted
|
| 1054 |
+
list. Patch by Mark Roseman.
|
| 1055 |
+
|
| 1056 |
+
- Issue #22726: Re-activate the config dialog help button with some content
|
| 1057 |
+
about the other buttons and the new IDLE Dark theme.
|
| 1058 |
+
|
| 1059 |
+
- Issue #24820: IDLE now has an 'IDLE Dark' built-in text color theme.
|
| 1060 |
+
It is more or less IDLE Classic inverted, with a cobalt blue background.
|
| 1061 |
+
Strings, comments, keywords, ... are still green, red, orange, ... .
|
| 1062 |
+
To use it with IDLEs released before November 2015, hit the
|
| 1063 |
+
'Save as New Custom Theme' button and enter a new name,
|
| 1064 |
+
such as 'Custom Dark'. The custom theme will work with any IDLE
|
| 1065 |
+
release, and can be modified.
|
| 1066 |
+
|
| 1067 |
+
- Issue #25224: README.txt is now an idlelib index for IDLE developers and
|
| 1068 |
+
curious users. The previous user content is now in the IDLE doc chapter.
|
| 1069 |
+
'IDLE' now means 'Integrated Development and Learning Environment'.
|
| 1070 |
+
|
| 1071 |
+
- Issue #24820: Users can now set breakpoint colors in
|
| 1072 |
+
Settings -> Custom Highlighting. Original patch by Mark Roseman.
|
| 1073 |
+
|
| 1074 |
+
- Issue #24972: Inactive selection background now matches active selection
|
| 1075 |
+
background, as configured by users, on all systems. Found items are now
|
| 1076 |
+
always highlighted on Windows. Initial patch by Mark Roseman.
|
| 1077 |
+
|
| 1078 |
+
- Issue #24570: Idle: make calltip and completion boxes appear on Macs
|
| 1079 |
+
affected by a tk regression. Initial patch by Mark Roseman.
|
| 1080 |
+
|
| 1081 |
+
- Issue #24988: Idle ScrolledList context menus (used in debugger)
|
| 1082 |
+
now work on Mac Aqua. Patch by Mark Roseman.
|
| 1083 |
+
|
| 1084 |
+
- Issue #24801: Make right-click for context menu work on Mac Aqua.
|
| 1085 |
+
Patch by Mark Roseman.
|
| 1086 |
+
|
| 1087 |
+
- Issue #25173: Associate tkinter messageboxes with a specific widget.
|
| 1088 |
+
For Mac OSX, make them a 'sheet'. Patch by Mark Roseman.
|
| 1089 |
+
|
| 1090 |
+
- Issue #25198: Enhance the initial html viewer now used for Idle Help.
|
| 1091 |
+
* Properly indent fixed-pitch text (patch by Mark Roseman).
|
| 1092 |
+
* Give code snippet a very Sphinx-like light blueish-gray background.
|
| 1093 |
+
* Re-use initial width and height set by users for shell and editor.
|
| 1094 |
+
* When the Table of Contents (TOC) menu is used, put the section header
|
| 1095 |
+
at the top of the screen.
|
| 1096 |
+
|
| 1097 |
+
- Issue #25225: Condense and rewrite Idle doc section on text colors.
|
| 1098 |
+
|
| 1099 |
+
- Issue #21995: Explain some differences between IDLE and console Python.
|
| 1100 |
+
|
| 1101 |
+
- Issue #22820: Explain need for *print* when running file from Idle editor.
|
| 1102 |
+
|
| 1103 |
+
- Issue #25224: Doc: augment Idle feature list and no-subprocess section.
|
| 1104 |
+
|
| 1105 |
+
- Issue #25219: Update doc for Idle command line options.
|
| 1106 |
+
Some were missing and notes were not correct.
|
| 1107 |
+
|
| 1108 |
+
- Issue #24861: Most of idlelib is private and subject to change.
|
| 1109 |
+
Use idleib.idle.* to start Idle. See idlelib.__init__.__doc__.
|
| 1110 |
+
|
| 1111 |
+
- Issue #25199: Idle: add synchronization comments for future maintainers.
|
| 1112 |
+
|
| 1113 |
+
- Issue #16893: Replace help.txt with help.html for Idle doc display.
|
| 1114 |
+
The new idlelib/help.html is rstripped Doc/build/html/library/idle.html.
|
| 1115 |
+
It looks better than help.txt and will better document Idle as released.
|
| 1116 |
+
The tkinter html viewer that works for this file was written by Mark Roseman.
|
| 1117 |
+
The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated.
|
| 1118 |
+
|
| 1119 |
+
- Issue #24199: Deprecate unused idlelib.idlever with possible removal in 3.6.
|
| 1120 |
+
|
| 1121 |
+
- Issue #24790: Remove extraneous code (which also create 2 & 3 conflicts).
|
| 1122 |
+
|
| 1123 |
+
|
| 1124 |
+
What's New in IDLE 3.5.0?
|
| 1125 |
+
=========================
|
| 1126 |
+
*Release date: 2015-09-13*
|
| 1127 |
+
|
| 1128 |
+
- Issue #23672: Allow Idle to edit and run files with astral chars in name.
|
| 1129 |
+
Patch by Mohd Sanad Zaki Rizvi.
|
| 1130 |
+
|
| 1131 |
+
- Issue 24745: Idle editor default font. Switch from Courier to
|
| 1132 |
+
platform-sensitive TkFixedFont. This should not affect current customized
|
| 1133 |
+
font selections. If there is a problem, edit $HOME/.idlerc/config-main.cfg
|
| 1134 |
+
and remove 'fontxxx' entries from [Editor Window]. Patch by Mark Roseman.
|
| 1135 |
+
|
| 1136 |
+
- Issue #21192: Idle editor. When a file is run, put its name in the restart bar.
|
| 1137 |
+
Do not print false prompts. Original patch by Adnan Umer.
|
| 1138 |
+
|
| 1139 |
+
- Issue #13884: Idle menus. Remove tearoff lines. Patch by Roger Serwy.
|
| 1140 |
+
|
| 1141 |
+
- Issue #23184: remove unused names and imports in idlelib.
|
| 1142 |
+
Initial patch by Al Sweigart.
|
| 1143 |
+
|
| 1144 |
+
- Issue #20577: Configuration of the max line length for the FormatParagraph
|
| 1145 |
+
extension has been moved from the General tab of the Idle preferences dialog
|
| 1146 |
+
to the FormatParagraph tab of the Config Extensions dialog.
|
| 1147 |
+
Patch by Tal Einat.
|
| 1148 |
+
|
| 1149 |
+
- Issue #16893: Update Idle doc chapter to match current Idle and add new
|
| 1150 |
+
information.
|
| 1151 |
+
|
| 1152 |
+
- Issue #3068: Add Idle extension configuration dialog to Options menu.
|
| 1153 |
+
Changes are written to HOME/.idlerc/config-extensions.cfg.
|
| 1154 |
+
Original patch by Tal Einat.
|
| 1155 |
+
|
| 1156 |
+
- Issue #16233: A module browser (File : Class Browser, Alt+C) requires an
|
| 1157 |
+
editor window with a filename. When Class Browser is requested otherwise,
|
| 1158 |
+
from a shell, output window, or 'Untitled' editor, Idle no longer displays
|
| 1159 |
+
an error box. It now pops up an Open Module box (Alt+M). If a valid name
|
| 1160 |
+
is entered and a module is opened, a corresponding browser is also opened.
|
| 1161 |
+
|
| 1162 |
+
- Issue #4832: Save As to type Python files automatically adds .py to the
|
| 1163 |
+
name you enter (even if your system does not display it). Some systems
|
| 1164 |
+
automatically add .txt when type is Text files.
|
| 1165 |
+
|
| 1166 |
+
- Issue #21986: Code objects are not normally pickled by the pickle module.
|
| 1167 |
+
To match this, they are no longer pickled when running under Idle.
|
| 1168 |
+
|
| 1169 |
+
- Issue #23180: Rename IDLE "Windows" menu item to "Window".
|
| 1170 |
+
Patch by Al Sweigart.
|
| 1171 |
+
|
| 1172 |
+
- Issue #17390: Adjust Editor window title; remove 'Python',
|
| 1173 |
+
move version to end.
|
| 1174 |
+
|
| 1175 |
+
- Issue #14105: Idle debugger breakpoints no longer disappear
|
| 1176 |
+
when inserting or deleting lines.
|
| 1177 |
+
|
| 1178 |
+
- Issue #17172: Turtledemo can now be run from Idle.
|
| 1179 |
+
Currently, the entry is on the Help menu, but it may move to Run.
|
| 1180 |
+
Patch by Ramchandra Apt and Lita Cho.
|
| 1181 |
+
|
| 1182 |
+
- Issue #21765: Add support for non-ascii identifiers to HyperParser.
|
| 1183 |
+
|
| 1184 |
+
- Issue #21940: Add unittest for WidgetRedirector. Initial patch by Saimadhav
|
| 1185 |
+
Heblikar.
|
| 1186 |
+
|
| 1187 |
+
- Issue #18592: Add unittest for SearchDialogBase. Patch by Phil Webster.
|
| 1188 |
+
|
| 1189 |
+
- Issue #21694: Add unittest for ParenMatch. Patch by Saimadhav Heblikar.
|
| 1190 |
+
|
| 1191 |
+
- Issue #21686: add unittest for HyperParser. Original patch by Saimadhav
|
| 1192 |
+
Heblikar.
|
| 1193 |
+
|
| 1194 |
+
- Issue #12387: Add missing upper(lower)case versions of default Windows key
|
| 1195 |
+
bindings for Idle so Caps Lock does not disable them. Patch by Roger Serwy.
|
| 1196 |
+
|
| 1197 |
+
- Issue #21695: Closing a Find-in-files output window while the search is
|
| 1198 |
+
still in progress no longer closes Idle.
|
| 1199 |
+
|
| 1200 |
+
- Issue #18910: Add unittest for textView. Patch by Phil Webster.
|
| 1201 |
+
|
| 1202 |
+
- Issue #18292: Add unittest for AutoExpand. Patch by Saihadhav Heblikar.
|
| 1203 |
+
|
| 1204 |
+
- Issue #18409: Add unittest for AutoComplete. Patch by Phil Webster.
|
| 1205 |
+
|
| 1206 |
+
- Issue #21477: htest.py - Improve framework, complete set of tests.
|
| 1207 |
+
Patches by Saimadhav Heblikar
|
| 1208 |
+
|
| 1209 |
+
- Issue #18104: Add idlelib/idle_test/htest.py with a few sample tests to begin
|
| 1210 |
+
consolidating and improving human-validated tests of Idle. Change other files
|
| 1211 |
+
as needed to work with htest. Running the module as __main__ runs all tests.
|
| 1212 |
+
|
| 1213 |
+
- Issue #21139: Change default paragraph width to 72, the PEP 8 recommendation.
|
| 1214 |
+
|
| 1215 |
+
- Issue #21284: Paragraph reformat test passes after user changes reformat width.
|
| 1216 |
+
|
| 1217 |
+
- Issue #17654: Ensure IDLE menus are customized properly on OS X for
|
| 1218 |
+
non-framework builds and for all variants of Tk.
|
| 1219 |
+
|
| 1220 |
+
|
| 1221 |
+
What's New in IDLE 3.4.0?
|
| 1222 |
+
=========================
|
| 1223 |
+
*Release date: 2014-03-16*
|
| 1224 |
+
|
| 1225 |
+
- Issue #17390: Display Python version on Idle title bar.
|
| 1226 |
+
Initial patch by Edmond Burnett.
|
| 1227 |
+
|
| 1228 |
+
- Issue #5066: Update IDLE docs. Patch by Todd Rovito.
|
| 1229 |
+
|
| 1230 |
+
- Issue #17625: Close the replace dialog after it is used.
|
| 1231 |
+
|
| 1232 |
+
- Issue #16226: Fix IDLE Path Browser crash.
|
| 1233 |
+
(Patch by Roger Serwy)
|
| 1234 |
+
|
| 1235 |
+
- Issue #15853: Prevent IDLE crash on OS X when opening Preferences menu
|
| 1236 |
+
with certain versions of Tk 8.5. Initial patch by Kevin Walzer.
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
+
What's New in IDLE 3.3.0?
|
| 1240 |
+
=========================
|
| 1241 |
+
*Release date: 2012-09-29*
|
| 1242 |
+
|
| 1243 |
+
- Issue #17625: Close the replace dialog after it is used.
|
| 1244 |
+
|
| 1245 |
+
- Issue #7163: Propagate return value of sys.stdout.write.
|
| 1246 |
+
|
| 1247 |
+
- Issue #15318: Prevent writing to sys.stdin.
|
| 1248 |
+
|
| 1249 |
+
- Issue #4832: Modify IDLE to save files with .py extension by
|
| 1250 |
+
default on Windows and OS X (Tk 8.5) as it already does with X11 Tk.
|
| 1251 |
+
|
| 1252 |
+
- Issue #13532, #15319: Check that arguments to sys.stdout.write are strings.
|
| 1253 |
+
|
| 1254 |
+
- Issue # 12510: Attempt to get certain tool tips no longer crashes IDLE.
|
| 1255 |
+
Erroneous tool tips have been corrected. Default added for callables.
|
| 1256 |
+
|
| 1257 |
+
- Issue #10365: File open dialog now works instead of crashing even when
|
| 1258 |
+
parent window is closed while dialog is open.
|
| 1259 |
+
|
| 1260 |
+
- Issue 14876: use user-selected font for highlight configuration.
|
| 1261 |
+
|
| 1262 |
+
- Issue #14937: Perform auto-completion of filenames in strings even for
|
| 1263 |
+
non-ASCII filenames. Likewise for identifiers.
|
| 1264 |
+
|
| 1265 |
+
- Issue #8515: Set __file__ when run file in IDLE.
|
| 1266 |
+
Initial patch by Bruce Frederiksen.
|
| 1267 |
+
|
| 1268 |
+
- IDLE can be launched as `python -m idlelib`
|
| 1269 |
+
|
| 1270 |
+
- Issue #14409: IDLE now properly executes commands in the Shell window
|
| 1271 |
+
when it cannot read the normal config files on startup and
|
| 1272 |
+
has to use the built-in default key bindings.
|
| 1273 |
+
There was previously a bug in one of the defaults.
|
| 1274 |
+
|
| 1275 |
+
- Issue #3573: IDLE hangs when passing invalid command line args
|
| 1276 |
+
(directory(ies) instead of file(s)).
|
| 1277 |
+
|
| 1278 |
+
- Issue #14018: Update checks for unstable system Tcl/Tk versions on OS X
|
| 1279 |
+
to include versions shipped with OS X 10.7 and 10.8 in addition to 10.6.
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
+
What's New in IDLE 3.2.1?
|
| 1283 |
+
=========================
|
| 1284 |
+
*Release date: 15-May-11*
|
| 1285 |
+
|
| 1286 |
+
- Issue #6378: Further adjust idle.bat to start associated Python
|
| 1287 |
+
|
| 1288 |
+
- Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
|
| 1289 |
+
|
| 1290 |
+
- Issue #1028: Ctrl-space binding to show completions was causing IDLE to exit.
|
| 1291 |
+
Tk < 8.5 was sending invalid Unicode null; replaced with valid null.
|
| 1292 |
+
|
| 1293 |
+
- Issue #4676: <Home> toggle failing on Tk 8.5, causing IDLE exits and strange selection
|
| 1294 |
+
behavior. Improve selection extension behaviour.
|
| 1295 |
+
|
| 1296 |
+
- Issue #3851: <Home> toggle non-functional when NumLock set on Windows.
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
What's New in IDLE 3.1b1?
|
| 1300 |
+
=========================
|
| 1301 |
+
*Release date: 06-May-09*
|
| 1302 |
+
|
| 1303 |
+
- Issue #5707: Use of 'filter' in keybindingDialog.py was causing custom key assignment to
|
| 1304 |
+
fail. Patch by Amaury Forgeot d'Arc.
|
| 1305 |
+
|
| 1306 |
+
- Issue #4815: Offer conversion to UTF-8 if source files have
|
| 1307 |
+
no encoding declaration and are not encoded in UTF-8.
|
| 1308 |
+
|
| 1309 |
+
- Issue #4008: Fix problems with non-ASCII source files.
|
| 1310 |
+
|
| 1311 |
+
- Issue #4323: Always encode source as UTF-8 without asking
|
| 1312 |
+
the user (unless a different encoding is declared); remove
|
| 1313 |
+
user configuration of source encoding; all according to
|
| 1314 |
+
PEP 3120.
|
| 1315 |
+
|
| 1316 |
+
- Issue #2665: On Windows, an IDLE installation upgraded from an old version
|
| 1317 |
+
would not start if a custom theme was defined.
|
| 1318 |
+
|
| 1319 |
+
------------------------------------------------------------------------
|
| 1320 |
+
Refer to NEWS2x.txt and HISTORY.txt for information on earlier releases.
|
| 1321 |
+
------------------------------------------------------------------------
|
llava/lib/python3.10/idlelib/TODO.txt
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Original IDLE todo, much of it now outdated:
|
| 2 |
+
============================================
|
| 3 |
+
TO DO:
|
| 4 |
+
|
| 5 |
+
- improve debugger:
|
| 6 |
+
- manage breakpoints globally, allow bp deletion, tbreak, cbreak etc.
|
| 7 |
+
- real object browser
|
| 8 |
+
- help on how to use it (a simple help button will do wonders)
|
| 9 |
+
- performance? (updates of large sets of locals are slow)
|
| 10 |
+
- better integration of "debug module"
|
| 11 |
+
- debugger should be global resource (attached to flist, not to shell)
|
| 12 |
+
- fix the stupid bug where you need to step twice
|
| 13 |
+
- display class name in stack viewer entries for methods
|
| 14 |
+
- suppress tracing through IDLE internals (e.g. print) DONE
|
| 15 |
+
- add a button to suppress through a specific module or class or method
|
| 16 |
+
- more object inspection to stack viewer, e.g. to view all array items
|
| 17 |
+
- insert the initial current directory into sys.path DONE
|
| 18 |
+
- default directory attribute for each window instead of only for windows
|
| 19 |
+
that have an associated filename
|
| 20 |
+
- command expansion from keywords, module contents, other buffers, etc.
|
| 21 |
+
- "Recent documents" menu item DONE
|
| 22 |
+
- Filter region command
|
| 23 |
+
- Optional horizontal scroll bar
|
| 24 |
+
- more Emacsisms:
|
| 25 |
+
- ^K should cut to buffer
|
| 26 |
+
- M-[, M-] to move by paragraphs
|
| 27 |
+
- incremental search?
|
| 28 |
+
- search should indicate wrap-around in some way
|
| 29 |
+
- restructure state sensitive code to avoid testing flags all the time
|
| 30 |
+
- persistent user state (e.g. window and cursor positions, bindings)
|
| 31 |
+
- make backups when saving
|
| 32 |
+
- check file mtimes at various points
|
| 33 |
+
- Pluggable interface with RCS/CVS/Perforce/Clearcase
|
| 34 |
+
- better help?
|
| 35 |
+
- don't open second class browser on same module (nor second path browser)
|
| 36 |
+
- unify class and path browsers
|
| 37 |
+
- Need to define a standard way whereby one can determine one is running
|
| 38 |
+
inside IDLE (needed for Tk mainloop, also handy for $PYTHONSTARTUP)
|
| 39 |
+
- Add more utility methods for use by extensions (a la get_selection)
|
| 40 |
+
- Way to run command in totally separate interpreter (fork+os.system?) DONE
|
| 41 |
+
- Way to find definition of fully-qualified name:
|
| 42 |
+
In other words, select "UserDict.UserDict", hit some magic key and
|
| 43 |
+
it loads up UserDict.py and finds the first def or class for UserDict.
|
| 44 |
+
- need a way to force colorization on/off
|
| 45 |
+
- need a way to force auto-indent on/off
|
| 46 |
+
|
| 47 |
+
Details:
|
| 48 |
+
|
| 49 |
+
- ^O (on Unix -- open-line) should honor autoindent
|
| 50 |
+
- after paste, show end of pasted text
|
| 51 |
+
- on Windows, should turn short filename to long filename (not only in argv!)
|
| 52 |
+
(shouldn't this be done -- or undone -- by ntpath.normpath?)
|
| 53 |
+
- new autoindent after colon even indents when the colon is in a comment!
|
| 54 |
+
- sometimes forward slashes in pathname remain
|
| 55 |
+
- sometimes star in window name remains in Windows menu
|
| 56 |
+
- With unix bindings, ESC by itself is ignored
|
| 57 |
+
- Sometimes for no apparent reason a selection from the cursor to the
|
| 58 |
+
end of the command buffer appears, which is hard to get rid of
|
| 59 |
+
because it stays when you are typing!
|
| 60 |
+
- The Line/Col in the status bar can be wrong initially in PyShell DONE
|
| 61 |
+
|
| 62 |
+
Structural problems:
|
| 63 |
+
|
| 64 |
+
- too much knowledge in FileList about EditorWindow (for example)
|
| 65 |
+
- should add some primitives for accessing the selection etc.
|
| 66 |
+
to repeat cumbersome code over and over
|
| 67 |
+
|
| 68 |
+
======================================================================
|
| 69 |
+
|
| 70 |
+
Jeff Bauer suggests:
|
| 71 |
+
|
| 72 |
+
- Open Module doesn't appear to handle hierarchical packages.
|
| 73 |
+
- Class browser should also allow hierarchical packages.
|
| 74 |
+
- Open and Open Module could benefit from a history, DONE
|
| 75 |
+
either command line style, or Microsoft recent-file
|
| 76 |
+
style.
|
| 77 |
+
- Add a Smalltalk-style inspector (i.e. Tkinspect)
|
| 78 |
+
|
| 79 |
+
The last suggestion is already a reality, but not yet
|
| 80 |
+
integrated into IDLE. I use a module called inspector.py,
|
| 81 |
+
that used to be available from python.org(?) It no longer
|
| 82 |
+
appears to be in the contributed section, and the source
|
| 83 |
+
has no author attribution.
|
| 84 |
+
|
| 85 |
+
In any case, the code is useful for visually navigating
|
| 86 |
+
an object's attributes, including its container hierarchy.
|
| 87 |
+
|
| 88 |
+
>>> from inspector import Tkinspect
|
| 89 |
+
>>> Tkinspect(None, myObject)
|
| 90 |
+
|
| 91 |
+
Tkinspect could probably be extended and refined to
|
| 92 |
+
integrate better into IDLE.
|
| 93 |
+
|
| 94 |
+
======================================================================
|
| 95 |
+
|
| 96 |
+
Comparison to PTUI
|
| 97 |
+
------------------
|
| 98 |
+
|
| 99 |
+
+ PTUI's help is better (HTML!)
|
| 100 |
+
|
| 101 |
+
+ PTUI can attach a shell to any module
|
| 102 |
+
|
| 103 |
+
+ PTUI has some more I/O commands:
|
| 104 |
+
open multiple
|
| 105 |
+
append
|
| 106 |
+
examine (what's that?)
|
| 107 |
+
|
| 108 |
+
======================================================================
|
| 109 |
+
|
| 110 |
+
Notes after trying to run Grail
|
| 111 |
+
-------------------------------
|
| 112 |
+
|
| 113 |
+
- Grail does stuff to sys.path based on sys.argv[0]; you must set
|
| 114 |
+
sys.argv[0] to something decent first (it is normally set to the path of
|
| 115 |
+
the idle script).
|
| 116 |
+
|
| 117 |
+
- Grail must be exec'ed in __main__ because that's imported by some
|
| 118 |
+
other parts of Grail.
|
| 119 |
+
|
| 120 |
+
- Grail uses a module called History and so does idle :-(
|
| 121 |
+
|
| 122 |
+
======================================================================
|
| 123 |
+
|
| 124 |
+
Robin Friedrich's items:
|
| 125 |
+
|
| 126 |
+
Things I'd like to see:
|
| 127 |
+
- I'd like support for shift-click extending the selection. There's a
|
| 128 |
+
bug now that it doesn't work the first time you try it.
|
| 129 |
+
- Printing is needed. How hard can that be on Windows? FIRST CUT DONE
|
| 130 |
+
- The python-mode trick of autoindenting a line with <tab> is neat and
|
| 131 |
+
very handy.
|
| 132 |
+
- (someday) a spellchecker for docstrings and comments.
|
| 133 |
+
- a pagedown/up command key which moves to next class/def statement (top
|
| 134 |
+
level)
|
| 135 |
+
- split window capability
|
| 136 |
+
- DnD text relocation/copying
|
| 137 |
+
|
| 138 |
+
Things I don't want to see.
|
| 139 |
+
- line numbers... will probably slow things down way too much.
|
| 140 |
+
- Please use another icon for the tree browser leaf. The small snake
|
| 141 |
+
isn't cutting it.
|
| 142 |
+
|
| 143 |
+
----------------------------------------------------------------------
|
| 144 |
+
|
| 145 |
+
- Customizable views (multi-window or multi-pane). (Markus Gritsch)
|
| 146 |
+
|
| 147 |
+
- Being able to double click (maybe double right click) on a callable
|
| 148 |
+
object in the editor which shows the source of the object, if
|
| 149 |
+
possible. (Gerrit Holl)
|
| 150 |
+
|
| 151 |
+
- Hooks into the guts, like in Emacs. (Mike Romberg)
|
| 152 |
+
|
| 153 |
+
- Sharing the editor with a remote tutor. (Martijn Faassen)
|
| 154 |
+
|
| 155 |
+
- Multiple views on the same file. (Tony J Ibbs)
|
| 156 |
+
|
| 157 |
+
- Store breakpoints in a global (per-project) database (GvR); Dirk
|
| 158 |
+
Heise adds: save some space-trimmed context and search around when
|
| 159 |
+
reopening a file that might have been edited by someone else.
|
| 160 |
+
|
| 161 |
+
- Capture menu events in extensions without changing the IDLE source.
|
| 162 |
+
(Matthias Barmeier)
|
| 163 |
+
|
| 164 |
+
- Use overlapping panels (a "notebook" in MFC terms I think) for info
|
| 165 |
+
that doesn't need to be accessible simultaneously (e.g. HTML source
|
| 166 |
+
and output). Use multi-pane windows for info that does need to be
|
| 167 |
+
shown together (e.g. class browser and source). (Albert Brandl)
|
| 168 |
+
|
| 169 |
+
- A project should invisibly track all symbols, for instant search,
|
| 170 |
+
replace and cross-ref. Projects should be allowed to span multiple
|
| 171 |
+
directories, hosts, etc. Project management files are placed in a
|
| 172 |
+
directory you specify. A global mapping between project names and
|
| 173 |
+
project directories should exist [not so sure --GvR]. (Tim Peters)
|
| 174 |
+
|
| 175 |
+
- Merge attr-tips and auto-expand. (Mark Hammond, Tim Peters)
|
| 176 |
+
|
| 177 |
+
- Python Shell should behave more like a "shell window" as users know
|
| 178 |
+
it -- i.e. you can only edit the current command, and the cursor can't
|
| 179 |
+
escape from the command area. (Albert Brandl)
|
| 180 |
+
|
| 181 |
+
- Set X11 class to "idle/Idle", set icon and title to something
|
| 182 |
+
beginning with "idle" -- for window manangers. (Randall Hopper)
|
| 183 |
+
|
| 184 |
+
- Config files editable through a preferences dialog. (me) DONE
|
| 185 |
+
|
| 186 |
+
- Config files still editable outside the preferences dialog.
|
| 187 |
+
(Randall Hopper) DONE
|
| 188 |
+
|
| 189 |
+
- When you're editing a command in PyShell, and there are only blank
|
| 190 |
+
lines below the cursor, hitting Return should ignore or delete those
|
| 191 |
+
blank lines rather than deciding you're not on the last line. (me)
|
| 192 |
+
|
| 193 |
+
- Run command (F5 c.s.) should be more like Pythonwin's Run -- a
|
| 194 |
+
dialog with options to give command line arguments, run the debugger,
|
| 195 |
+
etc. (me)
|
| 196 |
+
|
| 197 |
+
- Shouldn't be able to delete part of the prompt (or any text before
|
| 198 |
+
it) in the PyShell. (Martijn Faassen) DONE
|
| 199 |
+
|
| 200 |
+
- Emacs style auto-fill (also smart about comments and strings).
|
| 201 |
+
(Jeremy Hylton)
|
| 202 |
+
|
| 203 |
+
- Output of Run Script should go to a separate output window, not to
|
| 204 |
+
the shell window. Output of separate runs should all go to the same
|
| 205 |
+
window but clearly delimited. (David Scherer) REJECT FIRST, LATTER DONE
|
| 206 |
+
|
| 207 |
+
- GUI form designer to kick VB's butt. (Robert Geiger) THAT'S NOT IDLE
|
| 208 |
+
|
| 209 |
+
- Printing! Possibly via generation of PDF files which the user must
|
| 210 |
+
then send to the printer separately. (Dinu Gherman) FIRST CUT
|
llava/lib/python3.10/idlelib/__main__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IDLE main entry point
|
| 3 |
+
|
| 4 |
+
Run IDLE as python -m idlelib
|
| 5 |
+
"""
|
| 6 |
+
import idlelib.pyshell
|
| 7 |
+
idlelib.pyshell.main()
|
| 8 |
+
# This file does not work for 2.7; See issue 24212.
|
llava/lib/python3.10/idlelib/autocomplete_w.py
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
An auto-completion window for IDLE, used by the autocomplete extension
|
| 3 |
+
"""
|
| 4 |
+
import platform
|
| 5 |
+
|
| 6 |
+
from tkinter import *
|
| 7 |
+
from tkinter.ttk import Scrollbar
|
| 8 |
+
|
| 9 |
+
from idlelib.autocomplete import FILES, ATTRS
|
| 10 |
+
from idlelib.multicall import MC_SHIFT
|
| 11 |
+
|
| 12 |
+
HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
|
| 13 |
+
HIDE_FOCUS_OUT_SEQUENCE = "<FocusOut>"
|
| 14 |
+
HIDE_SEQUENCES = (HIDE_FOCUS_OUT_SEQUENCE, "<ButtonPress>")
|
| 15 |
+
KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
|
| 16 |
+
# We need to bind event beyond <Key> so that the function will be called
|
| 17 |
+
# before the default specific IDLE function
|
| 18 |
+
KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>", "<Key-Tab>",
|
| 19 |
+
"<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>",
|
| 20 |
+
"<Key-Prior>", "<Key-Next>", "<Key-Escape>")
|
| 21 |
+
KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
|
| 22 |
+
KEYRELEASE_SEQUENCE = "<KeyRelease>"
|
| 23 |
+
LISTUPDATE_SEQUENCE = "<B1-ButtonRelease>"
|
| 24 |
+
WINCONFIG_SEQUENCE = "<Configure>"
|
| 25 |
+
DOUBLECLICK_SEQUENCE = "<B1-Double-ButtonRelease>"
|
| 26 |
+
|
| 27 |
+
class AutoCompleteWindow:
|
| 28 |
+
|
| 29 |
+
def __init__(self, widget, tags):
|
| 30 |
+
# The widget (Text) on which we place the AutoCompleteWindow
|
| 31 |
+
self.widget = widget
|
| 32 |
+
# Tags to mark inserted text with
|
| 33 |
+
self.tags = tags
|
| 34 |
+
# The widgets we create
|
| 35 |
+
self.autocompletewindow = self.listbox = self.scrollbar = None
|
| 36 |
+
# The default foreground and background of a selection. Saved because
|
| 37 |
+
# they are changed to the regular colors of list items when the
|
| 38 |
+
# completion start is not a prefix of the selected completion
|
| 39 |
+
self.origselforeground = self.origselbackground = None
|
| 40 |
+
# The list of completions
|
| 41 |
+
self.completions = None
|
| 42 |
+
# A list with more completions, or None
|
| 43 |
+
self.morecompletions = None
|
| 44 |
+
# The completion mode, either autocomplete.ATTRS or .FILES.
|
| 45 |
+
self.mode = None
|
| 46 |
+
# The current completion start, on the text box (a string)
|
| 47 |
+
self.start = None
|
| 48 |
+
# The index of the start of the completion
|
| 49 |
+
self.startindex = None
|
| 50 |
+
# The last typed start, used so that when the selection changes,
|
| 51 |
+
# the new start will be as close as possible to the last typed one.
|
| 52 |
+
self.lasttypedstart = None
|
| 53 |
+
# Do we have an indication that the user wants the completion window
|
| 54 |
+
# (for example, he clicked the list)
|
| 55 |
+
self.userwantswindow = None
|
| 56 |
+
# event ids
|
| 57 |
+
self.hideid = self.keypressid = self.listupdateid = \
|
| 58 |
+
self.winconfigid = self.keyreleaseid = self.doubleclickid = None
|
| 59 |
+
# Flag set if last keypress was a tab
|
| 60 |
+
self.lastkey_was_tab = False
|
| 61 |
+
# Flag set to avoid recursive <Configure> callback invocations.
|
| 62 |
+
self.is_configuring = False
|
| 63 |
+
|
| 64 |
+
def _change_start(self, newstart):
|
| 65 |
+
min_len = min(len(self.start), len(newstart))
|
| 66 |
+
i = 0
|
| 67 |
+
while i < min_len and self.start[i] == newstart[i]:
|
| 68 |
+
i += 1
|
| 69 |
+
if i < len(self.start):
|
| 70 |
+
self.widget.delete("%s+%dc" % (self.startindex, i),
|
| 71 |
+
"%s+%dc" % (self.startindex, len(self.start)))
|
| 72 |
+
if i < len(newstart):
|
| 73 |
+
self.widget.insert("%s+%dc" % (self.startindex, i),
|
| 74 |
+
newstart[i:],
|
| 75 |
+
self.tags)
|
| 76 |
+
self.start = newstart
|
| 77 |
+
|
| 78 |
+
def _binary_search(self, s):
|
| 79 |
+
"""Find the first index in self.completions where completions[i] is
|
| 80 |
+
greater or equal to s, or the last index if there is no such.
|
| 81 |
+
"""
|
| 82 |
+
i = 0; j = len(self.completions)
|
| 83 |
+
while j > i:
|
| 84 |
+
m = (i + j) // 2
|
| 85 |
+
if self.completions[m] >= s:
|
| 86 |
+
j = m
|
| 87 |
+
else:
|
| 88 |
+
i = m + 1
|
| 89 |
+
return min(i, len(self.completions)-1)
|
| 90 |
+
|
| 91 |
+
def _complete_string(self, s):
|
| 92 |
+
"""Assuming that s is the prefix of a string in self.completions,
|
| 93 |
+
return the longest string which is a prefix of all the strings which
|
| 94 |
+
s is a prefix of them. If s is not a prefix of a string, return s.
|
| 95 |
+
"""
|
| 96 |
+
first = self._binary_search(s)
|
| 97 |
+
if self.completions[first][:len(s)] != s:
|
| 98 |
+
# There is not even one completion which s is a prefix of.
|
| 99 |
+
return s
|
| 100 |
+
# Find the end of the range of completions where s is a prefix of.
|
| 101 |
+
i = first + 1
|
| 102 |
+
j = len(self.completions)
|
| 103 |
+
while j > i:
|
| 104 |
+
m = (i + j) // 2
|
| 105 |
+
if self.completions[m][:len(s)] != s:
|
| 106 |
+
j = m
|
| 107 |
+
else:
|
| 108 |
+
i = m + 1
|
| 109 |
+
last = i-1
|
| 110 |
+
|
| 111 |
+
if first == last: # only one possible completion
|
| 112 |
+
return self.completions[first]
|
| 113 |
+
|
| 114 |
+
# We should return the maximum prefix of first and last
|
| 115 |
+
first_comp = self.completions[first]
|
| 116 |
+
last_comp = self.completions[last]
|
| 117 |
+
min_len = min(len(first_comp), len(last_comp))
|
| 118 |
+
i = len(s)
|
| 119 |
+
while i < min_len and first_comp[i] == last_comp[i]:
|
| 120 |
+
i += 1
|
| 121 |
+
return first_comp[:i]
|
| 122 |
+
|
| 123 |
+
def _selection_changed(self):
|
| 124 |
+
"""Call when the selection of the Listbox has changed.
|
| 125 |
+
|
| 126 |
+
Updates the Listbox display and calls _change_start.
|
| 127 |
+
"""
|
| 128 |
+
cursel = int(self.listbox.curselection()[0])
|
| 129 |
+
|
| 130 |
+
self.listbox.see(cursel)
|
| 131 |
+
|
| 132 |
+
lts = self.lasttypedstart
|
| 133 |
+
selstart = self.completions[cursel]
|
| 134 |
+
if self._binary_search(lts) == cursel:
|
| 135 |
+
newstart = lts
|
| 136 |
+
else:
|
| 137 |
+
min_len = min(len(lts), len(selstart))
|
| 138 |
+
i = 0
|
| 139 |
+
while i < min_len and lts[i] == selstart[i]:
|
| 140 |
+
i += 1
|
| 141 |
+
newstart = selstart[:i]
|
| 142 |
+
self._change_start(newstart)
|
| 143 |
+
|
| 144 |
+
if self.completions[cursel][:len(self.start)] == self.start:
|
| 145 |
+
# start is a prefix of the selected completion
|
| 146 |
+
self.listbox.configure(selectbackground=self.origselbackground,
|
| 147 |
+
selectforeground=self.origselforeground)
|
| 148 |
+
else:
|
| 149 |
+
self.listbox.configure(selectbackground=self.listbox.cget("bg"),
|
| 150 |
+
selectforeground=self.listbox.cget("fg"))
|
| 151 |
+
# If there are more completions, show them, and call me again.
|
| 152 |
+
if self.morecompletions:
|
| 153 |
+
self.completions = self.morecompletions
|
| 154 |
+
self.morecompletions = None
|
| 155 |
+
self.listbox.delete(0, END)
|
| 156 |
+
for item in self.completions:
|
| 157 |
+
self.listbox.insert(END, item)
|
| 158 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 159 |
+
self._selection_changed()
|
| 160 |
+
|
| 161 |
+
def show_window(self, comp_lists, index, complete, mode, userWantsWin):
|
| 162 |
+
"""Show the autocomplete list, bind events.
|
| 163 |
+
|
| 164 |
+
If complete is True, complete the text, and if there is exactly
|
| 165 |
+
one matching completion, don't open a list.
|
| 166 |
+
"""
|
| 167 |
+
# Handle the start we already have
|
| 168 |
+
self.completions, self.morecompletions = comp_lists
|
| 169 |
+
self.mode = mode
|
| 170 |
+
self.startindex = self.widget.index(index)
|
| 171 |
+
self.start = self.widget.get(self.startindex, "insert")
|
| 172 |
+
if complete:
|
| 173 |
+
completed = self._complete_string(self.start)
|
| 174 |
+
start = self.start
|
| 175 |
+
self._change_start(completed)
|
| 176 |
+
i = self._binary_search(completed)
|
| 177 |
+
if self.completions[i] == completed and \
|
| 178 |
+
(i == len(self.completions)-1 or
|
| 179 |
+
self.completions[i+1][:len(completed)] != completed):
|
| 180 |
+
# There is exactly one matching completion
|
| 181 |
+
return completed == start
|
| 182 |
+
self.userwantswindow = userWantsWin
|
| 183 |
+
self.lasttypedstart = self.start
|
| 184 |
+
|
| 185 |
+
# Put widgets in place
|
| 186 |
+
self.autocompletewindow = acw = Toplevel(self.widget)
|
| 187 |
+
# Put it in a position so that it is not seen.
|
| 188 |
+
acw.wm_geometry("+10000+10000")
|
| 189 |
+
# Make it float
|
| 190 |
+
acw.wm_overrideredirect(1)
|
| 191 |
+
try:
|
| 192 |
+
# This command is only needed and available on Tk >= 8.4.0 for OSX
|
| 193 |
+
# Without it, call tips intrude on the typing process by grabbing
|
| 194 |
+
# the focus.
|
| 195 |
+
acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
|
| 196 |
+
"help", "noActivates")
|
| 197 |
+
except TclError:
|
| 198 |
+
pass
|
| 199 |
+
self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
|
| 200 |
+
self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
|
| 201 |
+
exportselection=False)
|
| 202 |
+
for item in self.completions:
|
| 203 |
+
listbox.insert(END, item)
|
| 204 |
+
self.origselforeground = listbox.cget("selectforeground")
|
| 205 |
+
self.origselbackground = listbox.cget("selectbackground")
|
| 206 |
+
scrollbar.config(command=listbox.yview)
|
| 207 |
+
scrollbar.pack(side=RIGHT, fill=Y)
|
| 208 |
+
listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
| 209 |
+
#acw.update_idletasks() # Need for tk8.6.8 on macOS: #40128.
|
| 210 |
+
acw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
|
| 211 |
+
|
| 212 |
+
# Initialize the listbox selection
|
| 213 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 214 |
+
self._selection_changed()
|
| 215 |
+
|
| 216 |
+
# bind events
|
| 217 |
+
self.hideaid = acw.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 218 |
+
self.hidewid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 219 |
+
acw.event_add(HIDE_VIRTUAL_EVENT_NAME, HIDE_FOCUS_OUT_SEQUENCE)
|
| 220 |
+
for seq in HIDE_SEQUENCES:
|
| 221 |
+
self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 222 |
+
|
| 223 |
+
self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,
|
| 224 |
+
self.keypress_event)
|
| 225 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 226 |
+
self.widget.event_add(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 227 |
+
self.keyreleaseid = self.widget.bind(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 228 |
+
self.keyrelease_event)
|
| 229 |
+
self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
|
| 230 |
+
self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
|
| 231 |
+
self.listselect_event)
|
| 232 |
+
self.is_configuring = False
|
| 233 |
+
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
|
| 234 |
+
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
|
| 235 |
+
self.doubleclick_event)
|
| 236 |
+
return None
|
| 237 |
+
|
| 238 |
+
def winconfig_event(self, event):
|
| 239 |
+
if self.is_configuring:
|
| 240 |
+
# Avoid running on recursive <Configure> callback invocations.
|
| 241 |
+
return
|
| 242 |
+
|
| 243 |
+
self.is_configuring = True
|
| 244 |
+
if not self.is_active():
|
| 245 |
+
return
|
| 246 |
+
|
| 247 |
+
# Since the <Configure> event may occur after the completion window is gone,
|
| 248 |
+
# catch potential TclError exceptions when accessing acw. See: bpo-41611.
|
| 249 |
+
try:
|
| 250 |
+
# Position the completion list window
|
| 251 |
+
text = self.widget
|
| 252 |
+
text.see(self.startindex)
|
| 253 |
+
x, y, cx, cy = text.bbox(self.startindex)
|
| 254 |
+
acw = self.autocompletewindow
|
| 255 |
+
if platform.system().startswith('Windows'):
|
| 256 |
+
# On Windows an update() call is needed for the completion
|
| 257 |
+
# list window to be created, so that we can fetch its width
|
| 258 |
+
# and height. However, this is not needed on other platforms
|
| 259 |
+
# (tested on Ubuntu and macOS) but at one point began
|
| 260 |
+
# causing freezes on macOS. See issues 37849 and 41611.
|
| 261 |
+
acw.update()
|
| 262 |
+
acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
|
| 263 |
+
text_width, text_height = text.winfo_width(), text.winfo_height()
|
| 264 |
+
new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
|
| 265 |
+
new_y = text.winfo_rooty() + y
|
| 266 |
+
if (text_height - (y + cy) >= acw_height # enough height below
|
| 267 |
+
or y < acw_height): # not enough height above
|
| 268 |
+
# place acw below current line
|
| 269 |
+
new_y += cy
|
| 270 |
+
else:
|
| 271 |
+
# place acw above current line
|
| 272 |
+
new_y -= acw_height
|
| 273 |
+
acw.wm_geometry("+%d+%d" % (new_x, new_y))
|
| 274 |
+
acw.update_idletasks()
|
| 275 |
+
except TclError:
|
| 276 |
+
pass
|
| 277 |
+
|
| 278 |
+
if platform.system().startswith('Windows'):
|
| 279 |
+
# See issue 15786. When on Windows platform, Tk will misbehave
|
| 280 |
+
# to call winconfig_event multiple times, we need to prevent this,
|
| 281 |
+
# otherwise mouse button double click will not be able to used.
|
| 282 |
+
try:
|
| 283 |
+
acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 284 |
+
except TclError:
|
| 285 |
+
pass
|
| 286 |
+
self.winconfigid = None
|
| 287 |
+
|
| 288 |
+
self.is_configuring = False
|
| 289 |
+
|
| 290 |
+
def _hide_event_check(self):
|
| 291 |
+
if not self.autocompletewindow:
|
| 292 |
+
return
|
| 293 |
+
|
| 294 |
+
try:
|
| 295 |
+
if not self.autocompletewindow.focus_get():
|
| 296 |
+
self.hide_window()
|
| 297 |
+
except KeyError:
|
| 298 |
+
# See issue 734176, when user click on menu, acw.focus_get()
|
| 299 |
+
# will get KeyError.
|
| 300 |
+
self.hide_window()
|
| 301 |
+
|
| 302 |
+
def hide_event(self, event):
|
| 303 |
+
# Hide autocomplete list if it exists and does not have focus or
|
| 304 |
+
# mouse click on widget / text area.
|
| 305 |
+
if self.is_active():
|
| 306 |
+
if event.type == EventType.FocusOut:
|
| 307 |
+
# On Windows platform, it will need to delay the check for
|
| 308 |
+
# acw.focus_get() when click on acw, otherwise it will return
|
| 309 |
+
# None and close the window
|
| 310 |
+
self.widget.after(1, self._hide_event_check)
|
| 311 |
+
elif event.type == EventType.ButtonPress:
|
| 312 |
+
# ButtonPress event only bind to self.widget
|
| 313 |
+
self.hide_window()
|
| 314 |
+
|
| 315 |
+
def listselect_event(self, event):
|
| 316 |
+
if self.is_active():
|
| 317 |
+
self.userwantswindow = True
|
| 318 |
+
cursel = int(self.listbox.curselection()[0])
|
| 319 |
+
self._change_start(self.completions[cursel])
|
| 320 |
+
|
| 321 |
+
def doubleclick_event(self, event):
|
| 322 |
+
# Put the selected completion in the text, and close the list
|
| 323 |
+
cursel = int(self.listbox.curselection()[0])
|
| 324 |
+
self._change_start(self.completions[cursel])
|
| 325 |
+
self.hide_window()
|
| 326 |
+
|
| 327 |
+
def keypress_event(self, event):
|
| 328 |
+
if not self.is_active():
|
| 329 |
+
return None
|
| 330 |
+
keysym = event.keysym
|
| 331 |
+
if hasattr(event, "mc_state"):
|
| 332 |
+
state = event.mc_state
|
| 333 |
+
else:
|
| 334 |
+
state = 0
|
| 335 |
+
if keysym != "Tab":
|
| 336 |
+
self.lastkey_was_tab = False
|
| 337 |
+
if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
|
| 338 |
+
or (self.mode == FILES and keysym in
|
| 339 |
+
("period", "minus"))) \
|
| 340 |
+
and not (state & ~MC_SHIFT):
|
| 341 |
+
# Normal editing of text
|
| 342 |
+
if len(keysym) == 1:
|
| 343 |
+
self._change_start(self.start + keysym)
|
| 344 |
+
elif keysym == "underscore":
|
| 345 |
+
self._change_start(self.start + '_')
|
| 346 |
+
elif keysym == "period":
|
| 347 |
+
self._change_start(self.start + '.')
|
| 348 |
+
elif keysym == "minus":
|
| 349 |
+
self._change_start(self.start + '-')
|
| 350 |
+
else:
|
| 351 |
+
# keysym == "BackSpace"
|
| 352 |
+
if len(self.start) == 0:
|
| 353 |
+
self.hide_window()
|
| 354 |
+
return None
|
| 355 |
+
self._change_start(self.start[:-1])
|
| 356 |
+
self.lasttypedstart = self.start
|
| 357 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 358 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 359 |
+
self._selection_changed()
|
| 360 |
+
return "break"
|
| 361 |
+
|
| 362 |
+
elif keysym == "Return":
|
| 363 |
+
self.complete()
|
| 364 |
+
self.hide_window()
|
| 365 |
+
return 'break'
|
| 366 |
+
|
| 367 |
+
elif (self.mode == ATTRS and keysym in
|
| 368 |
+
("period", "space", "parenleft", "parenright", "bracketleft",
|
| 369 |
+
"bracketright")) or \
|
| 370 |
+
(self.mode == FILES and keysym in
|
| 371 |
+
("slash", "backslash", "quotedbl", "apostrophe")) \
|
| 372 |
+
and not (state & ~MC_SHIFT):
|
| 373 |
+
# If start is a prefix of the selection, but is not '' when
|
| 374 |
+
# completing file names, put the whole
|
| 375 |
+
# selected completion. Anyway, close the list.
|
| 376 |
+
cursel = int(self.listbox.curselection()[0])
|
| 377 |
+
if self.completions[cursel][:len(self.start)] == self.start \
|
| 378 |
+
and (self.mode == ATTRS or self.start):
|
| 379 |
+
self._change_start(self.completions[cursel])
|
| 380 |
+
self.hide_window()
|
| 381 |
+
return None
|
| 382 |
+
|
| 383 |
+
elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
|
| 384 |
+
not state:
|
| 385 |
+
# Move the selection in the listbox
|
| 386 |
+
self.userwantswindow = True
|
| 387 |
+
cursel = int(self.listbox.curselection()[0])
|
| 388 |
+
if keysym == "Home":
|
| 389 |
+
newsel = 0
|
| 390 |
+
elif keysym == "End":
|
| 391 |
+
newsel = len(self.completions)-1
|
| 392 |
+
elif keysym in ("Prior", "Next"):
|
| 393 |
+
jump = self.listbox.nearest(self.listbox.winfo_height()) - \
|
| 394 |
+
self.listbox.nearest(0)
|
| 395 |
+
if keysym == "Prior":
|
| 396 |
+
newsel = max(0, cursel-jump)
|
| 397 |
+
else:
|
| 398 |
+
assert keysym == "Next"
|
| 399 |
+
newsel = min(len(self.completions)-1, cursel+jump)
|
| 400 |
+
elif keysym == "Up":
|
| 401 |
+
newsel = max(0, cursel-1)
|
| 402 |
+
else:
|
| 403 |
+
assert keysym == "Down"
|
| 404 |
+
newsel = min(len(self.completions)-1, cursel+1)
|
| 405 |
+
self.listbox.select_clear(cursel)
|
| 406 |
+
self.listbox.select_set(newsel)
|
| 407 |
+
self._selection_changed()
|
| 408 |
+
self._change_start(self.completions[newsel])
|
| 409 |
+
return "break"
|
| 410 |
+
|
| 411 |
+
elif (keysym == "Tab" and not state):
|
| 412 |
+
if self.lastkey_was_tab:
|
| 413 |
+
# two tabs in a row; insert current selection and close acw
|
| 414 |
+
cursel = int(self.listbox.curselection()[0])
|
| 415 |
+
self._change_start(self.completions[cursel])
|
| 416 |
+
self.hide_window()
|
| 417 |
+
return "break"
|
| 418 |
+
else:
|
| 419 |
+
# first tab; let AutoComplete handle the completion
|
| 420 |
+
self.userwantswindow = True
|
| 421 |
+
self.lastkey_was_tab = True
|
| 422 |
+
return None
|
| 423 |
+
|
| 424 |
+
elif any(s in keysym for s in ("Shift", "Control", "Alt",
|
| 425 |
+
"Meta", "Command", "Option")):
|
| 426 |
+
# A modifier key, so ignore
|
| 427 |
+
return None
|
| 428 |
+
|
| 429 |
+
elif event.char and event.char >= ' ':
|
| 430 |
+
# Regular character with a non-length-1 keycode
|
| 431 |
+
self._change_start(self.start + event.char)
|
| 432 |
+
self.lasttypedstart = self.start
|
| 433 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 434 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 435 |
+
self._selection_changed()
|
| 436 |
+
return "break"
|
| 437 |
+
|
| 438 |
+
else:
|
| 439 |
+
# Unknown event, close the window and let it through.
|
| 440 |
+
self.hide_window()
|
| 441 |
+
return None
|
| 442 |
+
|
| 443 |
+
def keyrelease_event(self, event):
|
| 444 |
+
if not self.is_active():
|
| 445 |
+
return
|
| 446 |
+
if self.widget.index("insert") != \
|
| 447 |
+
self.widget.index("%s+%dc" % (self.startindex, len(self.start))):
|
| 448 |
+
# If we didn't catch an event which moved the insert, close window
|
| 449 |
+
self.hide_window()
|
| 450 |
+
|
| 451 |
+
def is_active(self):
|
| 452 |
+
return self.autocompletewindow is not None
|
| 453 |
+
|
| 454 |
+
def complete(self):
|
| 455 |
+
self._change_start(self._complete_string(self.start))
|
| 456 |
+
# The selection doesn't change.
|
| 457 |
+
|
| 458 |
+
def hide_window(self):
|
| 459 |
+
if not self.is_active():
|
| 460 |
+
return
|
| 461 |
+
|
| 462 |
+
# unbind events
|
| 463 |
+
self.autocompletewindow.event_delete(HIDE_VIRTUAL_EVENT_NAME,
|
| 464 |
+
HIDE_FOCUS_OUT_SEQUENCE)
|
| 465 |
+
for seq in HIDE_SEQUENCES:
|
| 466 |
+
self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 467 |
+
|
| 468 |
+
self.autocompletewindow.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideaid)
|
| 469 |
+
self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hidewid)
|
| 470 |
+
self.hideaid = None
|
| 471 |
+
self.hidewid = None
|
| 472 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 473 |
+
self.widget.event_delete(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 474 |
+
self.widget.unbind(KEYPRESS_VIRTUAL_EVENT_NAME, self.keypressid)
|
| 475 |
+
self.keypressid = None
|
| 476 |
+
self.widget.event_delete(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 477 |
+
KEYRELEASE_SEQUENCE)
|
| 478 |
+
self.widget.unbind(KEYRELEASE_VIRTUAL_EVENT_NAME, self.keyreleaseid)
|
| 479 |
+
self.keyreleaseid = None
|
| 480 |
+
self.listbox.unbind(LISTUPDATE_SEQUENCE, self.listupdateid)
|
| 481 |
+
self.listupdateid = None
|
| 482 |
+
if self.winconfigid:
|
| 483 |
+
self.autocompletewindow.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 484 |
+
self.winconfigid = None
|
| 485 |
+
|
| 486 |
+
# Re-focusOn frame.text (See issue #15786)
|
| 487 |
+
self.widget.focus_set()
|
| 488 |
+
|
| 489 |
+
# destroy widgets
|
| 490 |
+
self.scrollbar.destroy()
|
| 491 |
+
self.scrollbar = None
|
| 492 |
+
self.listbox.destroy()
|
| 493 |
+
self.listbox = None
|
| 494 |
+
self.autocompletewindow.destroy()
|
| 495 |
+
self.autocompletewindow = None
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
if __name__ == '__main__':
|
| 499 |
+
from unittest import main
|
| 500 |
+
main('idlelib.idle_test.test_autocomplete_w', verbosity=2, exit=False)
|
| 501 |
+
|
| 502 |
+
# TODO: autocomplete/w htest here
|
llava/lib/python3.10/idlelib/browser.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module browser.
|
| 2 |
+
|
| 3 |
+
XXX TO DO:
|
| 4 |
+
|
| 5 |
+
- reparse when source changed (maybe just a button would be OK?)
|
| 6 |
+
(or recheck on window popup)
|
| 7 |
+
- add popup menu with more options (e.g. doc strings, base classes, imports)
|
| 8 |
+
- add base classes to class browser tree
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import pyclbr
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
from idlelib.config import idleConf
|
| 16 |
+
from idlelib import pyshell
|
| 17 |
+
from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
|
| 18 |
+
from idlelib.util import py_extensions
|
| 19 |
+
from idlelib.window import ListedToplevel
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
file_open = None # Method...Item and Class...Item use this.
|
| 23 |
+
# Normally pyshell.flist.open, but there is no pyshell.flist for htest.
|
| 24 |
+
|
| 25 |
+
# The browser depends on pyclbr and importlib which do not support .pyi files.
|
| 26 |
+
browseable_extension_blocklist = ('.pyi',)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def is_browseable_extension(path):
|
| 30 |
+
_, ext = os.path.splitext(path)
|
| 31 |
+
ext = os.path.normcase(ext)
|
| 32 |
+
return ext in py_extensions and ext not in browseable_extension_blocklist
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def transform_children(child_dict, modname=None):
|
| 36 |
+
"""Transform a child dictionary to an ordered sequence of objects.
|
| 37 |
+
|
| 38 |
+
The dictionary maps names to pyclbr information objects.
|
| 39 |
+
Filter out imported objects.
|
| 40 |
+
Augment class names with bases.
|
| 41 |
+
The insertion order of the dictionary is assumed to have been in line
|
| 42 |
+
number order, so sorting is not necessary.
|
| 43 |
+
|
| 44 |
+
The current tree only calls this once per child_dict as it saves
|
| 45 |
+
TreeItems once created. A future tree and tests might violate this,
|
| 46 |
+
so a check prevents multiple in-place augmentations.
|
| 47 |
+
"""
|
| 48 |
+
obs = [] # Use list since values should already be sorted.
|
| 49 |
+
for key, obj in child_dict.items():
|
| 50 |
+
if modname is None or obj.module == modname:
|
| 51 |
+
if hasattr(obj, 'super') and obj.super and obj.name == key:
|
| 52 |
+
# If obj.name != key, it has already been suffixed.
|
| 53 |
+
supers = []
|
| 54 |
+
for sup in obj.super:
|
| 55 |
+
if isinstance(sup, str):
|
| 56 |
+
sname = sup
|
| 57 |
+
else:
|
| 58 |
+
sname = sup.name
|
| 59 |
+
if sup.module != obj.module:
|
| 60 |
+
sname = f'{sup.module}.{sname}'
|
| 61 |
+
supers.append(sname)
|
| 62 |
+
obj.name += '({})'.format(', '.join(supers))
|
| 63 |
+
obs.append(obj)
|
| 64 |
+
return obs
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class ModuleBrowser:
|
| 68 |
+
"""Browse module classes and functions in IDLE.
|
| 69 |
+
"""
|
| 70 |
+
# This class is also the base class for pathbrowser.PathBrowser.
|
| 71 |
+
# Init and close are inherited, other methods are overridden.
|
| 72 |
+
# PathBrowser.__init__ does not call __init__ below.
|
| 73 |
+
|
| 74 |
+
def __init__(self, master, path, *, _htest=False, _utest=False):
|
| 75 |
+
"""Create a window for browsing a module's structure.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
master: parent for widgets.
|
| 79 |
+
path: full path of file to browse.
|
| 80 |
+
_htest - bool; change box location when running htest.
|
| 81 |
+
-utest - bool; suppress contents when running unittest.
|
| 82 |
+
|
| 83 |
+
Global variables:
|
| 84 |
+
file_open: Function used for opening a file.
|
| 85 |
+
|
| 86 |
+
Instance variables:
|
| 87 |
+
name: Module name.
|
| 88 |
+
file: Full path and module with supported extension.
|
| 89 |
+
Used in creating ModuleBrowserTreeItem as the rootnode for
|
| 90 |
+
the tree and subsequently in the children.
|
| 91 |
+
"""
|
| 92 |
+
self.master = master
|
| 93 |
+
self.path = path
|
| 94 |
+
self._htest = _htest
|
| 95 |
+
self._utest = _utest
|
| 96 |
+
self.init()
|
| 97 |
+
|
| 98 |
+
def close(self, event=None):
|
| 99 |
+
"Dismiss the window and the tree nodes."
|
| 100 |
+
self.top.destroy()
|
| 101 |
+
self.node.destroy()
|
| 102 |
+
|
| 103 |
+
def init(self):
|
| 104 |
+
"Create browser tkinter widgets, including the tree."
|
| 105 |
+
global file_open
|
| 106 |
+
root = self.master
|
| 107 |
+
flist = (pyshell.flist if not (self._htest or self._utest)
|
| 108 |
+
else pyshell.PyShellFileList(root))
|
| 109 |
+
file_open = flist.open
|
| 110 |
+
pyclbr._modules.clear()
|
| 111 |
+
|
| 112 |
+
# create top
|
| 113 |
+
self.top = top = ListedToplevel(root)
|
| 114 |
+
top.protocol("WM_DELETE_WINDOW", self.close)
|
| 115 |
+
top.bind("<Escape>", self.close)
|
| 116 |
+
if self._htest: # place dialog below parent if running htest
|
| 117 |
+
top.geometry("+%d+%d" %
|
| 118 |
+
(root.winfo_rootx(), root.winfo_rooty() + 200))
|
| 119 |
+
self.settitle()
|
| 120 |
+
top.focus_set()
|
| 121 |
+
|
| 122 |
+
# create scrolled canvas
|
| 123 |
+
theme = idleConf.CurrentTheme()
|
| 124 |
+
background = idleConf.GetHighlight(theme, 'normal')['background']
|
| 125 |
+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0,
|
| 126 |
+
takefocus=1)
|
| 127 |
+
sc.frame.pack(expand=1, fill="both")
|
| 128 |
+
item = self.rootnode()
|
| 129 |
+
self.node = node = TreeNode(sc.canvas, None, item)
|
| 130 |
+
if not self._utest:
|
| 131 |
+
node.update()
|
| 132 |
+
node.expand()
|
| 133 |
+
|
| 134 |
+
def settitle(self):
|
| 135 |
+
"Set the window title."
|
| 136 |
+
self.top.wm_title("Module Browser - " + os.path.basename(self.path))
|
| 137 |
+
self.top.wm_iconname("Module Browser")
|
| 138 |
+
|
| 139 |
+
def rootnode(self):
|
| 140 |
+
"Return a ModuleBrowserTreeItem as the root of the tree."
|
| 141 |
+
return ModuleBrowserTreeItem(self.path)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class ModuleBrowserTreeItem(TreeItem):
|
| 145 |
+
"""Browser tree for Python module.
|
| 146 |
+
|
| 147 |
+
Uses TreeItem as the basis for the structure of the tree.
|
| 148 |
+
Used by both browsers.
|
| 149 |
+
"""
|
| 150 |
+
|
| 151 |
+
def __init__(self, file):
|
| 152 |
+
"""Create a TreeItem for the file.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
file: Full path and module name.
|
| 156 |
+
"""
|
| 157 |
+
self.file = file
|
| 158 |
+
|
| 159 |
+
def GetText(self):
|
| 160 |
+
"Return the module name as the text string to display."
|
| 161 |
+
return os.path.basename(self.file)
|
| 162 |
+
|
| 163 |
+
def GetIconName(self):
|
| 164 |
+
"Return the name of the icon to display."
|
| 165 |
+
return "python"
|
| 166 |
+
|
| 167 |
+
def GetSubList(self):
|
| 168 |
+
"Return ChildBrowserTreeItems for children."
|
| 169 |
+
return [ChildBrowserTreeItem(obj) for obj in self.listchildren()]
|
| 170 |
+
|
| 171 |
+
def OnDoubleClick(self):
|
| 172 |
+
"Open a module in an editor window when double clicked."
|
| 173 |
+
if not is_browseable_extension(self.file):
|
| 174 |
+
return
|
| 175 |
+
if not os.path.exists(self.file):
|
| 176 |
+
return
|
| 177 |
+
file_open(self.file)
|
| 178 |
+
|
| 179 |
+
def IsExpandable(self):
|
| 180 |
+
"Return True if Python file."
|
| 181 |
+
return is_browseable_extension(self.file)
|
| 182 |
+
|
| 183 |
+
def listchildren(self):
|
| 184 |
+
"Return sequenced classes and functions in the module."
|
| 185 |
+
if not is_browseable_extension(self.file):
|
| 186 |
+
return []
|
| 187 |
+
dir, base = os.path.split(self.file)
|
| 188 |
+
name, _ = os.path.splitext(base)
|
| 189 |
+
try:
|
| 190 |
+
tree = pyclbr.readmodule_ex(name, [dir] + sys.path)
|
| 191 |
+
except ImportError:
|
| 192 |
+
return []
|
| 193 |
+
return transform_children(tree, name)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class ChildBrowserTreeItem(TreeItem):
|
| 197 |
+
"""Browser tree for child nodes within the module.
|
| 198 |
+
|
| 199 |
+
Uses TreeItem as the basis for the structure of the tree.
|
| 200 |
+
"""
|
| 201 |
+
|
| 202 |
+
def __init__(self, obj):
|
| 203 |
+
"Create a TreeItem for a pyclbr class/function object."
|
| 204 |
+
self.obj = obj
|
| 205 |
+
self.name = obj.name
|
| 206 |
+
self.isfunction = isinstance(obj, pyclbr.Function)
|
| 207 |
+
|
| 208 |
+
def GetText(self):
|
| 209 |
+
"Return the name of the function/class to display."
|
| 210 |
+
name = self.name
|
| 211 |
+
if self.isfunction:
|
| 212 |
+
return "def " + name + "(...)"
|
| 213 |
+
else:
|
| 214 |
+
return "class " + name
|
| 215 |
+
|
| 216 |
+
def GetIconName(self):
|
| 217 |
+
"Return the name of the icon to display."
|
| 218 |
+
if self.isfunction:
|
| 219 |
+
return "python"
|
| 220 |
+
else:
|
| 221 |
+
return "folder"
|
| 222 |
+
|
| 223 |
+
def IsExpandable(self):
|
| 224 |
+
"Return True if self.obj has nested objects."
|
| 225 |
+
return self.obj.children != {}
|
| 226 |
+
|
| 227 |
+
def GetSubList(self):
|
| 228 |
+
"Return ChildBrowserTreeItems for children."
|
| 229 |
+
return [ChildBrowserTreeItem(obj)
|
| 230 |
+
for obj in transform_children(self.obj.children)]
|
| 231 |
+
|
| 232 |
+
def OnDoubleClick(self):
|
| 233 |
+
"Open module with file_open and position to lineno."
|
| 234 |
+
try:
|
| 235 |
+
edit = file_open(self.obj.file)
|
| 236 |
+
edit.gotoline(self.obj.lineno)
|
| 237 |
+
except (OSError, AttributeError):
|
| 238 |
+
pass
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def _module_browser(parent): # htest #
|
| 242 |
+
if len(sys.argv) > 1: # If pass file on command line.
|
| 243 |
+
file = sys.argv[1]
|
| 244 |
+
else:
|
| 245 |
+
file = __file__
|
| 246 |
+
# Add nested objects for htest.
|
| 247 |
+
class Nested_in_func(TreeNode):
|
| 248 |
+
def nested_in_class(): pass
|
| 249 |
+
def closure():
|
| 250 |
+
class Nested_in_closure: pass
|
| 251 |
+
ModuleBrowser(parent, file, _htest=True)
|
| 252 |
+
|
| 253 |
+
if __name__ == "__main__":
|
| 254 |
+
if len(sys.argv) == 1: # If pass file on command line, unittest fails.
|
| 255 |
+
from unittest import main
|
| 256 |
+
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
|
| 257 |
+
from idlelib.idle_test.htest import run
|
| 258 |
+
run(_module_browser)
|
llava/lib/python3.10/idlelib/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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)
|
llava/lib/python3.10/idlelib/calltip_w.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A call-tip window class for Tkinter/IDLE.
|
| 2 |
+
|
| 3 |
+
After tooltip.py, which uses ideas gleaned from PySol.
|
| 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)
|
llava/lib/python3.10/idlelib/codecontext.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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scrolled off the top of a window, it can be difficult to
|
| 4 |
+
determine which block you are in. This extension implements a pane at the top
|
| 5 |
+
of each IDLE edit window which provides block structure hints. These hints are
|
| 6 |
+
the lines which contain the block opening keywords, e.g. 'if', for the
|
| 7 |
+
enclosing block. The number of hint lines is determined by the maxlines
|
| 8 |
+
variable in the codecontext section of config-extensions.def. Lines which do
|
| 9 |
+
not open blocks are not shown in the context hints pane.
|
| 10 |
+
|
| 11 |
+
For EditorWindows, <<toggle-code-context>> is bound to CodeContext(self).
|
| 12 |
+
toggle_code_context_event.
|
| 13 |
+
"""
|
| 14 |
+
import re
|
| 15 |
+
from sys import maxsize as INFINITY
|
| 16 |
+
|
| 17 |
+
from tkinter import Frame, Text, TclError
|
| 18 |
+
from tkinter.constants import NSEW, SUNKEN
|
| 19 |
+
|
| 20 |
+
from idlelib.config import idleConf
|
| 21 |
+
|
| 22 |
+
BLOCKOPENERS = {'class', 'def', 'if', 'elif', 'else', 'while', 'for',
|
| 23 |
+
'try', 'except', 'finally', 'with', 'async'}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def get_spaces_firstword(codeline, c=re.compile(r"^(\s*)(\w*)")):
|
| 27 |
+
"Extract the beginning whitespace and first word from codeline."
|
| 28 |
+
return c.match(codeline).groups()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def get_line_info(codeline):
|
| 32 |
+
"""Return tuple of (line indent value, codeline, block start keyword).
|
| 33 |
+
|
| 34 |
+
The indentation of empty lines (or comment lines) is INFINITY.
|
| 35 |
+
If the line does not start a block, the keyword value is False.
|
| 36 |
+
"""
|
| 37 |
+
spaces, firstword = get_spaces_firstword(codeline)
|
| 38 |
+
indent = len(spaces)
|
| 39 |
+
if len(codeline) == indent or codeline[indent] == '#':
|
| 40 |
+
indent = INFINITY
|
| 41 |
+
opener = firstword in BLOCKOPENERS and firstword
|
| 42 |
+
return indent, codeline, opener
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class CodeContext:
|
| 46 |
+
"Display block context above the edit window."
|
| 47 |
+
UPDATEINTERVAL = 100 # millisec
|
| 48 |
+
|
| 49 |
+
def __init__(self, editwin):
|
| 50 |
+
"""Initialize settings for context block.
|
| 51 |
+
|
| 52 |
+
editwin is the Editor window for the context block.
|
| 53 |
+
self.text is the editor window text widget.
|
| 54 |
+
|
| 55 |
+
self.context displays the code context text above the editor text.
|
| 56 |
+
Initially None, it is toggled via <<toggle-code-context>>.
|
| 57 |
+
self.topvisible is the number of the top text line displayed.
|
| 58 |
+
self.info is a list of (line number, indent level, line text,
|
| 59 |
+
block keyword) tuples for the block structure above topvisible.
|
| 60 |
+
self.info[0] is initialized with a 'dummy' line which
|
| 61 |
+
starts the toplevel 'block' of the module.
|
| 62 |
+
|
| 63 |
+
self.t1 and self.t2 are two timer events on the editor text widget to
|
| 64 |
+
monitor for changes to the context text or editor font.
|
| 65 |
+
"""
|
| 66 |
+
self.editwin = editwin
|
| 67 |
+
self.text = editwin.text
|
| 68 |
+
self._reset()
|
| 69 |
+
|
| 70 |
+
def _reset(self):
|
| 71 |
+
self.context = None
|
| 72 |
+
self.cell00 = None
|
| 73 |
+
self.t1 = None
|
| 74 |
+
self.topvisible = 1
|
| 75 |
+
self.info = [(0, -1, "", False)]
|
| 76 |
+
|
| 77 |
+
@classmethod
|
| 78 |
+
def reload(cls):
|
| 79 |
+
"Load class variables from config."
|
| 80 |
+
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
|
| 81 |
+
"maxlines", type="int",
|
| 82 |
+
default=15)
|
| 83 |
+
|
| 84 |
+
def __del__(self):
|
| 85 |
+
"Cancel scheduled events."
|
| 86 |
+
if self.t1 is not None:
|
| 87 |
+
try:
|
| 88 |
+
self.text.after_cancel(self.t1)
|
| 89 |
+
except TclError: # pragma: no cover
|
| 90 |
+
pass
|
| 91 |
+
self.t1 = None
|
| 92 |
+
|
| 93 |
+
def toggle_code_context_event(self, event=None):
|
| 94 |
+
"""Toggle code context display.
|
| 95 |
+
|
| 96 |
+
If self.context doesn't exist, create it to match the size of the editor
|
| 97 |
+
window text (toggle on). If it does exist, destroy it (toggle off).
|
| 98 |
+
Return 'break' to complete the processing of the binding.
|
| 99 |
+
"""
|
| 100 |
+
if self.context is None:
|
| 101 |
+
# Calculate the border width and horizontal padding required to
|
| 102 |
+
# align the context with the text in the main Text widget.
|
| 103 |
+
#
|
| 104 |
+
# All values are passed through getint(), since some
|
| 105 |
+
# values may be pixel objects, which can't simply be added to ints.
|
| 106 |
+
widgets = self.editwin.text, self.editwin.text_frame
|
| 107 |
+
# Calculate the required horizontal padding and border width.
|
| 108 |
+
padx = 0
|
| 109 |
+
border = 0
|
| 110 |
+
for widget in widgets:
|
| 111 |
+
info = (widget.grid_info()
|
| 112 |
+
if widget is self.editwin.text
|
| 113 |
+
else widget.pack_info())
|
| 114 |
+
padx += widget.tk.getint(info['padx'])
|
| 115 |
+
padx += widget.tk.getint(widget.cget('padx'))
|
| 116 |
+
border += widget.tk.getint(widget.cget('border'))
|
| 117 |
+
context = self.context = Text(
|
| 118 |
+
self.editwin.text_frame,
|
| 119 |
+
height=1,
|
| 120 |
+
width=1, # Don't request more than we get.
|
| 121 |
+
highlightthickness=0,
|
| 122 |
+
padx=padx, border=border, relief=SUNKEN, state='disabled')
|
| 123 |
+
self.update_font()
|
| 124 |
+
self.update_highlight_colors()
|
| 125 |
+
context.bind('<ButtonRelease-1>', self.jumptoline)
|
| 126 |
+
# Get the current context and initiate the recurring update event.
|
| 127 |
+
self.timer_event()
|
| 128 |
+
# Grid the context widget above the text widget.
|
| 129 |
+
context.grid(row=0, column=1, sticky=NSEW)
|
| 130 |
+
|
| 131 |
+
line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 132 |
+
'linenumber')
|
| 133 |
+
self.cell00 = Frame(self.editwin.text_frame,
|
| 134 |
+
bg=line_number_colors['background'])
|
| 135 |
+
self.cell00.grid(row=0, column=0, sticky=NSEW)
|
| 136 |
+
menu_status = 'Hide'
|
| 137 |
+
else:
|
| 138 |
+
self.context.destroy()
|
| 139 |
+
self.context = None
|
| 140 |
+
self.cell00.destroy()
|
| 141 |
+
self.cell00 = None
|
| 142 |
+
self.text.after_cancel(self.t1)
|
| 143 |
+
self._reset()
|
| 144 |
+
menu_status = 'Show'
|
| 145 |
+
self.editwin.update_menu_label(menu='options', index='*ode*ontext',
|
| 146 |
+
label=f'{menu_status} Code Context')
|
| 147 |
+
return "break"
|
| 148 |
+
|
| 149 |
+
def get_context(self, new_topvisible, stopline=1, stopindent=0):
|
| 150 |
+
"""Return a list of block line tuples and the 'last' indent.
|
| 151 |
+
|
| 152 |
+
The tuple fields are (linenum, indent, text, opener).
|
| 153 |
+
The list represents header lines from new_topvisible back to
|
| 154 |
+
stopline with successively shorter indents > stopindent.
|
| 155 |
+
The list is returned ordered by line number.
|
| 156 |
+
Last indent returned is the smallest indent observed.
|
| 157 |
+
"""
|
| 158 |
+
assert stopline > 0
|
| 159 |
+
lines = []
|
| 160 |
+
# The indentation level we are currently in.
|
| 161 |
+
lastindent = INFINITY
|
| 162 |
+
# For a line to be interesting, it must begin with a block opening
|
| 163 |
+
# keyword, and have less indentation than lastindent.
|
| 164 |
+
for linenum in range(new_topvisible, stopline-1, -1):
|
| 165 |
+
codeline = self.text.get(f'{linenum}.0', f'{linenum}.end')
|
| 166 |
+
indent, text, opener = get_line_info(codeline)
|
| 167 |
+
if indent < lastindent:
|
| 168 |
+
lastindent = indent
|
| 169 |
+
if opener in ("else", "elif"):
|
| 170 |
+
# Also show the if statement.
|
| 171 |
+
lastindent += 1
|
| 172 |
+
if opener and linenum < new_topvisible and indent >= stopindent:
|
| 173 |
+
lines.append((linenum, indent, text, opener))
|
| 174 |
+
if lastindent <= stopindent:
|
| 175 |
+
break
|
| 176 |
+
lines.reverse()
|
| 177 |
+
return lines, lastindent
|
| 178 |
+
|
| 179 |
+
def update_code_context(self):
|
| 180 |
+
"""Update context information and lines visible in the context pane.
|
| 181 |
+
|
| 182 |
+
No update is done if the text hasn't been scrolled. If the text
|
| 183 |
+
was scrolled, the lines that should be shown in the context will
|
| 184 |
+
be retrieved and the context area will be updated with the code,
|
| 185 |
+
up to the number of maxlines.
|
| 186 |
+
"""
|
| 187 |
+
new_topvisible = self.editwin.getlineno("@0,0")
|
| 188 |
+
if self.topvisible == new_topvisible: # Haven't scrolled.
|
| 189 |
+
return
|
| 190 |
+
if self.topvisible < new_topvisible: # Scroll down.
|
| 191 |
+
lines, lastindent = self.get_context(new_topvisible,
|
| 192 |
+
self.topvisible)
|
| 193 |
+
# Retain only context info applicable to the region
|
| 194 |
+
# between topvisible and new_topvisible.
|
| 195 |
+
while self.info[-1][1] >= lastindent:
|
| 196 |
+
del self.info[-1]
|
| 197 |
+
else: # self.topvisible > new_topvisible: # Scroll up.
|
| 198 |
+
stopindent = self.info[-1][1] + 1
|
| 199 |
+
# Retain only context info associated
|
| 200 |
+
# with lines above new_topvisible.
|
| 201 |
+
while self.info[-1][0] >= new_topvisible:
|
| 202 |
+
stopindent = self.info[-1][1]
|
| 203 |
+
del self.info[-1]
|
| 204 |
+
lines, lastindent = self.get_context(new_topvisible,
|
| 205 |
+
self.info[-1][0]+1,
|
| 206 |
+
stopindent)
|
| 207 |
+
self.info.extend(lines)
|
| 208 |
+
self.topvisible = new_topvisible
|
| 209 |
+
# Last context_depth context lines.
|
| 210 |
+
context_strings = [x[2] for x in self.info[-self.context_depth:]]
|
| 211 |
+
showfirst = 0 if context_strings[0] else 1
|
| 212 |
+
# Update widget.
|
| 213 |
+
self.context['height'] = len(context_strings) - showfirst
|
| 214 |
+
self.context['state'] = 'normal'
|
| 215 |
+
self.context.delete('1.0', 'end')
|
| 216 |
+
self.context.insert('end', '\n'.join(context_strings[showfirst:]))
|
| 217 |
+
self.context['state'] = 'disabled'
|
| 218 |
+
|
| 219 |
+
def jumptoline(self, event=None):
|
| 220 |
+
""" Show clicked context line at top of editor.
|
| 221 |
+
|
| 222 |
+
If a selection was made, don't jump; allow copying.
|
| 223 |
+
If no visible context, show the top line of the file.
|
| 224 |
+
"""
|
| 225 |
+
try:
|
| 226 |
+
self.context.index("sel.first")
|
| 227 |
+
except TclError:
|
| 228 |
+
lines = len(self.info)
|
| 229 |
+
if lines == 1: # No context lines are showing.
|
| 230 |
+
newtop = 1
|
| 231 |
+
else:
|
| 232 |
+
# Line number clicked.
|
| 233 |
+
contextline = int(float(self.context.index('insert')))
|
| 234 |
+
# Lines not displayed due to maxlines.
|
| 235 |
+
offset = max(1, lines - self.context_depth) - 1
|
| 236 |
+
newtop = self.info[offset + contextline][0]
|
| 237 |
+
self.text.yview(f'{newtop}.0')
|
| 238 |
+
self.update_code_context()
|
| 239 |
+
|
| 240 |
+
def timer_event(self):
|
| 241 |
+
"Event on editor text widget triggered every UPDATEINTERVAL ms."
|
| 242 |
+
if self.context is not None:
|
| 243 |
+
self.update_code_context()
|
| 244 |
+
self.t1 = self.text.after(self.UPDATEINTERVAL, self.timer_event)
|
| 245 |
+
|
| 246 |
+
def update_font(self):
|
| 247 |
+
if self.context is not None:
|
| 248 |
+
font = idleConf.GetFont(self.text, 'main', 'EditorWindow')
|
| 249 |
+
self.context['font'] = font
|
| 250 |
+
|
| 251 |
+
def update_highlight_colors(self):
|
| 252 |
+
if self.context is not None:
|
| 253 |
+
colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'context')
|
| 254 |
+
self.context['background'] = colors['background']
|
| 255 |
+
self.context['foreground'] = colors['foreground']
|
| 256 |
+
|
| 257 |
+
if self.cell00 is not None:
|
| 258 |
+
line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 259 |
+
'linenumber')
|
| 260 |
+
self.cell00.config(bg=line_number_colors['background'])
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
CodeContext.reload()
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
if __name__ == "__main__":
|
| 267 |
+
from unittest import main
|
| 268 |
+
main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)
|
| 269 |
+
|
| 270 |
+
# Add htest.
|
llava/l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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)
|
llava/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>
|
llava/lib/python3.10/idlelib/config.py
ADDED
|
@@ -0,0 +1,911 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""idlelib.config -- Manage IDLE configuration information.
|
| 2 |
+
|
| 3 |
+
The comments at the beginning of config-main.def describe the
|
| 4 |
+
configuration files and the design implemented to update user
|
| 5 |
+
configuration information. In particular, user configuration choices
|
| 6 |
+
which duplicate the defaults will be removed from the user's
|
| 7 |
+
configuration files, and if a user file becomes empty, it will be
|
| 8 |
+
deleted.
|
| 9 |
+
|
| 10 |
+
The configuration database maps options to values. Conceptually, the
|
| 11 |
+
database keys are tuples (config-type, section, item). As implemented,
|
| 12 |
+
there are separate dicts for default and user values. Each has
|
| 13 |
+
config-type keys 'main', 'extensions', 'highlight', and 'keys'. The
|
| 14 |
+
value for each key is a ConfigParser instance that maps section and item
|
| 15 |
+
to values. For 'main' and 'extensions', user values override
|
| 16 |
+
default values. For 'highlight' and 'keys', user sections augment the
|
| 17 |
+
default sections (and must, therefore, have distinct names).
|
| 18 |
+
|
| 19 |
+
Throughout this module there is an emphasis on returning useable defaults
|
| 20 |
+
when a problem occurs in returning a requested configuration value back to
|
| 21 |
+
idle. This is to allow IDLE to continue to function in spite of errors in
|
| 22 |
+
the retrieval of config information. When a default is returned instead of
|
| 23 |
+
a requested config value, a message is printed to stderr to aid in
|
| 24 |
+
configuration problem notification and resolution.
|
| 25 |
+
"""
|
| 26 |
+
# TODOs added Oct 2014, tjr
|
| 27 |
+
|
| 28 |
+
from configparser import ConfigParser
|
| 29 |
+
import os
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
from tkinter.font import Font
|
| 33 |
+
import idlelib
|
| 34 |
+
|
| 35 |
+
class InvalidConfigType(Exception): pass
|
| 36 |
+
class InvalidConfigSet(Exception): pass
|
| 37 |
+
class InvalidTheme(Exception): pass
|
| 38 |
+
|
| 39 |
+
class IdleConfParser(ConfigParser):
|
| 40 |
+
"""
|
| 41 |
+
A ConfigParser specialised for idle configuration file handling
|
| 42 |
+
"""
|
| 43 |
+
def __init__(self, cfgFile, cfgDefaults=None):
|
| 44 |
+
"""
|
| 45 |
+
cfgFile - string, fully specified configuration file name
|
| 46 |
+
"""
|
| 47 |
+
self.file = cfgFile # This is currently '' when testing.
|
| 48 |
+
ConfigParser.__init__(self, defaults=cfgDefaults, strict=False)
|
| 49 |
+
|
| 50 |
+
def Get(self, section, option, type=None, default=None, raw=False):
|
| 51 |
+
"""
|
| 52 |
+
Get an option value for given section/option or return default.
|
| 53 |
+
If type is specified, return as type.
|
| 54 |
+
"""
|
| 55 |
+
# TODO Use default as fallback, at least if not None
|
| 56 |
+
# Should also print Warning(file, section, option).
|
| 57 |
+
# Currently may raise ValueError
|
| 58 |
+
if not self.has_option(section, option):
|
| 59 |
+
return default
|
| 60 |
+
if type == 'bool':
|
| 61 |
+
return self.getboolean(section, option)
|
| 62 |
+
elif type == 'int':
|
| 63 |
+
return self.getint(section, option)
|
| 64 |
+
else:
|
| 65 |
+
return self.get(section, option, raw=raw)
|
| 66 |
+
|
| 67 |
+
def GetOptionList(self, section):
|
| 68 |
+
"Return a list of options for given section, else []."
|
| 69 |
+
if self.has_section(section):
|
| 70 |
+
return self.options(section)
|
| 71 |
+
else: #return a default value
|
| 72 |
+
return []
|
| 73 |
+
|
| 74 |
+
def Load(self):
|
| 75 |
+
"Load the configuration file from disk."
|
| 76 |
+
if self.file:
|
| 77 |
+
self.read(self.file)
|
| 78 |
+
|
| 79 |
+
class IdleUserConfParser(IdleConfParser):
|
| 80 |
+
"""
|
| 81 |
+
IdleConfigParser specialised for user configuration handling.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def SetOption(self, section, option, value):
|
| 85 |
+
"""Return True if option is added or changed to value, else False.
|
| 86 |
+
|
| 87 |
+
Add section if required. False means option already had value.
|
| 88 |
+
"""
|
| 89 |
+
if self.has_option(section, option):
|
| 90 |
+
if self.get(section, option) == value:
|
| 91 |
+
return False
|
| 92 |
+
else:
|
| 93 |
+
self.set(section, option, value)
|
| 94 |
+
return True
|
| 95 |
+
else:
|
| 96 |
+
if not self.has_section(section):
|
| 97 |
+
self.add_section(section)
|
| 98 |
+
self.set(section, option, value)
|
| 99 |
+
return True
|
| 100 |
+
|
| 101 |
+
def RemoveOption(self, section, option):
|
| 102 |
+
"""Return True if option is removed from section, else False.
|
| 103 |
+
|
| 104 |
+
False if either section does not exist or did not have option.
|
| 105 |
+
"""
|
| 106 |
+
if self.has_section(section):
|
| 107 |
+
return self.remove_option(section, option)
|
| 108 |
+
return False
|
| 109 |
+
|
| 110 |
+
def AddSection(self, section):
|
| 111 |
+
"If section doesn't exist, add it."
|
| 112 |
+
if not self.has_section(section):
|
| 113 |
+
self.add_section(section)
|
| 114 |
+
|
| 115 |
+
def RemoveEmptySections(self):
|
| 116 |
+
"Remove any sections that have no options."
|
| 117 |
+
for section in self.sections():
|
| 118 |
+
if not self.GetOptionList(section):
|
| 119 |
+
self.remove_section(section)
|
| 120 |
+
|
| 121 |
+
def IsEmpty(self):
|
| 122 |
+
"Return True if no sections after removing empty sections."
|
| 123 |
+
self.RemoveEmptySections()
|
| 124 |
+
return not self.sections()
|
| 125 |
+
|
| 126 |
+
def Save(self):
|
| 127 |
+
"""Update user configuration file.
|
| 128 |
+
|
| 129 |
+
If self not empty after removing empty sections, write the file
|
| 130 |
+
to disk. Otherwise, remove the file from disk if it exists.
|
| 131 |
+
"""
|
| 132 |
+
fname = self.file
|
| 133 |
+
if fname and fname[0] != '#':
|
| 134 |
+
if not self.IsEmpty():
|
| 135 |
+
try:
|
| 136 |
+
cfgFile = open(fname, 'w')
|
| 137 |
+
except OSError:
|
| 138 |
+
os.unlink(fname)
|
| 139 |
+
cfgFile = open(fname, 'w')
|
| 140 |
+
with cfgFile:
|
| 141 |
+
self.write(cfgFile)
|
| 142 |
+
elif os.path.exists(self.file):
|
| 143 |
+
os.remove(self.file)
|
| 144 |
+
|
| 145 |
+
class IdleConf:
|
| 146 |
+
"""Hold config parsers for all idle config files in singleton instance.
|
| 147 |
+
|
| 148 |
+
Default config files, self.defaultCfg --
|
| 149 |
+
for config_type in self.config_types:
|
| 150 |
+
(idle install dir)/config-{config-type}.def
|
| 151 |
+
|
| 152 |
+
User config files, self.userCfg --
|
| 153 |
+
for config_type in self.config_types:
|
| 154 |
+
(user home dir)/.idlerc/config-{config-type}.cfg
|
| 155 |
+
"""
|
| 156 |
+
def __init__(self, _utest=False):
|
| 157 |
+
self.config_types = ('main', 'highlight', 'keys', 'extensions')
|
| 158 |
+
self.defaultCfg = {}
|
| 159 |
+
self.userCfg = {}
|
| 160 |
+
self.cfg = {} # TODO use to select userCfg vs defaultCfg
|
| 161 |
+
# self.blink_off_time = <first editor text>['insertofftime']
|
| 162 |
+
# See https:/bugs.python.org/issue4630, msg356516.
|
| 163 |
+
|
| 164 |
+
if not _utest:
|
| 165 |
+
self.CreateConfigHandlers()
|
| 166 |
+
self.LoadCfgFiles()
|
| 167 |
+
|
| 168 |
+
def CreateConfigHandlers(self):
|
| 169 |
+
"Populate default and user config parser dictionaries."
|
| 170 |
+
idledir = os.path.dirname(__file__)
|
| 171 |
+
self.userdir = userdir = '' if idlelib.testing else self.GetUserCfgDir()
|
| 172 |
+
for cfg_type in self.config_types:
|
| 173 |
+
self.defaultCfg[cfg_type] = IdleConfParser(
|
| 174 |
+
os.path.join(idledir, f'config-{cfg_type}.def'))
|
| 175 |
+
self.userCfg[cfg_type] = IdleUserConfParser(
|
| 176 |
+
os.path.join(userdir or '#', f'config-{cfg_type}.cfg'))
|
| 177 |
+
|
| 178 |
+
def GetUserCfgDir(self):
|
| 179 |
+
"""Return a filesystem directory for storing user config files.
|
| 180 |
+
|
| 181 |
+
Creates it if required.
|
| 182 |
+
"""
|
| 183 |
+
cfgDir = '.idlerc'
|
| 184 |
+
userDir = os.path.expanduser('~')
|
| 185 |
+
if userDir != '~': # expanduser() found user home dir
|
| 186 |
+
if not os.path.exists(userDir):
|
| 187 |
+
if not idlelib.testing:
|
| 188 |
+
warn = ('\n Warning: os.path.expanduser("~") points to\n ' +
|
| 189 |
+
userDir + ',\n but the path does not exist.')
|
| 190 |
+
try:
|
| 191 |
+
print(warn, file=sys.stderr)
|
| 192 |
+
except OSError:
|
| 193 |
+
pass
|
| 194 |
+
userDir = '~'
|
| 195 |
+
if userDir == "~": # still no path to home!
|
| 196 |
+
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
|
| 197 |
+
userDir = os.getcwd()
|
| 198 |
+
userDir = os.path.join(userDir, cfgDir)
|
| 199 |
+
if not os.path.exists(userDir):
|
| 200 |
+
try:
|
| 201 |
+
os.mkdir(userDir)
|
| 202 |
+
except OSError:
|
| 203 |
+
if not idlelib.testing:
|
| 204 |
+
warn = ('\n Warning: unable to create user config directory\n' +
|
| 205 |
+
userDir + '\n Check path and permissions.\n Exiting!\n')
|
| 206 |
+
try:
|
| 207 |
+
print(warn, file=sys.stderr)
|
| 208 |
+
except OSError:
|
| 209 |
+
pass
|
| 210 |
+
raise SystemExit
|
| 211 |
+
# TODO continue without userDIr instead of exit
|
| 212 |
+
return userDir
|
| 213 |
+
|
| 214 |
+
def GetOption(self, configType, section, option, default=None, type=None,
|
| 215 |
+
warn_on_default=True, raw=False):
|
| 216 |
+
"""Return a value for configType section option, or default.
|
| 217 |
+
|
| 218 |
+
If type is not None, return a value of that type. Also pass raw
|
| 219 |
+
to the config parser. First try to return a valid value
|
| 220 |
+
(including type) from a user configuration. If that fails, try
|
| 221 |
+
the default configuration. If that fails, return default, with a
|
| 222 |
+
default of None.
|
| 223 |
+
|
| 224 |
+
Warn if either user or default configurations have an invalid value.
|
| 225 |
+
Warn if default is returned and warn_on_default is True.
|
| 226 |
+
"""
|
| 227 |
+
try:
|
| 228 |
+
if self.userCfg[configType].has_option(section, option):
|
| 229 |
+
return self.userCfg[configType].Get(section, option,
|
| 230 |
+
type=type, raw=raw)
|
| 231 |
+
except ValueError:
|
| 232 |
+
warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
|
| 233 |
+
' invalid %r value for configuration option %r\n'
|
| 234 |
+
' from section %r: %r' %
|
| 235 |
+
(type, option, section,
|
| 236 |
+
self.userCfg[configType].Get(section, option, raw=raw)))
|
| 237 |
+
_warn(warning, configType, section, option)
|
| 238 |
+
try:
|
| 239 |
+
if self.defaultCfg[configType].has_option(section,option):
|
| 240 |
+
return self.defaultCfg[configType].Get(
|
| 241 |
+
section, option, type=type, raw=raw)
|
| 242 |
+
except ValueError:
|
| 243 |
+
pass
|
| 244 |
+
#returning default, print warning
|
| 245 |
+
if warn_on_default:
|
| 246 |
+
warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
|
| 247 |
+
' problem retrieving configuration option %r\n'
|
| 248 |
+
' from section %r.\n'
|
| 249 |
+
' returning default value: %r' %
|
| 250 |
+
(option, section, default))
|
| 251 |
+
_warn(warning, configType, section, option)
|
| 252 |
+
return default
|
| 253 |
+
|
| 254 |
+
def SetOption(self, configType, section, option, value):
|
| 255 |
+
"""Set section option to value in user config file."""
|
| 256 |
+
self.userCfg[configType].SetOption(section, option, value)
|
| 257 |
+
|
| 258 |
+
def GetSectionList(self, configSet, configType):
|
| 259 |
+
"""Return sections for configSet configType configuration.
|
| 260 |
+
|
| 261 |
+
configSet must be either 'user' or 'default'
|
| 262 |
+
configType must be in self.config_types.
|
| 263 |
+
"""
|
| 264 |
+
if not (configType in self.config_types):
|
| 265 |
+
raise InvalidConfigType('Invalid configType specified')
|
| 266 |
+
if configSet == 'user':
|
| 267 |
+
cfgParser = self.userCfg[configType]
|
| 268 |
+
elif configSet == 'default':
|
| 269 |
+
cfgParser=self.defaultCfg[configType]
|
| 270 |
+
else:
|
| 271 |
+
raise InvalidConfigSet('Invalid configSet specified')
|
| 272 |
+
return cfgParser.sections()
|
| 273 |
+
|
| 274 |
+
def GetHighlight(self, theme, element):
|
| 275 |
+
"""Return dict of theme element highlight colors.
|
| 276 |
+
|
| 277 |
+
The keys are 'foreground' and 'background'. The values are
|
| 278 |
+
tkinter color strings for configuring backgrounds and tags.
|
| 279 |
+
"""
|
| 280 |
+
cfg = ('default' if self.defaultCfg['highlight'].has_section(theme)
|
| 281 |
+
else 'user')
|
| 282 |
+
theme_dict = self.GetThemeDict(cfg, theme)
|
| 283 |
+
fore = theme_dict[element + '-foreground']
|
| 284 |
+
if element == 'cursor':
|
| 285 |
+
element = 'normal'
|
| 286 |
+
back = theme_dict[element + '-background']
|
| 287 |
+
return {"foreground": fore, "background": back}
|
| 288 |
+
|
| 289 |
+
def GetThemeDict(self, type, themeName):
|
| 290 |
+
"""Return {option:value} dict for elements in themeName.
|
| 291 |
+
|
| 292 |
+
type - string, 'default' or 'user' theme type
|
| 293 |
+
themeName - string, theme name
|
| 294 |
+
Values are loaded over ultimate fallback defaults to guarantee
|
| 295 |
+
that all theme elements are present in a newly created theme.
|
| 296 |
+
"""
|
| 297 |
+
if type == 'user':
|
| 298 |
+
cfgParser = self.userCfg['highlight']
|
| 299 |
+
elif type == 'default':
|
| 300 |
+
cfgParser = self.defaultCfg['highlight']
|
| 301 |
+
else:
|
| 302 |
+
raise InvalidTheme('Invalid theme type specified')
|
| 303 |
+
# Provide foreground and background colors for each theme
|
| 304 |
+
# element (other than cursor) even though some values are not
|
| 305 |
+
# yet used by idle, to allow for their use in the future.
|
| 306 |
+
# Default values are generally black and white.
|
| 307 |
+
# TODO copy theme from a class attribute.
|
| 308 |
+
theme ={'normal-foreground':'#000000',
|
| 309 |
+
'normal-background':'#ffffff',
|
| 310 |
+
'keyword-foreground':'#000000',
|
| 311 |
+
'keyword-background':'#ffffff',
|
| 312 |
+
'builtin-foreground':'#000000',
|
| 313 |
+
'builtin-background':'#ffffff',
|
| 314 |
+
'comment-foreground':'#000000',
|
| 315 |
+
'comment-background':'#ffffff',
|
| 316 |
+
'string-foreground':'#000000',
|
| 317 |
+
'string-background':'#ffffff',
|
| 318 |
+
'definition-foreground':'#000000',
|
| 319 |
+
'definition-background':'#ffffff',
|
| 320 |
+
'hilite-foreground':'#000000',
|
| 321 |
+
'hilite-background':'gray',
|
| 322 |
+
'break-foreground':'#ffffff',
|
| 323 |
+
'break-background':'#000000',
|
| 324 |
+
'hit-foreground':'#ffffff',
|
| 325 |
+
'hit-background':'#000000',
|
| 326 |
+
'error-foreground':'#ffffff',
|
| 327 |
+
'error-background':'#000000',
|
| 328 |
+
'context-foreground':'#000000',
|
| 329 |
+
'context-background':'#ffffff',
|
| 330 |
+
'linenumber-foreground':'#000000',
|
| 331 |
+
'linenumber-background':'#ffffff',
|
| 332 |
+
#cursor (only foreground can be set)
|
| 333 |
+
'cursor-foreground':'#000000',
|
| 334 |
+
#shell window
|
| 335 |
+
'stdout-foreground':'#000000',
|
| 336 |
+
'stdout-background':'#ffffff',
|
| 337 |
+
'stderr-foreground':'#000000',
|
| 338 |
+
'stderr-background':'#ffffff',
|
| 339 |
+
'console-foreground':'#000000',
|
| 340 |
+
'console-background':'#ffffff',
|
| 341 |
+
}
|
| 342 |
+
for element in theme:
|
| 343 |
+
if not (cfgParser.has_option(themeName, element) or
|
| 344 |
+
# Skip warning for new elements.
|
| 345 |
+
element.startswith(('context-', 'linenumber-'))):
|
| 346 |
+
# Print warning that will return a default color
|
| 347 |
+
warning = ('\n Warning: config.IdleConf.GetThemeDict'
|
| 348 |
+
' -\n problem retrieving theme element %r'
|
| 349 |
+
'\n from theme %r.\n'
|
| 350 |
+
' returning default color: %r' %
|
| 351 |
+
(element, themeName, theme[element]))
|
| 352 |
+
_warn(warning, 'highlight', themeName, element)
|
| 353 |
+
theme[element] = cfgParser.Get(
|
| 354 |
+
themeName, element, default=theme[element])
|
| 355 |
+
return theme
|
| 356 |
+
|
| 357 |
+
def CurrentTheme(self):
|
| 358 |
+
"Return the name of the currently active text color theme."
|
| 359 |
+
return self.current_colors_and_keys('Theme')
|
| 360 |
+
|
| 361 |
+
def CurrentKeys(self):
|
| 362 |
+
"""Return the name of the currently active key set."""
|
| 363 |
+
return self.current_colors_and_keys('Keys')
|
| 364 |
+
|
| 365 |
+
def current_colors_and_keys(self, section):
|
| 366 |
+
"""Return the currently active name for Theme or Keys section.
|
| 367 |
+
|
| 368 |
+
idlelib.config-main.def ('default') includes these sections
|
| 369 |
+
|
| 370 |
+
[Theme]
|
| 371 |
+
default= 1
|
| 372 |
+
name= IDLE Classic
|
| 373 |
+
name2=
|
| 374 |
+
|
| 375 |
+
[Keys]
|
| 376 |
+
default= 1
|
| 377 |
+
name=
|
| 378 |
+
name2=
|
| 379 |
+
|
| 380 |
+
Item 'name2', is used for built-in ('default') themes and keys
|
| 381 |
+
added after 2015 Oct 1 and 2016 July 1. This kludge is needed
|
| 382 |
+
because setting 'name' to a builtin not defined in older IDLEs
|
| 383 |
+
to display multiple error messages or quit.
|
| 384 |
+
See https://bugs.python.org/issue25313.
|
| 385 |
+
When default = True, 'name2' takes precedence over 'name',
|
| 386 |
+
while older IDLEs will just use name. When default = False,
|
| 387 |
+
'name2' may still be set, but it is ignored.
|
| 388 |
+
"""
|
| 389 |
+
cfgname = 'highlight' if section == 'Theme' else 'keys'
|
| 390 |
+
default = self.GetOption('main', section, 'default',
|
| 391 |
+
type='bool', default=True)
|
| 392 |
+
name = ''
|
| 393 |
+
if default:
|
| 394 |
+
name = self.GetOption('main', section, 'name2', default='')
|
| 395 |
+
if not name:
|
| 396 |
+
name = self.GetOption('main', section, 'name', default='')
|
| 397 |
+
if name:
|
| 398 |
+
source = self.defaultCfg if default else self.userCfg
|
| 399 |
+
if source[cfgname].has_section(name):
|
| 400 |
+
return name
|
| 401 |
+
return "IDLE Classic" if section == 'Theme' else self.default_keys()
|
| 402 |
+
|
| 403 |
+
@staticmethod
|
| 404 |
+
def default_keys():
|
| 405 |
+
if sys.platform[:3] == 'win':
|
| 406 |
+
return 'IDLE Classic Windows'
|
| 407 |
+
elif sys.platform == 'darwin':
|
| 408 |
+
return 'IDLE Classic OSX'
|
| 409 |
+
else:
|
| 410 |
+
return 'IDLE Modern Unix'
|
| 411 |
+
|
| 412 |
+
def GetExtensions(self, active_only=True,
|
| 413 |
+
editor_only=False, shell_only=False):
|
| 414 |
+
"""Return extensions in default and user config-extensions files.
|
| 415 |
+
|
| 416 |
+
If active_only True, only return active (enabled) extensions
|
| 417 |
+
and optionally only editor or shell extensions.
|
| 418 |
+
If active_only False, return all extensions.
|
| 419 |
+
"""
|
| 420 |
+
extns = self.RemoveKeyBindNames(
|
| 421 |
+
self.GetSectionList('default', 'extensions'))
|
| 422 |
+
userExtns = self.RemoveKeyBindNames(
|
| 423 |
+
self.GetSectionList('user', 'extensions'))
|
| 424 |
+
for extn in userExtns:
|
| 425 |
+
if extn not in extns: #user has added own extension
|
| 426 |
+
extns.append(extn)
|
| 427 |
+
for extn in ('AutoComplete','CodeContext',
|
| 428 |
+
'FormatParagraph','ParenMatch'):
|
| 429 |
+
extns.remove(extn)
|
| 430 |
+
# specific exclusions because we are storing config for mainlined old
|
| 431 |
+
# extensions in config-extensions.def for backward compatibility
|
| 432 |
+
if active_only:
|
| 433 |
+
activeExtns = []
|
| 434 |
+
for extn in extns:
|
| 435 |
+
if self.GetOption('extensions', extn, 'enable', default=True,
|
| 436 |
+
type='bool'):
|
| 437 |
+
#the extension is enabled
|
| 438 |
+
if editor_only or shell_only: # TODO both True contradict
|
| 439 |
+
if editor_only:
|
| 440 |
+
option = "enable_editor"
|
| 441 |
+
else:
|
| 442 |
+
option = "enable_shell"
|
| 443 |
+
if self.GetOption('extensions', extn,option,
|
| 444 |
+
default=True, type='bool',
|
| 445 |
+
warn_on_default=False):
|
| 446 |
+
activeExtns.append(extn)
|
| 447 |
+
else:
|
| 448 |
+
activeExtns.append(extn)
|
| 449 |
+
return activeExtns
|
| 450 |
+
else:
|
| 451 |
+
return extns
|
| 452 |
+
|
| 453 |
+
def RemoveKeyBindNames(self, extnNameList):
|
| 454 |
+
"Return extnNameList with keybinding section names removed."
|
| 455 |
+
return [n for n in extnNameList if not n.endswith(('_bindings', '_cfgBindings'))]
|
| 456 |
+
|
| 457 |
+
def GetExtnNameForEvent(self, virtualEvent):
|
| 458 |
+
"""Return the name of the extension binding virtualEvent, or None.
|
| 459 |
+
|
| 460 |
+
virtualEvent - string, name of the virtual event to test for,
|
| 461 |
+
without the enclosing '<< >>'
|
| 462 |
+
"""
|
| 463 |
+
extName = None
|
| 464 |
+
vEvent = '<<' + virtualEvent + '>>'
|
| 465 |
+
for extn in self.GetExtensions(active_only=0):
|
| 466 |
+
for event in self.GetExtensionKeys(extn):
|
| 467 |
+
if event == vEvent:
|
| 468 |
+
extName = extn # TODO return here?
|
| 469 |
+
return extName
|
| 470 |
+
|
| 471 |
+
def GetExtensionKeys(self, extensionName):
|
| 472 |
+
"""Return dict: {configurable extensionName event : active keybinding}.
|
| 473 |
+
|
| 474 |
+
Events come from default config extension_cfgBindings section.
|
| 475 |
+
Keybindings come from GetCurrentKeySet() active key dict,
|
| 476 |
+
where previously used bindings are disabled.
|
| 477 |
+
"""
|
| 478 |
+
keysName = extensionName + '_cfgBindings'
|
| 479 |
+
activeKeys = self.GetCurrentKeySet()
|
| 480 |
+
extKeys = {}
|
| 481 |
+
if self.defaultCfg['extensions'].has_section(keysName):
|
| 482 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
| 483 |
+
for eventName in eventNames:
|
| 484 |
+
event = '<<' + eventName + '>>'
|
| 485 |
+
binding = activeKeys[event]
|
| 486 |
+
extKeys[event] = binding
|
| 487 |
+
return extKeys
|
| 488 |
+
|
| 489 |
+
def __GetRawExtensionKeys(self,extensionName):
|
| 490 |
+
"""Return dict {configurable extensionName event : keybinding list}.
|
| 491 |
+
|
| 492 |
+
Events come from default config extension_cfgBindings section.
|
| 493 |
+
Keybindings list come from the splitting of GetOption, which
|
| 494 |
+
tries user config before default config.
|
| 495 |
+
"""
|
| 496 |
+
keysName = extensionName+'_cfgBindings'
|
| 497 |
+
extKeys = {}
|
| 498 |
+
if self.defaultCfg['extensions'].has_section(keysName):
|
| 499 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
| 500 |
+
for eventName in eventNames:
|
| 501 |
+
binding = self.GetOption(
|
| 502 |
+
'extensions', keysName, eventName, default='').split()
|
| 503 |
+
event = '<<' + eventName + '>>'
|
| 504 |
+
extKeys[event] = binding
|
| 505 |
+
return extKeys
|
| 506 |
+
|
| 507 |
+
def GetExtensionBindings(self, extensionName):
|
| 508 |
+
"""Return dict {extensionName event : active or defined keybinding}.
|
| 509 |
+
|
| 510 |
+
Augment self.GetExtensionKeys(extensionName) with mapping of non-
|
| 511 |
+
configurable events (from default config) to GetOption splits,
|
| 512 |
+
as in self.__GetRawExtensionKeys.
|
| 513 |
+
"""
|
| 514 |
+
bindsName = extensionName + '_bindings'
|
| 515 |
+
extBinds = self.GetExtensionKeys(extensionName)
|
| 516 |
+
#add the non-configurable bindings
|
| 517 |
+
if self.defaultCfg['extensions'].has_section(bindsName):
|
| 518 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(bindsName)
|
| 519 |
+
for eventName in eventNames:
|
| 520 |
+
binding = self.GetOption(
|
| 521 |
+
'extensions', bindsName, eventName, default='').split()
|
| 522 |
+
event = '<<' + eventName + '>>'
|
| 523 |
+
extBinds[event] = binding
|
| 524 |
+
|
| 525 |
+
return extBinds
|
| 526 |
+
|
| 527 |
+
def GetKeyBinding(self, keySetName, eventStr):
|
| 528 |
+
"""Return the keybinding list for keySetName eventStr.
|
| 529 |
+
|
| 530 |
+
keySetName - name of key binding set (config-keys section).
|
| 531 |
+
eventStr - virtual event, including brackets, as in '<<event>>'.
|
| 532 |
+
"""
|
| 533 |
+
eventName = eventStr[2:-2] #trim off the angle brackets
|
| 534 |
+
binding = self.GetOption('keys', keySetName, eventName, default='',
|
| 535 |
+
warn_on_default=False).split()
|
| 536 |
+
return binding
|
| 537 |
+
|
| 538 |
+
def GetCurrentKeySet(self):
|
| 539 |
+
"Return CurrentKeys with 'darwin' modifications."
|
| 540 |
+
result = self.GetKeySet(self.CurrentKeys())
|
| 541 |
+
|
| 542 |
+
if sys.platform == "darwin":
|
| 543 |
+
# macOS (OS X) Tk variants do not support the "Alt"
|
| 544 |
+
# keyboard modifier. Replace it with "Option".
|
| 545 |
+
# TODO (Ned?): the "Option" modifier does not work properly
|
| 546 |
+
# for Cocoa Tk and XQuartz Tk so we should not use it
|
| 547 |
+
# in the default 'OSX' keyset.
|
| 548 |
+
for k, v in result.items():
|
| 549 |
+
v2 = [ x.replace('<Alt-', '<Option-') for x in v ]
|
| 550 |
+
if v != v2:
|
| 551 |
+
result[k] = v2
|
| 552 |
+
|
| 553 |
+
return result
|
| 554 |
+
|
| 555 |
+
def GetKeySet(self, keySetName):
|
| 556 |
+
"""Return event-key dict for keySetName core plus active extensions.
|
| 557 |
+
|
| 558 |
+
If a binding defined in an extension is already in use, the
|
| 559 |
+
extension binding is disabled by being set to ''
|
| 560 |
+
"""
|
| 561 |
+
keySet = self.GetCoreKeys(keySetName)
|
| 562 |
+
activeExtns = self.GetExtensions(active_only=1)
|
| 563 |
+
for extn in activeExtns:
|
| 564 |
+
extKeys = self.__GetRawExtensionKeys(extn)
|
| 565 |
+
if extKeys: #the extension defines keybindings
|
| 566 |
+
for event in extKeys:
|
| 567 |
+
if extKeys[event] in keySet.values():
|
| 568 |
+
#the binding is already in use
|
| 569 |
+
extKeys[event] = '' #disable this binding
|
| 570 |
+
keySet[event] = extKeys[event] #add binding
|
| 571 |
+
return keySet
|
| 572 |
+
|
| 573 |
+
def IsCoreBinding(self, virtualEvent):
|
| 574 |
+
"""Return True if the virtual event is one of the core idle key events.
|
| 575 |
+
|
| 576 |
+
virtualEvent - string, name of the virtual event to test for,
|
| 577 |
+
without the enclosing '<< >>'
|
| 578 |
+
"""
|
| 579 |
+
return ('<<'+virtualEvent+'>>') in self.GetCoreKeys()
|
| 580 |
+
|
| 581 |
+
# TODO make keyBindings a file or class attribute used for test above
|
| 582 |
+
# and copied in function below.
|
| 583 |
+
|
| 584 |
+
former_extension_events = { # Those with user-configurable keys.
|
| 585 |
+
'<<force-open-completions>>', '<<expand-word>>',
|
| 586 |
+
'<<force-open-calltip>>', '<<flash-paren>>', '<<format-paragraph>>',
|
| 587 |
+
'<<run-module>>', '<<check-module>>', '<<zoom-height>>',
|
| 588 |
+
'<<run-custom>>',
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
def GetCoreKeys(self, keySetName=None):
|
| 592 |
+
"""Return dict of core virtual-key keybindings for keySetName.
|
| 593 |
+
|
| 594 |
+
The default keySetName None corresponds to the keyBindings base
|
| 595 |
+
dict. If keySetName is not None, bindings from the config
|
| 596 |
+
file(s) are loaded _over_ these defaults, so if there is a
|
| 597 |
+
problem getting any core binding there will be an 'ultimate last
|
| 598 |
+
resort fallback' to the CUA-ish bindings defined here.
|
| 599 |
+
"""
|
| 600 |
+
keyBindings={
|
| 601 |
+
'<<copy>>': ['<Control-c>', '<Control-C>'],
|
| 602 |
+
'<<cut>>': ['<Control-x>', '<Control-X>'],
|
| 603 |
+
'<<paste>>': ['<Control-v>', '<Control-V>'],
|
| 604 |
+
'<<beginning-of-line>>': ['<Control-a>', '<Home>'],
|
| 605 |
+
'<<center-insert>>': ['<Control-l>'],
|
| 606 |
+
'<<close-all-windows>>': ['<Control-q>'],
|
| 607 |
+
'<<close-window>>': ['<Alt-F4>'],
|
| 608 |
+
'<<do-nothing>>': ['<Control-x>'],
|
| 609 |
+
'<<end-of-file>>': ['<Control-d>'],
|
| 610 |
+
'<<python-docs>>': ['<F1>'],
|
| 611 |
+
'<<python-context-help>>': ['<Shift-F1>'],
|
| 612 |
+
'<<history-next>>': ['<Alt-n>'],
|
| 613 |
+
'<<history-previous>>': ['<Alt-p>'],
|
| 614 |
+
'<<interrupt-execution>>': ['<Control-c>'],
|
| 615 |
+
'<<view-restart>>': ['<F6>'],
|
| 616 |
+
'<<restart-shell>>': ['<Control-F6>'],
|
| 617 |
+
'<<open-class-browser>>': ['<Alt-c>'],
|
| 618 |
+
'<<open-module>>': ['<Alt-m>'],
|
| 619 |
+
'<<open-new-window>>': ['<Control-n>'],
|
| 620 |
+
'<<open-window-from-file>>': ['<Control-o>'],
|
| 621 |
+
'<<plain-newline-and-indent>>': ['<Control-j>'],
|
| 622 |
+
'<<print-window>>': ['<Control-p>'],
|
| 623 |
+
'<<redo>>': ['<Control-y>'],
|
| 624 |
+
'<<remove-selection>>': ['<Escape>'],
|
| 625 |
+
'<<save-copy-of-window-as-file>>': ['<Alt-Shift-S>'],
|
| 626 |
+
'<<save-window-as-file>>': ['<Alt-s>'],
|
| 627 |
+
'<<save-window>>': ['<Control-s>'],
|
| 628 |
+
'<<select-all>>': ['<Alt-a>'],
|
| 629 |
+
'<<toggle-auto-coloring>>': ['<Control-slash>'],
|
| 630 |
+
'<<undo>>': ['<Control-z>'],
|
| 631 |
+
'<<find-again>>': ['<Control-g>', '<F3>'],
|
| 632 |
+
'<<find-in-files>>': ['<Alt-F3>'],
|
| 633 |
+
'<<find-selection>>': ['<Control-F3>'],
|
| 634 |
+
'<<find>>': ['<Control-f>'],
|
| 635 |
+
'<<replace>>': ['<Control-h>'],
|
| 636 |
+
'<<goto-line>>': ['<Alt-g>'],
|
| 637 |
+
'<<smart-backspace>>': ['<Key-BackSpace>'],
|
| 638 |
+
'<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'],
|
| 639 |
+
'<<smart-indent>>': ['<Key-Tab>'],
|
| 640 |
+
'<<indent-region>>': ['<Control-Key-bracketright>'],
|
| 641 |
+
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
|
| 642 |
+
'<<comment-region>>': ['<Alt-Key-3>'],
|
| 643 |
+
'<<uncomment-region>>': ['<Alt-Key-4>'],
|
| 644 |
+
'<<tabify-region>>': ['<Alt-Key-5>'],
|
| 645 |
+
'<<untabify-region>>': ['<Alt-Key-6>'],
|
| 646 |
+
'<<toggle-tabs>>': ['<Alt-Key-t>'],
|
| 647 |
+
'<<change-indentwidth>>': ['<Alt-Key-u>'],
|
| 648 |
+
'<<del-word-left>>': ['<Control-Key-BackSpace>'],
|
| 649 |
+
'<<del-word-right>>': ['<Control-Key-Delete>'],
|
| 650 |
+
'<<force-open-completions>>': ['<Control-Key-space>'],
|
| 651 |
+
'<<expand-word>>': ['<Alt-Key-slash>'],
|
| 652 |
+
'<<force-open-calltip>>': ['<Control-Key-backslash>'],
|
| 653 |
+
'<<flash-paren>>': ['<Control-Key-0>'],
|
| 654 |
+
'<<format-paragraph>>': ['<Alt-Key-q>'],
|
| 655 |
+
'<<run-module>>': ['<Key-F5>'],
|
| 656 |
+
'<<run-custom>>': ['<Shift-Key-F5>'],
|
| 657 |
+
'<<check-module>>': ['<Alt-Key-x>'],
|
| 658 |
+
'<<zoom-height>>': ['<Alt-Key-2>'],
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
if keySetName:
|
| 662 |
+
if not (self.userCfg['keys'].has_section(keySetName) or
|
| 663 |
+
self.defaultCfg['keys'].has_section(keySetName)):
|
| 664 |
+
warning = (
|
| 665 |
+
'\n Warning: config.py - IdleConf.GetCoreKeys -\n'
|
| 666 |
+
' key set %r is not defined, using default bindings.' %
|
| 667 |
+
(keySetName,)
|
| 668 |
+
)
|
| 669 |
+
_warn(warning, 'keys', keySetName)
|
| 670 |
+
else:
|
| 671 |
+
for event in keyBindings:
|
| 672 |
+
binding = self.GetKeyBinding(keySetName, event)
|
| 673 |
+
if binding:
|
| 674 |
+
keyBindings[event] = binding
|
| 675 |
+
# Otherwise return default in keyBindings.
|
| 676 |
+
elif event not in self.former_extension_events:
|
| 677 |
+
warning = (
|
| 678 |
+
'\n Warning: config.py - IdleConf.GetCoreKeys -\n'
|
| 679 |
+
' problem retrieving key binding for event %r\n'
|
| 680 |
+
' from key set %r.\n'
|
| 681 |
+
' returning default value: %r' %
|
| 682 |
+
(event, keySetName, keyBindings[event])
|
| 683 |
+
)
|
| 684 |
+
_warn(warning, 'keys', keySetName, event)
|
| 685 |
+
return keyBindings
|
| 686 |
+
|
| 687 |
+
def GetExtraHelpSourceList(self, configSet):
|
| 688 |
+
"""Return list of extra help sources from a given configSet.
|
| 689 |
+
|
| 690 |
+
Valid configSets are 'user' or 'default'. Return a list of tuples of
|
| 691 |
+
the form (menu_item , path_to_help_file , option), or return the empty
|
| 692 |
+
list. 'option' is the sequence number of the help resource. 'option'
|
| 693 |
+
values determine the position of the menu items on the Help menu,
|
| 694 |
+
therefore the returned list must be sorted by 'option'.
|
| 695 |
+
|
| 696 |
+
"""
|
| 697 |
+
helpSources = []
|
| 698 |
+
if configSet == 'user':
|
| 699 |
+
cfgParser = self.userCfg['main']
|
| 700 |
+
elif configSet == 'default':
|
| 701 |
+
cfgParser = self.defaultCfg['main']
|
| 702 |
+
else:
|
| 703 |
+
raise InvalidConfigSet('Invalid configSet specified')
|
| 704 |
+
options=cfgParser.GetOptionList('HelpFiles')
|
| 705 |
+
for option in options:
|
| 706 |
+
value=cfgParser.Get('HelpFiles', option, default=';')
|
| 707 |
+
if value.find(';') == -1: #malformed config entry with no ';'
|
| 708 |
+
menuItem = '' #make these empty
|
| 709 |
+
helpPath = '' #so value won't be added to list
|
| 710 |
+
else: #config entry contains ';' as expected
|
| 711 |
+
value=value.split(';')
|
| 712 |
+
menuItem=value[0].strip()
|
| 713 |
+
helpPath=value[1].strip()
|
| 714 |
+
if menuItem and helpPath: #neither are empty strings
|
| 715 |
+
helpSources.append( (menuItem,helpPath,option) )
|
| 716 |
+
helpSources.sort(key=lambda x: x[2])
|
| 717 |
+
return helpSources
|
| 718 |
+
|
| 719 |
+
def GetAllExtraHelpSourcesList(self):
|
| 720 |
+
"""Return a list of the details of all additional help sources.
|
| 721 |
+
|
| 722 |
+
Tuples in the list are those of GetExtraHelpSourceList.
|
| 723 |
+
"""
|
| 724 |
+
allHelpSources = (self.GetExtraHelpSourceList('default') +
|
| 725 |
+
self.GetExtraHelpSourceList('user') )
|
| 726 |
+
return allHelpSources
|
| 727 |
+
|
| 728 |
+
def GetFont(self, root, configType, section):
|
| 729 |
+
"""Retrieve a font from configuration (font, font-size, font-bold)
|
| 730 |
+
Intercept the special value 'TkFixedFont' and substitute
|
| 731 |
+
the actual font, factoring in some tweaks if needed for
|
| 732 |
+
appearance sakes.
|
| 733 |
+
|
| 734 |
+
The 'root' parameter can normally be any valid Tkinter widget.
|
| 735 |
+
|
| 736 |
+
Return a tuple (family, size, weight) suitable for passing
|
| 737 |
+
to tkinter.Font
|
| 738 |
+
"""
|
| 739 |
+
family = self.GetOption(configType, section, 'font', default='courier')
|
| 740 |
+
size = self.GetOption(configType, section, 'font-size', type='int',
|
| 741 |
+
default='10')
|
| 742 |
+
bold = self.GetOption(configType, section, 'font-bold', default=0,
|
| 743 |
+
type='bool')
|
| 744 |
+
if (family == 'TkFixedFont'):
|
| 745 |
+
f = Font(name='TkFixedFont', exists=True, root=root)
|
| 746 |
+
actualFont = Font.actual(f)
|
| 747 |
+
family = actualFont['family']
|
| 748 |
+
size = actualFont['size']
|
| 749 |
+
if size <= 0:
|
| 750 |
+
size = 10 # if font in pixels, ignore actual size
|
| 751 |
+
bold = actualFont['weight'] == 'bold'
|
| 752 |
+
return (family, size, 'bold' if bold else 'normal')
|
| 753 |
+
|
| 754 |
+
def LoadCfgFiles(self):
|
| 755 |
+
"Load all configuration files."
|
| 756 |
+
for key in self.defaultCfg:
|
| 757 |
+
self.defaultCfg[key].Load()
|
| 758 |
+
self.userCfg[key].Load() #same keys
|
| 759 |
+
|
| 760 |
+
def SaveUserCfgFiles(self):
|
| 761 |
+
"Write all loaded user configuration files to disk."
|
| 762 |
+
for key in self.userCfg:
|
| 763 |
+
self.userCfg[key].Save()
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
idleConf = IdleConf()
|
| 767 |
+
|
| 768 |
+
_warned = set()
|
| 769 |
+
def _warn(msg, *key):
|
| 770 |
+
key = (msg,) + key
|
| 771 |
+
if key not in _warned:
|
| 772 |
+
try:
|
| 773 |
+
print(msg, file=sys.stderr)
|
| 774 |
+
except OSError:
|
| 775 |
+
pass
|
| 776 |
+
_warned.add(key)
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
class ConfigChanges(dict):
|
| 780 |
+
"""Manage a user's proposed configuration option changes.
|
| 781 |
+
|
| 782 |
+
Names used across multiple methods:
|
| 783 |
+
page -- one of the 4 top-level dicts representing a
|
| 784 |
+
.idlerc/config-x.cfg file.
|
| 785 |
+
config_type -- name of a page.
|
| 786 |
+
section -- a section within a page/file.
|
| 787 |
+
option -- name of an option within a section.
|
| 788 |
+
value -- value for the option.
|
| 789 |
+
|
| 790 |
+
Methods
|
| 791 |
+
add_option: Add option and value to changes.
|
| 792 |
+
save_option: Save option and value to config parser.
|
| 793 |
+
save_all: Save all the changes to the config parser and file.
|
| 794 |
+
delete_section: If section exists,
|
| 795 |
+
delete from changes, userCfg, and file.
|
| 796 |
+
clear: Clear all changes by clearing each page.
|
| 797 |
+
"""
|
| 798 |
+
def __init__(self):
|
| 799 |
+
"Create a page for each configuration file"
|
| 800 |
+
self.pages = [] # List of unhashable dicts.
|
| 801 |
+
for config_type in idleConf.config_types:
|
| 802 |
+
self[config_type] = {}
|
| 803 |
+
self.pages.append(self[config_type])
|
| 804 |
+
|
| 805 |
+
def add_option(self, config_type, section, item, value):
|
| 806 |
+
"Add item/value pair for config_type and section."
|
| 807 |
+
page = self[config_type]
|
| 808 |
+
value = str(value) # Make sure we use a string.
|
| 809 |
+
if section not in page:
|
| 810 |
+
page[section] = {}
|
| 811 |
+
page[section][item] = value
|
| 812 |
+
|
| 813 |
+
@staticmethod
|
| 814 |
+
def save_option(config_type, section, item, value):
|
| 815 |
+
"""Return True if the configuration value was added or changed.
|
| 816 |
+
|
| 817 |
+
Helper for save_all.
|
| 818 |
+
"""
|
| 819 |
+
if idleConf.defaultCfg[config_type].has_option(section, item):
|
| 820 |
+
if idleConf.defaultCfg[config_type].Get(section, item) == value:
|
| 821 |
+
# The setting equals a default setting, remove it from user cfg.
|
| 822 |
+
return idleConf.userCfg[config_type].RemoveOption(section, item)
|
| 823 |
+
# If we got here, set the option.
|
| 824 |
+
return idleConf.userCfg[config_type].SetOption(section, item, value)
|
| 825 |
+
|
| 826 |
+
def save_all(self):
|
| 827 |
+
"""Save configuration changes to the user config file.
|
| 828 |
+
|
| 829 |
+
Clear self in preparation for additional changes.
|
| 830 |
+
Return changed for testing.
|
| 831 |
+
"""
|
| 832 |
+
idleConf.userCfg['main'].Save()
|
| 833 |
+
|
| 834 |
+
changed = False
|
| 835 |
+
for config_type in self:
|
| 836 |
+
cfg_type_changed = False
|
| 837 |
+
page = self[config_type]
|
| 838 |
+
for section in page:
|
| 839 |
+
if section == 'HelpFiles': # Remove it for replacement.
|
| 840 |
+
idleConf.userCfg['main'].remove_section('HelpFiles')
|
| 841 |
+
cfg_type_changed = True
|
| 842 |
+
for item, value in page[section].items():
|
| 843 |
+
if self.save_option(config_type, section, item, value):
|
| 844 |
+
cfg_type_changed = True
|
| 845 |
+
if cfg_type_changed:
|
| 846 |
+
idleConf.userCfg[config_type].Save()
|
| 847 |
+
changed = True
|
| 848 |
+
for config_type in ['keys', 'highlight']:
|
| 849 |
+
# Save these even if unchanged!
|
| 850 |
+
idleConf.userCfg[config_type].Save()
|
| 851 |
+
self.clear()
|
| 852 |
+
# ConfigDialog caller must add the following call
|
| 853 |
+
# self.save_all_changed_extensions() # Uses a different mechanism.
|
| 854 |
+
return changed
|
| 855 |
+
|
| 856 |
+
def delete_section(self, config_type, section):
|
| 857 |
+
"""Delete a section from self, userCfg, and file.
|
| 858 |
+
|
| 859 |
+
Used to delete custom themes and keysets.
|
| 860 |
+
"""
|
| 861 |
+
if section in self[config_type]:
|
| 862 |
+
del self[config_type][section]
|
| 863 |
+
configpage = idleConf.userCfg[config_type]
|
| 864 |
+
configpage.remove_section(section)
|
| 865 |
+
configpage.Save()
|
| 866 |
+
|
| 867 |
+
def clear(self):
|
| 868 |
+
"""Clear all 4 pages.
|
| 869 |
+
|
| 870 |
+
Called in save_all after saving to idleConf.
|
| 871 |
+
XXX Mark window *title* when there are changes; unmark here.
|
| 872 |
+
"""
|
| 873 |
+
for page in self.pages:
|
| 874 |
+
page.clear()
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
# TODO Revise test output, write expanded unittest
|
| 878 |
+
def _dump(): # htest # (not really, but ignore in coverage)
|
| 879 |
+
from zlib import crc32
|
| 880 |
+
line, crc = 0, 0
|
| 881 |
+
|
| 882 |
+
def sprint(obj):
|
| 883 |
+
global line, crc
|
| 884 |
+
txt = str(obj)
|
| 885 |
+
line += 1
|
| 886 |
+
crc = crc32(txt.encode(encoding='utf-8'), crc)
|
| 887 |
+
print(txt)
|
| 888 |
+
#print('***', line, crc, '***') # Uncomment for diagnosis.
|
| 889 |
+
|
| 890 |
+
def dumpCfg(cfg):
|
| 891 |
+
print('\n', cfg, '\n') # Cfg has variable '0xnnnnnnnn' address.
|
| 892 |
+
for key in sorted(cfg.keys()):
|
| 893 |
+
sections = cfg[key].sections()
|
| 894 |
+
sprint(key)
|
| 895 |
+
sprint(sections)
|
| 896 |
+
for section in sections:
|
| 897 |
+
options = cfg[key].options(section)
|
| 898 |
+
sprint(section)
|
| 899 |
+
sprint(options)
|
| 900 |
+
for option in options:
|
| 901 |
+
sprint(option + ' = ' + cfg[key].Get(section, option))
|
| 902 |
+
|
| 903 |
+
dumpCfg(idleConf.defaultCfg)
|
| 904 |
+
dumpCfg(idleConf.userCfg)
|
| 905 |
+
print('\nlines = ', line, ', crc = ', crc, sep='')
|
| 906 |
+
|
| 907 |
+
if __name__ == '__main__':
|
| 908 |
+
from unittest import main
|
| 909 |
+
main('idlelib.idle_test.test_config', verbosity=2, exit=False)
|
| 910 |
+
|
| 911 |
+
# Run revised _dump() as htest?
|
llava/lib/python3.10/idlelib/config_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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)
|
llava/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)
|
| 549 |
+
|
| 550 |
+
# TODO: htest?
|
llava/lib/python3.10/idlelib/debugger_r.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 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)
|
llava/lib/python3.10/idlelib/debug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
# XXX TO DO:
|
| 10 |
+
# - for classes/modules, add "open source" to object browser
|
| 11 |
+
from reprlib import Repr
|
| 12 |
+
|
| 13 |
+
from idlelib.tree import TreeItem, TreeNode, ScrolledCanvas
|
| 14 |
+
|
| 15 |
+
myrepr = Repr()
|
| 16 |
+
myrepr.maxstring = 100
|
| 17 |
+
myrepr.maxother = 100
|
| 18 |
+
|
| 19 |
+
class ObjectTreeItem(TreeItem):
|
| 20 |
+
def __init__(self, labeltext, object, setfunction=None):
|
| 21 |
+
self.labeltext = labeltext
|
| 22 |
+
self.object = object
|
| 23 |
+
self.setfunction = setfunction
|
| 24 |
+
def GetLabelText(self):
|
| 25 |
+
return self.labeltext
|
| 26 |
+
def GetText(self):
|
| 27 |
+
return myrepr.repr(self.object)
|
| 28 |
+
def GetIconName(self):
|
| 29 |
+
if not self.IsExpandable():
|
| 30 |
+
return "python"
|
| 31 |
+
def IsEditable(self):
|
| 32 |
+
return self.setfunction is not None
|
| 33 |
+
def SetText(self, text):
|
| 34 |
+
try:
|
| 35 |
+
value = eval(text)
|
| 36 |
+
self.setfunction(value)
|
| 37 |
+
except:
|
| 38 |
+
pass
|
| 39 |
+
else:
|
| 40 |
+
self.object = value
|
| 41 |
+
def IsExpandable(self):
|
| 42 |
+
return not not dir(self.object)
|
| 43 |
+
def GetSubList(self):
|
| 44 |
+
keys = dir(self.object)
|
| 45 |
+
sublist = []
|
| 46 |
+
for key in keys:
|
| 47 |
+
try:
|
| 48 |
+
value = getattr(self.object, key)
|
| 49 |
+
except AttributeError:
|
| 50 |
+
continue
|
| 51 |
+
item = make_objecttreeitem(
|
| 52 |
+
str(key) + " =",
|
| 53 |
+
value,
|
| 54 |
+
lambda value, key=key, object=self.object:
|
| 55 |
+
setattr(object, key, value))
|
| 56 |
+
sublist.append(item)
|
| 57 |
+
return sublist
|
| 58 |
+
|
| 59 |
+
class ClassTreeItem(ObjectTreeItem):
|
| 60 |
+
def IsExpandable(self):
|
| 61 |
+
return True
|
| 62 |
+
def GetSubList(self):
|
| 63 |
+
sublist = ObjectTreeItem.GetSubList(self)
|
| 64 |
+
if len(self.object.__bases__) == 1:
|
| 65 |
+
item = make_objecttreeitem("__bases__[0] =",
|
| 66 |
+
self.object.__bases__[0])
|
| 67 |
+
else:
|
| 68 |
+
item = make_objecttreeitem("__bases__ =", self.object.__bases__)
|
| 69 |
+
sublist.insert(0, item)
|
| 70 |
+
return sublist
|
| 71 |
+
|
| 72 |
+
class AtomicObjectTreeItem(ObjectTreeItem):
|
| 73 |
+
def IsExpandable(self):
|
| 74 |
+
return False
|
| 75 |
+
|
| 76 |
+
class SequenceTreeItem(ObjectTreeItem):
|
| 77 |
+
def IsExpandable(self):
|
| 78 |
+
return len(self.object) > 0
|
| 79 |
+
def keys(self):
|
| 80 |
+
return range(len(self.object))
|
| 81 |
+
def GetSubList(self):
|
| 82 |
+
sublist = []
|
| 83 |
+
for key in self.keys():
|
| 84 |
+
try:
|
| 85 |
+
value = self.object[key]
|
| 86 |
+
except KeyError:
|
| 87 |
+
continue
|
| 88 |
+
def setfunction(value, key=key, object=self.object):
|
| 89 |
+
object[key] = value
|
| 90 |
+
item = make_objecttreeitem("%r:" % (key,), value, setfunction)
|
| 91 |
+
sublist.append(item)
|
| 92 |
+
return sublist
|
| 93 |
+
|
| 94 |
+
class DictTreeItem(SequenceTreeItem):
|
| 95 |
+
def keys(self):
|
| 96 |
+
keys = list(self.object.keys())
|
| 97 |
+
try:
|
| 98 |
+
keys.sort()
|
| 99 |
+
except:
|
| 100 |
+
pass
|
| 101 |
+
return keys
|
| 102 |
+
|
| 103 |
+
dispatch = {
|
| 104 |
+
int: AtomicObjectTreeItem,
|
| 105 |
+
float: AtomicObjectTreeItem,
|
| 106 |
+
str: AtomicObjectTreeItem,
|
| 107 |
+
tuple: SequenceTreeItem,
|
| 108 |
+
list: SequenceTreeItem,
|
| 109 |
+
dict: DictTreeItem,
|
| 110 |
+
type: ClassTreeItem,
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
def make_objecttreeitem(labeltext, object, setfunction=None):
|
| 114 |
+
t = type(object)
|
| 115 |
+
if t in dispatch:
|
| 116 |
+
c = dispatch[t]
|
| 117 |
+
else:
|
| 118 |
+
c = ObjectTreeItem
|
| 119 |
+
return c(labeltext, object, setfunction)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def _object_browser(parent): # htest #
|
| 123 |
+
import sys
|
| 124 |
+
from tkinter import Toplevel
|
| 125 |
+
top = Toplevel(parent)
|
| 126 |
+
top.title("Test debug object browser")
|
| 127 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 128 |
+
top.geometry("+%d+%d" % (x + 100, y + 175))
|
| 129 |
+
top.configure(bd=0, bg="yellow")
|
| 130 |
+
top.focus_set()
|
| 131 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
| 132 |
+
sc.frame.pack(expand=1, fill="both")
|
| 133 |
+
item = make_objecttreeitem("sys", sys)
|
| 134 |
+
node = TreeNode(sc.canvas, None, item)
|
| 135 |
+
node.update()
|
| 136 |
+
|
| 137 |
+
if __name__ == '__main__':
|
| 138 |
+
from unittest import main
|
| 139 |
+
main('idlelib.idle_test.test_debugobj', verbosity=2, exit=False)
|
| 140 |
+
|
| 141 |
+
from idlelib.idle_test.htest import run
|
| 142 |
+
run(_object_browser)
|
llava/lib/python3.10/idlelib/debugobj_r.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from idlelib import rpc
|
| 2 |
+
|
| 3 |
+
def remote_object_tree_item(item):
|
| 4 |
+
wrapper = WrappedObjectTreeItem(item)
|
| 5 |
+
oid = id(wrapper)
|
| 6 |
+
rpc.objecttable[oid] = wrapper
|
| 7 |
+
return oid
|
| 8 |
+
|
| 9 |
+
class WrappedObjectTreeItem:
|
| 10 |
+
# Lives in PYTHON subprocess
|
| 11 |
+
|
| 12 |
+
def __init__(self, item):
|
| 13 |
+
self.__item = item
|
| 14 |
+
|
| 15 |
+
def __getattr__(self, name):
|
| 16 |
+
value = getattr(self.__item, name)
|
| 17 |
+
return value
|
| 18 |
+
|
| 19 |
+
def _GetSubList(self):
|
| 20 |
+
sub_list = self.__item._GetSubList()
|
| 21 |
+
return list(map(remote_object_tree_item, sub_list))
|
| 22 |
+
|
| 23 |
+
class StubObjectTreeItem:
|
| 24 |
+
# Lives in IDLE process
|
| 25 |
+
|
| 26 |
+
def __init__(self, sockio, oid):
|
| 27 |
+
self.sockio = sockio
|
| 28 |
+
self.oid = oid
|
| 29 |
+
|
| 30 |
+
def __getattr__(self, name):
|
| 31 |
+
value = rpc.MethodProxy(self.sockio, self.oid, name)
|
| 32 |
+
return value
|
| 33 |
+
|
| 34 |
+
def _GetSubList(self):
|
| 35 |
+
sub_list = self.sockio.remotecall(self.oid, "_GetSubList", (), {})
|
| 36 |
+
return [StubObjectTreeItem(self.sockio, oid) for oid in sub_list]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
from unittest import main
|
| 41 |
+
main('idlelib.idle_test.test_debugobj_r', verbosity=2)
|
llava/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)
|
llava/lib/python3.10/idlelib/extend.txt
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Writing an IDLE extension
|
| 2 |
+
=========================
|
| 3 |
+
|
| 4 |
+
An IDLE extension can define new key bindings and menu entries for IDLE
|
| 5 |
+
edit windows. There is a simple mechanism to load extensions when IDLE
|
| 6 |
+
starts up and to attach them to each edit window. (It is also possible
|
| 7 |
+
to make other changes to IDLE, but this must be done by editing the IDLE
|
| 8 |
+
source code.)
|
| 9 |
+
|
| 10 |
+
The list of extensions loaded at startup time is configured by editing
|
| 11 |
+
the file config-extensions.def. See below for details.
|
| 12 |
+
|
| 13 |
+
An IDLE extension is defined by a class. Methods of the class define
|
| 14 |
+
actions that are invoked by event bindings or menu entries. Class (or
|
| 15 |
+
instance) variables define the bindings and menu additions; these are
|
| 16 |
+
automatically applied by IDLE when the extension is linked to an edit
|
| 17 |
+
window.
|
| 18 |
+
|
| 19 |
+
An IDLE extension class is instantiated with a single argument,
|
| 20 |
+
`editwin', an EditorWindow instance. The extension cannot assume much
|
| 21 |
+
about this argument, but it is guaranteed to have the following instance
|
| 22 |
+
variables:
|
| 23 |
+
|
| 24 |
+
text a Text instance (a widget)
|
| 25 |
+
io an IOBinding instance (more about this later)
|
| 26 |
+
flist the FileList instance (shared by all edit windows)
|
| 27 |
+
|
| 28 |
+
(There are a few more, but they are rarely useful.)
|
| 29 |
+
|
| 30 |
+
The extension class must not directly bind Window Manager (e.g. X) events.
|
| 31 |
+
Rather, it must define one or more virtual events, e.g. <<z-in>>, and
|
| 32 |
+
corresponding methods, e.g. z_in_event(). The virtual events will be
|
| 33 |
+
bound to the corresponding methods, and Window Manager events can then be bound
|
| 34 |
+
to the virtual events. (This indirection is done so that the key bindings can
|
| 35 |
+
easily be changed, and so that other sources of virtual events can exist, such
|
| 36 |
+
as menu entries.)
|
| 37 |
+
|
| 38 |
+
An extension can define menu entries. This is done with a class or instance
|
| 39 |
+
variable named menudefs; it should be a list of pairs, where each pair is a
|
| 40 |
+
menu name (lowercase) and a list of menu entries. Each menu entry is either
|
| 41 |
+
None (to insert a separator entry) or a pair of strings (menu_label,
|
| 42 |
+
virtual_event). Here, menu_label is the label of the menu entry, and
|
| 43 |
+
virtual_event is the virtual event to be generated when the entry is selected.
|
| 44 |
+
An underscore in the menu label is removed; the character following the
|
| 45 |
+
underscore is displayed underlined, to indicate the shortcut character (for
|
| 46 |
+
Windows).
|
| 47 |
+
|
| 48 |
+
At the moment, extensions cannot define whole new menus; they must define
|
| 49 |
+
entries in existing menus. Some menus are not present on some windows; such
|
| 50 |
+
entry definitions are then ignored, but key bindings are still applied. (This
|
| 51 |
+
should probably be refined in the future.)
|
| 52 |
+
|
| 53 |
+
Extensions are not required to define menu entries for all the events they
|
| 54 |
+
implement. (They are also not required to create keybindings, but in that
|
| 55 |
+
case there must be empty bindings in cofig-extensions.def)
|
| 56 |
+
|
| 57 |
+
Here is a partial example from zzdummy.py:
|
| 58 |
+
|
| 59 |
+
class ZzDummy:
|
| 60 |
+
|
| 61 |
+
menudefs = [
|
| 62 |
+
('format', [
|
| 63 |
+
('Z in', '<<z-in>>'),
|
| 64 |
+
('Z out', '<<z-out>>'),
|
| 65 |
+
] )
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
def __init__(self, editwin):
|
| 69 |
+
self.editwin = editwin
|
| 70 |
+
|
| 71 |
+
def z_in_event(self, event=None):
|
| 72 |
+
"...Do what you want here..."
|
| 73 |
+
|
| 74 |
+
The final piece of the puzzle is the file "config-extensions.def", which is
|
| 75 |
+
used to configure the loading of extensions and to establish key (or, more
|
| 76 |
+
generally, event) bindings to the virtual events defined in the extensions.
|
| 77 |
+
|
| 78 |
+
See the comments at the top of config-extensions.def for information. It's
|
| 79 |
+
currently necessary to manually modify that file to change IDLE's extension
|
| 80 |
+
loading or extension key bindings.
|
| 81 |
+
|
| 82 |
+
For further information on binding refer to the Tkinter Resources web page at
|
| 83 |
+
python.org and to the Tk Command "bind" man page.
|
llava/lib/python3.10/idlelib/filelist.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"idlelib.filelist"
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from tkinter import messagebox
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class FileList:
|
| 8 |
+
|
| 9 |
+
# N.B. this import overridden in PyShellFileList.
|
| 10 |
+
from idlelib.editor import EditorWindow
|
| 11 |
+
|
| 12 |
+
def __init__(self, root):
|
| 13 |
+
self.root = root
|
| 14 |
+
self.dict = {}
|
| 15 |
+
self.inversedict = {}
|
| 16 |
+
self.vars = {} # For EditorWindow.getrawvar (shared Tcl variables)
|
| 17 |
+
|
| 18 |
+
def open(self, filename, action=None):
|
| 19 |
+
assert filename
|
| 20 |
+
filename = self.canonize(filename)
|
| 21 |
+
if os.path.isdir(filename):
|
| 22 |
+
# This can happen when bad filename is passed on command line:
|
| 23 |
+
messagebox.showerror(
|
| 24 |
+
"File Error",
|
| 25 |
+
"%r is a directory." % (filename,),
|
| 26 |
+
master=self.root)
|
| 27 |
+
return None
|
| 28 |
+
key = os.path.normcase(filename)
|
| 29 |
+
if key in self.dict:
|
| 30 |
+
edit = self.dict[key]
|
| 31 |
+
edit.top.wakeup()
|
| 32 |
+
return edit
|
| 33 |
+
if action:
|
| 34 |
+
# Don't create window, perform 'action', e.g. open in same window
|
| 35 |
+
return action(filename)
|
| 36 |
+
else:
|
| 37 |
+
edit = self.EditorWindow(self, filename, key)
|
| 38 |
+
if edit.good_load:
|
| 39 |
+
return edit
|
| 40 |
+
else:
|
| 41 |
+
edit._close()
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
def gotofileline(self, filename, lineno=None):
|
| 45 |
+
edit = self.open(filename)
|
| 46 |
+
if edit is not None and lineno is not None:
|
| 47 |
+
edit.gotoline(lineno)
|
| 48 |
+
|
| 49 |
+
def new(self, filename=None):
|
| 50 |
+
return self.EditorWindow(self, filename)
|
| 51 |
+
|
| 52 |
+
def close_all_callback(self, *args, **kwds):
|
| 53 |
+
for edit in list(self.inversedict):
|
| 54 |
+
reply = edit.close()
|
| 55 |
+
if reply == "cancel":
|
| 56 |
+
break
|
| 57 |
+
return "break"
|
| 58 |
+
|
| 59 |
+
def unregister_maybe_terminate(self, edit):
|
| 60 |
+
try:
|
| 61 |
+
key = self.inversedict[edit]
|
| 62 |
+
except KeyError:
|
| 63 |
+
print("Don't know this EditorWindow object. (close)")
|
| 64 |
+
return
|
| 65 |
+
if key:
|
| 66 |
+
del self.dict[key]
|
| 67 |
+
del self.inversedict[edit]
|
| 68 |
+
if not self.inversedict:
|
| 69 |
+
self.root.quit()
|
| 70 |
+
|
| 71 |
+
def filename_changed_edit(self, edit):
|
| 72 |
+
edit.saved_change_hook()
|
| 73 |
+
try:
|
| 74 |
+
key = self.inversedict[edit]
|
| 75 |
+
except KeyError:
|
| 76 |
+
print("Don't know this EditorWindow object. (rename)")
|
| 77 |
+
return
|
| 78 |
+
filename = edit.io.filename
|
| 79 |
+
if not filename:
|
| 80 |
+
if key:
|
| 81 |
+
del self.dict[key]
|
| 82 |
+
self.inversedict[edit] = None
|
| 83 |
+
return
|
| 84 |
+
filename = self.canonize(filename)
|
| 85 |
+
newkey = os.path.normcase(filename)
|
| 86 |
+
if newkey == key:
|
| 87 |
+
return
|
| 88 |
+
if newkey in self.dict:
|
| 89 |
+
conflict = self.dict[newkey]
|
| 90 |
+
self.inversedict[conflict] = None
|
| 91 |
+
messagebox.showerror(
|
| 92 |
+
"Name Conflict",
|
| 93 |
+
"You now have multiple edit windows open for %r" % (filename,),
|
| 94 |
+
master=self.root)
|
| 95 |
+
self.dict[newkey] = edit
|
| 96 |
+
self.inversedict[edit] = newkey
|
| 97 |
+
if key:
|
| 98 |
+
try:
|
| 99 |
+
del self.dict[key]
|
| 100 |
+
except KeyError:
|
| 101 |
+
pass
|
| 102 |
+
|
| 103 |
+
def canonize(self, filename):
|
| 104 |
+
if not os.path.isabs(filename):
|
| 105 |
+
try:
|
| 106 |
+
pwd = os.getcwd()
|
| 107 |
+
except OSError:
|
| 108 |
+
pass
|
| 109 |
+
else:
|
| 110 |
+
filename = os.path.join(pwd, filename)
|
| 111 |
+
return os.path.normpath(filename)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _test(): # TODO check and convert to htest
|
| 115 |
+
from tkinter import Tk
|
| 116 |
+
from idlelib.editor import fixwordbreaks
|
| 117 |
+
from idlelib.run import fix_scaling
|
| 118 |
+
root = Tk()
|
| 119 |
+
fix_scaling(root)
|
| 120 |
+
fixwordbreaks(root)
|
| 121 |
+
root.withdraw()
|
| 122 |
+
flist = FileList(root)
|
| 123 |
+
flist.new()
|
| 124 |
+
if flist.inversedict:
|
| 125 |
+
root.mainloop()
|
| 126 |
+
|
| 127 |
+
if __name__ == '__main__':
|
| 128 |
+
from unittest import main
|
| 129 |
+
main('idlelib.idle_test.test_filelist', verbosity=2)
|
| 130 |
+
|
| 131 |
+
# _test()
|
llava/lib/python3.10/idlelib/grep.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Grep dialog for Find in Files functionality.
|
| 2 |
+
|
| 3 |
+
Inherits from SearchDialogBase for GUI and uses searchengine
|
| 4 |
+
to prepare search pattern.
|
| 5 |
+
"""
|
| 6 |
+
import fnmatch
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
from tkinter import StringVar, BooleanVar
|
| 11 |
+
from tkinter.ttk import Checkbutton # Frame imported in ...Base
|
| 12 |
+
|
| 13 |
+
from idlelib.searchbase import SearchDialogBase
|
| 14 |
+
from idlelib import searchengine
|
| 15 |
+
|
| 16 |
+
# Importing OutputWindow here fails due to import loop
|
| 17 |
+
# EditorWindow -> GrepDialog -> OutputWindow -> EditorWindow
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def grep(text, io=None, flist=None):
|
| 21 |
+
"""Open the Find in Files dialog.
|
| 22 |
+
|
| 23 |
+
Module-level function to access the singleton GrepDialog
|
| 24 |
+
instance and open the dialog. If text is selected, it is
|
| 25 |
+
used as the search phrase; otherwise, the previous entry
|
| 26 |
+
is used.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
text: Text widget that contains the selected text for
|
| 30 |
+
default search phrase.
|
| 31 |
+
io: iomenu.IOBinding instance with default path to search.
|
| 32 |
+
flist: filelist.FileList instance for OutputWindow parent.
|
| 33 |
+
"""
|
| 34 |
+
root = text._root()
|
| 35 |
+
engine = searchengine.get(root)
|
| 36 |
+
if not hasattr(engine, "_grepdialog"):
|
| 37 |
+
engine._grepdialog = GrepDialog(root, engine, flist)
|
| 38 |
+
dialog = engine._grepdialog
|
| 39 |
+
searchphrase = text.get("sel.first", "sel.last")
|
| 40 |
+
dialog.open(text, searchphrase, io)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def walk_error(msg):
|
| 44 |
+
"Handle os.walk error."
|
| 45 |
+
print(msg)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def findfiles(folder, pattern, recursive):
|
| 49 |
+
"""Generate file names in dir that match pattern.
|
| 50 |
+
|
| 51 |
+
Args:
|
| 52 |
+
folder: Root directory to search.
|
| 53 |
+
pattern: File pattern to match.
|
| 54 |
+
recursive: True to include subdirectories.
|
| 55 |
+
"""
|
| 56 |
+
for dirpath, _, filenames in os.walk(folder, onerror=walk_error):
|
| 57 |
+
yield from (os.path.join(dirpath, name)
|
| 58 |
+
for name in filenames
|
| 59 |
+
if fnmatch.fnmatch(name, pattern))
|
| 60 |
+
if not recursive:
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class GrepDialog(SearchDialogBase):
|
| 65 |
+
"Dialog for searching multiple files."
|
| 66 |
+
|
| 67 |
+
title = "Find in Files Dialog"
|
| 68 |
+
icon = "Grep"
|
| 69 |
+
needwrapbutton = 0
|
| 70 |
+
|
| 71 |
+
def __init__(self, root, engine, flist):
|
| 72 |
+
"""Create search dialog for searching for a phrase in the file system.
|
| 73 |
+
|
| 74 |
+
Uses SearchDialogBase as the basis for the GUI and a
|
| 75 |
+
searchengine instance to prepare the search.
|
| 76 |
+
|
| 77 |
+
Attributes:
|
| 78 |
+
flist: filelist.Filelist instance for OutputWindow parent.
|
| 79 |
+
globvar: String value of Entry widget for path to search.
|
| 80 |
+
globent: Entry widget for globvar. Created in
|
| 81 |
+
create_entries().
|
| 82 |
+
recvar: Boolean value of Checkbutton widget for
|
| 83 |
+
traversing through subdirectories.
|
| 84 |
+
"""
|
| 85 |
+
super().__init__(root, engine)
|
| 86 |
+
self.flist = flist
|
| 87 |
+
self.globvar = StringVar(root)
|
| 88 |
+
self.recvar = BooleanVar(root)
|
| 89 |
+
|
| 90 |
+
def open(self, text, searchphrase, io=None):
|
| 91 |
+
"""Make dialog visible on top of others and ready to use.
|
| 92 |
+
|
| 93 |
+
Extend the SearchDialogBase open() to set the initial value
|
| 94 |
+
for globvar.
|
| 95 |
+
|
| 96 |
+
Args:
|
| 97 |
+
text: Multicall object containing the text information.
|
| 98 |
+
searchphrase: String phrase to search.
|
| 99 |
+
io: iomenu.IOBinding instance containing file path.
|
| 100 |
+
"""
|
| 101 |
+
SearchDialogBase.open(self, text, searchphrase)
|
| 102 |
+
if io:
|
| 103 |
+
path = io.filename or ""
|
| 104 |
+
else:
|
| 105 |
+
path = ""
|
| 106 |
+
dir, base = os.path.split(path)
|
| 107 |
+
head, tail = os.path.splitext(base)
|
| 108 |
+
if not tail:
|
| 109 |
+
tail = ".py"
|
| 110 |
+
self.globvar.set(os.path.join(dir, "*" + tail))
|
| 111 |
+
|
| 112 |
+
def create_entries(self):
|
| 113 |
+
"Create base entry widgets and add widget for search path."
|
| 114 |
+
SearchDialogBase.create_entries(self)
|
| 115 |
+
self.globent = self.make_entry("In files:", self.globvar)[0]
|
| 116 |
+
|
| 117 |
+
def create_other_buttons(self):
|
| 118 |
+
"Add check button to recurse down subdirectories."
|
| 119 |
+
btn = Checkbutton(
|
| 120 |
+
self.make_frame()[0], variable=self.recvar,
|
| 121 |
+
text="Recurse down subdirectories")
|
| 122 |
+
btn.pack(side="top", fill="both")
|
| 123 |
+
|
| 124 |
+
def create_command_buttons(self):
|
| 125 |
+
"Create base command buttons and add button for Search Files."
|
| 126 |
+
SearchDialogBase.create_command_buttons(self)
|
| 127 |
+
self.make_button("Search Files", self.default_command, isdef=True)
|
| 128 |
+
|
| 129 |
+
def default_command(self, event=None):
|
| 130 |
+
"""Grep for search pattern in file path. The default command is bound
|
| 131 |
+
to <Return>.
|
| 132 |
+
|
| 133 |
+
If entry values are populated, set OutputWindow as stdout
|
| 134 |
+
and perform search. The search dialog is closed automatically
|
| 135 |
+
when the search begins.
|
| 136 |
+
"""
|
| 137 |
+
prog = self.engine.getprog()
|
| 138 |
+
if not prog:
|
| 139 |
+
return
|
| 140 |
+
path = self.globvar.get()
|
| 141 |
+
if not path:
|
| 142 |
+
self.top.bell()
|
| 143 |
+
return
|
| 144 |
+
from idlelib.outwin import OutputWindow # leave here!
|
| 145 |
+
save = sys.stdout
|
| 146 |
+
try:
|
| 147 |
+
sys.stdout = OutputWindow(self.flist)
|
| 148 |
+
self.grep_it(prog, path)
|
| 149 |
+
finally:
|
| 150 |
+
sys.stdout = save
|
| 151 |
+
|
| 152 |
+
def grep_it(self, prog, path):
|
| 153 |
+
"""Search for prog within the lines of the files in path.
|
| 154 |
+
|
| 155 |
+
For the each file in the path directory, open the file and
|
| 156 |
+
search each line for the matching pattern. If the pattern is
|
| 157 |
+
found, write the file and line information to stdout (which
|
| 158 |
+
is an OutputWindow).
|
| 159 |
+
|
| 160 |
+
Args:
|
| 161 |
+
prog: The compiled, cooked search pattern.
|
| 162 |
+
path: String containing the search path.
|
| 163 |
+
"""
|
| 164 |
+
folder, filepat = os.path.split(path)
|
| 165 |
+
if not folder:
|
| 166 |
+
folder = os.curdir
|
| 167 |
+
filelist = sorted(findfiles(folder, filepat, self.recvar.get()))
|
| 168 |
+
self.close()
|
| 169 |
+
pat = self.engine.getpat()
|
| 170 |
+
print(f"Searching {pat!r} in {path} ...")
|
| 171 |
+
hits = 0
|
| 172 |
+
try:
|
| 173 |
+
for fn in filelist:
|
| 174 |
+
try:
|
| 175 |
+
with open(fn, errors='replace') as f:
|
| 176 |
+
for lineno, line in enumerate(f, 1):
|
| 177 |
+
if line[-1:] == '\n':
|
| 178 |
+
line = line[:-1]
|
| 179 |
+
if prog.search(line):
|
| 180 |
+
sys.stdout.write(f"{fn}: {lineno}: {line}\n")
|
| 181 |
+
hits += 1
|
| 182 |
+
except OSError as msg:
|
| 183 |
+
print(msg)
|
| 184 |
+
print(f"Hits found: {hits}\n(Hint: right-click to open locations.)"
|
| 185 |
+
if hits else "No hits.")
|
| 186 |
+
except AttributeError:
|
| 187 |
+
# Tk window has been closed, OutputWindow.text = None,
|
| 188 |
+
# so in OW.write, OW.text.insert fails.
|
| 189 |
+
pass
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def _grep_dialog(parent): # htest #
|
| 193 |
+
from tkinter import Toplevel, Text, SEL, END
|
| 194 |
+
from tkinter.ttk import Frame, Button
|
| 195 |
+
from idlelib.pyshell import PyShellFileList
|
| 196 |
+
|
| 197 |
+
top = Toplevel(parent)
|
| 198 |
+
top.title("Test GrepDialog")
|
| 199 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 200 |
+
top.geometry(f"+{x}+{y + 175}")
|
| 201 |
+
|
| 202 |
+
flist = PyShellFileList(top)
|
| 203 |
+
frame = Frame(top)
|
| 204 |
+
frame.pack()
|
| 205 |
+
text = Text(frame, height=5)
|
| 206 |
+
text.pack()
|
| 207 |
+
|
| 208 |
+
def show_grep_dialog():
|
| 209 |
+
text.tag_add(SEL, "1.0", END)
|
| 210 |
+
grep(text, flist=flist)
|
| 211 |
+
text.tag_remove(SEL, "1.0", END)
|
| 212 |
+
|
| 213 |
+
button = Button(frame, text="Show GrepDialog", command=show_grep_dialog)
|
| 214 |
+
button.pack()
|
| 215 |
+
|
| 216 |
+
if __name__ == "__main__":
|
| 217 |
+
from unittest import main
|
| 218 |
+
main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
|
| 219 |
+
|
| 220 |
+
from idlelib.idle_test.htest import run
|
| 221 |
+
run(_grep_dialog)
|
llava/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: idle-dev@python.org',
|
| 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_about', verbosity=2, exit=False)
|
| 210 |
+
|
| 211 |
+
from idlelib.idle_test.htest import run
|
| 212 |
+
run(AboutDialog)
|
llava/lib/python3.10/idlelib/history.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Implement Idle Shell history mechanism with History class"
|
| 2 |
+
|
| 3 |
+
from idlelib.config import idleConf
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class History:
|
| 7 |
+
''' Implement Idle Shell history mechanism.
|
| 8 |
+
|
| 9 |
+
store - Store source statement (called from pyshell.resetoutput).
|
| 10 |
+
fetch - Fetch stored statement matching prefix already entered.
|
| 11 |
+
history_next - Bound to <<history-next>> event (default Alt-N).
|
| 12 |
+
history_prev - Bound to <<history-prev>> event (default Alt-P).
|
| 13 |
+
'''
|
| 14 |
+
def __init__(self, text):
|
| 15 |
+
'''Initialize data attributes and bind event methods.
|
| 16 |
+
|
| 17 |
+
.text - Idle wrapper of tk Text widget, with .bell().
|
| 18 |
+
.history - source statements, possibly with multiple lines.
|
| 19 |
+
.prefix - source already entered at prompt; filters history list.
|
| 20 |
+
.pointer - index into history.
|
| 21 |
+
.cyclic - wrap around history list (or not).
|
| 22 |
+
'''
|
| 23 |
+
self.text = text
|
| 24 |
+
self.history = []
|
| 25 |
+
self.prefix = None
|
| 26 |
+
self.pointer = None
|
| 27 |
+
self.cyclic = idleConf.GetOption("main", "History", "cyclic", 1, "bool")
|
| 28 |
+
text.bind("<<history-previous>>", self.history_prev)
|
| 29 |
+
text.bind("<<history-next>>", self.history_next)
|
| 30 |
+
|
| 31 |
+
def history_next(self, event):
|
| 32 |
+
"Fetch later statement; start with ealiest if cyclic."
|
| 33 |
+
self.fetch(reverse=False)
|
| 34 |
+
return "break"
|
| 35 |
+
|
| 36 |
+
def history_prev(self, event):
|
| 37 |
+
"Fetch earlier statement; start with most recent."
|
| 38 |
+
self.fetch(reverse=True)
|
| 39 |
+
return "break"
|
| 40 |
+
|
| 41 |
+
def fetch(self, reverse):
|
| 42 |
+
'''Fetch statement and replace current line in text widget.
|
| 43 |
+
|
| 44 |
+
Set prefix and pointer as needed for successive fetches.
|
| 45 |
+
Reset them to None, None when returning to the start line.
|
| 46 |
+
Sound bell when return to start line or cannot leave a line
|
| 47 |
+
because cyclic is False.
|
| 48 |
+
'''
|
| 49 |
+
nhist = len(self.history)
|
| 50 |
+
pointer = self.pointer
|
| 51 |
+
prefix = self.prefix
|
| 52 |
+
if pointer is not None and prefix is not None:
|
| 53 |
+
if self.text.compare("insert", "!=", "end-1c") or \
|
| 54 |
+
self.text.get("iomark", "end-1c") != self.history[pointer]:
|
| 55 |
+
pointer = prefix = None
|
| 56 |
+
self.text.mark_set("insert", "end-1c") # != after cursor move
|
| 57 |
+
if pointer is None or prefix is None:
|
| 58 |
+
prefix = self.text.get("iomark", "end-1c")
|
| 59 |
+
if reverse:
|
| 60 |
+
pointer = nhist # will be decremented
|
| 61 |
+
else:
|
| 62 |
+
if self.cyclic:
|
| 63 |
+
pointer = -1 # will be incremented
|
| 64 |
+
else: # abort history_next
|
| 65 |
+
self.text.bell()
|
| 66 |
+
return
|
| 67 |
+
nprefix = len(prefix)
|
| 68 |
+
while True:
|
| 69 |
+
pointer += -1 if reverse else 1
|
| 70 |
+
if pointer < 0 or pointer >= nhist:
|
| 71 |
+
self.text.bell()
|
| 72 |
+
if not self.cyclic and pointer < 0: # abort history_prev
|
| 73 |
+
return
|
| 74 |
+
else:
|
| 75 |
+
if self.text.get("iomark", "end-1c") != prefix:
|
| 76 |
+
self.text.delete("iomark", "end-1c")
|
| 77 |
+
self.text.insert("iomark", prefix, "stdin")
|
| 78 |
+
pointer = prefix = None
|
| 79 |
+
break
|
| 80 |
+
item = self.history[pointer]
|
| 81 |
+
if item[:nprefix] == prefix and len(item) > nprefix:
|
| 82 |
+
self.text.delete("iomark", "end-1c")
|
| 83 |
+
self.text.insert("iomark", item, "stdin")
|
| 84 |
+
break
|
| 85 |
+
self.text.see("insert")
|
| 86 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 87 |
+
self.pointer = pointer
|
| 88 |
+
self.prefix = prefix
|
| 89 |
+
|
| 90 |
+
def store(self, source):
|
| 91 |
+
"Store Shell input statement into history list."
|
| 92 |
+
source = source.strip()
|
| 93 |
+
if len(source) > 2:
|
| 94 |
+
# avoid duplicates
|
| 95 |
+
try:
|
| 96 |
+
self.history.remove(source)
|
| 97 |
+
except ValueError:
|
| 98 |
+
pass
|
| 99 |
+
self.history.append(source)
|
| 100 |
+
self.pointer = None
|
| 101 |
+
self.prefix = None
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
from unittest import main
|
| 106 |
+
main('idlelib.idle_test.test_history', verbosity=2, exit=False)
|
llava/lib/python3.10/idlelib/hyperparser.py
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Provide advanced parsing abilities for ParenMatch and other extensions.
|
| 2 |
+
|
| 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)
|
llava/lib/python3.10/idlelib/idle.bat
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
rem Start IDLE using the appropriate Python interpreter
|
| 3 |
+
set CURRDIR=%~dp0
|
| 4 |
+
start "IDLE" "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
llava/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()
|
llava/lib/python3.10/idlelib/idle.pyw
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import idlelib.pyshell
|
| 3 |
+
except ImportError:
|
| 4 |
+
# IDLE is not installed, but maybe pyshell is on sys.path:
|
| 5 |
+
from . import pyshell
|
| 6 |
+
import os
|
| 7 |
+
idledir = os.path.dirname(os.path.abspath(pyshell.__file__))
|
| 8 |
+
if idledir != os.getcwd():
|
| 9 |
+
# We're not in the IDLE directory, help the subprocess find run.py
|
| 10 |
+
pypath = os.environ.get('PYTHONPATH', '')
|
| 11 |
+
if pypath:
|
| 12 |
+
os.environ['PYTHONPATH'] = pypath + ':' + idledir
|
| 13 |
+
else:
|
| 14 |
+
os.environ['PYTHONPATH'] = idledir
|
| 15 |
+
pyshell.main()
|
| 16 |
+
else:
|
| 17 |
+
idlelib.pyshell.main()
|
llava/lib/python3.10/idlelib/iomenu.py
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import os
|
| 3 |
+
import shlex
|
| 4 |
+
import sys
|
| 5 |
+
import tempfile
|
| 6 |
+
import tokenize
|
| 7 |
+
|
| 8 |
+
from tkinter import filedialog
|
| 9 |
+
from tkinter import messagebox
|
| 10 |
+
from tkinter.simpledialog import askstring
|
| 11 |
+
|
| 12 |
+
from idlelib.config import idleConf
|
| 13 |
+
from idlelib.util import py_extensions
|
| 14 |
+
|
| 15 |
+
py_extensions = ' '.join("*"+ext for ext in py_extensions)
|
| 16 |
+
encoding = 'utf-8'
|
| 17 |
+
errors = 'surrogatepass' if sys.platform == 'win32' else 'surrogateescape'
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class IOBinding:
|
| 21 |
+
# One instance per editor Window so methods know which to save, close.
|
| 22 |
+
# Open returns focus to self.editwin if aborted.
|
| 23 |
+
# EditorWindow.open_module, others, belong here.
|
| 24 |
+
|
| 25 |
+
def __init__(self, editwin):
|
| 26 |
+
self.editwin = editwin
|
| 27 |
+
self.text = editwin.text
|
| 28 |
+
self.__id_open = self.text.bind("<<open-window-from-file>>", self.open)
|
| 29 |
+
self.__id_save = self.text.bind("<<save-window>>", self.save)
|
| 30 |
+
self.__id_saveas = self.text.bind("<<save-window-as-file>>",
|
| 31 |
+
self.save_as)
|
| 32 |
+
self.__id_savecopy = self.text.bind("<<save-copy-of-window-as-file>>",
|
| 33 |
+
self.save_a_copy)
|
| 34 |
+
self.fileencoding = 'utf-8'
|
| 35 |
+
self.__id_print = self.text.bind("<<print-window>>", self.print_window)
|
| 36 |
+
|
| 37 |
+
def close(self):
|
| 38 |
+
# Undo command bindings
|
| 39 |
+
self.text.unbind("<<open-window-from-file>>", self.__id_open)
|
| 40 |
+
self.text.unbind("<<save-window>>", self.__id_save)
|
| 41 |
+
self.text.unbind("<<save-window-as-file>>",self.__id_saveas)
|
| 42 |
+
self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy)
|
| 43 |
+
self.text.unbind("<<print-window>>", self.__id_print)
|
| 44 |
+
# Break cycles
|
| 45 |
+
self.editwin = None
|
| 46 |
+
self.text = None
|
| 47 |
+
self.filename_change_hook = None
|
| 48 |
+
|
| 49 |
+
def get_saved(self):
|
| 50 |
+
return self.editwin.get_saved()
|
| 51 |
+
|
| 52 |
+
def set_saved(self, flag):
|
| 53 |
+
self.editwin.set_saved(flag)
|
| 54 |
+
|
| 55 |
+
def reset_undo(self):
|
| 56 |
+
self.editwin.reset_undo()
|
| 57 |
+
|
| 58 |
+
filename_change_hook = None
|
| 59 |
+
|
| 60 |
+
def set_filename_change_hook(self, hook):
|
| 61 |
+
self.filename_change_hook = hook
|
| 62 |
+
|
| 63 |
+
filename = None
|
| 64 |
+
dirname = None
|
| 65 |
+
|
| 66 |
+
def set_filename(self, filename):
|
| 67 |
+
if filename and os.path.isdir(filename):
|
| 68 |
+
self.filename = None
|
| 69 |
+
self.dirname = filename
|
| 70 |
+
else:
|
| 71 |
+
self.filename = filename
|
| 72 |
+
self.dirname = None
|
| 73 |
+
self.set_saved(1)
|
| 74 |
+
if self.filename_change_hook:
|
| 75 |
+
self.filename_change_hook()
|
| 76 |
+
|
| 77 |
+
def open(self, event=None, editFile=None):
|
| 78 |
+
flist = self.editwin.flist
|
| 79 |
+
# Save in case parent window is closed (ie, during askopenfile()).
|
| 80 |
+
if flist:
|
| 81 |
+
if not editFile:
|
| 82 |
+
filename = self.askopenfile()
|
| 83 |
+
else:
|
| 84 |
+
filename=editFile
|
| 85 |
+
if filename:
|
| 86 |
+
# If editFile is valid and already open, flist.open will
|
| 87 |
+
# shift focus to its existing window.
|
| 88 |
+
# If the current window exists and is a fresh unnamed,
|
| 89 |
+
# unmodified editor window (not an interpreter shell),
|
| 90 |
+
# pass self.loadfile to flist.open so it will load the file
|
| 91 |
+
# in the current window (if the file is not already open)
|
| 92 |
+
# instead of a new window.
|
| 93 |
+
if (self.editwin and
|
| 94 |
+
not getattr(self.editwin, 'interp', None) and
|
| 95 |
+
not self.filename and
|
| 96 |
+
self.get_saved()):
|
| 97 |
+
flist.open(filename, self.loadfile)
|
| 98 |
+
else:
|
| 99 |
+
flist.open(filename)
|
| 100 |
+
else:
|
| 101 |
+
if self.text:
|
| 102 |
+
self.text.focus_set()
|
| 103 |
+
return "break"
|
| 104 |
+
|
| 105 |
+
# Code for use outside IDLE:
|
| 106 |
+
if self.get_saved():
|
| 107 |
+
reply = self.maybesave()
|
| 108 |
+
if reply == "cancel":
|
| 109 |
+
self.text.focus_set()
|
| 110 |
+
return "break"
|
| 111 |
+
if not editFile:
|
| 112 |
+
filename = self.askopenfile()
|
| 113 |
+
else:
|
| 114 |
+
filename=editFile
|
| 115 |
+
if filename:
|
| 116 |
+
self.loadfile(filename)
|
| 117 |
+
else:
|
| 118 |
+
self.text.focus_set()
|
| 119 |
+
return "break"
|
| 120 |
+
|
| 121 |
+
eol_convention = os.linesep # default
|
| 122 |
+
|
| 123 |
+
def loadfile(self, filename):
|
| 124 |
+
try:
|
| 125 |
+
try:
|
| 126 |
+
with tokenize.open(filename) as f:
|
| 127 |
+
chars = f.read()
|
| 128 |
+
fileencoding = f.encoding
|
| 129 |
+
eol_convention = f.newlines
|
| 130 |
+
converted = False
|
| 131 |
+
except (UnicodeDecodeError, SyntaxError):
|
| 132 |
+
# Wait for the editor window to appear
|
| 133 |
+
self.editwin.text.update()
|
| 134 |
+
enc = askstring(
|
| 135 |
+
"Specify file encoding",
|
| 136 |
+
"The file's encoding is invalid for Python 3.x.\n"
|
| 137 |
+
"IDLE will convert it to UTF-8.\n"
|
| 138 |
+
"What is the current encoding of the file?",
|
| 139 |
+
initialvalue='utf-8',
|
| 140 |
+
parent=self.editwin.text)
|
| 141 |
+
with open(filename, encoding=enc) as f:
|
| 142 |
+
chars = f.read()
|
| 143 |
+
fileencoding = f.encoding
|
| 144 |
+
eol_convention = f.newlines
|
| 145 |
+
converted = True
|
| 146 |
+
except OSError as err:
|
| 147 |
+
messagebox.showerror("I/O Error", str(err), parent=self.text)
|
| 148 |
+
return False
|
| 149 |
+
except UnicodeDecodeError:
|
| 150 |
+
messagebox.showerror("Decoding Error",
|
| 151 |
+
"File %s\nFailed to Decode" % filename,
|
| 152 |
+
parent=self.text)
|
| 153 |
+
return False
|
| 154 |
+
|
| 155 |
+
if not isinstance(eol_convention, str):
|
| 156 |
+
# If the file does not contain line separators, it is None.
|
| 157 |
+
# If the file contains mixed line separators, it is a tuple.
|
| 158 |
+
if eol_convention is not None:
|
| 159 |
+
messagebox.showwarning("Mixed Newlines",
|
| 160 |
+
"Mixed newlines detected.\n"
|
| 161 |
+
"The file will be changed on save.",
|
| 162 |
+
parent=self.text)
|
| 163 |
+
converted = True
|
| 164 |
+
eol_convention = os.linesep # default
|
| 165 |
+
|
| 166 |
+
self.text.delete("1.0", "end")
|
| 167 |
+
self.set_filename(None)
|
| 168 |
+
self.fileencoding = fileencoding
|
| 169 |
+
self.eol_convention = eol_convention
|
| 170 |
+
self.text.insert("1.0", chars)
|
| 171 |
+
self.reset_undo()
|
| 172 |
+
self.set_filename(filename)
|
| 173 |
+
if converted:
|
| 174 |
+
# We need to save the conversion results first
|
| 175 |
+
# before being able to execute the code
|
| 176 |
+
self.set_saved(False)
|
| 177 |
+
self.text.mark_set("insert", "1.0")
|
| 178 |
+
self.text.yview("insert")
|
| 179 |
+
self.updaterecentfileslist(filename)
|
| 180 |
+
return True
|
| 181 |
+
|
| 182 |
+
def maybesave(self):
|
| 183 |
+
if self.get_saved():
|
| 184 |
+
return "yes"
|
| 185 |
+
message = "Do you want to save %s before closing?" % (
|
| 186 |
+
self.filename or "this untitled document")
|
| 187 |
+
confirm = messagebox.askyesnocancel(
|
| 188 |
+
title="Save On Close",
|
| 189 |
+
message=message,
|
| 190 |
+
default=messagebox.YES,
|
| 191 |
+
parent=self.text)
|
| 192 |
+
if confirm:
|
| 193 |
+
reply = "yes"
|
| 194 |
+
self.save(None)
|
| 195 |
+
if not self.get_saved():
|
| 196 |
+
reply = "cancel"
|
| 197 |
+
elif confirm is None:
|
| 198 |
+
reply = "cancel"
|
| 199 |
+
else:
|
| 200 |
+
reply = "no"
|
| 201 |
+
self.text.focus_set()
|
| 202 |
+
return reply
|
| 203 |
+
|
| 204 |
+
def save(self, event):
|
| 205 |
+
if not self.filename:
|
| 206 |
+
self.save_as(event)
|
| 207 |
+
else:
|
| 208 |
+
if self.writefile(self.filename):
|
| 209 |
+
self.set_saved(True)
|
| 210 |
+
try:
|
| 211 |
+
self.editwin.store_file_breaks()
|
| 212 |
+
except AttributeError: # may be a PyShell
|
| 213 |
+
pass
|
| 214 |
+
self.text.focus_set()
|
| 215 |
+
return "break"
|
| 216 |
+
|
| 217 |
+
def save_as(self, event):
|
| 218 |
+
filename = self.asksavefile()
|
| 219 |
+
if filename:
|
| 220 |
+
if self.writefile(filename):
|
| 221 |
+
self.set_filename(filename)
|
| 222 |
+
self.set_saved(1)
|
| 223 |
+
try:
|
| 224 |
+
self.editwin.store_file_breaks()
|
| 225 |
+
except AttributeError:
|
| 226 |
+
pass
|
| 227 |
+
self.text.focus_set()
|
| 228 |
+
self.updaterecentfileslist(filename)
|
| 229 |
+
return "break"
|
| 230 |
+
|
| 231 |
+
def save_a_copy(self, event):
|
| 232 |
+
filename = self.asksavefile()
|
| 233 |
+
if filename:
|
| 234 |
+
self.writefile(filename)
|
| 235 |
+
self.text.focus_set()
|
| 236 |
+
self.updaterecentfileslist(filename)
|
| 237 |
+
return "break"
|
| 238 |
+
|
| 239 |
+
def writefile(self, filename):
|
| 240 |
+
text = self.fixnewlines()
|
| 241 |
+
chars = self.encode(text)
|
| 242 |
+
try:
|
| 243 |
+
with open(filename, "wb") as f:
|
| 244 |
+
f.write(chars)
|
| 245 |
+
f.flush()
|
| 246 |
+
os.fsync(f.fileno())
|
| 247 |
+
return True
|
| 248 |
+
except OSError as msg:
|
| 249 |
+
messagebox.showerror("I/O Error", str(msg),
|
| 250 |
+
parent=self.text)
|
| 251 |
+
return False
|
| 252 |
+
|
| 253 |
+
def fixnewlines(self):
|
| 254 |
+
"""Return text with os eols.
|
| 255 |
+
|
| 256 |
+
Add prompts if shell else final \n if missing.
|
| 257 |
+
"""
|
| 258 |
+
|
| 259 |
+
if hasattr(self.editwin, "interp"): # Saving shell.
|
| 260 |
+
text = self.editwin.get_prompt_text('1.0', self.text.index('end-1c'))
|
| 261 |
+
else:
|
| 262 |
+
if self.text.get("end-2c") != '\n':
|
| 263 |
+
self.text.insert("end-1c", "\n") # Changes 'end-1c' value.
|
| 264 |
+
text = self.text.get('1.0', "end-1c")
|
| 265 |
+
if self.eol_convention != "\n":
|
| 266 |
+
text = text.replace("\n", self.eol_convention)
|
| 267 |
+
return text
|
| 268 |
+
|
| 269 |
+
def encode(self, chars):
|
| 270 |
+
if isinstance(chars, bytes):
|
| 271 |
+
# This is either plain ASCII, or Tk was returning mixed-encoding
|
| 272 |
+
# text to us. Don't try to guess further.
|
| 273 |
+
return chars
|
| 274 |
+
# Preserve a BOM that might have been present on opening
|
| 275 |
+
if self.fileencoding == 'utf-8-sig':
|
| 276 |
+
return chars.encode('utf-8-sig')
|
| 277 |
+
# See whether there is anything non-ASCII in it.
|
| 278 |
+
# If not, no need to figure out the encoding.
|
| 279 |
+
try:
|
| 280 |
+
return chars.encode('ascii')
|
| 281 |
+
except UnicodeEncodeError:
|
| 282 |
+
pass
|
| 283 |
+
# Check if there is an encoding declared
|
| 284 |
+
try:
|
| 285 |
+
encoded = chars.encode('ascii', 'replace')
|
| 286 |
+
enc, _ = tokenize.detect_encoding(io.BytesIO(encoded).readline)
|
| 287 |
+
return chars.encode(enc)
|
| 288 |
+
except SyntaxError as err:
|
| 289 |
+
failed = str(err)
|
| 290 |
+
except UnicodeEncodeError:
|
| 291 |
+
failed = "Invalid encoding '%s'" % enc
|
| 292 |
+
messagebox.showerror(
|
| 293 |
+
"I/O Error",
|
| 294 |
+
"%s.\nSaving as UTF-8" % failed,
|
| 295 |
+
parent=self.text)
|
| 296 |
+
# Fallback: save as UTF-8, with BOM - ignoring the incorrect
|
| 297 |
+
# declared encoding
|
| 298 |
+
return chars.encode('utf-8-sig')
|
| 299 |
+
|
| 300 |
+
def print_window(self, event):
|
| 301 |
+
confirm = messagebox.askokcancel(
|
| 302 |
+
title="Print",
|
| 303 |
+
message="Print to Default Printer",
|
| 304 |
+
default=messagebox.OK,
|
| 305 |
+
parent=self.text)
|
| 306 |
+
if not confirm:
|
| 307 |
+
self.text.focus_set()
|
| 308 |
+
return "break"
|
| 309 |
+
tempfilename = None
|
| 310 |
+
saved = self.get_saved()
|
| 311 |
+
if saved:
|
| 312 |
+
filename = self.filename
|
| 313 |
+
# shell undo is reset after every prompt, looks saved, probably isn't
|
| 314 |
+
if not saved or filename is None:
|
| 315 |
+
(tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
|
| 316 |
+
filename = tempfilename
|
| 317 |
+
os.close(tfd)
|
| 318 |
+
if not self.writefile(tempfilename):
|
| 319 |
+
os.unlink(tempfilename)
|
| 320 |
+
return "break"
|
| 321 |
+
platform = os.name
|
| 322 |
+
printPlatform = True
|
| 323 |
+
if platform == 'posix': #posix platform
|
| 324 |
+
command = idleConf.GetOption('main','General',
|
| 325 |
+
'print-command-posix')
|
| 326 |
+
command = command + " 2>&1"
|
| 327 |
+
elif platform == 'nt': #win32 platform
|
| 328 |
+
command = idleConf.GetOption('main','General','print-command-win')
|
| 329 |
+
else: #no printing for this platform
|
| 330 |
+
printPlatform = False
|
| 331 |
+
if printPlatform: #we can try to print for this platform
|
| 332 |
+
command = command % shlex.quote(filename)
|
| 333 |
+
pipe = os.popen(command, "r")
|
| 334 |
+
# things can get ugly on NT if there is no printer available.
|
| 335 |
+
output = pipe.read().strip()
|
| 336 |
+
status = pipe.close()
|
| 337 |
+
if status:
|
| 338 |
+
output = "Printing failed (exit status 0x%x)\n" % \
|
| 339 |
+
status + output
|
| 340 |
+
if output:
|
| 341 |
+
output = "Printing command: %s\n" % repr(command) + output
|
| 342 |
+
messagebox.showerror("Print status", output, parent=self.text)
|
| 343 |
+
else: #no printing for this platform
|
| 344 |
+
message = "Printing is not enabled for this platform: %s" % platform
|
| 345 |
+
messagebox.showinfo("Print status", message, parent=self.text)
|
| 346 |
+
if tempfilename:
|
| 347 |
+
os.unlink(tempfilename)
|
| 348 |
+
return "break"
|
| 349 |
+
|
| 350 |
+
opendialog = None
|
| 351 |
+
savedialog = None
|
| 352 |
+
|
| 353 |
+
filetypes = (
|
| 354 |
+
("Python files", py_extensions, "TEXT"),
|
| 355 |
+
("Text files", "*.txt", "TEXT"),
|
| 356 |
+
("All files", "*"),
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
defaultextension = '.py' if sys.platform == 'darwin' else ''
|
| 360 |
+
|
| 361 |
+
def askopenfile(self):
|
| 362 |
+
dir, base = self.defaultfilename("open")
|
| 363 |
+
if not self.opendialog:
|
| 364 |
+
self.opendialog = filedialog.Open(parent=self.text,
|
| 365 |
+
filetypes=self.filetypes)
|
| 366 |
+
filename = self.opendialog.show(initialdir=dir, initialfile=base)
|
| 367 |
+
return filename
|
| 368 |
+
|
| 369 |
+
def defaultfilename(self, mode="open"):
|
| 370 |
+
if self.filename:
|
| 371 |
+
return os.path.split(self.filename)
|
| 372 |
+
elif self.dirname:
|
| 373 |
+
return self.dirname, ""
|
| 374 |
+
else:
|
| 375 |
+
try:
|
| 376 |
+
pwd = os.getcwd()
|
| 377 |
+
except OSError:
|
| 378 |
+
pwd = ""
|
| 379 |
+
return pwd, ""
|
| 380 |
+
|
| 381 |
+
def asksavefile(self):
|
| 382 |
+
dir, base = self.defaultfilename("save")
|
| 383 |
+
if not self.savedialog:
|
| 384 |
+
self.savedialog = filedialog.SaveAs(
|
| 385 |
+
parent=self.text,
|
| 386 |
+
filetypes=self.filetypes,
|
| 387 |
+
defaultextension=self.defaultextension)
|
| 388 |
+
filename = self.savedialog.show(initialdir=dir, initialfile=base)
|
| 389 |
+
return filename
|
| 390 |
+
|
| 391 |
+
def updaterecentfileslist(self,filename):
|
| 392 |
+
"Update recent file list on all editor windows"
|
| 393 |
+
if self.editwin.flist:
|
| 394 |
+
self.editwin.update_recent_files_list(filename)
|
| 395 |
+
|
| 396 |
+
def _io_binding(parent): # htest #
|
| 397 |
+
from tkinter import Toplevel, Text
|
| 398 |
+
|
| 399 |
+
root = Toplevel(parent)
|
| 400 |
+
root.title("Test IOBinding")
|
| 401 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 402 |
+
root.geometry("+%d+%d" % (x, y + 175))
|
| 403 |
+
class MyEditWin:
|
| 404 |
+
def __init__(self, text):
|
| 405 |
+
self.text = text
|
| 406 |
+
self.flist = None
|
| 407 |
+
self.text.bind("<Control-o>", self.open)
|
| 408 |
+
self.text.bind('<Control-p>', self.print)
|
| 409 |
+
self.text.bind("<Control-s>", self.save)
|
| 410 |
+
self.text.bind("<Alt-s>", self.saveas)
|
| 411 |
+
self.text.bind('<Control-c>', self.savecopy)
|
| 412 |
+
def get_saved(self): return 0
|
| 413 |
+
def set_saved(self, flag): pass
|
| 414 |
+
def reset_undo(self): pass
|
| 415 |
+
def open(self, event):
|
| 416 |
+
self.text.event_generate("<<open-window-from-file>>")
|
| 417 |
+
def print(self, event):
|
| 418 |
+
self.text.event_generate("<<print-window>>")
|
| 419 |
+
def save(self, event):
|
| 420 |
+
self.text.event_generate("<<save-window>>")
|
| 421 |
+
def saveas(self, event):
|
| 422 |
+
self.text.event_generate("<<save-window-as-file>>")
|
| 423 |
+
def savecopy(self, event):
|
| 424 |
+
self.text.event_generate("<<save-copy-of-window-as-file>>")
|
| 425 |
+
|
| 426 |
+
text = Text(root)
|
| 427 |
+
text.pack()
|
| 428 |
+
text.focus_set()
|
| 429 |
+
editwin = MyEditWin(text)
|
| 430 |
+
IOBinding(editwin)
|
| 431 |
+
|
| 432 |
+
if __name__ == "__main__":
|
| 433 |
+
from unittest import main
|
| 434 |
+
main('idlelib.idle_test.test_iomenu', verbosity=2, exit=False)
|
| 435 |
+
|
| 436 |
+
from idlelib.idle_test.htest import run
|
| 437 |
+
run(_io_binding)
|
llava/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)
|
llava/lib/python3.10/idlelib/mainmenu.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define the menu contents, hotkeys, and event bindings.
|
| 2 |
+
|
| 3 |
+
There is additional configuration information in the EditorWindow class (and
|
| 4 |
+
subclasses): the menus are created there based on the menu_specs (class)
|
| 5 |
+
variable, and menus not created are silently skipped in the code here. This
|
| 6 |
+
makes it possible, for example, to define a Debug menu which is only present in
|
| 7 |
+
the PythonShell window, and a Format menu which is only present in the Editor
|
| 8 |
+
windows.
|
| 9 |
+
|
| 10 |
+
"""
|
| 11 |
+
from importlib.util import find_spec
|
| 12 |
+
|
| 13 |
+
from idlelib.config import idleConf
|
| 14 |
+
|
| 15 |
+
# Warning: menudefs is altered in macosx.overrideRootMenu()
|
| 16 |
+
# after it is determined that an OS X Aqua Tk is in use,
|
| 17 |
+
# which cannot be done until after Tk() is first called.
|
| 18 |
+
# Do not alter the 'file', 'options', or 'help' cascades here
|
| 19 |
+
# without altering overrideRootMenu() as well.
|
| 20 |
+
# TODO: Make this more robust
|
| 21 |
+
|
| 22 |
+
menudefs = [
|
| 23 |
+
# underscore prefixes character to underscore
|
| 24 |
+
('file', [
|
| 25 |
+
('_New File', '<<open-new-window>>'),
|
| 26 |
+
('_Open...', '<<open-window-from-file>>'),
|
| 27 |
+
('Open _Module...', '<<open-module>>'),
|
| 28 |
+
('Module _Browser', '<<open-class-browser>>'),
|
| 29 |
+
('_Path Browser', '<<open-path-browser>>'),
|
| 30 |
+
None,
|
| 31 |
+
('_Save', '<<save-window>>'),
|
| 32 |
+
('Save _As...', '<<save-window-as-file>>'),
|
| 33 |
+
('Save Cop_y As...', '<<save-copy-of-window-as-file>>'),
|
| 34 |
+
None,
|
| 35 |
+
('Prin_t Window', '<<print-window>>'),
|
| 36 |
+
None,
|
| 37 |
+
('_Close Window', '<<close-window>>'),
|
| 38 |
+
('E_xit IDLE', '<<close-all-windows>>'),
|
| 39 |
+
]),
|
| 40 |
+
|
| 41 |
+
('edit', [
|
| 42 |
+
('_Undo', '<<undo>>'),
|
| 43 |
+
('_Redo', '<<redo>>'),
|
| 44 |
+
None,
|
| 45 |
+
('Select _All', '<<select-all>>'),
|
| 46 |
+
('Cu_t', '<<cut>>'),
|
| 47 |
+
('_Copy', '<<copy>>'),
|
| 48 |
+
('_Paste', '<<paste>>'),
|
| 49 |
+
None,
|
| 50 |
+
('_Find...', '<<find>>'),
|
| 51 |
+
('Find A_gain', '<<find-again>>'),
|
| 52 |
+
('Find _Selection', '<<find-selection>>'),
|
| 53 |
+
('Find in Files...', '<<find-in-files>>'),
|
| 54 |
+
('R_eplace...', '<<replace>>'),
|
| 55 |
+
None,
|
| 56 |
+
('Go to _Line', '<<goto-line>>'),
|
| 57 |
+
('S_how Completions', '<<force-open-completions>>'),
|
| 58 |
+
('E_xpand Word', '<<expand-word>>'),
|
| 59 |
+
('Show C_all Tip', '<<force-open-calltip>>'),
|
| 60 |
+
('Show Surrounding P_arens', '<<flash-paren>>'),
|
| 61 |
+
]),
|
| 62 |
+
|
| 63 |
+
('format', [
|
| 64 |
+
('F_ormat Paragraph', '<<format-paragraph>>'),
|
| 65 |
+
('_Indent Region', '<<indent-region>>'),
|
| 66 |
+
('_Dedent Region', '<<dedent-region>>'),
|
| 67 |
+
('Comment _Out Region', '<<comment-region>>'),
|
| 68 |
+
('U_ncomment Region', '<<uncomment-region>>'),
|
| 69 |
+
('Tabify Region', '<<tabify-region>>'),
|
| 70 |
+
('Untabify Region', '<<untabify-region>>'),
|
| 71 |
+
('Toggle Tabs', '<<toggle-tabs>>'),
|
| 72 |
+
('New Indent Width', '<<change-indentwidth>>'),
|
| 73 |
+
('S_trip Trailing Whitespace', '<<do-rstrip>>'),
|
| 74 |
+
]),
|
| 75 |
+
|
| 76 |
+
('run', [
|
| 77 |
+
('R_un Module', '<<run-module>>'),
|
| 78 |
+
('Run... _Customized', '<<run-custom>>'),
|
| 79 |
+
('C_heck Module', '<<check-module>>'),
|
| 80 |
+
('Python Shell', '<<open-python-shell>>'),
|
| 81 |
+
]),
|
| 82 |
+
|
| 83 |
+
('shell', [
|
| 84 |
+
('_View Last Restart', '<<view-restart>>'),
|
| 85 |
+
('_Restart Shell', '<<restart-shell>>'),
|
| 86 |
+
None,
|
| 87 |
+
('_Previous History', '<<history-previous>>'),
|
| 88 |
+
('_Next History', '<<history-next>>'),
|
| 89 |
+
None,
|
| 90 |
+
('_Interrupt Execution', '<<interrupt-execution>>'),
|
| 91 |
+
]),
|
| 92 |
+
|
| 93 |
+
('debug', [
|
| 94 |
+
('_Go to File/Line', '<<goto-file-line>>'),
|
| 95 |
+
('!_Debugger', '<<toggle-debugger>>'),
|
| 96 |
+
('_Stack Viewer', '<<open-stack-viewer>>'),
|
| 97 |
+
('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
|
| 98 |
+
]),
|
| 99 |
+
|
| 100 |
+
('options', [
|
| 101 |
+
('Configure _IDLE', '<<open-config-dialog>>'),
|
| 102 |
+
None,
|
| 103 |
+
('Show _Code Context', '<<toggle-code-context>>'),
|
| 104 |
+
('Show _Line Numbers', '<<toggle-line-numbers>>'),
|
| 105 |
+
('_Zoom Height', '<<zoom-height>>'),
|
| 106 |
+
]),
|
| 107 |
+
|
| 108 |
+
('window', [
|
| 109 |
+
]),
|
| 110 |
+
|
| 111 |
+
('help', [
|
| 112 |
+
('_About IDLE', '<<about-idle>>'),
|
| 113 |
+
None,
|
| 114 |
+
('_IDLE Doc', '<<help>>'),
|
| 115 |
+
('Python _Docs', '<<python-docs>>'),
|
| 116 |
+
]),
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
if find_spec('turtledemo'):
|
| 120 |
+
menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
|
| 121 |
+
|
| 122 |
+
default_keydefs = idleConf.GetCurrentKeySet()
|
| 123 |
+
|
| 124 |
+
if __name__ == '__main__':
|
| 125 |
+
from unittest import main
|
| 126 |
+
main('idlelib.idle_test.test_mainmenu', verbosity=2)
|
llava/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 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Editor window that can serve as an output file.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from tkinter import messagebox
|
| 7 |
+
|
| 8 |
+
from idlelib.editor import EditorWindow
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
file_line_pats = [
|
| 12 |
+
# order of patterns matters
|
| 13 |
+
r'file "([^"]*)", line (\d+)',
|
| 14 |
+
r'([^\s]+)\((\d+)\)',
|
| 15 |
+
r'^(\s*\S.*?):\s*(\d+):', # Win filename, maybe starting with spaces
|
| 16 |
+
r'([^\s]+):\s*(\d+):', # filename or path, ltrim
|
| 17 |
+
r'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
file_line_progs = None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def compile_progs():
|
| 24 |
+
"Compile the patterns for matching to file name and line number."
|
| 25 |
+
global file_line_progs
|
| 26 |
+
file_line_progs = [re.compile(pat, re.IGNORECASE)
|
| 27 |
+
for pat in file_line_pats]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def file_line_helper(line):
|
| 31 |
+
"""Extract file name and line number from line of text.
|
| 32 |
+
|
| 33 |
+
Check if line of text contains one of the file/line patterns.
|
| 34 |
+
If it does and if the file and line are valid, return
|
| 35 |
+
a tuple of the file name and line number. If it doesn't match
|
| 36 |
+
or if the file or line is invalid, return None.
|
| 37 |
+
"""
|
| 38 |
+
if not file_line_progs:
|
| 39 |
+
compile_progs()
|
| 40 |
+
for prog in file_line_progs:
|
| 41 |
+
match = prog.search(line)
|
| 42 |
+
if match:
|
| 43 |
+
filename, lineno = match.group(1, 2)
|
| 44 |
+
try:
|
| 45 |
+
f = open(filename, "r")
|
| 46 |
+
f.close()
|
| 47 |
+
break
|
| 48 |
+
except OSError:
|
| 49 |
+
continue
|
| 50 |
+
else:
|
| 51 |
+
return None
|
| 52 |
+
try:
|
| 53 |
+
return filename, int(lineno)
|
| 54 |
+
except TypeError:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class OutputWindow(EditorWindow):
|
| 59 |
+
"""An editor window that can serve as an output file.
|
| 60 |
+
|
| 61 |
+
Also the future base class for the Python shell window.
|
| 62 |
+
This class has no input facilities.
|
| 63 |
+
|
| 64 |
+
Adds binding to open a file at a line to the text widget.
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
# Our own right-button menu
|
| 68 |
+
rmenu_specs = [
|
| 69 |
+
("Cut", "<<cut>>", "rmenu_check_cut"),
|
| 70 |
+
("Copy", "<<copy>>", "rmenu_check_copy"),
|
| 71 |
+
("Paste", "<<paste>>", "rmenu_check_paste"),
|
| 72 |
+
(None, None, None),
|
| 73 |
+
("Go to file/line", "<<goto-file-line>>", None),
|
| 74 |
+
]
|
| 75 |
+
|
| 76 |
+
allow_code_context = False
|
| 77 |
+
|
| 78 |
+
def __init__(self, *args):
|
| 79 |
+
EditorWindow.__init__(self, *args)
|
| 80 |
+
self.text.bind("<<goto-file-line>>", self.goto_file_line)
|
| 81 |
+
|
| 82 |
+
# Customize EditorWindow
|
| 83 |
+
def ispythonsource(self, filename):
|
| 84 |
+
"Python source is only part of output: do not colorize."
|
| 85 |
+
return False
|
| 86 |
+
|
| 87 |
+
def short_title(self):
|
| 88 |
+
"Customize EditorWindow title."
|
| 89 |
+
return "Output"
|
| 90 |
+
|
| 91 |
+
def maybesave(self):
|
| 92 |
+
"Customize EditorWindow to not display save file messagebox."
|
| 93 |
+
return 'yes' if self.get_saved() else 'no'
|
| 94 |
+
|
| 95 |
+
# Act as output file
|
| 96 |
+
def write(self, s, tags=(), mark="insert"):
|
| 97 |
+
"""Write text to text widget.
|
| 98 |
+
|
| 99 |
+
The text is inserted at the given index with the provided
|
| 100 |
+
tags. The text widget is then scrolled to make it visible
|
| 101 |
+
and updated to display it, giving the effect of seeing each
|
| 102 |
+
line as it is added.
|
| 103 |
+
|
| 104 |
+
Args:
|
| 105 |
+
s: Text to insert into text widget.
|
| 106 |
+
tags: Tuple of tag strings to apply on the insert.
|
| 107 |
+
mark: Index for the insert.
|
| 108 |
+
|
| 109 |
+
Return:
|
| 110 |
+
Length of text inserted.
|
| 111 |
+
"""
|
| 112 |
+
assert isinstance(s, str)
|
| 113 |
+
self.text.insert(mark, s, tags)
|
| 114 |
+
self.text.see(mark)
|
| 115 |
+
self.text.update()
|
| 116 |
+
return len(s)
|
| 117 |
+
|
| 118 |
+
def writelines(self, lines):
|
| 119 |
+
"Write each item in lines iterable."
|
| 120 |
+
for line in lines:
|
| 121 |
+
self.write(line)
|
| 122 |
+
|
| 123 |
+
def flush(self):
|
| 124 |
+
"No flushing needed as write() directly writes to widget."
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
def showerror(self, *args, **kwargs):
|
| 128 |
+
messagebox.showerror(*args, **kwargs)
|
| 129 |
+
|
| 130 |
+
def goto_file_line(self, event=None):
|
| 131 |
+
"""Handle request to open file/line.
|
| 132 |
+
|
| 133 |
+
If the selected or previous line in the output window
|
| 134 |
+
contains a file name and line number, then open that file
|
| 135 |
+
name in a new window and position on the line number.
|
| 136 |
+
|
| 137 |
+
Otherwise, display an error messagebox.
|
| 138 |
+
"""
|
| 139 |
+
line = self.text.get("insert linestart", "insert lineend")
|
| 140 |
+
result = file_line_helper(line)
|
| 141 |
+
if not result:
|
| 142 |
+
# Try the previous line. This is handy e.g. in tracebacks,
|
| 143 |
+
# where you tend to right-click on the displayed source line
|
| 144 |
+
line = self.text.get("insert -1line linestart",
|
| 145 |
+
"insert -1line lineend")
|
| 146 |
+
result = file_line_helper(line)
|
| 147 |
+
if not result:
|
| 148 |
+
self.showerror(
|
| 149 |
+
"No special line",
|
| 150 |
+
"The line you point at doesn't look like "
|
| 151 |
+
"a valid file name followed by a line number.",
|
| 152 |
+
parent=self.text)
|
| 153 |
+
return
|
| 154 |
+
filename, lineno = result
|
| 155 |
+
self.flist.gotofileline(filename, lineno)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
# These classes are currently not used but might come in handy
|
| 159 |
+
class OnDemandOutputWindow:
|
| 160 |
+
|
| 161 |
+
tagdefs = {
|
| 162 |
+
# XXX Should use IdlePrefs.ColorPrefs
|
| 163 |
+
"stdout": {"foreground": "blue"},
|
| 164 |
+
"stderr": {"foreground": "#007700"},
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
def __init__(self, flist):
|
| 168 |
+
self.flist = flist
|
| 169 |
+
self.owin = None
|
| 170 |
+
|
| 171 |
+
def write(self, s, tags, mark):
|
| 172 |
+
if not self.owin:
|
| 173 |
+
self.setup()
|
| 174 |
+
self.owin.write(s, tags, mark)
|
| 175 |
+
|
| 176 |
+
def setup(self):
|
| 177 |
+
self.owin = owin = OutputWindow(self.flist)
|
| 178 |
+
text = owin.text
|
| 179 |
+
for tag, cnf in self.tagdefs.items():
|
| 180 |
+
if cnf:
|
| 181 |
+
text.tag_configure(tag, **cnf)
|
| 182 |
+
text.tag_raise('sel')
|
| 183 |
+
self.write = self.owin.write
|
| 184 |
+
|
| 185 |
+
if __name__ == '__main__':
|
| 186 |
+
from unittest import main
|
| 187 |
+
main('idlelib.idle_test.test_outwin', verbosity=2, exit=False)
|
llava/lib/python3.10/idlelib/parenmatch.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ren, 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)
|
llava/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 |
+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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)
|
llava/lib/python3.10/idlelib/pyshell.py
ADDED
|
@@ -0,0 +1,1713 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#! /usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
import sys
|
| 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
|
llava/lib/python3.10/idlelib/redirector.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tkinter import TclError
|
| 2 |
+
|
| 3 |
+
class WidgetRedirector:
|
| 4 |
+
"""Support for redirecting arbitrary widget subcommands.
|
| 5 |
+
|
| 6 |
+
Some Tk operations don't normally pass through tkinter. For example, if a
|
| 7 |
+
character is inserted into a Text widget by pressing a key, a default Tk
|
| 8 |
+
binding to the widget's 'insert' operation is activated, and the Tk library
|
| 9 |
+
processes the insert without calling back into tkinter.
|
| 10 |
+
|
| 11 |
+
Although a binding to <Key> could be made via tkinter, what we really want
|
| 12 |
+
to do is to hook the Tk 'insert' operation itself. For one thing, we want
|
| 13 |
+
a text.insert call in idle code to have the same effect as a key press.
|
| 14 |
+
|
| 15 |
+
When a widget is instantiated, a Tcl command is created whose name is the
|
| 16 |
+
same as the pathname widget._w. This command is used to invoke the various
|
| 17 |
+
widget operations, e.g. insert (for a Text widget). We are going to hook
|
| 18 |
+
this command and provide a facility ('register') to intercept the widget
|
| 19 |
+
operation. We will also intercept method calls on the tkinter class
|
| 20 |
+
instance that represents the tk widget.
|
| 21 |
+
|
| 22 |
+
In IDLE, WidgetRedirector is used in Percolator to intercept Text
|
| 23 |
+
commands. The function being registered provides access to the top
|
| 24 |
+
of a Percolator chain. At the bottom of the chain is a call to the
|
| 25 |
+
original Tk widget operation.
|
| 26 |
+
"""
|
| 27 |
+
def __init__(self, widget):
|
| 28 |
+
'''Initialize attributes and setup redirection.
|
| 29 |
+
|
| 30 |
+
_operations: dict mapping operation name to new function.
|
| 31 |
+
widget: the widget whose tcl command is to be intercepted.
|
| 32 |
+
tk: widget.tk, a convenience attribute, probably not needed.
|
| 33 |
+
orig: new name of the original tcl command.
|
| 34 |
+
|
| 35 |
+
Since renaming to orig fails with TclError when orig already
|
| 36 |
+
exists, only one WidgetDirector can exist for a given widget.
|
| 37 |
+
'''
|
| 38 |
+
self._operations = {}
|
| 39 |
+
self.widget = widget # widget instance
|
| 40 |
+
self.tk = tk = widget.tk # widget's root
|
| 41 |
+
w = widget._w # widget's (full) Tk pathname
|
| 42 |
+
self.orig = w + "_orig"
|
| 43 |
+
# Rename the Tcl command within Tcl:
|
| 44 |
+
tk.call("rename", w, self.orig)
|
| 45 |
+
# Create a new Tcl command whose name is the widget's pathname, and
|
| 46 |
+
# whose action is to dispatch on the operation passed to the widget:
|
| 47 |
+
tk.createcommand(w, self.dispatch)
|
| 48 |
+
|
| 49 |
+
def __repr__(self):
|
| 50 |
+
return "%s(%s<%s>)" % (self.__class__.__name__,
|
| 51 |
+
self.widget.__class__.__name__,
|
| 52 |
+
self.widget._w)
|
| 53 |
+
|
| 54 |
+
def close(self):
|
| 55 |
+
"Unregister operations and revert redirection created by .__init__."
|
| 56 |
+
for operation in list(self._operations):
|
| 57 |
+
self.unregister(operation)
|
| 58 |
+
widget = self.widget
|
| 59 |
+
tk = widget.tk
|
| 60 |
+
w = widget._w
|
| 61 |
+
# Restore the original widget Tcl command.
|
| 62 |
+
tk.deletecommand(w)
|
| 63 |
+
tk.call("rename", self.orig, w)
|
| 64 |
+
del self.widget, self.tk # Should not be needed
|
| 65 |
+
# if instance is deleted after close, as in Percolator.
|
| 66 |
+
|
| 67 |
+
def register(self, operation, function):
|
| 68 |
+
'''Return OriginalCommand(operation) after registering function.
|
| 69 |
+
|
| 70 |
+
Registration adds an operation: function pair to ._operations.
|
| 71 |
+
It also adds a widget function attribute that masks the tkinter
|
| 72 |
+
class instance method. Method masking operates independently
|
| 73 |
+
from command dispatch.
|
| 74 |
+
|
| 75 |
+
If a second function is registered for the same operation, the
|
| 76 |
+
first function is replaced in both places.
|
| 77 |
+
'''
|
| 78 |
+
self._operations[operation] = function
|
| 79 |
+
setattr(self.widget, operation, function)
|
| 80 |
+
return OriginalCommand(self, operation)
|
| 81 |
+
|
| 82 |
+
def unregister(self, operation):
|
| 83 |
+
'''Return the function for the operation, or None.
|
| 84 |
+
|
| 85 |
+
Deleting the instance attribute unmasks the class attribute.
|
| 86 |
+
'''
|
| 87 |
+
if operation in self._operations:
|
| 88 |
+
function = self._operations[operation]
|
| 89 |
+
del self._operations[operation]
|
| 90 |
+
try:
|
| 91 |
+
delattr(self.widget, operation)
|
| 92 |
+
except AttributeError:
|
| 93 |
+
pass
|
| 94 |
+
return function
|
| 95 |
+
else:
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
def dispatch(self, operation, *args):
|
| 99 |
+
'''Callback from Tcl which runs when the widget is referenced.
|
| 100 |
+
|
| 101 |
+
If an operation has been registered in self._operations, apply the
|
| 102 |
+
associated function to the args passed into Tcl. Otherwise, pass the
|
| 103 |
+
operation through to Tk via the original Tcl function.
|
| 104 |
+
|
| 105 |
+
Note that if a registered function is called, the operation is not
|
| 106 |
+
passed through to Tk. Apply the function returned by self.register()
|
| 107 |
+
to *args to accomplish that. For an example, see colorizer.py.
|
| 108 |
+
|
| 109 |
+
'''
|
| 110 |
+
m = self._operations.get(operation)
|
| 111 |
+
try:
|
| 112 |
+
if m:
|
| 113 |
+
return m(*args)
|
| 114 |
+
else:
|
| 115 |
+
return self.tk.call((self.orig, operation) + args)
|
| 116 |
+
except TclError:
|
| 117 |
+
return ""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class OriginalCommand:
|
| 121 |
+
'''Callable for original tk command that has been redirected.
|
| 122 |
+
|
| 123 |
+
Returned by .register; can be used in the function registered.
|
| 124 |
+
redir = WidgetRedirector(text)
|
| 125 |
+
def my_insert(*args):
|
| 126 |
+
print("insert", args)
|
| 127 |
+
original_insert(*args)
|
| 128 |
+
original_insert = redir.register("insert", my_insert)
|
| 129 |
+
'''
|
| 130 |
+
|
| 131 |
+
def __init__(self, redir, operation):
|
| 132 |
+
'''Create .tk_call and .orig_and_operation for .__call__ method.
|
| 133 |
+
|
| 134 |
+
.redir and .operation store the input args for __repr__.
|
| 135 |
+
.tk and .orig copy attributes of .redir (probably not needed).
|
| 136 |
+
'''
|
| 137 |
+
self.redir = redir
|
| 138 |
+
self.operation = operation
|
| 139 |
+
self.tk = redir.tk # redundant with self.redir
|
| 140 |
+
self.orig = redir.orig # redundant with self.redir
|
| 141 |
+
# These two could be deleted after checking recipient code.
|
| 142 |
+
self.tk_call = redir.tk.call
|
| 143 |
+
self.orig_and_operation = (redir.orig, operation)
|
| 144 |
+
|
| 145 |
+
def __repr__(self):
|
| 146 |
+
return "%s(%r, %r)" % (self.__class__.__name__,
|
| 147 |
+
self.redir, self.operation)
|
| 148 |
+
|
| 149 |
+
def __call__(self, *args):
|
| 150 |
+
return self.tk_call(self.orig_and_operation + args)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def _widget_redirector(parent): # htest #
|
| 154 |
+
from tkinter import Toplevel, Text
|
| 155 |
+
|
| 156 |
+
top = Toplevel(parent)
|
| 157 |
+
top.title("Test WidgetRedirector")
|
| 158 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 159 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 160 |
+
text = Text(top)
|
| 161 |
+
text.pack()
|
| 162 |
+
text.focus_set()
|
| 163 |
+
redir = WidgetRedirector(text)
|
| 164 |
+
def my_insert(*args):
|
| 165 |
+
print("insert", args)
|
| 166 |
+
original_insert(*args)
|
| 167 |
+
original_insert = redir.register("insert", my_insert)
|
| 168 |
+
|
| 169 |
+
if __name__ == "__main__":
|
| 170 |
+
from unittest import main
|
| 171 |
+
main('idlelib.idle_test.test_redirector', verbosity=2, exit=False)
|
| 172 |
+
|
| 173 |
+
from idlelib.idle_test.htest import run
|
| 174 |
+
run(_widget_redirector)
|
llava/lib/python3.10/idlelib/runscript.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,)
|
llava/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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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 idlelib.idle_test.htest import run
|
| 210 |
+
run(_searchbase)
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Line numbering implementation for IDLE as an extension.
|
| 2 |
+
Includes BaseSideBar which can be extended for other sidebar based extensions
|
| 3 |
+
"""
|
| 4 |
+
import contextlib
|
| 5 |
+
import functools
|
| 6 |
+
import itertools
|
| 7 |
+
|
| 8 |
+
import tkinter as tk
|
| 9 |
+
from tkinter.font import Font
|
| 10 |
+
from idlelib.config import idleConf
|
| 11 |
+
from idlelib.delegator import Delegator
|
| 12 |
+
from idlelib import macosx
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def get_lineno(text, index):
|
| 16 |
+
"""Return the line number of an index in a Tk text widget."""
|
| 17 |
+
text_index = text.index(index)
|
| 18 |
+
return int(float(text_index)) if text_index else None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_end_linenumber(text):
|
| 22 |
+
"""Return the number of the last line in a Tk text widget."""
|
| 23 |
+
return get_lineno(text, 'end-1c')
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def get_displaylines(text, index):
|
| 27 |
+
"""Display height, in lines, of a logical line in a Tk text widget."""
|
| 28 |
+
res = text.count(f"{index} linestart",
|
| 29 |
+
f"{index} lineend",
|
| 30 |
+
"displaylines")
|
| 31 |
+
return res[0] if res else 0
|
| 32 |
+
|
| 33 |
+
def get_widget_padding(widget):
|
| 34 |
+
"""Get the total padding of a Tk widget, including its border."""
|
| 35 |
+
# TODO: use also in codecontext.py
|
| 36 |
+
manager = widget.winfo_manager()
|
| 37 |
+
if manager == 'pack':
|
| 38 |
+
info = widget.pack_info()
|
| 39 |
+
elif manager == 'grid':
|
| 40 |
+
info = widget.grid_info()
|
| 41 |
+
else:
|
| 42 |
+
raise ValueError(f"Unsupported geometry manager: {manager}")
|
| 43 |
+
|
| 44 |
+
# All values are passed through getint(), since some
|
| 45 |
+
# values may be pixel objects, which can't simply be added to ints.
|
| 46 |
+
padx = sum(map(widget.tk.getint, [
|
| 47 |
+
info['padx'],
|
| 48 |
+
widget.cget('padx'),
|
| 49 |
+
widget.cget('border'),
|
| 50 |
+
]))
|
| 51 |
+
pady = sum(map(widget.tk.getint, [
|
| 52 |
+
info['pady'],
|
| 53 |
+
widget.cget('pady'),
|
| 54 |
+
widget.cget('border'),
|
| 55 |
+
]))
|
| 56 |
+
return padx, pady
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@contextlib.contextmanager
|
| 60 |
+
def temp_enable_text_widget(text):
|
| 61 |
+
text.configure(state=tk.NORMAL)
|
| 62 |
+
try:
|
| 63 |
+
yield
|
| 64 |
+
finally:
|
| 65 |
+
text.configure(state=tk.DISABLED)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class BaseSideBar:
|
| 69 |
+
"""A base class for sidebars using Text."""
|
| 70 |
+
def __init__(self, editwin):
|
| 71 |
+
self.editwin = editwin
|
| 72 |
+
self.parent = editwin.text_frame
|
| 73 |
+
self.text = editwin.text
|
| 74 |
+
|
| 75 |
+
self.is_shown = False
|
| 76 |
+
|
| 77 |
+
self.main_widget = self.init_widgets()
|
| 78 |
+
|
| 79 |
+
self.bind_events()
|
| 80 |
+
|
| 81 |
+
self.update_font()
|
| 82 |
+
self.update_colors()
|
| 83 |
+
|
| 84 |
+
def init_widgets(self):
|
| 85 |
+
"""Initialize the sidebar's widgets, returning the main widget."""
|
| 86 |
+
raise NotImplementedError
|
| 87 |
+
|
| 88 |
+
def update_font(self):
|
| 89 |
+
"""Update the sidebar text font, usually after config changes."""
|
| 90 |
+
raise NotImplementedError
|
| 91 |
+
|
| 92 |
+
def update_colors(self):
|
| 93 |
+
"""Update the sidebar text colors, usually after config changes."""
|
| 94 |
+
raise NotImplementedError
|
| 95 |
+
|
| 96 |
+
def grid(self):
|
| 97 |
+
"""Layout the widget, always using grid layout."""
|
| 98 |
+
raise NotImplementedError
|
| 99 |
+
|
| 100 |
+
def show_sidebar(self):
|
| 101 |
+
if not self.is_shown:
|
| 102 |
+
self.grid()
|
| 103 |
+
self.is_shown = True
|
| 104 |
+
|
| 105 |
+
def hide_sidebar(self):
|
| 106 |
+
if self.is_shown:
|
| 107 |
+
self.main_widget.grid_forget()
|
| 108 |
+
self.is_shown = False
|
| 109 |
+
|
| 110 |
+
def yscroll_event(self, *args, **kwargs):
|
| 111 |
+
"""Hook for vertical scrolling for sub-classes to override."""
|
| 112 |
+
raise NotImplementedError
|
| 113 |
+
|
| 114 |
+
def redirect_yscroll_event(self, *args, **kwargs):
|
| 115 |
+
"""Redirect vertical scrolling to the main editor text widget.
|
| 116 |
+
|
| 117 |
+
The scroll bar is also updated.
|
| 118 |
+
"""
|
| 119 |
+
self.editwin.vbar.set(*args)
|
| 120 |
+
return self.yscroll_event(*args, **kwargs)
|
| 121 |
+
|
| 122 |
+
def redirect_focusin_event(self, event):
|
| 123 |
+
"""Redirect focus-in events to the main editor text widget."""
|
| 124 |
+
self.text.focus_set()
|
| 125 |
+
return 'break'
|
| 126 |
+
|
| 127 |
+
def redirect_mousebutton_event(self, event, event_name):
|
| 128 |
+
"""Redirect mouse button events to the main editor text widget."""
|
| 129 |
+
self.text.focus_set()
|
| 130 |
+
self.text.event_generate(event_name, x=0, y=event.y)
|
| 131 |
+
return 'break'
|
| 132 |
+
|
| 133 |
+
def redirect_mousewheel_event(self, event):
|
| 134 |
+
"""Redirect mouse wheel events to the editwin text widget."""
|
| 135 |
+
self.text.event_generate('<MouseWheel>',
|
| 136 |
+
x=0, y=event.y, delta=event.delta)
|
| 137 |
+
return 'break'
|
| 138 |
+
|
| 139 |
+
def bind_events(self):
|
| 140 |
+
self.text['yscrollcommand'] = self.redirect_yscroll_event
|
| 141 |
+
|
| 142 |
+
# Ensure focus is always redirected to the main editor text widget.
|
| 143 |
+
self.main_widget.bind('<FocusIn>', self.redirect_focusin_event)
|
| 144 |
+
|
| 145 |
+
# Redirect mouse scrolling to the main editor text widget.
|
| 146 |
+
#
|
| 147 |
+
# Note that without this, scrolling with the mouse only scrolls
|
| 148 |
+
# the line numbers.
|
| 149 |
+
self.main_widget.bind('<MouseWheel>', self.redirect_mousewheel_event)
|
| 150 |
+
|
| 151 |
+
# Redirect mouse button events to the main editor text widget,
|
| 152 |
+
# except for the left mouse button (1).
|
| 153 |
+
#
|
| 154 |
+
# Note: X-11 sends Button-4 and Button-5 events for the scroll wheel.
|
| 155 |
+
def bind_mouse_event(event_name, target_event_name):
|
| 156 |
+
handler = functools.partial(self.redirect_mousebutton_event,
|
| 157 |
+
event_name=target_event_name)
|
| 158 |
+
self.main_widget.bind(event_name, handler)
|
| 159 |
+
|
| 160 |
+
for button in [2, 3, 4, 5]:
|
| 161 |
+
for event_name in (f'<Button-{button}>',
|
| 162 |
+
f'<ButtonRelease-{button}>',
|
| 163 |
+
f'<B{button}-Motion>',
|
| 164 |
+
):
|
| 165 |
+
bind_mouse_event(event_name, target_event_name=event_name)
|
| 166 |
+
|
| 167 |
+
# Convert double- and triple-click events to normal click events,
|
| 168 |
+
# since event_generate() doesn't allow generating such events.
|
| 169 |
+
for event_name in (f'<Double-Button-{button}>',
|
| 170 |
+
f'<Triple-Button-{button}>',
|
| 171 |
+
):
|
| 172 |
+
bind_mouse_event(event_name,
|
| 173 |
+
target_event_name=f'<Button-{button}>')
|
| 174 |
+
|
| 175 |
+
# start_line is set upon <Button-1> to allow selecting a range of rows
|
| 176 |
+
# by dragging. It is cleared upon <ButtonRelease-1>.
|
| 177 |
+
start_line = None
|
| 178 |
+
|
| 179 |
+
# last_y is initially set upon <B1-Leave> and is continuously updated
|
| 180 |
+
# upon <B1-Motion>, until <B1-Enter> or the mouse button is released.
|
| 181 |
+
# It is used in text_auto_scroll(), which is called repeatedly and
|
| 182 |
+
# does have a mouse event available.
|
| 183 |
+
last_y = None
|
| 184 |
+
|
| 185 |
+
# auto_scrolling_after_id is set whenever text_auto_scroll is
|
| 186 |
+
# scheduled via .after(). It is used to stop the auto-scrolling
|
| 187 |
+
# upon <B1-Enter>, as well as to avoid scheduling the function several
|
| 188 |
+
# times in parallel.
|
| 189 |
+
auto_scrolling_after_id = None
|
| 190 |
+
|
| 191 |
+
def drag_update_selection_and_insert_mark(y_coord):
|
| 192 |
+
"""Helper function for drag and selection event handlers."""
|
| 193 |
+
lineno = get_lineno(self.text, f"@0,{y_coord}")
|
| 194 |
+
a, b = sorted([start_line, lineno])
|
| 195 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 196 |
+
self.text.tag_add("sel", f"{a}.0", f"{b+1}.0")
|
| 197 |
+
self.text.mark_set("insert",
|
| 198 |
+
f"{lineno if lineno == a else lineno + 1}.0")
|
| 199 |
+
|
| 200 |
+
def b1_mousedown_handler(event):
|
| 201 |
+
nonlocal start_line
|
| 202 |
+
nonlocal last_y
|
| 203 |
+
start_line = int(float(self.text.index(f"@0,{event.y}")))
|
| 204 |
+
last_y = event.y
|
| 205 |
+
|
| 206 |
+
drag_update_selection_and_insert_mark(event.y)
|
| 207 |
+
self.main_widget.bind('<Button-1>', b1_mousedown_handler)
|
| 208 |
+
|
| 209 |
+
def b1_mouseup_handler(event):
|
| 210 |
+
# On mouse up, we're no longer dragging. Set the shared persistent
|
| 211 |
+
# variables to None to represent this.
|
| 212 |
+
nonlocal start_line
|
| 213 |
+
nonlocal last_y
|
| 214 |
+
start_line = None
|
| 215 |
+
last_y = None
|
| 216 |
+
self.text.event_generate('<ButtonRelease-1>', x=0, y=event.y)
|
| 217 |
+
self.main_widget.bind('<ButtonRelease-1>', b1_mouseup_handler)
|
| 218 |
+
|
| 219 |
+
def b1_drag_handler(event):
|
| 220 |
+
nonlocal last_y
|
| 221 |
+
if last_y is None: # i.e. if not currently dragging
|
| 222 |
+
return
|
| 223 |
+
last_y = event.y
|
| 224 |
+
drag_update_selection_and_insert_mark(event.y)
|
| 225 |
+
self.main_widget.bind('<B1-Motion>', b1_drag_handler)
|
| 226 |
+
|
| 227 |
+
def text_auto_scroll():
|
| 228 |
+
"""Mimic Text auto-scrolling when dragging outside of it."""
|
| 229 |
+
# See: https://github.com/tcltk/tk/blob/064ff9941b4b80b85916a8afe86a6c21fd388b54/library/text.tcl#L670
|
| 230 |
+
nonlocal auto_scrolling_after_id
|
| 231 |
+
y = last_y
|
| 232 |
+
if y is None:
|
| 233 |
+
self.main_widget.after_cancel(auto_scrolling_after_id)
|
| 234 |
+
auto_scrolling_after_id = None
|
| 235 |
+
return
|
| 236 |
+
elif y < 0:
|
| 237 |
+
self.text.yview_scroll(-1 + y, 'pixels')
|
| 238 |
+
drag_update_selection_and_insert_mark(y)
|
| 239 |
+
elif y > self.main_widget.winfo_height():
|
| 240 |
+
self.text.yview_scroll(1 + y - self.main_widget.winfo_height(),
|
| 241 |
+
'pixels')
|
| 242 |
+
drag_update_selection_and_insert_mark(y)
|
| 243 |
+
auto_scrolling_after_id = \
|
| 244 |
+
self.main_widget.after(50, text_auto_scroll)
|
| 245 |
+
|
| 246 |
+
def b1_leave_handler(event):
|
| 247 |
+
# Schedule the initial call to text_auto_scroll(), if not already
|
| 248 |
+
# scheduled.
|
| 249 |
+
nonlocal auto_scrolling_after_id
|
| 250 |
+
if auto_scrolling_after_id is None:
|
| 251 |
+
nonlocal last_y
|
| 252 |
+
last_y = event.y
|
| 253 |
+
auto_scrolling_after_id = \
|
| 254 |
+
self.main_widget.after(0, text_auto_scroll)
|
| 255 |
+
self.main_widget.bind('<B1-Leave>', b1_leave_handler)
|
| 256 |
+
|
| 257 |
+
def b1_enter_handler(event):
|
| 258 |
+
# Cancel the scheduling of text_auto_scroll(), if it exists.
|
| 259 |
+
nonlocal auto_scrolling_after_id
|
| 260 |
+
if auto_scrolling_after_id is not None:
|
| 261 |
+
self.main_widget.after_cancel(auto_scrolling_after_id)
|
| 262 |
+
auto_scrolling_after_id = None
|
| 263 |
+
self.main_widget.bind('<B1-Enter>', b1_enter_handler)
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
class EndLineDelegator(Delegator):
|
| 267 |
+
"""Generate callbacks with the current end line number.
|
| 268 |
+
|
| 269 |
+
The provided callback is called after every insert and delete.
|
| 270 |
+
"""
|
| 271 |
+
def __init__(self, changed_callback):
|
| 272 |
+
Delegator.__init__(self)
|
| 273 |
+
self.changed_callback = changed_callback
|
| 274 |
+
|
| 275 |
+
def insert(self, index, chars, tags=None):
|
| 276 |
+
self.delegate.insert(index, chars, tags)
|
| 277 |
+
self.changed_callback(get_end_linenumber(self.delegate))
|
| 278 |
+
|
| 279 |
+
def delete(self, index1, index2=None):
|
| 280 |
+
self.delegate.delete(index1, index2)
|
| 281 |
+
self.changed_callback(get_end_linenumber(self.delegate))
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
class LineNumbers(BaseSideBar):
|
| 285 |
+
"""Line numbers support for editor windows."""
|
| 286 |
+
def __init__(self, editwin):
|
| 287 |
+
super().__init__(editwin)
|
| 288 |
+
|
| 289 |
+
end_line_delegator = EndLineDelegator(self.update_sidebar_text)
|
| 290 |
+
# Insert the delegator after the undo delegator, so that line numbers
|
| 291 |
+
# are properly updated after undo and redo actions.
|
| 292 |
+
self.editwin.per.insertfilterafter(end_line_delegator,
|
| 293 |
+
after=self.editwin.undo)
|
| 294 |
+
|
| 295 |
+
def init_widgets(self):
|
| 296 |
+
_padx, pady = get_widget_padding(self.text)
|
| 297 |
+
self.sidebar_text = tk.Text(self.parent, width=1, wrap=tk.NONE,
|
| 298 |
+
padx=2, pady=pady,
|
| 299 |
+
borderwidth=0, highlightthickness=0)
|
| 300 |
+
self.sidebar_text.config(state=tk.DISABLED)
|
| 301 |
+
|
| 302 |
+
self.prev_end = 1
|
| 303 |
+
self._sidebar_width_type = type(self.sidebar_text['width'])
|
| 304 |
+
with temp_enable_text_widget(self.sidebar_text):
|
| 305 |
+
self.sidebar_text.insert('insert', '1', 'linenumber')
|
| 306 |
+
self.sidebar_text.config(takefocus=False, exportselection=False)
|
| 307 |
+
self.sidebar_text.tag_config('linenumber', justify=tk.RIGHT)
|
| 308 |
+
|
| 309 |
+
end = get_end_linenumber(self.text)
|
| 310 |
+
self.update_sidebar_text(end)
|
| 311 |
+
|
| 312 |
+
return self.sidebar_text
|
| 313 |
+
|
| 314 |
+
def grid(self):
|
| 315 |
+
self.sidebar_text.grid(row=1, column=0, sticky=tk.NSEW)
|
| 316 |
+
|
| 317 |
+
def update_font(self):
|
| 318 |
+
font = idleConf.GetFont(self.text, 'main', 'EditorWindow')
|
| 319 |
+
self.sidebar_text['font'] = font
|
| 320 |
+
|
| 321 |
+
def update_colors(self):
|
| 322 |
+
"""Update the sidebar text colors, usually after config changes."""
|
| 323 |
+
colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'linenumber')
|
| 324 |
+
foreground = colors['foreground']
|
| 325 |
+
background = colors['background']
|
| 326 |
+
self.sidebar_text.config(
|
| 327 |
+
fg=foreground, bg=background,
|
| 328 |
+
selectforeground=foreground, selectbackground=background,
|
| 329 |
+
inactiveselectbackground=background,
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
def update_sidebar_text(self, end):
|
| 333 |
+
"""
|
| 334 |
+
Perform the following action:
|
| 335 |
+
Each line sidebar_text contains the linenumber for that line
|
| 336 |
+
Synchronize with editwin.text so that both sidebar_text and
|
| 337 |
+
editwin.text contain the same number of lines"""
|
| 338 |
+
if end == self.prev_end:
|
| 339 |
+
return
|
| 340 |
+
|
| 341 |
+
width_difference = len(str(end)) - len(str(self.prev_end))
|
| 342 |
+
if width_difference:
|
| 343 |
+
cur_width = int(float(self.sidebar_text['width']))
|
| 344 |
+
new_width = cur_width + width_difference
|
| 345 |
+
self.sidebar_text['width'] = self._sidebar_width_type(new_width)
|
| 346 |
+
|
| 347 |
+
with temp_enable_text_widget(self.sidebar_text):
|
| 348 |
+
if end > self.prev_end:
|
| 349 |
+
new_text = '\n'.join(itertools.chain(
|
| 350 |
+
[''],
|
| 351 |
+
map(str, range(self.prev_end + 1, end + 1)),
|
| 352 |
+
))
|
| 353 |
+
self.sidebar_text.insert(f'end -1c', new_text, 'linenumber')
|
| 354 |
+
else:
|
| 355 |
+
self.sidebar_text.delete(f'{end+1}.0 -1c', 'end -1c')
|
| 356 |
+
|
| 357 |
+
self.prev_end = end
|
| 358 |
+
|
| 359 |
+
def yscroll_event(self, *args, **kwargs):
|
| 360 |
+
self.sidebar_text.yview_moveto(args[0])
|
| 361 |
+
return 'break'
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
class WrappedLineHeightChangeDelegator(Delegator):
|
| 365 |
+
def __init__(self, callback):
|
| 366 |
+
"""
|
| 367 |
+
callback - Callable, will be called when an insert, delete or replace
|
| 368 |
+
action on the text widget may require updating the shell
|
| 369 |
+
sidebar.
|
| 370 |
+
"""
|
| 371 |
+
Delegator.__init__(self)
|
| 372 |
+
self.callback = callback
|
| 373 |
+
|
| 374 |
+
def insert(self, index, chars, tags=None):
|
| 375 |
+
is_single_line = '\n' not in chars
|
| 376 |
+
if is_single_line:
|
| 377 |
+
before_displaylines = get_displaylines(self, index)
|
| 378 |
+
|
| 379 |
+
self.delegate.insert(index, chars, tags)
|
| 380 |
+
|
| 381 |
+
if is_single_line:
|
| 382 |
+
after_displaylines = get_displaylines(self, index)
|
| 383 |
+
if after_displaylines == before_displaylines:
|
| 384 |
+
return # no need to update the sidebar
|
| 385 |
+
|
| 386 |
+
self.callback()
|
| 387 |
+
|
| 388 |
+
def delete(self, index1, index2=None):
|
| 389 |
+
if index2 is None:
|
| 390 |
+
index2 = index1 + "+1c"
|
| 391 |
+
is_single_line = get_lineno(self, index1) == get_lineno(self, index2)
|
| 392 |
+
if is_single_line:
|
| 393 |
+
before_displaylines = get_displaylines(self, index1)
|
| 394 |
+
|
| 395 |
+
self.delegate.delete(index1, index2)
|
| 396 |
+
|
| 397 |
+
if is_single_line:
|
| 398 |
+
after_displaylines = get_displaylines(self, index1)
|
| 399 |
+
if after_displaylines == before_displaylines:
|
| 400 |
+
return # no need to update the sidebar
|
| 401 |
+
|
| 402 |
+
self.callback()
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
class ShellSidebar(BaseSideBar):
|
| 406 |
+
"""Sidebar for the PyShell window, for prompts etc."""
|
| 407 |
+
def __init__(self, editwin):
|
| 408 |
+
self.canvas = None
|
| 409 |
+
self.line_prompts = {}
|
| 410 |
+
|
| 411 |
+
super().__init__(editwin)
|
| 412 |
+
|
| 413 |
+
change_delegator = \
|
| 414 |
+
WrappedLineHeightChangeDelegator(self.change_callback)
|
| 415 |
+
# Insert the TextChangeDelegator after the last delegator, so that
|
| 416 |
+
# the sidebar reflects final changes to the text widget contents.
|
| 417 |
+
d = self.editwin.per.top
|
| 418 |
+
if d.delegate is not self.text:
|
| 419 |
+
while d.delegate is not self.editwin.per.bottom:
|
| 420 |
+
d = d.delegate
|
| 421 |
+
self.editwin.per.insertfilterafter(change_delegator, after=d)
|
| 422 |
+
|
| 423 |
+
self.is_shown = True
|
| 424 |
+
|
| 425 |
+
def init_widgets(self):
|
| 426 |
+
self.canvas = tk.Canvas(self.parent, width=30,
|
| 427 |
+
borderwidth=0, highlightthickness=0,
|
| 428 |
+
takefocus=False)
|
| 429 |
+
self.update_sidebar()
|
| 430 |
+
self.grid()
|
| 431 |
+
return self.canvas
|
| 432 |
+
|
| 433 |
+
def bind_events(self):
|
| 434 |
+
super().bind_events()
|
| 435 |
+
|
| 436 |
+
self.main_widget.bind(
|
| 437 |
+
# AquaTk defines <2> as the right button, not <3>.
|
| 438 |
+
"<Button-2>" if macosx.isAquaTk() else "<Button-3>",
|
| 439 |
+
self.context_menu_event,
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
def context_menu_event(self, event):
|
| 443 |
+
rmenu = tk.Menu(self.main_widget, tearoff=0)
|
| 444 |
+
has_selection = bool(self.text.tag_nextrange('sel', '1.0'))
|
| 445 |
+
def mkcmd(eventname):
|
| 446 |
+
return lambda: self.text.event_generate(eventname)
|
| 447 |
+
rmenu.add_command(label='Copy',
|
| 448 |
+
command=mkcmd('<<copy>>'),
|
| 449 |
+
state='normal' if has_selection else 'disabled')
|
| 450 |
+
rmenu.add_command(label='Copy with prompts',
|
| 451 |
+
command=mkcmd('<<copy-with-prompts>>'),
|
| 452 |
+
state='normal' if has_selection else 'disabled')
|
| 453 |
+
rmenu.tk_popup(event.x_root, event.y_root)
|
| 454 |
+
return "break"
|
| 455 |
+
|
| 456 |
+
def grid(self):
|
| 457 |
+
self.canvas.grid(row=1, column=0, sticky=tk.NSEW, padx=2, pady=0)
|
| 458 |
+
|
| 459 |
+
def change_callback(self):
|
| 460 |
+
if self.is_shown:
|
| 461 |
+
self.update_sidebar()
|
| 462 |
+
|
| 463 |
+
def update_sidebar(self):
|
| 464 |
+
text = self.text
|
| 465 |
+
text_tagnames = text.tag_names
|
| 466 |
+
canvas = self.canvas
|
| 467 |
+
line_prompts = self.line_prompts = {}
|
| 468 |
+
|
| 469 |
+
canvas.delete(tk.ALL)
|
| 470 |
+
|
| 471 |
+
index = text.index("@0,0")
|
| 472 |
+
if index.split('.', 1)[1] != '0':
|
| 473 |
+
index = text.index(f'{index}+1line linestart')
|
| 474 |
+
while (lineinfo := text.dlineinfo(index)) is not None:
|
| 475 |
+
y = lineinfo[1]
|
| 476 |
+
prev_newline_tagnames = text_tagnames(f"{index} linestart -1c")
|
| 477 |
+
prompt = (
|
| 478 |
+
'>>>' if "console" in prev_newline_tagnames else
|
| 479 |
+
'...' if "stdin" in prev_newline_tagnames else
|
| 480 |
+
None
|
| 481 |
+
)
|
| 482 |
+
if prompt:
|
| 483 |
+
canvas.create_text(2, y, anchor=tk.NW, text=prompt,
|
| 484 |
+
font=self.font, fill=self.colors[0])
|
| 485 |
+
lineno = get_lineno(text, index)
|
| 486 |
+
line_prompts[lineno] = prompt
|
| 487 |
+
index = text.index(f'{index}+1line')
|
| 488 |
+
|
| 489 |
+
def yscroll_event(self, *args, **kwargs):
|
| 490 |
+
"""Redirect vertical scrolling to the main editor text widget.
|
| 491 |
+
|
| 492 |
+
The scroll bar is also updated.
|
| 493 |
+
"""
|
| 494 |
+
self.change_callback()
|
| 495 |
+
return 'break'
|
| 496 |
+
|
| 497 |
+
def update_font(self):
|
| 498 |
+
"""Update the sidebar text font, usually after config changes."""
|
| 499 |
+
font = idleConf.GetFont(self.text, 'main', 'EditorWindow')
|
| 500 |
+
tk_font = Font(self.text, font=font)
|
| 501 |
+
char_width = max(tk_font.measure(char) for char in ['>', '.'])
|
| 502 |
+
self.canvas.configure(width=char_width * 3 + 4)
|
| 503 |
+
self.font = font
|
| 504 |
+
self.change_callback()
|
| 505 |
+
|
| 506 |
+
def update_colors(self):
|
| 507 |
+
"""Update the sidebar text colors, usually after config changes."""
|
| 508 |
+
linenumbers_colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'linenumber')
|
| 509 |
+
prompt_colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'console')
|
| 510 |
+
foreground = prompt_colors['foreground']
|
| 511 |
+
background = linenumbers_colors['background']
|
| 512 |
+
self.colors = (foreground, background)
|
| 513 |
+
self.canvas.configure(background=background)
|
| 514 |
+
self.change_callback()
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
def _linenumbers_drag_scrolling(parent): # htest #
|
| 518 |
+
from idlelib.idle_test.test_sidebar import Dummy_editwin
|
| 519 |
+
|
| 520 |
+
toplevel = tk.Toplevel(parent)
|
| 521 |
+
text_frame = tk.Frame(toplevel)
|
| 522 |
+
text_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
| 523 |
+
text_frame.rowconfigure(1, weight=1)
|
| 524 |
+
text_frame.columnconfigure(1, weight=1)
|
| 525 |
+
|
| 526 |
+
font = idleConf.GetFont(toplevel, 'main', 'EditorWindow')
|
| 527 |
+
text = tk.Text(text_frame, width=80, height=24, wrap=tk.NONE, font=font)
|
| 528 |
+
text.grid(row=1, column=1, sticky=tk.NSEW)
|
| 529 |
+
|
| 530 |
+
editwin = Dummy_editwin(text)
|
| 531 |
+
editwin.vbar = tk.Scrollbar(text_frame)
|
| 532 |
+
|
| 533 |
+
linenumbers = LineNumbers(editwin)
|
| 534 |
+
linenumbers.show_sidebar()
|
| 535 |
+
|
| 536 |
+
text.insert('1.0', '\n'.join('a'*i for i in range(1, 101)))
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
if __name__ == '__main__':
|
| 540 |
+
from unittest import main
|
| 541 |
+
main('idlelib.idle_test.test_sidebar', verbosity=2, exit=False)
|
| 542 |
+
|
| 543 |
+
from idlelib.idle_test.htest import run
|
| 544 |
+
run(_linenumbers_drag_scrolling)
|
llava/lib/python3.10/idlelib/squeezer.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""An IDLE extension to avoid having very long texts printed in the shell.
|
| 2 |
+
|
| 3 |
+
A common problem in IDLE's interactive shell is printing of large amounts of
|
| 4 |
+
text into the shell. This makes looking at the previous history difficult.
|
| 5 |
+
Worse, this can cause IDLE to become very slow, even to the point of being
|
| 6 |
+
completely unusable.
|
| 7 |
+
|
| 8 |
+
This extension will automatically replace long texts with a small button.
|
| 9 |
+
Double-clicking this button will remove it and insert the original text instead.
|
| 10 |
+
Middle-clicking will copy the text to the clipboard. Right-clicking will open
|
| 11 |
+
the text in a separate viewing window.
|
| 12 |
+
|
| 13 |
+
Additionally, any output can be manually "squeezed" by the user. This includes
|
| 14 |
+
output written to the standard error stream ("stderr"), such as exception
|
| 15 |
+
messages and their tracebacks.
|
| 16 |
+
"""
|
| 17 |
+
import re
|
| 18 |
+
|
| 19 |
+
import tkinter as tk
|
| 20 |
+
from tkinter import messagebox
|
| 21 |
+
|
| 22 |
+
from idlelib.config import idleConf
|
| 23 |
+
from idlelib.textview import view_text
|
| 24 |
+
from idlelib.tooltip import Hovertip
|
| 25 |
+
from idlelib import macosx
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def count_lines_with_wrapping(s, linewidth=80):
|
| 29 |
+
"""Count the number of lines in a given string.
|
| 30 |
+
|
| 31 |
+
Lines are counted as if the string was wrapped so that lines are never over
|
| 32 |
+
linewidth characters long.
|
| 33 |
+
|
| 34 |
+
Tabs are considered tabwidth characters long.
|
| 35 |
+
"""
|
| 36 |
+
tabwidth = 8 # Currently always true in Shell.
|
| 37 |
+
pos = 0
|
| 38 |
+
linecount = 1
|
| 39 |
+
current_column = 0
|
| 40 |
+
|
| 41 |
+
for m in re.finditer(r"[\t\n]", s):
|
| 42 |
+
# Process the normal chars up to tab or newline.
|
| 43 |
+
numchars = m.start() - pos
|
| 44 |
+
pos += numchars
|
| 45 |
+
current_column += numchars
|
| 46 |
+
|
| 47 |
+
# Deal with tab or newline.
|
| 48 |
+
if s[pos] == '\n':
|
| 49 |
+
# Avoid the `current_column == 0` edge-case, and while we're
|
| 50 |
+
# at it, don't bother adding 0.
|
| 51 |
+
if current_column > linewidth:
|
| 52 |
+
# If the current column was exactly linewidth, divmod
|
| 53 |
+
# would give (1,0), even though a new line hadn't yet
|
| 54 |
+
# been started. The same is true if length is any exact
|
| 55 |
+
# multiple of linewidth. Therefore, subtract 1 before
|
| 56 |
+
# dividing a non-empty line.
|
| 57 |
+
linecount += (current_column - 1) // linewidth
|
| 58 |
+
linecount += 1
|
| 59 |
+
current_column = 0
|
| 60 |
+
else:
|
| 61 |
+
assert s[pos] == '\t'
|
| 62 |
+
current_column += tabwidth - (current_column % tabwidth)
|
| 63 |
+
|
| 64 |
+
# If a tab passes the end of the line, consider the entire
|
| 65 |
+
# tab as being on the next line.
|
| 66 |
+
if current_column > linewidth:
|
| 67 |
+
linecount += 1
|
| 68 |
+
current_column = tabwidth
|
| 69 |
+
|
| 70 |
+
pos += 1 # After the tab or newline.
|
| 71 |
+
|
| 72 |
+
# Process remaining chars (no more tabs or newlines).
|
| 73 |
+
current_column += len(s) - pos
|
| 74 |
+
# Avoid divmod(-1, linewidth).
|
| 75 |
+
if current_column > 0:
|
| 76 |
+
linecount += (current_column - 1) // linewidth
|
| 77 |
+
else:
|
| 78 |
+
# Text ended with newline; don't count an extra line after it.
|
| 79 |
+
linecount -= 1
|
| 80 |
+
|
| 81 |
+
return linecount
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class ExpandingButton(tk.Button):
|
| 85 |
+
"""Class for the "squeezed" text buttons used by Squeezer
|
| 86 |
+
|
| 87 |
+
These buttons are displayed inside a Tk Text widget in place of text. A
|
| 88 |
+
user can then use the button to replace it with the original text, copy
|
| 89 |
+
the original text to the clipboard or view the original text in a separate
|
| 90 |
+
window.
|
| 91 |
+
|
| 92 |
+
Each button is tied to a Squeezer instance, and it knows to update the
|
| 93 |
+
Squeezer instance when it is expanded (and therefore removed).
|
| 94 |
+
"""
|
| 95 |
+
def __init__(self, s, tags, numoflines, squeezer):
|
| 96 |
+
self.s = s
|
| 97 |
+
self.tags = tags
|
| 98 |
+
self.numoflines = numoflines
|
| 99 |
+
self.squeezer = squeezer
|
| 100 |
+
self.editwin = editwin = squeezer.editwin
|
| 101 |
+
self.text = text = editwin.text
|
| 102 |
+
# The base Text widget is needed to change text before iomark.
|
| 103 |
+
self.base_text = editwin.per.bottom
|
| 104 |
+
|
| 105 |
+
line_plurality = "lines" if numoflines != 1 else "line"
|
| 106 |
+
button_text = f"Squeezed text ({numoflines} {line_plurality})."
|
| 107 |
+
tk.Button.__init__(self, text, text=button_text,
|
| 108 |
+
background="#FFFFC0", activebackground="#FFFFE0")
|
| 109 |
+
|
| 110 |
+
button_tooltip_text = (
|
| 111 |
+
"Double-click to expand, right-click for more options."
|
| 112 |
+
)
|
| 113 |
+
Hovertip(self, button_tooltip_text, hover_delay=80)
|
| 114 |
+
|
| 115 |
+
self.bind("<Double-Button-1>", self.expand)
|
| 116 |
+
if macosx.isAquaTk():
|
| 117 |
+
# AquaTk defines <2> as the right button, not <3>.
|
| 118 |
+
self.bind("<Button-2>", self.context_menu_event)
|
| 119 |
+
else:
|
| 120 |
+
self.bind("<Button-3>", self.context_menu_event)
|
| 121 |
+
self.selection_handle( # X windows only.
|
| 122 |
+
lambda offset, length: s[int(offset):int(offset) + int(length)])
|
| 123 |
+
|
| 124 |
+
self.is_dangerous = None
|
| 125 |
+
self.after_idle(self.set_is_dangerous)
|
| 126 |
+
|
| 127 |
+
def set_is_dangerous(self):
|
| 128 |
+
dangerous_line_len = 50 * self.text.winfo_width()
|
| 129 |
+
self.is_dangerous = (
|
| 130 |
+
self.numoflines > 1000 or
|
| 131 |
+
len(self.s) > 50000 or
|
| 132 |
+
any(
|
| 133 |
+
len(line_match.group(0)) >= dangerous_line_len
|
| 134 |
+
for line_match in re.finditer(r'[^\n]+', self.s)
|
| 135 |
+
)
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
def expand(self, event=None):
|
| 139 |
+
"""expand event handler
|
| 140 |
+
|
| 141 |
+
This inserts the original text in place of the button in the Text
|
| 142 |
+
widget, removes the button and updates the Squeezer instance.
|
| 143 |
+
|
| 144 |
+
If the original text is dangerously long, i.e. expanding it could
|
| 145 |
+
cause a performance degradation, ask the user for confirmation.
|
| 146 |
+
"""
|
| 147 |
+
if self.is_dangerous is None:
|
| 148 |
+
self.set_is_dangerous()
|
| 149 |
+
if self.is_dangerous:
|
| 150 |
+
confirm = messagebox.askokcancel(
|
| 151 |
+
title="Expand huge output?",
|
| 152 |
+
message="\n\n".join([
|
| 153 |
+
"The squeezed output is very long: %d lines, %d chars.",
|
| 154 |
+
"Expanding it could make IDLE slow or unresponsive.",
|
| 155 |
+
"It is recommended to view or copy the output instead.",
|
| 156 |
+
"Really expand?"
|
| 157 |
+
]) % (self.numoflines, len(self.s)),
|
| 158 |
+
default=messagebox.CANCEL,
|
| 159 |
+
parent=self.text)
|
| 160 |
+
if not confirm:
|
| 161 |
+
return "break"
|
| 162 |
+
|
| 163 |
+
index = self.text.index(self)
|
| 164 |
+
self.base_text.insert(index, self.s, self.tags)
|
| 165 |
+
self.base_text.delete(self)
|
| 166 |
+
self.editwin.on_squeezed_expand(index, self.s, self.tags)
|
| 167 |
+
self.squeezer.expandingbuttons.remove(self)
|
| 168 |
+
|
| 169 |
+
def copy(self, event=None):
|
| 170 |
+
"""copy event handler
|
| 171 |
+
|
| 172 |
+
Copy the original text to the clipboard.
|
| 173 |
+
"""
|
| 174 |
+
self.clipboard_clear()
|
| 175 |
+
self.clipboard_append(self.s)
|
| 176 |
+
|
| 177 |
+
def view(self, event=None):
|
| 178 |
+
"""view event handler
|
| 179 |
+
|
| 180 |
+
View the original text in a separate text viewer window.
|
| 181 |
+
"""
|
| 182 |
+
view_text(self.text, "Squeezed Output Viewer", self.s,
|
| 183 |
+
modal=False, wrap='none')
|
| 184 |
+
|
| 185 |
+
rmenu_specs = (
|
| 186 |
+
# Item structure: (label, method_name).
|
| 187 |
+
('copy', 'copy'),
|
| 188 |
+
('view', 'view'),
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
def context_menu_event(self, event):
|
| 192 |
+
self.text.mark_set("insert", "@%d,%d" % (event.x, event.y))
|
| 193 |
+
rmenu = tk.Menu(self.text, tearoff=0)
|
| 194 |
+
for label, method_name in self.rmenu_specs:
|
| 195 |
+
rmenu.add_command(label=label, command=getattr(self, method_name))
|
| 196 |
+
rmenu.tk_popup(event.x_root, event.y_root)
|
| 197 |
+
return "break"
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class Squeezer:
|
| 201 |
+
"""Replace long outputs in the shell with a simple button.
|
| 202 |
+
|
| 203 |
+
This avoids IDLE's shell slowing down considerably, and even becoming
|
| 204 |
+
completely unresponsive, when very long outputs are written.
|
| 205 |
+
"""
|
| 206 |
+
@classmethod
|
| 207 |
+
def reload(cls):
|
| 208 |
+
"""Load class variables from config."""
|
| 209 |
+
cls.auto_squeeze_min_lines = idleConf.GetOption(
|
| 210 |
+
"main", "PyShell", "auto-squeeze-min-lines",
|
| 211 |
+
type="int", default=50,
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
def __init__(self, editwin):
|
| 215 |
+
"""Initialize settings for Squeezer.
|
| 216 |
+
|
| 217 |
+
editwin is the shell's Editor window.
|
| 218 |
+
self.text is the editor window text widget.
|
| 219 |
+
self.base_test is the actual editor window Tk text widget, rather than
|
| 220 |
+
EditorWindow's wrapper.
|
| 221 |
+
self.expandingbuttons is the list of all buttons representing
|
| 222 |
+
"squeezed" output.
|
| 223 |
+
"""
|
| 224 |
+
self.editwin = editwin
|
| 225 |
+
self.text = text = editwin.text
|
| 226 |
+
|
| 227 |
+
# Get the base Text widget of the PyShell object, used to change
|
| 228 |
+
# text before the iomark. PyShell deliberately disables changing
|
| 229 |
+
# text before the iomark via its 'text' attribute, which is
|
| 230 |
+
# actually a wrapper for the actual Text widget. Squeezer,
|
| 231 |
+
# however, needs to make such changes.
|
| 232 |
+
self.base_text = editwin.per.bottom
|
| 233 |
+
|
| 234 |
+
# Twice the text widget's border width and internal padding;
|
| 235 |
+
# pre-calculated here for the get_line_width() method.
|
| 236 |
+
self.window_width_delta = 2 * (
|
| 237 |
+
int(text.cget('border')) +
|
| 238 |
+
int(text.cget('padx'))
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
self.expandingbuttons = []
|
| 242 |
+
|
| 243 |
+
# Replace the PyShell instance's write method with a wrapper,
|
| 244 |
+
# which inserts an ExpandingButton instead of a long text.
|
| 245 |
+
def mywrite(s, tags=(), write=editwin.write):
|
| 246 |
+
# Only auto-squeeze text which has just the "stdout" tag.
|
| 247 |
+
if tags != "stdout":
|
| 248 |
+
return write(s, tags)
|
| 249 |
+
|
| 250 |
+
# Only auto-squeeze text with at least the minimum
|
| 251 |
+
# configured number of lines.
|
| 252 |
+
auto_squeeze_min_lines = self.auto_squeeze_min_lines
|
| 253 |
+
# First, a very quick check to skip very short texts.
|
| 254 |
+
if len(s) < auto_squeeze_min_lines:
|
| 255 |
+
return write(s, tags)
|
| 256 |
+
# Now the full line-count check.
|
| 257 |
+
numoflines = self.count_lines(s)
|
| 258 |
+
if numoflines < auto_squeeze_min_lines:
|
| 259 |
+
return write(s, tags)
|
| 260 |
+
|
| 261 |
+
# Create an ExpandingButton instance.
|
| 262 |
+
expandingbutton = ExpandingButton(s, tags, numoflines, self)
|
| 263 |
+
|
| 264 |
+
# Insert the ExpandingButton into the Text widget.
|
| 265 |
+
text.mark_gravity("iomark", tk.RIGHT)
|
| 266 |
+
text.window_create("iomark", window=expandingbutton,
|
| 267 |
+
padx=3, pady=5)
|
| 268 |
+
text.see("iomark")
|
| 269 |
+
text.update()
|
| 270 |
+
text.mark_gravity("iomark", tk.LEFT)
|
| 271 |
+
|
| 272 |
+
# Add the ExpandingButton to the Squeezer's list.
|
| 273 |
+
self.expandingbuttons.append(expandingbutton)
|
| 274 |
+
|
| 275 |
+
editwin.write = mywrite
|
| 276 |
+
|
| 277 |
+
def count_lines(self, s):
|
| 278 |
+
"""Count the number of lines in a given text.
|
| 279 |
+
|
| 280 |
+
Before calculation, the tab width and line length of the text are
|
| 281 |
+
fetched, so that up-to-date values are used.
|
| 282 |
+
|
| 283 |
+
Lines are counted as if the string was wrapped so that lines are never
|
| 284 |
+
over linewidth characters long.
|
| 285 |
+
|
| 286 |
+
Tabs are considered tabwidth characters long.
|
| 287 |
+
"""
|
| 288 |
+
return count_lines_with_wrapping(s, self.editwin.width)
|
| 289 |
+
|
| 290 |
+
def squeeze_current_text(self):
|
| 291 |
+
"""Squeeze the text block where the insertion cursor is.
|
| 292 |
+
|
| 293 |
+
If the cursor is not in a squeezable block of text, give the
|
| 294 |
+
user a small warning and do nothing.
|
| 295 |
+
"""
|
| 296 |
+
# Set tag_name to the first valid tag found on the "insert" cursor.
|
| 297 |
+
tag_names = self.text.tag_names(tk.INSERT)
|
| 298 |
+
for tag_name in ("stdout", "stderr"):
|
| 299 |
+
if tag_name in tag_names:
|
| 300 |
+
break
|
| 301 |
+
else:
|
| 302 |
+
# The insert cursor doesn't have a "stdout" or "stderr" tag.
|
| 303 |
+
self.text.bell()
|
| 304 |
+
return "break"
|
| 305 |
+
|
| 306 |
+
# Find the range to squeeze.
|
| 307 |
+
start, end = self.text.tag_prevrange(tag_name, tk.INSERT + "+1c")
|
| 308 |
+
s = self.text.get(start, end)
|
| 309 |
+
|
| 310 |
+
# If the last char is a newline, remove it from the range.
|
| 311 |
+
if len(s) > 0 and s[-1] == '\n':
|
| 312 |
+
end = self.text.index("%s-1c" % end)
|
| 313 |
+
s = s[:-1]
|
| 314 |
+
|
| 315 |
+
# Delete the text.
|
| 316 |
+
self.base_text.delete(start, end)
|
| 317 |
+
|
| 318 |
+
# Prepare an ExpandingButton.
|
| 319 |
+
numoflines = self.count_lines(s)
|
| 320 |
+
expandingbutton = ExpandingButton(s, tag_name, numoflines, self)
|
| 321 |
+
|
| 322 |
+
# insert the ExpandingButton to the Text
|
| 323 |
+
self.text.window_create(start, window=expandingbutton,
|
| 324 |
+
padx=3, pady=5)
|
| 325 |
+
|
| 326 |
+
# Insert the ExpandingButton to the list of ExpandingButtons,
|
| 327 |
+
# while keeping the list ordered according to the position of
|
| 328 |
+
# the buttons in the Text widget.
|
| 329 |
+
i = len(self.expandingbuttons)
|
| 330 |
+
while i > 0 and self.text.compare(self.expandingbuttons[i-1],
|
| 331 |
+
">", expandingbutton):
|
| 332 |
+
i -= 1
|
| 333 |
+
self.expandingbuttons.insert(i, expandingbutton)
|
| 334 |
+
|
| 335 |
+
return "break"
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
Squeezer.reload()
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
if __name__ == "__main__":
|
| 342 |
+
from unittest import main
|
| 343 |
+
main('idlelib.idle_test.test_squeezer', verbosity=2, exit=False)
|
| 344 |
+
|
| 345 |
+
# Add htest.
|
llava/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)
|
llava/lib/python3.10/idlelib/tree.py
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# XXX TO DO:
|
| 2 |
+
# - popup menu
|
| 3 |
+
# - support partial or total redisplay
|
| 4 |
+
# - key bindings (instead of quick-n-dirty bindings on Canvas):
|
| 5 |
+
# - up/down arrow keys to move focus around
|
| 6 |
+
# - ditto for page up/down, home/end
|
| 7 |
+
# - left/right arrows to expand/collapse & move out/in
|
| 8 |
+
# - more doc strings
|
| 9 |
+
# - add icons for "file", "module", "class", "method"; better "python" icon
|
| 10 |
+
# - callback for selection???
|
| 11 |
+
# - multiple-item selection
|
| 12 |
+
# - tooltips
|
| 13 |
+
# - redo geometry without magic numbers
|
| 14 |
+
# - keep track of object ids to allow more careful cleaning
|
| 15 |
+
# - optimize tree redraw after expand of subnode
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
|
| 19 |
+
from tkinter import *
|
| 20 |
+
from tkinter.ttk import Frame, Scrollbar
|
| 21 |
+
|
| 22 |
+
from idlelib.config import idleConf
|
| 23 |
+
from idlelib import zoomheight
|
| 24 |
+
|
| 25 |
+
ICONDIR = "Icons"
|
| 26 |
+
|
| 27 |
+
# Look for Icons subdirectory in the same directory as this module
|
| 28 |
+
try:
|
| 29 |
+
_icondir = os.path.join(os.path.dirname(__file__), ICONDIR)
|
| 30 |
+
except NameError:
|
| 31 |
+
_icondir = ICONDIR
|
| 32 |
+
if os.path.isdir(_icondir):
|
| 33 |
+
ICONDIR = _icondir
|
| 34 |
+
elif not os.path.isdir(ICONDIR):
|
| 35 |
+
raise RuntimeError("can't find icon directory (%r)" % (ICONDIR,))
|
| 36 |
+
|
| 37 |
+
def listicons(icondir=ICONDIR):
|
| 38 |
+
"""Utility to display the available icons."""
|
| 39 |
+
root = Tk()
|
| 40 |
+
import glob
|
| 41 |
+
list = glob.glob(os.path.join(glob.escape(icondir), "*.gif"))
|
| 42 |
+
list.sort()
|
| 43 |
+
images = []
|
| 44 |
+
row = column = 0
|
| 45 |
+
for file in list:
|
| 46 |
+
name = os.path.splitext(os.path.basename(file))[0]
|
| 47 |
+
image = PhotoImage(file=file, master=root)
|
| 48 |
+
images.append(image)
|
| 49 |
+
label = Label(root, image=image, bd=1, relief="raised")
|
| 50 |
+
label.grid(row=row, column=column)
|
| 51 |
+
label = Label(root, text=name)
|
| 52 |
+
label.grid(row=row+1, column=column)
|
| 53 |
+
column = column + 1
|
| 54 |
+
if column >= 10:
|
| 55 |
+
row = row+2
|
| 56 |
+
column = 0
|
| 57 |
+
root.images = images
|
| 58 |
+
|
| 59 |
+
def wheel_event(event, widget=None):
|
| 60 |
+
"""Handle scrollwheel event.
|
| 61 |
+
|
| 62 |
+
For wheel up, event.delta = 120*n on Windows, -1*n on darwin,
|
| 63 |
+
where n can be > 1 if one scrolls fast. Flicking the wheel
|
| 64 |
+
generates up to maybe 20 events with n up to 10 or more 1.
|
| 65 |
+
Macs use wheel down (delta = 1*n) to scroll up, so positive
|
| 66 |
+
delta means to scroll up on both systems.
|
| 67 |
+
|
| 68 |
+
X-11 sends Control-Button-4,5 events instead.
|
| 69 |
+
|
| 70 |
+
The widget parameter is needed so browser label bindings can pass
|
| 71 |
+
the underlying canvas.
|
| 72 |
+
|
| 73 |
+
This function depends on widget.yview to not be overridden by
|
| 74 |
+
a subclass.
|
| 75 |
+
"""
|
| 76 |
+
up = {EventType.MouseWheel: event.delta > 0,
|
| 77 |
+
EventType.ButtonPress: event.num == 4}
|
| 78 |
+
lines = -5 if up[event.type] else 5
|
| 79 |
+
widget = event.widget if widget is None else widget
|
| 80 |
+
widget.yview(SCROLL, lines, 'units')
|
| 81 |
+
return 'break'
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class TreeNode:
|
| 85 |
+
|
| 86 |
+
def __init__(self, canvas, parent, item):
|
| 87 |
+
self.canvas = canvas
|
| 88 |
+
self.parent = parent
|
| 89 |
+
self.item = item
|
| 90 |
+
self.state = 'collapsed'
|
| 91 |
+
self.selected = False
|
| 92 |
+
self.children = []
|
| 93 |
+
self.x = self.y = None
|
| 94 |
+
self.iconimages = {} # cache of PhotoImage instances for icons
|
| 95 |
+
|
| 96 |
+
def destroy(self):
|
| 97 |
+
for c in self.children[:]:
|
| 98 |
+
self.children.remove(c)
|
| 99 |
+
c.destroy()
|
| 100 |
+
self.parent = None
|
| 101 |
+
|
| 102 |
+
def geticonimage(self, name):
|
| 103 |
+
try:
|
| 104 |
+
return self.iconimages[name]
|
| 105 |
+
except KeyError:
|
| 106 |
+
pass
|
| 107 |
+
file, ext = os.path.splitext(name)
|
| 108 |
+
ext = ext or ".gif"
|
| 109 |
+
fullname = os.path.join(ICONDIR, file + ext)
|
| 110 |
+
image = PhotoImage(master=self.canvas, file=fullname)
|
| 111 |
+
self.iconimages[name] = image
|
| 112 |
+
return image
|
| 113 |
+
|
| 114 |
+
def select(self, event=None):
|
| 115 |
+
if self.selected:
|
| 116 |
+
return
|
| 117 |
+
self.deselectall()
|
| 118 |
+
self.selected = True
|
| 119 |
+
self.canvas.delete(self.image_id)
|
| 120 |
+
self.drawicon()
|
| 121 |
+
self.drawtext()
|
| 122 |
+
|
| 123 |
+
def deselect(self, event=None):
|
| 124 |
+
if not self.selected:
|
| 125 |
+
return
|
| 126 |
+
self.selected = False
|
| 127 |
+
self.canvas.delete(self.image_id)
|
| 128 |
+
self.drawicon()
|
| 129 |
+
self.drawtext()
|
| 130 |
+
|
| 131 |
+
def deselectall(self):
|
| 132 |
+
if self.parent:
|
| 133 |
+
self.parent.deselectall()
|
| 134 |
+
else:
|
| 135 |
+
self.deselecttree()
|
| 136 |
+
|
| 137 |
+
def deselecttree(self):
|
| 138 |
+
if self.selected:
|
| 139 |
+
self.deselect()
|
| 140 |
+
for child in self.children:
|
| 141 |
+
child.deselecttree()
|
| 142 |
+
|
| 143 |
+
def flip(self, event=None):
|
| 144 |
+
if self.state == 'expanded':
|
| 145 |
+
self.collapse()
|
| 146 |
+
else:
|
| 147 |
+
self.expand()
|
| 148 |
+
self.item.OnDoubleClick()
|
| 149 |
+
return "break"
|
| 150 |
+
|
| 151 |
+
def expand(self, event=None):
|
| 152 |
+
if not self.item._IsExpandable():
|
| 153 |
+
return
|
| 154 |
+
if self.state != 'expanded':
|
| 155 |
+
self.state = 'expanded'
|
| 156 |
+
self.update()
|
| 157 |
+
self.view()
|
| 158 |
+
|
| 159 |
+
def collapse(self, event=None):
|
| 160 |
+
if self.state != 'collapsed':
|
| 161 |
+
self.state = 'collapsed'
|
| 162 |
+
self.update()
|
| 163 |
+
|
| 164 |
+
def view(self):
|
| 165 |
+
top = self.y - 2
|
| 166 |
+
bottom = self.lastvisiblechild().y + 17
|
| 167 |
+
height = bottom - top
|
| 168 |
+
visible_top = self.canvas.canvasy(0)
|
| 169 |
+
visible_height = self.canvas.winfo_height()
|
| 170 |
+
visible_bottom = self.canvas.canvasy(visible_height)
|
| 171 |
+
if visible_top <= top and bottom <= visible_bottom:
|
| 172 |
+
return
|
| 173 |
+
x0, y0, x1, y1 = self.canvas._getints(self.canvas['scrollregion'])
|
| 174 |
+
if top >= visible_top and height <= visible_height:
|
| 175 |
+
fraction = top + height - visible_height
|
| 176 |
+
else:
|
| 177 |
+
fraction = top
|
| 178 |
+
fraction = float(fraction) / y1
|
| 179 |
+
self.canvas.yview_moveto(fraction)
|
| 180 |
+
|
| 181 |
+
def lastvisiblechild(self):
|
| 182 |
+
if self.children and self.state == 'expanded':
|
| 183 |
+
return self.children[-1].lastvisiblechild()
|
| 184 |
+
else:
|
| 185 |
+
return self
|
| 186 |
+
|
| 187 |
+
def update(self):
|
| 188 |
+
if self.parent:
|
| 189 |
+
self.parent.update()
|
| 190 |
+
else:
|
| 191 |
+
oldcursor = self.canvas['cursor']
|
| 192 |
+
self.canvas['cursor'] = "watch"
|
| 193 |
+
self.canvas.update()
|
| 194 |
+
self.canvas.delete(ALL) # XXX could be more subtle
|
| 195 |
+
self.draw(7, 2)
|
| 196 |
+
x0, y0, x1, y1 = self.canvas.bbox(ALL)
|
| 197 |
+
self.canvas.configure(scrollregion=(0, 0, x1, y1))
|
| 198 |
+
self.canvas['cursor'] = oldcursor
|
| 199 |
+
|
| 200 |
+
def draw(self, x, y):
|
| 201 |
+
# XXX This hard-codes too many geometry constants!
|
| 202 |
+
dy = 20
|
| 203 |
+
self.x, self.y = x, y
|
| 204 |
+
self.drawicon()
|
| 205 |
+
self.drawtext()
|
| 206 |
+
if self.state != 'expanded':
|
| 207 |
+
return y + dy
|
| 208 |
+
# draw children
|
| 209 |
+
if not self.children:
|
| 210 |
+
sublist = self.item._GetSubList()
|
| 211 |
+
if not sublist:
|
| 212 |
+
# _IsExpandable() was mistaken; that's allowed
|
| 213 |
+
return y+17
|
| 214 |
+
for item in sublist:
|
| 215 |
+
child = self.__class__(self.canvas, self, item)
|
| 216 |
+
self.children.append(child)
|
| 217 |
+
cx = x+20
|
| 218 |
+
cy = y + dy
|
| 219 |
+
cylast = 0
|
| 220 |
+
for child in self.children:
|
| 221 |
+
cylast = cy
|
| 222 |
+
self.canvas.create_line(x+9, cy+7, cx, cy+7, fill="gray50")
|
| 223 |
+
cy = child.draw(cx, cy)
|
| 224 |
+
if child.item._IsExpandable():
|
| 225 |
+
if child.state == 'expanded':
|
| 226 |
+
iconname = "minusnode"
|
| 227 |
+
callback = child.collapse
|
| 228 |
+
else:
|
| 229 |
+
iconname = "plusnode"
|
| 230 |
+
callback = child.expand
|
| 231 |
+
image = self.geticonimage(iconname)
|
| 232 |
+
id = self.canvas.create_image(x+9, cylast+7, image=image)
|
| 233 |
+
# XXX This leaks bindings until canvas is deleted:
|
| 234 |
+
self.canvas.tag_bind(id, "<1>", callback)
|
| 235 |
+
self.canvas.tag_bind(id, "<Double-1>", lambda x: None)
|
| 236 |
+
id = self.canvas.create_line(x+9, y+10, x+9, cylast+7,
|
| 237 |
+
##stipple="gray50", # XXX Seems broken in Tk 8.0.x
|
| 238 |
+
fill="gray50")
|
| 239 |
+
self.canvas.tag_lower(id) # XXX .lower(id) before Python 1.5.2
|
| 240 |
+
return cy
|
| 241 |
+
|
| 242 |
+
def drawicon(self):
|
| 243 |
+
if self.selected:
|
| 244 |
+
imagename = (self.item.GetSelectedIconName() or
|
| 245 |
+
self.item.GetIconName() or
|
| 246 |
+
"openfolder")
|
| 247 |
+
else:
|
| 248 |
+
imagename = self.item.GetIconName() or "folder"
|
| 249 |
+
image = self.geticonimage(imagename)
|
| 250 |
+
id = self.canvas.create_image(self.x, self.y, anchor="nw", image=image)
|
| 251 |
+
self.image_id = id
|
| 252 |
+
self.canvas.tag_bind(id, "<1>", self.select)
|
| 253 |
+
self.canvas.tag_bind(id, "<Double-1>", self.flip)
|
| 254 |
+
|
| 255 |
+
def drawtext(self):
|
| 256 |
+
textx = self.x+20-1
|
| 257 |
+
texty = self.y-4
|
| 258 |
+
labeltext = self.item.GetLabelText()
|
| 259 |
+
if labeltext:
|
| 260 |
+
id = self.canvas.create_text(textx, texty, anchor="nw",
|
| 261 |
+
text=labeltext)
|
| 262 |
+
self.canvas.tag_bind(id, "<1>", self.select)
|
| 263 |
+
self.canvas.tag_bind(id, "<Double-1>", self.flip)
|
| 264 |
+
x0, y0, x1, y1 = self.canvas.bbox(id)
|
| 265 |
+
textx = max(x1, 200) + 10
|
| 266 |
+
text = self.item.GetText() or "<no text>"
|
| 267 |
+
try:
|
| 268 |
+
self.entry
|
| 269 |
+
except AttributeError:
|
| 270 |
+
pass
|
| 271 |
+
else:
|
| 272 |
+
self.edit_finish()
|
| 273 |
+
try:
|
| 274 |
+
self.label
|
| 275 |
+
except AttributeError:
|
| 276 |
+
# padding carefully selected (on Windows) to match Entry widget:
|
| 277 |
+
self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
|
| 278 |
+
theme = idleConf.CurrentTheme()
|
| 279 |
+
if self.selected:
|
| 280 |
+
self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
|
| 281 |
+
else:
|
| 282 |
+
self.label.configure(idleConf.GetHighlight(theme, 'normal'))
|
| 283 |
+
id = self.canvas.create_window(textx, texty,
|
| 284 |
+
anchor="nw", window=self.label)
|
| 285 |
+
self.label.bind("<1>", self.select_or_edit)
|
| 286 |
+
self.label.bind("<Double-1>", self.flip)
|
| 287 |
+
self.label.bind("<MouseWheel>", lambda e: wheel_event(e, self.canvas))
|
| 288 |
+
self.label.bind("<Button-4>", lambda e: wheel_event(e, self.canvas))
|
| 289 |
+
self.label.bind("<Button-5>", lambda e: wheel_event(e, self.canvas))
|
| 290 |
+
self.text_id = id
|
| 291 |
+
|
| 292 |
+
def select_or_edit(self, event=None):
|
| 293 |
+
if self.selected and self.item.IsEditable():
|
| 294 |
+
self.edit(event)
|
| 295 |
+
else:
|
| 296 |
+
self.select(event)
|
| 297 |
+
|
| 298 |
+
def edit(self, event=None):
|
| 299 |
+
self.entry = Entry(self.label, bd=0, highlightthickness=1, width=0)
|
| 300 |
+
self.entry.insert(0, self.label['text'])
|
| 301 |
+
self.entry.selection_range(0, END)
|
| 302 |
+
self.entry.pack(ipadx=5)
|
| 303 |
+
self.entry.focus_set()
|
| 304 |
+
self.entry.bind("<Return>", self.edit_finish)
|
| 305 |
+
self.entry.bind("<Escape>", self.edit_cancel)
|
| 306 |
+
|
| 307 |
+
def edit_finish(self, event=None):
|
| 308 |
+
try:
|
| 309 |
+
entry = self.entry
|
| 310 |
+
del self.entry
|
| 311 |
+
except AttributeError:
|
| 312 |
+
return
|
| 313 |
+
text = entry.get()
|
| 314 |
+
entry.destroy()
|
| 315 |
+
if text and text != self.item.GetText():
|
| 316 |
+
self.item.SetText(text)
|
| 317 |
+
text = self.item.GetText()
|
| 318 |
+
self.label['text'] = text
|
| 319 |
+
self.drawtext()
|
| 320 |
+
self.canvas.focus_set()
|
| 321 |
+
|
| 322 |
+
def edit_cancel(self, event=None):
|
| 323 |
+
try:
|
| 324 |
+
entry = self.entry
|
| 325 |
+
del self.entry
|
| 326 |
+
except AttributeError:
|
| 327 |
+
return
|
| 328 |
+
entry.destroy()
|
| 329 |
+
self.drawtext()
|
| 330 |
+
self.canvas.focus_set()
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
class TreeItem:
|
| 334 |
+
|
| 335 |
+
"""Abstract class representing tree items.
|
| 336 |
+
|
| 337 |
+
Methods should typically be overridden, otherwise a default action
|
| 338 |
+
is used.
|
| 339 |
+
|
| 340 |
+
"""
|
| 341 |
+
|
| 342 |
+
def __init__(self):
|
| 343 |
+
"""Constructor. Do whatever you need to do."""
|
| 344 |
+
|
| 345 |
+
def GetText(self):
|
| 346 |
+
"""Return text string to display."""
|
| 347 |
+
|
| 348 |
+
def GetLabelText(self):
|
| 349 |
+
"""Return label text string to display in front of text (if any)."""
|
| 350 |
+
|
| 351 |
+
expandable = None
|
| 352 |
+
|
| 353 |
+
def _IsExpandable(self):
|
| 354 |
+
"""Do not override! Called by TreeNode."""
|
| 355 |
+
if self.expandable is None:
|
| 356 |
+
self.expandable = self.IsExpandable()
|
| 357 |
+
return self.expandable
|
| 358 |
+
|
| 359 |
+
def IsExpandable(self):
|
| 360 |
+
"""Return whether there are subitems."""
|
| 361 |
+
return 1
|
| 362 |
+
|
| 363 |
+
def _GetSubList(self):
|
| 364 |
+
"""Do not override! Called by TreeNode."""
|
| 365 |
+
if not self.IsExpandable():
|
| 366 |
+
return []
|
| 367 |
+
sublist = self.GetSubList()
|
| 368 |
+
if not sublist:
|
| 369 |
+
self.expandable = 0
|
| 370 |
+
return sublist
|
| 371 |
+
|
| 372 |
+
def IsEditable(self):
|
| 373 |
+
"""Return whether the item's text may be edited."""
|
| 374 |
+
|
| 375 |
+
def SetText(self, text):
|
| 376 |
+
"""Change the item's text (if it is editable)."""
|
| 377 |
+
|
| 378 |
+
def GetIconName(self):
|
| 379 |
+
"""Return name of icon to be displayed normally."""
|
| 380 |
+
|
| 381 |
+
def GetSelectedIconName(self):
|
| 382 |
+
"""Return name of icon to be displayed when selected."""
|
| 383 |
+
|
| 384 |
+
def GetSubList(self):
|
| 385 |
+
"""Return list of items forming sublist."""
|
| 386 |
+
|
| 387 |
+
def OnDoubleClick(self):
|
| 388 |
+
"""Called on a double-click on the item."""
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
# Example application
|
| 392 |
+
|
| 393 |
+
class FileTreeItem(TreeItem):
|
| 394 |
+
|
| 395 |
+
"""Example TreeItem subclass -- browse the file system."""
|
| 396 |
+
|
| 397 |
+
def __init__(self, path):
|
| 398 |
+
self.path = path
|
| 399 |
+
|
| 400 |
+
def GetText(self):
|
| 401 |
+
return os.path.basename(self.path) or self.path
|
| 402 |
+
|
| 403 |
+
def IsEditable(self):
|
| 404 |
+
return os.path.basename(self.path) != ""
|
| 405 |
+
|
| 406 |
+
def SetText(self, text):
|
| 407 |
+
newpath = os.path.dirname(self.path)
|
| 408 |
+
newpath = os.path.join(newpath, text)
|
| 409 |
+
if os.path.dirname(newpath) != os.path.dirname(self.path):
|
| 410 |
+
return
|
| 411 |
+
try:
|
| 412 |
+
os.rename(self.path, newpath)
|
| 413 |
+
self.path = newpath
|
| 414 |
+
except OSError:
|
| 415 |
+
pass
|
| 416 |
+
|
| 417 |
+
def GetIconName(self):
|
| 418 |
+
if not self.IsExpandable():
|
| 419 |
+
return "python" # XXX wish there was a "file" icon
|
| 420 |
+
|
| 421 |
+
def IsExpandable(self):
|
| 422 |
+
return os.path.isdir(self.path)
|
| 423 |
+
|
| 424 |
+
def GetSubList(self):
|
| 425 |
+
try:
|
| 426 |
+
names = os.listdir(self.path)
|
| 427 |
+
except OSError:
|
| 428 |
+
return []
|
| 429 |
+
names.sort(key = os.path.normcase)
|
| 430 |
+
sublist = []
|
| 431 |
+
for name in names:
|
| 432 |
+
item = FileTreeItem(os.path.join(self.path, name))
|
| 433 |
+
sublist.append(item)
|
| 434 |
+
return sublist
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
# A canvas widget with scroll bars and some useful bindings
|
| 438 |
+
|
| 439 |
+
class ScrolledCanvas:
|
| 440 |
+
|
| 441 |
+
def __init__(self, master, **opts):
|
| 442 |
+
if 'yscrollincrement' not in opts:
|
| 443 |
+
opts['yscrollincrement'] = 17
|
| 444 |
+
self.master = master
|
| 445 |
+
self.frame = Frame(master)
|
| 446 |
+
self.frame.rowconfigure(0, weight=1)
|
| 447 |
+
self.frame.columnconfigure(0, weight=1)
|
| 448 |
+
self.canvas = Canvas(self.frame, **opts)
|
| 449 |
+
self.canvas.grid(row=0, column=0, sticky="nsew")
|
| 450 |
+
self.vbar = Scrollbar(self.frame, name="vbar")
|
| 451 |
+
self.vbar.grid(row=0, column=1, sticky="nse")
|
| 452 |
+
self.hbar = Scrollbar(self.frame, name="hbar", orient="horizontal")
|
| 453 |
+
self.hbar.grid(row=1, column=0, sticky="ews")
|
| 454 |
+
self.canvas['yscrollcommand'] = self.vbar.set
|
| 455 |
+
self.vbar['command'] = self.canvas.yview
|
| 456 |
+
self.canvas['xscrollcommand'] = self.hbar.set
|
| 457 |
+
self.hbar['command'] = self.canvas.xview
|
| 458 |
+
self.canvas.bind("<Key-Prior>", self.page_up)
|
| 459 |
+
self.canvas.bind("<Key-Next>", self.page_down)
|
| 460 |
+
self.canvas.bind("<Key-Up>", self.unit_up)
|
| 461 |
+
self.canvas.bind("<Key-Down>", self.unit_down)
|
| 462 |
+
self.canvas.bind("<MouseWheel>", wheel_event)
|
| 463 |
+
self.canvas.bind("<Button-4>", wheel_event)
|
| 464 |
+
self.canvas.bind("<Button-5>", wheel_event)
|
| 465 |
+
#if isinstance(master, Toplevel) or isinstance(master, Tk):
|
| 466 |
+
self.canvas.bind("<Alt-Key-2>", self.zoom_height)
|
| 467 |
+
self.canvas.focus_set()
|
| 468 |
+
def page_up(self, event):
|
| 469 |
+
self.canvas.yview_scroll(-1, "page")
|
| 470 |
+
return "break"
|
| 471 |
+
def page_down(self, event):
|
| 472 |
+
self.canvas.yview_scroll(1, "page")
|
| 473 |
+
return "break"
|
| 474 |
+
def unit_up(self, event):
|
| 475 |
+
self.canvas.yview_scroll(-1, "unit")
|
| 476 |
+
return "break"
|
| 477 |
+
def unit_down(self, event):
|
| 478 |
+
self.canvas.yview_scroll(1, "unit")
|
| 479 |
+
return "break"
|
| 480 |
+
def zoom_height(self, event):
|
| 481 |
+
zoomheight.zoom_height(self.master)
|
| 482 |
+
return "break"
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def _tree_widget(parent): # htest #
|
| 486 |
+
top = Toplevel(parent)
|
| 487 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 488 |
+
top.geometry("+%d+%d" % (x+50, y+175))
|
| 489 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
| 490 |
+
sc.frame.pack(expand=1, fill="both", side=LEFT)
|
| 491 |
+
item = FileTreeItem(ICONDIR)
|
| 492 |
+
node = TreeNode(sc.canvas, None, item)
|
| 493 |
+
node.expand()
|
| 494 |
+
|
| 495 |
+
if __name__ == '__main__':
|
| 496 |
+
from unittest import main
|
| 497 |
+
main('idlelib.idle_test.test_tree', verbosity=2, exit=False)
|
| 498 |
+
|
| 499 |
+
from idlelib.idle_test.htest import run
|
| 500 |
+
run(_tree_widget)
|
llava/lib/python3.10/idlelib/undo.py
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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create widgets,
|
| 6 |
+
# although many methods operate on text widget arguments.
|
| 7 |
+
|
| 8 |
+
#$ event <<redo>>
|
| 9 |
+
#$ win <Control-y>
|
| 10 |
+
#$ unix <Alt-z>
|
| 11 |
+
|
| 12 |
+
#$ event <<undo>>
|
| 13 |
+
#$ win <Control-z>
|
| 14 |
+
#$ unix <Control-z>
|
| 15 |
+
|
| 16 |
+
#$ event <<dump-undo-state>>
|
| 17 |
+
#$ win <Control-backslash>
|
| 18 |
+
#$ unix <Control-backslash>
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class UndoDelegator(Delegator):
|
| 22 |
+
|
| 23 |
+
max_undo = 1000
|
| 24 |
+
|
| 25 |
+
def __init__(self):
|
| 26 |
+
Delegator.__init__(self)
|
| 27 |
+
self.reset_undo()
|
| 28 |
+
|
| 29 |
+
def setdelegate(self, delegate):
|
| 30 |
+
if self.delegate is not None:
|
| 31 |
+
self.unbind("<<undo>>")
|
| 32 |
+
self.unbind("<<redo>>")
|
| 33 |
+
self.unbind("<<dump-undo-state>>")
|
| 34 |
+
Delegator.setdelegate(self, delegate)
|
| 35 |
+
if delegate is not None:
|
| 36 |
+
self.bind("<<undo>>", self.undo_event)
|
| 37 |
+
self.bind("<<redo>>", self.redo_event)
|
| 38 |
+
self.bind("<<dump-undo-state>>", self.dump_event)
|
| 39 |
+
|
| 40 |
+
def dump_event(self, event):
|
| 41 |
+
from pprint import pprint
|
| 42 |
+
pprint(self.undolist[:self.pointer])
|
| 43 |
+
print("pointer:", self.pointer, end=' ')
|
| 44 |
+
print("saved:", self.saved, end=' ')
|
| 45 |
+
print("can_merge:", self.can_merge, end=' ')
|
| 46 |
+
print("get_saved():", self.get_saved())
|
| 47 |
+
pprint(self.undolist[self.pointer:])
|
| 48 |
+
return "break"
|
| 49 |
+
|
| 50 |
+
def reset_undo(self):
|
| 51 |
+
self.was_saved = -1
|
| 52 |
+
self.pointer = 0
|
| 53 |
+
self.undolist = []
|
| 54 |
+
self.undoblock = 0 # or a CommandSequence instance
|
| 55 |
+
self.set_saved(1)
|
| 56 |
+
|
| 57 |
+
def set_saved(self, flag):
|
| 58 |
+
if flag:
|
| 59 |
+
self.saved = self.pointer
|
| 60 |
+
else:
|
| 61 |
+
self.saved = -1
|
| 62 |
+
self.can_merge = False
|
| 63 |
+
self.check_saved()
|
| 64 |
+
|
| 65 |
+
def get_saved(self):
|
| 66 |
+
return self.saved == self.pointer
|
| 67 |
+
|
| 68 |
+
saved_change_hook = None
|
| 69 |
+
|
| 70 |
+
def set_saved_change_hook(self, hook):
|
| 71 |
+
self.saved_change_hook = hook
|
| 72 |
+
|
| 73 |
+
was_saved = -1
|
| 74 |
+
|
| 75 |
+
def check_saved(self):
|
| 76 |
+
is_saved = self.get_saved()
|
| 77 |
+
if is_saved != self.was_saved:
|
| 78 |
+
self.was_saved = is_saved
|
| 79 |
+
if self.saved_change_hook:
|
| 80 |
+
self.saved_change_hook()
|
| 81 |
+
|
| 82 |
+
def insert(self, index, chars, tags=None):
|
| 83 |
+
self.addcmd(InsertCommand(index, chars, tags))
|
| 84 |
+
|
| 85 |
+
def delete(self, index1, index2=None):
|
| 86 |
+
self.addcmd(DeleteCommand(index1, index2))
|
| 87 |
+
|
| 88 |
+
# Clients should call undo_block_start() and undo_block_stop()
|
| 89 |
+
# around a sequence of editing cmds to be treated as a unit by
|
| 90 |
+
# undo & redo. Nested matching calls are OK, and the inner calls
|
| 91 |
+
# then act like nops. OK too if no editing cmds, or only one
|
| 92 |
+
# editing cmd, is issued in between: if no cmds, the whole
|
| 93 |
+
# sequence has no effect; and if only one cmd, that cmd is entered
|
| 94 |
+
# directly into the undo list, as if undo_block_xxx hadn't been
|
| 95 |
+
# called. The intent of all that is to make this scheme easy
|
| 96 |
+
# to use: all the client has to worry about is making sure each
|
| 97 |
+
# _start() call is matched by a _stop() call.
|
| 98 |
+
|
| 99 |
+
def undo_block_start(self):
|
| 100 |
+
if self.undoblock == 0:
|
| 101 |
+
self.undoblock = CommandSequence()
|
| 102 |
+
self.undoblock.bump_depth()
|
| 103 |
+
|
| 104 |
+
def undo_block_stop(self):
|
| 105 |
+
if self.undoblock.bump_depth(-1) == 0:
|
| 106 |
+
cmd = self.undoblock
|
| 107 |
+
self.undoblock = 0
|
| 108 |
+
if len(cmd) > 0:
|
| 109 |
+
if len(cmd) == 1:
|
| 110 |
+
# no need to wrap a single cmd
|
| 111 |
+
cmd = cmd.getcmd(0)
|
| 112 |
+
# this blk of cmds, or single cmd, has already
|
| 113 |
+
# been done, so don't execute it again
|
| 114 |
+
self.addcmd(cmd, 0)
|
| 115 |
+
|
| 116 |
+
def addcmd(self, cmd, execute=True):
|
| 117 |
+
if execute:
|
| 118 |
+
cmd.do(self.delegate)
|
| 119 |
+
if self.undoblock != 0:
|
| 120 |
+
self.undoblock.append(cmd)
|
| 121 |
+
return
|
| 122 |
+
if self.can_merge and self.pointer > 0:
|
| 123 |
+
lastcmd = self.undolist[self.pointer-1]
|
| 124 |
+
if lastcmd.merge(cmd):
|
| 125 |
+
return
|
| 126 |
+
self.undolist[self.pointer:] = [cmd]
|
| 127 |
+
if self.saved > self.pointer:
|
| 128 |
+
self.saved = -1
|
| 129 |
+
self.pointer = self.pointer + 1
|
| 130 |
+
if len(self.undolist) > self.max_undo:
|
| 131 |
+
##print "truncating undo list"
|
| 132 |
+
del self.undolist[0]
|
| 133 |
+
self.pointer = self.pointer - 1
|
| 134 |
+
if self.saved >= 0:
|
| 135 |
+
self.saved = self.saved - 1
|
| 136 |
+
self.can_merge = True
|
| 137 |
+
self.check_saved()
|
| 138 |
+
|
| 139 |
+
def undo_event(self, event):
|
| 140 |
+
if self.pointer == 0:
|
| 141 |
+
self.bell()
|
| 142 |
+
return "break"
|
| 143 |
+
cmd = self.undolist[self.pointer - 1]
|
| 144 |
+
cmd.undo(self.delegate)
|
| 145 |
+
self.pointer = self.pointer - 1
|
| 146 |
+
self.can_merge = False
|
| 147 |
+
self.check_saved()
|
| 148 |
+
return "break"
|
| 149 |
+
|
| 150 |
+
def redo_event(self, event):
|
| 151 |
+
if self.pointer >= len(self.undolist):
|
| 152 |
+
self.bell()
|
| 153 |
+
return "break"
|
| 154 |
+
cmd = self.undolist[self.pointer]
|
| 155 |
+
cmd.redo(self.delegate)
|
| 156 |
+
self.pointer = self.pointer + 1
|
| 157 |
+
self.can_merge = False
|
| 158 |
+
self.check_saved()
|
| 159 |
+
return "break"
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class Command:
|
| 163 |
+
# Base class for Undoable commands
|
| 164 |
+
|
| 165 |
+
tags = None
|
| 166 |
+
|
| 167 |
+
def __init__(self, index1, index2, chars, tags=None):
|
| 168 |
+
self.marks_before = {}
|
| 169 |
+
self.marks_after = {}
|
| 170 |
+
self.index1 = index1
|
| 171 |
+
self.index2 = index2
|
| 172 |
+
self.chars = chars
|
| 173 |
+
if tags:
|
| 174 |
+
self.tags = tags
|
| 175 |
+
|
| 176 |
+
def __repr__(self):
|
| 177 |
+
s = self.__class__.__name__
|
| 178 |
+
t = (self.index1, self.index2, self.chars, self.tags)
|
| 179 |
+
if self.tags is None:
|
| 180 |
+
t = t[:-1]
|
| 181 |
+
return s + repr(t)
|
| 182 |
+
|
| 183 |
+
def do(self, text):
|
| 184 |
+
pass
|
| 185 |
+
|
| 186 |
+
def redo(self, text):
|
| 187 |
+
pass
|
| 188 |
+
|
| 189 |
+
def undo(self, text):
|
| 190 |
+
pass
|
| 191 |
+
|
| 192 |
+
def merge(self, cmd):
|
| 193 |
+
return 0
|
| 194 |
+
|
| 195 |
+
def save_marks(self, text):
|
| 196 |
+
marks = {}
|
| 197 |
+
for name in text.mark_names():
|
| 198 |
+
if name != "insert" and name != "current":
|
| 199 |
+
marks[name] = text.index(name)
|
| 200 |
+
return marks
|
| 201 |
+
|
| 202 |
+
def set_marks(self, text, marks):
|
| 203 |
+
for name, index in marks.items():
|
| 204 |
+
text.mark_set(name, index)
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
class InsertCommand(Command):
|
| 208 |
+
# Undoable insert command
|
| 209 |
+
|
| 210 |
+
def __init__(self, index1, chars, tags=None):
|
| 211 |
+
Command.__init__(self, index1, None, chars, tags)
|
| 212 |
+
|
| 213 |
+
def do(self, text):
|
| 214 |
+
self.marks_before = self.save_marks(text)
|
| 215 |
+
self.index1 = text.index(self.index1)
|
| 216 |
+
if text.compare(self.index1, ">", "end-1c"):
|
| 217 |
+
# Insert before the final newline
|
| 218 |
+
self.index1 = text.index("end-1c")
|
| 219 |
+
text.insert(self.index1, self.chars, self.tags)
|
| 220 |
+
self.index2 = text.index("%s+%dc" % (self.index1, len(self.chars)))
|
| 221 |
+
self.marks_after = self.save_marks(text)
|
| 222 |
+
##sys.__stderr__.write("do: %s\n" % self)
|
| 223 |
+
|
| 224 |
+
def redo(self, text):
|
| 225 |
+
text.mark_set('insert', self.index1)
|
| 226 |
+
text.insert(self.index1, self.chars, self.tags)
|
| 227 |
+
self.set_marks(text, self.marks_after)
|
| 228 |
+
text.see('insert')
|
| 229 |
+
##sys.__stderr__.write("redo: %s\n" % self)
|
| 230 |
+
|
| 231 |
+
def undo(self, text):
|
| 232 |
+
text.mark_set('insert', self.index1)
|
| 233 |
+
text.delete(self.index1, self.index2)
|
| 234 |
+
self.set_marks(text, self.marks_before)
|
| 235 |
+
text.see('insert')
|
| 236 |
+
##sys.__stderr__.write("undo: %s\n" % self)
|
| 237 |
+
|
| 238 |
+
def merge(self, cmd):
|
| 239 |
+
if self.__class__ is not cmd.__class__:
|
| 240 |
+
return False
|
| 241 |
+
if self.index2 != cmd.index1:
|
| 242 |
+
return False
|
| 243 |
+
if self.tags != cmd.tags:
|
| 244 |
+
return False
|
| 245 |
+
if len(cmd.chars) != 1:
|
| 246 |
+
return False
|
| 247 |
+
if self.chars and \
|
| 248 |
+
self.classify(self.chars[-1]) != self.classify(cmd.chars):
|
| 249 |
+
return False
|
| 250 |
+
self.index2 = cmd.index2
|
| 251 |
+
self.chars = self.chars + cmd.chars
|
| 252 |
+
return True
|
| 253 |
+
|
| 254 |
+
alphanumeric = string.ascii_letters + string.digits + "_"
|
| 255 |
+
|
| 256 |
+
def classify(self, c):
|
| 257 |
+
if c in self.alphanumeric:
|
| 258 |
+
return "alphanumeric"
|
| 259 |
+
if c == "\n":
|
| 260 |
+
return "newline"
|
| 261 |
+
return "punctuation"
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
class DeleteCommand(Command):
|
| 265 |
+
# Undoable delete command
|
| 266 |
+
|
| 267 |
+
def __init__(self, index1, index2=None):
|
| 268 |
+
Command.__init__(self, index1, index2, None, None)
|
| 269 |
+
|
| 270 |
+
def do(self, text):
|
| 271 |
+
self.marks_before = self.save_marks(text)
|
| 272 |
+
self.index1 = text.index(self.index1)
|
| 273 |
+
if self.index2:
|
| 274 |
+
self.index2 = text.index(self.index2)
|
| 275 |
+
else:
|
| 276 |
+
self.index2 = text.index(self.index1 + " +1c")
|
| 277 |
+
if text.compare(self.index2, ">", "end-1c"):
|
| 278 |
+
# Don't delete the final newline
|
| 279 |
+
self.index2 = text.index("end-1c")
|
| 280 |
+
self.chars = text.get(self.index1, self.index2)
|
| 281 |
+
text.delete(self.index1, self.index2)
|
| 282 |
+
self.marks_after = self.save_marks(text)
|
| 283 |
+
##sys.__stderr__.write("do: %s\n" % self)
|
| 284 |
+
|
| 285 |
+
def redo(self, text):
|
| 286 |
+
text.mark_set('insert', self.index1)
|
| 287 |
+
text.delete(self.index1, self.index2)
|
| 288 |
+
self.set_marks(text, self.marks_after)
|
| 289 |
+
text.see('insert')
|
| 290 |
+
##sys.__stderr__.write("redo: %s\n" % self)
|
| 291 |
+
|
| 292 |
+
def undo(self, text):
|
| 293 |
+
text.mark_set('insert', self.index1)
|
| 294 |
+
text.insert(self.index1, self.chars)
|
| 295 |
+
self.set_marks(text, self.marks_before)
|
| 296 |
+
text.see('insert')
|
| 297 |
+
##sys.__stderr__.write("undo: %s\n" % self)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class CommandSequence(Command):
|
| 301 |
+
# Wrapper for a sequence of undoable cmds to be undone/redone
|
| 302 |
+
# as a unit
|
| 303 |
+
|
| 304 |
+
def __init__(self):
|
| 305 |
+
self.cmds = []
|
| 306 |
+
self.depth = 0
|
| 307 |
+
|
| 308 |
+
def __repr__(self):
|
| 309 |
+
s = self.__class__.__name__
|
| 310 |
+
strs = []
|
| 311 |
+
for cmd in self.cmds:
|
| 312 |
+
strs.append(" %r" % (cmd,))
|
| 313 |
+
return s + "(\n" + ",\n".join(strs) + "\n)"
|
| 314 |
+
|
| 315 |
+
def __len__(self):
|
| 316 |
+
return len(self.cmds)
|
| 317 |
+
|
| 318 |
+
def append(self, cmd):
|
| 319 |
+
self.cmds.append(cmd)
|
| 320 |
+
|
| 321 |
+
def getcmd(self, i):
|
| 322 |
+
return self.cmds[i]
|
| 323 |
+
|
| 324 |
+
def redo(self, text):
|
| 325 |
+
for cmd in self.cmds:
|
| 326 |
+
cmd.redo(text)
|
| 327 |
+
|
| 328 |
+
def undo(self, text):
|
| 329 |
+
cmds = self.cmds[:]
|
| 330 |
+
cmds.reverse()
|
| 331 |
+
for cmd in cmds:
|
| 332 |
+
cmd.undo(text)
|
| 333 |
+
|
| 334 |
+
def bump_depth(self, incr=1):
|
| 335 |
+
self.depth = self.depth + incr
|
| 336 |
+
return self.depth
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def _undo_delegator(parent): # htest #
|
| 340 |
+
from tkinter import Toplevel, Text, Button
|
| 341 |
+
from idlelib.percolator import Percolator
|
| 342 |
+
undowin = Toplevel(parent)
|
| 343 |
+
undowin.title("Test UndoDelegator")
|
| 344 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 345 |
+
undowin.geometry("+%d+%d" % (x, y + 175))
|
| 346 |
+
|
| 347 |
+
text = Text(undowin, height=10)
|
| 348 |
+
text.pack()
|
| 349 |
+
text.focus_set()
|
| 350 |
+
p = Percolator(text)
|
| 351 |
+
d = UndoDelegator()
|
| 352 |
+
p.insertfilter(d)
|
| 353 |
+
|
| 354 |
+
undo = Button(undowin, text="Undo", command=lambda:d.undo_event(None))
|
| 355 |
+
undo.pack(side='left')
|
| 356 |
+
redo = Button(undowin, text="Redo", command=lambda:d.redo_event(None))
|
| 357 |
+
redo.pack(side='left')
|
| 358 |
+
dump = Button(undowin, text="Dump", command=lambda:d.dump_event(None))
|
| 359 |
+
dump.pack(side='left')
|
| 360 |
+
|
| 361 |
+
if __name__ == "__main__":
|
| 362 |
+
from unittest import main
|
| 363 |
+
main('idlelib.idle_test.test_undo', verbosity=2, exit=False)
|
| 364 |
+
|
| 365 |
+
from idlelib.idle_test.htest import run
|
| 366 |
+
run(_undo_delegator)
|
llava/lib/python3.10/idlelib/util.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Idlelib objects with no external idlelib dependencies
|
| 3 |
+
which are needed in more than one idlelib module.
|
| 4 |
+
|
| 5 |
+
They are included here because
|
| 6 |
+
a) they don't particularly belong elsewhere; or
|
| 7 |
+
b) because inclusion here simplifies the idlelib dependency graph.
|
| 8 |
+
|
| 9 |
+
TODO:
|
| 10 |
+
* Python versions (editor and help_about),
|
| 11 |
+
* tk version and patchlevel (pyshell, help_about, maxos?, editor?),
|
| 12 |
+
* std streams (pyshell, run),
|
| 13 |
+
* warning stuff (pyshell, run).
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
# .pyw is for Windows; .pyi is for stub files.
|
| 17 |
+
py_extensions = ('.py', '.pyw', '.pyi') # Order needed for open/save dialogs.
|
| 18 |
+
|
| 19 |
+
if __name__ == '__main__':
|
| 20 |
+
from unittest import main
|
| 21 |
+
main('idlelib.idle_test.test_util', verbosity=2)
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_adaptive_avg_pool2d_backward_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _adaptive_avg_pool2d_backward {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_adaptive_avg_pool2d_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_adaptive_avg_pool2d_backward(Tensor grad_output, Tensor self) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & grad_output, const at::Tensor & self);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & self);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _adaptive_avg_pool2d_backward_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_adaptive_avg_pool2d_backward")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_adaptive_avg_pool2d_backward.out(Tensor grad_output, Tensor self, *, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & grad_output, const at::Tensor & self, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & self, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|