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
- deepseek/lib/python3.10/idlelib/CREDITS.txt +47 -0
- deepseek/lib/python3.10/idlelib/HISTORY.txt +296 -0
- deepseek/lib/python3.10/idlelib/NEWS2x.txt +660 -0
- deepseek/lib/python3.10/idlelib/README.txt +290 -0
- deepseek/lib/python3.10/idlelib/TODO.txt +210 -0
- deepseek/lib/python3.10/idlelib/__init__.py +10 -0
- deepseek/lib/python3.10/idlelib/autocomplete.py +228 -0
- deepseek/lib/python3.10/idlelib/autoexpand.py +96 -0
- deepseek/lib/python3.10/idlelib/calltip_w.py +201 -0
- deepseek/lib/python3.10/idlelib/config-extensions.def +62 -0
- deepseek/lib/python3.10/idlelib/config-keys.def +309 -0
- deepseek/lib/python3.10/idlelib/config.py +911 -0
- deepseek/lib/python3.10/idlelib/configdialog.py +0 -0
- deepseek/lib/python3.10/idlelib/debugger_r.py +393 -0
- deepseek/lib/python3.10/idlelib/debugobj_r.py +41 -0
- deepseek/lib/python3.10/idlelib/dynoption.py +55 -0
- deepseek/lib/python3.10/idlelib/extend.txt +83 -0
- deepseek/lib/python3.10/idlelib/filelist.py +131 -0
- deepseek/lib/python3.10/idlelib/format.py +426 -0
- deepseek/lib/python3.10/idlelib/grep.py +221 -0
- deepseek/lib/python3.10/idlelib/help.html +1178 -0
- deepseek/lib/python3.10/idlelib/help.py +294 -0
- deepseek/lib/python3.10/idlelib/history.py +106 -0
- deepseek/lib/python3.10/idlelib/hyperparser.py +312 -0
- deepseek/lib/python3.10/idlelib/idle.bat +4 -0
- deepseek/lib/python3.10/idlelib/idle.py +14 -0
- deepseek/lib/python3.10/idlelib/iomenu.py +437 -0
- deepseek/lib/python3.10/idlelib/multicall.py +448 -0
- deepseek/lib/python3.10/idlelib/parenmatch.py +183 -0
- deepseek/lib/python3.10/idlelib/pathbrowser.py +111 -0
- deepseek/lib/python3.10/idlelib/pyparse.py +589 -0
- deepseek/lib/python3.10/idlelib/query.py +392 -0
- deepseek/lib/python3.10/idlelib/replace.py +307 -0
- deepseek/lib/python3.10/idlelib/rpc.py +635 -0
- deepseek/lib/python3.10/idlelib/run.py +642 -0
- deepseek/lib/python3.10/idlelib/search.py +164 -0
- deepseek/lib/python3.10/idlelib/searchengine.py +234 -0
- deepseek/lib/python3.10/idlelib/squeezer.py +345 -0
- deepseek/lib/python3.10/idlelib/stackviewer.py +155 -0
- deepseek/lib/python3.10/idlelib/statusbar.py +50 -0
- deepseek/lib/python3.10/idlelib/textview.py +193 -0
- deepseek/lib/python3.10/idlelib/undo.py +366 -0
- deepseek/lib/python3.10/idlelib/util.py +21 -0
- deepseek/lib/python3.10/idlelib/zoomheight.py +124 -0
- deepseek/lib/python3.10/idlelib/zzdummy.py +73 -0
- deepseek/lib/python3.10/lib2to3/__pycache__/__main__.cpython-310.pyc +0 -0
- deepseek/lib/python3.10/lib2to3/__pycache__/btm_matcher.cpython-310.pyc +0 -0
- deepseek/lib/python3.10/lib2to3/__pycache__/fixer_base.cpython-310.pyc +0 -0
- deepseek/lib/python3.10/lib2to3/__pycache__/pygram.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -426,3 +426,4 @@ deepseek/lib/libgomp.so.1.0.0 filter=lfs diff=lfs merge=lfs -text
|
|
| 426 |
evalkit_tf437/lib/python3.10/site-packages/matplotlib/_tri.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 427 |
deepseek/lib/python3.10/ensurepip/_bundled/pip-23.0.1-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
| 428 |
deepseek/lib/python3.10/tkinter/__pycache__/__init__.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 426 |
evalkit_tf437/lib/python3.10/site-packages/matplotlib/_tri.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 427 |
deepseek/lib/python3.10/ensurepip/_bundled/pip-23.0.1-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
| 428 |
deepseek/lib/python3.10/tkinter/__pycache__/__init__.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 429 |
+
evalkit_tf437/lib/python3.10/site-packages/scipy/sparse/linalg/_propack/_dpropack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
deepseek/lib/python3.10/idlelib/CREDITS.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Guido van Rossum, as well as being the creator of the Python language, is the
|
| 2 |
+
original creator of IDLE. Other contributors prior to Version 0.8 include
|
| 3 |
+
Mark Hammond, Jeremy Hylton, Tim Peters, and Moshe Zadka.
|
| 4 |
+
|
| 5 |
+
Until Python 2.3, IDLE's development was carried out in the SF IDLEfork project. The
|
| 6 |
+
objective was to develop a version of IDLE which had an execution environment
|
| 7 |
+
which could be initialized prior to each run of user code.
|
| 8 |
+
IDLefork was merged into the Python code base in 2003.
|
| 9 |
+
|
| 10 |
+
The IDLEfork project was initiated by David Scherer, with some help from Peter
|
| 11 |
+
Schneider-Kamp and Nicholas Riley. David wrote the first version of the RPC
|
| 12 |
+
code and designed a fast turn-around environment for VPython. Guido developed
|
| 13 |
+
the RPC code and Remote Debugger currently integrated in IDLE. Bruce Sherwood
|
| 14 |
+
contributed considerable time testing and suggesting improvements.
|
| 15 |
+
|
| 16 |
+
Besides David and Guido, the main developers who were active on IDLEfork
|
| 17 |
+
are Stephen M. Gava, who implemented the configuration GUI, the new
|
| 18 |
+
configuration system, and the About dialog, and Kurt B. Kaiser, who completed
|
| 19 |
+
the integration of the RPC and remote debugger, implemented the threaded
|
| 20 |
+
subprocess, and made a number of usability enhancements.
|
| 21 |
+
|
| 22 |
+
Other contributors include Raymond Hettinger, Tony Lownds (Mac integration),
|
| 23 |
+
Neal Norwitz (code check and clean-up), Ronald Oussoren (Mac integration),
|
| 24 |
+
Noam Raphael (Code Context, Call Tips, many other patches), and Chui Tey (RPC
|
| 25 |
+
integration, debugger integration and persistent breakpoints).
|
| 26 |
+
|
| 27 |
+
Scott David Daniels, Tal Einat, Hernan Foffani, Christos Georgiou,
|
| 28 |
+
Jim Jewett, Martin v. Löwis, Jason Orendorff, Guilherme Polo, Josh Robb,
|
| 29 |
+
Nigel Rowe, Bruce Sherwood, Jeff Shute, and Weeble have submitted useful
|
| 30 |
+
patches. Thanks, guys!
|
| 31 |
+
|
| 32 |
+
Major contributors since 2005:
|
| 33 |
+
|
| 34 |
+
- 2005: Tal Einat
|
| 35 |
+
- 2010: Terry Jan Reedy (current maintainer)
|
| 36 |
+
- 2013: Roger Serwys
|
| 37 |
+
- 2014: Saimadhav Heblikar
|
| 38 |
+
- 2015: Mark Roseman
|
| 39 |
+
- 2017: Louie Lu, Cheryl Sabella, and Serhiy Storchaka
|
| 40 |
+
|
| 41 |
+
For additional details refer to NEWS.txt and Changelog.
|
| 42 |
+
|
| 43 |
+
Please contact the IDLE maintainer (kbk@shore.net) to have yourself included
|
| 44 |
+
here if you are one of those we missed!
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
deepseek/lib/python3.10/idlelib/HISTORY.txt
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
IDLE History
|
| 2 |
+
============
|
| 3 |
+
|
| 4 |
+
This file contains the release messages for previous IDLE releases.
|
| 5 |
+
As you read on you go back to the dark ages of IDLE's history.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
What's New in IDLEfork 0.8.1?
|
| 9 |
+
=============================
|
| 10 |
+
|
| 11 |
+
*Release date: 22-Jul-2001*
|
| 12 |
+
|
| 13 |
+
- New tarball released as a result of the 'revitalisation' of the IDLEfork
|
| 14 |
+
project.
|
| 15 |
+
|
| 16 |
+
- This release requires python 2.1 or better. Compatibility with earlier
|
| 17 |
+
versions of python (especially ancient ones like 1.5x) is no longer a
|
| 18 |
+
priority in IDLEfork development.
|
| 19 |
+
|
| 20 |
+
- This release is based on a merging of the earlier IDLE fork work with current
|
| 21 |
+
cvs IDLE (post IDLE version 0.8), with some minor additional coding by Kurt
|
| 22 |
+
B. Kaiser and Stephen M. Gava.
|
| 23 |
+
|
| 24 |
+
- This release is basically functional but also contains some known breakages,
|
| 25 |
+
particularly with running things from the shell window. Also the debugger is
|
| 26 |
+
not working, but I believe this was the case with the previous IDLE fork
|
| 27 |
+
release (0.7.1) as well.
|
| 28 |
+
|
| 29 |
+
- This release is being made now to mark the point at which IDLEfork is
|
| 30 |
+
launching into a new stage of development.
|
| 31 |
+
|
| 32 |
+
- IDLEfork CVS will now be branched to enable further development and
|
| 33 |
+
exploration of the two "execution in a remote process" patches submitted by
|
| 34 |
+
David Scherer (David's is currently in IDLEfork) and GvR, while stabilisation
|
| 35 |
+
and development of less heavyweight improvements (like user customisation)
|
| 36 |
+
can continue on the trunk.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
What's New in IDLEfork 0.7.1?
|
| 40 |
+
==============================
|
| 41 |
+
|
| 42 |
+
*Release date: 15-Aug-2000*
|
| 43 |
+
|
| 44 |
+
- First project tarball released.
|
| 45 |
+
|
| 46 |
+
- This was the first release of IDLE fork, which at this stage was a
|
| 47 |
+
combination of IDLE 0.5 and the VPython idle fork, with additional changes
|
| 48 |
+
coded by David Scherer, Peter Schneider-Kamp and Nicholas Riley.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
IDLEfork 0.7.1 - 29 May 2000
|
| 53 |
+
-----------------------------
|
| 54 |
+
|
| 55 |
+
David Scherer <dscherer@cmu.edu>
|
| 56 |
+
|
| 57 |
+
- This is a modification of the CVS version of IDLE 0.5, updated as of
|
| 58 |
+
2000-03-09. It is alpha software and might be unstable. If it breaks, you
|
| 59 |
+
get to keep both pieces.
|
| 60 |
+
|
| 61 |
+
- If you have problems or suggestions, you should either contact me or post to
|
| 62 |
+
the list at http://www.python.org/mailman/listinfo/idle-dev (making it clear
|
| 63 |
+
that you are using this modified version of IDLE).
|
| 64 |
+
|
| 65 |
+
- Changes:
|
| 66 |
+
|
| 67 |
+
- The ExecBinding module, a replacement for ScriptBinding, executes programs
|
| 68 |
+
in a separate process, piping standard I/O through an RPC mechanism to an
|
| 69 |
+
OnDemandOutputWindow in IDLE. It supports executing unnamed programs
|
| 70 |
+
(through a temporary file). It does not yet support debugging.
|
| 71 |
+
|
| 72 |
+
- When running programs with ExecBinding, tracebacks will be clipped to
|
| 73 |
+
exclude system modules. If, however, a system module calls back into the
|
| 74 |
+
user program, that part of the traceback will be shown.
|
| 75 |
+
|
| 76 |
+
- The OnDemandOutputWindow class has been improved. In particular, it now
|
| 77 |
+
supports a readline() function used to implement user input, and a
|
| 78 |
+
scroll_clear() operation which is used to hide the output of a previous run
|
| 79 |
+
by scrolling it out of the window.
|
| 80 |
+
|
| 81 |
+
- Startup behavior has been changed. By default IDLE starts up with just a
|
| 82 |
+
blank editor window, rather than an interactive window. Opening a file in
|
| 83 |
+
such a blank window replaces the (nonexistent) contents of that window
|
| 84 |
+
instead of creating another window. Because of the need to have a
|
| 85 |
+
well-known port for the ExecBinding protocol, only one copy of IDLE can be
|
| 86 |
+
running. Additional invocations use the RPC mechanism to report their
|
| 87 |
+
command line arguments to the copy already running.
|
| 88 |
+
|
| 89 |
+
- The menus have been reorganized. In particular, the excessively large
|
| 90 |
+
'edit' menu has been split up into 'edit', 'format', and 'run'.
|
| 91 |
+
|
| 92 |
+
- 'Python Documentation' now works on Windows, if the win32api module is
|
| 93 |
+
present.
|
| 94 |
+
|
| 95 |
+
- A few key bindings have been changed: F1 now loads Python Documentation
|
| 96 |
+
instead of the IDLE help; shift-TAB is now a synonym for unindent.
|
| 97 |
+
|
| 98 |
+
- New modules:
|
| 99 |
+
|
| 100 |
+
ExecBinding.py Executes program through loader
|
| 101 |
+
loader.py Bootstraps user program
|
| 102 |
+
protocol.py RPC protocol
|
| 103 |
+
Remote.py User-process interpreter
|
| 104 |
+
spawn.py OS-specific code to start programs
|
| 105 |
+
|
| 106 |
+
- Files modified:
|
| 107 |
+
|
| 108 |
+
autoindent.py ( bindings tweaked )
|
| 109 |
+
bindings.py ( menus reorganized )
|
| 110 |
+
config.txt ( execbinding enabled )
|
| 111 |
+
editorwindow.py ( new menus, fixed 'Python Documentation' )
|
| 112 |
+
filelist.py ( hook for "open in same window" )
|
| 113 |
+
formatparagraph.py ( bindings tweaked )
|
| 114 |
+
idle.bat ( removed absolute pathname )
|
| 115 |
+
idle.pyw ( weird bug due to import with same name? )
|
| 116 |
+
iobinding.py ( open in same window, EOL convention )
|
| 117 |
+
keydefs.py ( bindings tweaked )
|
| 118 |
+
outputwindow.py ( readline, scroll_clear, etc )
|
| 119 |
+
pyshell.py ( changed startup behavior )
|
| 120 |
+
readme.txt ( <Recursion on file with id=1234567> )
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
IDLE 0.5 - February 2000 - Release Notes
|
| 125 |
+
----------------------------------------
|
| 126 |
+
|
| 127 |
+
This is an early release of IDLE, my own attempt at a Tkinter-based
|
| 128 |
+
IDE for Python.
|
| 129 |
+
|
| 130 |
+
(For a more detailed change log, see the file ChangeLog.)
|
| 131 |
+
|
| 132 |
+
FEATURES
|
| 133 |
+
|
| 134 |
+
IDLE has the following features:
|
| 135 |
+
|
| 136 |
+
- coded in 100% pure Python, using the Tkinter GUI toolkit (i.e. Tcl/Tk)
|
| 137 |
+
|
| 138 |
+
- cross-platform: works on Windows and Unix (on the Mac, there are
|
| 139 |
+
currently problems with Tcl/Tk)
|
| 140 |
+
|
| 141 |
+
- multi-window text editor with multiple undo, Python colorizing
|
| 142 |
+
and many other features, e.g. smart indent and call tips
|
| 143 |
+
|
| 144 |
+
- Python shell window (a.k.a. interactive interpreter)
|
| 145 |
+
|
| 146 |
+
- debugger (not complete, but you can set breakpoints, view and step)
|
| 147 |
+
|
| 148 |
+
USAGE
|
| 149 |
+
|
| 150 |
+
The main program is in the file "idle.py"; on Unix, you should be able
|
| 151 |
+
to run it by typing "./idle.py" to your shell. On Windows, you can
|
| 152 |
+
run it by double-clicking it; you can use idle.pyw to avoid popping up
|
| 153 |
+
a DOS console. If you want to pass command line arguments on Windows,
|
| 154 |
+
use the batch file idle.bat.
|
| 155 |
+
|
| 156 |
+
Command line arguments: files passed on the command line are executed,
|
| 157 |
+
not opened for editing, unless you give the -e command line option.
|
| 158 |
+
Try "./idle.py -h" to see other command line options.
|
| 159 |
+
|
| 160 |
+
IDLE requires Python 1.5.2, so it is currently only usable with a
|
| 161 |
+
Python 1.5.2 distribution. (An older version of IDLE is distributed
|
| 162 |
+
with Python 1.5.2; you can drop this version on top of it.)
|
| 163 |
+
|
| 164 |
+
COPYRIGHT
|
| 165 |
+
|
| 166 |
+
IDLE is covered by the standard Python copyright notice
|
| 167 |
+
(http://www.python.org/doc/Copyright.html).
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
New in IDLE 0.5 (2/15/2000)
|
| 171 |
+
---------------------------
|
| 172 |
+
|
| 173 |
+
Tons of stuff, much of it contributed by Tim Peters and Mark Hammond:
|
| 174 |
+
|
| 175 |
+
- Status bar, displaying current line/column (Moshe Zadka).
|
| 176 |
+
|
| 177 |
+
- Better stack viewer, using tree widget. (XXX Only used by Stack
|
| 178 |
+
Viewer menu, not by the debugger.)
|
| 179 |
+
|
| 180 |
+
- Format paragraph now recognizes Python block comments and reformats
|
| 181 |
+
them correctly (MH)
|
| 182 |
+
|
| 183 |
+
- New version of pyclbr.py parses top-level functions and understands
|
| 184 |
+
much more of Python's syntax; this is reflected in the class and path
|
| 185 |
+
browsers (TP)
|
| 186 |
+
|
| 187 |
+
- Much better auto-indent; knows how to indent the insides of
|
| 188 |
+
multi-line statements (TP)
|
| 189 |
+
|
| 190 |
+
- Call tip window pops up when you type the name of a known function
|
| 191 |
+
followed by an open parenthesis. Hit ESC or click elsewhere in the
|
| 192 |
+
window to close the tip window (MH)
|
| 193 |
+
|
| 194 |
+
- Comment out region now inserts ## to make it stand out more (TP)
|
| 195 |
+
|
| 196 |
+
- New path and class browsers based on a tree widget that looks
|
| 197 |
+
familiar to Windows users
|
| 198 |
+
|
| 199 |
+
- Reworked script running commands to be more intuitive: I/O now
|
| 200 |
+
always goes to the *Python Shell* window, and raw_input() works
|
| 201 |
+
correctly. You use F5 to import/reload a module: this adds the module
|
| 202 |
+
name to the __main__ namespace. You use Control-F5 to run a script:
|
| 203 |
+
this runs the script *in* the __main__ namespace. The latter also
|
| 204 |
+
sets sys.argv[] to the script name
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
New in IDLE 0.4 (4/7/99)
|
| 208 |
+
------------------------
|
| 209 |
+
|
| 210 |
+
Most important change: a new menu entry "File -> Path browser", shows
|
| 211 |
+
a 4-column hierarchical browser which lets you browse sys.path,
|
| 212 |
+
directories, modules, and classes. Yes, it's a superset of the Class
|
| 213 |
+
browser menu entry. There's also a new internal module,
|
| 214 |
+
MultiScrolledLists.py, which provides the framework for this dialog.
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
New in IDLE 0.3 (2/17/99)
|
| 218 |
+
-------------------------
|
| 219 |
+
|
| 220 |
+
Most important changes:
|
| 221 |
+
|
| 222 |
+
- Enabled support for running a module, with or without the debugger.
|
| 223 |
+
Output goes to a new window. Pressing F5 in a module is effectively a
|
| 224 |
+
reload of that module; Control-F5 loads it under the debugger.
|
| 225 |
+
|
| 226 |
+
- Re-enable tearing off the Windows menu, and make a torn-off Windows
|
| 227 |
+
menu update itself whenever a window is opened or closed.
|
| 228 |
+
|
| 229 |
+
- Menu items can now be have a checkbox (when the menu label starts
|
| 230 |
+
with "!"); use this for the Debugger and "Auto-open stack viewer"
|
| 231 |
+
(was: JIT stack viewer) menu items.
|
| 232 |
+
|
| 233 |
+
- Added a Quit button to the Debugger API.
|
| 234 |
+
|
| 235 |
+
- The current directory is explicitly inserted into sys.path.
|
| 236 |
+
|
| 237 |
+
- Fix the debugger (when using Python 1.5.2b2) to use canonical
|
| 238 |
+
filenames for breakpoints, so these actually work. (There's still a
|
| 239 |
+
lot of work to be done to the management of breakpoints in the
|
| 240 |
+
debugger though.)
|
| 241 |
+
|
| 242 |
+
- Closing a window that is still colorizing now actually works.
|
| 243 |
+
|
| 244 |
+
- Allow dragging of the separator between the two list boxes in the
|
| 245 |
+
class browser.
|
| 246 |
+
|
| 247 |
+
- Bind ESC to "close window" of the debugger, stack viewer and class
|
| 248 |
+
browser. It removes the selection highlighting in regular text
|
| 249 |
+
windows. (These are standard Windows conventions.)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
New in IDLE 0.2 (1/8/99)
|
| 253 |
+
------------------------
|
| 254 |
+
|
| 255 |
+
Lots of changes; here are the highlights:
|
| 256 |
+
|
| 257 |
+
General:
|
| 258 |
+
|
| 259 |
+
- You can now write and configure your own IDLE extension modules; see
|
| 260 |
+
extend.txt.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
File menu:
|
| 264 |
+
|
| 265 |
+
The command to open the Python shell window is now in the File menu.
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
Edit menu:
|
| 269 |
+
|
| 270 |
+
New Find dialog with more options; replace dialog; find in files dialog.
|
| 271 |
+
|
| 272 |
+
Commands to tabify or untabify a region.
|
| 273 |
+
|
| 274 |
+
Command to format a paragraph.
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
Debug menu:
|
| 278 |
+
|
| 279 |
+
JIT (Just-In-Time) stack viewer toggle -- if set, the stack viewer
|
| 280 |
+
automaticall pops up when you get a traceback.
|
| 281 |
+
|
| 282 |
+
Windows menu:
|
| 283 |
+
|
| 284 |
+
Zoom height -- make the window full height.
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
Help menu:
|
| 288 |
+
|
| 289 |
+
The help text now show up in a regular window so you can search and
|
| 290 |
+
even edit it if you like.
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
IDLE 0.1 was distributed with the Python 1.5.2b1 release on 12/22/98.
|
| 295 |
+
|
| 296 |
+
======================================================================
|
deepseek/lib/python3.10/idlelib/NEWS2x.txt
ADDED
|
@@ -0,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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
What's New in IDLE 2.7? (Merged into 3.1 before 2.7 release.)
|
| 2 |
+
=======================
|
| 3 |
+
*Release date: XX-XXX-2010*
|
| 4 |
+
|
| 5 |
+
- idle.py modified and simplified to better support developing experimental
|
| 6 |
+
versions of IDLE which are not installed in the standard location.
|
| 7 |
+
|
| 8 |
+
- OutputWindow/PyShell right click menu "Go to file/line" wasn't working with
|
| 9 |
+
file paths containing spaces. Bug 5559.
|
| 10 |
+
|
| 11 |
+
- Windows: Version string for the .chm help file changed, file not being
|
| 12 |
+
accessed Patch 5783 Guilherme Polo
|
| 13 |
+
|
| 14 |
+
- Allow multiple IDLE GUI/subprocess pairs to exist simultaneously. Thanks to
|
| 15 |
+
David Scherer for suggesting the use of an ephemeral port for the GUI.
|
| 16 |
+
Patch 1529142 Weeble.
|
| 17 |
+
|
| 18 |
+
- Remove port spec from run.py and fix bug where subprocess fails to
|
| 19 |
+
extract port from command line when warnings are present.
|
| 20 |
+
|
| 21 |
+
- Tk 8.5 Text widget requires 'wordprocessor' tabstyle attr to handle
|
| 22 |
+
mixed space/tab properly. Issue 5129, patch by Guilherme Polo.
|
| 23 |
+
|
| 24 |
+
- Issue #3549: On MacOS the preferences menu was not present
|
| 25 |
+
|
| 26 |
+
- IDLE would print a "Unhandled server exception!" message when internal
|
| 27 |
+
debugging is enabled.
|
| 28 |
+
|
| 29 |
+
- Issue #4455: IDLE failed to display the windows list when two windows have
|
| 30 |
+
the same title.
|
| 31 |
+
|
| 32 |
+
- Issue #4383: When IDLE cannot make the connection to its subprocess, it would
|
| 33 |
+
fail to properly display the error message.
|
| 34 |
+
|
| 35 |
+
- help() was not paging to the shell. Issue1650.
|
| 36 |
+
|
| 37 |
+
- CodeContext was not importing.
|
| 38 |
+
|
| 39 |
+
- Corrected two 3.0 compatibility errors reported by Mark Summerfield:
|
| 40 |
+
http://mail.python.org/pipermail/python-3000/2007-December/011491.html
|
| 41 |
+
|
| 42 |
+
- Shell was not colorizing due to bug introduced at r57998, Bug 1586.
|
| 43 |
+
|
| 44 |
+
- Issue #1585: IDLE uses non-existent xrange() function.
|
| 45 |
+
|
| 46 |
+
- Windows EOL sequence not converted correctly, encoding error.
|
| 47 |
+
Caused file save to fail. Bug 1130.
|
| 48 |
+
|
| 49 |
+
- IDLE converted to Python 3000 syntax.
|
| 50 |
+
|
| 51 |
+
- Strings became Unicode.
|
| 52 |
+
|
| 53 |
+
- CallTips module now uses the inspect module to produce the argspec.
|
| 54 |
+
|
| 55 |
+
- IDLE modules now use absolute import instead of implied relative import.
|
| 56 |
+
|
| 57 |
+
- atexit call replaces sys.exitfunc. The functionality of delete-exitfunc flag
|
| 58 |
+
in config-main.cfg remains unchanged: if set, registered exit functions will
|
| 59 |
+
be cleared before IDLE exits.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
What's New in IDLE 2.6
|
| 63 |
+
======================
|
| 64 |
+
*Release date: 01-Oct-2008*, merged into 3.0 releases detailed above (3.0rc2)
|
| 65 |
+
|
| 66 |
+
- Issue #2665: On Windows, an IDLE installation upgraded from an old version
|
| 67 |
+
would not start if a custom theme was defined.
|
| 68 |
+
|
| 69 |
+
- Home / Control-A toggles between left margin and end of leading white
|
| 70 |
+
space. issue1196903, patch by Jeff Shute.
|
| 71 |
+
|
| 72 |
+
- Improved AutoCompleteWindow logic. issue2062, patch by Tal Einat.
|
| 73 |
+
|
| 74 |
+
- Autocompletion of filenames now support alternate separators, e.g. the
|
| 75 |
+
'/' char on Windows. issue2061 Patch by Tal Einat.
|
| 76 |
+
|
| 77 |
+
- Configured selection highlighting colors were ignored; updating highlighting
|
| 78 |
+
in the config dialog would cause non-Python files to be colored as if they
|
| 79 |
+
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
|
| 80 |
+
|
| 81 |
+
- ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat
|
| 82 |
+
|
| 83 |
+
- There was an error on exit if no sys.exitfunc was defined. Issue 1647.
|
| 84 |
+
|
| 85 |
+
- Could not open files in .idlerc directory if latter was hidden on Windows.
|
| 86 |
+
Issue 1743, Issue 1862.
|
| 87 |
+
|
| 88 |
+
- Configure Dialog: improved layout for keybinding. Patch 1457 Tal Einat.
|
| 89 |
+
|
| 90 |
+
- tabpage.py updated: tabbedPages.py now supports multiple dynamic rows
|
| 91 |
+
of tabs. Patch 1612746 Tal Einat.
|
| 92 |
+
|
| 93 |
+
- Add confirmation dialog before printing. Patch 1717170 Tal Einat.
|
| 94 |
+
|
| 95 |
+
- Show paste position if > 80 col. Patch 1659326 Tal Einat.
|
| 96 |
+
|
| 97 |
+
- Update cursor color without restarting. Patch 1725576 Tal Einat.
|
| 98 |
+
|
| 99 |
+
- Allow keyboard interrupt only when user code is executing in subprocess.
|
| 100 |
+
Patch 1225 Tal Einat (reworked from IDLE-Spoon).
|
| 101 |
+
|
| 102 |
+
- configDialog cleanup. Patch 1730217 Tal Einat.
|
| 103 |
+
|
| 104 |
+
- textView cleanup. Patch 1718043 Tal Einat.
|
| 105 |
+
|
| 106 |
+
- Clean up EditorWindow close.
|
| 107 |
+
|
| 108 |
+
- Patch 1693258: Fix for duplicate "preferences" menu-OS X. Backport of r56204.
|
| 109 |
+
|
| 110 |
+
- OSX: Avoid crash for those versions of Tcl/Tk which don't have a console
|
| 111 |
+
|
| 112 |
+
- Bug in idlelib.MultiCall: Options dialog was crashing IDLE if there was an
|
| 113 |
+
option in config-extensions w/o a value. Patch #1672481, Tal Einat
|
| 114 |
+
|
| 115 |
+
- Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
|
| 116 |
+
mouse and cursor selection in ACWindow implemented; double Tab inserts
|
| 117 |
+
current selection and closes ACW (similar to double-click and Return); scroll
|
| 118 |
+
wheel now works in ACW. Added AutoComplete instructions to IDLE Help.
|
| 119 |
+
|
| 120 |
+
- AutoCompleteWindow moved below input line, will move above if there
|
| 121 |
+
isn't enough space. Patch 1621265 Tal Einat
|
| 122 |
+
|
| 123 |
+
- Calltips now 'handle' tuples in the argument list (display '<tuple>' :)
|
| 124 |
+
Suggested solution by Christos Georgiou, Bug 791968.
|
| 125 |
+
|
| 126 |
+
- Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
|
| 127 |
+
|
| 128 |
+
- Avoid hang when encountering a duplicate in a completion list. Bug 1571112.
|
| 129 |
+
|
| 130 |
+
- Patch #1362975: Rework CodeContext indentation algorithm to
|
| 131 |
+
avoid hard-coding pixel widths.
|
| 132 |
+
|
| 133 |
+
- Bug #813342: Start the IDLE subprocess with -Qnew if the parent
|
| 134 |
+
is started with that option.
|
| 135 |
+
|
| 136 |
+
- Honor the "Cancel" action in the save dialog (Debian bug #299092)
|
| 137 |
+
|
| 138 |
+
- Some syntax errors were being caught by tokenize during the tabnanny
|
| 139 |
+
check, resulting in obscure error messages. Do the syntax check
|
| 140 |
+
first. Bug 1562716, 1562719
|
| 141 |
+
|
| 142 |
+
- IDLE's version number takes a big jump to match the version number of
|
| 143 |
+
the Python release of which it's a part.
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
What's New in IDLE 1.2?
|
| 147 |
+
=======================
|
| 148 |
+
*Release date: 19-SEP-2006*
|
| 149 |
+
|
| 150 |
+
- File menu hotkeys: there were three 'p' assignments. Reassign the
|
| 151 |
+
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
|
| 152 |
+
Shell hotkey from 's' to 'l'.
|
| 153 |
+
|
| 154 |
+
- IDLE honors new quit() and exit() commands from site.py Quitter() object.
|
| 155 |
+
Patch 1540892, Jim Jewett
|
| 156 |
+
|
| 157 |
+
- The 'with' statement is now a Code Context block opener.
|
| 158 |
+
Patch 1540851, Jim Jewett
|
| 159 |
+
|
| 160 |
+
- Retrieval of previous shell command was not always preserving indentation
|
| 161 |
+
(since 1.2a1) Patch 1528468 Tal Einat.
|
| 162 |
+
|
| 163 |
+
- Changing tokenize (39046) to detect dedent broke tabnanny check (since 1.2a1)
|
| 164 |
+
|
| 165 |
+
- ToggleTab dialog was setting indent to 8 even if cancelled (since 1.2a1).
|
| 166 |
+
|
| 167 |
+
- When used w/o subprocess, all exceptions were preceded by an error
|
| 168 |
+
message claiming they were IDLE internal errors (since 1.2a1).
|
| 169 |
+
|
| 170 |
+
- Bug #1525817: Don't truncate short lines in IDLE's tool tips.
|
| 171 |
+
|
| 172 |
+
- Bug #1517990: IDLE keybindings on MacOS X now work correctly
|
| 173 |
+
|
| 174 |
+
- Bug #1517996: IDLE now longer shows the default Tk menu when a
|
| 175 |
+
path browser, class browser or debugger is the frontmost window on MacOS X
|
| 176 |
+
|
| 177 |
+
- EditorWindow.test() was failing. Bug 1417598
|
| 178 |
+
|
| 179 |
+
- EditorWindow failed when used stand-alone if sys.ps1 not set.
|
| 180 |
+
Bug 1010370 Dave Florek
|
| 181 |
+
|
| 182 |
+
- Tooltips failed on new-syle class __init__ args. Bug 1027566 Loren Guthrie
|
| 183 |
+
|
| 184 |
+
- Avoid occasional failure to detect closing paren properly.
|
| 185 |
+
Patch 1407280 Tal Einat
|
| 186 |
+
|
| 187 |
+
- Rebinding Tab key was inserting 'tab' instead of 'Tab'. Bug 1179168.
|
| 188 |
+
|
| 189 |
+
- Colorizer now handles #<builtin> correctly, also unicode strings and
|
| 190 |
+
'as' keyword in comment directly following import command. Closes 1325071.
|
| 191 |
+
Patch 1479219 Tal Einat
|
| 192 |
+
|
| 193 |
+
- Patch #1162825: Support non-ASCII characters in IDLE window titles.
|
| 194 |
+
|
| 195 |
+
- Source file f.flush() after writing; trying to avoid lossage if user
|
| 196 |
+
kills GUI.
|
| 197 |
+
|
| 198 |
+
- Options / Keys / Advanced dialog made functional. Also, allow binding
|
| 199 |
+
of 'movement' keys.
|
| 200 |
+
|
| 201 |
+
- 'syntax' patch adds improved calltips and a new class attribute listbox.
|
| 202 |
+
MultiCall module allows binding multiple actions to an event.
|
| 203 |
+
Patch 906702 Noam Raphael
|
| 204 |
+
|
| 205 |
+
- Better indentation after first line of string continuation.
|
| 206 |
+
IDLEfork Patch 681992, Noam Raphael
|
| 207 |
+
|
| 208 |
+
- Fixed CodeContext alignment problem, following suggestion from Tal Einat.
|
| 209 |
+
|
| 210 |
+
- Increased performance in CodeContext extension Patch 936169 Noam Raphael
|
| 211 |
+
|
| 212 |
+
- Mac line endings were incorrect when pasting code from some browsers
|
| 213 |
+
when using X11 and the Fink distribution. Python Bug 1263656.
|
| 214 |
+
|
| 215 |
+
- <Enter> when cursor is on a previous command retrieves that command. Instead
|
| 216 |
+
of replacing the input line, the previous command is now appended to the
|
| 217 |
+
input line. Indentation is preserved, and undo is enabled.
|
| 218 |
+
Patch 1196917 Jeff Shute
|
| 219 |
+
|
| 220 |
+
- Clarify "tab/space" Error Dialog and "Tab Width" Dialog associated with
|
| 221 |
+
the Untabify command.
|
| 222 |
+
|
| 223 |
+
- Corrected "tab/space" Error Dialog to show correct menu for Untabify.
|
| 224 |
+
Patch 1196980 Jeff Shute
|
| 225 |
+
|
| 226 |
+
- New files are colorized by default, and colorizing is removed when
|
| 227 |
+
saving as non-Python files. Patch 1196895 Jeff Shute
|
| 228 |
+
Closes Python Bugs 775012 and 800432, partial fix IDLEfork 763524
|
| 229 |
+
|
| 230 |
+
- Improve subprocess link error notification.
|
| 231 |
+
|
| 232 |
+
- run.py: use Queue's blocking feature instead of sleeping in the main
|
| 233 |
+
loop. Patch # 1190163 Michiel de Hoon
|
| 234 |
+
|
| 235 |
+
- Add config-main option to make the 'history' feature non-cyclic.
|
| 236 |
+
Default remains cyclic. Python Patch 914546 Noam Raphael.
|
| 237 |
+
|
| 238 |
+
- Removed ability to configure tabs indent from Options dialog. This 'feature'
|
| 239 |
+
has never worked and no one has complained. It is still possible to set a
|
| 240 |
+
default tabs (v. spaces) indent 'manually' via config-main.def (or to turn on
|
| 241 |
+
tabs for the current EditorWindow via the Format menu) but IDLE will
|
| 242 |
+
encourage indentation via spaces.
|
| 243 |
+
|
| 244 |
+
- Enable setting the indentation width using the Options dialog.
|
| 245 |
+
Bug # 783877
|
| 246 |
+
|
| 247 |
+
- Add keybindings for del-word-left and del-word-right.
|
| 248 |
+
|
| 249 |
+
- Discourage using an indent width other than 8 when using tabs to indent
|
| 250 |
+
Python code.
|
| 251 |
+
|
| 252 |
+
- Restore use of EditorWindow.set_indentation_params(), was dead code since
|
| 253 |
+
Autoindent was merged into EditorWindow. This allows IDLE to conform to the
|
| 254 |
+
indentation width of a loaded file. (But it still will not switch to tabs
|
| 255 |
+
even if the file uses tabs.) Any change in indent width is local to that
|
| 256 |
+
window.
|
| 257 |
+
|
| 258 |
+
- Add Tabnanny check before Run/F5, not just when Checking module.
|
| 259 |
+
|
| 260 |
+
- If an extension can't be loaded, print warning and skip it instead of
|
| 261 |
+
erroring out.
|
| 262 |
+
|
| 263 |
+
- Improve error handling when .idlerc can't be created (warn and exit).
|
| 264 |
+
|
| 265 |
+
- The GUI was hanging if the shell window was closed while a raw_input()
|
| 266 |
+
was pending. Restored the quit() of the readline() mainloop().
|
| 267 |
+
http://mail.python.org/pipermail/idle-dev/2004-December/002307.html
|
| 268 |
+
|
| 269 |
+
- The remote procedure call module rpc.py can now access data attributes of
|
| 270 |
+
remote registered objects. Changes to these attributes are local, however.
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
What's New in IDLE 1.1?
|
| 274 |
+
=======================
|
| 275 |
+
*Release date: 30-NOV-2004*
|
| 276 |
+
|
| 277 |
+
- On OpenBSD, terminating IDLE with ctrl-c from the command line caused a
|
| 278 |
+
stuck subprocess MainThread because only the SocketThread was exiting.
|
| 279 |
+
|
| 280 |
+
- Saving a Keyset w/o making changes (by using the "Save as New Custom Key Set"
|
| 281 |
+
button) caused IDLE to fail on restart (no new keyset was created in
|
| 282 |
+
config-keys.cfg). Also true for Theme/highlights. Python Bug 1064535.
|
| 283 |
+
|
| 284 |
+
- A change to the linecache.py API caused IDLE to exit when an exception was
|
| 285 |
+
raised while running without the subprocess (-n switch). Python Bug 1063840.
|
| 286 |
+
|
| 287 |
+
- When paragraph reformat width was made configurable, a bug was
|
| 288 |
+
introduced that caused reformatting of comment blocks to ignore how
|
| 289 |
+
far the block was indented, effectively adding the indentation width
|
| 290 |
+
to the reformat width. This has been repaired, and the reformat
|
| 291 |
+
width is again a bound on the total width of reformatted lines.
|
| 292 |
+
|
| 293 |
+
- Improve keyboard focus binding, especially in Windows menu. Improve
|
| 294 |
+
window raising, especially in the Windows menu and in the debugger.
|
| 295 |
+
IDLEfork 763524.
|
| 296 |
+
|
| 297 |
+
- If user passes a non-existent filename on the commandline, just
|
| 298 |
+
open a new file, don't raise a dialog. IDLEfork 854928.
|
| 299 |
+
|
| 300 |
+
- EditorWindow.py was not finding the .chm help file on Windows. Typo
|
| 301 |
+
at Rev 1.54. Python Bug 990954
|
| 302 |
+
|
| 303 |
+
- checking sys.platform for substring 'win' was breaking IDLE docs on Mac
|
| 304 |
+
(darwin). Also, Mac Safari browser requires full file:// URIs. SF 900580.
|
| 305 |
+
|
| 306 |
+
- Redirect the warning stream to the shell during the ScriptBinding check of
|
| 307 |
+
user code and format the warning similarly to an exception for both that
|
| 308 |
+
check and for runtime warnings raised in the subprocess.
|
| 309 |
+
|
| 310 |
+
- CodeContext hint pane visibility state is now persistent across sessions.
|
| 311 |
+
The pane no longer appears in the shell window. Added capability to limit
|
| 312 |
+
extensions to shell window or editor windows. Noam Raphael addition
|
| 313 |
+
to Patch 936169.
|
| 314 |
+
|
| 315 |
+
- Paragraph reformat width is now a configurable parameter in the
|
| 316 |
+
Options GUI.
|
| 317 |
+
|
| 318 |
+
- New Extension: CodeContext. Provides block structuring hints for code
|
| 319 |
+
which has scrolled above an edit window. Patch 936169 Noam Raphael.
|
| 320 |
+
|
| 321 |
+
- If nulls somehow got into the strings in recent-files.lst
|
| 322 |
+
EditorWindow.update_recent_files_list() was failing. Python Bug 931336.
|
| 323 |
+
|
| 324 |
+
- If the normal background is changed via Configure/Highlighting, it will
|
| 325 |
+
update immediately, thanks to the previously mentioned patch by Nigel Rowe.
|
| 326 |
+
|
| 327 |
+
- Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
|
| 328 |
+
This also fixed IDLEfork bug [ 693418 ] Normal text background color not
|
| 329 |
+
refreshed and Python bug [897872 ] Unknown color name on HP-UX
|
| 330 |
+
|
| 331 |
+
- rpc.py:SocketIO - Large modules were generating large pickles when downloaded
|
| 332 |
+
to the execution server. The return of the OK response from the subprocess
|
| 333 |
+
initialization was interfering and causing the sending socket to be not
|
| 334 |
+
ready. Add an IO ready test to fix this. Moved the polling IO ready test
|
| 335 |
+
into pollpacket().
|
| 336 |
+
|
| 337 |
+
- Fix typo in rpc.py, s/b "pickle.PicklingError" not "pickle.UnpicklingError".
|
| 338 |
+
|
| 339 |
+
- Added a Tk error dialog to run.py inform the user if the subprocess can't
|
| 340 |
+
connect to the user GUI process. Added a timeout to the GUI's listening
|
| 341 |
+
socket. Added Tk error dialogs to PyShell.py to announce a failure to bind
|
| 342 |
+
the port or connect to the subprocess. Clean up error handling during
|
| 343 |
+
connection initiation phase. This is an update of Python Patch 778323.
|
| 344 |
+
|
| 345 |
+
- Print correct exception even if source file changed since shell was
|
| 346 |
+
restarted. IDLEfork Patch 869012 Noam Raphael
|
| 347 |
+
|
| 348 |
+
- Keybindings with the Shift modifier now work correctly. So do bindings which
|
| 349 |
+
use the Space key. Limit unmodified user keybindings to the function keys.
|
| 350 |
+
Python Bug 775353, IDLEfork Bugs 755647, 761557
|
| 351 |
+
|
| 352 |
+
- After an exception, run.py was not setting the exception vector. Noam
|
| 353 |
+
Raphael suggested correcting this so pdb's postmortem pm() would work.
|
| 354 |
+
IDLEfork Patch 844675
|
| 355 |
+
|
| 356 |
+
- IDLE now does not fail to save the file anymore if the Tk buffer is not a
|
| 357 |
+
Unicode string, yet eol_convention is. Python Bugs 774680, 788378
|
| 358 |
+
|
| 359 |
+
- IDLE didn't start correctly when Python was installed in "Program Files" on
|
| 360 |
+
W2K and XP. Python Bugs 780451, 784183
|
| 361 |
+
|
| 362 |
+
- config-main.def documentation incorrectly referred to idle- instead of
|
| 363 |
+
config- filenames. SF 782759 Also added note about .idlerc location.
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
What's New in IDLE 1.0?
|
| 367 |
+
=======================
|
| 368 |
+
*Release date: 29-Jul-2003*
|
| 369 |
+
|
| 370 |
+
- Added a banner to the shell discussing warnings possibly raised by personal
|
| 371 |
+
firewall software. Added same comment to README.txt.
|
| 372 |
+
|
| 373 |
+
- Calltip error when docstring was None Python Bug 775541
|
| 374 |
+
|
| 375 |
+
- Updated extend.txt, help.txt, and config-extensions.def to correctly
|
| 376 |
+
reflect the current status of the configuration system. Python Bug 768469
|
| 377 |
+
|
| 378 |
+
- Fixed: Call Tip Trimming May Loop Forever. Python Patch 769142 (Daniels)
|
| 379 |
+
|
| 380 |
+
- Replaced apply(f, args, kwds) with f(*args, **kwargs) to improve performance
|
| 381 |
+
Python Patch 768187
|
| 382 |
+
|
| 383 |
+
- Break or continue statements outside a loop were causing IDLE crash
|
| 384 |
+
Python Bug 767794
|
| 385 |
+
|
| 386 |
+
- Convert Unicode strings from readline to IOBinding.encoding. Also set
|
| 387 |
+
sys.std{in|out|err}.encoding, for both the local and the subprocess case.
|
| 388 |
+
SF IDLEfork patch 682347.
|
| 389 |
+
|
| 390 |
+
- Extend AboutDialog.ViewFile() to support file encodings. Make the CREDITS
|
| 391 |
+
file Latin-1.
|
| 392 |
+
|
| 393 |
+
- Updated the About dialog to reflect re-integration into Python. Provide
|
| 394 |
+
buttons to display Python's NEWS, License, and Credits, plus additional
|
| 395 |
+
buttons for IDLE's README and NEWS.
|
| 396 |
+
|
| 397 |
+
- TextViewer() now has a third parameter which allows inserting text into the
|
| 398 |
+
viewer instead of reading from a file.
|
| 399 |
+
|
| 400 |
+
- (Created the .../Lib/idlelib directory in the Python CVS, which is a clone of
|
| 401 |
+
IDLEfork modified to install in the Python environment. The code in the
|
| 402 |
+
interrupt module has been moved to thread.interrupt_main(). )
|
| 403 |
+
|
| 404 |
+
- Printing the Shell window was failing if it was not saved first SF 748975
|
| 405 |
+
|
| 406 |
+
- When using the Search in Files dialog, if the user had a selection
|
| 407 |
+
highlighted in his Editor window, insert it into the dialog search field.
|
| 408 |
+
|
| 409 |
+
- The Python Shell entry was disappearing from the Windows menu.
|
| 410 |
+
|
| 411 |
+
- Update the Windows file list when a file name change occurs
|
| 412 |
+
|
| 413 |
+
- Change to File / Open Module: always pop up the dialog, using the current
|
| 414 |
+
selection as the default value. This is easier to use habitually.
|
| 415 |
+
|
| 416 |
+
- Avoided a problem with starting the subprocess when 'localhost' doesn't
|
| 417 |
+
resolve to the user's loopback interface. SF 747772
|
| 418 |
+
|
| 419 |
+
- Fixed an issue with highlighted errors never de-colorizing. SF 747677. Also
|
| 420 |
+
improved notification of Tabnanny Token Error.
|
| 421 |
+
|
| 422 |
+
- File / New will by default save in the directory of the Edit window from
|
| 423 |
+
which it was initiated. SF 748973 Guido van Rossum patch.
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
What's New in IDLEfork 0.9b1?
|
| 427 |
+
=============================
|
| 428 |
+
*Release date: 02-Jun-2003*
|
| 429 |
+
|
| 430 |
+
- The current working directory of the execution environment (and shell
|
| 431 |
+
following completion of execution) is now that of the module being run.
|
| 432 |
+
|
| 433 |
+
- Added the delete-exitfunc option to config-main.def. (This option is not
|
| 434 |
+
included in the Options dialog.) Setting this to True (the default) will
|
| 435 |
+
cause IDLE to not run sys.exitfunc/atexit when the subprocess exits.
|
| 436 |
+
|
| 437 |
+
- IDLE now preserves the line ending codes when editing a file produced on
|
| 438 |
+
a different platform. SF 661759, SF 538584
|
| 439 |
+
|
| 440 |
+
- Reduced default editor font size to 10 point and increased window height
|
| 441 |
+
to provide a better initial impression on Windows.
|
| 442 |
+
|
| 443 |
+
- Options / Fonts/Tabs / Set Base Editor Font: List box was not highlighting
|
| 444 |
+
the default font when first installed on Windows. SF 661676
|
| 445 |
+
|
| 446 |
+
- Added Autosave feature: when user runs code from edit window, if the file
|
| 447 |
+
has been modified IDLE will silently save it if Autosave is enabled. The
|
| 448 |
+
option is set in the Options dialog, and the default is to prompt the
|
| 449 |
+
user to save the file. SF 661318 Bruce Sherwood patch.
|
| 450 |
+
|
| 451 |
+
- Improved the RESTART annotation in the shell window when the user restarts
|
| 452 |
+
the shell while it is generating output. Also improved annotation when user
|
| 453 |
+
repeatedly hammers the Ctrl-F6 restart.
|
| 454 |
+
|
| 455 |
+
- Allow IDLE to run when not installed and cwd is not the IDLE directory
|
| 456 |
+
SF Patch 686254 "Run IDLEfork from any directory without set-up" - Raphael
|
| 457 |
+
|
| 458 |
+
- When a module is run from an EditorWindow: if its directory is not in
|
| 459 |
+
sys.path, prepend it. This allows the module to import other modules in
|
| 460 |
+
the same directory. Do the same for a script run from the command line.
|
| 461 |
+
|
| 462 |
+
- Correctly restart the subprocess if it is running user code and the user
|
| 463 |
+
attempts to run some other module or restarts the shell. Do the same if
|
| 464 |
+
the link is broken and it is possible to restart the subprocess and re-
|
| 465 |
+
connect to the GUI. SF RFE 661321.
|
| 466 |
+
|
| 467 |
+
- Improved exception reporting when running commands or scripts from the
|
| 468 |
+
command line.
|
| 469 |
+
|
| 470 |
+
- Added a -n command line switch to start IDLE without the subprocess.
|
| 471 |
+
Removed the Shell menu when running in that mode. Updated help messages.
|
| 472 |
+
|
| 473 |
+
- Added a comment to the shell startup header to indicate when IDLE is not
|
| 474 |
+
using the subprocess.
|
| 475 |
+
|
| 476 |
+
- Restore the ability to run without the subprocess. This can be important for
|
| 477 |
+
some platforms or configurations. (Running without the subprocess allows the
|
| 478 |
+
debugger to trace through parts of IDLE itself, which may or may not be
|
| 479 |
+
desirable, depending on your point of view. In addition, the traditional
|
| 480 |
+
reload/import tricks must be use if user source code is changed.) This is
|
| 481 |
+
helpful for developing IDLE using IDLE, because one instance can be used to
|
| 482 |
+
edit the code and a separate instance run to test changes. (Multiple
|
| 483 |
+
concurrent IDLE instances with subprocesses is a future feature)
|
| 484 |
+
|
| 485 |
+
- Improve the error message a user gets when saving a file with non-ASCII
|
| 486 |
+
characters and no source encoding is specified. Done by adding a dialog
|
| 487 |
+
'EncodingMessage', which contains the line to add in a fixed-font entry
|
| 488 |
+
widget, and which has a button to add that line to the file automatically.
|
| 489 |
+
Also, add a configuration option 'EditorWindow/encoding', which has three
|
| 490 |
+
possible values: none, utf-8, and locale. None is the default: IDLE will show
|
| 491 |
+
this dialog when non-ASCII characters are encountered. utf-8 means that files
|
| 492 |
+
with non-ASCII characters are saved as utf-8-with-bom. locale means that
|
| 493 |
+
files are saved in the locale's encoding; the dialog is only displayed if the
|
| 494 |
+
source contains characters outside the locale's charset. SF 710733 - Loewis
|
| 495 |
+
|
| 496 |
+
- Improved I/O response by tweaking the wait parameter in various
|
| 497 |
+
calls to signal.signal().
|
| 498 |
+
|
| 499 |
+
- Implemented a threaded subprocess which allows interrupting a pass
|
| 500 |
+
loop in user code using the 'interrupt' extension. User code runs
|
| 501 |
+
in MainThread, while the RPCServer is handled by SockThread. This is
|
| 502 |
+
necessary because Windows doesn't support signals.
|
| 503 |
+
|
| 504 |
+
- Implemented the 'interrupt' extension module, which allows a subthread
|
| 505 |
+
to raise a KeyboardInterrupt in the main thread.
|
| 506 |
+
|
| 507 |
+
- Attempting to save the shell raised an error related to saving
|
| 508 |
+
breakpoints, which are not implemented in the shell
|
| 509 |
+
|
| 510 |
+
- Provide a correct message when 'exit' or 'quit' are entered at the
|
| 511 |
+
IDLE command prompt SF 695861
|
| 512 |
+
|
| 513 |
+
- Eliminate extra blank line in shell output caused by not flushing
|
| 514 |
+
stdout when user code ends with an unterminated print. SF 695861
|
| 515 |
+
|
| 516 |
+
- Moved responsibility for exception formatting (i.e. pruning IDLE internal
|
| 517 |
+
calls) out of rpc.py into the client and server.
|
| 518 |
+
|
| 519 |
+
- Exit IDLE cleanly even when doing subprocess I/O
|
| 520 |
+
|
| 521 |
+
- Handle subprocess interrupt with an RPC message.
|
| 522 |
+
|
| 523 |
+
- Restart the subprocess if it terminates itself. (VPython programs do that)
|
| 524 |
+
|
| 525 |
+
- Support subclassing of exceptions, including in the shell, by moving the
|
| 526 |
+
exception formatting to the subprocess.
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
What's New in IDLEfork 0.9 Alpha 2?
|
| 530 |
+
===================================
|
| 531 |
+
*Release date: 27-Jan-2003*
|
| 532 |
+
|
| 533 |
+
- Updated INSTALL.txt to claify use of the python2 rpm.
|
| 534 |
+
|
| 535 |
+
- Improved formatting in IDLE Help.
|
| 536 |
+
|
| 537 |
+
- Run menu: Replace "Run Script" with "Run Module".
|
| 538 |
+
|
| 539 |
+
- Code encountering an unhandled exception under the debugger now shows
|
| 540 |
+
the correct traceback, with IDLE internal levels pruned out.
|
| 541 |
+
|
| 542 |
+
- If an exception occurs entirely in IDLE, don't prune the IDLE internal
|
| 543 |
+
modules from the traceback displayed.
|
| 544 |
+
|
| 545 |
+
- Class Browser and Path Browser now use Alt-Key-2 for vertical zoom.
|
| 546 |
+
|
| 547 |
+
- IDLE icons will now install correctly even when setup.py is run from the
|
| 548 |
+
build directory
|
| 549 |
+
|
| 550 |
+
- Class Browser now compatible with Python2.3 version of pyclbr.py
|
| 551 |
+
|
| 552 |
+
- Left cursor move in presence of selected text now moves from left end
|
| 553 |
+
of the selection.
|
| 554 |
+
|
| 555 |
+
- Add Meta keybindings to "IDLE Classic Windows" to handle reversed
|
| 556 |
+
Alt/Meta on some Linux distros.
|
| 557 |
+
|
| 558 |
+
- Change default: IDLE now starts with Python Shell.
|
| 559 |
+
|
| 560 |
+
- Removed the File Path from the Additional Help Sources scrolled list.
|
| 561 |
+
|
| 562 |
+
- Add capability to access Additional Help Sources on the web if the
|
| 563 |
+
Help File Path begins with //http or www. (Otherwise local path is
|
| 564 |
+
validated, as before.)
|
| 565 |
+
|
| 566 |
+
- Additional Help Sources were not being posted on the Help menu in the
|
| 567 |
+
order entered. Implement sorting the list by [HelpFiles] 'option'
|
| 568 |
+
number.
|
| 569 |
+
|
| 570 |
+
- Add Browse button to New Help Source dialog. Arrange to start in
|
| 571 |
+
Python/Doc if platform is Windows, otherwise start in current directory.
|
| 572 |
+
|
| 573 |
+
- Put the Additional Help Sources directly on the Help menu instead of in
|
| 574 |
+
an Extra Help cascade menu. Rearrange the Help menu so the Additional
|
| 575 |
+
Help Sources come last. Update help.txt appropriately.
|
| 576 |
+
|
| 577 |
+
- Fix Tk root pop-ups in configSectionNameDialog.py and configDialog.py
|
| 578 |
+
|
| 579 |
+
- Uniform capitalization in General tab of ConfigDialog, update the doc string.
|
| 580 |
+
|
| 581 |
+
- Fix bug in ConfigDialog where SaveAllChangedConfig() was unexpectedly
|
| 582 |
+
deleting Additional Help Sources from the user's config file.
|
| 583 |
+
|
| 584 |
+
- Make configHelpSourceEdit OK button the default and bind <Return>
|
| 585 |
+
|
| 586 |
+
- Fix Tk root pop-ups in configHelpSourceEdit: error dialogs not attached
|
| 587 |
+
to parents.
|
| 588 |
+
|
| 589 |
+
- Use os.startfile() to open both Additional Help and Python Help on the
|
| 590 |
+
Windows platform. The application associated with the file type will act as
|
| 591 |
+
the viewer. Windows help files (.chm) are now supported via the
|
| 592 |
+
Settings/General/Additional Help facility.
|
| 593 |
+
|
| 594 |
+
- If Python Help files are installed locally on Linux, use them instead of
|
| 595 |
+
accessing python.org.
|
| 596 |
+
|
| 597 |
+
- Make the methods for finding the Python help docs more robust, and make
|
| 598 |
+
them work in the installed configuration, also.
|
| 599 |
+
|
| 600 |
+
- On the Save Before Run dialog, make the OK button the default. One
|
| 601 |
+
less mouse action!
|
| 602 |
+
|
| 603 |
+
- Add a method: EditorWindow.get_geometry() for future use in implementing
|
| 604 |
+
window location persistence.
|
| 605 |
+
|
| 606 |
+
- Removed the "Help/Advice" menu entry. Thanks, David! We'll remember!
|
| 607 |
+
|
| 608 |
+
- Change the "Classic Windows" theme's paste key to be <ctrl-v>.
|
| 609 |
+
|
| 610 |
+
- Rearrange the Shell menu to put Stack Viewer entries adjacent.
|
| 611 |
+
|
| 612 |
+
- Add the ability to restart the subprocess interpreter from the shell window;
|
| 613 |
+
add an associated menu entry "Shell/Restart" with binding Control-F6. Update
|
| 614 |
+
IDLE help.
|
| 615 |
+
|
| 616 |
+
- Upon a restart, annotate the shell window with a "restart boundary". Add a
|
| 617 |
+
shell window menu "Shell/View Restart" with binding F6 to jump to the most
|
| 618 |
+
recent restart boundary.
|
| 619 |
+
|
| 620 |
+
- Add Shell menu to Python Shell; change "Settings" to "Options".
|
| 621 |
+
|
| 622 |
+
- Remove incorrect comment in setup.py: IDLEfork is now installed as a package.
|
| 623 |
+
|
| 624 |
+
- Add INSTALL.txt, HISTORY.txt, NEWS.txt to installed configuration.
|
| 625 |
+
|
| 626 |
+
- In installer text, fix reference to Visual Python, should be VPython.
|
| 627 |
+
Properly credit David Scherer.
|
| 628 |
+
|
| 629 |
+
- Modified idle, idle.py, idle.pyw to improve exception handling.
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
What's New in IDLEfork 0.9 Alpha 1?
|
| 633 |
+
===================================
|
| 634 |
+
*Release date: 31-Dec-2002*
|
| 635 |
+
|
| 636 |
+
- First release of major new functionality. For further details refer to
|
| 637 |
+
Idle-dev and/or the Sourceforge CVS.
|
| 638 |
+
|
| 639 |
+
- Adapted to the Mac platform.
|
| 640 |
+
|
| 641 |
+
- Overhauled the IDLE startup options and revised the idle -h help message,
|
| 642 |
+
which provides details of command line usage.
|
| 643 |
+
|
| 644 |
+
- Multiple bug fixes and usability enhancements.
|
| 645 |
+
|
| 646 |
+
- Introduced the new RPC implementation, which includes a debugger. The output
|
| 647 |
+
of user code is to the shell, and the shell may be used to inspect the
|
| 648 |
+
environment after the run has finished. (In version 0.8.1 the shell
|
| 649 |
+
environment was separate from the environment of the user code.)
|
| 650 |
+
|
| 651 |
+
- Introduced the configuration GUI and a new About dialog.
|
| 652 |
+
|
| 653 |
+
- Removed David Scherer's Remote Procedure Call code and replaced with Guido
|
| 654 |
+
van Rossum's. GvR code has support for the IDLE debugger and uses the shell
|
| 655 |
+
to inspect the environment of code Run from an Edit window. Files removed:
|
| 656 |
+
ExecBinding.py, loader.py, protocol.py, Remote.py, spawn.py
|
| 657 |
+
|
| 658 |
+
--------------------------------------------------------------------
|
| 659 |
+
Refer to HISTORY.txt for additional information on earlier releases.
|
| 660 |
+
--------------------------------------------------------------------
|
deepseek/lib/python3.10/idlelib/README.tx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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
README.txt: an index to idlelib files and the IDLE menu.
|
| 2 |
+
|
| 3 |
+
IDLE is Python's Integrated Development and Learning
|
| 4 |
+
Environment. The user documentation is part of the Library Reference and
|
| 5 |
+
is available in IDLE by selecting Help => IDLE Help. This README documents
|
| 6 |
+
idlelib for IDLE developers and curious users.
|
| 7 |
+
|
| 8 |
+
IDLELIB FILES lists files alphabetically by category,
|
| 9 |
+
with a short description of each.
|
| 10 |
+
|
| 11 |
+
IDLE MENU show the menu tree, annotated with the module
|
| 12 |
+
or module object that implements the corresponding function.
|
| 13 |
+
|
| 14 |
+
This file is descriptive, not prescriptive, and may have errors
|
| 15 |
+
and omissions and lag behind changes in idlelib.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
IDLELIB FILES
|
| 19 |
+
=============
|
| 20 |
+
|
| 21 |
+
Implementation files not in IDLE MENU are marked (nim).
|
| 22 |
+
|
| 23 |
+
Startup
|
| 24 |
+
-------
|
| 25 |
+
__init__.py # import, does nothing
|
| 26 |
+
__main__.py # -m, starts IDLE
|
| 27 |
+
idle.bat
|
| 28 |
+
idle.py
|
| 29 |
+
idle.pyw
|
| 30 |
+
|
| 31 |
+
Implementation
|
| 32 |
+
--------------
|
| 33 |
+
autocomplete.py # Complete attribute names or filenames.
|
| 34 |
+
autocomplete_w.py # Display completions.
|
| 35 |
+
autoexpand.py # Expand word with previous word in file.
|
| 36 |
+
browser.py # Create module browser window.
|
| 37 |
+
calltip.py # Create calltip text.
|
| 38 |
+
calltip_w.py # Display calltip.
|
| 39 |
+
codecontext.py # Show compound statement headers otherwise not visible.
|
| 40 |
+
colorizer.py # Colorize text (nim).
|
| 41 |
+
config.py # Load, fetch, and save configuration (nim).
|
| 42 |
+
configdialog.py # Display user configuration dialogs.
|
| 43 |
+
config_key.py # Change keybindings.
|
| 44 |
+
debugger.py # Debug code run from shell or editor; show window.
|
| 45 |
+
debugger_r.py # Debug code run in remote process.
|
| 46 |
+
debugobj.py # Define class used in stackviewer.
|
| 47 |
+
debugobj_r.py # Communicate objects between processes with rpc (nim).
|
| 48 |
+
delegator.py # Define base class for delegators (nim).
|
| 49 |
+
dynoption.py # Define mutable OptionMenu widget (nim)
|
| 50 |
+
editor.py # Define most of editor and utility functions.
|
| 51 |
+
filelist.py # Open files and manage list of open windows (nim).
|
| 52 |
+
format.py # Define format menu options.
|
| 53 |
+
grep.py # Find all occurrences of pattern in multiple files.
|
| 54 |
+
help.py # Display IDLE's html doc.
|
| 55 |
+
help_about.py # Display About IDLE dialog.
|
| 56 |
+
history.py # Get previous or next user input in shell (nim)
|
| 57 |
+
hyperparser.py # Parse code around a given index.
|
| 58 |
+
iomenu.py # Open, read, and write files
|
| 59 |
+
macosx.py # Help IDLE run on Macs (nim).
|
| 60 |
+
mainmenu.py # Define most of IDLE menu.
|
| 61 |
+
multicall.py # Wrap tk widget to allow multiple calls per event (nim).
|
| 62 |
+
outwin.py # Create window for grep output.
|
| 63 |
+
parenmatch.py # Match fenceposts: (), [], and {}.
|
| 64 |
+
pathbrowser.py # Create path browser window.
|
| 65 |
+
percolator.py # Manage delegator stack (nim).
|
| 66 |
+
pyparse.py # Give information on code indentation
|
| 67 |
+
pyshell.py # Start IDLE, manage shell, complete editor window
|
| 68 |
+
query.py # Query user for information
|
| 69 |
+
redirector.py # Intercept widget subcommands (for percolator) (nim).
|
| 70 |
+
replace.py # Search and replace pattern in text.
|
| 71 |
+
rpc.py # Communicate between idle and user processes (nim).
|
| 72 |
+
run.py # Manage user code execution subprocess.
|
| 73 |
+
runscript.py # Check and run user code.
|
| 74 |
+
scrolledlist.py # Define scrolledlist widget for IDLE (nim).
|
| 75 |
+
search.py # Search for pattern in text.
|
| 76 |
+
searchbase.py # Define base for search, replace, and grep dialogs.
|
| 77 |
+
searchengine.py # Define engine for all 3 search dialogs.
|
| 78 |
+
sidebar.py # Define line number and shell prompt sidebars.
|
| 79 |
+
squeezer.py # Squeeze long shell output (nim).
|
| 80 |
+
stackviewer.py # View stack after exception.
|
| 81 |
+
statusbar.py # Define status bar for windows (nim).
|
| 82 |
+
tabbedpages.py # Define tabbed pages widget (nim).
|
| 83 |
+
textview.py # Define read-only text widget (nim).
|
| 84 |
+
tooltip.py # Define popups for calltips, squeezer (nim).
|
| 85 |
+
tree.py # Define tree widget, used in browsers (nim).
|
| 86 |
+
undo.py # Manage undo stack.
|
| 87 |
+
util.py # Define common objects imported elsewhere (nim).
|
| 88 |
+
windows.py # Manage window list and define listed top level.
|
| 89 |
+
zoomheight.py # Zoom window to full height of screen.
|
| 90 |
+
zzdummy.py # Example extension.
|
| 91 |
+
|
| 92 |
+
Configuration
|
| 93 |
+
-------------
|
| 94 |
+
config-extensions.def # Defaults for extensions
|
| 95 |
+
config-highlight.def # Defaults for colorizing
|
| 96 |
+
config-keys.def # Defaults for key bindings
|
| 97 |
+
config-main.def # Defaults for font and general tabs
|
| 98 |
+
|
| 99 |
+
Text
|
| 100 |
+
----
|
| 101 |
+
CREDITS.txt # not maintained, displayed by About IDLE
|
| 102 |
+
HISTORY.txt # NEWS up to July 2001
|
| 103 |
+
NEWS.txt # commits, displayed by About IDLE
|
| 104 |
+
NEWS2.txt # commits to Python2
|
| 105 |
+
README.txt # this file, displayed by About IDLE
|
| 106 |
+
TODO.txt # needs review
|
| 107 |
+
extend.txt # about writing extensions
|
| 108 |
+
help.html # copy of idle.html in docs, displayed by IDLE Help
|
| 109 |
+
|
| 110 |
+
Subdirectories
|
| 111 |
+
--------------
|
| 112 |
+
Icons # small image files
|
| 113 |
+
idle_test # files for human test and automated unit tests
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
IDLE MENUS
|
| 117 |
+
==========
|
| 118 |
+
|
| 119 |
+
Top level items and most submenu items are defined in mainmenu.
|
| 120 |
+
Extensions add submenu items when active. The names given are
|
| 121 |
+
found, quoted, in one of these modules, paired with a '<<pseudoevent>>'.
|
| 122 |
+
Each pseudoevent is bound to an event handler. Some event handlers
|
| 123 |
+
call another function that does the actual work. The annotations below
|
| 124 |
+
are intended to at least give the module where the actual work is done.
|
| 125 |
+
'eEW' = editor.EditorWindow
|
| 126 |
+
|
| 127 |
+
File
|
| 128 |
+
New File # eEW.new_callback
|
| 129 |
+
Open... # iomenu.open
|
| 130 |
+
Open Module # eEw.open_module
|
| 131 |
+
Recent Files
|
| 132 |
+
Class Browser # eEW.open_class_browser, browser.ClassBrowser
|
| 133 |
+
Path Browser # eEW.open_path_browser, pathbrowser
|
| 134 |
+
---
|
| 135 |
+
Save # iomenu.save
|
| 136 |
+
Save As... # iomenu.save_as
|
| 137 |
+
Save Copy As... # iomenu.save_a_copy
|
| 138 |
+
---
|
| 139 |
+
Print Window # iomenu.print_window
|
| 140 |
+
---
|
| 141 |
+
Close # eEW.close_event
|
| 142 |
+
Exit # flist.close_all_callback (bound in eEW)
|
| 143 |
+
|
| 144 |
+
Edit
|
| 145 |
+
Undo # undodelegator
|
| 146 |
+
Redo # undodelegator
|
| 147 |
+
--- # eEW.right_menu_event
|
| 148 |
+
Cut # eEW.cut
|
| 149 |
+
Copy # eEW.copy
|
| 150 |
+
Paste # eEW.past
|
| 151 |
+
Select All # eEW.select_all (+ see eEW.remove_selection)
|
| 152 |
+
--- # Next 5 items use searchengine; dialogs use searchbase
|
| 153 |
+
Find # eEW.find_event, search.SearchDialog.find
|
| 154 |
+
Find Again # eEW.find_again_event, sSD.find_again
|
| 155 |
+
Find Selection # eEW.find_selection_event, sSD.find_selection
|
| 156 |
+
Find in Files... # eEW.find_in_files_event, grep
|
| 157 |
+
Replace... # eEW.replace_event, replace.ReplaceDialog.replace
|
| 158 |
+
Go to Line # eEW.goto_line_event
|
| 159 |
+
Show Completions # autocomplete extension and autocompleteWidow (&HP)
|
| 160 |
+
Expand Word # autoexpand extension
|
| 161 |
+
Show call tip # Calltips extension and CalltipWindow (& Hyperparser)
|
| 162 |
+
Show surrounding parens # parenmatch (& Hyperparser)
|
| 163 |
+
|
| 164 |
+
Format (Editor only) [fFR = format.FormatRegion]
|
| 165 |
+
Format Paragraph # format.FormatParagraph.format_paragraph_event
|
| 166 |
+
Indent Region # fFR.indent_region_event
|
| 167 |
+
Dedent Region # fFR.dedent_region_event
|
| 168 |
+
Comment Out Reg. # fFR.comment_region_event
|
| 169 |
+
Uncomment Region # fFR.uncomment_region_event
|
| 170 |
+
Tabify Region # fFR.tabify_region_event
|
| 171 |
+
Untabify Region # fFR.untabify_region_event
|
| 172 |
+
Toggle Tabs # format.Indents.toggle_tabs_event
|
| 173 |
+
New Indent Width # format.Indents.change_indentwidth_event
|
| 174 |
+
Strip tailing whitespace # format.rstrip
|
| 175 |
+
Zin # zzdummy
|
| 176 |
+
Zout # zzdummy
|
| 177 |
+
|
| 178 |
+
Run (Editor only)
|
| 179 |
+
Run Module # runscript.ScriptBinding.run_module_event
|
| 180 |
+
Run... Customized # runscript.ScriptBinding.run_custom_event
|
| 181 |
+
Check Module # runscript.ScriptBinding.check_module_event
|
| 182 |
+
Python Shell # pyshell.Pyshell, pyshell.ModifiedInterpreter
|
| 183 |
+
|
| 184 |
+
Shell # pyshell
|
| 185 |
+
View Last Restart # pyshell.PyShell.view_restart_mark
|
| 186 |
+
Restart Shell # pyshell.PyShell.restart_shell
|
| 187 |
+
Previous History # history.History.history_prev
|
| 188 |
+
Next History # history.History.history_next
|
| 189 |
+
Interrupt Execution # pyshell.PyShell.cancel_callback
|
| 190 |
+
|
| 191 |
+
Debug (Shell only)
|
| 192 |
+
Go to File/Line # outwin.OutputWindow.goto_file_line
|
| 193 |
+
debugger # debugger, debugger_r, PyShell.toggle_debugger
|
| 194 |
+
Stack Viewer # stackviewer, PyShell.open_stack_viewer
|
| 195 |
+
Auto-open Stack Viewer # stackviewer
|
| 196 |
+
|
| 197 |
+
Options
|
| 198 |
+
Configure IDLE # eEW.config_dialog, config, configdialog (cd)
|
| 199 |
+
(Parts of the dialog)
|
| 200 |
+
Buttons # cd.ConfigDialog
|
| 201 |
+
Font tab # cd.FontPage, config-main.def
|
| 202 |
+
Highlight tab # cd.HighPage, query, config-highlight.def
|
| 203 |
+
Keys tab # cd.KeysPage, query, config_key, config_keys.def
|
| 204 |
+
Windows tab # cd.WinPage, config_main.def
|
| 205 |
+
Shell/Ed tab # cd.ShedPage, config-main.def
|
| 206 |
+
Extensions tab # config-extensions.def, corresponding .py files
|
| 207 |
+
---
|
| 208 |
+
... Code Context # codecontext
|
| 209 |
+
... Line Numbers # sidebar
|
| 210 |
+
Zoomheight # zoomheight
|
| 211 |
+
|
| 212 |
+
Window
|
| 213 |
+
<open windows> # windows
|
| 214 |
+
|
| 215 |
+
Help
|
| 216 |
+
About IDLE # eEW.about_dialog, help_about.AboutDialog
|
| 217 |
+
---
|
| 218 |
+
IDLE Help # eEW.help_dialog, help.show_idlehelp
|
| 219 |
+
Python Docs # eEW.python_docs
|
| 220 |
+
Turtle Demo # eEW.open_turtle_demo
|
| 221 |
+
---
|
| 222 |
+
<other help sources>
|
| 223 |
+
|
| 224 |
+
<Context Menu> (right click)
|
| 225 |
+
Defined in editor, PyShell.pyshell
|
| 226 |
+
Cut
|
| 227 |
+
Copy
|
| 228 |
+
Paste
|
| 229 |
+
---
|
| 230 |
+
Go to file/line (shell and output only)
|
| 231 |
+
Set Breakpoint (editor only)
|
| 232 |
+
Clear Breakpoint (editor only)
|
| 233 |
+
Defined in debugger
|
| 234 |
+
Go to source line
|
| 235 |
+
Show stack frame
|
| 236 |
+
|
| 237 |
+
<No menu>
|
| 238 |
+
Center Insert # eEW.center_insert_event
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
OTHER TOPICS
|
| 242 |
+
============
|
| 243 |
+
|
| 244 |
+
Generally use PEP 8.
|
| 245 |
+
|
| 246 |
+
import statements
|
| 247 |
+
-----------------
|
| 248 |
+
Put imports at the top, unless there is a good reason otherwise.
|
| 249 |
+
PEP 8 says to group stdlib, 3rd-party dependencies, and package imports.
|
| 250 |
+
For idlelib, the groups are general stdlib, tkinter, and idlelib.
|
| 251 |
+
Sort modules within each group, except that tkinter.ttk follows tkinter.
|
| 252 |
+
Sort 'from idlelib import mod1' and 'from idlelib.mod2 import object'
|
| 253 |
+
together by module, ignoring within module objects.
|
| 254 |
+
Put 'import __main__' after other idlelib imports.
|
| 255 |
+
|
| 256 |
+
Imports only needed for testing are put not at the top but in an
|
| 257 |
+
htest function def or "if __name__ == '__main__'" clause.
|
| 258 |
+
|
| 259 |
+
Within module imports like "from idlelib.mod import class" may cause
|
| 260 |
+
circular imports to deadlock. Even without this, circular imports may
|
| 261 |
+
require at least one of the imports to be delayed until a function call.
|
| 262 |
+
|
| 263 |
+
What's New entries
|
| 264 |
+
------------------
|
| 265 |
+
|
| 266 |
+
Repository directory Doc/whatsnew/ has a file 3.n.rst for each 3.n
|
| 267 |
+
Python version. For the first entry in each file, add subsection
|
| 268 |
+
'IDLE and idlelib', in alphabetical position, to the 'Improved Modules'
|
| 269 |
+
section. For the rest of cpython, entries to 3.(n+1).rst begin with
|
| 270 |
+
the release of 3.n.0b1. For IDLE, entries for features backported from
|
| 271 |
+
'main' to '3.n' during its beta period do not got in 3.(n+1).rst. The
|
| 272 |
+
latter usually gets its first entry during the 3.n.0 candidate period
|
| 273 |
+
or after the 3.n.0 release.
|
| 274 |
+
|
| 275 |
+
When, as per PEP 434, feature changes are backported, entries are placed
|
| 276 |
+
in the 3.n.rst file *in the main branch* for each Python version n that
|
| 277 |
+
gets the backport. (Note: the format of entries have varied between
|
| 278 |
+
versions.) Add a line "New in 3.n maintenance releases." before the
|
| 279 |
+
first back-ported feature after 3.n.0 is released. Since each older
|
| 280 |
+
version file gets a different number of backports, it is easiest to
|
| 281 |
+
make a separate PR for each file and label it with the backports
|
| 282 |
+
needed.
|
| 283 |
+
|
| 284 |
+
Github repository and issues
|
| 285 |
+
----------------------------
|
| 286 |
+
|
| 287 |
+
The CPython repository is https://github.com/python/cpython. The
|
| 288 |
+
IDLE Issues listing is https://github.com/orgs/python/projects/31.
|
| 289 |
+
The main classification is by Topic, based on the IDLE menu. View the
|
| 290 |
+
topics list by clicking the [<]] button in the upper right.
|
deepseek/lib/python3.10/idlelib/TODO.txt
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
| 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
|
deepseek/lib/python3.10/idlelib/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The idlelib package implements the Idle application.
|
| 2 |
+
|
| 3 |
+
Idle includes an interactive shell and editor.
|
| 4 |
+
Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
|
| 5 |
+
Use the files named idle.* to start Idle.
|
| 6 |
+
|
| 7 |
+
The other files are private implementations. Their details are subject to
|
| 8 |
+
change. See PEP 434 for more. Import them at your own risk.
|
| 9 |
+
"""
|
| 10 |
+
testing = False # Set True by test.test_idle.
|
deepseek/lib/python3.10/idlelib/autocomplete.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Complete either attribute names or file names.
|
| 2 |
+
|
| 3 |
+
Either on demand or after a user-selected delay after a key character,
|
| 4 |
+
pop up a list of candidates.
|
| 5 |
+
"""
|
| 6 |
+
import __main__
|
| 7 |
+
import keyword
|
| 8 |
+
import os
|
| 9 |
+
import string
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
# Modified keyword list is used in fetch_completions.
|
| 13 |
+
completion_kwds = [s for s in keyword.kwlist
|
| 14 |
+
if s not in {'True', 'False', 'None'}] # In builtins.
|
| 15 |
+
completion_kwds.extend(('match', 'case')) # Context keywords.
|
| 16 |
+
completion_kwds.sort()
|
| 17 |
+
|
| 18 |
+
# Two types of completions; defined here for autocomplete_w import below.
|
| 19 |
+
ATTRS, FILES = 0, 1
|
| 20 |
+
from idlelib import autocomplete_w
|
| 21 |
+
from idlelib.config import idleConf
|
| 22 |
+
from idlelib.hyperparser import HyperParser
|
| 23 |
+
|
| 24 |
+
# Tuples passed to open_completions.
|
| 25 |
+
# EvalFunc, Complete, WantWin, Mode
|
| 26 |
+
FORCE = True, False, True, None # Control-Space.
|
| 27 |
+
TAB = False, True, True, None # Tab.
|
| 28 |
+
TRY_A = False, False, False, ATTRS # '.' for attributes.
|
| 29 |
+
TRY_F = False, False, False, FILES # '/' in quotes for file name.
|
| 30 |
+
|
| 31 |
+
# This string includes all chars that may be in an identifier.
|
| 32 |
+
# TODO Update this here and elsewhere.
|
| 33 |
+
ID_CHARS = string.ascii_letters + string.digits + "_"
|
| 34 |
+
|
| 35 |
+
SEPS = f"{os.sep}{os.altsep if os.altsep else ''}"
|
| 36 |
+
TRIGGERS = f".{SEPS}"
|
| 37 |
+
|
| 38 |
+
class AutoComplete:
|
| 39 |
+
|
| 40 |
+
def __init__(self, editwin=None, tags=None):
|
| 41 |
+
self.editwin = editwin
|
| 42 |
+
if editwin is not None: # not in subprocess or no-gui test
|
| 43 |
+
self.text = editwin.text
|
| 44 |
+
self.tags = tags
|
| 45 |
+
self.autocompletewindow = None
|
| 46 |
+
# id of delayed call, and the index of the text insert when
|
| 47 |
+
# the delayed call was issued. If _delayed_completion_id is
|
| 48 |
+
# None, there is no delayed call.
|
| 49 |
+
self._delayed_completion_id = None
|
| 50 |
+
self._delayed_completion_index = None
|
| 51 |
+
|
| 52 |
+
@classmethod
|
| 53 |
+
def reload(cls):
|
| 54 |
+
cls.popupwait = idleConf.GetOption(
|
| 55 |
+
"extensions", "AutoComplete", "popupwait", type="int", default=0)
|
| 56 |
+
|
| 57 |
+
def _make_autocomplete_window(self): # Makes mocking easier.
|
| 58 |
+
return autocomplete_w.AutoCompleteWindow(self.text, tags=self.tags)
|
| 59 |
+
|
| 60 |
+
def _remove_autocomplete_window(self, event=None):
|
| 61 |
+
if self.autocompletewindow:
|
| 62 |
+
self.autocompletewindow.hide_window()
|
| 63 |
+
self.autocompletewindow = None
|
| 64 |
+
|
| 65 |
+
def force_open_completions_event(self, event):
|
| 66 |
+
"(^space) Open completion list, even if a function call is needed."
|
| 67 |
+
self.open_completions(FORCE)
|
| 68 |
+
return "break"
|
| 69 |
+
|
| 70 |
+
def autocomplete_event(self, event):
|
| 71 |
+
"(tab) Complete word or open list if multiple options."
|
| 72 |
+
if hasattr(event, "mc_state") and event.mc_state or\
|
| 73 |
+
not self.text.get("insert linestart", "insert").strip():
|
| 74 |
+
# A modifier was pressed along with the tab or
|
| 75 |
+
# there is only previous whitespace on this line, so tab.
|
| 76 |
+
return None
|
| 77 |
+
if self.autocompletewindow and self.autocompletewindow.is_active():
|
| 78 |
+
self.autocompletewindow.complete()
|
| 79 |
+
return "break"
|
| 80 |
+
else:
|
| 81 |
+
opened = self.open_completions(TAB)
|
| 82 |
+
return "break" if opened else None
|
| 83 |
+
|
| 84 |
+
def try_open_completions_event(self, event=None):
|
| 85 |
+
"(./) Open completion list after pause with no movement."
|
| 86 |
+
lastchar = self.text.get("insert-1c")
|
| 87 |
+
if lastchar in TRIGGERS:
|
| 88 |
+
args = TRY_A if lastchar == "." else TRY_F
|
| 89 |
+
self._delayed_completion_index = self.text.index("insert")
|
| 90 |
+
if self._delayed_completion_id is not None:
|
| 91 |
+
self.text.after_cancel(self._delayed_completion_id)
|
| 92 |
+
self._delayed_completion_id = self.text.after(
|
| 93 |
+
self.popupwait, self._delayed_open_completions, args)
|
| 94 |
+
|
| 95 |
+
def _delayed_open_completions(self, args):
|
| 96 |
+
"Call open_completions if index unchanged."
|
| 97 |
+
self._delayed_completion_id = None
|
| 98 |
+
if self.text.index("insert") == self._delayed_completion_index:
|
| 99 |
+
self.open_completions(args)
|
| 100 |
+
|
| 101 |
+
def open_completions(self, args):
|
| 102 |
+
"""Find the completions and create the AutoCompleteWindow.
|
| 103 |
+
Return True if successful (no syntax error or so found).
|
| 104 |
+
If complete is True, then if there's nothing to complete and no
|
| 105 |
+
start of completion, won't open completions and return False.
|
| 106 |
+
If mode is given, will open a completion list only in this mode.
|
| 107 |
+
"""
|
| 108 |
+
evalfuncs, complete, wantwin, mode = args
|
| 109 |
+
# Cancel another delayed call, if it exists.
|
| 110 |
+
if self._delayed_completion_id is not None:
|
| 111 |
+
self.text.after_cancel(self._delayed_completion_id)
|
| 112 |
+
self._delayed_completion_id = None
|
| 113 |
+
|
| 114 |
+
hp = HyperParser(self.editwin, "insert")
|
| 115 |
+
curline = self.text.get("insert linestart", "insert")
|
| 116 |
+
i = j = len(curline)
|
| 117 |
+
if hp.is_in_string() and (not mode or mode==FILES):
|
| 118 |
+
# Find the beginning of the string.
|
| 119 |
+
# fetch_completions will look at the file system to determine
|
| 120 |
+
# whether the string value constitutes an actual file name
|
| 121 |
+
# XXX could consider raw strings here and unescape the string
|
| 122 |
+
# value if it's not raw.
|
| 123 |
+
self._remove_autocomplete_window()
|
| 124 |
+
mode = FILES
|
| 125 |
+
# Find last separator or string start
|
| 126 |
+
while i and curline[i-1] not in "'\"" + SEPS:
|
| 127 |
+
i -= 1
|
| 128 |
+
comp_start = curline[i:j]
|
| 129 |
+
j = i
|
| 130 |
+
# Find string start
|
| 131 |
+
while i and curline[i-1] not in "'\"":
|
| 132 |
+
i -= 1
|
| 133 |
+
comp_what = curline[i:j]
|
| 134 |
+
elif hp.is_in_code() and (not mode or mode==ATTRS):
|
| 135 |
+
self._remove_autocomplete_window()
|
| 136 |
+
mode = ATTRS
|
| 137 |
+
while i and (curline[i-1] in ID_CHARS or ord(curline[i-1]) > 127):
|
| 138 |
+
i -= 1
|
| 139 |
+
comp_start = curline[i:j]
|
| 140 |
+
if i and curline[i-1] == '.': # Need object with attributes.
|
| 141 |
+
hp.set_index("insert-%dc" % (len(curline)-(i-1)))
|
| 142 |
+
comp_what = hp.get_expression()
|
| 143 |
+
if (not comp_what or
|
| 144 |
+
(not evalfuncs and comp_what.find('(') != -1)):
|
| 145 |
+
return None
|
| 146 |
+
else:
|
| 147 |
+
comp_what = ""
|
| 148 |
+
else:
|
| 149 |
+
return None
|
| 150 |
+
|
| 151 |
+
if complete and not comp_what and not comp_start:
|
| 152 |
+
return None
|
| 153 |
+
comp_lists = self.fetch_completions(comp_what, mode)
|
| 154 |
+
if not comp_lists[0]:
|
| 155 |
+
return None
|
| 156 |
+
self.autocompletewindow = self._make_autocomplete_window()
|
| 157 |
+
return not self.autocompletewindow.show_window(
|
| 158 |
+
comp_lists, "insert-%dc" % len(comp_start),
|
| 159 |
+
complete, mode, wantwin)
|
| 160 |
+
|
| 161 |
+
def fetch_completions(self, what, mode):
|
| 162 |
+
"""Return a pair of lists of completions for something. The first list
|
| 163 |
+
is a sublist of the second. Both are sorted.
|
| 164 |
+
|
| 165 |
+
If there is a Python subprocess, get the comp. list there. Otherwise,
|
| 166 |
+
either fetch_completions() is running in the subprocess itself or it
|
| 167 |
+
was called in an IDLE EditorWindow before any script had been run.
|
| 168 |
+
|
| 169 |
+
The subprocess environment is that of the most recently run script. If
|
| 170 |
+
two unrelated modules are being edited some calltips in the current
|
| 171 |
+
module may be inoperative if the module was not the last to run.
|
| 172 |
+
"""
|
| 173 |
+
try:
|
| 174 |
+
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
|
| 175 |
+
except:
|
| 176 |
+
rpcclt = None
|
| 177 |
+
if rpcclt:
|
| 178 |
+
return rpcclt.remotecall("exec", "get_the_completion_list",
|
| 179 |
+
(what, mode), {})
|
| 180 |
+
else:
|
| 181 |
+
if mode == ATTRS:
|
| 182 |
+
if what == "": # Main module names.
|
| 183 |
+
namespace = {**__main__.__builtins__.__dict__,
|
| 184 |
+
**__main__.__dict__}
|
| 185 |
+
bigl = eval("dir()", namespace)
|
| 186 |
+
bigl.extend(completion_kwds)
|
| 187 |
+
bigl.sort()
|
| 188 |
+
if "__all__" in bigl:
|
| 189 |
+
smalll = sorted(eval("__all__", namespace))
|
| 190 |
+
else:
|
| 191 |
+
smalll = [s for s in bigl if s[:1] != '_']
|
| 192 |
+
else:
|
| 193 |
+
try:
|
| 194 |
+
entity = self.get_entity(what)
|
| 195 |
+
bigl = dir(entity)
|
| 196 |
+
bigl.sort()
|
| 197 |
+
if "__all__" in bigl:
|
| 198 |
+
smalll = sorted(entity.__all__)
|
| 199 |
+
else:
|
| 200 |
+
smalll = [s for s in bigl if s[:1] != '_']
|
| 201 |
+
except:
|
| 202 |
+
return [], []
|
| 203 |
+
|
| 204 |
+
elif mode == FILES:
|
| 205 |
+
if what == "":
|
| 206 |
+
what = "."
|
| 207 |
+
try:
|
| 208 |
+
expandedpath = os.path.expanduser(what)
|
| 209 |
+
bigl = os.listdir(expandedpath)
|
| 210 |
+
bigl.sort()
|
| 211 |
+
smalll = [s for s in bigl if s[:1] != '.']
|
| 212 |
+
except OSError:
|
| 213 |
+
return [], []
|
| 214 |
+
|
| 215 |
+
if not smalll:
|
| 216 |
+
smalll = bigl
|
| 217 |
+
return smalll, bigl
|
| 218 |
+
|
| 219 |
+
def get_entity(self, name):
|
| 220 |
+
"Lookup name in a namespace spanning sys.modules and __main.dict__."
|
| 221 |
+
return eval(name, {**sys.modules, **__main__.__dict__})
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
AutoComplete.reload()
|
| 225 |
+
|
| 226 |
+
if __name__ == '__main__':
|
| 227 |
+
from unittest import main
|
| 228 |
+
main('idlelib.idle_test.test_autocomplete', verbosity=2)
|
deepseek/lib/python3.10/idlelib/autoexpand.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Complete the current word before the cursor with words in the editor.
|
| 2 |
+
|
| 3 |
+
Each menu selection or shortcut key selection replaces the word with a
|
| 4 |
+
different word with the same prefix. The search for matches begins
|
| 5 |
+
before the target and moves toward the top of the editor. It then starts
|
| 6 |
+
after the cursor and moves down. It then returns to the original word and
|
| 7 |
+
the cycle starts again.
|
| 8 |
+
|
| 9 |
+
Changing the current text line or leaving the cursor in a different
|
| 10 |
+
place before requesting the next selection causes AutoExpand to reset
|
| 11 |
+
its state.
|
| 12 |
+
|
| 13 |
+
There is only one instance of Autoexpand.
|
| 14 |
+
'''
|
| 15 |
+
import re
|
| 16 |
+
import string
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class AutoExpand:
|
| 20 |
+
wordchars = string.ascii_letters + string.digits + "_"
|
| 21 |
+
|
| 22 |
+
def __init__(self, editwin):
|
| 23 |
+
self.text = editwin.text
|
| 24 |
+
self.bell = self.text.bell
|
| 25 |
+
self.state = None
|
| 26 |
+
|
| 27 |
+
def expand_word_event(self, event):
|
| 28 |
+
"Replace the current word with the next expansion."
|
| 29 |
+
curinsert = self.text.index("insert")
|
| 30 |
+
curline = self.text.get("insert linestart", "insert lineend")
|
| 31 |
+
if not self.state:
|
| 32 |
+
words = self.getwords()
|
| 33 |
+
index = 0
|
| 34 |
+
else:
|
| 35 |
+
words, index, insert, line = self.state
|
| 36 |
+
if insert != curinsert or line != curline:
|
| 37 |
+
words = self.getwords()
|
| 38 |
+
index = 0
|
| 39 |
+
if not words:
|
| 40 |
+
self.bell()
|
| 41 |
+
return "break"
|
| 42 |
+
word = self.getprevword()
|
| 43 |
+
self.text.delete("insert - %d chars" % len(word), "insert")
|
| 44 |
+
newword = words[index]
|
| 45 |
+
index = (index + 1) % len(words)
|
| 46 |
+
if index == 0:
|
| 47 |
+
self.bell() # Warn we cycled around
|
| 48 |
+
self.text.insert("insert", newword)
|
| 49 |
+
curinsert = self.text.index("insert")
|
| 50 |
+
curline = self.text.get("insert linestart", "insert lineend")
|
| 51 |
+
self.state = words, index, curinsert, curline
|
| 52 |
+
return "break"
|
| 53 |
+
|
| 54 |
+
def getwords(self):
|
| 55 |
+
"Return a list of words that match the prefix before the cursor."
|
| 56 |
+
word = self.getprevword()
|
| 57 |
+
if not word:
|
| 58 |
+
return []
|
| 59 |
+
before = self.text.get("1.0", "insert wordstart")
|
| 60 |
+
wbefore = re.findall(r"\b" + word + r"\w+\b", before)
|
| 61 |
+
del before
|
| 62 |
+
after = self.text.get("insert wordend", "end")
|
| 63 |
+
wafter = re.findall(r"\b" + word + r"\w+\b", after)
|
| 64 |
+
del after
|
| 65 |
+
if not wbefore and not wafter:
|
| 66 |
+
return []
|
| 67 |
+
words = []
|
| 68 |
+
dict = {}
|
| 69 |
+
# search backwards through words before
|
| 70 |
+
wbefore.reverse()
|
| 71 |
+
for w in wbefore:
|
| 72 |
+
if dict.get(w):
|
| 73 |
+
continue
|
| 74 |
+
words.append(w)
|
| 75 |
+
dict[w] = w
|
| 76 |
+
# search onwards through words after
|
| 77 |
+
for w in wafter:
|
| 78 |
+
if dict.get(w):
|
| 79 |
+
continue
|
| 80 |
+
words.append(w)
|
| 81 |
+
dict[w] = w
|
| 82 |
+
words.append(word)
|
| 83 |
+
return words
|
| 84 |
+
|
| 85 |
+
def getprevword(self):
|
| 86 |
+
"Return the word prefix before the cursor."
|
| 87 |
+
line = self.text.get("insert linestart", "insert")
|
| 88 |
+
i = len(line)
|
| 89 |
+
while i > 0 and line[i-1] in self.wordchars:
|
| 90 |
+
i = i-1
|
| 91 |
+
return line[i:]
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
if __name__ == '__main__':
|
| 95 |
+
from unittest import main
|
| 96 |
+
main('idlelib.idle_test.test_autoexpand', verbosity=2)
|
deepseek/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)
|
deepseek/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>
|
deepseek/lib/python3.10/idlelib/config-keys.def
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle key binding settings.
|
| 3 |
+
# Where multiple keys are specified for an action: if they are separated
|
| 4 |
+
# by a space (eg. action=<key1> <key2>) then the keys are alternatives, if
|
| 5 |
+
# there is no space (eg. action=<key1><key2>) then the keys comprise a
|
| 6 |
+
# single 'emacs style' multi-keystoke binding. The tk event specifier 'Key'
|
| 7 |
+
# is used in all cases, for consistency in auto key conflict checking in the
|
| 8 |
+
# configuration gui.
|
| 9 |
+
|
| 10 |
+
[IDLE Classic Windows]
|
| 11 |
+
copy=<Control-Key-c> <Control-Key-C>
|
| 12 |
+
cut=<Control-Key-x> <Control-Key-X>
|
| 13 |
+
paste=<Control-Key-v> <Control-Key-V>
|
| 14 |
+
beginning-of-line= <Key-Home>
|
| 15 |
+
center-insert=<Control-Key-l> <Control-Key-L>
|
| 16 |
+
close-all-windows=<Control-Key-q> <Control-Key-Q>
|
| 17 |
+
close-window=<Alt-Key-F4> <Meta-Key-F4>
|
| 18 |
+
do-nothing=<Control-Key-F12>
|
| 19 |
+
end-of-file=<Control-Key-d> <Control-Key-D>
|
| 20 |
+
python-docs=<Key-F1>
|
| 21 |
+
python-context-help=<Shift-Key-F1>
|
| 22 |
+
history-next=<Alt-Key-n> <Meta-Key-n> <Alt-Key-N> <Meta-Key-N>
|
| 23 |
+
history-previous=<Alt-Key-p> <Meta-Key-p> <Alt-Key-P> <Meta-Key-P>
|
| 24 |
+
interrupt-execution=<Control-Key-c> <Control-Key-C>
|
| 25 |
+
view-restart=<Key-F6>
|
| 26 |
+
restart-shell=<Control-Key-F6>
|
| 27 |
+
open-class-browser=<Alt-Key-c> <Meta-Key-c> <Alt-Key-C> <Meta-Key-C>
|
| 28 |
+
open-module=<Alt-Key-m> <Meta-Key-m> <Alt-Key-M> <Meta-Key-M>
|
| 29 |
+
open-new-window=<Control-Key-n> <Control-Key-N>
|
| 30 |
+
open-window-from-file=<Control-Key-o> <Control-Key-O>
|
| 31 |
+
plain-newline-and-indent=<Control-Key-j> <Control-Key-J>
|
| 32 |
+
print-window=<Control-Key-p> <Control-Key-P>
|
| 33 |
+
redo=<Control-Shift-Key-Z> <Control-Shift-Key-z>
|
| 34 |
+
remove-selection=<Key-Escape>
|
| 35 |
+
save-copy-of-window-as-file=<Alt-Shift-Key-S> <Alt-Shift-Key-s>
|
| 36 |
+
save-window-as-file=<Control-Shift-Key-S> <Control-Shift-Key-s>
|
| 37 |
+
save-window=<Control-Key-s> <Control-Key-S>
|
| 38 |
+
select-all=<Control-Key-a> <Control-Key-A>
|
| 39 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 40 |
+
undo=<Control-Key-z> <Control-Key-Z>
|
| 41 |
+
find=<Control-Key-f> <Control-Key-F>
|
| 42 |
+
find-again=<Control-Key-g> <Key-F3> <Control-Key-G>
|
| 43 |
+
find-in-files=<Alt-Key-F3> <Meta-Key-F3>
|
| 44 |
+
find-selection=<Control-Key-F3>
|
| 45 |
+
replace=<Control-Key-h> <Control-Key-H>
|
| 46 |
+
goto-line=<Alt-Key-g> <Meta-Key-g> <Alt-Key-G> <Meta-Key-G>
|
| 47 |
+
smart-backspace=<Key-BackSpace>
|
| 48 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 49 |
+
smart-indent=<Key-Tab>
|
| 50 |
+
indent-region=<Control-Key-bracketright>
|
| 51 |
+
dedent-region=<Control-Key-bracketleft>
|
| 52 |
+
comment-region=<Alt-Key-3> <Meta-Key-3>
|
| 53 |
+
uncomment-region=<Alt-Key-4> <Meta-Key-4>
|
| 54 |
+
tabify-region=<Alt-Key-5> <Meta-Key-5>
|
| 55 |
+
untabify-region=<Alt-Key-6> <Meta-Key-6>
|
| 56 |
+
toggle-tabs=<Alt-Key-t> <Meta-Key-t> <Alt-Key-T> <Meta-Key-T>
|
| 57 |
+
change-indentwidth=<Alt-Key-u> <Meta-Key-u> <Alt-Key-U> <Meta-Key-U>
|
| 58 |
+
del-word-left=<Control-Key-BackSpace>
|
| 59 |
+
del-word-right=<Control-Key-Delete>
|
| 60 |
+
force-open-completions= <Control-Key-space>
|
| 61 |
+
expand-word= <Alt-Key-slash>
|
| 62 |
+
force-open-calltip= <Control-Key-backslash>
|
| 63 |
+
format-paragraph= <Alt-Key-q>
|
| 64 |
+
flash-paren= <Control-Key-0>
|
| 65 |
+
run-module= <Key-F5>
|
| 66 |
+
run-custom= <Shift-Key-F5>
|
| 67 |
+
check-module= <Alt-Key-x>
|
| 68 |
+
zoom-height= <Alt-Key-2>
|
| 69 |
+
|
| 70 |
+
[IDLE Classic Unix]
|
| 71 |
+
copy=<Alt-Key-w> <Meta-Key-w>
|
| 72 |
+
cut=<Control-Key-w>
|
| 73 |
+
paste=<Control-Key-y>
|
| 74 |
+
beginning-of-line=<Control-Key-a> <Key-Home>
|
| 75 |
+
center-insert=<Control-Key-l>
|
| 76 |
+
close-all-windows=<Control-Key-x><Control-Key-c>
|
| 77 |
+
close-window=<Control-Key-x><Control-Key-0>
|
| 78 |
+
do-nothing=<Control-Key-x>
|
| 79 |
+
end-of-file=<Control-Key-d>
|
| 80 |
+
history-next=<Alt-Key-n> <Meta-Key-n>
|
| 81 |
+
history-previous=<Alt-Key-p> <Meta-Key-p>
|
| 82 |
+
interrupt-execution=<Control-Key-c>
|
| 83 |
+
view-restart=<Key-F6>
|
| 84 |
+
restart-shell=<Control-Key-F6>
|
| 85 |
+
open-class-browser=<Control-Key-x><Control-Key-b>
|
| 86 |
+
open-module=<Control-Key-x><Control-Key-m>
|
| 87 |
+
open-new-window=<Control-Key-x><Control-Key-n>
|
| 88 |
+
open-window-from-file=<Control-Key-x><Control-Key-f>
|
| 89 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 90 |
+
print-window=<Control-x><Control-Key-p>
|
| 91 |
+
python-docs=<Control-Key-h>
|
| 92 |
+
python-context-help=<Control-Shift-Key-H>
|
| 93 |
+
redo=<Alt-Key-z> <Meta-Key-z>
|
| 94 |
+
remove-selection=<Key-Escape>
|
| 95 |
+
save-copy-of-window-as-file=<Control-Key-x><Control-Key-y>
|
| 96 |
+
save-window-as-file=<Control-Key-x><Control-Key-w>
|
| 97 |
+
save-window=<Control-Key-x><Control-Key-s>
|
| 98 |
+
select-all=<Alt-Key-a> <Meta-Key-a>
|
| 99 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 100 |
+
undo=<Control-Key-z>
|
| 101 |
+
find=<Control-Key-u><Control-Key-u><Control-Key-s>
|
| 102 |
+
find-again=<Control-Key-u><Control-Key-s>
|
| 103 |
+
find-in-files=<Alt-Key-s> <Meta-Key-s>
|
| 104 |
+
find-selection=<Control-Key-s>
|
| 105 |
+
replace=<Control-Key-r>
|
| 106 |
+
goto-line=<Alt-Key-g> <Meta-Key-g>
|
| 107 |
+
smart-backspace=<Key-BackSpace>
|
| 108 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 109 |
+
smart-indent=<Key-Tab>
|
| 110 |
+
indent-region=<Control-Key-bracketright>
|
| 111 |
+
dedent-region=<Control-Key-bracketleft>
|
| 112 |
+
comment-region=<Alt-Key-3>
|
| 113 |
+
uncomment-region=<Alt-Key-4>
|
| 114 |
+
tabify-region=<Alt-Key-5>
|
| 115 |
+
untabify-region=<Alt-Key-6>
|
| 116 |
+
toggle-tabs=<Alt-Key-t>
|
| 117 |
+
change-indentwidth=<Alt-Key-u>
|
| 118 |
+
del-word-left=<Alt-Key-BackSpace>
|
| 119 |
+
del-word-right=<Alt-Key-d>
|
| 120 |
+
force-open-completions= <Control-Key-space>
|
| 121 |
+
expand-word= <Alt-Key-slash>
|
| 122 |
+
force-open-calltip= <Control-Key-backslash>
|
| 123 |
+
format-paragraph= <Alt-Key-q>
|
| 124 |
+
flash-paren= <Control-Key-0>
|
| 125 |
+
run-module= <Key-F5>
|
| 126 |
+
run-custom= <Shift-Key-F5>
|
| 127 |
+
check-module= <Alt-Key-x>
|
| 128 |
+
zoom-height= <Alt-Key-2>
|
| 129 |
+
|
| 130 |
+
[IDLE Modern Unix]
|
| 131 |
+
copy = <Control-Shift-Key-C> <Control-Key-Insert>
|
| 132 |
+
cut = <Control-Key-x> <Shift-Key-Delete>
|
| 133 |
+
paste = <Control-Key-v> <Shift-Key-Insert>
|
| 134 |
+
beginning-of-line = <Key-Home>
|
| 135 |
+
center-insert = <Control-Key-l>
|
| 136 |
+
close-all-windows = <Control-Key-q>
|
| 137 |
+
close-window = <Control-Key-w> <Control-Shift-Key-W>
|
| 138 |
+
do-nothing = <Control-Key-F12>
|
| 139 |
+
end-of-file = <Control-Key-d>
|
| 140 |
+
history-next = <Alt-Key-n> <Meta-Key-n>
|
| 141 |
+
history-previous = <Alt-Key-p> <Meta-Key-p>
|
| 142 |
+
interrupt-execution = <Control-Key-c>
|
| 143 |
+
view-restart = <Key-F6>
|
| 144 |
+
restart-shell = <Control-Key-F6>
|
| 145 |
+
open-class-browser = <Control-Key-b>
|
| 146 |
+
open-module = <Control-Key-m>
|
| 147 |
+
open-new-window = <Control-Key-n>
|
| 148 |
+
open-window-from-file = <Control-Key-o>
|
| 149 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 150 |
+
print-window = <Control-Key-p>
|
| 151 |
+
python-context-help = <Shift-Key-F1>
|
| 152 |
+
python-docs = <Key-F1>
|
| 153 |
+
redo = <Control-Shift-Key-Z>
|
| 154 |
+
remove-selection = <Key-Escape>
|
| 155 |
+
save-copy-of-window-as-file = <Alt-Shift-Key-S>
|
| 156 |
+
save-window-as-file = <Control-Shift-Key-S>
|
| 157 |
+
save-window = <Control-Key-s>
|
| 158 |
+
select-all = <Control-Key-a>
|
| 159 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 160 |
+
undo = <Control-Key-z>
|
| 161 |
+
find = <Control-Key-f>
|
| 162 |
+
find-again = <Key-F3>
|
| 163 |
+
find-in-files = <Control-Shift-Key-f>
|
| 164 |
+
find-selection = <Control-Key-h>
|
| 165 |
+
replace = <Control-Key-r>
|
| 166 |
+
goto-line = <Control-Key-g>
|
| 167 |
+
smart-backspace = <Key-BackSpace>
|
| 168 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 169 |
+
smart-indent = <Key-Tab>
|
| 170 |
+
indent-region = <Control-Key-bracketright>
|
| 171 |
+
dedent-region = <Control-Key-bracketleft>
|
| 172 |
+
comment-region = <Control-Key-d>
|
| 173 |
+
uncomment-region = <Control-Shift-Key-D>
|
| 174 |
+
tabify-region = <Alt-Key-5>
|
| 175 |
+
untabify-region = <Alt-Key-6>
|
| 176 |
+
toggle-tabs = <Control-Key-T>
|
| 177 |
+
change-indentwidth = <Alt-Key-u>
|
| 178 |
+
del-word-left = <Control-Key-BackSpace>
|
| 179 |
+
del-word-right = <Control-Key-Delete>
|
| 180 |
+
force-open-completions= <Control-Key-space>
|
| 181 |
+
expand-word= <Alt-Key-slash>
|
| 182 |
+
force-open-calltip= <Control-Key-backslash>
|
| 183 |
+
format-paragraph= <Alt-Key-q>
|
| 184 |
+
flash-paren= <Control-Key-0>
|
| 185 |
+
run-module= <Key-F5>
|
| 186 |
+
run-custom= <Shift-Key-F5>
|
| 187 |
+
check-module= <Alt-Key-x>
|
| 188 |
+
zoom-height= <Alt-Key-2>
|
| 189 |
+
|
| 190 |
+
[IDLE Classic Mac]
|
| 191 |
+
copy=<Command-Key-c>
|
| 192 |
+
cut=<Command-Key-x>
|
| 193 |
+
paste=<Command-Key-v>
|
| 194 |
+
beginning-of-line= <Key-Home>
|
| 195 |
+
center-insert=<Control-Key-l>
|
| 196 |
+
close-all-windows=<Command-Key-q>
|
| 197 |
+
close-window=<Command-Key-w>
|
| 198 |
+
do-nothing=<Control-Key-F12>
|
| 199 |
+
end-of-file=<Control-Key-d>
|
| 200 |
+
python-docs=<Key-F1>
|
| 201 |
+
python-context-help=<Shift-Key-F1>
|
| 202 |
+
history-next=<Control-Key-n>
|
| 203 |
+
history-previous=<Control-Key-p>
|
| 204 |
+
interrupt-execution=<Control-Key-c>
|
| 205 |
+
view-restart=<Key-F6>
|
| 206 |
+
restart-shell=<Control-Key-F6>
|
| 207 |
+
open-class-browser=<Command-Key-b>
|
| 208 |
+
open-module=<Command-Key-m>
|
| 209 |
+
open-new-window=<Command-Key-n>
|
| 210 |
+
open-window-from-file=<Command-Key-o>
|
| 211 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 212 |
+
print-window=<Command-Key-p>
|
| 213 |
+
redo=<Shift-Command-Key-Z>
|
| 214 |
+
remove-selection=<Key-Escape>
|
| 215 |
+
save-window-as-file=<Shift-Command-Key-S>
|
| 216 |
+
save-window=<Command-Key-s>
|
| 217 |
+
save-copy-of-window-as-file=<Option-Command-Key-s>
|
| 218 |
+
select-all=<Command-Key-a>
|
| 219 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 220 |
+
undo=<Command-Key-z>
|
| 221 |
+
find=<Command-Key-f>
|
| 222 |
+
find-again=<Command-Key-g> <Key-F3>
|
| 223 |
+
find-in-files=<Command-Key-F3>
|
| 224 |
+
find-selection=<Shift-Command-Key-F3>
|
| 225 |
+
replace=<Command-Key-r>
|
| 226 |
+
goto-line=<Command-Key-j>
|
| 227 |
+
smart-backspace=<Key-BackSpace>
|
| 228 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 229 |
+
smart-indent=<Key-Tab>
|
| 230 |
+
indent-region=<Command-Key-bracketright>
|
| 231 |
+
dedent-region=<Command-Key-bracketleft>
|
| 232 |
+
comment-region=<Control-Key-3>
|
| 233 |
+
uncomment-region=<Control-Key-4>
|
| 234 |
+
tabify-region=<Control-Key-5>
|
| 235 |
+
untabify-region=<Control-Key-6>
|
| 236 |
+
toggle-tabs=<Control-Key-t>
|
| 237 |
+
change-indentwidth=<Control-Key-u>
|
| 238 |
+
del-word-left=<Control-Key-BackSpace>
|
| 239 |
+
del-word-right=<Control-Key-Delete>
|
| 240 |
+
force-open-completions= <Control-Key-space>
|
| 241 |
+
expand-word= <Option-Key-slash>
|
| 242 |
+
force-open-calltip= <Control-Key-backslash>
|
| 243 |
+
format-paragraph= <Option-Key-q>
|
| 244 |
+
flash-paren= <Control-Key-0>
|
| 245 |
+
run-module= <Key-F5>
|
| 246 |
+
run-custom= <Shift-Key-F5>
|
| 247 |
+
check-module= <Option-Key-x>
|
| 248 |
+
zoom-height= <Option-Key-0>
|
| 249 |
+
|
| 250 |
+
[IDLE Classic OSX]
|
| 251 |
+
toggle-tabs = <Control-Key-t>
|
| 252 |
+
interrupt-execution = <Control-Key-c>
|
| 253 |
+
untabify-region = <Control-Key-6>
|
| 254 |
+
remove-selection = <Key-Escape>
|
| 255 |
+
print-window = <Command-Key-p>
|
| 256 |
+
replace = <Command-Key-r>
|
| 257 |
+
goto-line = <Command-Key-j>
|
| 258 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 259 |
+
history-previous = <Control-Key-p>
|
| 260 |
+
beginning-of-line = <Control-Key-Left>
|
| 261 |
+
end-of-line = <Control-Key-Right>
|
| 262 |
+
comment-region = <Control-Key-3>
|
| 263 |
+
redo = <Shift-Command-Key-Z>
|
| 264 |
+
close-window = <Command-Key-w>
|
| 265 |
+
restart-shell = <Control-Key-F6>
|
| 266 |
+
save-window-as-file = <Shift-Command-Key-S>
|
| 267 |
+
close-all-windows = <Command-Key-q>
|
| 268 |
+
view-restart = <Key-F6>
|
| 269 |
+
tabify-region = <Control-Key-5>
|
| 270 |
+
find-again = <Command-Key-g> <Key-F3>
|
| 271 |
+
find = <Command-Key-f>
|
| 272 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 273 |
+
select-all = <Command-Key-a>
|
| 274 |
+
smart-backspace = <Key-BackSpace>
|
| 275 |
+
change-indentwidth = <Control-Key-u>
|
| 276 |
+
do-nothing = <Control-Key-F12>
|
| 277 |
+
smart-indent = <Key-Tab>
|
| 278 |
+
center-insert = <Control-Key-l>
|
| 279 |
+
history-next = <Control-Key-n>
|
| 280 |
+
del-word-right = <Option-Key-Delete>
|
| 281 |
+
undo = <Command-Key-z>
|
| 282 |
+
save-window = <Command-Key-s>
|
| 283 |
+
uncomment-region = <Control-Key-4>
|
| 284 |
+
cut = <Command-Key-x>
|
| 285 |
+
find-in-files = <Command-Key-F3>
|
| 286 |
+
dedent-region = <Command-Key-bracketleft>
|
| 287 |
+
copy = <Command-Key-c>
|
| 288 |
+
paste = <Command-Key-v>
|
| 289 |
+
indent-region = <Command-Key-bracketright>
|
| 290 |
+
del-word-left = <Option-Key-BackSpace> <Option-Command-Key-BackSpace>
|
| 291 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 292 |
+
end-of-file = <Control-Key-d>
|
| 293 |
+
open-class-browser = <Command-Key-b>
|
| 294 |
+
open-new-window = <Command-Key-n>
|
| 295 |
+
open-module = <Command-Key-m>
|
| 296 |
+
find-selection = <Shift-Command-Key-F3>
|
| 297 |
+
python-context-help = <Shift-Key-F1>
|
| 298 |
+
save-copy-of-window-as-file = <Option-Command-Key-s>
|
| 299 |
+
open-window-from-file = <Command-Key-o>
|
| 300 |
+
python-docs = <Key-F1>
|
| 301 |
+
force-open-completions= <Control-Key-space>
|
| 302 |
+
expand-word= <Option-Key-slash>
|
| 303 |
+
force-open-calltip= <Control-Key-backslash>
|
| 304 |
+
format-paragraph= <Option-Key-q>
|
| 305 |
+
flash-paren= <Control-Key-0>
|
| 306 |
+
run-module= <Key-F5>
|
| 307 |
+
run-custom= <Shift-Key-F5>
|
| 308 |
+
check-module= <Option-Key-x>
|
| 309 |
+
zoom-height= <Option-Key-0>
|
deepseek/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?
|
deepseek/lib/python3.10/idlelib/configdialog.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deepseek/lib/python3.10/idlelib/debugger_r.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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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)
|
deepseek/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)
|
deepseek/lib/python3.10/idlelib/dynoption.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
OptionMenu widget modified to allow dynamic menu reconfiguration
|
| 3 |
+
and setting of highlightthickness
|
| 4 |
+
"""
|
| 5 |
+
from tkinter import OptionMenu, _setit, StringVar, Button
|
| 6 |
+
|
| 7 |
+
class DynOptionMenu(OptionMenu):
|
| 8 |
+
"""Add SetMenu and highlightthickness to OptionMenu.
|
| 9 |
+
|
| 10 |
+
Highlightthickness adds space around menu button.
|
| 11 |
+
"""
|
| 12 |
+
def __init__(self, master, variable, value, *values, **kwargs):
|
| 13 |
+
highlightthickness = kwargs.pop('highlightthickness', None)
|
| 14 |
+
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
|
| 15 |
+
self['highlightthickness'] = highlightthickness
|
| 16 |
+
self.variable = variable
|
| 17 |
+
self.command = kwargs.get('command')
|
| 18 |
+
|
| 19 |
+
def SetMenu(self,valueList,value=None):
|
| 20 |
+
"""
|
| 21 |
+
clear and reload the menu with a new set of options.
|
| 22 |
+
valueList - list of new options
|
| 23 |
+
value - initial value to set the optionmenu's menubutton to
|
| 24 |
+
"""
|
| 25 |
+
self['menu'].delete(0,'end')
|
| 26 |
+
for item in valueList:
|
| 27 |
+
self['menu'].add_command(label=item,
|
| 28 |
+
command=_setit(self.variable,item,self.command))
|
| 29 |
+
if value:
|
| 30 |
+
self.variable.set(value)
|
| 31 |
+
|
| 32 |
+
def _dyn_option_menu(parent): # htest #
|
| 33 |
+
from tkinter import Toplevel # + StringVar, Button
|
| 34 |
+
|
| 35 |
+
top = Toplevel(parent)
|
| 36 |
+
top.title("Test dynamic option menu")
|
| 37 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 38 |
+
top.geometry("200x100+%d+%d" % (x + 250, y + 175))
|
| 39 |
+
top.focus_set()
|
| 40 |
+
|
| 41 |
+
var = StringVar(top)
|
| 42 |
+
var.set("Old option set") #Set the default value
|
| 43 |
+
dyn = DynOptionMenu(top, var, "old1","old2","old3","old4",
|
| 44 |
+
highlightthickness=5)
|
| 45 |
+
dyn.pack()
|
| 46 |
+
|
| 47 |
+
def update():
|
| 48 |
+
dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
|
| 49 |
+
button = Button(top, text="Change option set", command=update)
|
| 50 |
+
button.pack()
|
| 51 |
+
|
| 52 |
+
if __name__ == '__main__':
|
| 53 |
+
# Only module without unittests because of intention to replace.
|
| 54 |
+
from idlelib.idle_test.htest import run
|
| 55 |
+
run(_dyn_option_menu)
|
deepseek/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.
|
deepseek/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()
|
deepseek/lib/python3.10/idlelib/format.py
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Region formatting options: paragraph, comment block, indent, deindent,
|
| 4 |
+
comment, uncomment, tabify, and untabify.
|
| 5 |
+
|
| 6 |
+
File renamed from paragraph.py with functions added from editor.py.
|
| 7 |
+
"""
|
| 8 |
+
import re
|
| 9 |
+
from tkinter.messagebox import askyesno
|
| 10 |
+
from tkinter.simpledialog import askinteger
|
| 11 |
+
from idlelib.config import idleConf
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class FormatParagraph:
|
| 15 |
+
"""Format a paragraph, comment block, or selection to a max width.
|
| 16 |
+
|
| 17 |
+
Does basic, standard text formatting, and also understands Python
|
| 18 |
+
comment blocks. Thus, for editing Python source code, this
|
| 19 |
+
extension is really only suitable for reformatting these comment
|
| 20 |
+
blocks or triple-quoted strings.
|
| 21 |
+
|
| 22 |
+
Known problems with comment reformatting:
|
| 23 |
+
* If there is a selection marked, and the first line of the
|
| 24 |
+
selection is not complete, the block will probably not be detected
|
| 25 |
+
as comments, and will have the normal "text formatting" rules
|
| 26 |
+
applied.
|
| 27 |
+
* If a comment block has leading whitespace that mixes tabs and
|
| 28 |
+
spaces, they will not be considered part of the same block.
|
| 29 |
+
* Fancy comments, like this bulleted list, aren't handled :-)
|
| 30 |
+
"""
|
| 31 |
+
def __init__(self, editwin):
|
| 32 |
+
self.editwin = editwin
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def reload(cls):
|
| 36 |
+
cls.max_width = idleConf.GetOption('extensions', 'FormatParagraph',
|
| 37 |
+
'max-width', type='int', default=72)
|
| 38 |
+
|
| 39 |
+
def close(self):
|
| 40 |
+
self.editwin = None
|
| 41 |
+
|
| 42 |
+
def format_paragraph_event(self, event, limit=None):
|
| 43 |
+
"""Formats paragraph to a max width specified in idleConf.
|
| 44 |
+
|
| 45 |
+
If text is selected, format_paragraph_event will start breaking lines
|
| 46 |
+
at the max width, starting from the beginning selection.
|
| 47 |
+
|
| 48 |
+
If no text is selected, format_paragraph_event uses the current
|
| 49 |
+
cursor location to determine the paragraph (lines of text surrounded
|
| 50 |
+
by blank lines) and formats it.
|
| 51 |
+
|
| 52 |
+
The length limit parameter is for testing with a known value.
|
| 53 |
+
"""
|
| 54 |
+
limit = self.max_width if limit is None else limit
|
| 55 |
+
text = self.editwin.text
|
| 56 |
+
first, last = self.editwin.get_selection_indices()
|
| 57 |
+
if first and last:
|
| 58 |
+
data = text.get(first, last)
|
| 59 |
+
comment_header = get_comment_header(data)
|
| 60 |
+
else:
|
| 61 |
+
first, last, comment_header, data = \
|
| 62 |
+
find_paragraph(text, text.index("insert"))
|
| 63 |
+
if comment_header:
|
| 64 |
+
newdata = reformat_comment(data, limit, comment_header)
|
| 65 |
+
else:
|
| 66 |
+
newdata = reformat_paragraph(data, limit)
|
| 67 |
+
text.tag_remove("sel", "1.0", "end")
|
| 68 |
+
|
| 69 |
+
if newdata != data:
|
| 70 |
+
text.mark_set("insert", first)
|
| 71 |
+
text.undo_block_start()
|
| 72 |
+
text.delete(first, last)
|
| 73 |
+
text.insert(first, newdata)
|
| 74 |
+
text.undo_block_stop()
|
| 75 |
+
else:
|
| 76 |
+
text.mark_set("insert", last)
|
| 77 |
+
text.see("insert")
|
| 78 |
+
return "break"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
FormatParagraph.reload()
|
| 82 |
+
|
| 83 |
+
def find_paragraph(text, mark):
|
| 84 |
+
"""Returns the start/stop indices enclosing the paragraph that mark is in.
|
| 85 |
+
|
| 86 |
+
Also returns the comment format string, if any, and paragraph of text
|
| 87 |
+
between the start/stop indices.
|
| 88 |
+
"""
|
| 89 |
+
lineno, col = map(int, mark.split("."))
|
| 90 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 91 |
+
|
| 92 |
+
# Look for start of next paragraph if the index passed in is a blank line
|
| 93 |
+
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
|
| 94 |
+
lineno = lineno + 1
|
| 95 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 96 |
+
first_lineno = lineno
|
| 97 |
+
comment_header = get_comment_header(line)
|
| 98 |
+
comment_header_len = len(comment_header)
|
| 99 |
+
|
| 100 |
+
# Once start line found, search for end of paragraph (a blank line)
|
| 101 |
+
while get_comment_header(line)==comment_header and \
|
| 102 |
+
not is_all_white(line[comment_header_len:]):
|
| 103 |
+
lineno = lineno + 1
|
| 104 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 105 |
+
last = "%d.0" % lineno
|
| 106 |
+
|
| 107 |
+
# Search back to beginning of paragraph (first blank line before)
|
| 108 |
+
lineno = first_lineno - 1
|
| 109 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 110 |
+
while lineno > 0 and \
|
| 111 |
+
get_comment_header(line)==comment_header and \
|
| 112 |
+
not is_all_white(line[comment_header_len:]):
|
| 113 |
+
lineno = lineno - 1
|
| 114 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 115 |
+
first = "%d.0" % (lineno+1)
|
| 116 |
+
|
| 117 |
+
return first, last, comment_header, text.get(first, last)
|
| 118 |
+
|
| 119 |
+
# This should perhaps be replaced with textwrap.wrap
|
| 120 |
+
def reformat_paragraph(data, limit):
|
| 121 |
+
"""Return data reformatted to specified width (limit)."""
|
| 122 |
+
lines = data.split("\n")
|
| 123 |
+
i = 0
|
| 124 |
+
n = len(lines)
|
| 125 |
+
while i < n and is_all_white(lines[i]):
|
| 126 |
+
i = i+1
|
| 127 |
+
if i >= n:
|
| 128 |
+
return data
|
| 129 |
+
indent1 = get_indent(lines[i])
|
| 130 |
+
if i+1 < n and not is_all_white(lines[i+1]):
|
| 131 |
+
indent2 = get_indent(lines[i+1])
|
| 132 |
+
else:
|
| 133 |
+
indent2 = indent1
|
| 134 |
+
new = lines[:i]
|
| 135 |
+
partial = indent1
|
| 136 |
+
while i < n and not is_all_white(lines[i]):
|
| 137 |
+
# XXX Should take double space after period (etc.) into account
|
| 138 |
+
words = re.split(r"(\s+)", lines[i])
|
| 139 |
+
for j in range(0, len(words), 2):
|
| 140 |
+
word = words[j]
|
| 141 |
+
if not word:
|
| 142 |
+
continue # Can happen when line ends in whitespace
|
| 143 |
+
if len((partial + word).expandtabs()) > limit and \
|
| 144 |
+
partial != indent1:
|
| 145 |
+
new.append(partial.rstrip())
|
| 146 |
+
partial = indent2
|
| 147 |
+
partial = partial + word + " "
|
| 148 |
+
if j+1 < len(words) and words[j+1] != " ":
|
| 149 |
+
partial = partial + " "
|
| 150 |
+
i = i+1
|
| 151 |
+
new.append(partial.rstrip())
|
| 152 |
+
# XXX Should reformat remaining paragraphs as well
|
| 153 |
+
new.extend(lines[i:])
|
| 154 |
+
return "\n".join(new)
|
| 155 |
+
|
| 156 |
+
def reformat_comment(data, limit, comment_header):
|
| 157 |
+
"""Return data reformatted to specified width with comment header."""
|
| 158 |
+
|
| 159 |
+
# Remove header from the comment lines
|
| 160 |
+
lc = len(comment_header)
|
| 161 |
+
data = "\n".join(line[lc:] for line in data.split("\n"))
|
| 162 |
+
# Reformat to maxformatwidth chars or a 20 char width,
|
| 163 |
+
# whichever is greater.
|
| 164 |
+
format_width = max(limit - len(comment_header), 20)
|
| 165 |
+
newdata = reformat_paragraph(data, format_width)
|
| 166 |
+
# re-split and re-insert the comment header.
|
| 167 |
+
newdata = newdata.split("\n")
|
| 168 |
+
# If the block ends in a \n, we don't want the comment prefix
|
| 169 |
+
# inserted after it. (Im not sure it makes sense to reformat a
|
| 170 |
+
# comment block that is not made of complete lines, but whatever!)
|
| 171 |
+
# Can't think of a clean solution, so we hack away
|
| 172 |
+
block_suffix = ""
|
| 173 |
+
if not newdata[-1]:
|
| 174 |
+
block_suffix = "\n"
|
| 175 |
+
newdata = newdata[:-1]
|
| 176 |
+
return '\n'.join(comment_header+line for line in newdata) + block_suffix
|
| 177 |
+
|
| 178 |
+
def is_all_white(line):
|
| 179 |
+
"""Return True if line is empty or all whitespace."""
|
| 180 |
+
|
| 181 |
+
return re.match(r"^\s*$", line) is not None
|
| 182 |
+
|
| 183 |
+
def get_indent(line):
|
| 184 |
+
"""Return the initial space or tab indent of line."""
|
| 185 |
+
return re.match(r"^([ \t]*)", line).group()
|
| 186 |
+
|
| 187 |
+
def get_comment_header(line):
|
| 188 |
+
"""Return string with leading whitespace and '#' from line or ''.
|
| 189 |
+
|
| 190 |
+
A null return indicates that the line is not a comment line. A non-
|
| 191 |
+
null return, such as ' #', will be used to find the other lines of
|
| 192 |
+
a comment block with the same indent.
|
| 193 |
+
"""
|
| 194 |
+
m = re.match(r"^([ \t]*#*)", line)
|
| 195 |
+
if m is None: return ""
|
| 196 |
+
return m.group(1)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Copied from editor.py; importing it would cause an import cycle.
|
| 200 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 201 |
+
|
| 202 |
+
def get_line_indent(line, tabwidth):
|
| 203 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 204 |
+
|
| 205 |
+
The effective # of spaces is the length after properly "expanding"
|
| 206 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 207 |
+
"""
|
| 208 |
+
m = _line_indent_re.match(line)
|
| 209 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class FormatRegion:
|
| 213 |
+
"Format selected text (region)."
|
| 214 |
+
|
| 215 |
+
def __init__(self, editwin):
|
| 216 |
+
self.editwin = editwin
|
| 217 |
+
|
| 218 |
+
def get_region(self):
|
| 219 |
+
"""Return line information about the selected text region.
|
| 220 |
+
|
| 221 |
+
If text is selected, the first and last indices will be
|
| 222 |
+
for the selection. If there is no text selected, the
|
| 223 |
+
indices will be the current cursor location.
|
| 224 |
+
|
| 225 |
+
Return a tuple containing (first index, last index,
|
| 226 |
+
string representation of text, list of text lines).
|
| 227 |
+
"""
|
| 228 |
+
text = self.editwin.text
|
| 229 |
+
first, last = self.editwin.get_selection_indices()
|
| 230 |
+
if first and last:
|
| 231 |
+
head = text.index(first + " linestart")
|
| 232 |
+
tail = text.index(last + "-1c lineend +1c")
|
| 233 |
+
else:
|
| 234 |
+
head = text.index("insert linestart")
|
| 235 |
+
tail = text.index("insert lineend +1c")
|
| 236 |
+
chars = text.get(head, tail)
|
| 237 |
+
lines = chars.split("\n")
|
| 238 |
+
return head, tail, chars, lines
|
| 239 |
+
|
| 240 |
+
def set_region(self, head, tail, chars, lines):
|
| 241 |
+
"""Replace the text between the given indices.
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
head: Starting index of text to replace.
|
| 245 |
+
tail: Ending index of text to replace.
|
| 246 |
+
chars: Expected to be string of current text
|
| 247 |
+
between head and tail.
|
| 248 |
+
lines: List of new lines to insert between head
|
| 249 |
+
and tail.
|
| 250 |
+
"""
|
| 251 |
+
text = self.editwin.text
|
| 252 |
+
newchars = "\n".join(lines)
|
| 253 |
+
if newchars == chars:
|
| 254 |
+
text.bell()
|
| 255 |
+
return
|
| 256 |
+
text.tag_remove("sel", "1.0", "end")
|
| 257 |
+
text.mark_set("insert", head)
|
| 258 |
+
text.undo_block_start()
|
| 259 |
+
text.delete(head, tail)
|
| 260 |
+
text.insert(head, newchars)
|
| 261 |
+
text.undo_block_stop()
|
| 262 |
+
text.tag_add("sel", head, "insert")
|
| 263 |
+
|
| 264 |
+
def indent_region_event(self, event=None):
|
| 265 |
+
"Indent region by indentwidth spaces."
|
| 266 |
+
head, tail, chars, lines = self.get_region()
|
| 267 |
+
for pos in range(len(lines)):
|
| 268 |
+
line = lines[pos]
|
| 269 |
+
if line:
|
| 270 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 271 |
+
effective = effective + self.editwin.indentwidth
|
| 272 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 273 |
+
self.set_region(head, tail, chars, lines)
|
| 274 |
+
return "break"
|
| 275 |
+
|
| 276 |
+
def dedent_region_event(self, event=None):
|
| 277 |
+
"Dedent region by indentwidth spaces."
|
| 278 |
+
head, tail, chars, lines = self.get_region()
|
| 279 |
+
for pos in range(len(lines)):
|
| 280 |
+
line = lines[pos]
|
| 281 |
+
if line:
|
| 282 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 283 |
+
effective = max(effective - self.editwin.indentwidth, 0)
|
| 284 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 285 |
+
self.set_region(head, tail, chars, lines)
|
| 286 |
+
return "break"
|
| 287 |
+
|
| 288 |
+
def comment_region_event(self, event=None):
|
| 289 |
+
"""Comment out each line in region.
|
| 290 |
+
|
| 291 |
+
## is appended to the beginning of each line to comment it out.
|
| 292 |
+
"""
|
| 293 |
+
head, tail, chars, lines = self.get_region()
|
| 294 |
+
for pos in range(len(lines) - 1):
|
| 295 |
+
line = lines[pos]
|
| 296 |
+
lines[pos] = '##' + line
|
| 297 |
+
self.set_region(head, tail, chars, lines)
|
| 298 |
+
return "break"
|
| 299 |
+
|
| 300 |
+
def uncomment_region_event(self, event=None):
|
| 301 |
+
"""Uncomment each line in region.
|
| 302 |
+
|
| 303 |
+
Remove ## or # in the first positions of a line. If the comment
|
| 304 |
+
is not in the beginning position, this command will have no effect.
|
| 305 |
+
"""
|
| 306 |
+
head, tail, chars, lines = self.get_region()
|
| 307 |
+
for pos in range(len(lines)):
|
| 308 |
+
line = lines[pos]
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if line[:2] == '##':
|
| 312 |
+
line = line[2:]
|
| 313 |
+
elif line[:1] == '#':
|
| 314 |
+
line = line[1:]
|
| 315 |
+
lines[pos] = line
|
| 316 |
+
self.set_region(head, tail, chars, lines)
|
| 317 |
+
return "break"
|
| 318 |
+
|
| 319 |
+
def tabify_region_event(self, event=None):
|
| 320 |
+
"Convert leading spaces to tabs for each line in selected region."
|
| 321 |
+
head, tail, chars, lines = self.get_region()
|
| 322 |
+
tabwidth = self._asktabwidth()
|
| 323 |
+
if tabwidth is None:
|
| 324 |
+
return
|
| 325 |
+
for pos in range(len(lines)):
|
| 326 |
+
line = lines[pos]
|
| 327 |
+
if line:
|
| 328 |
+
raw, effective = get_line_indent(line, tabwidth)
|
| 329 |
+
ntabs, nspaces = divmod(effective, tabwidth)
|
| 330 |
+
lines[pos] = '\t' * ntabs + ' ' * nspaces + line[raw:]
|
| 331 |
+
self.set_region(head, tail, chars, lines)
|
| 332 |
+
return "break"
|
| 333 |
+
|
| 334 |
+
def untabify_region_event(self, event=None):
|
| 335 |
+
"Expand tabs to spaces for each line in region."
|
| 336 |
+
head, tail, chars, lines = self.get_region()
|
| 337 |
+
tabwidth = self._asktabwidth()
|
| 338 |
+
if tabwidth is None:
|
| 339 |
+
return
|
| 340 |
+
for pos in range(len(lines)):
|
| 341 |
+
lines[pos] = lines[pos].expandtabs(tabwidth)
|
| 342 |
+
self.set_region(head, tail, chars, lines)
|
| 343 |
+
return "break"
|
| 344 |
+
|
| 345 |
+
def _asktabwidth(self):
|
| 346 |
+
"Return value for tab width."
|
| 347 |
+
return askinteger(
|
| 348 |
+
"Tab width",
|
| 349 |
+
"Columns per tab? (2-16)",
|
| 350 |
+
parent=self.editwin.text,
|
| 351 |
+
initialvalue=self.editwin.indentwidth,
|
| 352 |
+
minvalue=2,
|
| 353 |
+
maxvalue=16)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
class Indents:
|
| 357 |
+
"Change future indents."
|
| 358 |
+
|
| 359 |
+
def __init__(self, editwin):
|
| 360 |
+
self.editwin = editwin
|
| 361 |
+
|
| 362 |
+
def toggle_tabs_event(self, event):
|
| 363 |
+
editwin = self.editwin
|
| 364 |
+
usetabs = editwin.usetabs
|
| 365 |
+
if askyesno(
|
| 366 |
+
"Toggle tabs",
|
| 367 |
+
"Turn tabs " + ("on", "off")[usetabs] +
|
| 368 |
+
"?\nIndent width " +
|
| 369 |
+
("will be", "remains at")[usetabs] + " 8." +
|
| 370 |
+
"\n Note: a tab is always 8 columns",
|
| 371 |
+
parent=editwin.text):
|
| 372 |
+
editwin.usetabs = not usetabs
|
| 373 |
+
# Try to prevent inconsistent indentation.
|
| 374 |
+
# User must change indent width manually after using tabs.
|
| 375 |
+
editwin.indentwidth = 8
|
| 376 |
+
return "break"
|
| 377 |
+
|
| 378 |
+
def change_indentwidth_event(self, event):
|
| 379 |
+
editwin = self.editwin
|
| 380 |
+
new = askinteger(
|
| 381 |
+
"Indent width",
|
| 382 |
+
"New indent width (2-16)\n(Always use 8 when using tabs)",
|
| 383 |
+
parent=editwin.text,
|
| 384 |
+
initialvalue=editwin.indentwidth,
|
| 385 |
+
minvalue=2,
|
| 386 |
+
maxvalue=16)
|
| 387 |
+
if new and new != editwin.indentwidth and not editwin.usetabs:
|
| 388 |
+
editwin.indentwidth = new
|
| 389 |
+
return "break"
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
class Rstrip: # 'Strip Trailing Whitespace" on "Format" menu.
|
| 393 |
+
def __init__(self, editwin):
|
| 394 |
+
self.editwin = editwin
|
| 395 |
+
|
| 396 |
+
def do_rstrip(self, event=None):
|
| 397 |
+
text = self.editwin.text
|
| 398 |
+
undo = self.editwin.undo
|
| 399 |
+
undo.undo_block_start()
|
| 400 |
+
|
| 401 |
+
end_line = int(float(text.index('end')))
|
| 402 |
+
for cur in range(1, end_line):
|
| 403 |
+
txt = text.get('%i.0' % cur, '%i.end' % cur)
|
| 404 |
+
raw = len(txt)
|
| 405 |
+
cut = len(txt.rstrip())
|
| 406 |
+
# Since text.delete() marks file as changed, even if not,
|
| 407 |
+
# only call it when needed to actually delete something.
|
| 408 |
+
if cut < raw:
|
| 409 |
+
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
|
| 410 |
+
|
| 411 |
+
if (text.get('end-2c') == '\n' # File ends with at least 1 newline;
|
| 412 |
+
and not hasattr(self.editwin, 'interp')): # & is not Shell.
|
| 413 |
+
# Delete extra user endlines.
|
| 414 |
+
while (text.index('end-1c') > '1.0' # Stop if file empty.
|
| 415 |
+
and text.get('end-3c') == '\n'):
|
| 416 |
+
text.delete('end-3c')
|
| 417 |
+
# Because tk indexes are slice indexes and never raise,
|
| 418 |
+
# a file with only newlines will be emptied.
|
| 419 |
+
# patchcheck.py does the same.
|
| 420 |
+
|
| 421 |
+
undo.undo_block_stop()
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
if __name__ == "__main__":
|
| 425 |
+
from unittest import main
|
| 426 |
+
main('idlelib.idle_test.test_format', verbosity=2, exit=False)
|
deepseek/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)
|
deepseek/lib/python3.10/idlelib/help.html
ADDED
|
@@ -0,0 +1,1178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
|
| 4 |
+
<html lang="en">
|
| 5 |
+
<head>
|
| 6 |
+
<meta charset="utf-8" />
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
|
| 8 |
+
|
| 9 |
+
<title>IDLE — Python 3.12.0a0 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 10 |
+
|
| 11 |
+
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
|
| 12 |
+
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?2022.1" />
|
| 13 |
+
|
| 14 |
+
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
|
| 15 |
+
<script src="../_static/jquery.js"></script>
|
| 16 |
+
<script src="../_static/underscore.js"></script>
|
| 17 |
+
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
|
| 18 |
+
<script src="../_static/doctools.js"></script>
|
| 19 |
+
|
| 20 |
+
<script src="../_static/sidebar.js"></script>
|
| 21 |
+
|
| 22 |
+
<link rel="search" type="application/opensearchdescription+xml"
|
| 23 |
+
title="Search within Python 3.12.0a0 documentation"
|
| 24 |
+
href="../_static/opensearch.xml"/>
|
| 25 |
+
<link rel="author" title="About these documents" href="../about.html" />
|
| 26 |
+
<link rel="index" title="Index" href="../genindex.html" />
|
| 27 |
+
<link rel="search" title="Search" href="../search.html" />
|
| 28 |
+
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
| 29 |
+
<link rel="next" title="Development Tools" href="development.html" />
|
| 30 |
+
<link rel="prev" title="tkinter.tix — Extension widgets for Tk" href="tkinter.tix.html" />
|
| 31 |
+
<link rel="canonical" href="https://docs.python.org/3/library/idle.html" />
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
<style>
|
| 38 |
+
@media only screen {
|
| 39 |
+
table.full-width-table {
|
| 40 |
+
width: 100%;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
</style>
|
| 44 |
+
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
| 45 |
+
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
| 46 |
+
<script type="text/javascript" src="../_static/menu.js"></script>
|
| 47 |
+
|
| 48 |
+
</head>
|
| 49 |
+
<body>
|
| 50 |
+
<div class="mobile-nav">
|
| 51 |
+
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
| 52 |
+
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
| 53 |
+
<label for="menuToggler" class="toggler__label">
|
| 54 |
+
<span></span>
|
| 55 |
+
</label>
|
| 56 |
+
<nav class="nav-content" role="navigation">
|
| 57 |
+
<a href="https://www.python.org/" class="nav-logo">
|
| 58 |
+
<img src="../_static/py.svg" alt="Logo"/>
|
| 59 |
+
</a>
|
| 60 |
+
<div class="version_switcher_placeholder"></div>
|
| 61 |
+
<form role="search" class="search" action="../search.html" method="get">
|
| 62 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
| 63 |
+
<path fill-rule="nonzero"
|
| 64 |
+
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
| 65 |
+
</svg>
|
| 66 |
+
<input type="text" name="q" aria-label="Quick search"/>
|
| 67 |
+
<input type="submit" value="Go"/>
|
| 68 |
+
</form>
|
| 69 |
+
</nav>
|
| 70 |
+
<div class="menu-wrapper">
|
| 71 |
+
<nav class="menu" role="navigation" aria-label="main navigation">
|
| 72 |
+
<div class="language_switcher_placeholder"></div>
|
| 73 |
+
<div>
|
| 74 |
+
<h3><a href="../contents.html">Table of Contents</a></h3>
|
| 75 |
+
<ul>
|
| 76 |
+
<li><a class="reference internal" href="#">IDLE</a><ul>
|
| 77 |
+
<li><a class="reference internal" href="#menus">Menus</a><ul>
|
| 78 |
+
<li><a class="reference internal" href="#file-menu-shell-and-editor">File menu (Shell and Editor)</a></li>
|
| 79 |
+
<li><a class="reference internal" href="#edit-menu-shell-and-editor">Edit menu (Shell and Editor)</a></li>
|
| 80 |
+
<li><a class="reference internal" href="#format-menu-editor-window-only">Format menu (Editor window only)</a></li>
|
| 81 |
+
<li><a class="reference internal" href="#run-menu-editor-window-only">Run menu (Editor window only)</a></li>
|
| 82 |
+
<li><a class="reference internal" href="#shell-menu-shell-window-only">Shell menu (Shell window only)</a></li>
|
| 83 |
+
<li><a class="reference internal" href="#debug-menu-shell-window-only">Debug menu (Shell window only)</a></li>
|
| 84 |
+
<li><a class="reference internal" href="#options-menu-shell-and-editor">Options menu (Shell and Editor)</a></li>
|
| 85 |
+
<li><a class="reference internal" href="#window-menu-shell-and-editor">Window menu (Shell and Editor)</a></li>
|
| 86 |
+
<li><a class="reference internal" href="#help-menu-shell-and-editor">Help menu (Shell and Editor)</a></li>
|
| 87 |
+
<li><a class="reference internal" href="#context-menus">Context menus</a></li>
|
| 88 |
+
</ul>
|
| 89 |
+
</li>
|
| 90 |
+
<li><a class="reference internal" href="#editing-and-navigation">Editing and Navigation</a><ul>
|
| 91 |
+
<li><a class="reference internal" href="#editor-windows">Editor windows</a></li>
|
| 92 |
+
<li><a class="reference internal" href="#key-bindings">Key bindings</a></li>
|
| 93 |
+
<li><a class="reference internal" href="#automatic-indentation">Automatic indentation</a></li>
|
| 94 |
+
<li><a class="reference internal" href="#search-and-replace">Search and Replace</a></li>
|
| 95 |
+
<li><a class="reference internal" href="#completions">Completions</a></li>
|
| 96 |
+
<li><a class="reference internal" href="#calltips">Calltips</a></li>
|
| 97 |
+
<li><a class="reference internal" href="#code-context">Code Context</a></li>
|
| 98 |
+
<li><a class="reference internal" href="#shell-window">Shell window</a></li>
|
| 99 |
+
<li><a class="reference internal" href="#text-colors">Text colors</a></li>
|
| 100 |
+
</ul>
|
| 101 |
+
</li>
|
| 102 |
+
<li><a class="reference internal" href="#startup-and-code-execution">Startup and Code Execution</a><ul>
|
| 103 |
+
<li><a class="reference internal" href="#command-line-usage">Command line usage</a></li>
|
| 104 |
+
<li><a class="reference internal" href="#startup-failure">Startup failure</a></li>
|
| 105 |
+
<li><a class="reference internal" href="#running-user-code">Running user code</a></li>
|
| 106 |
+
<li><a class="reference internal" href="#user-output-in-shell">User output in Shell</a></li>
|
| 107 |
+
<li><a class="reference internal" href="#developing-tkinter-applications">Developing tkinter applications</a></li>
|
| 108 |
+
<li><a class="reference internal" href="#running-without-a-subprocess">Running without a subprocess</a></li>
|
| 109 |
+
</ul>
|
| 110 |
+
</li>
|
| 111 |
+
<li><a class="reference internal" href="#help-and-preferences">Help and Preferences</a><ul>
|
| 112 |
+
<li><a class="reference internal" href="#help-sources">Help sources</a></li>
|
| 113 |
+
<li><a class="reference internal" href="#setting-preferences">Setting preferences</a></li>
|
| 114 |
+
<li><a class="reference internal" href="#idle-on-macos">IDLE on macOS</a></li>
|
| 115 |
+
<li><a class="reference internal" href="#extensions">Extensions</a></li>
|
| 116 |
+
</ul>
|
| 117 |
+
</li>
|
| 118 |
+
<li><a class="reference internal" href="#module-idlelib">idlelib</a></li>
|
| 119 |
+
</ul>
|
| 120 |
+
</li>
|
| 121 |
+
</ul>
|
| 122 |
+
|
| 123 |
+
</div>
|
| 124 |
+
<div>
|
| 125 |
+
<h4>Previous topic</h4>
|
| 126 |
+
<p class="topless"><a href="tkinter.tix.html"
|
| 127 |
+
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code> — Extension widgets for Tk</a></p>
|
| 128 |
+
</div>
|
| 129 |
+
<div>
|
| 130 |
+
<h4>Next topic</h4>
|
| 131 |
+
<p class="topless"><a href="development.html"
|
| 132 |
+
title="next chapter">Development Tools</a></p>
|
| 133 |
+
</div>
|
| 134 |
+
<div role="note" aria-label="source link">
|
| 135 |
+
<h3>This Page</h3>
|
| 136 |
+
<ul class="this-page-menu">
|
| 137 |
+
<li><a href="../bugs.html">Report a Bug</a></li>
|
| 138 |
+
<li>
|
| 139 |
+
<a href="https://github.com/python/cpython/blob/main/Doc/library/idle.rst"
|
| 140 |
+
rel="nofollow">Show Source
|
| 141 |
+
</a>
|
| 142 |
+
</li>
|
| 143 |
+
</ul>
|
| 144 |
+
</div>
|
| 145 |
+
</nav>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
<div class="related" role="navigation" aria-label="related navigation">
|
| 151 |
+
<h3>Navigation</h3>
|
| 152 |
+
<ul>
|
| 153 |
+
<li class="right" style="margin-right: 10px">
|
| 154 |
+
<a href="../genindex.html" title="General Index"
|
| 155 |
+
accesskey="I">index</a></li>
|
| 156 |
+
<li class="right" >
|
| 157 |
+
<a href="../py-modindex.html" title="Python Module Index"
|
| 158 |
+
>modules</a> |</li>
|
| 159 |
+
<li class="right" >
|
| 160 |
+
<a href="development.html" title="Development Tools"
|
| 161 |
+
accesskey="N">next</a> |</li>
|
| 162 |
+
<li class="right" >
|
| 163 |
+
<a href="tkinter.tix.html" title="tkinter.tix — Extension widgets for Tk"
|
| 164 |
+
accesskey="P">previous</a> |</li>
|
| 165 |
+
|
| 166 |
+
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
| 167 |
+
<li><a href="https://www.python.org/">Python</a> »</li>
|
| 168 |
+
<li class="switchers">
|
| 169 |
+
<div class="language_switcher_placeholder"></div>
|
| 170 |
+
<div class="version_switcher_placeholder"></div>
|
| 171 |
+
</li>
|
| 172 |
+
<li>
|
| 173 |
+
|
| 174 |
+
</li>
|
| 175 |
+
<li id="cpython-language-and-version">
|
| 176 |
+
<a href="../index.html">3.12.0a0 Documentation</a> »
|
| 177 |
+
</li>
|
| 178 |
+
|
| 179 |
+
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
| 180 |
+
<li class="nav-item nav-item-2"><a href="tk.html" accesskey="U">Graphical User Interfaces with Tk</a> »</li>
|
| 181 |
+
<li class="nav-item nav-item-this"><a href="">IDLE</a></li>
|
| 182 |
+
<li class="right">
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
<div class="inline-search" role="search">
|
| 186 |
+
<form class="inline-search" action="../search.html" method="get">
|
| 187 |
+
<input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
|
| 188 |
+
<input type="submit" value="Go" />
|
| 189 |
+
<input type="hidden" name="check_keywords" value="yes" />
|
| 190 |
+
<input type="hidden" name="area" value="default" />
|
| 191 |
+
</form>
|
| 192 |
+
</div>
|
| 193 |
+
|
|
| 194 |
+
</li>
|
| 195 |
+
|
| 196 |
+
</ul>
|
| 197 |
+
</div>
|
| 198 |
+
|
| 199 |
+
<div class="document">
|
| 200 |
+
<div class="documentwrapper">
|
| 201 |
+
<div class="bodywrapper">
|
| 202 |
+
<div class="body" role="main">
|
| 203 |
+
|
| 204 |
+
<section id="idle">
|
| 205 |
+
<span id="id1"></span><h1>IDLE<a class="headerlink" href="#idle" title="Permalink to this heading">¶</a></h1>
|
| 206 |
+
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib/">Lib/idlelib/</a></p>
|
| 207 |
+
<hr class="docutils" id="index-0" />
|
| 208 |
+
<p>IDLE is Python’s Integrated Development and Learning Environment.</p>
|
| 209 |
+
<p>IDLE has the following features:</p>
|
| 210 |
+
<ul class="simple">
|
| 211 |
+
<li><p>coded in 100% pure Python, using the <a class="reference internal" href="tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> GUI toolkit</p></li>
|
| 212 |
+
<li><p>cross-platform: works mostly the same on Windows, Unix, and macOS</p></li>
|
| 213 |
+
<li><p>Python shell window (interactive interpreter) with colorizing
|
| 214 |
+
of code input, output, and error messages</p></li>
|
| 215 |
+
<li><p>multi-window text editor with multiple undo, Python colorizing,
|
| 216 |
+
smart indent, call tips, auto completion, and other features</p></li>
|
| 217 |
+
<li><p>search within any window, replace within editor windows, and search
|
| 218 |
+
through multiple files (grep)</p></li>
|
| 219 |
+
<li><p>debugger with persistent breakpoints, stepping, and viewing
|
| 220 |
+
of global and local namespaces</p></li>
|
| 221 |
+
<li><p>configuration, browsers, and other dialogs</p></li>
|
| 222 |
+
</ul>
|
| 223 |
+
<section id="menus">
|
| 224 |
+
<h2>Menus<a class="headerlink" href="#menus" title="Permalink to this heading">¶</a></h2>
|
| 225 |
+
<p>IDLE has two main window types, the Shell window and the Editor window. It is
|
| 226 |
+
possible to have multiple editor windows simultaneously. On Windows and
|
| 227 |
+
Linux, each has its own top menu. Each menu documented below indicates
|
| 228 |
+
which window type it is associated with.</p>
|
| 229 |
+
<p>Output windows, such as used for Edit => Find in Files, are a subtype of editor
|
| 230 |
+
window. They currently have the same top menu but a different
|
| 231 |
+
default title and context menu.</p>
|
| 232 |
+
<p>On macOS, there is one application menu. It dynamically changes according
|
| 233 |
+
to the window currently selected. It has an IDLE menu, and some entries
|
| 234 |
+
described below are moved around to conform to Apple guidelines.</p>
|
| 235 |
+
<section id="file-menu-shell-and-editor">
|
| 236 |
+
<h3>File menu (Shell and Editor)<a class="headerlink" href="#file-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 237 |
+
<dl class="simple">
|
| 238 |
+
<dt>New File</dt><dd><p>Create a new file editing window.</p>
|
| 239 |
+
</dd>
|
| 240 |
+
<dt>Open…</dt><dd><p>Open an existing file with an Open dialog.</p>
|
| 241 |
+
</dd>
|
| 242 |
+
<dt>Open Module…</dt><dd><p>Open an existing module (searches sys.path).</p>
|
| 243 |
+
</dd>
|
| 244 |
+
<dt>Recent Files</dt><dd><p>Open a list of recent files. Click one to open it.</p>
|
| 245 |
+
</dd>
|
| 246 |
+
</dl>
|
| 247 |
+
<dl class="simple" id="index-1">
|
| 248 |
+
<dt>Module Browser</dt><dd><p>Show functions, classes, and methods in the current Editor file in a
|
| 249 |
+
tree structure. In the shell, open a module first.</p>
|
| 250 |
+
</dd>
|
| 251 |
+
<dt>Path Browser</dt><dd><p>Show sys.path directories, modules, functions, classes and methods in a
|
| 252 |
+
tree structure.</p>
|
| 253 |
+
</dd>
|
| 254 |
+
<dt>Save</dt><dd><p>Save the current window to the associated file, if there is one. Windows
|
| 255 |
+
that have been changed since being opened or last saved have a * before
|
| 256 |
+
and after the window title. If there is no associated file,
|
| 257 |
+
do Save As instead.</p>
|
| 258 |
+
</dd>
|
| 259 |
+
<dt>Save As…</dt><dd><p>Save the current window with a Save As dialog. The file saved becomes the
|
| 260 |
+
new associated file for the window. (If your file namager is set to hide
|
| 261 |
+
extensions, the current extension will be omitted in the file name box.
|
| 262 |
+
If the new filename has no ‘.’, ‘.py’ and ‘.txt’ will be added for Python
|
| 263 |
+
and text files, except that on macOS Aqua,’.py’ is added for all files.)</p>
|
| 264 |
+
</dd>
|
| 265 |
+
<dt>Save Copy As…</dt><dd><p>Save the current window to different file without changing the associated
|
| 266 |
+
file. (See Save As note above about filename extensions.)</p>
|
| 267 |
+
</dd>
|
| 268 |
+
<dt>Print Window</dt><dd><p>Print the current window to the default printer.</p>
|
| 269 |
+
</dd>
|
| 270 |
+
<dt>Close Window</dt><dd><p>Close the current window (if an unsaved editor, ask to save; if an unsaved
|
| 271 |
+
Shell, ask to quit execution). Calling <code class="docutils literal notranslate"><span class="pre">exit()</span></code> or <code class="docutils literal notranslate"><span class="pre">close()</span></code> in the Shell
|
| 272 |
+
window also closes Shell. If this is the only window, also exit IDLE.</p>
|
| 273 |
+
</dd>
|
| 274 |
+
<dt>Exit IDLE</dt><dd><p>Close all windows and quit IDLE (ask to save unsaved edit windows).</p>
|
| 275 |
+
</dd>
|
| 276 |
+
</dl>
|
| 277 |
+
</section>
|
| 278 |
+
<section id="edit-menu-shell-and-editor">
|
| 279 |
+
<h3>Edit menu (Shell and Editor)<a class="headerlink" href="#edit-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 280 |
+
<dl class="simple">
|
| 281 |
+
<dt>Undo</dt><dd><p>Undo the last change to the current window. A maximum of 1000 changes may
|
| 282 |
+
be undone.</p>
|
| 283 |
+
</dd>
|
| 284 |
+
<dt>Redo</dt><dd><p>Redo the last undone change to the current window.</p>
|
| 285 |
+
</dd>
|
| 286 |
+
<dt>Select All</dt><dd><p>Select the entire contents of the current window.</p>
|
| 287 |
+
</dd>
|
| 288 |
+
<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>
|
| 289 |
+
</dd>
|
| 290 |
+
<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>
|
| 291 |
+
</dd>
|
| 292 |
+
<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>
|
| 293 |
+
</dd>
|
| 294 |
+
</dl>
|
| 295 |
+
<p>The clipboard functions are also available in context menus.</p>
|
| 296 |
+
<dl class="simple">
|
| 297 |
+
<dt>Find…</dt><dd><p>Open a search dialog with many options</p>
|
| 298 |
+
</dd>
|
| 299 |
+
<dt>Find Again</dt><dd><p>Repeat the last search, if there is one.</p>
|
| 300 |
+
</dd>
|
| 301 |
+
<dt>Find Selection</dt><dd><p>Search for the currently selected string, if there is one.</p>
|
| 302 |
+
</dd>
|
| 303 |
+
<dt>Find in Files…</dt><dd><p>Open a file search dialog. Put results in a new output window.</p>
|
| 304 |
+
</dd>
|
| 305 |
+
<dt>Replace…</dt><dd><p>Open a search-and-replace dialog.</p>
|
| 306 |
+
</dd>
|
| 307 |
+
<dt>Go to Line</dt><dd><p>Move the cursor to the beginning of the line requested and make that
|
| 308 |
+
line visible. A request past the end of the file goes to the end.
|
| 309 |
+
Clear any selection and update the line and column status.</p>
|
| 310 |
+
</dd>
|
| 311 |
+
<dt>Show Completions</dt><dd><p>Open a scrollable list allowing selection of existing names. See
|
| 312 |
+
<a class="reference internal" href="#completions"><span class="std std-ref">Completions</span></a> in the Editing and navigation section below.</p>
|
| 313 |
+
</dd>
|
| 314 |
+
<dt>Expand Word</dt><dd><p>Expand a prefix you have typed to match a full word in the same window;
|
| 315 |
+
repeat to get a different expansion.</p>
|
| 316 |
+
</dd>
|
| 317 |
+
<dt>Show Call Tip</dt><dd><p>After an unclosed parenthesis for a function, open a small window with
|
| 318 |
+
function parameter hints. See <a class="reference internal" href="#calltips"><span class="std std-ref">Calltips</span></a> in the
|
| 319 |
+
Editing and navigation section below.</p>
|
| 320 |
+
</dd>
|
| 321 |
+
<dt>Show Surrounding Parens</dt><dd><p>Highlight the surrounding parenthesis.</p>
|
| 322 |
+
</dd>
|
| 323 |
+
</dl>
|
| 324 |
+
</section>
|
| 325 |
+
<section id="format-menu-editor-window-only">
|
| 326 |
+
<span id="format-menu"></span><h3>Format menu (Editor window only)<a class="headerlink" href="#format-menu-editor-window-only" title="Permalink to this heading">¶</a></h3>
|
| 327 |
+
<dl class="simple">
|
| 328 |
+
<dt>Format Paragraph</dt><dd><p>Reformat the current blank-line-delimited paragraph in comment block or
|
| 329 |
+
multiline string or selected line in a string. All lines in the
|
| 330 |
+
paragraph will be formatted to less than N columns, where N defaults to 72.</p>
|
| 331 |
+
</dd>
|
| 332 |
+
<dt>Indent Region</dt><dd><p>Shift selected lines right by the indent width (default 4 spaces).</p>
|
| 333 |
+
</dd>
|
| 334 |
+
<dt>Dedent Region</dt><dd><p>Shift selected lines left by the indent width (default 4 spaces).</p>
|
| 335 |
+
</dd>
|
| 336 |
+
<dt>Comment Out Region</dt><dd><p>Insert ## in front of selected lines.</p>
|
| 337 |
+
</dd>
|
| 338 |
+
<dt>Uncomment Region</dt><dd><p>Remove leading # or ## from selected lines.</p>
|
| 339 |
+
</dd>
|
| 340 |
+
<dt>Tabify Region</dt><dd><p>Turn <em>leading</em> stretches of spaces into tabs. (Note: We recommend using
|
| 341 |
+
4 space blocks to indent Python code.)</p>
|
| 342 |
+
</dd>
|
| 343 |
+
<dt>Untabify Region</dt><dd><p>Turn <em>all</em> tabs into the correct number of spaces.</p>
|
| 344 |
+
</dd>
|
| 345 |
+
<dt>Toggle Tabs</dt><dd><p>Open a dialog to switch between indenting with spaces and tabs.</p>
|
| 346 |
+
</dd>
|
| 347 |
+
<dt>New Indent Width</dt><dd><p>Open a dialog to change indent width. The accepted default by the Python
|
| 348 |
+
community is 4 spaces.</p>
|
| 349 |
+
</dd>
|
| 350 |
+
<dt>Strip Trailing Chitespace</dt><dd><p>Remove trailing space and other whitespace characters after the last
|
| 351 |
+
non-whitespace character of a line by applying str.rstrip to each line,
|
| 352 |
+
including lines within multiline strings. Except for Shell windows,
|
| 353 |
+
remove extra newlines at the end of the file.</p>
|
| 354 |
+
</dd>
|
| 355 |
+
</dl>
|
| 356 |
+
</section>
|
| 357 |
+
<section id="run-menu-editor-window-only">
|
| 358 |
+
<span id="index-2"></span><h3>Run menu (Editor window only)<a class="headerlink" href="#run-menu-editor-window-only" title="Permalink to this heading">¶</a></h3>
|
| 359 |
+
<dl class="simple" id="run-module">
|
| 360 |
+
<dt>Run Module</dt><dd><p>Do <a class="reference internal" href="#check-module"><span class="std std-ref">Check Module</span></a>. If no error, restart the shell to clean the
|
| 361 |
+
environment, then execute the module. Output is displayed in the Shell
|
| 362 |
+
window. Note that output requires use of <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code>.
|
| 363 |
+
When execution is complete, the Shell retains focus and displays a prompt.
|
| 364 |
+
At this point, one may interactively explore the result of execution.
|
| 365 |
+
This is similar to executing a file with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span> <span class="pre">file</span></code> at a command
|
| 366 |
+
line.</p>
|
| 367 |
+
</dd>
|
| 368 |
+
</dl>
|
| 369 |
+
<dl class="simple" id="run-custom">
|
| 370 |
+
<dt>Run… Customized</dt><dd><p>Same as <a class="reference internal" href="#run-module"><span class="std std-ref">Run Module</span></a>, but run the module with customized
|
| 371 |
+
settings. <em>Command Line Arguments</em> extend <a class="reference internal" href="sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> as if passed
|
| 372 |
+
on a command line. The module can be run in the Shell without restarting.</p>
|
| 373 |
+
</dd>
|
| 374 |
+
</dl>
|
| 375 |
+
<dl class="simple" id="check-module">
|
| 376 |
+
<dt>Check Module</dt><dd><p>Check the syntax of the module currently open in the Editor window. If the
|
| 377 |
+
module has not been saved IDLE will either prompt the user to save or
|
| 378 |
+
autosave, as selected in the General tab of the Idle Settings dialog. If
|
| 379 |
+
there is a syntax error, the approximate location is indicated in the
|
| 380 |
+
Editor window.</p>
|
| 381 |
+
</dd>
|
| 382 |
+
</dl>
|
| 383 |
+
<dl class="simple" id="python-shell">
|
| 384 |
+
<dt>Python Shell</dt><dd><p>Open or wake up the Python Shell window.</p>
|
| 385 |
+
</dd>
|
| 386 |
+
</dl>
|
| 387 |
+
</section>
|
| 388 |
+
<section id="shell-menu-shell-window-only">
|
| 389 |
+
<h3>Shell menu (Shell window only)<a class="headerlink" href="#shell-menu-shell-window-only" title="Permalink to this heading">¶</a></h3>
|
| 390 |
+
<dl class="simple">
|
| 391 |
+
<dt>View Last Restart</dt><dd><p>Scroll the shell window to the last Shell restart.</p>
|
| 392 |
+
</dd>
|
| 393 |
+
<dt>Restart Shell</dt><dd><p>Restart the shell to clean the environment and reset display and exception handling.</p>
|
| 394 |
+
</dd>
|
| 395 |
+
<dt>Previous History</dt><dd><p>Cycle through earlier commands in history which match the current entry.</p>
|
| 396 |
+
</dd>
|
| 397 |
+
<dt>Next History</dt><dd><p>Cycle through later commands in history which match the current entry.</p>
|
| 398 |
+
</dd>
|
| 399 |
+
<dt>Interrupt Execution</dt><dd><p>Stop a running program.</p>
|
| 400 |
+
</dd>
|
| 401 |
+
</dl>
|
| 402 |
+
</section>
|
| 403 |
+
<section id="debug-menu-shell-window-only">
|
| 404 |
+
<h3>Debug menu (Shell window only)<a class="headerlink" href="#debug-menu-shell-window-only" title="Permalink to this heading">¶</a></h3>
|
| 405 |
+
<dl class="simple">
|
| 406 |
+
<dt>Go to File/Line</dt><dd><p>Look on the current line. with the cursor, and the line above for a filename
|
| 407 |
+
and line number. If found, open the file if not already open, and show the
|
| 408 |
+
line. Use this to view source lines referenced in an exception traceback
|
| 409 |
+
and lines found by Find in Files. Also available in the context menu of
|
| 410 |
+
the Shell window and Output windows.</p>
|
| 411 |
+
</dd>
|
| 412 |
+
</dl>
|
| 413 |
+
<dl class="simple" id="index-3">
|
| 414 |
+
<dt>Debugger (toggle)</dt><dd><p>When activated, code entered in the Shell or run from an Editor will run
|
| 415 |
+
under the debugger. In the Editor, breakpoints can be set with the context
|
| 416 |
+
menu. This feature is still incomplete and somewhat experimental.</p>
|
| 417 |
+
</dd>
|
| 418 |
+
<dt>Stack Viewer</dt><dd><p>Show the stack traceback of the last exception in a tree widget, with
|
| 419 |
+
access to locals and globals.</p>
|
| 420 |
+
</dd>
|
| 421 |
+
<dt>Auto-open Stack Viewer</dt><dd><p>Toggle automatically opening the stack viewer on an unhandled exception.</p>
|
| 422 |
+
</dd>
|
| 423 |
+
</dl>
|
| 424 |
+
</section>
|
| 425 |
+
<section id="options-menu-shell-and-editor">
|
| 426 |
+
<h3>Options menu (Shell and Editor)<a class="headerlink" href="#options-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 427 |
+
<dl class="simple">
|
| 428 |
+
<dt>Configure IDLE</dt><dd><p>Open a configuration dialog and change preferences for the following:
|
| 429 |
+
fonts, indentation, keybindings, text color themes, startup windows and
|
| 430 |
+
size, additional help sources, and extensions. On macOS, open the
|
| 431 |
+
configuration dialog by selecting Preferences in the application
|
| 432 |
+
menu. For more details, see
|
| 433 |
+
<a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a> under Help and preferences.</p>
|
| 434 |
+
</dd>
|
| 435 |
+
</dl>
|
| 436 |
+
<p>Most configuration options apply to all windows or all future windows.
|
| 437 |
+
The option items below only apply to the active window.</p>
|
| 438 |
+
<dl class="simple">
|
| 439 |
+
<dt>Show/Hide Code Context (Editor Window only)</dt><dd><p>Open a pane at the top of the edit window which shows the block context
|
| 440 |
+
of the code which has scrolled above the top of the window. See
|
| 441 |
+
<a class="reference internal" href="#code-context"><span class="std std-ref">Code Context</span></a> in the Editing and Navigation section
|
| 442 |
+
below.</p>
|
| 443 |
+
</dd>
|
| 444 |
+
<dt>Show/Hide Line Numbers (Editor Window only)</dt><dd><p>Open a column to the left of the edit window which shows the number
|
| 445 |
+
of each line of text. The default is off, which may be changed in the
|
| 446 |
+
preferences (see <a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a>).</p>
|
| 447 |
+
</dd>
|
| 448 |
+
<dt>Zoom/Restore Height</dt><dd><p>Toggles the window between normal size and maximum height. The initial size
|
| 449 |
+
defaults to 40 lines by 80 chars unless changed on the General tab of the
|
| 450 |
+
Configure IDLE dialog. The maximum height for a screen is determined by
|
| 451 |
+
momentarily maximizing a window the first time one is zoomed on the screen.
|
| 452 |
+
Changing screen settings may invalidate the saved height. This toggle has
|
| 453 |
+
no effect when a window is maximized.</p>
|
| 454 |
+
</dd>
|
| 455 |
+
</dl>
|
| 456 |
+
</section>
|
| 457 |
+
<section id="window-menu-shell-and-editor">
|
| 458 |
+
<h3>Window menu (Shell and Editor)<a class="headerlink" href="#window-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 459 |
+
<p>Lists the names of all open windows; select one to bring it to the foreground
|
| 460 |
+
(deiconifying it if necessary).</p>
|
| 461 |
+
</section>
|
| 462 |
+
<section id="help-menu-shell-and-editor">
|
| 463 |
+
<h3>Help menu (Shell and Editor)<a class="headerlink" href="#help-menu-shell-and-editor" title="Permalink to this heading">¶</a></h3>
|
| 464 |
+
<dl class="simple">
|
| 465 |
+
<dt>About IDLE</dt><dd><p>Display version, copyright, license, credits, and more.</p>
|
| 466 |
+
</dd>
|
| 467 |
+
<dt>IDLE Help</dt><dd><p>Display this IDLE document, detailing the menu options, basic editing and
|
| 468 |
+
navigation, and other tips.</p>
|
| 469 |
+
</dd>
|
| 470 |
+
<dt>Python Docs</dt><dd><p>Access local Python documentation, if installed, or start a web browser
|
| 471 |
+
and open docs.python.org showing the latest Python documentation.</p>
|
| 472 |
+
</dd>
|
| 473 |
+
<dt>Turtle Demo</dt><dd><p>Run the turtledemo module with example Python code and turtle drawings.</p>
|
| 474 |
+
</dd>
|
| 475 |
+
</dl>
|
| 476 |
+
<p>Additional help sources may be added here with the Configure IDLE dialog under
|
| 477 |
+
the General tab. See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below
|
| 478 |
+
for more on Help menu choices.</p>
|
| 479 |
+
</section>
|
| 480 |
+
<section id="context-menus">
|
| 481 |
+
<span id="index-4"></span><h3>Context menus<a class="headerlink" href="#context-menus" title="Permalink to this heading">¶</a></h3>
|
| 482 |
+
<p>Open a context menu by right-clicking in a window (Control-click on macOS).
|
| 483 |
+
Context menus have the standard clipboard functions also on the Edit menu.</p>
|
| 484 |
+
<dl class="simple">
|
| 485 |
+
<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>
|
| 486 |
+
</dd>
|
| 487 |
+
<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>
|
| 488 |
+
</dd>
|
| 489 |
+
<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>
|
| 490 |
+
</dd>
|
| 491 |
+
</dl>
|
| 492 |
+
<p>Editor windows also have breakpoint functions. Lines with a breakpoint set are
|
| 493 |
+
specially marked. Breakpoints only have an effect when running under the
|
| 494 |
+
debugger. Breakpoints for a file are saved in the user’s <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>
|
| 495 |
+
directory.</p>
|
| 496 |
+
<dl class="simple">
|
| 497 |
+
<dt>Set Breakpoint</dt><dd><p>Set a breakpoint on the current line.</p>
|
| 498 |
+
</dd>
|
| 499 |
+
<dt>Clear Breakpoint</dt><dd><p>Clear the breakpoint on that line.</p>
|
| 500 |
+
</dd>
|
| 501 |
+
</dl>
|
| 502 |
+
<p>Shell and Output windows also have the following.</p>
|
| 503 |
+
<dl class="simple">
|
| 504 |
+
<dt>Go to file/line</dt><dd><p>Same as in Debug menu.</p>
|
| 505 |
+
</dd>
|
| 506 |
+
</dl>
|
| 507 |
+
<p>The Shell window also has an output squeezing facility explained in the <em>Python
|
| 508 |
+
Shell window</em> subsection below.</p>
|
| 509 |
+
<dl class="simple">
|
| 510 |
+
<dt>Squeeze</dt><dd><p>If the cursor is over an output line, squeeze all the output between
|
| 511 |
+
the code above and the prompt below down to a ‘Squeezed text’ label.</p>
|
| 512 |
+
</dd>
|
| 513 |
+
</dl>
|
| 514 |
+
</section>
|
| 515 |
+
</section>
|
| 516 |
+
<section id="editing-and-navigation">
|
| 517 |
+
<span id="id2"></span><h2>Editing and Navigation<a class="headerlink" href="#editing-and-navigation" title="Permalink to this heading">¶</a></h2>
|
| 518 |
+
<section id="editor-windows">
|
| 519 |
+
<h3>Editor windows<a class="headerlink" href="#editor-windows" title="Permalink to this heading">¶</a></h3>
|
| 520 |
+
<p>IDLE may open editor windows when it starts, depending on settings
|
| 521 |
+
and how you start IDLE. Thereafter, use the File menu. There can be only
|
| 522 |
+
one open editor window for a given file.</p>
|
| 523 |
+
<p>The title bar contains the name of the file, the full path, and the version
|
| 524 |
+
of Python and IDLE running the window. The status bar contains the line
|
| 525 |
+
number (‘Ln’) and column number (‘Col’). Line numbers start with 1;
|
| 526 |
+
column numbers with 0.</p>
|
| 527 |
+
<p>IDLE assumes that files with a known .py* extension contain Python code
|
| 528 |
+
and that other files do not. Run Python code with the Run menu.</p>
|
| 529 |
+
</section>
|
| 530 |
+
<section id="key-bindings">
|
| 531 |
+
<h3>Key bindings<a class="headerlink" href="#key-bindings" title="Permalink to this heading">¶</a></h3>
|
| 532 |
+
<p>In this section, ‘C’ refers to the <kbd class="kbd docutils literal notranslate">Control</kbd> key on Windows and Unix and
|
| 533 |
+
the <kbd class="kbd docutils literal notranslate">Command</kbd> key on macOS.</p>
|
| 534 |
+
<ul>
|
| 535 |
+
<li><p><kbd class="kbd docutils literal notranslate">Backspace</kbd> deletes to the left; <kbd class="kbd docutils literal notranslate">Del</kbd> deletes to the right</p></li>
|
| 536 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Backspace</kbd></kbd> delete word left; <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Del</kbd></kbd> delete word to the right</p></li>
|
| 537 |
+
<li><p>Arrow keys and <kbd class="kbd docutils literal notranslate">Page Up</kbd>/<kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Page</kbd> <kbd class="kbd docutils literal notranslate">Down</kbd></kbd> to move around</p></li>
|
| 538 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">LeftArrow</kbd></kbd> and <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">RightArrow</kbd></kbd> moves by words</p></li>
|
| 539 |
+
<li><p><kbd class="kbd docutils literal notranslate">Home</kbd>/<kbd class="kbd docutils literal notranslate">End</kbd> go to begin/end of line</p></li>
|
| 540 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Home</kbd></kbd>/<kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">End</kbd></kbd> go to begin/end of file</p></li>
|
| 541 |
+
<li><p>Some useful Emacs bindings are inherited from Tcl/Tk:</p>
|
| 542 |
+
<blockquote>
|
| 543 |
+
<div><ul class="simple">
|
| 544 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">a</kbd></kbd> beginning of line</p></li>
|
| 545 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">e</kbd></kbd> end of line</p></li>
|
| 546 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">k</kbd></kbd> kill line (but doesn’t put it in clipboard)</p></li>
|
| 547 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">l</kbd></kbd> center window around the insertion point</p></li>
|
| 548 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">b</kbd></kbd> go backward one character without deleting (usually you can
|
| 549 |
+
also use the cursor key for this)</p></li>
|
| 550 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">f</kbd></kbd> go forward one character without deleting (usually you can
|
| 551 |
+
also use the cursor key for this)</p></li>
|
| 552 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd></kbd> go up one line (usually you can also use the cursor key for
|
| 553 |
+
this)</p></li>
|
| 554 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd></kbd> delete next character</p></li>
|
| 555 |
+
</ul>
|
| 556 |
+
</div></blockquote>
|
| 557 |
+
</li>
|
| 558 |
+
</ul>
|
| 559 |
+
<p>Standard keybindings (like <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd></kbd> to copy and <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">v</kbd></kbd> to paste)
|
| 560 |
+
may work. Keybindings are selected in the Configure IDLE dialog.</p>
|
| 561 |
+
</section>
|
| 562 |
+
<section id="automatic-indentation">
|
| 563 |
+
<h3>Automatic indentation<a class="headerlink" href="#automatic-indentation" title="Permalink to this heading">¶</a></h3>
|
| 564 |
+
<p>After a block-opening statement, the next line is indented by 4 spaces (in the
|
| 565 |
+
Python Shell window by one tab). After certain keywords (break, return etc.)
|
| 566 |
+
the next line is dedented. In leading indentation, <kbd class="kbd docutils literal notranslate">Backspace</kbd> deletes up
|
| 567 |
+
to 4 spaces if they are there. <kbd class="kbd docutils literal notranslate">Tab</kbd> inserts spaces (in the Python
|
| 568 |
+
Shell window one tab), number depends on Indent width. Currently, tabs
|
| 569 |
+
are restricted to four spaces due to Tcl/Tk limitations.</p>
|
| 570 |
+
<p>See also the indent/dedent region commands on the
|
| 571 |
+
<a class="reference internal" href="#format-menu"><span class="std std-ref">Format menu</span></a>.</p>
|
| 572 |
+
</section>
|
| 573 |
+
<section id="search-and-replace">
|
| 574 |
+
<h3>Search and Replace<a class="headerlink" href="#search-and-replace" title="Permalink to this heading">¶</a></h3>
|
| 575 |
+
<p>Any selection becomes a search target. However, only selections within
|
| 576 |
+
a line work because searches are only performed within lines with the
|
| 577 |
+
terminal newline removed. If <code class="docutils literal notranslate"><span class="pre">[x]</span> <span class="pre">Regular</span> <span class="pre">expresion</span></code> is checked, the
|
| 578 |
+
target is interpreted according to the Python re module.</p>
|
| 579 |
+
</section>
|
| 580 |
+
<section id="completions">
|
| 581 |
+
<span id="id3"></span><h3>Completions<a class="headerlink" href="#completions" title="Permalink to this heading">¶</a></h3>
|
| 582 |
+
<p>Completions are supplied, when requested and available, for module
|
| 583 |
+
names, attributes of classes or functions, or filenames. Each request
|
| 584 |
+
method displays a completion box with existing names. (See tab
|
| 585 |
+
completions below for an exception.) For any box, change the name
|
| 586 |
+
being completed and the item highlighted in the box by
|
| 587 |
+
typing and deleting characters; by hitting <kbd class="kbd docutils literal notranslate">Up</kbd>, <kbd class="kbd docutils literal notranslate">Down</kbd>,
|
| 588 |
+
<kbd class="kbd docutils literal notranslate">PageUp</kbd>, <kbd class="kbd docutils literal notranslate">PageDown</kbd>, <kbd class="kbd docutils literal notranslate">Home</kbd>, and <kbd class="kbd docutils literal notranslate">End</kbd> keys;
|
| 589 |
+
and by a single click within the box. Close the box with <kbd class="kbd docutils literal notranslate">Escape</kbd>,
|
| 590 |
+
<kbd class="kbd docutils literal notranslate">Enter</kbd>, and double <kbd class="kbd docutils literal notranslate">Tab</kbd> keys or clicks outside the box.
|
| 591 |
+
A double click within the box selects and closes.</p>
|
| 592 |
+
<p>One way to open a box is to type a key character and wait for a
|
| 593 |
+
predefined interval. This defaults to 2 seconds; customize it
|
| 594 |
+
in the settings dialog. (To prevent auto popups, set the delay to a
|
| 595 |
+
large number of milliseconds, such as 100000000.) For imported module
|
| 596 |
+
names or class or function attributes, type ‘.’.
|
| 597 |
+
For filenames in the root directory, type <a class="reference internal" href="os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.sep</span></code></a> or
|
| 598 |
+
<a class="reference internal" href="os.html#os.altsep" title="os.altsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.altsep</span></code></a> immediately after an opening quote. (On Windows,
|
| 599 |
+
one can specify a drive first.) Move into subdirectories by typing a
|
| 600 |
+
directory name and a separator.</p>
|
| 601 |
+
<p>Instead of waiting, or after a box is closed, open a completion box
|
| 602 |
+
immediately with Show Completions on the Edit menu. The default hot
|
| 603 |
+
key is <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">space</kbd></kbd>. If one types a prefix for the desired name
|
| 604 |
+
before opening the box, the first match or near miss is made visible.
|
| 605 |
+
The result is the same as if one enters a prefix
|
| 606 |
+
after the box is displayed. Show Completions after a quote completes
|
| 607 |
+
filenames in the current directory instead of a root directory.</p>
|
| 608 |
+
<p>Hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix usually has the same effect as Show
|
| 609 |
+
Completions. (With no prefix, it indents.) However, if there is only
|
| 610 |
+
one match to the prefix, that match is immediately added to the editor
|
| 611 |
+
text without opening a box.</p>
|
| 612 |
+
<p>Invoking ‘Show Completions’, or hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix,
|
| 613 |
+
outside of a string and without a preceding ‘.’ opens a box with
|
| 614 |
+
keywords, builtin names, and available module-level names.</p>
|
| 615 |
+
<p>When editing code in an editor (as oppose to Shell), increase the
|
| 616 |
+
available module-level names by running your code
|
| 617 |
+
and not restarting the Shell thereafter. This is especially useful
|
| 618 |
+
after adding imports at the top of a file. This also increases
|
| 619 |
+
possible attribute completions.</p>
|
| 620 |
+
<p>Completion boxes initially exclude names beginning with ‘_’ or, for
|
| 621 |
+
modules, not included in ‘__all__’. The hidden names can be accessed
|
| 622 |
+
by typing ‘_’ after ‘.’, either before or after the box is opened.</p>
|
| 623 |
+
</section>
|
| 624 |
+
<section id="calltips">
|
| 625 |
+
<span id="id4"></span><h3>Calltips<a class="headerlink" href="#calltips" title="Permalink to this heading">¶</a></h3>
|
| 626 |
+
<p>A calltip is shown automatically when one types <kbd class="kbd docutils literal notranslate">(</kbd> after the name
|
| 627 |
+
of an <em>accessible</em> function. A function name expression may include
|
| 628 |
+
dots and subscripts. A calltip remains until it is clicked, the cursor
|
| 629 |
+
is moved out of the argument area, or <kbd class="kbd docutils literal notranslate">)</kbd> is typed. Whenever the
|
| 630 |
+
cursor is in the argument part of a definition, select Edit and “Show
|
| 631 |
+
Call Tip” on the menu or enter its shortcut to display a calltip.</p>
|
| 632 |
+
<p>The calltip consists of the function’s signature and docstring up to
|
| 633 |
+
the latter’s first blank line or the fifth non-blank line. (Some builtin
|
| 634 |
+
functions lack an accessible signature.) A ‘/’ or ‘*’ in the signature
|
| 635 |
+
indicates that the preceding or following arguments are passed by
|
| 636 |
+
position or name (keyword) only. Details are subject to change.</p>
|
| 637 |
+
<p>In Shell, the accessible functions depends on what modules have been
|
| 638 |
+
imported into the user process, including those imported by Idle itself,
|
| 639 |
+
and which definitions have been run, all since the last restart.</p>
|
| 640 |
+
<p>For example, restart the Shell and enter <code class="docutils literal notranslate"><span class="pre">itertools.count(</span></code>. A calltip
|
| 641 |
+
appears because Idle imports itertools into the user process for its own
|
| 642 |
+
use. (This could change.) Enter <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code> and nothing appears.
|
| 643 |
+
Idle does not itself import turtle. The menu entry and shortcut also do
|
| 644 |
+
nothing. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">turtle</span></code>. Thereafter, <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code>
|
| 645 |
+
will display a calltip.</p>
|
| 646 |
+
<p>In an editor, import statements have no effect until one runs the file.
|
| 647 |
+
One might want to run a file after writing import statements, after
|
| 648 |
+
adding function definitions, or after opening an existing file.</p>
|
| 649 |
+
</section>
|
| 650 |
+
<section id="code-context">
|
| 651 |
+
<span id="id5"></span><h3>Code Context<a class="headerlink" href="#code-context" title="Permalink to this heading">¶</a></h3>
|
| 652 |
+
<p>Within an editor window containing Python code, code context can be toggled
|
| 653 |
+
in order to show or hide a pane at the top of the window. When shown, this
|
| 654 |
+
pane freezes the opening lines for block code, such as those beginning with
|
| 655 |
+
<code class="docutils literal notranslate"><span class="pre">class</span></code>, <code class="docutils literal notranslate"><span class="pre">def</span></code>, or <code class="docutils literal notranslate"><span class="pre">if</span></code> keywords, that would have otherwise scrolled
|
| 656 |
+
out of view. The size of the pane will be expanded and contracted as needed
|
| 657 |
+
to show the all current levels of context, up to the maximum number of
|
| 658 |
+
lines defined in the Configure IDLE dialog (which defaults to 15). If there
|
| 659 |
+
are no current context lines and the feature is toggled on, a single blank
|
| 660 |
+
line will display. Clicking on a line in the context pane will move that
|
| 661 |
+
line to the top of the editor.</p>
|
| 662 |
+
<p>The text and background colors for the context pane can be configured under
|
| 663 |
+
the Highlights tab in the Configure IDLE dialog.</p>
|
| 664 |
+
</section>
|
| 665 |
+
<section id="shell-window">
|
| 666 |
+
<h3>Shell window<a class="headerlink" href="#shell-window" title="Permalink to this heading">¶</a></h3>
|
| 667 |
+
<p>In IDLE’s Shell, enter, edit, and recall complete statements. (Most
|
| 668 |
+
consoles and terminals only work with a single physical line at a time).</p>
|
| 669 |
+
<p>Submit a single-line statement for execution by hitting <kbd class="kbd docutils literal notranslate">Return</kbd>
|
| 670 |
+
with the cursor anywhere on the line. If a line is extended with
|
| 671 |
+
Backslash (<kbd class="kbd docutils literal notranslate">\</kbd>), the cursor must be on the last physical line.
|
| 672 |
+
Submit a multi-line compound statement by entering a blank line after
|
| 673 |
+
the statement.</p>
|
| 674 |
+
<p>When one pastes code into Shell, it is not compiled and possibly executed
|
| 675 |
+
until one hits <kbd class="kbd docutils literal notranslate">Return</kbd>, as specified above.
|
| 676 |
+
One may edit pasted code first.
|
| 677 |
+
If one pastes more than one statement into Shell, the result will be a
|
| 678 |
+
<a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> when multiple statements are compiled as if they were one.</p>
|
| 679 |
+
<p>Lines containing <code class="docutils literal notranslate"><span class="pre">RESTART</span></code> mean that the user execution process has been
|
| 680 |
+
re-started. This occurs when the user execution process has crashed,
|
| 681 |
+
when one requests a restart on the Shell menu, or when one runs code
|
| 682 |
+
in an editor window.</p>
|
| 683 |
+
<p>The editing features described in previous subsections work when entering
|
| 684 |
+
code interactively. IDLE’s Shell window also responds to the following keys.</p>
|
| 685 |
+
<ul>
|
| 686 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd></kbd> interrupts executing command</p></li>
|
| 687 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd></kbd> sends end-of-file; closes window if typed at a <code class="docutils literal notranslate"><span class="pre">>>></span></code> prompt</p></li>
|
| 688 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">/</kbd></kbd> (Expand word) is also useful to reduce typing</p>
|
| 689 |
+
<p>Command history</p>
|
| 690 |
+
<ul class="simple">
|
| 691 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd></kbd> retrieves previous command matching what you have typed. On
|
| 692 |
+
macOS use <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd></kbd>.</p></li>
|
| 693 |
+
<li><p><kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd></kbd> retrieves next. On macOS use <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd></kbd>.</p></li>
|
| 694 |
+
<li><p><kbd class="kbd docutils literal notranslate">Return</kbd> while the cursor is on any previous command
|
| 695 |
+
retrieves that command</p></li>
|
| 696 |
+
</ul>
|
| 697 |
+
</li>
|
| 698 |
+
</ul>
|
| 699 |
+
</section>
|
| 700 |
+
<section id="text-colors">
|
| 701 |
+
<h3>Text colors<a class="headerlink" href="#text-colors" title="Permalink to this heading">¶</a></h3>
|
| 702 |
+
<p>Idle defaults to black on white text, but colors text with special meanings.
|
| 703 |
+
For the shell, these are shell output, shell error, user output, and
|
| 704 |
+
user error. For Python code, at the shell prompt or in an editor, these are
|
| 705 |
+
keywords, builtin class and function names, names following <code class="docutils literal notranslate"><span class="pre">class</span></code> and
|
| 706 |
+
<code class="docutils literal notranslate"><span class="pre">def</span></code>, strings, and comments. For any text window, these are the cursor (when
|
| 707 |
+
present), found text (when possible), and selected text.</p>
|
| 708 |
+
<p>IDLE also highlights the <a class="reference internal" href="../reference/lexical_analysis.html#soft-keywords"><span class="std std-ref">soft keywords</span></a> <a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">match</span></code></a>,
|
| 709 |
+
<a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">case</span></code></a>, and <a class="reference internal" href="../reference/compound_stmts.html#wildcard-patterns"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">_</span></code></a> in
|
| 710 |
+
pattern-matching statements. However, this highlighting is not perfect and
|
| 711 |
+
will be incorrect in some rare cases, including some <code class="docutils literal notranslate"><span class="pre">_</span></code>-s in <code class="docutils literal notranslate"><span class="pre">case</span></code>
|
| 712 |
+
patterns.</p>
|
| 713 |
+
<p>Text coloring is done in the background, so uncolorized text is occasionally
|
| 714 |
+
visible. To change the color scheme, use the Configure IDLE dialog
|
| 715 |
+
Highlighting tab. The marking of debugger breakpoint lines in the editor and
|
| 716 |
+
text in popups and dialogs is not user-configurable.</p>
|
| 717 |
+
</section>
|
| 718 |
+
</section>
|
| 719 |
+
<section id="startup-and-code-execution">
|
| 720 |
+
<h2>Startup and Code Execution<a class="headerlink" href="#startup-and-code-execution" title="Permalink to this heading">¶</a></h2>
|
| 721 |
+
<p>Upon startup with the <code class="docutils literal notranslate"><span class="pre">-s</span></code> option, IDLE will execute the file referenced by
|
| 722 |
+
the environment variables <span class="target" id="index-5"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> or <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>.
|
| 723 |
+
IDLE first checks for <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code>; if <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is present the file
|
| 724 |
+
referenced is run. If <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is not present, IDLE checks for
|
| 725 |
+
<code class="docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code>. Files referenced by these environment variables are
|
| 726 |
+
convenient places to store functions that are used frequently from the IDLE
|
| 727 |
+
shell, or for executing import statements to import common modules.</p>
|
| 728 |
+
<p>In addition, <code class="docutils literal notranslate"><span class="pre">Tk</span></code> also loads a startup file if it is present. Note that the
|
| 729 |
+
Tk file is loaded unconditionally. This additional file is <code class="docutils literal notranslate"><span class="pre">.Idle.py</span></code> and is
|
| 730 |
+
looked for in the user’s home directory. Statements in this file will be
|
| 731 |
+
executed in the Tk namespace, so this file is not useful for importing
|
| 732 |
+
functions to be used from IDLE’s Python shell.</p>
|
| 733 |
+
<section id="command-line-usage">
|
| 734 |
+
<h3>Command line usage<a class="headerlink" href="#command-line-usage" title="Permalink to this heading">¶</a></h3>
|
| 735 |
+
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
|
| 736 |
+
|
| 737 |
+
-c command run command in the shell window
|
| 738 |
+
-d enable debugger and open shell window
|
| 739 |
+
-e open editor window
|
| 740 |
+
-h print help message with legal combinations and exit
|
| 741 |
+
-i open shell window
|
| 742 |
+
-r file run file in shell window
|
| 743 |
+
-s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
|
| 744 |
+
-t title set title of shell window
|
| 745 |
+
- run stdin in shell (- must be last option before args)
|
| 746 |
+
</pre></div>
|
| 747 |
+
</div>
|
| 748 |
+
<p>If there are arguments:</p>
|
| 749 |
+
<ul class="simple">
|
| 750 |
+
<li><p>If <code class="docutils literal notranslate"><span class="pre">-</span></code>, <code class="docutils literal notranslate"><span class="pre">-c</span></code>, or <code class="docutils literal notranslate"><span class="pre">r</span></code> is used, all arguments are placed in
|
| 751 |
+
<code class="docutils literal notranslate"><span class="pre">sys.argv[1:...]</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> is set to <code class="docutils literal notranslate"><span class="pre">''</span></code>, <code class="docutils literal notranslate"><span class="pre">'-c'</span></code>,
|
| 752 |
+
or <code class="docutils literal notranslate"><span class="pre">'-r'</span></code>. No editor window is opened, even if that is the default
|
| 753 |
+
set in the Options dialog.</p></li>
|
| 754 |
+
<li><p>Otherwise, arguments are files opened for editing and
|
| 755 |
+
<code class="docutils literal notranslate"><span class="pre">sys.argv</span></code> reflects the arguments passed to IDLE itself.</p></li>
|
| 756 |
+
</ul>
|
| 757 |
+
</section>
|
| 758 |
+
<section id="startup-failure">
|
| 759 |
+
<h3>Startup failure<a class="headerlink" href="#startup-failure" title="Permalink to this heading">¶</a></h3>
|
| 760 |
+
<p>IDLE uses a socket to communicate between the IDLE GUI process and the user
|
| 761 |
+
code execution process. A connection must be established whenever the Shell
|
| 762 |
+
starts or restarts. (The latter is indicated by a divider line that says
|
| 763 |
+
‘RESTART’). If the user process fails to connect to the GUI process, it
|
| 764 |
+
usually displays a <code class="docutils literal notranslate"><span class="pre">Tk</span></code> error box with a ‘cannot connect’ message
|
| 765 |
+
that directs the user here. It then exits.</p>
|
| 766 |
+
<p>One specific connection failure on Unix systems results from
|
| 767 |
+
misconfigured masquerading rules somewhere in a system’s network setup.
|
| 768 |
+
When IDLE is started from a terminal, one will see a message starting
|
| 769 |
+
with <code class="docutils literal notranslate"><span class="pre">**</span> <span class="pre">Invalid</span> <span class="pre">host:</span></code>.
|
| 770 |
+
The valid value is <code class="docutils literal notranslate"><span class="pre">127.0.0.1</span> <span class="pre">(idlelib.rpc.LOCALHOST)</span></code>.
|
| 771 |
+
One can diagnose with <code class="docutils literal notranslate"><span class="pre">tcpconnect</span> <span class="pre">-irv</span> <span class="pre">127.0.0.1</span> <span class="pre">6543</span></code> in one
|
| 772 |
+
terminal window and <code class="docutils literal notranslate"><span class="pre">tcplisten</span> <span class="pre"><same</span> <span class="pre">args></span></code> in another.</p>
|
| 773 |
+
<p>A common cause of failure is a user-written file with the same name as a
|
| 774 |
+
standard library module, such as <em>random.py</em> and <em>tkinter.py</em>. When such a
|
| 775 |
+
file is located in the same directory as a file that is about to be run,
|
| 776 |
+
IDLE cannot import the stdlib file. The current fix is to rename the
|
| 777 |
+
user file.</p>
|
| 778 |
+
<p>Though less common than in the past, an antivirus or firewall program may
|
| 779 |
+
stop the connection. If the program cannot be taught to allow the
|
| 780 |
+
connection, then it must be turned off for IDLE to work. It is safe to
|
| 781 |
+
allow this internal connection because no data is visible on external
|
| 782 |
+
ports. A similar problem is a network mis-configuration that blocks
|
| 783 |
+
connections.</p>
|
| 784 |
+
<p>Python installation issues occasionally stop IDLE: multiple versions can
|
| 785 |
+
clash, or a single installation might need admin access. If one undo the
|
| 786 |
+
clash, or cannot or does not want to run as admin, it might be easiest to
|
| 787 |
+
completely remove Python and start over.</p>
|
| 788 |
+
<p>A zombie pythonw.exe process could be a problem. On Windows, use Task
|
| 789 |
+
Manager to check for one and stop it if there is. Sometimes a restart
|
| 790 |
+
initiated by a program crash or Keyboard Interrupt (control-C) may fail
|
| 791 |
+
to connect. Dismissing the error box or using Restart Shell on the Shell
|
| 792 |
+
menu may fix a temporary problem.</p>
|
| 793 |
+
<p>When IDLE first starts, it attempts to read user configuration files in
|
| 794 |
+
<code class="docutils literal notranslate"><span class="pre">~/.idlerc/</span></code> (~ is one’s home directory). If there is a problem, an error
|
| 795 |
+
message should be displayed. Leaving aside random disk glitches, this can
|
| 796 |
+
be prevented by never editing the files by hand. Instead, use the
|
| 797 |
+
configuration dialog, under Options. Once there is an error in a user
|
| 798 |
+
configuration file, the best solution may be to delete it and start over
|
| 799 |
+
with the settings dialog.</p>
|
| 800 |
+
<p>If IDLE quits with no message, and it was not started from a console, try
|
| 801 |
+
starting it from a console or terminal (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">idlelib</span></code>) and see if
|
| 802 |
+
this results in an error message.</p>
|
| 803 |
+
<p>On Unix-based systems with tcl/tk older than <code class="docutils literal notranslate"><span class="pre">8.6.11</span></code> (see
|
| 804 |
+
<code class="docutils literal notranslate"><span class="pre">About</span> <span class="pre">IDLE</span></code>) certain characters of certain fonts can cause
|
| 805 |
+
a tk failure with a message to the terminal. This can happen either
|
| 806 |
+
if one starts IDLE to edit a file with such a character or later
|
| 807 |
+
when entering such a character. If one cannot upgrade tcl/tk,
|
| 808 |
+
then re-configure IDLE to use a font that works better.</p>
|
| 809 |
+
</section>
|
| 810 |
+
<section id="running-user-code">
|
| 811 |
+
<h3>Running user code<a class="headerlink" href="#running-user-code" title="Permalink to this heading">¶</a></h3>
|
| 812 |
+
<p>With rare exceptions, the result of executing Python code with IDLE is
|
| 813 |
+
intended to be the same as executing the same code by the default method,
|
| 814 |
+
directly with Python in a text-mode system console or terminal window.
|
| 815 |
+
However, the different interface and operation occasionally affect
|
| 816 |
+
visible results. For instance, <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> starts with more entries,
|
| 817 |
+
and <code class="docutils literal notranslate"><span class="pre">threading.active_count()</span></code> returns 2 instead of 1.</p>
|
| 818 |
+
<p>By default, IDLE runs user code in a separate OS process rather than in
|
| 819 |
+
the user interface process that runs the shell and editor. In the execution
|
| 820 |
+
process, it replaces <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>
|
| 821 |
+
with objects that get input from and send output to the Shell window.
|
| 822 |
+
The original values stored in <code class="docutils literal notranslate"><span class="pre">sys.__stdin__</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.__stdout__</span></code>, and
|
| 823 |
+
<code class="docutils literal notranslate"><span class="pre">sys.__stderr__</span></code> are not touched, but may be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
|
| 824 |
+
<p>Sending print output from one process to a text widget in another is
|
| 825 |
+
slower than printing to a system terminal in the same process.
|
| 826 |
+
This has the most effect when printing multiple arguments, as the string
|
| 827 |
+
for each argument, each separator, the newline are sent separately.
|
| 828 |
+
For development, this is usually not a problem, but if one wants to
|
| 829 |
+
print faster in IDLE, format and join together everything one wants
|
| 830 |
+
displayed together and then print a single string. Both format strings
|
| 831 |
+
and <a class="reference internal" href="stdtypes.html#str.join" title="str.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.join()</span></code></a> can help combine fields and lines.</p>
|
| 832 |
+
<p>IDLE’s standard stream replacements are not inherited by subprocesses
|
| 833 |
+
created in the execution process, whether directly by user code or by
|
| 834 |
+
modules such as multiprocessing. If such subprocess use <code class="docutils literal notranslate"><span class="pre">input</span></code> from
|
| 835 |
+
sys.stdin or <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code> to sys.stdout or sys.stderr,
|
| 836 |
+
IDLE should be started in a command line window. (On Windows,
|
| 837 |
+
use <code class="docutils literal notranslate"><span class="pre">python</span></code> or <code class="docutils literal notranslate"><span class="pre">py</span></code> rather than <code class="docutils literal notranslate"><span class="pre">pythonw</span></code> or <code class="docutils literal notranslate"><span class="pre">pyw</span></code>.)
|
| 838 |
+
The secondary subprocess
|
| 839 |
+
will then be attached to that window for input and output.</p>
|
| 840 |
+
<p>If <code class="docutils literal notranslate"><span class="pre">sys</span></code> is reset by user code, such as with <code class="docutils literal notranslate"><span class="pre">importlib.reload(sys)</span></code>,
|
| 841 |
+
IDLE’s changes are lost and input from the keyboard and output to the screen
|
| 842 |
+
will not work correctly.</p>
|
| 843 |
+
<p>When Shell has the focus, it controls the keyboard and screen. This is
|
| 844 |
+
normally transparent, but functions that directly access the keyboard
|
| 845 |
+
and screen will not work. These include system-specific functions that
|
| 846 |
+
determine whether a key has been pressed and if so, which.</p>
|
| 847 |
+
<p>The IDLE code running in the execution process adds frames to the call stack
|
| 848 |
+
that would not be there otherwise. IDLE wraps <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit</span></code> and
|
| 849 |
+
<code class="docutils literal notranslate"><span class="pre">sys.setrecursionlimit</span></code> to reduce the effect of the additional stack
|
| 850 |
+
frames.</p>
|
| 851 |
+
<p>When user code raises SystemExit either directly or by calling sys.exit,
|
| 852 |
+
IDLE returns to a Shell prompt instead of exiting.</p>
|
| 853 |
+
</section>
|
| 854 |
+
<section id="user-output-in-shell">
|
| 855 |
+
<h3>User output in Shell<a class="headerlink" href="#user-output-in-shell" title="Permalink to this heading">¶</a></h3>
|
| 856 |
+
<p>When a program outputs text, the result is determined by the
|
| 857 |
+
corresponding output device. When IDLE executes user code, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>
|
| 858 |
+
and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> are connected to the display area of IDLE’s Shell. Some of
|
| 859 |
+
its features are inherited from the underlying Tk Text widget. Others
|
| 860 |
+
are programmed additions. Where it matters, Shell is designed for development
|
| 861 |
+
rather than production runs.</p>
|
| 862 |
+
<p>For instance, Shell never throws away output. A program that sends unlimited
|
| 863 |
+
output to Shell will eventually fill memory, resulting in a memory error.
|
| 864 |
+
In contrast, some system text windows only keep the last n lines of output.
|
| 865 |
+
A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
|
| 866 |
+
with 300 the default.</p>
|
| 867 |
+
<p>A Tk Text widget, and hence IDLE’s Shell, displays characters (codepoints) in
|
| 868 |
+
the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
|
| 869 |
+
displayed with a proper glyph and which with a replacement box depends on the
|
| 870 |
+
operating system and installed fonts. Tab characters cause the following text
|
| 871 |
+
to begin after the next tab stop. (They occur every 8 ‘characters’). Newline
|
| 872 |
+
characters cause following text to appear on a new line. Other control
|
| 873 |
+
characters are ignored or displayed as a space, box, or something else,
|
| 874 |
+
depending on the operating system and font. (Moving the text cursor through
|
| 875 |
+
such output with arrow keys may exhibit some surprising spacing behavior.)</p>
|
| 876 |
+
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="s1">'a</span><span class="se">\t</span><span class="s1">b</span><span class="se">\a</span><span class="s1"><</span><span class="se">\x02</span><span class="s1">><</span><span class="se">\r</span><span class="s1">></span><span class="se">\b</span><span class="s1">c</span><span class="se">\n</span><span class="s1">d'</span> <span class="c1"># Enter 22 chars.</span>
|
| 877 |
+
<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
|
| 878 |
+
<span class="go">14</span>
|
| 879 |
+
<span class="gp">>>> </span><span class="n">s</span> <span class="c1"># Display repr(s)</span>
|
| 880 |
+
<span class="go">'a\tb\x07<\x02><\r>\x08c\nd'</span>
|
| 881 |
+
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> <span class="c1"># Display s as is.</span>
|
| 882 |
+
<span class="go"># Result varies by OS and font. Try it.</span>
|
| 883 |
+
</pre></div>
|
| 884 |
+
</div>
|
| 885 |
+
<p>The <code class="docutils literal notranslate"><span class="pre">repr</span></code> function is used for interactive echo of expression
|
| 886 |
+
values. It returns an altered version of the input string in which
|
| 887 |
+
control codes, some BMP codepoints, and all non-BMP codepoints are
|
| 888 |
+
replaced with escape codes. As demonstrated above, it allows one to
|
| 889 |
+
identify the characters in a string, regardless of how they are displayed.</p>
|
| 890 |
+
<p>Normal and error output are generally kept separate (on separate lines)
|
| 891 |
+
from code input and each other. They each get different highlight colors.</p>
|
| 892 |
+
<p>For SyntaxError tracebacks, the normal ‘^’ marking where the error was
|
| 893 |
+
detected is replaced by coloring the text with an error highlight.
|
| 894 |
+
When code run from a file causes other exceptions, one may right click
|
| 895 |
+
on a traceback line to jump to the corresponding line in an IDLE editor.
|
| 896 |
+
The file will be opened if necessary.</p>
|
| 897 |
+
<p>Shell has a special facility for squeezing output lines down to a
|
| 898 |
+
‘Squeezed text’ label. This is done automatically
|
| 899 |
+
for output over N lines (N = 50 by default).
|
| 900 |
+
N can be changed in the PyShell section of the General
|
| 901 |
+
page of the Settings dialog. Output with fewer lines can be squeezed by
|
| 902 |
+
right clicking on the output. This can be useful lines long enough to slow
|
| 903 |
+
down scrolling.</p>
|
| 904 |
+
<p>Squeezed output is expanded in place by double-clicking the label.
|
| 905 |
+
It can also be sent to the clipboard or a separate view window by
|
| 906 |
+
right-clicking the label.</p>
|
| 907 |
+
</section>
|
| 908 |
+
<section id="developing-tkinter-applications">
|
| 909 |
+
<h3>Developing tkinter applications<a class="headerlink" href="#developing-tkinter-applications" title="Permalink to this heading">¶</a></h3>
|
| 910 |
+
<p>IDLE is intentionally different from standard Python in order to
|
| 911 |
+
facilitate development of tkinter programs. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">tkinter</span> <span class="pre">as</span> <span class="pre">tk;</span>
|
| 912 |
+
<span class="pre">root</span> <span class="pre">=</span> <span class="pre">tk.Tk()</span></code> in standard Python and nothing appears. Enter the same
|
| 913 |
+
in IDLE and a tk window appears. In standard Python, one must also enter
|
| 914 |
+
<code class="docutils literal notranslate"><span class="pre">root.update()</span></code> to see the window. IDLE does the equivalent in the
|
| 915 |
+
background, about 20 times a second, which is about every 50 milliseconds.
|
| 916 |
+
Next enter <code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">=</span> <span class="pre">tk.Button(root,</span> <span class="pre">text='button');</span> <span class="pre">b.pack()</span></code>. Again,
|
| 917 |
+
nothing visibly changes in standard Python until one enters <code class="docutils literal notranslate"><span class="pre">root.update()</span></code>.</p>
|
| 918 |
+
<p>Most tkinter programs run <code class="docutils literal notranslate"><span class="pre">root.mainloop()</span></code>, which usually does not
|
| 919 |
+
return until the tk app is destroyed. If the program is run with
|
| 920 |
+
<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span></code> or from an IDLE editor, a <code class="docutils literal notranslate"><span class="pre">>>></span></code> shell prompt does not
|
| 921 |
+
appear until <code class="docutils literal notranslate"><span class="pre">mainloop()</span></code> returns, at which time there is nothing left
|
| 922 |
+
to interact with.</p>
|
| 923 |
+
<p>When running a tkinter program from an IDLE editor, one can comment out
|
| 924 |
+
the mainloop call. One then gets a shell prompt immediately and can
|
| 925 |
+
interact with the live application. One just has to remember to
|
| 926 |
+
re-enable the mainloop call when running in standard Python.</p>
|
| 927 |
+
</section>
|
| 928 |
+
<section id="running-without-a-subprocess">
|
| 929 |
+
<h3>Running without a subprocess<a class="headerlink" href="#running-without-a-subprocess" title="Permalink to this heading">¶</a></h3>
|
| 930 |
+
<p>By default, IDLE executes user code in a separate subprocess via a socket,
|
| 931 |
+
which uses the internal loopback interface. This connection is not
|
| 932 |
+
externally visible and no data is sent to or received from the internet.
|
| 933 |
+
If firewall software complains anyway, you can ignore it.</p>
|
| 934 |
+
<p>If the attempt to make the socket connection fails, Idle will notify you.
|
| 935 |
+
Such failures are sometimes transient, but if persistent, the problem
|
| 936 |
+
may be either a firewall blocking the connection or misconfiguration of
|
| 937 |
+
a particular system. Until the problem is fixed, one can run Idle with
|
| 938 |
+
the -n command line switch.</p>
|
| 939 |
+
<p>If IDLE is started with the -n command line switch it will run in a
|
| 940 |
+
single process and will not create the subprocess which runs the RPC
|
| 941 |
+
Python execution server. This can be useful if Python cannot create
|
| 942 |
+
the subprocess or the RPC socket interface on your platform. However,
|
| 943 |
+
in this mode user code is not isolated from IDLE itself. Also, the
|
| 944 |
+
environment is not restarted when Run/Run Module (F5) is selected. If
|
| 945 |
+
your code has been modified, you must reload() the affected modules and
|
| 946 |
+
re-import any specific items (e.g. from foo import baz) if the changes
|
| 947 |
+
are to take effect. For these reasons, it is preferable to run IDLE
|
| 948 |
+
with the default subprocess if at all possible.</p>
|
| 949 |
+
<div class="deprecated">
|
| 950 |
+
<p><span class="versionmodified deprecated">Deprecated since version 3.4.</span></p>
|
| 951 |
+
</div>
|
| 952 |
+
</section>
|
| 953 |
+
</section>
|
| 954 |
+
<section id="help-and-preferences">
|
| 955 |
+
<h2>Help and Preferences<a class="headerlink" href="#help-and-preferences" title="Permalink to this heading">¶</a></h2>
|
| 956 |
+
<section id="help-sources">
|
| 957 |
+
<span id="id6"></span><h3>Help sources<a class="headerlink" href="#help-sources" title="Permalink to this heading">¶</a></h3>
|
| 958 |
+
<p>Help menu entry “IDLE Help” displays a formatted html version of the
|
| 959 |
+
IDLE chapter of the Library Reference. The result, in a read-only
|
| 960 |
+
tkinter text window, is close to what one sees in a web browser.
|
| 961 |
+
Navigate through the text with a mousewheel,
|
| 962 |
+
the scrollbar, or up and down arrow keys held down.
|
| 963 |
+
Or click the TOC (Table of Contents) button and select a section
|
| 964 |
+
header in the opened box.</p>
|
| 965 |
+
<p>Help menu entry “Python Docs” opens the extensive sources of help,
|
| 966 |
+
including tutorials, available at <code class="docutils literal notranslate"><span class="pre">docs.python.org/x.y</span></code>, where ‘x.y’
|
| 967 |
+
is the currently running Python version. If your system
|
| 968 |
+
has an off-line copy of the docs (this may be an installation option),
|
| 969 |
+
that will be opened instead.</p>
|
| 970 |
+
<p>Selected URLs can be added or removed from the help menu at any time using the
|
| 971 |
+
General tab of the Configure IDLE dialog.</p>
|
| 972 |
+
</section>
|
| 973 |
+
<section id="setting-preferences">
|
| 974 |
+
<span id="preferences"></span><h3>Setting preferences<a class="headerlink" href="#setting-preferences" title="Permalink to this heading">¶</a></h3>
|
| 975 |
+
<p>The font preferences, highlighting, keys, and general preferences can be
|
| 976 |
+
changed via Configure IDLE on the Option menu.
|
| 977 |
+
Non-default user settings are saved in a <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code> directory in the user’s
|
| 978 |
+
home directory. Problems caused by bad user configuration files are solved
|
| 979 |
+
by editing or deleting one or more of the files in <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>.</p>
|
| 980 |
+
<p>On the Font tab, see the text sample for the effect of font face and size
|
| 981 |
+
on multiple characters in multiple languages. Edit the sample to add
|
| 982 |
+
other characters of personal interest. Use the sample to select
|
| 983 |
+
monospaced fonts. If particular characters have problems in Shell or an
|
| 984 |
+
editor, add them to the top of the sample and try changing first size
|
| 985 |
+
and then font.</p>
|
| 986 |
+
<p>On the Highlights and Keys tab, select a built-in or custom color theme
|
| 987 |
+
and key set. To use a newer built-in color theme or key set with older
|
| 988 |
+
IDLEs, save it as a new custom theme or key set and it well be accessible
|
| 989 |
+
to older IDLEs.</p>
|
| 990 |
+
</section>
|
| 991 |
+
<section id="idle-on-macos">
|
| 992 |
+
<h3>IDLE on macOS<a class="headerlink" href="#idle-on-macos" title="Permalink to this heading">¶</a></h3>
|
| 993 |
+
<p>Under System Preferences: Dock, one can set “Prefer tabs when opening
|
| 994 |
+
documents” to “Always”. This setting is not compatible with the tk/tkinter
|
| 995 |
+
GUI framework used by IDLE, and it breaks a few IDLE features.</p>
|
| 996 |
+
</section>
|
| 997 |
+
<section id="extensions">
|
| 998 |
+
<h3>Extensions<a class="headerlink" href="#extensions" title="Permalink to this heading">¶</a></h3>
|
| 999 |
+
<p>IDLE contains an extension facility. Preferences for extensions can be
|
| 1000 |
+
changed with the Extensions tab of the preferences dialog. See the
|
| 1001 |
+
beginning of config-extensions.def in the idlelib directory for further
|
| 1002 |
+
information. The only current default extension is zzdummy, an example
|
| 1003 |
+
also used for testing.</p>
|
| 1004 |
+
</section>
|
| 1005 |
+
</section>
|
| 1006 |
+
<section id="module-idlelib">
|
| 1007 |
+
<span id="idlelib"></span><h2>idlelib<a class="headerlink" href="#module-idlelib" title="Permalink to this heading">¶</a></h2>
|
| 1008 |
+
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib">Lib/idlelib</a></p>
|
| 1009 |
+
<hr class="docutils" />
|
| 1010 |
+
<p>The Lib/idlelib package implements the IDLE application. See the rest
|
| 1011 |
+
of this page for how to use IDLE.</p>
|
| 1012 |
+
<p>The files in idlelib are described in idlelib/README.txt. Access it
|
| 1013 |
+
either in idlelib or click Help => About IDLE on the IDLE menu. This
|
| 1014 |
+
file also maps IDLE menu items to the code that implements the item.
|
| 1015 |
+
Except for files listed under ‘Startup’, the idlelib code is ‘private’ in
|
| 1016 |
+
sense that feature changes can be backported (see <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0434/"><strong>PEP 434</strong></a>).</p>
|
| 1017 |
+
</section>
|
| 1018 |
+
</section>
|
| 1019 |
+
|
| 1020 |
+
|
| 1021 |
+
<div class="clearer"></div>
|
| 1022 |
+
</div>
|
| 1023 |
+
</div>
|
| 1024 |
+
</div>
|
| 1025 |
+
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
| 1026 |
+
<div class="sphinxsidebarwrapper">
|
| 1027 |
+
<div>
|
| 1028 |
+
<h3><a href="../contents.html">Table of Contents</a></h3>
|
| 1029 |
+
<ul>
|
| 1030 |
+
<li><a class="reference internal" href="#">IDLE</a><ul>
|
| 1031 |
+
<li><a class="reference internal" href="#menus">Menus</a><ul>
|
| 1032 |
+
<li><a class="reference internal" href="#file-menu-shell-and-editor">File menu (Shell and Editor)</a></li>
|
| 1033 |
+
<li><a class="reference internal" href="#edit-menu-shell-and-editor">Edit menu (Shell and Editor)</a></li>
|
| 1034 |
+
<li><a class="reference internal" href="#format-menu-editor-window-only">Format menu (Editor window only)</a></li>
|
| 1035 |
+
<li><a class="reference internal" href="#run-menu-editor-window-only">Run menu (Editor window only)</a></li>
|
| 1036 |
+
<li><a class="reference internal" href="#shell-menu-shell-window-only">Shell menu (Shell window only)</a></li>
|
| 1037 |
+
<li><a class="reference internal" href="#debug-menu-shell-window-only">Debug menu (Shell window only)</a></li>
|
| 1038 |
+
<li><a class="reference internal" href="#options-menu-shell-and-editor">Options menu (Shell and Editor)</a></li>
|
| 1039 |
+
<li><a class="reference internal" href="#window-menu-shell-and-editor">Window menu (Shell and Editor)</a></li>
|
| 1040 |
+
<li><a class="reference internal" href="#help-menu-shell-and-editor">Help menu (Shell and Editor)</a></li>
|
| 1041 |
+
<li><a class="reference internal" href="#context-menus">Context menus</a></li>
|
| 1042 |
+
</ul>
|
| 1043 |
+
</li>
|
| 1044 |
+
<li><a class="reference internal" href="#editing-and-navigation">Editing and Navigation</a><ul>
|
| 1045 |
+
<li><a class="reference internal" href="#editor-windows">Editor windows</a></li>
|
| 1046 |
+
<li><a class="reference internal" href="#key-bindings">Key bindings</a></li>
|
| 1047 |
+
<li><a class="reference internal" href="#automatic-indentation">Automatic indentation</a></li>
|
| 1048 |
+
<li><a class="reference internal" href="#search-and-replace">Search and Replace</a></li>
|
| 1049 |
+
<li><a class="reference internal" href="#completions">Completions</a></li>
|
| 1050 |
+
<li><a class="reference internal" href="#calltips">Calltips</a></li>
|
| 1051 |
+
<li><a class="reference internal" href="#code-context">Code Context</a></li>
|
| 1052 |
+
<li><a class="reference internal" href="#shell-window">Shell window</a></li>
|
| 1053 |
+
<li><a class="reference internal" href="#text-colors">Text colors</a></li>
|
| 1054 |
+
</ul>
|
| 1055 |
+
</li>
|
| 1056 |
+
<li><a class="reference internal" href="#startup-and-code-execution">Startup and Code Execution</a><ul>
|
| 1057 |
+
<li><a class="reference internal" href="#command-line-usage">Command line usage</a></li>
|
| 1058 |
+
<li><a class="reference internal" href="#startup-failure">Startup failure</a></li>
|
| 1059 |
+
<li><a class="reference internal" href="#running-user-code">Running user code</a></li>
|
| 1060 |
+
<li><a class="reference internal" href="#user-output-in-shell">User output in Shell</a></li>
|
| 1061 |
+
<li><a class="reference internal" href="#developing-tkinter-applications">Developing tkinter applications</a></li>
|
| 1062 |
+
<li><a class="reference internal" href="#running-without-a-subprocess">Running without a subprocess</a></li>
|
| 1063 |
+
</ul>
|
| 1064 |
+
</li>
|
| 1065 |
+
<li><a class="reference internal" href="#help-and-preferences">Help and Preferences</a><ul>
|
| 1066 |
+
<li><a class="reference internal" href="#help-sources">Help sources</a></li>
|
| 1067 |
+
<li><a class="reference internal" href="#setting-preferences">Setting preferences</a></li>
|
| 1068 |
+
<li><a class="reference internal" href="#idle-on-macos">IDLE on macOS</a></li>
|
| 1069 |
+
<li><a class="reference internal" href="#extensions">Extensions</a></li>
|
| 1070 |
+
</ul>
|
| 1071 |
+
</li>
|
| 1072 |
+
<li><a class="reference internal" href="#module-idlelib">idlelib</a></li>
|
| 1073 |
+
</ul>
|
| 1074 |
+
</li>
|
| 1075 |
+
</ul>
|
| 1076 |
+
|
| 1077 |
+
</div>
|
| 1078 |
+
<div>
|
| 1079 |
+
<h4>Previous topic</h4>
|
| 1080 |
+
<p class="topless"><a href="tkinter.tix.html"
|
| 1081 |
+
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code> — Extension widgets for Tk</a></p>
|
| 1082 |
+
</div>
|
| 1083 |
+
<div>
|
| 1084 |
+
<h4>Next topic</h4>
|
| 1085 |
+
<p class="topless"><a href="development.html"
|
| 1086 |
+
title="next chapter">Development Tools</a></p>
|
| 1087 |
+
</div>
|
| 1088 |
+
<div role="note" aria-label="source link">
|
| 1089 |
+
<h3>This Page</h3>
|
| 1090 |
+
<ul class="this-page-menu">
|
| 1091 |
+
<li><a href="../bugs.html">Report a Bug</a></li>
|
| 1092 |
+
<li>
|
| 1093 |
+
<a href="https://github.com/python/cpython/blob/main/Doc/library/idle.rst"
|
| 1094 |
+
rel="nofollow">Show Source
|
| 1095 |
+
</a>
|
| 1096 |
+
</li>
|
| 1097 |
+
</ul>
|
| 1098 |
+
</div>
|
| 1099 |
+
</div>
|
| 1100 |
+
<div id="sidebarbutton" title="Collapse sidebar">
|
| 1101 |
+
<span>«</span>
|
| 1102 |
+
</div>
|
| 1103 |
+
|
| 1104 |
+
</div>
|
| 1105 |
+
<div class="clearer"></div>
|
| 1106 |
+
</div>
|
| 1107 |
+
<div class="related" role="navigation" aria-label="related navigation">
|
| 1108 |
+
<h3>Navigation</h3>
|
| 1109 |
+
<ul>
|
| 1110 |
+
<li class="right" style="margin-right: 10px">
|
| 1111 |
+
<a href="../genindex.html" title="General Index"
|
| 1112 |
+
>index</a></li>
|
| 1113 |
+
<li class="right" >
|
| 1114 |
+
<a href="../py-modindex.html" title="Python Module Index"
|
| 1115 |
+
>modules</a> |</li>
|
| 1116 |
+
<li class="right" >
|
| 1117 |
+
<a href="development.html" title="Development Tools"
|
| 1118 |
+
>next</a> |</li>
|
| 1119 |
+
<li class="right" >
|
| 1120 |
+
<a href="tkinter.tix.html" title="tkinter.tix — Extension widgets for Tk"
|
| 1121 |
+
>previous</a> |</li>
|
| 1122 |
+
|
| 1123 |
+
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
| 1124 |
+
<li><a href="https://www.python.org/">Python</a> »</li>
|
| 1125 |
+
<li class="switchers">
|
| 1126 |
+
<div class="language_switcher_placeholder"></div>
|
| 1127 |
+
<div class="version_switcher_placeholder"></div>
|
| 1128 |
+
</li>
|
| 1129 |
+
<li>
|
| 1130 |
+
|
| 1131 |
+
</li>
|
| 1132 |
+
<li id="cpython-language-and-version">
|
| 1133 |
+
<a href="../index.html">3.12.0a0 Documentation</a> »
|
| 1134 |
+
</li>
|
| 1135 |
+
|
| 1136 |
+
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
| 1137 |
+
<li class="nav-item nav-item-2"><a href="tk.html" >Graphical User Interfaces with Tk</a> »</li>
|
| 1138 |
+
<li class="nav-item nav-item-this"><a href="">IDLE</a></li>
|
| 1139 |
+
<li class="right">
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
<div class="inline-search" role="search">
|
| 1143 |
+
<form class="inline-search" action="../search.html" method="get">
|
| 1144 |
+
<input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
|
| 1145 |
+
<input type="submit" value="Go" />
|
| 1146 |
+
<input type="hidden" name="check_keywords" value="yes" />
|
| 1147 |
+
<input type="hidden" name="area" value="default" />
|
| 1148 |
+
</form>
|
| 1149 |
+
</div>
|
| 1150 |
+
|
|
| 1151 |
+
</li>
|
| 1152 |
+
|
| 1153 |
+
</ul>
|
| 1154 |
+
</div>
|
| 1155 |
+
<div class="footer">
|
| 1156 |
+
© <a href="../copyright.html">Copyright</a> 2001-2022, Python Software Foundation.
|
| 1157 |
+
<br />
|
| 1158 |
+
This page is licensed under the Python Software Foundation License Version 2.
|
| 1159 |
+
<br />
|
| 1160 |
+
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
| 1161 |
+
<br />
|
| 1162 |
+
See <a href="/license.html">History and License</a> for more information.<br />
|
| 1163 |
+
<br />
|
| 1164 |
+
|
| 1165 |
+
The Python Software Foundation is a non-profit corporation.
|
| 1166 |
+
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
| 1167 |
+
<br />
|
| 1168 |
+
<br />
|
| 1169 |
+
|
| 1170 |
+
Last updated on Sep 03, 2022.
|
| 1171 |
+
<a href="/bugs.html">Found a bug</a>?
|
| 1172 |
+
<br />
|
| 1173 |
+
|
| 1174 |
+
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.0.2.
|
| 1175 |
+
</div>
|
| 1176 |
+
|
| 1177 |
+
</body>
|
| 1178 |
+
</html>
|
deepseek/lib/python3.10/idlelib/help.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" help.py: Implement the Idle help menu.
|
| 2 |
+
Contents are subject to revision at any time, without notice.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
Help => About IDLE: display About Idle dialog
|
| 6 |
+
|
| 7 |
+
<to be moved here from help_about.py>
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Help => IDLE Help: Display help.html with proper formatting.
|
| 11 |
+
Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html
|
| 12 |
+
(help.copy_strip)=> Lib/idlelib/help.html
|
| 13 |
+
|
| 14 |
+
HelpParser - Parse help.html and render to tk Text.
|
| 15 |
+
|
| 16 |
+
HelpText - Display formatted help.html.
|
| 17 |
+
|
| 18 |
+
HelpFrame - Contain text, scrollbar, and table-of-contents.
|
| 19 |
+
(This will be needed for display in a future tabbed window.)
|
| 20 |
+
|
| 21 |
+
HelpWindow - Display HelpFrame in a standalone window.
|
| 22 |
+
|
| 23 |
+
copy_strip - Copy idle.html to help.html, rstripping each line.
|
| 24 |
+
|
| 25 |
+
show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
|
| 26 |
+
"""
|
| 27 |
+
from html.parser import HTMLParser
|
| 28 |
+
from os.path import abspath, dirname, isfile, join
|
| 29 |
+
from platform import python_version
|
| 30 |
+
|
| 31 |
+
from tkinter import Toplevel, Text, Menu
|
| 32 |
+
from tkinter.ttk import Frame, Menubutton, Scrollbar, Style
|
| 33 |
+
from tkinter import font as tkfont
|
| 34 |
+
|
| 35 |
+
from idlelib.config import idleConf
|
| 36 |
+
|
| 37 |
+
## About IDLE ##
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## IDLE Help ##
|
| 41 |
+
|
| 42 |
+
class HelpParser(HTMLParser):
|
| 43 |
+
"""Render help.html into a text widget.
|
| 44 |
+
|
| 45 |
+
The overridden handle_xyz methods handle a subset of html tags.
|
| 46 |
+
The supplied text should have the needed tag configurations.
|
| 47 |
+
The behavior for unsupported tags, such as table, is undefined.
|
| 48 |
+
If the tags generated by Sphinx change, this class, especially
|
| 49 |
+
the handle_starttag and handle_endtags methods, might have to also.
|
| 50 |
+
"""
|
| 51 |
+
def __init__(self, text):
|
| 52 |
+
HTMLParser.__init__(self, convert_charrefs=True)
|
| 53 |
+
self.text = text # Text widget we're rendering into.
|
| 54 |
+
self.tags = '' # Current block level text tags to apply.
|
| 55 |
+
self.chartags = '' # Current character level text tags.
|
| 56 |
+
self.show = False # Exclude html page navigation.
|
| 57 |
+
self.hdrlink = False # Exclude html header links.
|
| 58 |
+
self.level = 0 # Track indentation level.
|
| 59 |
+
self.pre = False # Displaying preformatted text?
|
| 60 |
+
self.hprefix = '' # Heading prefix (like '25.5'?) to remove.
|
| 61 |
+
self.nested_dl = False # In a nested <dl>?
|
| 62 |
+
self.simplelist = False # In a simple list (no double spacing)?
|
| 63 |
+
self.toc = [] # Pair headers with text indexes for toc.
|
| 64 |
+
self.header = '' # Text within header tags for toc.
|
| 65 |
+
self.prevtag = None # Previous tag info (opener?, tag).
|
| 66 |
+
|
| 67 |
+
def indent(self, amt=1):
|
| 68 |
+
"Change indent (+1, 0, -1) and tags."
|
| 69 |
+
self.level += amt
|
| 70 |
+
self.tags = '' if self.level == 0 else 'l'+str(self.level)
|
| 71 |
+
|
| 72 |
+
def handle_starttag(self, tag, attrs):
|
| 73 |
+
"Handle starttags in help.html."
|
| 74 |
+
class_ = ''
|
| 75 |
+
for a, v in attrs:
|
| 76 |
+
if a == 'class':
|
| 77 |
+
class_ = v
|
| 78 |
+
s = ''
|
| 79 |
+
if tag == 'section' and attrs == [('id', 'idle')]:
|
| 80 |
+
self.show = True # Start main content.
|
| 81 |
+
elif tag == 'div' and class_ == 'clearer':
|
| 82 |
+
self.show = False # End main content.
|
| 83 |
+
elif tag == 'p' and self.prevtag and not self.prevtag[0]:
|
| 84 |
+
# Begin a new block for <p> tags after a closed tag.
|
| 85 |
+
# Avoid extra lines, e.g. after <pre> tags.
|
| 86 |
+
lastline = self.text.get('end-1c linestart', 'end-1c')
|
| 87 |
+
s = '\n\n' if lastline and not lastline.isspace() else '\n'
|
| 88 |
+
elif tag == 'span' and class_ == 'pre':
|
| 89 |
+
self.chartags = 'pre'
|
| 90 |
+
elif tag == 'span' and class_ == 'versionmodified':
|
| 91 |
+
self.chartags = 'em'
|
| 92 |
+
elif tag == 'em':
|
| 93 |
+
self.chartags = 'em'
|
| 94 |
+
elif tag in ['ul', 'ol']:
|
| 95 |
+
if class_.find('simple') != -1:
|
| 96 |
+
s = '\n'
|
| 97 |
+
self.simplelist = True
|
| 98 |
+
else:
|
| 99 |
+
self.simplelist = False
|
| 100 |
+
self.indent()
|
| 101 |
+
elif tag == 'dl':
|
| 102 |
+
if self.level > 0:
|
| 103 |
+
self.nested_dl = True
|
| 104 |
+
elif tag == 'li':
|
| 105 |
+
s = '\n* ' if self.simplelist else '\n\n* '
|
| 106 |
+
elif tag == 'dt':
|
| 107 |
+
s = '\n\n' if not self.nested_dl else '\n' # Avoid extra line.
|
| 108 |
+
self.nested_dl = False
|
| 109 |
+
elif tag == 'dd':
|
| 110 |
+
self.indent()
|
| 111 |
+
s = '\n'
|
| 112 |
+
elif tag == 'pre':
|
| 113 |
+
self.pre = True
|
| 114 |
+
if self.show:
|
| 115 |
+
self.text.insert('end', '\n\n')
|
| 116 |
+
self.tags = 'preblock'
|
| 117 |
+
elif tag == 'a' and class_ == 'headerlink':
|
| 118 |
+
self.hdrlink = True
|
| 119 |
+
elif tag == 'h1':
|
| 120 |
+
self.tags = tag
|
| 121 |
+
elif tag in ['h2', 'h3']:
|
| 122 |
+
if self.show:
|
| 123 |
+
self.header = ''
|
| 124 |
+
self.text.insert('end', '\n\n')
|
| 125 |
+
self.tags = tag
|
| 126 |
+
if self.show:
|
| 127 |
+
self.text.insert('end', s, (self.tags, self.chartags))
|
| 128 |
+
self.prevtag = (True, tag)
|
| 129 |
+
|
| 130 |
+
def handle_endtag(self, tag):
|
| 131 |
+
"Handle endtags in help.html."
|
| 132 |
+
if tag in ['h1', 'h2', 'h3']:
|
| 133 |
+
assert self.level == 0
|
| 134 |
+
if self.show:
|
| 135 |
+
indent = (' ' if tag == 'h3' else
|
| 136 |
+
' ' if tag == 'h2' else
|
| 137 |
+
'')
|
| 138 |
+
self.toc.append((indent+self.header, self.text.index('insert')))
|
| 139 |
+
self.tags = ''
|
| 140 |
+
elif tag in ['span', 'em']:
|
| 141 |
+
self.chartags = ''
|
| 142 |
+
elif tag == 'a':
|
| 143 |
+
self.hdrlink = False
|
| 144 |
+
elif tag == 'pre':
|
| 145 |
+
self.pre = False
|
| 146 |
+
self.tags = ''
|
| 147 |
+
elif tag in ['ul', 'dd', 'ol']:
|
| 148 |
+
self.indent(-1)
|
| 149 |
+
self.prevtag = (False, tag)
|
| 150 |
+
|
| 151 |
+
def handle_data(self, data):
|
| 152 |
+
"Handle date segments in help.html."
|
| 153 |
+
if self.show and not self.hdrlink:
|
| 154 |
+
d = data if self.pre else data.replace('\n', ' ')
|
| 155 |
+
if self.tags == 'h1':
|
| 156 |
+
try:
|
| 157 |
+
self.hprefix = d[0:d.index(' ')]
|
| 158 |
+
except ValueError:
|
| 159 |
+
self.hprefix = ''
|
| 160 |
+
if self.tags in ['h1', 'h2', 'h3']:
|
| 161 |
+
if (self.hprefix != '' and
|
| 162 |
+
d[0:len(self.hprefix)] == self.hprefix):
|
| 163 |
+
d = d[len(self.hprefix):]
|
| 164 |
+
self.header += d.strip()
|
| 165 |
+
self.text.insert('end', d, (self.tags, self.chartags))
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class HelpText(Text):
|
| 169 |
+
"Display help.html."
|
| 170 |
+
def __init__(self, parent, filename):
|
| 171 |
+
"Configure tags and feed file to parser."
|
| 172 |
+
uwide = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 173 |
+
uhigh = idleConf.GetOption('main', 'EditorWindow', 'height', type='int')
|
| 174 |
+
uhigh = 3 * uhigh // 4 # Lines average 4/3 of editor line height.
|
| 175 |
+
Text.__init__(self, parent, wrap='word', highlightthickness=0,
|
| 176 |
+
padx=5, borderwidth=0, width=uwide, height=uhigh)
|
| 177 |
+
|
| 178 |
+
normalfont = self.findfont(['TkDefaultFont', 'arial', 'helvetica'])
|
| 179 |
+
fixedfont = self.findfont(['TkFixedFont', 'monaco', 'courier'])
|
| 180 |
+
self['font'] = (normalfont, 12)
|
| 181 |
+
self.tag_configure('em', font=(normalfont, 12, 'italic'))
|
| 182 |
+
self.tag_configure('h1', font=(normalfont, 20, 'bold'))
|
| 183 |
+
self.tag_configure('h2', font=(normalfont, 18, 'bold'))
|
| 184 |
+
self.tag_configure('h3', font=(normalfont, 15, 'bold'))
|
| 185 |
+
self.tag_configure('pre', font=(fixedfont, 12), background='#f6f6ff')
|
| 186 |
+
self.tag_configure('preblock', font=(fixedfont, 10), lmargin1=25,
|
| 187 |
+
borderwidth=1, relief='solid', background='#eeffcc')
|
| 188 |
+
self.tag_configure('l1', lmargin1=25, lmargin2=25)
|
| 189 |
+
self.tag_configure('l2', lmargin1=50, lmargin2=50)
|
| 190 |
+
self.tag_configure('l3', lmargin1=75, lmargin2=75)
|
| 191 |
+
self.tag_configure('l4', lmargin1=100, lmargin2=100)
|
| 192 |
+
|
| 193 |
+
self.parser = HelpParser(self)
|
| 194 |
+
with open(filename, encoding='utf-8') as f:
|
| 195 |
+
contents = f.read()
|
| 196 |
+
self.parser.feed(contents)
|
| 197 |
+
self['state'] = 'disabled'
|
| 198 |
+
|
| 199 |
+
def findfont(self, names):
|
| 200 |
+
"Return name of first font family derived from names."
|
| 201 |
+
for name in names:
|
| 202 |
+
if name.lower() in (x.lower() for x in tkfont.names(root=self)):
|
| 203 |
+
font = tkfont.Font(name=name, exists=True, root=self)
|
| 204 |
+
return font.actual()['family']
|
| 205 |
+
elif name.lower() in (x.lower()
|
| 206 |
+
for x in tkfont.families(root=self)):
|
| 207 |
+
return name
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
class HelpFrame(Frame):
|
| 211 |
+
"Display html text, scrollbar, and toc."
|
| 212 |
+
def __init__(self, parent, filename):
|
| 213 |
+
Frame.__init__(self, parent)
|
| 214 |
+
self.text = text = HelpText(self, filename)
|
| 215 |
+
self.style = Style(parent)
|
| 216 |
+
self['style'] = 'helpframe.TFrame'
|
| 217 |
+
self.style.configure('helpframe.TFrame', background=text['background'])
|
| 218 |
+
self.toc = toc = self.toc_menu(text)
|
| 219 |
+
self.scroll = scroll = Scrollbar(self, command=text.yview)
|
| 220 |
+
text['yscrollcommand'] = scroll.set
|
| 221 |
+
|
| 222 |
+
self.rowconfigure(0, weight=1)
|
| 223 |
+
self.columnconfigure(1, weight=1) # Only expand the text widget.
|
| 224 |
+
toc.grid(row=0, column=0, sticky='nw')
|
| 225 |
+
text.grid(row=0, column=1, sticky='nsew')
|
| 226 |
+
scroll.grid(row=0, column=2, sticky='ns')
|
| 227 |
+
|
| 228 |
+
def toc_menu(self, text):
|
| 229 |
+
"Create table of contents as drop-down menu."
|
| 230 |
+
toc = Menubutton(self, text='TOC')
|
| 231 |
+
drop = Menu(toc, tearoff=False)
|
| 232 |
+
for lbl, dex in text.parser.toc:
|
| 233 |
+
drop.add_command(label=lbl, command=lambda dex=dex:text.yview(dex))
|
| 234 |
+
toc['menu'] = drop
|
| 235 |
+
return toc
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
class HelpWindow(Toplevel):
|
| 239 |
+
"Display frame with rendered html."
|
| 240 |
+
def __init__(self, parent, filename, title):
|
| 241 |
+
Toplevel.__init__(self, parent)
|
| 242 |
+
self.wm_title(title)
|
| 243 |
+
self.protocol("WM_DELETE_WINDOW", self.destroy)
|
| 244 |
+
HelpFrame(self, filename).grid(column=0, row=0, sticky='nsew')
|
| 245 |
+
self.grid_columnconfigure(0, weight=1)
|
| 246 |
+
self.grid_rowconfigure(0, weight=1)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def copy_strip():
|
| 250 |
+
"""Copy idle.html to idlelib/help.html, stripping trailing whitespace.
|
| 251 |
+
|
| 252 |
+
Files with trailing whitespace cannot be pushed to the git cpython
|
| 253 |
+
repository. For 3.x (on Windows), help.html is generated, after
|
| 254 |
+
editing idle.rst on the master branch, with
|
| 255 |
+
sphinx-build -bhtml . build/html
|
| 256 |
+
python_d.exe -c "from idlelib.help import copy_strip; copy_strip()"
|
| 257 |
+
Check build/html/library/idle.html, the help.html diff, and the text
|
| 258 |
+
displayed by Help => IDLE Help. Add a blurb and create a PR.
|
| 259 |
+
|
| 260 |
+
It can be worthwhile to occasionally generate help.html without
|
| 261 |
+
touching idle.rst. Changes to the master version and to the doc
|
| 262 |
+
build system may result in changes that should not changed
|
| 263 |
+
the displayed text, but might break HelpParser.
|
| 264 |
+
|
| 265 |
+
As long as master and maintenance versions of idle.rst remain the
|
| 266 |
+
same, help.html can be backported. The internal Python version
|
| 267 |
+
number is not displayed. If maintenance idle.rst diverges from
|
| 268 |
+
the master version, then instead of backporting help.html from
|
| 269 |
+
master, repeat the procedure above to generate a maintenance
|
| 270 |
+
version.
|
| 271 |
+
"""
|
| 272 |
+
src = join(abspath(dirname(dirname(dirname(__file__)))),
|
| 273 |
+
'Doc', 'build', 'html', 'library', 'idle.html')
|
| 274 |
+
dst = join(abspath(dirname(__file__)), 'help.html')
|
| 275 |
+
with open(src, 'rb') as inn,\
|
| 276 |
+
open(dst, 'wb') as out:
|
| 277 |
+
for line in inn:
|
| 278 |
+
out.write(line.rstrip() + b'\n')
|
| 279 |
+
print(f'{src} copied to {dst}')
|
| 280 |
+
|
| 281 |
+
def show_idlehelp(parent):
|
| 282 |
+
"Create HelpWindow; called from Idle Help event handler."
|
| 283 |
+
filename = join(abspath(dirname(__file__)), 'help.html')
|
| 284 |
+
if not isfile(filename):
|
| 285 |
+
# Try copy_strip, present message.
|
| 286 |
+
return
|
| 287 |
+
HelpWindow(parent, filename, 'IDLE Help (%s)' % python_version())
|
| 288 |
+
|
| 289 |
+
if __name__ == '__main__':
|
| 290 |
+
from unittest import main
|
| 291 |
+
main('idlelib.idle_test.test_help', verbosity=2, exit=False)
|
| 292 |
+
|
| 293 |
+
from idlelib.idle_test.htest import run
|
| 294 |
+
run(show_idlehelp)
|
deepseek/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)
|
deepseek/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)
|
deepseek/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
|
deepseek/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()
|
deepseek/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)
|
deepseek/lib/python3.10/idlelib/multicall.py
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MultiCall - a class which inherits its methods from a Tkinter widget (Text, for
|
| 3 |
+
example), but enables multiple calls of functions per virtual event - all
|
| 4 |
+
matching events will be called, not only the most specific one. This is done
|
| 5 |
+
by wrapping the event functions - event_add, event_delete and event_info.
|
| 6 |
+
MultiCall recognizes only a subset of legal event sequences. Sequences which
|
| 7 |
+
are not recognized are treated by the original Tk handling mechanism. A
|
| 8 |
+
more-specific event will be called before a less-specific event.
|
| 9 |
+
|
| 10 |
+
The recognized sequences are complete one-event sequences (no emacs-style
|
| 11 |
+
Ctrl-X Ctrl-C, no shortcuts like <3>), for all types of events.
|
| 12 |
+
Key/Button Press/Release events can have modifiers.
|
| 13 |
+
The recognized modifiers are Shift, Control, Option and Command for Mac, and
|
| 14 |
+
Control, Alt, Shift, Meta/M for other platforms.
|
| 15 |
+
|
| 16 |
+
For all events which were handled by MultiCall, a new member is added to the
|
| 17 |
+
event instance passed to the binded functions - mc_type. This is one of the
|
| 18 |
+
event type constants defined in this module (such as MC_KEYPRESS).
|
| 19 |
+
For Key/Button events (which are handled by MultiCall and may receive
|
| 20 |
+
modifiers), another member is added - mc_state. This member gives the state
|
| 21 |
+
of the recognized modifiers, as a combination of the modifier constants
|
| 22 |
+
also defined in this module (for example, MC_SHIFT).
|
| 23 |
+
Using these members is absolutely portable.
|
| 24 |
+
|
| 25 |
+
The order by which events are called is defined by these rules:
|
| 26 |
+
1. A more-specific event will be called before a less-specific event.
|
| 27 |
+
2. A recently-binded event will be called before a previously-binded event,
|
| 28 |
+
unless this conflicts with the first rule.
|
| 29 |
+
Each function will be called at most once for each event.
|
| 30 |
+
"""
|
| 31 |
+
import re
|
| 32 |
+
import sys
|
| 33 |
+
|
| 34 |
+
import tkinter
|
| 35 |
+
|
| 36 |
+
# the event type constants, which define the meaning of mc_type
|
| 37 |
+
MC_KEYPRESS=0; MC_KEYRELEASE=1; MC_BUTTONPRESS=2; MC_BUTTONRELEASE=3;
|
| 38 |
+
MC_ACTIVATE=4; MC_CIRCULATE=5; MC_COLORMAP=6; MC_CONFIGURE=7;
|
| 39 |
+
MC_DEACTIVATE=8; MC_DESTROY=9; MC_ENTER=10; MC_EXPOSE=11; MC_FOCUSIN=12;
|
| 40 |
+
MC_FOCUSOUT=13; MC_GRAVITY=14; MC_LEAVE=15; MC_MAP=16; MC_MOTION=17;
|
| 41 |
+
MC_MOUSEWHEEL=18; MC_PROPERTY=19; MC_REPARENT=20; MC_UNMAP=21; MC_VISIBILITY=22;
|
| 42 |
+
# the modifier state constants, which define the meaning of mc_state
|
| 43 |
+
MC_SHIFT = 1<<0; MC_CONTROL = 1<<2; MC_ALT = 1<<3; MC_META = 1<<5
|
| 44 |
+
MC_OPTION = 1<<6; MC_COMMAND = 1<<7
|
| 45 |
+
|
| 46 |
+
# define the list of modifiers, to be used in complex event types.
|
| 47 |
+
if sys.platform == "darwin":
|
| 48 |
+
_modifiers = (("Shift",), ("Control",), ("Option",), ("Command",))
|
| 49 |
+
_modifier_masks = (MC_SHIFT, MC_CONTROL, MC_OPTION, MC_COMMAND)
|
| 50 |
+
else:
|
| 51 |
+
_modifiers = (("Control",), ("Alt",), ("Shift",), ("Meta", "M"))
|
| 52 |
+
_modifier_masks = (MC_CONTROL, MC_ALT, MC_SHIFT, MC_META)
|
| 53 |
+
|
| 54 |
+
# a dictionary to map a modifier name into its number
|
| 55 |
+
_modifier_names = dict([(name, number)
|
| 56 |
+
for number in range(len(_modifiers))
|
| 57 |
+
for name in _modifiers[number]])
|
| 58 |
+
|
| 59 |
+
# In 3.4, if no shell window is ever open, the underlying Tk widget is
|
| 60 |
+
# destroyed before .__del__ methods here are called. The following
|
| 61 |
+
# is used to selectively ignore shutdown exceptions to avoid
|
| 62 |
+
# 'Exception ignored' messages. See http://bugs.python.org/issue20167
|
| 63 |
+
APPLICATION_GONE = "application has been destroyed"
|
| 64 |
+
|
| 65 |
+
# A binder is a class which binds functions to one type of event. It has two
|
| 66 |
+
# methods: bind and unbind, which get a function and a parsed sequence, as
|
| 67 |
+
# returned by _parse_sequence(). There are two types of binders:
|
| 68 |
+
# _SimpleBinder handles event types with no modifiers and no detail.
|
| 69 |
+
# No Python functions are called when no events are binded.
|
| 70 |
+
# _ComplexBinder handles event types with modifiers and a detail.
|
| 71 |
+
# A Python function is called each time an event is generated.
|
| 72 |
+
|
| 73 |
+
class _SimpleBinder:
|
| 74 |
+
def __init__(self, type, widget, widgetinst):
|
| 75 |
+
self.type = type
|
| 76 |
+
self.sequence = '<'+_types[type][0]+'>'
|
| 77 |
+
self.widget = widget
|
| 78 |
+
self.widgetinst = widgetinst
|
| 79 |
+
self.bindedfuncs = []
|
| 80 |
+
self.handlerid = None
|
| 81 |
+
|
| 82 |
+
def bind(self, triplet, func):
|
| 83 |
+
if not self.handlerid:
|
| 84 |
+
def handler(event, l = self.bindedfuncs, mc_type = self.type):
|
| 85 |
+
event.mc_type = mc_type
|
| 86 |
+
wascalled = {}
|
| 87 |
+
for i in range(len(l)-1, -1, -1):
|
| 88 |
+
func = l[i]
|
| 89 |
+
if func not in wascalled:
|
| 90 |
+
wascalled[func] = True
|
| 91 |
+
r = func(event)
|
| 92 |
+
if r:
|
| 93 |
+
return r
|
| 94 |
+
self.handlerid = self.widget.bind(self.widgetinst,
|
| 95 |
+
self.sequence, handler)
|
| 96 |
+
self.bindedfuncs.append(func)
|
| 97 |
+
|
| 98 |
+
def unbind(self, triplet, func):
|
| 99 |
+
self.bindedfuncs.remove(func)
|
| 100 |
+
if not self.bindedfuncs:
|
| 101 |
+
self.widget.unbind(self.widgetinst, self.sequence, self.handlerid)
|
| 102 |
+
self.handlerid = None
|
| 103 |
+
|
| 104 |
+
def __del__(self):
|
| 105 |
+
if self.handlerid:
|
| 106 |
+
try:
|
| 107 |
+
self.widget.unbind(self.widgetinst, self.sequence,
|
| 108 |
+
self.handlerid)
|
| 109 |
+
except tkinter.TclError as e:
|
| 110 |
+
if not APPLICATION_GONE in e.args[0]:
|
| 111 |
+
raise
|
| 112 |
+
|
| 113 |
+
# An int in range(1 << len(_modifiers)) represents a combination of modifiers
|
| 114 |
+
# (if the least significant bit is on, _modifiers[0] is on, and so on).
|
| 115 |
+
# _state_subsets gives for each combination of modifiers, or *state*,
|
| 116 |
+
# a list of the states which are a subset of it. This list is ordered by the
|
| 117 |
+
# number of modifiers is the state - the most specific state comes first.
|
| 118 |
+
_states = range(1 << len(_modifiers))
|
| 119 |
+
_state_names = [''.join(m[0]+'-'
|
| 120 |
+
for i, m in enumerate(_modifiers)
|
| 121 |
+
if (1 << i) & s)
|
| 122 |
+
for s in _states]
|
| 123 |
+
|
| 124 |
+
def expand_substates(states):
|
| 125 |
+
'''For each item of states return a list containing all combinations of
|
| 126 |
+
that item with individual bits reset, sorted by the number of set bits.
|
| 127 |
+
'''
|
| 128 |
+
def nbits(n):
|
| 129 |
+
"number of bits set in n base 2"
|
| 130 |
+
nb = 0
|
| 131 |
+
while n:
|
| 132 |
+
n, rem = divmod(n, 2)
|
| 133 |
+
nb += rem
|
| 134 |
+
return nb
|
| 135 |
+
statelist = []
|
| 136 |
+
for state in states:
|
| 137 |
+
substates = list(set(state & x for x in states))
|
| 138 |
+
substates.sort(key=nbits, reverse=True)
|
| 139 |
+
statelist.append(substates)
|
| 140 |
+
return statelist
|
| 141 |
+
|
| 142 |
+
_state_subsets = expand_substates(_states)
|
| 143 |
+
|
| 144 |
+
# _state_codes gives for each state, the portable code to be passed as mc_state
|
| 145 |
+
_state_codes = []
|
| 146 |
+
for s in _states:
|
| 147 |
+
r = 0
|
| 148 |
+
for i in range(len(_modifiers)):
|
| 149 |
+
if (1 << i) & s:
|
| 150 |
+
r |= _modifier_masks[i]
|
| 151 |
+
_state_codes.append(r)
|
| 152 |
+
|
| 153 |
+
class _ComplexBinder:
|
| 154 |
+
# This class binds many functions, and only unbinds them when it is deleted.
|
| 155 |
+
# self.handlerids is the list of seqs and ids of binded handler functions.
|
| 156 |
+
# The binded functions sit in a dictionary of lists of lists, which maps
|
| 157 |
+
# a detail (or None) and a state into a list of functions.
|
| 158 |
+
# When a new detail is discovered, handlers for all the possible states
|
| 159 |
+
# are binded.
|
| 160 |
+
|
| 161 |
+
def __create_handler(self, lists, mc_type, mc_state):
|
| 162 |
+
def handler(event, lists = lists,
|
| 163 |
+
mc_type = mc_type, mc_state = mc_state,
|
| 164 |
+
ishandlerrunning = self.ishandlerrunning,
|
| 165 |
+
doafterhandler = self.doafterhandler):
|
| 166 |
+
ishandlerrunning[:] = [True]
|
| 167 |
+
event.mc_type = mc_type
|
| 168 |
+
event.mc_state = mc_state
|
| 169 |
+
wascalled = {}
|
| 170 |
+
r = None
|
| 171 |
+
for l in lists:
|
| 172 |
+
for i in range(len(l)-1, -1, -1):
|
| 173 |
+
func = l[i]
|
| 174 |
+
if func not in wascalled:
|
| 175 |
+
wascalled[func] = True
|
| 176 |
+
r = l[i](event)
|
| 177 |
+
if r:
|
| 178 |
+
break
|
| 179 |
+
if r:
|
| 180 |
+
break
|
| 181 |
+
ishandlerrunning[:] = []
|
| 182 |
+
# Call all functions in doafterhandler and remove them from list
|
| 183 |
+
for f in doafterhandler:
|
| 184 |
+
f()
|
| 185 |
+
doafterhandler[:] = []
|
| 186 |
+
if r:
|
| 187 |
+
return r
|
| 188 |
+
return handler
|
| 189 |
+
|
| 190 |
+
def __init__(self, type, widget, widgetinst):
|
| 191 |
+
self.type = type
|
| 192 |
+
self.typename = _types[type][0]
|
| 193 |
+
self.widget = widget
|
| 194 |
+
self.widgetinst = widgetinst
|
| 195 |
+
self.bindedfuncs = {None: [[] for s in _states]}
|
| 196 |
+
self.handlerids = []
|
| 197 |
+
# we don't want to change the lists of functions while a handler is
|
| 198 |
+
# running - it will mess up the loop and anyway, we usually want the
|
| 199 |
+
# change to happen from the next event. So we have a list of functions
|
| 200 |
+
# for the handler to run after it finishes calling the binded functions.
|
| 201 |
+
# It calls them only once.
|
| 202 |
+
# ishandlerrunning is a list. An empty one means no, otherwise - yes.
|
| 203 |
+
# this is done so that it would be mutable.
|
| 204 |
+
self.ishandlerrunning = []
|
| 205 |
+
self.doafterhandler = []
|
| 206 |
+
for s in _states:
|
| 207 |
+
lists = [self.bindedfuncs[None][i] for i in _state_subsets[s]]
|
| 208 |
+
handler = self.__create_handler(lists, type, _state_codes[s])
|
| 209 |
+
seq = '<'+_state_names[s]+self.typename+'>'
|
| 210 |
+
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
|
| 211 |
+
seq, handler)))
|
| 212 |
+
|
| 213 |
+
def bind(self, triplet, func):
|
| 214 |
+
if triplet[2] not in self.bindedfuncs:
|
| 215 |
+
self.bindedfuncs[triplet[2]] = [[] for s in _states]
|
| 216 |
+
for s in _states:
|
| 217 |
+
lists = [ self.bindedfuncs[detail][i]
|
| 218 |
+
for detail in (triplet[2], None)
|
| 219 |
+
for i in _state_subsets[s] ]
|
| 220 |
+
handler = self.__create_handler(lists, self.type,
|
| 221 |
+
_state_codes[s])
|
| 222 |
+
seq = "<%s%s-%s>"% (_state_names[s], self.typename, triplet[2])
|
| 223 |
+
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
|
| 224 |
+
seq, handler)))
|
| 225 |
+
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].append(func)
|
| 226 |
+
if not self.ishandlerrunning:
|
| 227 |
+
doit()
|
| 228 |
+
else:
|
| 229 |
+
self.doafterhandler.append(doit)
|
| 230 |
+
|
| 231 |
+
def unbind(self, triplet, func):
|
| 232 |
+
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func)
|
| 233 |
+
if not self.ishandlerrunning:
|
| 234 |
+
doit()
|
| 235 |
+
else:
|
| 236 |
+
self.doafterhandler.append(doit)
|
| 237 |
+
|
| 238 |
+
def __del__(self):
|
| 239 |
+
for seq, id in self.handlerids:
|
| 240 |
+
try:
|
| 241 |
+
self.widget.unbind(self.widgetinst, seq, id)
|
| 242 |
+
except tkinter.TclError as e:
|
| 243 |
+
if not APPLICATION_GONE in e.args[0]:
|
| 244 |
+
raise
|
| 245 |
+
|
| 246 |
+
# define the list of event types to be handled by MultiEvent. the order is
|
| 247 |
+
# compatible with the definition of event type constants.
|
| 248 |
+
_types = (
|
| 249 |
+
("KeyPress", "Key"), ("KeyRelease",), ("ButtonPress", "Button"),
|
| 250 |
+
("ButtonRelease",), ("Activate",), ("Circulate",), ("Colormap",),
|
| 251 |
+
("Configure",), ("Deactivate",), ("Destroy",), ("Enter",), ("Expose",),
|
| 252 |
+
("FocusIn",), ("FocusOut",), ("Gravity",), ("Leave",), ("Map",),
|
| 253 |
+
("Motion",), ("MouseWheel",), ("Property",), ("Reparent",), ("Unmap",),
|
| 254 |
+
("Visibility",),
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
# which binder should be used for every event type?
|
| 258 |
+
_binder_classes = (_ComplexBinder,) * 4 + (_SimpleBinder,) * (len(_types)-4)
|
| 259 |
+
|
| 260 |
+
# A dictionary to map a type name into its number
|
| 261 |
+
_type_names = dict([(name, number)
|
| 262 |
+
for number in range(len(_types))
|
| 263 |
+
for name in _types[number]])
|
| 264 |
+
|
| 265 |
+
_keysym_re = re.compile(r"^\w+$")
|
| 266 |
+
_button_re = re.compile(r"^[1-5]$")
|
| 267 |
+
def _parse_sequence(sequence):
|
| 268 |
+
"""Get a string which should describe an event sequence. If it is
|
| 269 |
+
successfully parsed as one, return a tuple containing the state (as an int),
|
| 270 |
+
the event type (as an index of _types), and the detail - None if none, or a
|
| 271 |
+
string if there is one. If the parsing is unsuccessful, return None.
|
| 272 |
+
"""
|
| 273 |
+
if not sequence or sequence[0] != '<' or sequence[-1] != '>':
|
| 274 |
+
return None
|
| 275 |
+
words = sequence[1:-1].split('-')
|
| 276 |
+
modifiers = 0
|
| 277 |
+
while words and words[0] in _modifier_names:
|
| 278 |
+
modifiers |= 1 << _modifier_names[words[0]]
|
| 279 |
+
del words[0]
|
| 280 |
+
if words and words[0] in _type_names:
|
| 281 |
+
type = _type_names[words[0]]
|
| 282 |
+
del words[0]
|
| 283 |
+
else:
|
| 284 |
+
return None
|
| 285 |
+
if _binder_classes[type] is _SimpleBinder:
|
| 286 |
+
if modifiers or words:
|
| 287 |
+
return None
|
| 288 |
+
else:
|
| 289 |
+
detail = None
|
| 290 |
+
else:
|
| 291 |
+
# _ComplexBinder
|
| 292 |
+
if type in [_type_names[s] for s in ("KeyPress", "KeyRelease")]:
|
| 293 |
+
type_re = _keysym_re
|
| 294 |
+
else:
|
| 295 |
+
type_re = _button_re
|
| 296 |
+
|
| 297 |
+
if not words:
|
| 298 |
+
detail = None
|
| 299 |
+
elif len(words) == 1 and type_re.match(words[0]):
|
| 300 |
+
detail = words[0]
|
| 301 |
+
else:
|
| 302 |
+
return None
|
| 303 |
+
|
| 304 |
+
return modifiers, type, detail
|
| 305 |
+
|
| 306 |
+
def _triplet_to_sequence(triplet):
|
| 307 |
+
if triplet[2]:
|
| 308 |
+
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'-'+ \
|
| 309 |
+
triplet[2]+'>'
|
| 310 |
+
else:
|
| 311 |
+
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'>'
|
| 312 |
+
|
| 313 |
+
_multicall_dict = {}
|
| 314 |
+
def MultiCallCreator(widget):
|
| 315 |
+
"""Return a MultiCall class which inherits its methods from the
|
| 316 |
+
given widget class (for example, Tkinter.Text). This is used
|
| 317 |
+
instead of a templating mechanism.
|
| 318 |
+
"""
|
| 319 |
+
if widget in _multicall_dict:
|
| 320 |
+
return _multicall_dict[widget]
|
| 321 |
+
|
| 322 |
+
class MultiCall (widget):
|
| 323 |
+
assert issubclass(widget, tkinter.Misc)
|
| 324 |
+
|
| 325 |
+
def __init__(self, *args, **kwargs):
|
| 326 |
+
widget.__init__(self, *args, **kwargs)
|
| 327 |
+
# a dictionary which maps a virtual event to a tuple with:
|
| 328 |
+
# 0. the function binded
|
| 329 |
+
# 1. a list of triplets - the sequences it is binded to
|
| 330 |
+
self.__eventinfo = {}
|
| 331 |
+
self.__binders = [_binder_classes[i](i, widget, self)
|
| 332 |
+
for i in range(len(_types))]
|
| 333 |
+
|
| 334 |
+
def bind(self, sequence=None, func=None, add=None):
|
| 335 |
+
#print("bind(%s, %s, %s)" % (sequence, func, add),
|
| 336 |
+
# file=sys.__stderr__)
|
| 337 |
+
if type(sequence) is str and len(sequence) > 2 and \
|
| 338 |
+
sequence[:2] == "<<" and sequence[-2:] == ">>":
|
| 339 |
+
if sequence in self.__eventinfo:
|
| 340 |
+
ei = self.__eventinfo[sequence]
|
| 341 |
+
if ei[0] is not None:
|
| 342 |
+
for triplet in ei[1]:
|
| 343 |
+
self.__binders[triplet[1]].unbind(triplet, ei[0])
|
| 344 |
+
ei[0] = func
|
| 345 |
+
if ei[0] is not None:
|
| 346 |
+
for triplet in ei[1]:
|
| 347 |
+
self.__binders[triplet[1]].bind(triplet, func)
|
| 348 |
+
else:
|
| 349 |
+
self.__eventinfo[sequence] = [func, []]
|
| 350 |
+
return widget.bind(self, sequence, func, add)
|
| 351 |
+
|
| 352 |
+
def unbind(self, sequence, funcid=None):
|
| 353 |
+
if type(sequence) is str and len(sequence) > 2 and \
|
| 354 |
+
sequence[:2] == "<<" and sequence[-2:] == ">>" and \
|
| 355 |
+
sequence in self.__eventinfo:
|
| 356 |
+
func, triplets = self.__eventinfo[sequence]
|
| 357 |
+
if func is not None:
|
| 358 |
+
for triplet in triplets:
|
| 359 |
+
self.__binders[triplet[1]].unbind(triplet, func)
|
| 360 |
+
self.__eventinfo[sequence][0] = None
|
| 361 |
+
return widget.unbind(self, sequence, funcid)
|
| 362 |
+
|
| 363 |
+
def event_add(self, virtual, *sequences):
|
| 364 |
+
#print("event_add(%s, %s)" % (repr(virtual), repr(sequences)),
|
| 365 |
+
# file=sys.__stderr__)
|
| 366 |
+
if virtual not in self.__eventinfo:
|
| 367 |
+
self.__eventinfo[virtual] = [None, []]
|
| 368 |
+
|
| 369 |
+
func, triplets = self.__eventinfo[virtual]
|
| 370 |
+
for seq in sequences:
|
| 371 |
+
triplet = _parse_sequence(seq)
|
| 372 |
+
if triplet is None:
|
| 373 |
+
#print("Tkinter event_add(%s)" % seq, file=sys.__stderr__)
|
| 374 |
+
widget.event_add(self, virtual, seq)
|
| 375 |
+
else:
|
| 376 |
+
if func is not None:
|
| 377 |
+
self.__binders[triplet[1]].bind(triplet, func)
|
| 378 |
+
triplets.append(triplet)
|
| 379 |
+
|
| 380 |
+
def event_delete(self, virtual, *sequences):
|
| 381 |
+
if virtual not in self.__eventinfo:
|
| 382 |
+
return
|
| 383 |
+
func, triplets = self.__eventinfo[virtual]
|
| 384 |
+
for seq in sequences:
|
| 385 |
+
triplet = _parse_sequence(seq)
|
| 386 |
+
if triplet is None:
|
| 387 |
+
#print("Tkinter event_delete: %s" % seq, file=sys.__stderr__)
|
| 388 |
+
widget.event_delete(self, virtual, seq)
|
| 389 |
+
else:
|
| 390 |
+
if func is not None:
|
| 391 |
+
self.__binders[triplet[1]].unbind(triplet, func)
|
| 392 |
+
triplets.remove(triplet)
|
| 393 |
+
|
| 394 |
+
def event_info(self, virtual=None):
|
| 395 |
+
if virtual is None or virtual not in self.__eventinfo:
|
| 396 |
+
return widget.event_info(self, virtual)
|
| 397 |
+
else:
|
| 398 |
+
return tuple(map(_triplet_to_sequence,
|
| 399 |
+
self.__eventinfo[virtual][1])) + \
|
| 400 |
+
widget.event_info(self, virtual)
|
| 401 |
+
|
| 402 |
+
def __del__(self):
|
| 403 |
+
for virtual in self.__eventinfo:
|
| 404 |
+
func, triplets = self.__eventinfo[virtual]
|
| 405 |
+
if func:
|
| 406 |
+
for triplet in triplets:
|
| 407 |
+
try:
|
| 408 |
+
self.__binders[triplet[1]].unbind(triplet, func)
|
| 409 |
+
except tkinter.TclError as e:
|
| 410 |
+
if not APPLICATION_GONE in e.args[0]:
|
| 411 |
+
raise
|
| 412 |
+
|
| 413 |
+
_multicall_dict[widget] = MultiCall
|
| 414 |
+
return MultiCall
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def _multi_call(parent): # htest #
|
| 418 |
+
top = tkinter.Toplevel(parent)
|
| 419 |
+
top.title("Test MultiCall")
|
| 420 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 421 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 422 |
+
text = MultiCallCreator(tkinter.Text)(top)
|
| 423 |
+
text.pack()
|
| 424 |
+
def bindseq(seq, n=[0]):
|
| 425 |
+
def handler(event):
|
| 426 |
+
print(seq)
|
| 427 |
+
text.bind("<<handler%d>>"%n[0], handler)
|
| 428 |
+
text.event_add("<<handler%d>>"%n[0], seq)
|
| 429 |
+
n[0] += 1
|
| 430 |
+
bindseq("<Key>")
|
| 431 |
+
bindseq("<Control-Key>")
|
| 432 |
+
bindseq("<Alt-Key-a>")
|
| 433 |
+
bindseq("<Control-Key-a>")
|
| 434 |
+
bindseq("<Alt-Control-Key-a>")
|
| 435 |
+
bindseq("<Key-b>")
|
| 436 |
+
bindseq("<Control-Button-1>")
|
| 437 |
+
bindseq("<Button-2>")
|
| 438 |
+
bindseq("<Alt-Button-1>")
|
| 439 |
+
bindseq("<FocusOut>")
|
| 440 |
+
bindseq("<Enter>")
|
| 441 |
+
bindseq("<Leave>")
|
| 442 |
+
|
| 443 |
+
if __name__ == "__main__":
|
| 444 |
+
from unittest import main
|
| 445 |
+
main('idlelib.idle_test.test_mainmenu', verbosity=2, exit=False)
|
| 446 |
+
|
| 447 |
+
from idlelib.idle_test.htest import run
|
| 448 |
+
run(_multi_call)
|
deepseek/lib/python3.10/idlelib/parenmatch.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ParenMatch -- for parenthesis matching.
|
| 2 |
+
|
| 3 |
+
When you hit a right paren, the cursor should move briefly to the left
|
| 4 |
+
paren. Paren here is used generically; the matching applies to
|
| 5 |
+
parentheses, square brackets, and curly braces.
|
| 6 |
+
"""
|
| 7 |
+
from idlelib.hyperparser import HyperParser
|
| 8 |
+
from idlelib.config import idleConf
|
| 9 |
+
|
| 10 |
+
_openers = {')':'(',']':'[','}':'{'}
|
| 11 |
+
CHECK_DELAY = 100 # milliseconds
|
| 12 |
+
|
| 13 |
+
class ParenMatch:
|
| 14 |
+
"""Highlight matching openers and closers, (), [], and {}.
|
| 15 |
+
|
| 16 |
+
There are three supported styles of paren matching. When a right
|
| 17 |
+
paren (opener) is typed:
|
| 18 |
+
|
| 19 |
+
opener -- highlight the matching left paren (closer);
|
| 20 |
+
parens -- highlight the left and right parens (opener and closer);
|
| 21 |
+
expression -- highlight the entire expression from opener to closer.
|
| 22 |
+
(For back compatibility, 'default' is a synonym for 'opener').
|
| 23 |
+
|
| 24 |
+
Flash-delay is the maximum milliseconds the highlighting remains.
|
| 25 |
+
Any cursor movement (key press or click) before that removes the
|
| 26 |
+
highlight. If flash-delay is 0, there is no maximum.
|
| 27 |
+
|
| 28 |
+
TODO:
|
| 29 |
+
- Augment bell() with mismatch warning in status window.
|
| 30 |
+
- Highlight when cursor is moved to the right of a closer.
|
| 31 |
+
This might be too expensive to check.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
RESTORE_VIRTUAL_EVENT_NAME = "<<parenmatch-check-restore>>"
|
| 35 |
+
# We want the restore event be called before the usual return and
|
| 36 |
+
# backspace events.
|
| 37 |
+
RESTORE_SEQUENCES = ("<KeyPress>", "<ButtonPress>",
|
| 38 |
+
"<Key-Return>", "<Key-BackSpace>")
|
| 39 |
+
|
| 40 |
+
def __init__(self, editwin):
|
| 41 |
+
self.editwin = editwin
|
| 42 |
+
self.text = editwin.text
|
| 43 |
+
# Bind the check-restore event to the function restore_event,
|
| 44 |
+
# so that we can then use activate_restore (which calls event_add)
|
| 45 |
+
# and deactivate_restore (which calls event_delete).
|
| 46 |
+
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
|
| 47 |
+
self.restore_event)
|
| 48 |
+
self.counter = 0
|
| 49 |
+
self.is_restore_active = 0
|
| 50 |
+
|
| 51 |
+
@classmethod
|
| 52 |
+
def reload(cls):
|
| 53 |
+
cls.STYLE = idleConf.GetOption(
|
| 54 |
+
'extensions','ParenMatch','style', default='opener')
|
| 55 |
+
cls.FLASH_DELAY = idleConf.GetOption(
|
| 56 |
+
'extensions','ParenMatch','flash-delay', type='int',default=500)
|
| 57 |
+
cls.BELL = idleConf.GetOption(
|
| 58 |
+
'extensions','ParenMatch','bell', type='bool', default=1)
|
| 59 |
+
cls.HILITE_CONFIG = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 60 |
+
'hilite')
|
| 61 |
+
|
| 62 |
+
def activate_restore(self):
|
| 63 |
+
"Activate mechanism to restore text from highlighting."
|
| 64 |
+
if not self.is_restore_active:
|
| 65 |
+
for seq in self.RESTORE_SEQUENCES:
|
| 66 |
+
self.text.event_add(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
|
| 67 |
+
self.is_restore_active = True
|
| 68 |
+
|
| 69 |
+
def deactivate_restore(self):
|
| 70 |
+
"Remove restore event bindings."
|
| 71 |
+
if self.is_restore_active:
|
| 72 |
+
for seq in self.RESTORE_SEQUENCES:
|
| 73 |
+
self.text.event_delete(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
|
| 74 |
+
self.is_restore_active = False
|
| 75 |
+
|
| 76 |
+
def flash_paren_event(self, event):
|
| 77 |
+
"Handle editor 'show surrounding parens' event (menu or shortcut)."
|
| 78 |
+
indices = (HyperParser(self.editwin, "insert")
|
| 79 |
+
.get_surrounding_brackets())
|
| 80 |
+
self.finish_paren_event(indices)
|
| 81 |
+
return "break"
|
| 82 |
+
|
| 83 |
+
def paren_closed_event(self, event):
|
| 84 |
+
"Handle user input of closer."
|
| 85 |
+
# If user bound non-closer to <<paren-closed>>, quit.
|
| 86 |
+
closer = self.text.get("insert-1c")
|
| 87 |
+
if closer not in _openers:
|
| 88 |
+
return
|
| 89 |
+
hp = HyperParser(self.editwin, "insert-1c")
|
| 90 |
+
if not hp.is_in_code():
|
| 91 |
+
return
|
| 92 |
+
indices = hp.get_surrounding_brackets(_openers[closer], True)
|
| 93 |
+
self.finish_paren_event(indices)
|
| 94 |
+
return # Allow calltips to see ')'
|
| 95 |
+
|
| 96 |
+
def finish_paren_event(self, indices):
|
| 97 |
+
if indices is None and self.BELL:
|
| 98 |
+
self.text.bell()
|
| 99 |
+
return
|
| 100 |
+
self.activate_restore()
|
| 101 |
+
# self.create_tag(indices)
|
| 102 |
+
self.tagfuncs.get(self.STYLE, self.create_tag_expression)(self, indices)
|
| 103 |
+
# self.set_timeout()
|
| 104 |
+
(self.set_timeout_last if self.FLASH_DELAY else
|
| 105 |
+
self.set_timeout_none)()
|
| 106 |
+
|
| 107 |
+
def restore_event(self, event=None):
|
| 108 |
+
"Remove effect of doing match."
|
| 109 |
+
self.text.tag_delete("paren")
|
| 110 |
+
self.deactivate_restore()
|
| 111 |
+
self.counter += 1 # disable the last timer, if there is one.
|
| 112 |
+
|
| 113 |
+
def handle_restore_timer(self, timer_count):
|
| 114 |
+
if timer_count == self.counter:
|
| 115 |
+
self.restore_event()
|
| 116 |
+
|
| 117 |
+
# any one of the create_tag_XXX methods can be used depending on
|
| 118 |
+
# the style
|
| 119 |
+
|
| 120 |
+
def create_tag_opener(self, indices):
|
| 121 |
+
"""Highlight the single paren that matches"""
|
| 122 |
+
self.text.tag_add("paren", indices[0])
|
| 123 |
+
self.text.tag_config("paren", self.HILITE_CONFIG)
|
| 124 |
+
|
| 125 |
+
def create_tag_parens(self, indices):
|
| 126 |
+
"""Highlight the left and right parens"""
|
| 127 |
+
if self.text.get(indices[1]) in (')', ']', '}'):
|
| 128 |
+
rightindex = indices[1]+"+1c"
|
| 129 |
+
else:
|
| 130 |
+
rightindex = indices[1]
|
| 131 |
+
self.text.tag_add("paren", indices[0], indices[0]+"+1c", rightindex+"-1c", rightindex)
|
| 132 |
+
self.text.tag_config("paren", self.HILITE_CONFIG)
|
| 133 |
+
|
| 134 |
+
def create_tag_expression(self, indices):
|
| 135 |
+
"""Highlight the entire expression"""
|
| 136 |
+
if self.text.get(indices[1]) in (')', ']', '}'):
|
| 137 |
+
rightindex = indices[1]+"+1c"
|
| 138 |
+
else:
|
| 139 |
+
rightindex = indices[1]
|
| 140 |
+
self.text.tag_add("paren", indices[0], rightindex)
|
| 141 |
+
self.text.tag_config("paren", self.HILITE_CONFIG)
|
| 142 |
+
|
| 143 |
+
tagfuncs = {
|
| 144 |
+
'opener': create_tag_opener,
|
| 145 |
+
'default': create_tag_opener,
|
| 146 |
+
'parens': create_tag_parens,
|
| 147 |
+
'expression': create_tag_expression,
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
# any one of the set_timeout_XXX methods can be used depending on
|
| 151 |
+
# the style
|
| 152 |
+
|
| 153 |
+
def set_timeout_none(self):
|
| 154 |
+
"""Highlight will remain until user input turns it off
|
| 155 |
+
or the insert has moved"""
|
| 156 |
+
# After CHECK_DELAY, call a function which disables the "paren" tag
|
| 157 |
+
# if the event is for the most recent timer and the insert has changed,
|
| 158 |
+
# or schedules another call for itself.
|
| 159 |
+
self.counter += 1
|
| 160 |
+
def callme(callme, self=self, c=self.counter,
|
| 161 |
+
index=self.text.index("insert")):
|
| 162 |
+
if index != self.text.index("insert"):
|
| 163 |
+
self.handle_restore_timer(c)
|
| 164 |
+
else:
|
| 165 |
+
self.editwin.text_frame.after(CHECK_DELAY, callme, callme)
|
| 166 |
+
self.editwin.text_frame.after(CHECK_DELAY, callme, callme)
|
| 167 |
+
|
| 168 |
+
def set_timeout_last(self):
|
| 169 |
+
"""The last highlight created will be removed after FLASH_DELAY millisecs"""
|
| 170 |
+
# associate a counter with an event; only disable the "paren"
|
| 171 |
+
# tag if the event is for the most recent timer.
|
| 172 |
+
self.counter += 1
|
| 173 |
+
self.editwin.text_frame.after(
|
| 174 |
+
self.FLASH_DELAY,
|
| 175 |
+
lambda self=self, c=self.counter: self.handle_restore_timer(c))
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
ParenMatch.reload()
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
from unittest import main
|
| 183 |
+
main('idlelib.idle_test.test_parenmatch', verbosity=2)
|
deepseek/lib/python3.10/idlelib/pathbrowser.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.machinery
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
from idlelib.browser import ModuleBrowser, ModuleBrowserTreeItem
|
| 6 |
+
from idlelib.tree import TreeItem
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class PathBrowser(ModuleBrowser):
|
| 10 |
+
|
| 11 |
+
def __init__(self, master, *, _htest=False, _utest=False):
|
| 12 |
+
"""
|
| 13 |
+
_htest - bool, change box location when running htest
|
| 14 |
+
"""
|
| 15 |
+
self.master = master
|
| 16 |
+
self._htest = _htest
|
| 17 |
+
self._utest = _utest
|
| 18 |
+
self.init()
|
| 19 |
+
|
| 20 |
+
def settitle(self):
|
| 21 |
+
"Set window titles."
|
| 22 |
+
self.top.wm_title("Path Browser")
|
| 23 |
+
self.top.wm_iconname("Path Browser")
|
| 24 |
+
|
| 25 |
+
def rootnode(self):
|
| 26 |
+
return PathBrowserTreeItem()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class PathBrowserTreeItem(TreeItem):
|
| 30 |
+
|
| 31 |
+
def GetText(self):
|
| 32 |
+
return "sys.path"
|
| 33 |
+
|
| 34 |
+
def GetSubList(self):
|
| 35 |
+
sublist = []
|
| 36 |
+
for dir in sys.path:
|
| 37 |
+
item = DirBrowserTreeItem(dir)
|
| 38 |
+
sublist.append(item)
|
| 39 |
+
return sublist
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class DirBrowserTreeItem(TreeItem):
|
| 43 |
+
|
| 44 |
+
def __init__(self, dir, packages=[]):
|
| 45 |
+
self.dir = dir
|
| 46 |
+
self.packages = packages
|
| 47 |
+
|
| 48 |
+
def GetText(self):
|
| 49 |
+
if not self.packages:
|
| 50 |
+
return self.dir
|
| 51 |
+
else:
|
| 52 |
+
return self.packages[-1] + ": package"
|
| 53 |
+
|
| 54 |
+
def GetSubList(self):
|
| 55 |
+
try:
|
| 56 |
+
names = os.listdir(self.dir or os.curdir)
|
| 57 |
+
except OSError:
|
| 58 |
+
return []
|
| 59 |
+
packages = []
|
| 60 |
+
for name in names:
|
| 61 |
+
file = os.path.join(self.dir, name)
|
| 62 |
+
if self.ispackagedir(file):
|
| 63 |
+
nn = os.path.normcase(name)
|
| 64 |
+
packages.append((nn, name, file))
|
| 65 |
+
packages.sort()
|
| 66 |
+
sublist = []
|
| 67 |
+
for nn, name, file in packages:
|
| 68 |
+
item = DirBrowserTreeItem(file, self.packages + [name])
|
| 69 |
+
sublist.append(item)
|
| 70 |
+
for nn, name in self.listmodules(names):
|
| 71 |
+
item = ModuleBrowserTreeItem(os.path.join(self.dir, name))
|
| 72 |
+
sublist.append(item)
|
| 73 |
+
return sublist
|
| 74 |
+
|
| 75 |
+
def ispackagedir(self, file):
|
| 76 |
+
" Return true for directories that are packages."
|
| 77 |
+
if not os.path.isdir(file):
|
| 78 |
+
return False
|
| 79 |
+
init = os.path.join(file, "__init__.py")
|
| 80 |
+
return os.path.exists(init)
|
| 81 |
+
|
| 82 |
+
def listmodules(self, allnames):
|
| 83 |
+
modules = {}
|
| 84 |
+
suffixes = importlib.machinery.EXTENSION_SUFFIXES[:]
|
| 85 |
+
suffixes += importlib.machinery.SOURCE_SUFFIXES
|
| 86 |
+
suffixes += importlib.machinery.BYTECODE_SUFFIXES
|
| 87 |
+
sorted = []
|
| 88 |
+
for suff in suffixes:
|
| 89 |
+
i = -len(suff)
|
| 90 |
+
for name in allnames[:]:
|
| 91 |
+
normed_name = os.path.normcase(name)
|
| 92 |
+
if normed_name[i:] == suff:
|
| 93 |
+
mod_name = name[:i]
|
| 94 |
+
if mod_name not in modules:
|
| 95 |
+
modules[mod_name] = None
|
| 96 |
+
sorted.append((normed_name, name))
|
| 97 |
+
allnames.remove(name)
|
| 98 |
+
sorted.sort()
|
| 99 |
+
return sorted
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _path_browser(parent): # htest #
|
| 103 |
+
PathBrowser(parent, _htest=True)
|
| 104 |
+
parent.mainloop()
|
| 105 |
+
|
| 106 |
+
if __name__ == "__main__":
|
| 107 |
+
from unittest import main
|
| 108 |
+
main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False)
|
| 109 |
+
|
| 110 |
+
from idlelib.idle_test.htest import run
|
| 111 |
+
run(_path_browser)
|
deepseek/lib/python3.10/idlelib/pyparse.py
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define partial Python code Parser used by editor and hyperparser.
|
| 2 |
+
|
| 3 |
+
Instances of ParseMap are used with str.translate.
|
| 4 |
+
|
| 5 |
+
The following bound search and match functions are defined:
|
| 6 |
+
_synchre - start of popular statement;
|
| 7 |
+
_junkre - whitespace or comment line;
|
| 8 |
+
_match_stringre: string, possibly without closer;
|
| 9 |
+
_itemre - line that may have bracket structure start;
|
| 10 |
+
_closere - line that must be followed by dedent.
|
| 11 |
+
_chew_ordinaryre - non-special characters.
|
| 12 |
+
"""
|
| 13 |
+
import re
|
| 14 |
+
|
| 15 |
+
# Reason last statement is continued (or C_NONE if it's not).
|
| 16 |
+
(C_NONE, C_BACKSLASH, C_STRING_FIRST_LINE,
|
| 17 |
+
C_STRING_NEXT_LINES, C_BRACKET) = range(5)
|
| 18 |
+
|
| 19 |
+
# Find what looks like the start of a popular statement.
|
| 20 |
+
|
| 21 |
+
_synchre = re.compile(r"""
|
| 22 |
+
^
|
| 23 |
+
[ \t]*
|
| 24 |
+
(?: while
|
| 25 |
+
| else
|
| 26 |
+
| def
|
| 27 |
+
| return
|
| 28 |
+
| assert
|
| 29 |
+
| break
|
| 30 |
+
| class
|
| 31 |
+
| continue
|
| 32 |
+
| elif
|
| 33 |
+
| try
|
| 34 |
+
| except
|
| 35 |
+
| raise
|
| 36 |
+
| import
|
| 37 |
+
| yield
|
| 38 |
+
)
|
| 39 |
+
\b
|
| 40 |
+
""", re.VERBOSE | re.MULTILINE).search
|
| 41 |
+
|
| 42 |
+
# Match blank line or non-indenting comment line.
|
| 43 |
+
|
| 44 |
+
_junkre = re.compile(r"""
|
| 45 |
+
[ \t]*
|
| 46 |
+
(?: \# \S .* )?
|
| 47 |
+
\n
|
| 48 |
+
""", re.VERBOSE).match
|
| 49 |
+
|
| 50 |
+
# Match any flavor of string; the terminating quote is optional
|
| 51 |
+
# so that we're robust in the face of incomplete program text.
|
| 52 |
+
|
| 53 |
+
_match_stringre = re.compile(r"""
|
| 54 |
+
\""" [^"\\]* (?:
|
| 55 |
+
(?: \\. | "(?!"") )
|
| 56 |
+
[^"\\]*
|
| 57 |
+
)*
|
| 58 |
+
(?: \""" )?
|
| 59 |
+
|
| 60 |
+
| " [^"\\\n]* (?: \\. [^"\\\n]* )* "?
|
| 61 |
+
|
| 62 |
+
| ''' [^'\\]* (?:
|
| 63 |
+
(?: \\. | '(?!'') )
|
| 64 |
+
[^'\\]*
|
| 65 |
+
)*
|
| 66 |
+
(?: ''' )?
|
| 67 |
+
|
| 68 |
+
| ' [^'\\\n]* (?: \\. [^'\\\n]* )* '?
|
| 69 |
+
""", re.VERBOSE | re.DOTALL).match
|
| 70 |
+
|
| 71 |
+
# Match a line that starts with something interesting;
|
| 72 |
+
# used to find the first item of a bracket structure.
|
| 73 |
+
|
| 74 |
+
_itemre = re.compile(r"""
|
| 75 |
+
[ \t]*
|
| 76 |
+
[^\s#\\] # if we match, m.end()-1 is the interesting char
|
| 77 |
+
""", re.VERBOSE).match
|
| 78 |
+
|
| 79 |
+
# Match start of statements that should be followed by a dedent.
|
| 80 |
+
|
| 81 |
+
_closere = re.compile(r"""
|
| 82 |
+
\s*
|
| 83 |
+
(?: return
|
| 84 |
+
| break
|
| 85 |
+
| continue
|
| 86 |
+
| raise
|
| 87 |
+
| pass
|
| 88 |
+
)
|
| 89 |
+
\b
|
| 90 |
+
""", re.VERBOSE).match
|
| 91 |
+
|
| 92 |
+
# Chew up non-special chars as quickly as possible. If match is
|
| 93 |
+
# successful, m.end() less 1 is the index of the last boring char
|
| 94 |
+
# matched. If match is unsuccessful, the string starts with an
|
| 95 |
+
# interesting char.
|
| 96 |
+
|
| 97 |
+
_chew_ordinaryre = re.compile(r"""
|
| 98 |
+
[^[\](){}#'"\\]+
|
| 99 |
+
""", re.VERBOSE).match
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class ParseMap(dict):
|
| 103 |
+
r"""Dict subclass that maps anything not in dict to 'x'.
|
| 104 |
+
|
| 105 |
+
This is designed to be used with str.translate in study1.
|
| 106 |
+
Anything not specifically mapped otherwise becomes 'x'.
|
| 107 |
+
Example: replace everything except whitespace with 'x'.
|
| 108 |
+
|
| 109 |
+
>>> keepwhite = ParseMap((ord(c), ord(c)) for c in ' \t\n\r')
|
| 110 |
+
>>> "a + b\tc\nd".translate(keepwhite)
|
| 111 |
+
'x x x\tx\nx'
|
| 112 |
+
"""
|
| 113 |
+
# Calling this triples access time; see bpo-32940
|
| 114 |
+
def __missing__(self, key):
|
| 115 |
+
return 120 # ord('x')
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Map all ascii to 120 to avoid __missing__ call, then replace some.
|
| 119 |
+
trans = ParseMap.fromkeys(range(128), 120)
|
| 120 |
+
trans.update((ord(c), ord('(')) for c in "({[") # open brackets => '(';
|
| 121 |
+
trans.update((ord(c), ord(')')) for c in ")}]") # close brackets => ')'.
|
| 122 |
+
trans.update((ord(c), ord(c)) for c in "\"'\\\n#") # Keep these.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class Parser:
|
| 126 |
+
|
| 127 |
+
def __init__(self, indentwidth, tabwidth):
|
| 128 |
+
self.indentwidth = indentwidth
|
| 129 |
+
self.tabwidth = tabwidth
|
| 130 |
+
|
| 131 |
+
def set_code(self, s):
|
| 132 |
+
assert len(s) == 0 or s[-1] == '\n'
|
| 133 |
+
self.code = s
|
| 134 |
+
self.study_level = 0
|
| 135 |
+
|
| 136 |
+
def find_good_parse_start(self, is_char_in_string):
|
| 137 |
+
"""
|
| 138 |
+
Return index of a good place to begin parsing, as close to the
|
| 139 |
+
end of the string as possible. This will be the start of some
|
| 140 |
+
popular stmt like "if" or "def". Return None if none found:
|
| 141 |
+
the caller should pass more prior context then, if possible, or
|
| 142 |
+
if not (the entire program text up until the point of interest
|
| 143 |
+
has already been tried) pass 0 to set_lo().
|
| 144 |
+
|
| 145 |
+
This will be reliable iff given a reliable is_char_in_string()
|
| 146 |
+
function, meaning that when it says "no", it's absolutely
|
| 147 |
+
guaranteed that the char is not in a string.
|
| 148 |
+
"""
|
| 149 |
+
code, pos = self.code, None
|
| 150 |
+
|
| 151 |
+
# Peek back from the end for a good place to start,
|
| 152 |
+
# but don't try too often; pos will be left None, or
|
| 153 |
+
# bumped to a legitimate synch point.
|
| 154 |
+
limit = len(code)
|
| 155 |
+
for tries in range(5):
|
| 156 |
+
i = code.rfind(":\n", 0, limit)
|
| 157 |
+
if i < 0:
|
| 158 |
+
break
|
| 159 |
+
i = code.rfind('\n', 0, i) + 1 # start of colon line (-1+1=0)
|
| 160 |
+
m = _synchre(code, i, limit)
|
| 161 |
+
if m and not is_char_in_string(m.start()):
|
| 162 |
+
pos = m.start()
|
| 163 |
+
break
|
| 164 |
+
limit = i
|
| 165 |
+
if pos is None:
|
| 166 |
+
# Nothing looks like a block-opener, or stuff does
|
| 167 |
+
# but is_char_in_string keeps returning true; most likely
|
| 168 |
+
# we're in or near a giant string, the colorizer hasn't
|
| 169 |
+
# caught up enough to be helpful, or there simply *aren't*
|
| 170 |
+
# any interesting stmts. In any of these cases we're
|
| 171 |
+
# going to have to parse the whole thing to be sure, so
|
| 172 |
+
# give it one last try from the start, but stop wasting
|
| 173 |
+
# time here regardless of the outcome.
|
| 174 |
+
m = _synchre(code)
|
| 175 |
+
if m and not is_char_in_string(m.start()):
|
| 176 |
+
pos = m.start()
|
| 177 |
+
return pos
|
| 178 |
+
|
| 179 |
+
# Peeking back worked; look forward until _synchre no longer
|
| 180 |
+
# matches.
|
| 181 |
+
i = pos + 1
|
| 182 |
+
while m := _synchre(code, i):
|
| 183 |
+
s, i = m.span()
|
| 184 |
+
if not is_char_in_string(s):
|
| 185 |
+
pos = s
|
| 186 |
+
return pos
|
| 187 |
+
|
| 188 |
+
def set_lo(self, lo):
|
| 189 |
+
""" Throw away the start of the string.
|
| 190 |
+
|
| 191 |
+
Intended to be called with the result of find_good_parse_start().
|
| 192 |
+
"""
|
| 193 |
+
assert lo == 0 or self.code[lo-1] == '\n'
|
| 194 |
+
if lo > 0:
|
| 195 |
+
self.code = self.code[lo:]
|
| 196 |
+
|
| 197 |
+
def _study1(self):
|
| 198 |
+
"""Find the line numbers of non-continuation lines.
|
| 199 |
+
|
| 200 |
+
As quickly as humanly possible <wink>, find the line numbers (0-
|
| 201 |
+
based) of the non-continuation lines.
|
| 202 |
+
Creates self.{goodlines, continuation}.
|
| 203 |
+
"""
|
| 204 |
+
if self.study_level >= 1:
|
| 205 |
+
return
|
| 206 |
+
self.study_level = 1
|
| 207 |
+
|
| 208 |
+
# Map all uninteresting characters to "x", all open brackets
|
| 209 |
+
# to "(", all close brackets to ")", then collapse runs of
|
| 210 |
+
# uninteresting characters. This can cut the number of chars
|
| 211 |
+
# by a factor of 10-40, and so greatly speed the following loop.
|
| 212 |
+
code = self.code
|
| 213 |
+
code = code.translate(trans)
|
| 214 |
+
code = code.replace('xxxxxxxx', 'x')
|
| 215 |
+
code = code.replace('xxxx', 'x')
|
| 216 |
+
code = code.replace('xx', 'x')
|
| 217 |
+
code = code.replace('xx', 'x')
|
| 218 |
+
code = code.replace('\nx', '\n')
|
| 219 |
+
# Replacing x\n with \n would be incorrect because
|
| 220 |
+
# x may be preceded by a backslash.
|
| 221 |
+
|
| 222 |
+
# March over the squashed version of the program, accumulating
|
| 223 |
+
# the line numbers of non-continued stmts, and determining
|
| 224 |
+
# whether & why the last stmt is a continuation.
|
| 225 |
+
continuation = C_NONE
|
| 226 |
+
level = lno = 0 # level is nesting level; lno is line number
|
| 227 |
+
self.goodlines = goodlines = [0]
|
| 228 |
+
push_good = goodlines.append
|
| 229 |
+
i, n = 0, len(code)
|
| 230 |
+
while i < n:
|
| 231 |
+
ch = code[i]
|
| 232 |
+
i = i+1
|
| 233 |
+
|
| 234 |
+
# cases are checked in decreasing order of frequency
|
| 235 |
+
if ch == 'x':
|
| 236 |
+
continue
|
| 237 |
+
|
| 238 |
+
if ch == '\n':
|
| 239 |
+
lno = lno + 1
|
| 240 |
+
if level == 0:
|
| 241 |
+
push_good(lno)
|
| 242 |
+
# else we're in an unclosed bracket structure
|
| 243 |
+
continue
|
| 244 |
+
|
| 245 |
+
if ch == '(':
|
| 246 |
+
level = level + 1
|
| 247 |
+
continue
|
| 248 |
+
|
| 249 |
+
if ch == ')':
|
| 250 |
+
if level:
|
| 251 |
+
level = level - 1
|
| 252 |
+
# else the program is invalid, but we can't complain
|
| 253 |
+
continue
|
| 254 |
+
|
| 255 |
+
if ch == '"' or ch == "'":
|
| 256 |
+
# consume the string
|
| 257 |
+
quote = ch
|
| 258 |
+
if code[i-1:i+2] == quote * 3:
|
| 259 |
+
quote = quote * 3
|
| 260 |
+
firstlno = lno
|
| 261 |
+
w = len(quote) - 1
|
| 262 |
+
i = i+w
|
| 263 |
+
while i < n:
|
| 264 |
+
ch = code[i]
|
| 265 |
+
i = i+1
|
| 266 |
+
|
| 267 |
+
if ch == 'x':
|
| 268 |
+
continue
|
| 269 |
+
|
| 270 |
+
if code[i-1:i+w] == quote:
|
| 271 |
+
i = i+w
|
| 272 |
+
break
|
| 273 |
+
|
| 274 |
+
if ch == '\n':
|
| 275 |
+
lno = lno + 1
|
| 276 |
+
if w == 0:
|
| 277 |
+
# unterminated single-quoted string
|
| 278 |
+
if level == 0:
|
| 279 |
+
push_good(lno)
|
| 280 |
+
break
|
| 281 |
+
continue
|
| 282 |
+
|
| 283 |
+
if ch == '\\':
|
| 284 |
+
assert i < n
|
| 285 |
+
if code[i] == '\n':
|
| 286 |
+
lno = lno + 1
|
| 287 |
+
i = i+1
|
| 288 |
+
continue
|
| 289 |
+
|
| 290 |
+
# else comment char or paren inside string
|
| 291 |
+
|
| 292 |
+
else:
|
| 293 |
+
# didn't break out of the loop, so we're still
|
| 294 |
+
# inside a string
|
| 295 |
+
if (lno - 1) == firstlno:
|
| 296 |
+
# before the previous \n in code, we were in the first
|
| 297 |
+
# line of the string
|
| 298 |
+
continuation = C_STRING_FIRST_LINE
|
| 299 |
+
else:
|
| 300 |
+
continuation = C_STRING_NEXT_LINES
|
| 301 |
+
continue # with outer loop
|
| 302 |
+
|
| 303 |
+
if ch == '#':
|
| 304 |
+
# consume the comment
|
| 305 |
+
i = code.find('\n', i)
|
| 306 |
+
assert i >= 0
|
| 307 |
+
continue
|
| 308 |
+
|
| 309 |
+
assert ch == '\\'
|
| 310 |
+
assert i < n
|
| 311 |
+
if code[i] == '\n':
|
| 312 |
+
lno = lno + 1
|
| 313 |
+
if i+1 == n:
|
| 314 |
+
continuation = C_BACKSLASH
|
| 315 |
+
i = i+1
|
| 316 |
+
|
| 317 |
+
# The last stmt may be continued for all 3 reasons.
|
| 318 |
+
# String continuation takes precedence over bracket
|
| 319 |
+
# continuation, which beats backslash continuation.
|
| 320 |
+
if (continuation != C_STRING_FIRST_LINE
|
| 321 |
+
and continuation != C_STRING_NEXT_LINES and level > 0):
|
| 322 |
+
continuation = C_BRACKET
|
| 323 |
+
self.continuation = continuation
|
| 324 |
+
|
| 325 |
+
# Push the final line number as a sentinel value, regardless of
|
| 326 |
+
# whether it's continued.
|
| 327 |
+
assert (continuation == C_NONE) == (goodlines[-1] == lno)
|
| 328 |
+
if goodlines[-1] != lno:
|
| 329 |
+
push_good(lno)
|
| 330 |
+
|
| 331 |
+
def get_continuation_type(self):
|
| 332 |
+
self._study1()
|
| 333 |
+
return self.continuation
|
| 334 |
+
|
| 335 |
+
def _study2(self):
|
| 336 |
+
"""
|
| 337 |
+
study1 was sufficient to determine the continuation status,
|
| 338 |
+
but doing more requires looking at every character. study2
|
| 339 |
+
does this for the last interesting statement in the block.
|
| 340 |
+
Creates:
|
| 341 |
+
self.stmt_start, stmt_end
|
| 342 |
+
slice indices of last interesting stmt
|
| 343 |
+
self.stmt_bracketing
|
| 344 |
+
the bracketing structure of the last interesting stmt; for
|
| 345 |
+
example, for the statement "say(boo) or die",
|
| 346 |
+
stmt_bracketing will be ((0, 0), (0, 1), (2, 0), (2, 1),
|
| 347 |
+
(4, 0)). Strings and comments are treated as brackets, for
|
| 348 |
+
the matter.
|
| 349 |
+
self.lastch
|
| 350 |
+
last interesting character before optional trailing comment
|
| 351 |
+
self.lastopenbracketpos
|
| 352 |
+
if continuation is C_BRACKET, index of last open bracket
|
| 353 |
+
"""
|
| 354 |
+
if self.study_level >= 2:
|
| 355 |
+
return
|
| 356 |
+
self._study1()
|
| 357 |
+
self.study_level = 2
|
| 358 |
+
|
| 359 |
+
# Set p and q to slice indices of last interesting stmt.
|
| 360 |
+
code, goodlines = self.code, self.goodlines
|
| 361 |
+
i = len(goodlines) - 1 # Index of newest line.
|
| 362 |
+
p = len(code) # End of goodlines[i]
|
| 363 |
+
while i:
|
| 364 |
+
assert p
|
| 365 |
+
# Make p be the index of the stmt at line number goodlines[i].
|
| 366 |
+
# Move p back to the stmt at line number goodlines[i-1].
|
| 367 |
+
q = p
|
| 368 |
+
for nothing in range(goodlines[i-1], goodlines[i]):
|
| 369 |
+
# tricky: sets p to 0 if no preceding newline
|
| 370 |
+
p = code.rfind('\n', 0, p-1) + 1
|
| 371 |
+
# The stmt code[p:q] isn't a continuation, but may be blank
|
| 372 |
+
# or a non-indenting comment line.
|
| 373 |
+
if _junkre(code, p):
|
| 374 |
+
i = i-1
|
| 375 |
+
else:
|
| 376 |
+
break
|
| 377 |
+
if i == 0:
|
| 378 |
+
# nothing but junk!
|
| 379 |
+
assert p == 0
|
| 380 |
+
q = p
|
| 381 |
+
self.stmt_start, self.stmt_end = p, q
|
| 382 |
+
|
| 383 |
+
# Analyze this stmt, to find the last open bracket (if any)
|
| 384 |
+
# and last interesting character (if any).
|
| 385 |
+
lastch = ""
|
| 386 |
+
stack = [] # stack of open bracket indices
|
| 387 |
+
push_stack = stack.append
|
| 388 |
+
bracketing = [(p, 0)]
|
| 389 |
+
while p < q:
|
| 390 |
+
# suck up all except ()[]{}'"#\\
|
| 391 |
+
m = _chew_ordinaryre(code, p, q)
|
| 392 |
+
if m:
|
| 393 |
+
# we skipped at least one boring char
|
| 394 |
+
newp = m.end()
|
| 395 |
+
# back up over totally boring whitespace
|
| 396 |
+
i = newp - 1 # index of last boring char
|
| 397 |
+
while i >= p and code[i] in " \t\n":
|
| 398 |
+
i = i-1
|
| 399 |
+
if i >= p:
|
| 400 |
+
lastch = code[i]
|
| 401 |
+
p = newp
|
| 402 |
+
if p >= q:
|
| 403 |
+
break
|
| 404 |
+
|
| 405 |
+
ch = code[p]
|
| 406 |
+
|
| 407 |
+
if ch in "([{":
|
| 408 |
+
push_stack(p)
|
| 409 |
+
bracketing.append((p, len(stack)))
|
| 410 |
+
lastch = ch
|
| 411 |
+
p = p+1
|
| 412 |
+
continue
|
| 413 |
+
|
| 414 |
+
if ch in ")]}":
|
| 415 |
+
if stack:
|
| 416 |
+
del stack[-1]
|
| 417 |
+
lastch = ch
|
| 418 |
+
p = p+1
|
| 419 |
+
bracketing.append((p, len(stack)))
|
| 420 |
+
continue
|
| 421 |
+
|
| 422 |
+
if ch == '"' or ch == "'":
|
| 423 |
+
# consume string
|
| 424 |
+
# Note that study1 did this with a Python loop, but
|
| 425 |
+
# we use a regexp here; the reason is speed in both
|
| 426 |
+
# cases; the string may be huge, but study1 pre-squashed
|
| 427 |
+
# strings to a couple of characters per line. study1
|
| 428 |
+
# also needed to keep track of newlines, and we don't
|
| 429 |
+
# have to.
|
| 430 |
+
bracketing.append((p, len(stack)+1))
|
| 431 |
+
lastch = ch
|
| 432 |
+
p = _match_stringre(code, p, q).end()
|
| 433 |
+
bracketing.append((p, len(stack)))
|
| 434 |
+
continue
|
| 435 |
+
|
| 436 |
+
if ch == '#':
|
| 437 |
+
# consume comment and trailing newline
|
| 438 |
+
bracketing.append((p, len(stack)+1))
|
| 439 |
+
p = code.find('\n', p, q) + 1
|
| 440 |
+
assert p > 0
|
| 441 |
+
bracketing.append((p, len(stack)))
|
| 442 |
+
continue
|
| 443 |
+
|
| 444 |
+
assert ch == '\\'
|
| 445 |
+
p = p+1 # beyond backslash
|
| 446 |
+
assert p < q
|
| 447 |
+
if code[p] != '\n':
|
| 448 |
+
# the program is invalid, but can't complain
|
| 449 |
+
lastch = ch + code[p]
|
| 450 |
+
p = p+1 # beyond escaped char
|
| 451 |
+
|
| 452 |
+
# end while p < q:
|
| 453 |
+
|
| 454 |
+
self.lastch = lastch
|
| 455 |
+
self.lastopenbracketpos = stack[-1] if stack else None
|
| 456 |
+
self.stmt_bracketing = tuple(bracketing)
|
| 457 |
+
|
| 458 |
+
def compute_bracket_indent(self):
|
| 459 |
+
"""Return number of spaces the next line should be indented.
|
| 460 |
+
|
| 461 |
+
Line continuation must be C_BRACKET.
|
| 462 |
+
"""
|
| 463 |
+
self._study2()
|
| 464 |
+
assert self.continuation == C_BRACKET
|
| 465 |
+
j = self.lastopenbracketpos
|
| 466 |
+
code = self.code
|
| 467 |
+
n = len(code)
|
| 468 |
+
origi = i = code.rfind('\n', 0, j) + 1
|
| 469 |
+
j = j+1 # one beyond open bracket
|
| 470 |
+
# find first list item; set i to start of its line
|
| 471 |
+
while j < n:
|
| 472 |
+
m = _itemre(code, j)
|
| 473 |
+
if m:
|
| 474 |
+
j = m.end() - 1 # index of first interesting char
|
| 475 |
+
extra = 0
|
| 476 |
+
break
|
| 477 |
+
else:
|
| 478 |
+
# this line is junk; advance to next line
|
| 479 |
+
i = j = code.find('\n', j) + 1
|
| 480 |
+
else:
|
| 481 |
+
# nothing interesting follows the bracket;
|
| 482 |
+
# reproduce the bracket line's indentation + a level
|
| 483 |
+
j = i = origi
|
| 484 |
+
while code[j] in " \t":
|
| 485 |
+
j = j+1
|
| 486 |
+
extra = self.indentwidth
|
| 487 |
+
return len(code[i:j].expandtabs(self.tabwidth)) + extra
|
| 488 |
+
|
| 489 |
+
def get_num_lines_in_stmt(self):
|
| 490 |
+
"""Return number of physical lines in last stmt.
|
| 491 |
+
|
| 492 |
+
The statement doesn't have to be an interesting statement. This is
|
| 493 |
+
intended to be called when continuation is C_BACKSLASH.
|
| 494 |
+
"""
|
| 495 |
+
self._study1()
|
| 496 |
+
goodlines = self.goodlines
|
| 497 |
+
return goodlines[-1] - goodlines[-2]
|
| 498 |
+
|
| 499 |
+
def compute_backslash_indent(self):
|
| 500 |
+
"""Return number of spaces the next line should be indented.
|
| 501 |
+
|
| 502 |
+
Line continuation must be C_BACKSLASH. Also assume that the new
|
| 503 |
+
line is the first one following the initial line of the stmt.
|
| 504 |
+
"""
|
| 505 |
+
self._study2()
|
| 506 |
+
assert self.continuation == C_BACKSLASH
|
| 507 |
+
code = self.code
|
| 508 |
+
i = self.stmt_start
|
| 509 |
+
while code[i] in " \t":
|
| 510 |
+
i = i+1
|
| 511 |
+
startpos = i
|
| 512 |
+
|
| 513 |
+
# See whether the initial line starts an assignment stmt; i.e.,
|
| 514 |
+
# look for an = operator
|
| 515 |
+
endpos = code.find('\n', startpos) + 1
|
| 516 |
+
found = level = 0
|
| 517 |
+
while i < endpos:
|
| 518 |
+
ch = code[i]
|
| 519 |
+
if ch in "([{":
|
| 520 |
+
level = level + 1
|
| 521 |
+
i = i+1
|
| 522 |
+
elif ch in ")]}":
|
| 523 |
+
if level:
|
| 524 |
+
level = level - 1
|
| 525 |
+
i = i+1
|
| 526 |
+
elif ch == '"' or ch == "'":
|
| 527 |
+
i = _match_stringre(code, i, endpos).end()
|
| 528 |
+
elif ch == '#':
|
| 529 |
+
# This line is unreachable because the # makes a comment of
|
| 530 |
+
# everything after it.
|
| 531 |
+
break
|
| 532 |
+
elif level == 0 and ch == '=' and \
|
| 533 |
+
(i == 0 or code[i-1] not in "=<>!") and \
|
| 534 |
+
code[i+1] != '=':
|
| 535 |
+
found = 1
|
| 536 |
+
break
|
| 537 |
+
else:
|
| 538 |
+
i = i+1
|
| 539 |
+
|
| 540 |
+
if found:
|
| 541 |
+
# found a legit =, but it may be the last interesting
|
| 542 |
+
# thing on the line
|
| 543 |
+
i = i+1 # move beyond the =
|
| 544 |
+
found = re.match(r"\s*\\", code[i:endpos]) is None
|
| 545 |
+
|
| 546 |
+
if not found:
|
| 547 |
+
# oh well ... settle for moving beyond the first chunk
|
| 548 |
+
# of non-whitespace chars
|
| 549 |
+
i = startpos
|
| 550 |
+
while code[i] not in " \t\n":
|
| 551 |
+
i = i+1
|
| 552 |
+
|
| 553 |
+
return len(code[self.stmt_start:i].expandtabs(\
|
| 554 |
+
self.tabwidth)) + 1
|
| 555 |
+
|
| 556 |
+
def get_base_indent_string(self):
|
| 557 |
+
"""Return the leading whitespace on the initial line of the last
|
| 558 |
+
interesting stmt.
|
| 559 |
+
"""
|
| 560 |
+
self._study2()
|
| 561 |
+
i, n = self.stmt_start, self.stmt_end
|
| 562 |
+
j = i
|
| 563 |
+
code = self.code
|
| 564 |
+
while j < n and code[j] in " \t":
|
| 565 |
+
j = j + 1
|
| 566 |
+
return code[i:j]
|
| 567 |
+
|
| 568 |
+
def is_block_opener(self):
|
| 569 |
+
"Return True if the last interesting statement opens a block."
|
| 570 |
+
self._study2()
|
| 571 |
+
return self.lastch == ':'
|
| 572 |
+
|
| 573 |
+
def is_block_closer(self):
|
| 574 |
+
"Return True if the last interesting statement closes a block."
|
| 575 |
+
self._study2()
|
| 576 |
+
return _closere(self.code, self.stmt_start) is not None
|
| 577 |
+
|
| 578 |
+
def get_last_stmt_bracketing(self):
|
| 579 |
+
"""Return bracketing structure of the last interesting statement.
|
| 580 |
+
|
| 581 |
+
The returned tuple is in the format defined in _study2().
|
| 582 |
+
"""
|
| 583 |
+
self._study2()
|
| 584 |
+
return self.stmt_bracketing
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
if __name__ == '__main__':
|
| 588 |
+
from unittest import main
|
| 589 |
+
main('idlelib.idle_test.test_pyparse', verbosity=2)
|
deepseek/lib/python3.10/idlelib/query.py
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Dialogs that query users and verify the answer before accepting.
|
| 3 |
+
|
| 4 |
+
Query is the generic base class for a popup dialog.
|
| 5 |
+
The user must either enter a valid answer or close the dialog.
|
| 6 |
+
Entries are validated when <Return> is entered or [Ok] is clicked.
|
| 7 |
+
Entries are ignored when [Cancel] or [X] are clicked.
|
| 8 |
+
The 'return value' is .result set to either a valid answer or None.
|
| 9 |
+
|
| 10 |
+
Subclass SectionName gets a name for a new config file section.
|
| 11 |
+
Configdialog uses it for new highlight theme and keybinding set names.
|
| 12 |
+
Subclass ModuleName gets a name for File => Open Module.
|
| 13 |
+
Subclass HelpSource gets menu item and path for additions to Help menu.
|
| 14 |
+
"""
|
| 15 |
+
# Query and Section name result from splitting GetCfgSectionNameDialog
|
| 16 |
+
# of configSectionNameDialog.py (temporarily config_sec.py) into
|
| 17 |
+
# generic and specific parts. 3.6 only, July 2016.
|
| 18 |
+
# ModuleName.entry_ok came from editor.EditorWindow.load_module.
|
| 19 |
+
# HelpSource was extracted from configHelpSourceEdit.py (temporarily
|
| 20 |
+
# config_help.py), with darwin code moved from ok to path_ok.
|
| 21 |
+
|
| 22 |
+
import importlib.util, importlib.abc
|
| 23 |
+
import os
|
| 24 |
+
import shlex
|
| 25 |
+
from sys import executable, platform # Platform is set for one test.
|
| 26 |
+
|
| 27 |
+
from tkinter import Toplevel, StringVar, BooleanVar, W, E, S
|
| 28 |
+
from tkinter.ttk import Frame, Button, Entry, Label, Checkbutton
|
| 29 |
+
from tkinter import filedialog
|
| 30 |
+
from tkinter.font import Font
|
| 31 |
+
from tkinter.simpledialog import _setup_dialog
|
| 32 |
+
|
| 33 |
+
class Query(Toplevel):
|
| 34 |
+
"""Base class for getting verified answer from a user.
|
| 35 |
+
|
| 36 |
+
For this base class, accept any non-blank string.
|
| 37 |
+
"""
|
| 38 |
+
def __init__(self, parent, title, message, *, text0='', used_names={},
|
| 39 |
+
_htest=False, _utest=False):
|
| 40 |
+
"""Create modal popup, return when destroyed.
|
| 41 |
+
|
| 42 |
+
Additional subclass init must be done before this unless
|
| 43 |
+
_utest=True is passed to suppress wait_window().
|
| 44 |
+
|
| 45 |
+
title - string, title of popup dialog
|
| 46 |
+
message - string, informational message to display
|
| 47 |
+
text0 - initial value for entry
|
| 48 |
+
used_names - names already in use
|
| 49 |
+
_htest - bool, change box location when running htest
|
| 50 |
+
_utest - bool, leave window hidden and not modal
|
| 51 |
+
"""
|
| 52 |
+
self.parent = parent # Needed for Font call.
|
| 53 |
+
self.message = message
|
| 54 |
+
self.text0 = text0
|
| 55 |
+
self.used_names = used_names
|
| 56 |
+
|
| 57 |
+
Toplevel.__init__(self, parent)
|
| 58 |
+
self.withdraw() # Hide while configuring, especially geometry.
|
| 59 |
+
self.title(title)
|
| 60 |
+
self.transient(parent)
|
| 61 |
+
if not _utest: # Otherwise fail when directly run unittest.
|
| 62 |
+
self.grab_set()
|
| 63 |
+
|
| 64 |
+
_setup_dialog(self)
|
| 65 |
+
if self._windowingsystem == 'aqua':
|
| 66 |
+
self.bind("<Command-.>", self.cancel)
|
| 67 |
+
self.bind('<Key-Escape>', self.cancel)
|
| 68 |
+
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
| 69 |
+
self.bind('<Key-Return>', self.ok)
|
| 70 |
+
self.bind("<KP_Enter>", self.ok)
|
| 71 |
+
|
| 72 |
+
self.create_widgets()
|
| 73 |
+
self.update_idletasks() # Need here for winfo_reqwidth below.
|
| 74 |
+
self.geometry( # Center dialog over parent (or below htest box).
|
| 75 |
+
"+%d+%d" % (
|
| 76 |
+
parent.winfo_rootx() +
|
| 77 |
+
(parent.winfo_width()/2 - self.winfo_reqwidth()/2),
|
| 78 |
+
parent.winfo_rooty() +
|
| 79 |
+
((parent.winfo_height()/2 - self.winfo_reqheight()/2)
|
| 80 |
+
if not _htest else 150)
|
| 81 |
+
) )
|
| 82 |
+
self.resizable(height=False, width=False)
|
| 83 |
+
|
| 84 |
+
if not _utest:
|
| 85 |
+
self.deiconify() # Unhide now that geometry set.
|
| 86 |
+
self.entry.focus_set()
|
| 87 |
+
self.wait_window()
|
| 88 |
+
|
| 89 |
+
def create_widgets(self, ok_text='OK'): # Do not replace.
|
| 90 |
+
"""Create entry (rows, extras, buttons.
|
| 91 |
+
|
| 92 |
+
Entry stuff on rows 0-2, spanning cols 0-2.
|
| 93 |
+
Buttons on row 99, cols 1, 2.
|
| 94 |
+
"""
|
| 95 |
+
# Bind to self the widgets needed for entry_ok or unittest.
|
| 96 |
+
self.frame = frame = Frame(self, padding=10)
|
| 97 |
+
frame.grid(column=0, row=0, sticky='news')
|
| 98 |
+
frame.grid_columnconfigure(0, weight=1)
|
| 99 |
+
|
| 100 |
+
entrylabel = Label(frame, anchor='w', justify='left',
|
| 101 |
+
text=self.message)
|
| 102 |
+
self.entryvar = StringVar(self, self.text0)
|
| 103 |
+
self.entry = Entry(frame, width=30, textvariable=self.entryvar)
|
| 104 |
+
self.error_font = Font(name='TkCaptionFont',
|
| 105 |
+
exists=True, root=self.parent)
|
| 106 |
+
self.entry_error = Label(frame, text=' ', foreground='red',
|
| 107 |
+
font=self.error_font)
|
| 108 |
+
# Display or blank error by setting ['text'] =.
|
| 109 |
+
entrylabel.grid(column=0, row=0, columnspan=3, padx=5, sticky=W)
|
| 110 |
+
self.entry.grid(column=0, row=1, columnspan=3, padx=5, sticky=W+E,
|
| 111 |
+
pady=[10,0])
|
| 112 |
+
self.entry_error.grid(column=0, row=2, columnspan=3, padx=5,
|
| 113 |
+
sticky=W+E)
|
| 114 |
+
|
| 115 |
+
self.create_extra()
|
| 116 |
+
|
| 117 |
+
self.button_ok = Button(
|
| 118 |
+
frame, text=ok_text, default='active', command=self.ok)
|
| 119 |
+
self.button_cancel = Button(
|
| 120 |
+
frame, text='Cancel', command=self.cancel)
|
| 121 |
+
|
| 122 |
+
self.button_ok.grid(column=1, row=99, padx=5)
|
| 123 |
+
self.button_cancel.grid(column=2, row=99, padx=5)
|
| 124 |
+
|
| 125 |
+
def create_extra(self): pass # Override to add widgets.
|
| 126 |
+
|
| 127 |
+
def showerror(self, message, widget=None):
|
| 128 |
+
#self.bell(displayof=self)
|
| 129 |
+
(widget or self.entry_error)['text'] = 'ERROR: ' + message
|
| 130 |
+
|
| 131 |
+
def entry_ok(self): # Example: usually replace.
|
| 132 |
+
"Return non-blank entry or None."
|
| 133 |
+
entry = self.entry.get().strip()
|
| 134 |
+
if not entry:
|
| 135 |
+
self.showerror('blank line.')
|
| 136 |
+
return None
|
| 137 |
+
return entry
|
| 138 |
+
|
| 139 |
+
def ok(self, event=None): # Do not replace.
|
| 140 |
+
'''If entry is valid, bind it to 'result' and destroy tk widget.
|
| 141 |
+
|
| 142 |
+
Otherwise leave dialog open for user to correct entry or cancel.
|
| 143 |
+
'''
|
| 144 |
+
self.entry_error['text'] = ''
|
| 145 |
+
entry = self.entry_ok()
|
| 146 |
+
if entry is not None:
|
| 147 |
+
self.result = entry
|
| 148 |
+
self.destroy()
|
| 149 |
+
else:
|
| 150 |
+
# [Ok] moves focus. (<Return> does not.) Move it back.
|
| 151 |
+
self.entry.focus_set()
|
| 152 |
+
|
| 153 |
+
def cancel(self, event=None): # Do not replace.
|
| 154 |
+
"Set dialog result to None and destroy tk widget."
|
| 155 |
+
self.result = None
|
| 156 |
+
self.destroy()
|
| 157 |
+
|
| 158 |
+
def destroy(self):
|
| 159 |
+
self.grab_release()
|
| 160 |
+
super().destroy()
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
class SectionName(Query):
|
| 164 |
+
"Get a name for a config file section name."
|
| 165 |
+
# Used in ConfigDialog.GetNewKeysName, .GetNewThemeName (837)
|
| 166 |
+
|
| 167 |
+
def __init__(self, parent, title, message, used_names,
|
| 168 |
+
*, _htest=False, _utest=False):
|
| 169 |
+
super().__init__(parent, title, message, used_names=used_names,
|
| 170 |
+
_htest=_htest, _utest=_utest)
|
| 171 |
+
|
| 172 |
+
def entry_ok(self):
|
| 173 |
+
"Return sensible ConfigParser section name or None."
|
| 174 |
+
name = self.entry.get().strip()
|
| 175 |
+
if not name:
|
| 176 |
+
self.showerror('no name specified.')
|
| 177 |
+
return None
|
| 178 |
+
elif len(name)>30:
|
| 179 |
+
self.showerror('name is longer than 30 characters.')
|
| 180 |
+
return None
|
| 181 |
+
elif name in self.used_names:
|
| 182 |
+
self.showerror('name is already in use.')
|
| 183 |
+
return None
|
| 184 |
+
return name
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
class ModuleName(Query):
|
| 188 |
+
"Get a module name for Open Module menu entry."
|
| 189 |
+
# Used in open_module (editor.EditorWindow until move to iobinding).
|
| 190 |
+
|
| 191 |
+
def __init__(self, parent, title, message, text0,
|
| 192 |
+
*, _htest=False, _utest=False):
|
| 193 |
+
super().__init__(parent, title, message, text0=text0,
|
| 194 |
+
_htest=_htest, _utest=_utest)
|
| 195 |
+
|
| 196 |
+
def entry_ok(self):
|
| 197 |
+
"Return entered module name as file path or None."
|
| 198 |
+
name = self.entry.get().strip()
|
| 199 |
+
if not name:
|
| 200 |
+
self.showerror('no name specified.')
|
| 201 |
+
return None
|
| 202 |
+
# XXX Ought to insert current file's directory in front of path.
|
| 203 |
+
try:
|
| 204 |
+
spec = importlib.util.find_spec(name)
|
| 205 |
+
except (ValueError, ImportError) as msg:
|
| 206 |
+
self.showerror(str(msg))
|
| 207 |
+
return None
|
| 208 |
+
if spec is None:
|
| 209 |
+
self.showerror("module not found.")
|
| 210 |
+
return None
|
| 211 |
+
if not isinstance(spec.loader, importlib.abc.SourceLoader):
|
| 212 |
+
self.showerror("not a source-based module.")
|
| 213 |
+
return None
|
| 214 |
+
try:
|
| 215 |
+
file_path = spec.loader.get_filename(name)
|
| 216 |
+
except AttributeError:
|
| 217 |
+
self.showerror("loader does not support get_filename.")
|
| 218 |
+
return None
|
| 219 |
+
except ImportError:
|
| 220 |
+
# Some special modules require this (e.g. os.path)
|
| 221 |
+
try:
|
| 222 |
+
file_path = spec.loader.get_filename()
|
| 223 |
+
except TypeError:
|
| 224 |
+
self.showerror("loader failed to get filename.")
|
| 225 |
+
return None
|
| 226 |
+
return file_path
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class Goto(Query):
|
| 230 |
+
"Get a positive line number for editor Go To Line."
|
| 231 |
+
# Used in editor.EditorWindow.goto_line_event.
|
| 232 |
+
|
| 233 |
+
def entry_ok(self):
|
| 234 |
+
try:
|
| 235 |
+
lineno = int(self.entry.get())
|
| 236 |
+
except ValueError:
|
| 237 |
+
self.showerror('not a base 10 integer.')
|
| 238 |
+
return None
|
| 239 |
+
if lineno <= 0:
|
| 240 |
+
self.showerror('not a positive integer.')
|
| 241 |
+
return None
|
| 242 |
+
return lineno
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
class HelpSource(Query):
|
| 246 |
+
"Get menu name and help source for Help menu."
|
| 247 |
+
# Used in ConfigDialog.HelpListItemAdd/Edit, (941/9)
|
| 248 |
+
|
| 249 |
+
def __init__(self, parent, title, *, menuitem='', filepath='',
|
| 250 |
+
used_names={}, _htest=False, _utest=False):
|
| 251 |
+
"""Get menu entry and url/local file for Additional Help.
|
| 252 |
+
|
| 253 |
+
User enters a name for the Help resource and a web url or file
|
| 254 |
+
name. The user can browse for the file.
|
| 255 |
+
"""
|
| 256 |
+
self.filepath = filepath
|
| 257 |
+
message = 'Name for item on Help menu:'
|
| 258 |
+
super().__init__(
|
| 259 |
+
parent, title, message, text0=menuitem,
|
| 260 |
+
used_names=used_names, _htest=_htest, _utest=_utest)
|
| 261 |
+
|
| 262 |
+
def create_extra(self):
|
| 263 |
+
"Add path widjets to rows 10-12."
|
| 264 |
+
frame = self.frame
|
| 265 |
+
pathlabel = Label(frame, anchor='w', justify='left',
|
| 266 |
+
text='Help File Path: Enter URL or browse for file')
|
| 267 |
+
self.pathvar = StringVar(self, self.filepath)
|
| 268 |
+
self.path = Entry(frame, textvariable=self.pathvar, width=40)
|
| 269 |
+
browse = Button(frame, text='Browse', width=8,
|
| 270 |
+
command=self.browse_file)
|
| 271 |
+
self.path_error = Label(frame, text=' ', foreground='red',
|
| 272 |
+
font=self.error_font)
|
| 273 |
+
|
| 274 |
+
pathlabel.grid(column=0, row=10, columnspan=3, padx=5, pady=[10,0],
|
| 275 |
+
sticky=W)
|
| 276 |
+
self.path.grid(column=0, row=11, columnspan=2, padx=5, sticky=W+E,
|
| 277 |
+
pady=[10,0])
|
| 278 |
+
browse.grid(column=2, row=11, padx=5, sticky=W+S)
|
| 279 |
+
self.path_error.grid(column=0, row=12, columnspan=3, padx=5,
|
| 280 |
+
sticky=W+E)
|
| 281 |
+
|
| 282 |
+
def askfilename(self, filetypes, initdir, initfile): # htest #
|
| 283 |
+
# Extracted from browse_file so can mock for unittests.
|
| 284 |
+
# Cannot unittest as cannot simulate button clicks.
|
| 285 |
+
# Test by running htest, such as by running this file.
|
| 286 |
+
return filedialog.Open(parent=self, filetypes=filetypes)\
|
| 287 |
+
.show(initialdir=initdir, initialfile=initfile)
|
| 288 |
+
|
| 289 |
+
def browse_file(self):
|
| 290 |
+
filetypes = [
|
| 291 |
+
("HTML Files", "*.htm *.html", "TEXT"),
|
| 292 |
+
("PDF Files", "*.pdf", "TEXT"),
|
| 293 |
+
("Windows Help Files", "*.chm"),
|
| 294 |
+
("Text Files", "*.txt", "TEXT"),
|
| 295 |
+
("All Files", "*")]
|
| 296 |
+
path = self.pathvar.get()
|
| 297 |
+
if path:
|
| 298 |
+
dir, base = os.path.split(path)
|
| 299 |
+
else:
|
| 300 |
+
base = None
|
| 301 |
+
if platform[:3] == 'win':
|
| 302 |
+
dir = os.path.join(os.path.dirname(executable), 'Doc')
|
| 303 |
+
if not os.path.isdir(dir):
|
| 304 |
+
dir = os.getcwd()
|
| 305 |
+
else:
|
| 306 |
+
dir = os.getcwd()
|
| 307 |
+
file = self.askfilename(filetypes, dir, base)
|
| 308 |
+
if file:
|
| 309 |
+
self.pathvar.set(file)
|
| 310 |
+
|
| 311 |
+
item_ok = SectionName.entry_ok # localize for test override
|
| 312 |
+
|
| 313 |
+
def path_ok(self):
|
| 314 |
+
"Simple validity check for menu file path"
|
| 315 |
+
path = self.path.get().strip()
|
| 316 |
+
if not path: #no path specified
|
| 317 |
+
self.showerror('no help file path specified.', self.path_error)
|
| 318 |
+
return None
|
| 319 |
+
elif not path.startswith(('www.', 'http')):
|
| 320 |
+
if path[:5] == 'file:':
|
| 321 |
+
path = path[5:]
|
| 322 |
+
if not os.path.exists(path):
|
| 323 |
+
self.showerror('help file path does not exist.',
|
| 324 |
+
self.path_error)
|
| 325 |
+
return None
|
| 326 |
+
if platform == 'darwin': # for Mac Safari
|
| 327 |
+
path = "file://" + path
|
| 328 |
+
return path
|
| 329 |
+
|
| 330 |
+
def entry_ok(self):
|
| 331 |
+
"Return apparently valid (name, path) or None"
|
| 332 |
+
self.path_error['text'] = ''
|
| 333 |
+
name = self.item_ok()
|
| 334 |
+
path = self.path_ok()
|
| 335 |
+
return None if name is None or path is None else (name, path)
|
| 336 |
+
|
| 337 |
+
class CustomRun(Query):
|
| 338 |
+
"""Get settings for custom run of module.
|
| 339 |
+
|
| 340 |
+
1. Command line arguments to extend sys.argv.
|
| 341 |
+
2. Whether to restart Shell or not.
|
| 342 |
+
"""
|
| 343 |
+
# Used in runscript.run_custom_event
|
| 344 |
+
|
| 345 |
+
def __init__(self, parent, title, *, cli_args=[],
|
| 346 |
+
_htest=False, _utest=False):
|
| 347 |
+
"""cli_args is a list of strings.
|
| 348 |
+
|
| 349 |
+
The list is assigned to the default Entry StringVar.
|
| 350 |
+
The strings are displayed joined by ' ' for display.
|
| 351 |
+
"""
|
| 352 |
+
message = 'Command Line Arguments for sys.argv:'
|
| 353 |
+
super().__init__(
|
| 354 |
+
parent, title, message, text0=cli_args,
|
| 355 |
+
_htest=_htest, _utest=_utest)
|
| 356 |
+
|
| 357 |
+
def create_extra(self):
|
| 358 |
+
"Add run mode on rows 10-12."
|
| 359 |
+
frame = self.frame
|
| 360 |
+
self.restartvar = BooleanVar(self, value=True)
|
| 361 |
+
restart = Checkbutton(frame, variable=self.restartvar, onvalue=True,
|
| 362 |
+
offvalue=False, text='Restart shell')
|
| 363 |
+
self.args_error = Label(frame, text=' ', foreground='red',
|
| 364 |
+
font=self.error_font)
|
| 365 |
+
|
| 366 |
+
restart.grid(column=0, row=10, columnspan=3, padx=5, sticky='w')
|
| 367 |
+
self.args_error.grid(column=0, row=12, columnspan=3, padx=5,
|
| 368 |
+
sticky='we')
|
| 369 |
+
|
| 370 |
+
def cli_args_ok(self):
|
| 371 |
+
"Validity check and parsing for command line arguments."
|
| 372 |
+
cli_string = self.entry.get().strip()
|
| 373 |
+
try:
|
| 374 |
+
cli_args = shlex.split(cli_string, posix=True)
|
| 375 |
+
except ValueError as err:
|
| 376 |
+
self.showerror(str(err))
|
| 377 |
+
return None
|
| 378 |
+
return cli_args
|
| 379 |
+
|
| 380 |
+
def entry_ok(self):
|
| 381 |
+
"Return apparently valid (cli_args, restart) or None."
|
| 382 |
+
cli_args = self.cli_args_ok()
|
| 383 |
+
restart = self.restartvar.get()
|
| 384 |
+
return None if cli_args is None else (cli_args, restart)
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
if __name__ == '__main__':
|
| 388 |
+
from unittest import main
|
| 389 |
+
main('idlelib.idle_test.test_query', verbosity=2, exit=False)
|
| 390 |
+
|
| 391 |
+
from idlelib.idle_test.htest import run
|
| 392 |
+
run(Query, HelpSource, CustomRun)
|
deepseek/lib/python3.10/idlelib/replace.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Replace dialog for IDLE. Inherits SearchDialogBase for GUI.
|
| 2 |
+
Uses idlelib.searchengine.SearchEngine for search capability.
|
| 3 |
+
Defines various replace related functions like replace, replace all,
|
| 4 |
+
and replace+find.
|
| 5 |
+
"""
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
from tkinter import StringVar, TclError
|
| 9 |
+
|
| 10 |
+
from idlelib.searchbase import SearchDialogBase
|
| 11 |
+
from idlelib import searchengine
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def replace(text, insert_tags=None):
|
| 15 |
+
"""Create or reuse a singleton ReplaceDialog instance.
|
| 16 |
+
|
| 17 |
+
The singleton dialog saves user entries and preferences
|
| 18 |
+
across instances.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
text: Text widget containing the text to be searched.
|
| 22 |
+
"""
|
| 23 |
+
root = text._root()
|
| 24 |
+
engine = searchengine.get(root)
|
| 25 |
+
if not hasattr(engine, "_replacedialog"):
|
| 26 |
+
engine._replacedialog = ReplaceDialog(root, engine)
|
| 27 |
+
dialog = engine._replacedialog
|
| 28 |
+
dialog.open(text, insert_tags=insert_tags)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ReplaceDialog(SearchDialogBase):
|
| 32 |
+
"Dialog for finding and replacing a pattern in text."
|
| 33 |
+
|
| 34 |
+
title = "Replace Dialog"
|
| 35 |
+
icon = "Replace"
|
| 36 |
+
|
| 37 |
+
def __init__(self, root, engine):
|
| 38 |
+
"""Create search dialog for finding and replacing text.
|
| 39 |
+
|
| 40 |
+
Uses SearchDialogBase as the basis for the GUI and a
|
| 41 |
+
searchengine instance to prepare the search.
|
| 42 |
+
|
| 43 |
+
Attributes:
|
| 44 |
+
replvar: StringVar containing 'Replace with:' value.
|
| 45 |
+
replent: Entry widget for replvar. Created in
|
| 46 |
+
create_entries().
|
| 47 |
+
ok: Boolean used in searchengine.search_text to indicate
|
| 48 |
+
whether the search includes the selection.
|
| 49 |
+
"""
|
| 50 |
+
super().__init__(root, engine)
|
| 51 |
+
self.replvar = StringVar(root)
|
| 52 |
+
self.insert_tags = None
|
| 53 |
+
|
| 54 |
+
def open(self, text, insert_tags=None):
|
| 55 |
+
"""Make dialog visible on top of others and ready to use.
|
| 56 |
+
|
| 57 |
+
Also, highlight the currently selected text and set the
|
| 58 |
+
search to include the current selection (self.ok).
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
text: Text widget being searched.
|
| 62 |
+
"""
|
| 63 |
+
SearchDialogBase.open(self, text)
|
| 64 |
+
try:
|
| 65 |
+
first = text.index("sel.first")
|
| 66 |
+
except TclError:
|
| 67 |
+
first = None
|
| 68 |
+
try:
|
| 69 |
+
last = text.index("sel.last")
|
| 70 |
+
except TclError:
|
| 71 |
+
last = None
|
| 72 |
+
first = first or text.index("insert")
|
| 73 |
+
last = last or first
|
| 74 |
+
self.show_hit(first, last)
|
| 75 |
+
self.ok = True
|
| 76 |
+
self.insert_tags = insert_tags
|
| 77 |
+
|
| 78 |
+
def create_entries(self):
|
| 79 |
+
"Create base and additional label and text entry widgets."
|
| 80 |
+
SearchDialogBase.create_entries(self)
|
| 81 |
+
self.replent = self.make_entry("Replace with:", self.replvar)[0]
|
| 82 |
+
|
| 83 |
+
def create_command_buttons(self):
|
| 84 |
+
"""Create base and additional command buttons.
|
| 85 |
+
|
| 86 |
+
The additional buttons are for Find, Replace,
|
| 87 |
+
Replace+Find, and Replace All.
|
| 88 |
+
"""
|
| 89 |
+
SearchDialogBase.create_command_buttons(self)
|
| 90 |
+
self.make_button("Find", self.find_it)
|
| 91 |
+
self.make_button("Replace", self.replace_it)
|
| 92 |
+
self.make_button("Replace+Find", self.default_command, isdef=True)
|
| 93 |
+
self.make_button("Replace All", self.replace_all)
|
| 94 |
+
|
| 95 |
+
def find_it(self, event=None):
|
| 96 |
+
"Handle the Find button."
|
| 97 |
+
self.do_find(False)
|
| 98 |
+
|
| 99 |
+
def replace_it(self, event=None):
|
| 100 |
+
"""Handle the Replace button.
|
| 101 |
+
|
| 102 |
+
If the find is successful, then perform replace.
|
| 103 |
+
"""
|
| 104 |
+
if self.do_find(self.ok):
|
| 105 |
+
self.do_replace()
|
| 106 |
+
|
| 107 |
+
def default_command(self, event=None):
|
| 108 |
+
"""Handle the Replace+Find button as the default command.
|
| 109 |
+
|
| 110 |
+
First performs a replace and then, if the replace was
|
| 111 |
+
successful, a find next.
|
| 112 |
+
"""
|
| 113 |
+
if self.do_find(self.ok):
|
| 114 |
+
if self.do_replace(): # Only find next match if replace succeeded.
|
| 115 |
+
# A bad re can cause it to fail.
|
| 116 |
+
self.do_find(False)
|
| 117 |
+
|
| 118 |
+
def _replace_expand(self, m, repl):
|
| 119 |
+
"Expand replacement text if regular expression."
|
| 120 |
+
if self.engine.isre():
|
| 121 |
+
try:
|
| 122 |
+
new = m.expand(repl)
|
| 123 |
+
except re.error:
|
| 124 |
+
self.engine.report_error(repl, 'Invalid Replace Expression')
|
| 125 |
+
new = None
|
| 126 |
+
else:
|
| 127 |
+
new = repl
|
| 128 |
+
|
| 129 |
+
return new
|
| 130 |
+
|
| 131 |
+
def replace_all(self, event=None):
|
| 132 |
+
"""Handle the Replace All button.
|
| 133 |
+
|
| 134 |
+
Search text for occurrences of the Find value and replace
|
| 135 |
+
each of them. The 'wrap around' value controls the start
|
| 136 |
+
point for searching. If wrap isn't set, then the searching
|
| 137 |
+
starts at the first occurrence after the current selection;
|
| 138 |
+
if wrap is set, the replacement starts at the first line.
|
| 139 |
+
The replacement is always done top-to-bottom in the text.
|
| 140 |
+
"""
|
| 141 |
+
prog = self.engine.getprog()
|
| 142 |
+
if not prog:
|
| 143 |
+
return
|
| 144 |
+
repl = self.replvar.get()
|
| 145 |
+
text = self.text
|
| 146 |
+
res = self.engine.search_text(text, prog)
|
| 147 |
+
if not res:
|
| 148 |
+
self.bell()
|
| 149 |
+
return
|
| 150 |
+
text.tag_remove("sel", "1.0", "end")
|
| 151 |
+
text.tag_remove("hit", "1.0", "end")
|
| 152 |
+
line = res[0]
|
| 153 |
+
col = res[1].start()
|
| 154 |
+
if self.engine.iswrap():
|
| 155 |
+
line = 1
|
| 156 |
+
col = 0
|
| 157 |
+
ok = True
|
| 158 |
+
first = last = None
|
| 159 |
+
# XXX ought to replace circular instead of top-to-bottom when wrapping
|
| 160 |
+
text.undo_block_start()
|
| 161 |
+
while res := self.engine.search_forward(
|
| 162 |
+
text, prog, line, col, wrap=False, ok=ok):
|
| 163 |
+
line, m = res
|
| 164 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 165 |
+
orig = m.group()
|
| 166 |
+
new = self._replace_expand(m, repl)
|
| 167 |
+
if new is None:
|
| 168 |
+
break
|
| 169 |
+
i, j = m.span()
|
| 170 |
+
first = "%d.%d" % (line, i)
|
| 171 |
+
last = "%d.%d" % (line, j)
|
| 172 |
+
if new == orig:
|
| 173 |
+
text.mark_set("insert", last)
|
| 174 |
+
else:
|
| 175 |
+
text.mark_set("insert", first)
|
| 176 |
+
if first != last:
|
| 177 |
+
text.delete(first, last)
|
| 178 |
+
if new:
|
| 179 |
+
text.insert(first, new, self.insert_tags)
|
| 180 |
+
col = i + len(new)
|
| 181 |
+
ok = False
|
| 182 |
+
text.undo_block_stop()
|
| 183 |
+
if first and last:
|
| 184 |
+
self.show_hit(first, last)
|
| 185 |
+
self.close()
|
| 186 |
+
|
| 187 |
+
def do_find(self, ok=False):
|
| 188 |
+
"""Search for and highlight next occurrence of pattern in text.
|
| 189 |
+
|
| 190 |
+
No text replacement is done with this option.
|
| 191 |
+
"""
|
| 192 |
+
if not self.engine.getprog():
|
| 193 |
+
return False
|
| 194 |
+
text = self.text
|
| 195 |
+
res = self.engine.search_text(text, None, ok)
|
| 196 |
+
if not res:
|
| 197 |
+
self.bell()
|
| 198 |
+
return False
|
| 199 |
+
line, m = res
|
| 200 |
+
i, j = m.span()
|
| 201 |
+
first = "%d.%d" % (line, i)
|
| 202 |
+
last = "%d.%d" % (line, j)
|
| 203 |
+
self.show_hit(first, last)
|
| 204 |
+
self.ok = True
|
| 205 |
+
return True
|
| 206 |
+
|
| 207 |
+
def do_replace(self):
|
| 208 |
+
"Replace search pattern in text with replacement value."
|
| 209 |
+
prog = self.engine.getprog()
|
| 210 |
+
if not prog:
|
| 211 |
+
return False
|
| 212 |
+
text = self.text
|
| 213 |
+
try:
|
| 214 |
+
first = pos = text.index("sel.first")
|
| 215 |
+
last = text.index("sel.last")
|
| 216 |
+
except TclError:
|
| 217 |
+
pos = None
|
| 218 |
+
if not pos:
|
| 219 |
+
first = last = pos = text.index("insert")
|
| 220 |
+
line, col = searchengine.get_line_col(pos)
|
| 221 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 222 |
+
m = prog.match(chars, col)
|
| 223 |
+
if not prog:
|
| 224 |
+
return False
|
| 225 |
+
new = self._replace_expand(m, self.replvar.get())
|
| 226 |
+
if new is None:
|
| 227 |
+
return False
|
| 228 |
+
text.mark_set("insert", first)
|
| 229 |
+
text.undo_block_start()
|
| 230 |
+
if m.group():
|
| 231 |
+
text.delete(first, last)
|
| 232 |
+
if new:
|
| 233 |
+
text.insert(first, new, self.insert_tags)
|
| 234 |
+
text.undo_block_stop()
|
| 235 |
+
self.show_hit(first, text.index("insert"))
|
| 236 |
+
self.ok = False
|
| 237 |
+
return True
|
| 238 |
+
|
| 239 |
+
def show_hit(self, first, last):
|
| 240 |
+
"""Highlight text between first and last indices.
|
| 241 |
+
|
| 242 |
+
Text is highlighted via the 'hit' tag and the marked
|
| 243 |
+
section is brought into view.
|
| 244 |
+
|
| 245 |
+
The colors from the 'hit' tag aren't currently shown
|
| 246 |
+
when the text is displayed. This is due to the 'sel'
|
| 247 |
+
tag being added first, so the colors in the 'sel'
|
| 248 |
+
config are seen instead of the colors for 'hit'.
|
| 249 |
+
"""
|
| 250 |
+
text = self.text
|
| 251 |
+
text.mark_set("insert", first)
|
| 252 |
+
text.tag_remove("sel", "1.0", "end")
|
| 253 |
+
text.tag_add("sel", first, last)
|
| 254 |
+
text.tag_remove("hit", "1.0", "end")
|
| 255 |
+
if first == last:
|
| 256 |
+
text.tag_add("hit", first)
|
| 257 |
+
else:
|
| 258 |
+
text.tag_add("hit", first, last)
|
| 259 |
+
text.see("insert")
|
| 260 |
+
text.update_idletasks()
|
| 261 |
+
|
| 262 |
+
def close(self, event=None):
|
| 263 |
+
"Close the dialog and remove hit tags."
|
| 264 |
+
SearchDialogBase.close(self, event)
|
| 265 |
+
self.text.tag_remove("hit", "1.0", "end")
|
| 266 |
+
self.insert_tags = None
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def _replace_dialog(parent): # htest #
|
| 270 |
+
from tkinter import Toplevel, Text, END, SEL
|
| 271 |
+
from tkinter.ttk import Frame, Button
|
| 272 |
+
|
| 273 |
+
top = Toplevel(parent)
|
| 274 |
+
top.title("Test ReplaceDialog")
|
| 275 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 276 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 277 |
+
|
| 278 |
+
# mock undo delegator methods
|
| 279 |
+
def undo_block_start():
|
| 280 |
+
pass
|
| 281 |
+
|
| 282 |
+
def undo_block_stop():
|
| 283 |
+
pass
|
| 284 |
+
|
| 285 |
+
frame = Frame(top)
|
| 286 |
+
frame.pack()
|
| 287 |
+
text = Text(frame, inactiveselectbackground='gray')
|
| 288 |
+
text.undo_block_start = undo_block_start
|
| 289 |
+
text.undo_block_stop = undo_block_stop
|
| 290 |
+
text.pack()
|
| 291 |
+
text.insert("insert","This is a sample sTring\nPlus MORE.")
|
| 292 |
+
text.focus_set()
|
| 293 |
+
|
| 294 |
+
def show_replace():
|
| 295 |
+
text.tag_add(SEL, "1.0", END)
|
| 296 |
+
replace(text)
|
| 297 |
+
text.tag_remove(SEL, "1.0", END)
|
| 298 |
+
|
| 299 |
+
button = Button(frame, text="Replace", command=show_replace)
|
| 300 |
+
button.pack()
|
| 301 |
+
|
| 302 |
+
if __name__ == '__main__':
|
| 303 |
+
from unittest import main
|
| 304 |
+
main('idlelib.idle_test.test_replace', verbosity=2, exit=False)
|
| 305 |
+
|
| 306 |
+
from idlelib.idle_test.htest import run
|
| 307 |
+
run(_replace_dialog)
|
deepseek/lib/python3.10/idlelib/rpc.py
ADDED
|
@@ -0,0 +1,635 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""RPC Implementation, originally written for the Python Idle IDE
|
| 2 |
+
|
| 3 |
+
For security reasons, GvR requested that Idle's Python execution server process
|
| 4 |
+
connect to the Idle process, which listens for the connection. Since Idle has
|
| 5 |
+
only one client per server, this was not a limitation.
|
| 6 |
+
|
| 7 |
+
+---------------------------------+ +-------------+
|
| 8 |
+
| socketserver.BaseRequestHandler | | SocketIO |
|
| 9 |
+
+---------------------------------+ +-------------+
|
| 10 |
+
^ | register() |
|
| 11 |
+
| | unregister()|
|
| 12 |
+
| +-------------+
|
| 13 |
+
| ^ ^
|
| 14 |
+
| | |
|
| 15 |
+
| + -------------------+ |
|
| 16 |
+
| | |
|
| 17 |
+
+-------------------------+ +-----------------+
|
| 18 |
+
| RPCHandler | | RPCClient |
|
| 19 |
+
| [attribute of RPCServer]| | |
|
| 20 |
+
+-------------------------+ +-----------------+
|
| 21 |
+
|
| 22 |
+
The RPCServer handler class is expected to provide register/unregister methods.
|
| 23 |
+
RPCHandler inherits the mix-in class SocketIO, which provides these methods.
|
| 24 |
+
|
| 25 |
+
See the Idle run.main() docstring for further information on how this was
|
| 26 |
+
accomplished in Idle.
|
| 27 |
+
|
| 28 |
+
"""
|
| 29 |
+
import builtins
|
| 30 |
+
import copyreg
|
| 31 |
+
import io
|
| 32 |
+
import marshal
|
| 33 |
+
import os
|
| 34 |
+
import pickle
|
| 35 |
+
import queue
|
| 36 |
+
import select
|
| 37 |
+
import socket
|
| 38 |
+
import socketserver
|
| 39 |
+
import struct
|
| 40 |
+
import sys
|
| 41 |
+
import threading
|
| 42 |
+
import traceback
|
| 43 |
+
import types
|
| 44 |
+
|
| 45 |
+
def unpickle_code(ms):
|
| 46 |
+
"Return code object from marshal string ms."
|
| 47 |
+
co = marshal.loads(ms)
|
| 48 |
+
assert isinstance(co, types.CodeType)
|
| 49 |
+
return co
|
| 50 |
+
|
| 51 |
+
def pickle_code(co):
|
| 52 |
+
"Return unpickle function and tuple with marshalled co code object."
|
| 53 |
+
assert isinstance(co, types.CodeType)
|
| 54 |
+
ms = marshal.dumps(co)
|
| 55 |
+
return unpickle_code, (ms,)
|
| 56 |
+
|
| 57 |
+
def dumps(obj, protocol=None):
|
| 58 |
+
"Return pickled (or marshalled) string for obj."
|
| 59 |
+
# IDLE passes 'None' to select pickle.DEFAULT_PROTOCOL.
|
| 60 |
+
f = io.BytesIO()
|
| 61 |
+
p = CodePickler(f, protocol)
|
| 62 |
+
p.dump(obj)
|
| 63 |
+
return f.getvalue()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class CodePickler(pickle.Pickler):
|
| 67 |
+
dispatch_table = {types.CodeType: pickle_code, **copyreg.dispatch_table}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
BUFSIZE = 8*1024
|
| 71 |
+
LOCALHOST = '127.0.0.1'
|
| 72 |
+
|
| 73 |
+
class RPCServer(socketserver.TCPServer):
|
| 74 |
+
|
| 75 |
+
def __init__(self, addr, handlerclass=None):
|
| 76 |
+
if handlerclass is None:
|
| 77 |
+
handlerclass = RPCHandler
|
| 78 |
+
socketserver.TCPServer.__init__(self, addr, handlerclass)
|
| 79 |
+
|
| 80 |
+
def server_bind(self):
|
| 81 |
+
"Override TCPServer method, no bind() phase for connecting entity"
|
| 82 |
+
pass
|
| 83 |
+
|
| 84 |
+
def server_activate(self):
|
| 85 |
+
"""Override TCPServer method, connect() instead of listen()
|
| 86 |
+
|
| 87 |
+
Due to the reversed connection, self.server_address is actually the
|
| 88 |
+
address of the Idle Client to which we are connecting.
|
| 89 |
+
|
| 90 |
+
"""
|
| 91 |
+
self.socket.connect(self.server_address)
|
| 92 |
+
|
| 93 |
+
def get_request(self):
|
| 94 |
+
"Override TCPServer method, return already connected socket"
|
| 95 |
+
return self.socket, self.server_address
|
| 96 |
+
|
| 97 |
+
def handle_error(self, request, client_address):
|
| 98 |
+
"""Override TCPServer method
|
| 99 |
+
|
| 100 |
+
Error message goes to __stderr__. No error message if exiting
|
| 101 |
+
normally or socket raised EOF. Other exceptions not handled in
|
| 102 |
+
server code will cause os._exit.
|
| 103 |
+
|
| 104 |
+
"""
|
| 105 |
+
try:
|
| 106 |
+
raise
|
| 107 |
+
except SystemExit:
|
| 108 |
+
raise
|
| 109 |
+
except:
|
| 110 |
+
erf = sys.__stderr__
|
| 111 |
+
print('\n' + '-'*40, file=erf)
|
| 112 |
+
print('Unhandled server exception!', file=erf)
|
| 113 |
+
print('Thread: %s' % threading.current_thread().name, file=erf)
|
| 114 |
+
print('Client Address: ', client_address, file=erf)
|
| 115 |
+
print('Request: ', repr(request), file=erf)
|
| 116 |
+
traceback.print_exc(file=erf)
|
| 117 |
+
print('\n*** Unrecoverable, server exiting!', file=erf)
|
| 118 |
+
print('-'*40, file=erf)
|
| 119 |
+
os._exit(0)
|
| 120 |
+
|
| 121 |
+
#----------------- end class RPCServer --------------------
|
| 122 |
+
|
| 123 |
+
objecttable = {}
|
| 124 |
+
request_queue = queue.Queue(0)
|
| 125 |
+
response_queue = queue.Queue(0)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class SocketIO:
|
| 129 |
+
|
| 130 |
+
nextseq = 0
|
| 131 |
+
|
| 132 |
+
def __init__(self, sock, objtable=None, debugging=None):
|
| 133 |
+
self.sockthread = threading.current_thread()
|
| 134 |
+
if debugging is not None:
|
| 135 |
+
self.debugging = debugging
|
| 136 |
+
self.sock = sock
|
| 137 |
+
if objtable is None:
|
| 138 |
+
objtable = objecttable
|
| 139 |
+
self.objtable = objtable
|
| 140 |
+
self.responses = {}
|
| 141 |
+
self.cvars = {}
|
| 142 |
+
|
| 143 |
+
def close(self):
|
| 144 |
+
sock = self.sock
|
| 145 |
+
self.sock = None
|
| 146 |
+
if sock is not None:
|
| 147 |
+
sock.close()
|
| 148 |
+
|
| 149 |
+
def exithook(self):
|
| 150 |
+
"override for specific exit action"
|
| 151 |
+
os._exit(0)
|
| 152 |
+
|
| 153 |
+
def debug(self, *args):
|
| 154 |
+
if not self.debugging:
|
| 155 |
+
return
|
| 156 |
+
s = self.location + " " + str(threading.current_thread().name)
|
| 157 |
+
for a in args:
|
| 158 |
+
s = s + " " + str(a)
|
| 159 |
+
print(s, file=sys.__stderr__)
|
| 160 |
+
|
| 161 |
+
def register(self, oid, object):
|
| 162 |
+
self.objtable[oid] = object
|
| 163 |
+
|
| 164 |
+
def unregister(self, oid):
|
| 165 |
+
try:
|
| 166 |
+
del self.objtable[oid]
|
| 167 |
+
except KeyError:
|
| 168 |
+
pass
|
| 169 |
+
|
| 170 |
+
def localcall(self, seq, request):
|
| 171 |
+
self.debug("localcall:", request)
|
| 172 |
+
try:
|
| 173 |
+
how, (oid, methodname, args, kwargs) = request
|
| 174 |
+
except TypeError:
|
| 175 |
+
return ("ERROR", "Bad request format")
|
| 176 |
+
if oid not in self.objtable:
|
| 177 |
+
return ("ERROR", "Unknown object id: %r" % (oid,))
|
| 178 |
+
obj = self.objtable[oid]
|
| 179 |
+
if methodname == "__methods__":
|
| 180 |
+
methods = {}
|
| 181 |
+
_getmethods(obj, methods)
|
| 182 |
+
return ("OK", methods)
|
| 183 |
+
if methodname == "__attributes__":
|
| 184 |
+
attributes = {}
|
| 185 |
+
_getattributes(obj, attributes)
|
| 186 |
+
return ("OK", attributes)
|
| 187 |
+
if not hasattr(obj, methodname):
|
| 188 |
+
return ("ERROR", "Unsupported method name: %r" % (methodname,))
|
| 189 |
+
method = getattr(obj, methodname)
|
| 190 |
+
try:
|
| 191 |
+
if how == 'CALL':
|
| 192 |
+
ret = method(*args, **kwargs)
|
| 193 |
+
if isinstance(ret, RemoteObject):
|
| 194 |
+
ret = remoteref(ret)
|
| 195 |
+
return ("OK", ret)
|
| 196 |
+
elif how == 'QUEUE':
|
| 197 |
+
request_queue.put((seq, (method, args, kwargs)))
|
| 198 |
+
return("QUEUED", None)
|
| 199 |
+
else:
|
| 200 |
+
return ("ERROR", "Unsupported message type: %s" % how)
|
| 201 |
+
except SystemExit:
|
| 202 |
+
raise
|
| 203 |
+
except KeyboardInterrupt:
|
| 204 |
+
raise
|
| 205 |
+
except OSError:
|
| 206 |
+
raise
|
| 207 |
+
except Exception as ex:
|
| 208 |
+
return ("CALLEXC", ex)
|
| 209 |
+
except:
|
| 210 |
+
msg = "*** Internal Error: rpc.py:SocketIO.localcall()\n\n"\
|
| 211 |
+
" Object: %s \n Method: %s \n Args: %s\n"
|
| 212 |
+
print(msg % (oid, method, args), file=sys.__stderr__)
|
| 213 |
+
traceback.print_exc(file=sys.__stderr__)
|
| 214 |
+
return ("EXCEPTION", None)
|
| 215 |
+
|
| 216 |
+
def remotecall(self, oid, methodname, args, kwargs):
|
| 217 |
+
self.debug("remotecall:asynccall: ", oid, methodname)
|
| 218 |
+
seq = self.asynccall(oid, methodname, args, kwargs)
|
| 219 |
+
return self.asyncreturn(seq)
|
| 220 |
+
|
| 221 |
+
def remotequeue(self, oid, methodname, args, kwargs):
|
| 222 |
+
self.debug("remotequeue:asyncqueue: ", oid, methodname)
|
| 223 |
+
seq = self.asyncqueue(oid, methodname, args, kwargs)
|
| 224 |
+
return self.asyncreturn(seq)
|
| 225 |
+
|
| 226 |
+
def asynccall(self, oid, methodname, args, kwargs):
|
| 227 |
+
request = ("CALL", (oid, methodname, args, kwargs))
|
| 228 |
+
seq = self.newseq()
|
| 229 |
+
if threading.current_thread() != self.sockthread:
|
| 230 |
+
cvar = threading.Condition()
|
| 231 |
+
self.cvars[seq] = cvar
|
| 232 |
+
self.debug(("asynccall:%d:" % seq), oid, methodname, args, kwargs)
|
| 233 |
+
self.putmessage((seq, request))
|
| 234 |
+
return seq
|
| 235 |
+
|
| 236 |
+
def asyncqueue(self, oid, methodname, args, kwargs):
|
| 237 |
+
request = ("QUEUE", (oid, methodname, args, kwargs))
|
| 238 |
+
seq = self.newseq()
|
| 239 |
+
if threading.current_thread() != self.sockthread:
|
| 240 |
+
cvar = threading.Condition()
|
| 241 |
+
self.cvars[seq] = cvar
|
| 242 |
+
self.debug(("asyncqueue:%d:" % seq), oid, methodname, args, kwargs)
|
| 243 |
+
self.putmessage((seq, request))
|
| 244 |
+
return seq
|
| 245 |
+
|
| 246 |
+
def asyncreturn(self, seq):
|
| 247 |
+
self.debug("asyncreturn:%d:call getresponse(): " % seq)
|
| 248 |
+
response = self.getresponse(seq, wait=0.05)
|
| 249 |
+
self.debug(("asyncreturn:%d:response: " % seq), response)
|
| 250 |
+
return self.decoderesponse(response)
|
| 251 |
+
|
| 252 |
+
def decoderesponse(self, response):
|
| 253 |
+
how, what = response
|
| 254 |
+
if how == "OK":
|
| 255 |
+
return what
|
| 256 |
+
if how == "QUEUED":
|
| 257 |
+
return None
|
| 258 |
+
if how == "EXCEPTION":
|
| 259 |
+
self.debug("decoderesponse: EXCEPTION")
|
| 260 |
+
return None
|
| 261 |
+
if how == "EOF":
|
| 262 |
+
self.debug("decoderesponse: EOF")
|
| 263 |
+
self.decode_interrupthook()
|
| 264 |
+
return None
|
| 265 |
+
if how == "ERROR":
|
| 266 |
+
self.debug("decoderesponse: Internal ERROR:", what)
|
| 267 |
+
raise RuntimeError(what)
|
| 268 |
+
if how == "CALLEXC":
|
| 269 |
+
self.debug("decoderesponse: Call Exception:", what)
|
| 270 |
+
raise what
|
| 271 |
+
raise SystemError(how, what)
|
| 272 |
+
|
| 273 |
+
def decode_interrupthook(self):
|
| 274 |
+
""
|
| 275 |
+
raise EOFError
|
| 276 |
+
|
| 277 |
+
def mainloop(self):
|
| 278 |
+
"""Listen on socket until I/O not ready or EOF
|
| 279 |
+
|
| 280 |
+
pollresponse() will loop looking for seq number None, which
|
| 281 |
+
never comes, and exit on EOFError.
|
| 282 |
+
|
| 283 |
+
"""
|
| 284 |
+
try:
|
| 285 |
+
self.getresponse(myseq=None, wait=0.05)
|
| 286 |
+
except EOFError:
|
| 287 |
+
self.debug("mainloop:return")
|
| 288 |
+
return
|
| 289 |
+
|
| 290 |
+
def getresponse(self, myseq, wait):
|
| 291 |
+
response = self._getresponse(myseq, wait)
|
| 292 |
+
if response is not None:
|
| 293 |
+
how, what = response
|
| 294 |
+
if how == "OK":
|
| 295 |
+
response = how, self._proxify(what)
|
| 296 |
+
return response
|
| 297 |
+
|
| 298 |
+
def _proxify(self, obj):
|
| 299 |
+
if isinstance(obj, RemoteProxy):
|
| 300 |
+
return RPCProxy(self, obj.oid)
|
| 301 |
+
if isinstance(obj, list):
|
| 302 |
+
return list(map(self._proxify, obj))
|
| 303 |
+
# XXX Check for other types -- not currently needed
|
| 304 |
+
return obj
|
| 305 |
+
|
| 306 |
+
def _getresponse(self, myseq, wait):
|
| 307 |
+
self.debug("_getresponse:myseq:", myseq)
|
| 308 |
+
if threading.current_thread() is self.sockthread:
|
| 309 |
+
# this thread does all reading of requests or responses
|
| 310 |
+
while True:
|
| 311 |
+
response = self.pollresponse(myseq, wait)
|
| 312 |
+
if response is not None:
|
| 313 |
+
return response
|
| 314 |
+
else:
|
| 315 |
+
# wait for notification from socket handling thread
|
| 316 |
+
cvar = self.cvars[myseq]
|
| 317 |
+
cvar.acquire()
|
| 318 |
+
while myseq not in self.responses:
|
| 319 |
+
cvar.wait()
|
| 320 |
+
response = self.responses[myseq]
|
| 321 |
+
self.debug("_getresponse:%s: thread woke up: response: %s" %
|
| 322 |
+
(myseq, response))
|
| 323 |
+
del self.responses[myseq]
|
| 324 |
+
del self.cvars[myseq]
|
| 325 |
+
cvar.release()
|
| 326 |
+
return response
|
| 327 |
+
|
| 328 |
+
def newseq(self):
|
| 329 |
+
self.nextseq = seq = self.nextseq + 2
|
| 330 |
+
return seq
|
| 331 |
+
|
| 332 |
+
def putmessage(self, message):
|
| 333 |
+
self.debug("putmessage:%d:" % message[0])
|
| 334 |
+
try:
|
| 335 |
+
s = dumps(message)
|
| 336 |
+
except pickle.PicklingError:
|
| 337 |
+
print("Cannot pickle:", repr(message), file=sys.__stderr__)
|
| 338 |
+
raise
|
| 339 |
+
s = struct.pack("<i", len(s)) + s
|
| 340 |
+
while len(s) > 0:
|
| 341 |
+
try:
|
| 342 |
+
r, w, x = select.select([], [self.sock], [])
|
| 343 |
+
n = self.sock.send(s[:BUFSIZE])
|
| 344 |
+
except (AttributeError, TypeError):
|
| 345 |
+
raise OSError("socket no longer exists")
|
| 346 |
+
s = s[n:]
|
| 347 |
+
|
| 348 |
+
buff = b''
|
| 349 |
+
bufneed = 4
|
| 350 |
+
bufstate = 0 # meaning: 0 => reading count; 1 => reading data
|
| 351 |
+
|
| 352 |
+
def pollpacket(self, wait):
|
| 353 |
+
self._stage0()
|
| 354 |
+
if len(self.buff) < self.bufneed:
|
| 355 |
+
r, w, x = select.select([self.sock.fileno()], [], [], wait)
|
| 356 |
+
if len(r) == 0:
|
| 357 |
+
return None
|
| 358 |
+
try:
|
| 359 |
+
s = self.sock.recv(BUFSIZE)
|
| 360 |
+
except OSError:
|
| 361 |
+
raise EOFError
|
| 362 |
+
if len(s) == 0:
|
| 363 |
+
raise EOFError
|
| 364 |
+
self.buff += s
|
| 365 |
+
self._stage0()
|
| 366 |
+
return self._stage1()
|
| 367 |
+
|
| 368 |
+
def _stage0(self):
|
| 369 |
+
if self.bufstate == 0 and len(self.buff) >= 4:
|
| 370 |
+
s = self.buff[:4]
|
| 371 |
+
self.buff = self.buff[4:]
|
| 372 |
+
self.bufneed = struct.unpack("<i", s)[0]
|
| 373 |
+
self.bufstate = 1
|
| 374 |
+
|
| 375 |
+
def _stage1(self):
|
| 376 |
+
if self.bufstate == 1 and len(self.buff) >= self.bufneed:
|
| 377 |
+
packet = self.buff[:self.bufneed]
|
| 378 |
+
self.buff = self.buff[self.bufneed:]
|
| 379 |
+
self.bufneed = 4
|
| 380 |
+
self.bufstate = 0
|
| 381 |
+
return packet
|
| 382 |
+
|
| 383 |
+
def pollmessage(self, wait):
|
| 384 |
+
packet = self.pollpacket(wait)
|
| 385 |
+
if packet is None:
|
| 386 |
+
return None
|
| 387 |
+
try:
|
| 388 |
+
message = pickle.loads(packet)
|
| 389 |
+
except pickle.UnpicklingError:
|
| 390 |
+
print("-----------------------", file=sys.__stderr__)
|
| 391 |
+
print("cannot unpickle packet:", repr(packet), file=sys.__stderr__)
|
| 392 |
+
traceback.print_stack(file=sys.__stderr__)
|
| 393 |
+
print("-----------------------", file=sys.__stderr__)
|
| 394 |
+
raise
|
| 395 |
+
return message
|
| 396 |
+
|
| 397 |
+
def pollresponse(self, myseq, wait):
|
| 398 |
+
"""Handle messages received on the socket.
|
| 399 |
+
|
| 400 |
+
Some messages received may be asynchronous 'call' or 'queue' requests,
|
| 401 |
+
and some may be responses for other threads.
|
| 402 |
+
|
| 403 |
+
'call' requests are passed to self.localcall() with the expectation of
|
| 404 |
+
immediate execution, during which time the socket is not serviced.
|
| 405 |
+
|
| 406 |
+
'queue' requests are used for tasks (which may block or hang) to be
|
| 407 |
+
processed in a different thread. These requests are fed into
|
| 408 |
+
request_queue by self.localcall(). Responses to queued requests are
|
| 409 |
+
taken from response_queue and sent across the link with the associated
|
| 410 |
+
sequence numbers. Messages in the queues are (sequence_number,
|
| 411 |
+
request/response) tuples and code using this module removing messages
|
| 412 |
+
from the request_queue is responsible for returning the correct
|
| 413 |
+
sequence number in the response_queue.
|
| 414 |
+
|
| 415 |
+
pollresponse() will loop until a response message with the myseq
|
| 416 |
+
sequence number is received, and will save other responses in
|
| 417 |
+
self.responses and notify the owning thread.
|
| 418 |
+
|
| 419 |
+
"""
|
| 420 |
+
while True:
|
| 421 |
+
# send queued response if there is one available
|
| 422 |
+
try:
|
| 423 |
+
qmsg = response_queue.get(0)
|
| 424 |
+
except queue.Empty:
|
| 425 |
+
pass
|
| 426 |
+
else:
|
| 427 |
+
seq, response = qmsg
|
| 428 |
+
message = (seq, ('OK', response))
|
| 429 |
+
self.putmessage(message)
|
| 430 |
+
# poll for message on link
|
| 431 |
+
try:
|
| 432 |
+
message = self.pollmessage(wait)
|
| 433 |
+
if message is None: # socket not ready
|
| 434 |
+
return None
|
| 435 |
+
except EOFError:
|
| 436 |
+
self.handle_EOF()
|
| 437 |
+
return None
|
| 438 |
+
except AttributeError:
|
| 439 |
+
return None
|
| 440 |
+
seq, resq = message
|
| 441 |
+
how = resq[0]
|
| 442 |
+
self.debug("pollresponse:%d:myseq:%s" % (seq, myseq))
|
| 443 |
+
# process or queue a request
|
| 444 |
+
if how in ("CALL", "QUEUE"):
|
| 445 |
+
self.debug("pollresponse:%d:localcall:call:" % seq)
|
| 446 |
+
response = self.localcall(seq, resq)
|
| 447 |
+
self.debug("pollresponse:%d:localcall:response:%s"
|
| 448 |
+
% (seq, response))
|
| 449 |
+
if how == "CALL":
|
| 450 |
+
self.putmessage((seq, response))
|
| 451 |
+
elif how == "QUEUE":
|
| 452 |
+
# don't acknowledge the 'queue' request!
|
| 453 |
+
pass
|
| 454 |
+
continue
|
| 455 |
+
# return if completed message transaction
|
| 456 |
+
elif seq == myseq:
|
| 457 |
+
return resq
|
| 458 |
+
# must be a response for a different thread:
|
| 459 |
+
else:
|
| 460 |
+
cv = self.cvars.get(seq, None)
|
| 461 |
+
# response involving unknown sequence number is discarded,
|
| 462 |
+
# probably intended for prior incarnation of server
|
| 463 |
+
if cv is not None:
|
| 464 |
+
cv.acquire()
|
| 465 |
+
self.responses[seq] = resq
|
| 466 |
+
cv.notify()
|
| 467 |
+
cv.release()
|
| 468 |
+
continue
|
| 469 |
+
|
| 470 |
+
def handle_EOF(self):
|
| 471 |
+
"action taken upon link being closed by peer"
|
| 472 |
+
self.EOFhook()
|
| 473 |
+
self.debug("handle_EOF")
|
| 474 |
+
for key in self.cvars:
|
| 475 |
+
cv = self.cvars[key]
|
| 476 |
+
cv.acquire()
|
| 477 |
+
self.responses[key] = ('EOF', None)
|
| 478 |
+
cv.notify()
|
| 479 |
+
cv.release()
|
| 480 |
+
# call our (possibly overridden) exit function
|
| 481 |
+
self.exithook()
|
| 482 |
+
|
| 483 |
+
def EOFhook(self):
|
| 484 |
+
"Classes using rpc client/server can override to augment EOF action"
|
| 485 |
+
pass
|
| 486 |
+
|
| 487 |
+
#----------------- end class SocketIO --------------------
|
| 488 |
+
|
| 489 |
+
class RemoteObject:
|
| 490 |
+
# Token mix-in class
|
| 491 |
+
pass
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def remoteref(obj):
|
| 495 |
+
oid = id(obj)
|
| 496 |
+
objecttable[oid] = obj
|
| 497 |
+
return RemoteProxy(oid)
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
class RemoteProxy:
|
| 501 |
+
|
| 502 |
+
def __init__(self, oid):
|
| 503 |
+
self.oid = oid
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
class RPCHandler(socketserver.BaseRequestHandler, SocketIO):
|
| 507 |
+
|
| 508 |
+
debugging = False
|
| 509 |
+
location = "#S" # Server
|
| 510 |
+
|
| 511 |
+
def __init__(self, sock, addr, svr):
|
| 512 |
+
svr.current_handler = self ## cgt xxx
|
| 513 |
+
SocketIO.__init__(self, sock)
|
| 514 |
+
socketserver.BaseRequestHandler.__init__(self, sock, addr, svr)
|
| 515 |
+
|
| 516 |
+
def handle(self):
|
| 517 |
+
"handle() method required by socketserver"
|
| 518 |
+
self.mainloop()
|
| 519 |
+
|
| 520 |
+
def get_remote_proxy(self, oid):
|
| 521 |
+
return RPCProxy(self, oid)
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
class RPCClient(SocketIO):
|
| 525 |
+
|
| 526 |
+
debugging = False
|
| 527 |
+
location = "#C" # Client
|
| 528 |
+
|
| 529 |
+
nextseq = 1 # Requests coming from the client are odd numbered
|
| 530 |
+
|
| 531 |
+
def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):
|
| 532 |
+
self.listening_sock = socket.socket(family, type)
|
| 533 |
+
self.listening_sock.bind(address)
|
| 534 |
+
self.listening_sock.listen(1)
|
| 535 |
+
|
| 536 |
+
def accept(self):
|
| 537 |
+
working_sock, address = self.listening_sock.accept()
|
| 538 |
+
if self.debugging:
|
| 539 |
+
print("****** Connection request from ", address, file=sys.__stderr__)
|
| 540 |
+
if address[0] == LOCALHOST:
|
| 541 |
+
SocketIO.__init__(self, working_sock)
|
| 542 |
+
else:
|
| 543 |
+
print("** Invalid host: ", address, file=sys.__stderr__)
|
| 544 |
+
raise OSError
|
| 545 |
+
|
| 546 |
+
def get_remote_proxy(self, oid):
|
| 547 |
+
return RPCProxy(self, oid)
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
class RPCProxy:
|
| 551 |
+
|
| 552 |
+
__methods = None
|
| 553 |
+
__attributes = None
|
| 554 |
+
|
| 555 |
+
def __init__(self, sockio, oid):
|
| 556 |
+
self.sockio = sockio
|
| 557 |
+
self.oid = oid
|
| 558 |
+
|
| 559 |
+
def __getattr__(self, name):
|
| 560 |
+
if self.__methods is None:
|
| 561 |
+
self.__getmethods()
|
| 562 |
+
if self.__methods.get(name):
|
| 563 |
+
return MethodProxy(self.sockio, self.oid, name)
|
| 564 |
+
if self.__attributes is None:
|
| 565 |
+
self.__getattributes()
|
| 566 |
+
if name in self.__attributes:
|
| 567 |
+
value = self.sockio.remotecall(self.oid, '__getattribute__',
|
| 568 |
+
(name,), {})
|
| 569 |
+
return value
|
| 570 |
+
else:
|
| 571 |
+
raise AttributeError(name)
|
| 572 |
+
|
| 573 |
+
def __getattributes(self):
|
| 574 |
+
self.__attributes = self.sockio.remotecall(self.oid,
|
| 575 |
+
"__attributes__", (), {})
|
| 576 |
+
|
| 577 |
+
def __getmethods(self):
|
| 578 |
+
self.__methods = self.sockio.remotecall(self.oid,
|
| 579 |
+
"__methods__", (), {})
|
| 580 |
+
|
| 581 |
+
def _getmethods(obj, methods):
|
| 582 |
+
# Helper to get a list of methods from an object
|
| 583 |
+
# Adds names to dictionary argument 'methods'
|
| 584 |
+
for name in dir(obj):
|
| 585 |
+
attr = getattr(obj, name)
|
| 586 |
+
if callable(attr):
|
| 587 |
+
methods[name] = 1
|
| 588 |
+
if isinstance(obj, type):
|
| 589 |
+
for super in obj.__bases__:
|
| 590 |
+
_getmethods(super, methods)
|
| 591 |
+
|
| 592 |
+
def _getattributes(obj, attributes):
|
| 593 |
+
for name in dir(obj):
|
| 594 |
+
attr = getattr(obj, name)
|
| 595 |
+
if not callable(attr):
|
| 596 |
+
attributes[name] = 1
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
class MethodProxy:
|
| 600 |
+
|
| 601 |
+
def __init__(self, sockio, oid, name):
|
| 602 |
+
self.sockio = sockio
|
| 603 |
+
self.oid = oid
|
| 604 |
+
self.name = name
|
| 605 |
+
|
| 606 |
+
def __call__(self, /, *args, **kwargs):
|
| 607 |
+
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
|
| 608 |
+
return value
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
# XXX KBK 09Sep03 We need a proper unit test for this module. Previously
|
| 612 |
+
# existing test code was removed at Rev 1.27 (r34098).
|
| 613 |
+
|
| 614 |
+
def displayhook(value):
|
| 615 |
+
"""Override standard display hook to use non-locale encoding"""
|
| 616 |
+
if value is None:
|
| 617 |
+
return
|
| 618 |
+
# Set '_' to None to avoid recursion
|
| 619 |
+
builtins._ = None
|
| 620 |
+
text = repr(value)
|
| 621 |
+
try:
|
| 622 |
+
sys.stdout.write(text)
|
| 623 |
+
except UnicodeEncodeError:
|
| 624 |
+
# let's use ascii while utf8-bmp codec doesn't present
|
| 625 |
+
encoding = 'ascii'
|
| 626 |
+
bytes = text.encode(encoding, 'backslashreplace')
|
| 627 |
+
text = bytes.decode(encoding, 'strict')
|
| 628 |
+
sys.stdout.write(text)
|
| 629 |
+
sys.stdout.write("\n")
|
| 630 |
+
builtins._ = value
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
if __name__ == '__main__':
|
| 634 |
+
from unittest import main
|
| 635 |
+
main('idlelib.idle_test.test_rpc', verbosity=2,)
|
deepseek/lib/python3.10/idlelib/run.py
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" idlelib.run
|
| 2 |
+
|
| 3 |
+
Simplified, pyshell.ModifiedInterpreter spawns a subprocess with
|
| 4 |
+
f'''{sys.executable} -c "__import__('idlelib.run').run.main()"'''
|
| 5 |
+
'.run' is needed because __import__ returns idlelib, not idlelib.run.
|
| 6 |
+
"""
|
| 7 |
+
import contextlib
|
| 8 |
+
import functools
|
| 9 |
+
import io
|
| 10 |
+
import linecache
|
| 11 |
+
import queue
|
| 12 |
+
import sys
|
| 13 |
+
import textwrap
|
| 14 |
+
import time
|
| 15 |
+
import traceback
|
| 16 |
+
import _thread as thread
|
| 17 |
+
import threading
|
| 18 |
+
import warnings
|
| 19 |
+
|
| 20 |
+
import idlelib # testing
|
| 21 |
+
from idlelib import autocomplete # AutoComplete, fetch_encodings
|
| 22 |
+
from idlelib import calltip # Calltip
|
| 23 |
+
from idlelib import debugger_r # start_debugger
|
| 24 |
+
from idlelib import debugobj_r # remote_object_tree_item
|
| 25 |
+
from idlelib import iomenu # encoding
|
| 26 |
+
from idlelib import rpc # multiple objects
|
| 27 |
+
from idlelib import stackviewer # StackTreeItem
|
| 28 |
+
import __main__
|
| 29 |
+
|
| 30 |
+
import tkinter # Use tcl and, if startup fails, messagebox.
|
| 31 |
+
if not hasattr(sys.modules['idlelib.run'], 'firstrun'):
|
| 32 |
+
# Undo modifications of tkinter by idlelib imports; see bpo-25507.
|
| 33 |
+
for mod in ('simpledialog', 'messagebox', 'font',
|
| 34 |
+
'dialog', 'filedialog', 'commondialog',
|
| 35 |
+
'ttk'):
|
| 36 |
+
delattr(tkinter, mod)
|
| 37 |
+
del sys.modules['tkinter.' + mod]
|
| 38 |
+
# Avoid AttributeError if run again; see bpo-37038.
|
| 39 |
+
sys.modules['idlelib.run'].firstrun = False
|
| 40 |
+
|
| 41 |
+
LOCALHOST = '127.0.0.1'
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
eof = 'Ctrl-D (end-of-file)'
|
| 45 |
+
exit.eof = eof
|
| 46 |
+
quit.eof = eof
|
| 47 |
+
except NameError: # In case subprocess started with -S (maybe in future).
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def idle_formatwarning(message, category, filename, lineno, line=None):
|
| 52 |
+
"""Format warnings the IDLE way."""
|
| 53 |
+
|
| 54 |
+
s = "\nWarning (from warnings module):\n"
|
| 55 |
+
s += ' File \"%s\", line %s\n' % (filename, lineno)
|
| 56 |
+
if line is None:
|
| 57 |
+
line = linecache.getline(filename, lineno)
|
| 58 |
+
line = line.strip()
|
| 59 |
+
if line:
|
| 60 |
+
s += " %s\n" % line
|
| 61 |
+
s += "%s: %s\n" % (category.__name__, message)
|
| 62 |
+
return s
|
| 63 |
+
|
| 64 |
+
def idle_showwarning_subproc(
|
| 65 |
+
message, category, filename, lineno, file=None, line=None):
|
| 66 |
+
"""Show Idle-format warning after replacing warnings.showwarning.
|
| 67 |
+
|
| 68 |
+
The only difference is the formatter called.
|
| 69 |
+
"""
|
| 70 |
+
if file is None:
|
| 71 |
+
file = sys.stderr
|
| 72 |
+
try:
|
| 73 |
+
file.write(idle_formatwarning(
|
| 74 |
+
message, category, filename, lineno, line))
|
| 75 |
+
except OSError:
|
| 76 |
+
pass # the file (probably stderr) is invalid - this warning gets lost.
|
| 77 |
+
|
| 78 |
+
_warnings_showwarning = None
|
| 79 |
+
|
| 80 |
+
def capture_warnings(capture):
|
| 81 |
+
"Replace warning.showwarning with idle_showwarning_subproc, or reverse."
|
| 82 |
+
|
| 83 |
+
global _warnings_showwarning
|
| 84 |
+
if capture:
|
| 85 |
+
if _warnings_showwarning is None:
|
| 86 |
+
_warnings_showwarning = warnings.showwarning
|
| 87 |
+
warnings.showwarning = idle_showwarning_subproc
|
| 88 |
+
else:
|
| 89 |
+
if _warnings_showwarning is not None:
|
| 90 |
+
warnings.showwarning = _warnings_showwarning
|
| 91 |
+
_warnings_showwarning = None
|
| 92 |
+
|
| 93 |
+
capture_warnings(True)
|
| 94 |
+
tcl = tkinter.Tcl()
|
| 95 |
+
|
| 96 |
+
def handle_tk_events(tcl=tcl):
|
| 97 |
+
"""Process any tk events that are ready to be dispatched if tkinter
|
| 98 |
+
has been imported, a tcl interpreter has been created and tk has been
|
| 99 |
+
loaded."""
|
| 100 |
+
tcl.eval("update")
|
| 101 |
+
|
| 102 |
+
# Thread shared globals: Establish a queue between a subthread (which handles
|
| 103 |
+
# the socket) and the main thread (which runs user code), plus global
|
| 104 |
+
# completion, exit and interruptable (the main thread) flags:
|
| 105 |
+
|
| 106 |
+
exit_now = False
|
| 107 |
+
quitting = False
|
| 108 |
+
interruptable = False
|
| 109 |
+
|
| 110 |
+
def main(del_exitfunc=False):
|
| 111 |
+
"""Start the Python execution server in a subprocess
|
| 112 |
+
|
| 113 |
+
In the Python subprocess, RPCServer is instantiated with handlerclass
|
| 114 |
+
MyHandler, which inherits register/unregister methods from RPCHandler via
|
| 115 |
+
the mix-in class SocketIO.
|
| 116 |
+
|
| 117 |
+
When the RPCServer 'server' is instantiated, the TCPServer initialization
|
| 118 |
+
creates an instance of run.MyHandler and calls its handle() method.
|
| 119 |
+
handle() instantiates a run.Executive object, passing it a reference to the
|
| 120 |
+
MyHandler object. That reference is saved as attribute rpchandler of the
|
| 121 |
+
Executive instance. The Executive methods have access to the reference and
|
| 122 |
+
can pass it on to entities that they command
|
| 123 |
+
(e.g. debugger_r.Debugger.start_debugger()). The latter, in turn, can
|
| 124 |
+
call MyHandler(SocketIO) register/unregister methods via the reference to
|
| 125 |
+
register and unregister themselves.
|
| 126 |
+
|
| 127 |
+
"""
|
| 128 |
+
global exit_now
|
| 129 |
+
global quitting
|
| 130 |
+
global no_exitfunc
|
| 131 |
+
no_exitfunc = del_exitfunc
|
| 132 |
+
#time.sleep(15) # test subprocess not responding
|
| 133 |
+
try:
|
| 134 |
+
assert(len(sys.argv) > 1)
|
| 135 |
+
port = int(sys.argv[-1])
|
| 136 |
+
except:
|
| 137 |
+
print("IDLE Subprocess: no IP port passed in sys.argv.",
|
| 138 |
+
file=sys.__stderr__)
|
| 139 |
+
return
|
| 140 |
+
|
| 141 |
+
capture_warnings(True)
|
| 142 |
+
sys.argv[:] = [""]
|
| 143 |
+
sockthread = threading.Thread(target=manage_socket,
|
| 144 |
+
name='SockThread',
|
| 145 |
+
args=((LOCALHOST, port),))
|
| 146 |
+
sockthread.daemon = True
|
| 147 |
+
sockthread.start()
|
| 148 |
+
while True:
|
| 149 |
+
try:
|
| 150 |
+
if exit_now:
|
| 151 |
+
try:
|
| 152 |
+
exit()
|
| 153 |
+
except KeyboardInterrupt:
|
| 154 |
+
# exiting but got an extra KBI? Try again!
|
| 155 |
+
continue
|
| 156 |
+
try:
|
| 157 |
+
request = rpc.request_queue.get(block=True, timeout=0.05)
|
| 158 |
+
except queue.Empty:
|
| 159 |
+
request = None
|
| 160 |
+
# Issue 32207: calling handle_tk_events here adds spurious
|
| 161 |
+
# queue.Empty traceback to event handling exceptions.
|
| 162 |
+
if request:
|
| 163 |
+
seq, (method, args, kwargs) = request
|
| 164 |
+
ret = method(*args, **kwargs)
|
| 165 |
+
rpc.response_queue.put((seq, ret))
|
| 166 |
+
else:
|
| 167 |
+
handle_tk_events()
|
| 168 |
+
except KeyboardInterrupt:
|
| 169 |
+
if quitting:
|
| 170 |
+
exit_now = True
|
| 171 |
+
continue
|
| 172 |
+
except SystemExit:
|
| 173 |
+
capture_warnings(False)
|
| 174 |
+
raise
|
| 175 |
+
except:
|
| 176 |
+
type, value, tb = sys.exc_info()
|
| 177 |
+
try:
|
| 178 |
+
print_exception()
|
| 179 |
+
rpc.response_queue.put((seq, None))
|
| 180 |
+
except:
|
| 181 |
+
# Link didn't work, print same exception to __stderr__
|
| 182 |
+
traceback.print_exception(type, value, tb, file=sys.__stderr__)
|
| 183 |
+
exit()
|
| 184 |
+
else:
|
| 185 |
+
continue
|
| 186 |
+
|
| 187 |
+
def manage_socket(address):
|
| 188 |
+
for i in range(3):
|
| 189 |
+
time.sleep(i)
|
| 190 |
+
try:
|
| 191 |
+
server = MyRPCServer(address, MyHandler)
|
| 192 |
+
break
|
| 193 |
+
except OSError as err:
|
| 194 |
+
print("IDLE Subprocess: OSError: " + err.args[1] +
|
| 195 |
+
", retrying....", file=sys.__stderr__)
|
| 196 |
+
socket_error = err
|
| 197 |
+
else:
|
| 198 |
+
print("IDLE Subprocess: Connection to "
|
| 199 |
+
"IDLE GUI failed, exiting.", file=sys.__stderr__)
|
| 200 |
+
show_socket_error(socket_error, address)
|
| 201 |
+
global exit_now
|
| 202 |
+
exit_now = True
|
| 203 |
+
return
|
| 204 |
+
server.handle_request() # A single request only
|
| 205 |
+
|
| 206 |
+
def show_socket_error(err, address):
|
| 207 |
+
"Display socket error from manage_socket."
|
| 208 |
+
import tkinter
|
| 209 |
+
from tkinter.messagebox import showerror
|
| 210 |
+
root = tkinter.Tk()
|
| 211 |
+
fix_scaling(root)
|
| 212 |
+
root.withdraw()
|
| 213 |
+
showerror(
|
| 214 |
+
"Subprocess Connection Error",
|
| 215 |
+
f"IDLE's subprocess can't connect to {address[0]}:{address[1]}.\n"
|
| 216 |
+
f"Fatal OSError #{err.errno}: {err.strerror}.\n"
|
| 217 |
+
"See the 'Startup failure' section of the IDLE doc, online at\n"
|
| 218 |
+
"https://docs.python.org/3/library/idle.html#startup-failure",
|
| 219 |
+
parent=root)
|
| 220 |
+
root.destroy()
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def get_message_lines(typ, exc, tb):
|
| 224 |
+
"Return line composing the exception message."
|
| 225 |
+
if typ in (AttributeError, NameError):
|
| 226 |
+
# 3.10+ hints are not directly accessible from python (#44026).
|
| 227 |
+
err = io.StringIO()
|
| 228 |
+
with contextlib.redirect_stderr(err):
|
| 229 |
+
sys.__excepthook__(typ, exc, tb)
|
| 230 |
+
return [err.getvalue().split("\n")[-2] + "\n"]
|
| 231 |
+
else:
|
| 232 |
+
return traceback.format_exception_only(typ, exc)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def print_exception():
|
| 236 |
+
import linecache
|
| 237 |
+
linecache.checkcache()
|
| 238 |
+
flush_stdout()
|
| 239 |
+
efile = sys.stderr
|
| 240 |
+
typ, val, tb = excinfo = sys.exc_info()
|
| 241 |
+
sys.last_type, sys.last_value, sys.last_traceback = excinfo
|
| 242 |
+
seen = set()
|
| 243 |
+
|
| 244 |
+
def print_exc(typ, exc, tb):
|
| 245 |
+
seen.add(id(exc))
|
| 246 |
+
context = exc.__context__
|
| 247 |
+
cause = exc.__cause__
|
| 248 |
+
if cause is not None and id(cause) not in seen:
|
| 249 |
+
print_exc(type(cause), cause, cause.__traceback__)
|
| 250 |
+
print("\nThe above exception was the direct cause "
|
| 251 |
+
"of the following exception:\n", file=efile)
|
| 252 |
+
elif (context is not None and
|
| 253 |
+
not exc.__suppress_context__ and
|
| 254 |
+
id(context) not in seen):
|
| 255 |
+
print_exc(type(context), context, context.__traceback__)
|
| 256 |
+
print("\nDuring handling of the above exception, "
|
| 257 |
+
"another exception occurred:\n", file=efile)
|
| 258 |
+
if tb:
|
| 259 |
+
tbe = traceback.extract_tb(tb)
|
| 260 |
+
print('Traceback (most recent call last):', file=efile)
|
| 261 |
+
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
|
| 262 |
+
"debugger_r.py", "bdb.py")
|
| 263 |
+
cleanup_traceback(tbe, exclude)
|
| 264 |
+
traceback.print_list(tbe, file=efile)
|
| 265 |
+
lines = get_message_lines(typ, exc, tb)
|
| 266 |
+
for line in lines:
|
| 267 |
+
print(line, end='', file=efile)
|
| 268 |
+
|
| 269 |
+
print_exc(typ, val, tb)
|
| 270 |
+
|
| 271 |
+
def cleanup_traceback(tb, exclude):
|
| 272 |
+
"Remove excluded traces from beginning/end of tb; get cached lines"
|
| 273 |
+
orig_tb = tb[:]
|
| 274 |
+
while tb:
|
| 275 |
+
for rpcfile in exclude:
|
| 276 |
+
if tb[0][0].count(rpcfile):
|
| 277 |
+
break # found an exclude, break for: and delete tb[0]
|
| 278 |
+
else:
|
| 279 |
+
break # no excludes, have left RPC code, break while:
|
| 280 |
+
del tb[0]
|
| 281 |
+
while tb:
|
| 282 |
+
for rpcfile in exclude:
|
| 283 |
+
if tb[-1][0].count(rpcfile):
|
| 284 |
+
break
|
| 285 |
+
else:
|
| 286 |
+
break
|
| 287 |
+
del tb[-1]
|
| 288 |
+
if len(tb) == 0:
|
| 289 |
+
# exception was in IDLE internals, don't prune!
|
| 290 |
+
tb[:] = orig_tb[:]
|
| 291 |
+
print("** IDLE Internal Exception: ", file=sys.stderr)
|
| 292 |
+
rpchandler = rpc.objecttable['exec'].rpchandler
|
| 293 |
+
for i in range(len(tb)):
|
| 294 |
+
fn, ln, nm, line = tb[i]
|
| 295 |
+
if nm == '?':
|
| 296 |
+
nm = "-toplevel-"
|
| 297 |
+
if not line and fn.startswith("<pyshell#"):
|
| 298 |
+
line = rpchandler.remotecall('linecache', 'getline',
|
| 299 |
+
(fn, ln), {})
|
| 300 |
+
tb[i] = fn, ln, nm, line
|
| 301 |
+
|
| 302 |
+
def flush_stdout():
|
| 303 |
+
"""XXX How to do this now?"""
|
| 304 |
+
|
| 305 |
+
def exit():
|
| 306 |
+
"""Exit subprocess, possibly after first clearing exit functions.
|
| 307 |
+
|
| 308 |
+
If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
|
| 309 |
+
functions registered with atexit will be removed before exiting.
|
| 310 |
+
(VPython support)
|
| 311 |
+
|
| 312 |
+
"""
|
| 313 |
+
if no_exitfunc:
|
| 314 |
+
import atexit
|
| 315 |
+
atexit._clear()
|
| 316 |
+
capture_warnings(False)
|
| 317 |
+
sys.exit(0)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def fix_scaling(root):
|
| 321 |
+
"""Scale fonts on HiDPI displays."""
|
| 322 |
+
import tkinter.font
|
| 323 |
+
scaling = float(root.tk.call('tk', 'scaling'))
|
| 324 |
+
if scaling > 1.4:
|
| 325 |
+
for name in tkinter.font.names(root):
|
| 326 |
+
font = tkinter.font.Font(root=root, name=name, exists=True)
|
| 327 |
+
size = int(font['size'])
|
| 328 |
+
if size < 0:
|
| 329 |
+
font['size'] = round(-0.75*size)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def fixdoc(fun, text):
|
| 333 |
+
tem = (fun.__doc__ + '\n\n') if fun.__doc__ is not None else ''
|
| 334 |
+
fun.__doc__ = tem + textwrap.fill(textwrap.dedent(text))
|
| 335 |
+
|
| 336 |
+
RECURSIONLIMIT_DELTA = 30
|
| 337 |
+
|
| 338 |
+
def install_recursionlimit_wrappers():
|
| 339 |
+
"""Install wrappers to always add 30 to the recursion limit."""
|
| 340 |
+
# see: bpo-26806
|
| 341 |
+
|
| 342 |
+
@functools.wraps(sys.setrecursionlimit)
|
| 343 |
+
def setrecursionlimit(*args, **kwargs):
|
| 344 |
+
# mimic the original sys.setrecursionlimit()'s input handling
|
| 345 |
+
if kwargs:
|
| 346 |
+
raise TypeError(
|
| 347 |
+
"setrecursionlimit() takes no keyword arguments")
|
| 348 |
+
try:
|
| 349 |
+
limit, = args
|
| 350 |
+
except ValueError:
|
| 351 |
+
raise TypeError(f"setrecursionlimit() takes exactly one "
|
| 352 |
+
f"argument ({len(args)} given)")
|
| 353 |
+
if not limit > 0:
|
| 354 |
+
raise ValueError(
|
| 355 |
+
"recursion limit must be greater or equal than 1")
|
| 356 |
+
|
| 357 |
+
return setrecursionlimit.__wrapped__(limit + RECURSIONLIMIT_DELTA)
|
| 358 |
+
|
| 359 |
+
fixdoc(setrecursionlimit, f"""\
|
| 360 |
+
This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible
|
| 361 |
+
uninterruptible loops.""")
|
| 362 |
+
|
| 363 |
+
@functools.wraps(sys.getrecursionlimit)
|
| 364 |
+
def getrecursionlimit():
|
| 365 |
+
return getrecursionlimit.__wrapped__() - RECURSIONLIMIT_DELTA
|
| 366 |
+
|
| 367 |
+
fixdoc(getrecursionlimit, f"""\
|
| 368 |
+
This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate
|
| 369 |
+
for the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit.""")
|
| 370 |
+
|
| 371 |
+
# add the delta to the default recursion limit, to compensate
|
| 372 |
+
sys.setrecursionlimit(sys.getrecursionlimit() + RECURSIONLIMIT_DELTA)
|
| 373 |
+
|
| 374 |
+
sys.setrecursionlimit = setrecursionlimit
|
| 375 |
+
sys.getrecursionlimit = getrecursionlimit
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def uninstall_recursionlimit_wrappers():
|
| 379 |
+
"""Uninstall the recursion limit wrappers from the sys module.
|
| 380 |
+
|
| 381 |
+
IDLE only uses this for tests. Users can import run and call
|
| 382 |
+
this to remove the wrapping.
|
| 383 |
+
"""
|
| 384 |
+
if (
|
| 385 |
+
getattr(sys.setrecursionlimit, '__wrapped__', None) and
|
| 386 |
+
getattr(sys.getrecursionlimit, '__wrapped__', None)
|
| 387 |
+
):
|
| 388 |
+
sys.setrecursionlimit = sys.setrecursionlimit.__wrapped__
|
| 389 |
+
sys.getrecursionlimit = sys.getrecursionlimit.__wrapped__
|
| 390 |
+
sys.setrecursionlimit(sys.getrecursionlimit() - RECURSIONLIMIT_DELTA)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class MyRPCServer(rpc.RPCServer):
|
| 394 |
+
|
| 395 |
+
def handle_error(self, request, client_address):
|
| 396 |
+
"""Override RPCServer method for IDLE
|
| 397 |
+
|
| 398 |
+
Interrupt the MainThread and exit server if link is dropped.
|
| 399 |
+
|
| 400 |
+
"""
|
| 401 |
+
global quitting
|
| 402 |
+
try:
|
| 403 |
+
raise
|
| 404 |
+
except SystemExit:
|
| 405 |
+
raise
|
| 406 |
+
except EOFError:
|
| 407 |
+
global exit_now
|
| 408 |
+
exit_now = True
|
| 409 |
+
thread.interrupt_main()
|
| 410 |
+
except:
|
| 411 |
+
erf = sys.__stderr__
|
| 412 |
+
print(textwrap.dedent(f"""
|
| 413 |
+
{'-'*40}
|
| 414 |
+
Unhandled exception in user code execution server!'
|
| 415 |
+
Thread: {threading.current_thread().name}
|
| 416 |
+
IDLE Client Address: {client_address}
|
| 417 |
+
Request: {request!r}
|
| 418 |
+
"""), file=erf)
|
| 419 |
+
traceback.print_exc(limit=-20, file=erf)
|
| 420 |
+
print(textwrap.dedent(f"""
|
| 421 |
+
*** Unrecoverable, server exiting!
|
| 422 |
+
|
| 423 |
+
Users should never see this message; it is likely transient.
|
| 424 |
+
If this recurs, report this with a copy of the message
|
| 425 |
+
and an explanation of how to make it repeat.
|
| 426 |
+
{'-'*40}"""), file=erf)
|
| 427 |
+
quitting = True
|
| 428 |
+
thread.interrupt_main()
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
# Pseudofiles for shell-remote communication (also used in pyshell)
|
| 432 |
+
|
| 433 |
+
class StdioFile(io.TextIOBase):
|
| 434 |
+
|
| 435 |
+
def __init__(self, shell, tags, encoding='utf-8', errors='strict'):
|
| 436 |
+
self.shell = shell
|
| 437 |
+
self.tags = tags
|
| 438 |
+
self._encoding = encoding
|
| 439 |
+
self._errors = errors
|
| 440 |
+
|
| 441 |
+
@property
|
| 442 |
+
def encoding(self):
|
| 443 |
+
return self._encoding
|
| 444 |
+
|
| 445 |
+
@property
|
| 446 |
+
def errors(self):
|
| 447 |
+
return self._errors
|
| 448 |
+
|
| 449 |
+
@property
|
| 450 |
+
def name(self):
|
| 451 |
+
return '<%s>' % self.tags
|
| 452 |
+
|
| 453 |
+
def isatty(self):
|
| 454 |
+
return True
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
class StdOutputFile(StdioFile):
|
| 458 |
+
|
| 459 |
+
def writable(self):
|
| 460 |
+
return True
|
| 461 |
+
|
| 462 |
+
def write(self, s):
|
| 463 |
+
if self.closed:
|
| 464 |
+
raise ValueError("write to closed file")
|
| 465 |
+
s = str.encode(s, self.encoding, self.errors).decode(self.encoding, self.errors)
|
| 466 |
+
return self.shell.write(s, self.tags)
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
class StdInputFile(StdioFile):
|
| 470 |
+
_line_buffer = ''
|
| 471 |
+
|
| 472 |
+
def readable(self):
|
| 473 |
+
return True
|
| 474 |
+
|
| 475 |
+
def read(self, size=-1):
|
| 476 |
+
if self.closed:
|
| 477 |
+
raise ValueError("read from closed file")
|
| 478 |
+
if size is None:
|
| 479 |
+
size = -1
|
| 480 |
+
elif not isinstance(size, int):
|
| 481 |
+
raise TypeError('must be int, not ' + type(size).__name__)
|
| 482 |
+
result = self._line_buffer
|
| 483 |
+
self._line_buffer = ''
|
| 484 |
+
if size < 0:
|
| 485 |
+
while line := self.shell.readline():
|
| 486 |
+
result += line
|
| 487 |
+
else:
|
| 488 |
+
while len(result) < size:
|
| 489 |
+
line = self.shell.readline()
|
| 490 |
+
if not line: break
|
| 491 |
+
result += line
|
| 492 |
+
self._line_buffer = result[size:]
|
| 493 |
+
result = result[:size]
|
| 494 |
+
return result
|
| 495 |
+
|
| 496 |
+
def readline(self, size=-1):
|
| 497 |
+
if self.closed:
|
| 498 |
+
raise ValueError("read from closed file")
|
| 499 |
+
if size is None:
|
| 500 |
+
size = -1
|
| 501 |
+
elif not isinstance(size, int):
|
| 502 |
+
raise TypeError('must be int, not ' + type(size).__name__)
|
| 503 |
+
line = self._line_buffer or self.shell.readline()
|
| 504 |
+
if size < 0:
|
| 505 |
+
size = len(line)
|
| 506 |
+
eol = line.find('\n', 0, size)
|
| 507 |
+
if eol >= 0:
|
| 508 |
+
size = eol + 1
|
| 509 |
+
self._line_buffer = line[size:]
|
| 510 |
+
return line[:size]
|
| 511 |
+
|
| 512 |
+
def close(self):
|
| 513 |
+
self.shell.close()
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
class MyHandler(rpc.RPCHandler):
|
| 517 |
+
|
| 518 |
+
def handle(self):
|
| 519 |
+
"""Override base method"""
|
| 520 |
+
executive = Executive(self)
|
| 521 |
+
self.register("exec", executive)
|
| 522 |
+
self.console = self.get_remote_proxy("console")
|
| 523 |
+
sys.stdin = StdInputFile(self.console, "stdin",
|
| 524 |
+
iomenu.encoding, iomenu.errors)
|
| 525 |
+
sys.stdout = StdOutputFile(self.console, "stdout",
|
| 526 |
+
iomenu.encoding, iomenu.errors)
|
| 527 |
+
sys.stderr = StdOutputFile(self.console, "stderr",
|
| 528 |
+
iomenu.encoding, "backslashreplace")
|
| 529 |
+
|
| 530 |
+
sys.displayhook = rpc.displayhook
|
| 531 |
+
# page help() text to shell.
|
| 532 |
+
import pydoc # import must be done here to capture i/o binding
|
| 533 |
+
pydoc.pager = pydoc.plainpager
|
| 534 |
+
|
| 535 |
+
# Keep a reference to stdin so that it won't try to exit IDLE if
|
| 536 |
+
# sys.stdin gets changed from within IDLE's shell. See issue17838.
|
| 537 |
+
self._keep_stdin = sys.stdin
|
| 538 |
+
|
| 539 |
+
install_recursionlimit_wrappers()
|
| 540 |
+
|
| 541 |
+
self.interp = self.get_remote_proxy("interp")
|
| 542 |
+
rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)
|
| 543 |
+
|
| 544 |
+
def exithook(self):
|
| 545 |
+
"override SocketIO method - wait for MainThread to shut us down"
|
| 546 |
+
time.sleep(10)
|
| 547 |
+
|
| 548 |
+
def EOFhook(self):
|
| 549 |
+
"Override SocketIO method - terminate wait on callback and exit thread"
|
| 550 |
+
global quitting
|
| 551 |
+
quitting = True
|
| 552 |
+
thread.interrupt_main()
|
| 553 |
+
|
| 554 |
+
def decode_interrupthook(self):
|
| 555 |
+
"interrupt awakened thread"
|
| 556 |
+
global quitting
|
| 557 |
+
quitting = True
|
| 558 |
+
thread.interrupt_main()
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
class Executive:
|
| 562 |
+
|
| 563 |
+
def __init__(self, rpchandler):
|
| 564 |
+
self.rpchandler = rpchandler
|
| 565 |
+
if idlelib.testing is False:
|
| 566 |
+
self.locals = __main__.__dict__
|
| 567 |
+
self.calltip = calltip.Calltip()
|
| 568 |
+
self.autocomplete = autocomplete.AutoComplete()
|
| 569 |
+
else:
|
| 570 |
+
self.locals = {}
|
| 571 |
+
|
| 572 |
+
def runcode(self, code):
|
| 573 |
+
global interruptable
|
| 574 |
+
try:
|
| 575 |
+
self.user_exc_info = None
|
| 576 |
+
interruptable = True
|
| 577 |
+
try:
|
| 578 |
+
exec(code, self.locals)
|
| 579 |
+
finally:
|
| 580 |
+
interruptable = False
|
| 581 |
+
except SystemExit as e:
|
| 582 |
+
if e.args: # SystemExit called with an argument.
|
| 583 |
+
ob = e.args[0]
|
| 584 |
+
if not isinstance(ob, (type(None), int)):
|
| 585 |
+
print('SystemExit: ' + str(ob), file=sys.stderr)
|
| 586 |
+
# Return to the interactive prompt.
|
| 587 |
+
except:
|
| 588 |
+
self.user_exc_info = sys.exc_info() # For testing, hook, viewer.
|
| 589 |
+
if quitting:
|
| 590 |
+
exit()
|
| 591 |
+
if sys.excepthook is sys.__excepthook__:
|
| 592 |
+
print_exception()
|
| 593 |
+
else:
|
| 594 |
+
try:
|
| 595 |
+
sys.excepthook(*self.user_exc_info)
|
| 596 |
+
except:
|
| 597 |
+
self.user_exc_info = sys.exc_info() # For testing.
|
| 598 |
+
print_exception()
|
| 599 |
+
jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
|
| 600 |
+
if jit:
|
| 601 |
+
self.rpchandler.interp.open_remote_stack_viewer()
|
| 602 |
+
else:
|
| 603 |
+
flush_stdout()
|
| 604 |
+
|
| 605 |
+
def interrupt_the_server(self):
|
| 606 |
+
if interruptable:
|
| 607 |
+
thread.interrupt_main()
|
| 608 |
+
|
| 609 |
+
def start_the_debugger(self, gui_adap_oid):
|
| 610 |
+
return debugger_r.start_debugger(self.rpchandler, gui_adap_oid)
|
| 611 |
+
|
| 612 |
+
def stop_the_debugger(self, idb_adap_oid):
|
| 613 |
+
"Unregister the Idb Adapter. Link objects and Idb then subject to GC"
|
| 614 |
+
self.rpchandler.unregister(idb_adap_oid)
|
| 615 |
+
|
| 616 |
+
def get_the_calltip(self, name):
|
| 617 |
+
return self.calltip.fetch_tip(name)
|
| 618 |
+
|
| 619 |
+
def get_the_completion_list(self, what, mode):
|
| 620 |
+
return self.autocomplete.fetch_completions(what, mode)
|
| 621 |
+
|
| 622 |
+
def stackviewer(self, flist_oid=None):
|
| 623 |
+
if self.user_exc_info:
|
| 624 |
+
typ, val, tb = self.user_exc_info
|
| 625 |
+
else:
|
| 626 |
+
return None
|
| 627 |
+
flist = None
|
| 628 |
+
if flist_oid is not None:
|
| 629 |
+
flist = self.rpchandler.get_remote_proxy(flist_oid)
|
| 630 |
+
while tb and tb.tb_frame.f_globals["__name__"] in ["rpc", "run"]:
|
| 631 |
+
tb = tb.tb_next
|
| 632 |
+
sys.last_type = typ
|
| 633 |
+
sys.last_value = val
|
| 634 |
+
item = stackviewer.StackTreeItem(flist, tb)
|
| 635 |
+
return debugobj_r.remote_object_tree_item(item)
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
if __name__ == '__main__':
|
| 639 |
+
from unittest import main
|
| 640 |
+
main('idlelib.idle_test.test_run', verbosity=2)
|
| 641 |
+
|
| 642 |
+
capture_warnings(False) # Make sure turned off; see bpo-18081.
|
deepseek/lib/python3.10/idlelib/search.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Search dialog for Find, Find Again, and Find Selection
|
| 2 |
+
functionality.
|
| 3 |
+
|
| 4 |
+
Inherits from SearchDialogBase for GUI and uses searchengine
|
| 5 |
+
to prepare search pattern.
|
| 6 |
+
"""
|
| 7 |
+
from tkinter import TclError
|
| 8 |
+
|
| 9 |
+
from idlelib import searchengine
|
| 10 |
+
from idlelib.searchbase import SearchDialogBase
|
| 11 |
+
|
| 12 |
+
def _setup(text):
|
| 13 |
+
"""Return the new or existing singleton SearchDialog instance.
|
| 14 |
+
|
| 15 |
+
The singleton dialog saves user entries and preferences
|
| 16 |
+
across instances.
|
| 17 |
+
|
| 18 |
+
Args:
|
| 19 |
+
text: Text widget containing the text to be searched.
|
| 20 |
+
"""
|
| 21 |
+
root = text._root()
|
| 22 |
+
engine = searchengine.get(root)
|
| 23 |
+
if not hasattr(engine, "_searchdialog"):
|
| 24 |
+
engine._searchdialog = SearchDialog(root, engine)
|
| 25 |
+
return engine._searchdialog
|
| 26 |
+
|
| 27 |
+
def find(text):
|
| 28 |
+
"""Open the search dialog.
|
| 29 |
+
|
| 30 |
+
Module-level function to access the singleton SearchDialog
|
| 31 |
+
instance and open the dialog. If text is selected, it is
|
| 32 |
+
used as the search phrase; otherwise, the previous entry
|
| 33 |
+
is used. No search is done with this command.
|
| 34 |
+
"""
|
| 35 |
+
pat = text.get("sel.first", "sel.last")
|
| 36 |
+
return _setup(text).open(text, pat) # Open is inherited from SDBase.
|
| 37 |
+
|
| 38 |
+
def find_again(text):
|
| 39 |
+
"""Repeat the search for the last pattern and preferences.
|
| 40 |
+
|
| 41 |
+
Module-level function to access the singleton SearchDialog
|
| 42 |
+
instance to search again using the user entries and preferences
|
| 43 |
+
from the last dialog. If there was no prior search, open the
|
| 44 |
+
search dialog; otherwise, perform the search without showing the
|
| 45 |
+
dialog.
|
| 46 |
+
"""
|
| 47 |
+
return _setup(text).find_again(text)
|
| 48 |
+
|
| 49 |
+
def find_selection(text):
|
| 50 |
+
"""Search for the selected pattern in the text.
|
| 51 |
+
|
| 52 |
+
Module-level function to access the singleton SearchDialog
|
| 53 |
+
instance to search using the selected text. With a text
|
| 54 |
+
selection, perform the search without displaying the dialog.
|
| 55 |
+
Without a selection, use the prior entry as the search phrase
|
| 56 |
+
and don't display the dialog. If there has been no prior
|
| 57 |
+
search, open the search dialog.
|
| 58 |
+
"""
|
| 59 |
+
return _setup(text).find_selection(text)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class SearchDialog(SearchDialogBase):
|
| 63 |
+
"Dialog for finding a pattern in text."
|
| 64 |
+
|
| 65 |
+
def create_widgets(self):
|
| 66 |
+
"Create the base search dialog and add a button for Find Next."
|
| 67 |
+
SearchDialogBase.create_widgets(self)
|
| 68 |
+
# TODO - why is this here and not in a create_command_buttons?
|
| 69 |
+
self.make_button("Find Next", self.default_command, isdef=True)
|
| 70 |
+
|
| 71 |
+
def default_command(self, event=None):
|
| 72 |
+
"Handle the Find Next button as the default command."
|
| 73 |
+
if not self.engine.getprog():
|
| 74 |
+
return
|
| 75 |
+
self.find_again(self.text)
|
| 76 |
+
|
| 77 |
+
def find_again(self, text):
|
| 78 |
+
"""Repeat the last search.
|
| 79 |
+
|
| 80 |
+
If no search was previously run, open a new search dialog. In
|
| 81 |
+
this case, no search is done.
|
| 82 |
+
|
| 83 |
+
If a search was previously run, the search dialog won't be
|
| 84 |
+
shown and the options from the previous search (including the
|
| 85 |
+
search pattern) will be used to find the next occurrence
|
| 86 |
+
of the pattern. Next is relative based on direction.
|
| 87 |
+
|
| 88 |
+
Position the window to display the located occurrence in the
|
| 89 |
+
text.
|
| 90 |
+
|
| 91 |
+
Return True if the search was successful and False otherwise.
|
| 92 |
+
"""
|
| 93 |
+
if not self.engine.getpat():
|
| 94 |
+
self.open(text)
|
| 95 |
+
return False
|
| 96 |
+
if not self.engine.getprog():
|
| 97 |
+
return False
|
| 98 |
+
res = self.engine.search_text(text)
|
| 99 |
+
if res:
|
| 100 |
+
line, m = res
|
| 101 |
+
i, j = m.span()
|
| 102 |
+
first = "%d.%d" % (line, i)
|
| 103 |
+
last = "%d.%d" % (line, j)
|
| 104 |
+
try:
|
| 105 |
+
selfirst = text.index("sel.first")
|
| 106 |
+
sellast = text.index("sel.last")
|
| 107 |
+
if selfirst == first and sellast == last:
|
| 108 |
+
self.bell()
|
| 109 |
+
return False
|
| 110 |
+
except TclError:
|
| 111 |
+
pass
|
| 112 |
+
text.tag_remove("sel", "1.0", "end")
|
| 113 |
+
text.tag_add("sel", first, last)
|
| 114 |
+
text.mark_set("insert", self.engine.isback() and first or last)
|
| 115 |
+
text.see("insert")
|
| 116 |
+
return True
|
| 117 |
+
else:
|
| 118 |
+
self.bell()
|
| 119 |
+
return False
|
| 120 |
+
|
| 121 |
+
def find_selection(self, text):
|
| 122 |
+
"""Search for selected text with previous dialog preferences.
|
| 123 |
+
|
| 124 |
+
Instead of using the same pattern for searching (as Find
|
| 125 |
+
Again does), this first resets the pattern to the currently
|
| 126 |
+
selected text. If the selected text isn't changed, then use
|
| 127 |
+
the prior search phrase.
|
| 128 |
+
"""
|
| 129 |
+
pat = text.get("sel.first", "sel.last")
|
| 130 |
+
if pat:
|
| 131 |
+
self.engine.setcookedpat(pat)
|
| 132 |
+
return self.find_again(text)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _search_dialog(parent): # htest #
|
| 136 |
+
"Display search test box."
|
| 137 |
+
from tkinter import Toplevel, Text
|
| 138 |
+
from tkinter.ttk import Frame, Button
|
| 139 |
+
|
| 140 |
+
top = Toplevel(parent)
|
| 141 |
+
top.title("Test SearchDialog")
|
| 142 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 143 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 144 |
+
|
| 145 |
+
frame = Frame(top)
|
| 146 |
+
frame.pack()
|
| 147 |
+
text = Text(frame, inactiveselectbackground='gray')
|
| 148 |
+
text.pack()
|
| 149 |
+
text.insert("insert","This is a sample string.\n"*5)
|
| 150 |
+
|
| 151 |
+
def show_find():
|
| 152 |
+
text.tag_add('sel', '1.0', 'end')
|
| 153 |
+
_setup(text).open(text)
|
| 154 |
+
text.tag_remove('sel', '1.0', 'end')
|
| 155 |
+
|
| 156 |
+
button = Button(frame, text="Search (selection ignored)", command=show_find)
|
| 157 |
+
button.pack()
|
| 158 |
+
|
| 159 |
+
if __name__ == '__main__':
|
| 160 |
+
from unittest import main
|
| 161 |
+
main('idlelib.idle_test.test_search', verbosity=2, exit=False)
|
| 162 |
+
|
| 163 |
+
from idlelib.idle_test.htest import run
|
| 164 |
+
run(_search_dialog)
|
deepseek/lib/python3.10/idlelib/searchengine.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Define SearchEngine for search dialogs.'''
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
from tkinter import StringVar, BooleanVar, TclError
|
| 5 |
+
from tkinter import messagebox
|
| 6 |
+
|
| 7 |
+
def get(root):
|
| 8 |
+
'''Return the singleton SearchEngine instance for the process.
|
| 9 |
+
|
| 10 |
+
The single SearchEngine saves settings between dialog instances.
|
| 11 |
+
If there is not a SearchEngine already, make one.
|
| 12 |
+
'''
|
| 13 |
+
if not hasattr(root, "_searchengine"):
|
| 14 |
+
root._searchengine = SearchEngine(root)
|
| 15 |
+
# This creates a cycle that persists until root is deleted.
|
| 16 |
+
return root._searchengine
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SearchEngine:
|
| 20 |
+
"""Handles searching a text widget for Find, Replace, and Grep."""
|
| 21 |
+
|
| 22 |
+
def __init__(self, root):
|
| 23 |
+
'''Initialize Variables that save search state.
|
| 24 |
+
|
| 25 |
+
The dialogs bind these to the UI elements present in the dialogs.
|
| 26 |
+
'''
|
| 27 |
+
self.root = root # need for report_error()
|
| 28 |
+
self.patvar = StringVar(root, '') # search pattern
|
| 29 |
+
self.revar = BooleanVar(root, False) # regular expression?
|
| 30 |
+
self.casevar = BooleanVar(root, False) # match case?
|
| 31 |
+
self.wordvar = BooleanVar(root, False) # match whole word?
|
| 32 |
+
self.wrapvar = BooleanVar(root, True) # wrap around buffer?
|
| 33 |
+
self.backvar = BooleanVar(root, False) # search backwards?
|
| 34 |
+
|
| 35 |
+
# Access methods
|
| 36 |
+
|
| 37 |
+
def getpat(self):
|
| 38 |
+
return self.patvar.get()
|
| 39 |
+
|
| 40 |
+
def setpat(self, pat):
|
| 41 |
+
self.patvar.set(pat)
|
| 42 |
+
|
| 43 |
+
def isre(self):
|
| 44 |
+
return self.revar.get()
|
| 45 |
+
|
| 46 |
+
def iscase(self):
|
| 47 |
+
return self.casevar.get()
|
| 48 |
+
|
| 49 |
+
def isword(self):
|
| 50 |
+
return self.wordvar.get()
|
| 51 |
+
|
| 52 |
+
def iswrap(self):
|
| 53 |
+
return self.wrapvar.get()
|
| 54 |
+
|
| 55 |
+
def isback(self):
|
| 56 |
+
return self.backvar.get()
|
| 57 |
+
|
| 58 |
+
# Higher level access methods
|
| 59 |
+
|
| 60 |
+
def setcookedpat(self, pat):
|
| 61 |
+
"Set pattern after escaping if re."
|
| 62 |
+
# called only in search.py: 66
|
| 63 |
+
if self.isre():
|
| 64 |
+
pat = re.escape(pat)
|
| 65 |
+
self.setpat(pat)
|
| 66 |
+
|
| 67 |
+
def getcookedpat(self):
|
| 68 |
+
pat = self.getpat()
|
| 69 |
+
if not self.isre(): # if True, see setcookedpat
|
| 70 |
+
pat = re.escape(pat)
|
| 71 |
+
if self.isword():
|
| 72 |
+
pat = r"\b%s\b" % pat
|
| 73 |
+
return pat
|
| 74 |
+
|
| 75 |
+
def getprog(self):
|
| 76 |
+
"Return compiled cooked search pattern."
|
| 77 |
+
pat = self.getpat()
|
| 78 |
+
if not pat:
|
| 79 |
+
self.report_error(pat, "Empty regular expression")
|
| 80 |
+
return None
|
| 81 |
+
pat = self.getcookedpat()
|
| 82 |
+
flags = 0
|
| 83 |
+
if not self.iscase():
|
| 84 |
+
flags = flags | re.IGNORECASE
|
| 85 |
+
try:
|
| 86 |
+
prog = re.compile(pat, flags)
|
| 87 |
+
except re.error as e:
|
| 88 |
+
self.report_error(pat, e.msg, e.pos)
|
| 89 |
+
return None
|
| 90 |
+
return prog
|
| 91 |
+
|
| 92 |
+
def report_error(self, pat, msg, col=None):
|
| 93 |
+
# Derived class could override this with something fancier
|
| 94 |
+
msg = "Error: " + str(msg)
|
| 95 |
+
if pat:
|
| 96 |
+
msg = msg + "\nPattern: " + str(pat)
|
| 97 |
+
if col is not None:
|
| 98 |
+
msg = msg + "\nOffset: " + str(col)
|
| 99 |
+
messagebox.showerror("Regular expression error",
|
| 100 |
+
msg, master=self.root)
|
| 101 |
+
|
| 102 |
+
def search_text(self, text, prog=None, ok=0):
|
| 103 |
+
'''Return (lineno, matchobj) or None for forward/backward search.
|
| 104 |
+
|
| 105 |
+
This function calls the right function with the right arguments.
|
| 106 |
+
It directly return the result of that call.
|
| 107 |
+
|
| 108 |
+
Text is a text widget. Prog is a precompiled pattern.
|
| 109 |
+
The ok parameter is a bit complicated as it has two effects.
|
| 110 |
+
|
| 111 |
+
If there is a selection, the search begin at either end,
|
| 112 |
+
depending on the direction setting and ok, with ok meaning that
|
| 113 |
+
the search starts with the selection. Otherwise, search begins
|
| 114 |
+
at the insert mark.
|
| 115 |
+
|
| 116 |
+
To aid progress, the search functions do not return an empty
|
| 117 |
+
match at the starting position unless ok is True.
|
| 118 |
+
'''
|
| 119 |
+
|
| 120 |
+
if not prog:
|
| 121 |
+
prog = self.getprog()
|
| 122 |
+
if not prog:
|
| 123 |
+
return None # Compilation failed -- stop
|
| 124 |
+
wrap = self.wrapvar.get()
|
| 125 |
+
first, last = get_selection(text)
|
| 126 |
+
if self.isback():
|
| 127 |
+
if ok:
|
| 128 |
+
start = last
|
| 129 |
+
else:
|
| 130 |
+
start = first
|
| 131 |
+
line, col = get_line_col(start)
|
| 132 |
+
res = self.search_backward(text, prog, line, col, wrap, ok)
|
| 133 |
+
else:
|
| 134 |
+
if ok:
|
| 135 |
+
start = first
|
| 136 |
+
else:
|
| 137 |
+
start = last
|
| 138 |
+
line, col = get_line_col(start)
|
| 139 |
+
res = self.search_forward(text, prog, line, col, wrap, ok)
|
| 140 |
+
return res
|
| 141 |
+
|
| 142 |
+
def search_forward(self, text, prog, line, col, wrap, ok=0):
|
| 143 |
+
wrapped = 0
|
| 144 |
+
startline = line
|
| 145 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 146 |
+
while chars:
|
| 147 |
+
m = prog.search(chars[:-1], col)
|
| 148 |
+
if m:
|
| 149 |
+
if ok or m.end() > col:
|
| 150 |
+
return line, m
|
| 151 |
+
line = line + 1
|
| 152 |
+
if wrapped and line > startline:
|
| 153 |
+
break
|
| 154 |
+
col = 0
|
| 155 |
+
ok = 1
|
| 156 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 157 |
+
if not chars and wrap:
|
| 158 |
+
wrapped = 1
|
| 159 |
+
wrap = 0
|
| 160 |
+
line = 1
|
| 161 |
+
chars = text.get("1.0", "2.0")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
def search_backward(self, text, prog, line, col, wrap, ok=0):
|
| 165 |
+
wrapped = 0
|
| 166 |
+
startline = line
|
| 167 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 168 |
+
while True:
|
| 169 |
+
m = search_reverse(prog, chars[:-1], col)
|
| 170 |
+
if m:
|
| 171 |
+
if ok or m.start() < col:
|
| 172 |
+
return line, m
|
| 173 |
+
line = line - 1
|
| 174 |
+
if wrapped and line < startline:
|
| 175 |
+
break
|
| 176 |
+
ok = 1
|
| 177 |
+
if line <= 0:
|
| 178 |
+
if not wrap:
|
| 179 |
+
break
|
| 180 |
+
wrapped = 1
|
| 181 |
+
wrap = 0
|
| 182 |
+
pos = text.index("end-1c")
|
| 183 |
+
line, col = map(int, pos.split("."))
|
| 184 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 185 |
+
col = len(chars) - 1
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def search_reverse(prog, chars, col):
|
| 190 |
+
'''Search backwards and return an re match object or None.
|
| 191 |
+
|
| 192 |
+
This is done by searching forwards until there is no match.
|
| 193 |
+
Prog: compiled re object with a search method returning a match.
|
| 194 |
+
Chars: line of text, without \\n.
|
| 195 |
+
Col: stop index for the search; the limit for match.end().
|
| 196 |
+
'''
|
| 197 |
+
m = prog.search(chars)
|
| 198 |
+
if not m:
|
| 199 |
+
return None
|
| 200 |
+
found = None
|
| 201 |
+
i, j = m.span() # m.start(), m.end() == match slice indexes
|
| 202 |
+
while i < col and j <= col:
|
| 203 |
+
found = m
|
| 204 |
+
if i == j:
|
| 205 |
+
j = j+1
|
| 206 |
+
m = prog.search(chars, j)
|
| 207 |
+
if not m:
|
| 208 |
+
break
|
| 209 |
+
i, j = m.span()
|
| 210 |
+
return found
|
| 211 |
+
|
| 212 |
+
def get_selection(text):
|
| 213 |
+
'''Return tuple of 'line.col' indexes from selection or insert mark.
|
| 214 |
+
'''
|
| 215 |
+
try:
|
| 216 |
+
first = text.index("sel.first")
|
| 217 |
+
last = text.index("sel.last")
|
| 218 |
+
except TclError:
|
| 219 |
+
first = last = None
|
| 220 |
+
if not first:
|
| 221 |
+
first = text.index("insert")
|
| 222 |
+
if not last:
|
| 223 |
+
last = first
|
| 224 |
+
return first, last
|
| 225 |
+
|
| 226 |
+
def get_line_col(index):
|
| 227 |
+
'''Return (line, col) tuple of ints from 'line.col' string.'''
|
| 228 |
+
line, col = map(int, index.split(".")) # Fails on invalid index
|
| 229 |
+
return line, col
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
if __name__ == "__main__":
|
| 233 |
+
from unittest import main
|
| 234 |
+
main('idlelib.idle_test.test_searchengine', verbosity=2)
|
deepseek/lib/python3.10/idlelib/squeezer.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ive 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.
|
deepseek/lib/python3.10/idlelib/stackviewer.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import linecache
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
import tkinter as tk
|
| 6 |
+
|
| 7 |
+
from idlelib.debugobj import ObjectTreeItem, make_objecttreeitem
|
| 8 |
+
from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
|
| 9 |
+
|
| 10 |
+
def StackBrowser(root, flist=None, tb=None, top=None):
|
| 11 |
+
global sc, item, node # For testing.
|
| 12 |
+
if top is None:
|
| 13 |
+
top = tk.Toplevel(root)
|
| 14 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0)
|
| 15 |
+
sc.frame.pack(expand=1, fill="both")
|
| 16 |
+
item = StackTreeItem(flist, tb)
|
| 17 |
+
node = TreeNode(sc.canvas, None, item)
|
| 18 |
+
node.expand()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class StackTreeItem(TreeItem):
|
| 22 |
+
|
| 23 |
+
def __init__(self, flist=None, tb=None):
|
| 24 |
+
self.flist = flist
|
| 25 |
+
self.stack = self.get_stack(tb)
|
| 26 |
+
self.text = self.get_exception()
|
| 27 |
+
|
| 28 |
+
def get_stack(self, tb):
|
| 29 |
+
if tb is None:
|
| 30 |
+
tb = sys.last_traceback
|
| 31 |
+
stack = []
|
| 32 |
+
if tb and tb.tb_frame is None:
|
| 33 |
+
tb = tb.tb_next
|
| 34 |
+
while tb is not None:
|
| 35 |
+
stack.append((tb.tb_frame, tb.tb_lineno))
|
| 36 |
+
tb = tb.tb_next
|
| 37 |
+
return stack
|
| 38 |
+
|
| 39 |
+
def get_exception(self):
|
| 40 |
+
type = sys.last_type
|
| 41 |
+
value = sys.last_value
|
| 42 |
+
if hasattr(type, "__name__"):
|
| 43 |
+
type = type.__name__
|
| 44 |
+
s = str(type)
|
| 45 |
+
if value is not None:
|
| 46 |
+
s = s + ": " + str(value)
|
| 47 |
+
return s
|
| 48 |
+
|
| 49 |
+
def GetText(self):
|
| 50 |
+
return self.text
|
| 51 |
+
|
| 52 |
+
def GetSubList(self):
|
| 53 |
+
sublist = []
|
| 54 |
+
for info in self.stack:
|
| 55 |
+
item = FrameTreeItem(info, self.flist)
|
| 56 |
+
sublist.append(item)
|
| 57 |
+
return sublist
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class FrameTreeItem(TreeItem):
|
| 61 |
+
|
| 62 |
+
def __init__(self, info, flist):
|
| 63 |
+
self.info = info
|
| 64 |
+
self.flist = flist
|
| 65 |
+
|
| 66 |
+
def GetText(self):
|
| 67 |
+
frame, lineno = self.info
|
| 68 |
+
try:
|
| 69 |
+
modname = frame.f_globals["__name__"]
|
| 70 |
+
except:
|
| 71 |
+
modname = "?"
|
| 72 |
+
code = frame.f_code
|
| 73 |
+
filename = code.co_filename
|
| 74 |
+
funcname = code.co_name
|
| 75 |
+
sourceline = linecache.getline(filename, lineno)
|
| 76 |
+
sourceline = sourceline.strip()
|
| 77 |
+
if funcname in ("?", "", None):
|
| 78 |
+
item = "%s, line %d: %s" % (modname, lineno, sourceline)
|
| 79 |
+
else:
|
| 80 |
+
item = "%s.%s(...), line %d: %s" % (modname, funcname,
|
| 81 |
+
lineno, sourceline)
|
| 82 |
+
return item
|
| 83 |
+
|
| 84 |
+
def GetSubList(self):
|
| 85 |
+
frame, lineno = self.info
|
| 86 |
+
sublist = []
|
| 87 |
+
if frame.f_globals is not frame.f_locals:
|
| 88 |
+
item = VariablesTreeItem("<locals>", frame.f_locals, self.flist)
|
| 89 |
+
sublist.append(item)
|
| 90 |
+
item = VariablesTreeItem("<globals>", frame.f_globals, self.flist)
|
| 91 |
+
sublist.append(item)
|
| 92 |
+
return sublist
|
| 93 |
+
|
| 94 |
+
def OnDoubleClick(self):
|
| 95 |
+
if self.flist:
|
| 96 |
+
frame, lineno = self.info
|
| 97 |
+
filename = frame.f_code.co_filename
|
| 98 |
+
if os.path.isfile(filename):
|
| 99 |
+
self.flist.gotofileline(filename, lineno)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class VariablesTreeItem(ObjectTreeItem):
|
| 103 |
+
|
| 104 |
+
def GetText(self):
|
| 105 |
+
return self.labeltext
|
| 106 |
+
|
| 107 |
+
def GetLabelText(self):
|
| 108 |
+
return None
|
| 109 |
+
|
| 110 |
+
def IsExpandable(self):
|
| 111 |
+
return len(self.object) > 0
|
| 112 |
+
|
| 113 |
+
def GetSubList(self):
|
| 114 |
+
sublist = []
|
| 115 |
+
for key in self.object.keys():
|
| 116 |
+
try:
|
| 117 |
+
value = self.object[key]
|
| 118 |
+
except KeyError:
|
| 119 |
+
continue
|
| 120 |
+
def setfunction(value, key=key, object=self.object):
|
| 121 |
+
object[key] = value
|
| 122 |
+
item = make_objecttreeitem(key + " =", value, setfunction)
|
| 123 |
+
sublist.append(item)
|
| 124 |
+
return sublist
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _stack_viewer(parent): # htest #
|
| 128 |
+
from idlelib.pyshell import PyShellFileList
|
| 129 |
+
top = tk.Toplevel(parent)
|
| 130 |
+
top.title("Test StackViewer")
|
| 131 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 132 |
+
top.geometry("+%d+%d" % (x + 50, y + 175))
|
| 133 |
+
flist = PyShellFileList(top)
|
| 134 |
+
try: # to obtain a traceback object
|
| 135 |
+
intentional_name_error
|
| 136 |
+
except NameError:
|
| 137 |
+
exc_type, exc_value, exc_tb = sys.exc_info()
|
| 138 |
+
# inject stack trace to sys
|
| 139 |
+
sys.last_type = exc_type
|
| 140 |
+
sys.last_value = exc_value
|
| 141 |
+
sys.last_traceback = exc_tb
|
| 142 |
+
|
| 143 |
+
StackBrowser(top, flist=flist, top=top, tb=exc_tb)
|
| 144 |
+
|
| 145 |
+
# restore sys to original state
|
| 146 |
+
del sys.last_type
|
| 147 |
+
del sys.last_value
|
| 148 |
+
del sys.last_traceback
|
| 149 |
+
|
| 150 |
+
if __name__ == '__main__':
|
| 151 |
+
from unittest import main
|
| 152 |
+
main('idlelib.idle_test.test_stackviewer', verbosity=2, exit=False)
|
| 153 |
+
|
| 154 |
+
from idlelib.idle_test.htest import run
|
| 155 |
+
run(_stack_viewer)
|
deepseek/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)
|
deepseek/lib/python3.10/idlelib/textview.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from tkinter import Toplevel, Text, TclError,\
|
| 5 |
+
HORIZONTAL, VERTICAL, NS, EW, NSEW, NONE, WORD, SUNKEN
|
| 6 |
+
from tkinter.ttk import Frame, Scrollbar, Button
|
| 7 |
+
from tkinter.messagebox import showerror
|
| 8 |
+
|
| 9 |
+
from idlelib.colorizer import color_config
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class AutoHideScrollbar(Scrollbar):
|
| 13 |
+
"""A scrollbar that is automatically hidden when not needed.
|
| 14 |
+
|
| 15 |
+
Only the grid geometry manager is supported.
|
| 16 |
+
"""
|
| 17 |
+
def set(self, lo, hi):
|
| 18 |
+
if float(lo) > 0.0 or float(hi) < 1.0:
|
| 19 |
+
self.grid()
|
| 20 |
+
else:
|
| 21 |
+
self.grid_remove()
|
| 22 |
+
super().set(lo, hi)
|
| 23 |
+
|
| 24 |
+
def pack(self, **kwargs):
|
| 25 |
+
raise TclError(f'{self.__class__.__name__} does not support "pack"')
|
| 26 |
+
|
| 27 |
+
def place(self, **kwargs):
|
| 28 |
+
raise TclError(f'{self.__class__.__name__} does not support "place"')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ScrollableTextFrame(Frame):
|
| 32 |
+
"""Display text with scrollbar(s)."""
|
| 33 |
+
|
| 34 |
+
def __init__(self, master, wrap=NONE, **kwargs):
|
| 35 |
+
"""Create a frame for Textview.
|
| 36 |
+
|
| 37 |
+
master - master widget for this frame
|
| 38 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 39 |
+
|
| 40 |
+
All parameters except for 'wrap' are passed to Frame.__init__().
|
| 41 |
+
|
| 42 |
+
The Text widget is accessible via the 'text' attribute.
|
| 43 |
+
|
| 44 |
+
Note: Changing the wrapping mode of the text widget after
|
| 45 |
+
instantiation is not supported.
|
| 46 |
+
"""
|
| 47 |
+
super().__init__(master, **kwargs)
|
| 48 |
+
|
| 49 |
+
text = self.text = Text(self, wrap=wrap)
|
| 50 |
+
text.grid(row=0, column=0, sticky=NSEW)
|
| 51 |
+
self.grid_rowconfigure(0, weight=1)
|
| 52 |
+
self.grid_columnconfigure(0, weight=1)
|
| 53 |
+
|
| 54 |
+
# vertical scrollbar
|
| 55 |
+
self.yscroll = AutoHideScrollbar(self, orient=VERTICAL,
|
| 56 |
+
takefocus=False,
|
| 57 |
+
command=text.yview)
|
| 58 |
+
self.yscroll.grid(row=0, column=1, sticky=NS)
|
| 59 |
+
text['yscrollcommand'] = self.yscroll.set
|
| 60 |
+
|
| 61 |
+
# horizontal scrollbar - only when wrap is set to NONE
|
| 62 |
+
if wrap == NONE:
|
| 63 |
+
self.xscroll = AutoHideScrollbar(self, orient=HORIZONTAL,
|
| 64 |
+
takefocus=False,
|
| 65 |
+
command=text.xview)
|
| 66 |
+
self.xscroll.grid(row=1, column=0, sticky=EW)
|
| 67 |
+
text['xscrollcommand'] = self.xscroll.set
|
| 68 |
+
else:
|
| 69 |
+
self.xscroll = None
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class ViewFrame(Frame):
|
| 73 |
+
"Display TextFrame and Close button."
|
| 74 |
+
def __init__(self, parent, contents, wrap='word'):
|
| 75 |
+
"""Create a frame for viewing text with a "Close" button.
|
| 76 |
+
|
| 77 |
+
parent - parent widget for this frame
|
| 78 |
+
contents - text to display
|
| 79 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 80 |
+
|
| 81 |
+
The Text widget is accessible via the 'text' attribute.
|
| 82 |
+
"""
|
| 83 |
+
super().__init__(parent)
|
| 84 |
+
self.parent = parent
|
| 85 |
+
self.bind('<Return>', self.ok)
|
| 86 |
+
self.bind('<Escape>', self.ok)
|
| 87 |
+
self.textframe = ScrollableTextFrame(self, relief=SUNKEN, height=700)
|
| 88 |
+
|
| 89 |
+
text = self.text = self.textframe.text
|
| 90 |
+
text.insert('1.0', contents)
|
| 91 |
+
text.configure(wrap=wrap, highlightthickness=0, state='disabled')
|
| 92 |
+
color_config(text)
|
| 93 |
+
text.focus_set()
|
| 94 |
+
|
| 95 |
+
self.button_ok = button_ok = Button(
|
| 96 |
+
self, text='Close', command=self.ok, takefocus=False)
|
| 97 |
+
self.textframe.pack(side='top', expand=True, fill='both')
|
| 98 |
+
button_ok.pack(side='bottom')
|
| 99 |
+
|
| 100 |
+
def ok(self, event=None):
|
| 101 |
+
"""Dismiss text viewer dialog."""
|
| 102 |
+
self.parent.destroy()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class ViewWindow(Toplevel):
|
| 106 |
+
"A simple text viewer dialog for IDLE."
|
| 107 |
+
|
| 108 |
+
def __init__(self, parent, title, contents, modal=True, wrap=WORD,
|
| 109 |
+
*, _htest=False, _utest=False):
|
| 110 |
+
"""Show the given text in a scrollable window with a 'close' button.
|
| 111 |
+
|
| 112 |
+
If modal is left True, users cannot interact with other windows
|
| 113 |
+
until the textview window is closed.
|
| 114 |
+
|
| 115 |
+
parent - parent of this dialog
|
| 116 |
+
title - string which is title of popup dialog
|
| 117 |
+
contents - text to display in dialog
|
| 118 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 119 |
+
_htest - bool; change box location when running htest.
|
| 120 |
+
_utest - bool; don't wait_window when running unittest.
|
| 121 |
+
"""
|
| 122 |
+
super().__init__(parent)
|
| 123 |
+
self['borderwidth'] = 5
|
| 124 |
+
# Place dialog below parent if running htest.
|
| 125 |
+
x = parent.winfo_rootx() + 10
|
| 126 |
+
y = parent.winfo_rooty() + (10 if not _htest else 100)
|
| 127 |
+
self.geometry(f'=750x500+{x}+{y}')
|
| 128 |
+
|
| 129 |
+
self.title(title)
|
| 130 |
+
self.viewframe = ViewFrame(self, contents, wrap=wrap)
|
| 131 |
+
self.protocol("WM_DELETE_WINDOW", self.ok)
|
| 132 |
+
self.button_ok = button_ok = Button(self, text='Close',
|
| 133 |
+
command=self.ok, takefocus=False)
|
| 134 |
+
self.viewframe.pack(side='top', expand=True, fill='both')
|
| 135 |
+
|
| 136 |
+
self.is_modal = modal
|
| 137 |
+
if self.is_modal:
|
| 138 |
+
self.transient(parent)
|
| 139 |
+
self.grab_set()
|
| 140 |
+
if not _utest:
|
| 141 |
+
self.wait_window()
|
| 142 |
+
|
| 143 |
+
def ok(self, event=None):
|
| 144 |
+
"""Dismiss text viewer dialog."""
|
| 145 |
+
if self.is_modal:
|
| 146 |
+
self.grab_release()
|
| 147 |
+
self.destroy()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def view_text(parent, title, contents, modal=True, wrap='word', _utest=False):
|
| 151 |
+
"""Create text viewer for given text.
|
| 152 |
+
|
| 153 |
+
parent - parent of this dialog
|
| 154 |
+
title - string which is the title of popup dialog
|
| 155 |
+
contents - text to display in this dialog
|
| 156 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 157 |
+
modal - controls if users can interact with other windows while this
|
| 158 |
+
dialog is displayed
|
| 159 |
+
_utest - bool; controls wait_window on unittest
|
| 160 |
+
"""
|
| 161 |
+
return ViewWindow(parent, title, contents, modal, wrap=wrap, _utest=_utest)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def view_file(parent, title, filename, encoding, modal=True, wrap='word',
|
| 165 |
+
_utest=False):
|
| 166 |
+
"""Create text viewer for text in filename.
|
| 167 |
+
|
| 168 |
+
Return error message if file cannot be read. Otherwise calls view_text
|
| 169 |
+
with contents of the file.
|
| 170 |
+
"""
|
| 171 |
+
try:
|
| 172 |
+
with open(filename, 'r', encoding=encoding) as file:
|
| 173 |
+
contents = file.read()
|
| 174 |
+
except OSError:
|
| 175 |
+
showerror(title='File Load Error',
|
| 176 |
+
message=f'Unable to load file {filename!r} .',
|
| 177 |
+
parent=parent)
|
| 178 |
+
except UnicodeDecodeError as err:
|
| 179 |
+
showerror(title='Unicode Decode Error',
|
| 180 |
+
message=str(err),
|
| 181 |
+
parent=parent)
|
| 182 |
+
else:
|
| 183 |
+
return view_text(parent, title, contents, modal, wrap=wrap,
|
| 184 |
+
_utest=_utest)
|
| 185 |
+
return None
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
if __name__ == '__main__':
|
| 189 |
+
from unittest import main
|
| 190 |
+
main('idlelib.idle_test.test_textview', verbosity=2, exit=False)
|
| 191 |
+
|
| 192 |
+
from idlelib.idle_test.htest import run
|
| 193 |
+
run(ViewWindow)
|
deepseek/lib/python3.10/idlelib/undo.py
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import string
|
| 2 |
+
|
| 3 |
+
from idlelib.delegator import Delegator
|
| 4 |
+
|
| 5 |
+
# tkinter import not needed because module does not 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)
|
deepseek/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)
|
deepseek/lib/python3.10/idlelib/zoomheight.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"Zoom a window to maximum height."
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
import tkinter
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class WmInfoGatheringError(Exception):
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class ZoomHeight:
|
| 13 |
+
# Cached values for maximized window dimensions, one for each set
|
| 14 |
+
# of screen dimensions.
|
| 15 |
+
_max_height_and_y_coords = {}
|
| 16 |
+
|
| 17 |
+
def __init__(self, editwin):
|
| 18 |
+
self.editwin = editwin
|
| 19 |
+
self.top = self.editwin.top
|
| 20 |
+
|
| 21 |
+
def zoom_height_event(self, event=None):
|
| 22 |
+
zoomed = self.zoom_height()
|
| 23 |
+
|
| 24 |
+
if zoomed is None:
|
| 25 |
+
self.top.bell()
|
| 26 |
+
else:
|
| 27 |
+
menu_status = 'Restore' if zoomed else 'Zoom'
|
| 28 |
+
self.editwin.update_menu_label(menu='options', index='* Height',
|
| 29 |
+
label=f'{menu_status} Height')
|
| 30 |
+
|
| 31 |
+
return "break"
|
| 32 |
+
|
| 33 |
+
def zoom_height(self):
|
| 34 |
+
top = self.top
|
| 35 |
+
|
| 36 |
+
width, height, x, y = get_window_geometry(top)
|
| 37 |
+
|
| 38 |
+
if top.wm_state() != 'normal':
|
| 39 |
+
# Can't zoom/restore window height for windows not in the 'normal'
|
| 40 |
+
# state, e.g. maximized and full-screen windows.
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
maxheight, maxy = self.get_max_height_and_y_coord()
|
| 45 |
+
except WmInfoGatheringError:
|
| 46 |
+
return None
|
| 47 |
+
|
| 48 |
+
if height != maxheight:
|
| 49 |
+
# Maximize the window's height.
|
| 50 |
+
set_window_geometry(top, (width, maxheight, x, maxy))
|
| 51 |
+
return True
|
| 52 |
+
else:
|
| 53 |
+
# Restore the window's height.
|
| 54 |
+
#
|
| 55 |
+
# .wm_geometry('') makes the window revert to the size requested
|
| 56 |
+
# by the widgets it contains.
|
| 57 |
+
top.wm_geometry('')
|
| 58 |
+
return False
|
| 59 |
+
|
| 60 |
+
def get_max_height_and_y_coord(self):
|
| 61 |
+
top = self.top
|
| 62 |
+
|
| 63 |
+
screen_dimensions = (top.winfo_screenwidth(),
|
| 64 |
+
top.winfo_screenheight())
|
| 65 |
+
if screen_dimensions not in self._max_height_and_y_coords:
|
| 66 |
+
orig_state = top.wm_state()
|
| 67 |
+
|
| 68 |
+
# Get window geometry info for maximized windows.
|
| 69 |
+
try:
|
| 70 |
+
top.wm_state('zoomed')
|
| 71 |
+
except tkinter.TclError:
|
| 72 |
+
# The 'zoomed' state is not supported by some esoteric WMs,
|
| 73 |
+
# such as Xvfb.
|
| 74 |
+
raise WmInfoGatheringError(
|
| 75 |
+
'Failed getting geometry of maximized windows, because ' +
|
| 76 |
+
'the "zoomed" window state is unavailable.')
|
| 77 |
+
top.update()
|
| 78 |
+
maxwidth, maxheight, maxx, maxy = get_window_geometry(top)
|
| 79 |
+
if sys.platform == 'win32':
|
| 80 |
+
# On Windows, the returned Y coordinate is the one before
|
| 81 |
+
# maximizing, so we use 0 which is correct unless a user puts
|
| 82 |
+
# their dock on the top of the screen (very rare).
|
| 83 |
+
maxy = 0
|
| 84 |
+
maxrooty = top.winfo_rooty()
|
| 85 |
+
|
| 86 |
+
# Get the "root y" coordinate for non-maximized windows with their
|
| 87 |
+
# y coordinate set to that of maximized windows. This is needed
|
| 88 |
+
# to properly handle different title bar heights for non-maximized
|
| 89 |
+
# vs. maximized windows, as seen e.g. in Windows 10.
|
| 90 |
+
top.wm_state('normal')
|
| 91 |
+
top.update()
|
| 92 |
+
orig_geom = get_window_geometry(top)
|
| 93 |
+
max_y_geom = orig_geom[:3] + (maxy,)
|
| 94 |
+
set_window_geometry(top, max_y_geom)
|
| 95 |
+
top.update()
|
| 96 |
+
max_y_geom_rooty = top.winfo_rooty()
|
| 97 |
+
|
| 98 |
+
# Adjust the maximum window height to account for the different
|
| 99 |
+
# title bar heights of non-maximized vs. maximized windows.
|
| 100 |
+
maxheight += maxrooty - max_y_geom_rooty
|
| 101 |
+
|
| 102 |
+
self._max_height_and_y_coords[screen_dimensions] = maxheight, maxy
|
| 103 |
+
|
| 104 |
+
set_window_geometry(top, orig_geom)
|
| 105 |
+
top.wm_state(orig_state)
|
| 106 |
+
|
| 107 |
+
return self._max_height_and_y_coords[screen_dimensions]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def get_window_geometry(top):
|
| 111 |
+
geom = top.wm_geometry()
|
| 112 |
+
m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
|
| 113 |
+
return tuple(map(int, m.groups()))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def set_window_geometry(top, geometry):
|
| 117 |
+
top.wm_geometry("{:d}x{:d}+{:d}+{:d}".format(*geometry))
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
from unittest import main
|
| 122 |
+
main('idlelib.idle_test.test_zoomheight', verbosity=2, exit=False)
|
| 123 |
+
|
| 124 |
+
# Add htest?
|
deepseek/lib/python3.10/idlelib/zzdummy.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Example extension, also used for testing.
|
| 2 |
+
|
| 3 |
+
See extend.txt for more details on creating an extension.
|
| 4 |
+
See config-extension.def for configuring an extension.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from idlelib.config import idleConf
|
| 8 |
+
from functools import wraps
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def format_selection(format_line):
|
| 12 |
+
"Apply a formatting function to all of the selected lines."
|
| 13 |
+
|
| 14 |
+
@wraps(format_line)
|
| 15 |
+
def apply(self, event=None):
|
| 16 |
+
head, tail, chars, lines = self.formatter.get_region()
|
| 17 |
+
for pos in range(len(lines) - 1):
|
| 18 |
+
line = lines[pos]
|
| 19 |
+
lines[pos] = format_line(self, line)
|
| 20 |
+
self.formatter.set_region(head, tail, chars, lines)
|
| 21 |
+
return 'break'
|
| 22 |
+
|
| 23 |
+
return apply
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class ZzDummy:
|
| 27 |
+
"""Prepend or remove initial text from selected lines."""
|
| 28 |
+
|
| 29 |
+
# Extend the format menu.
|
| 30 |
+
menudefs = [
|
| 31 |
+
('format', [
|
| 32 |
+
('Z in', '<<z-in>>'),
|
| 33 |
+
('Z out', '<<z-out>>'),
|
| 34 |
+
] )
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
def __init__(self, editwin):
|
| 38 |
+
"Initialize the settings for this extension."
|
| 39 |
+
self.editwin = editwin
|
| 40 |
+
self.text = editwin.text
|
| 41 |
+
self.formatter = editwin.fregion
|
| 42 |
+
|
| 43 |
+
@classmethod
|
| 44 |
+
def reload(cls):
|
| 45 |
+
"Load class variables from config."
|
| 46 |
+
cls.ztext = idleConf.GetOption('extensions', 'ZzDummy', 'z-text')
|
| 47 |
+
|
| 48 |
+
@format_selection
|
| 49 |
+
def z_in_event(self, line):
|
| 50 |
+
"""Insert text at the beginning of each selected line.
|
| 51 |
+
|
| 52 |
+
This is bound to the <<z-in>> virtual event when the extensions
|
| 53 |
+
are loaded.
|
| 54 |
+
"""
|
| 55 |
+
return f'{self.ztext}{line}'
|
| 56 |
+
|
| 57 |
+
@format_selection
|
| 58 |
+
def z_out_event(self, line):
|
| 59 |
+
"""Remove specific text from the beginning of each selected line.
|
| 60 |
+
|
| 61 |
+
This is bound to the <<z-out>> virtual event when the extensions
|
| 62 |
+
are loaded.
|
| 63 |
+
"""
|
| 64 |
+
zlength = 0 if not line.startswith(self.ztext) else len(self.ztext)
|
| 65 |
+
return line[zlength:]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
ZzDummy.reload()
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
import unittest
|
| 73 |
+
unittest.main('idlelib.idle_test.test_zzdummy', verbosity=2, exit=False)
|
deepseek/lib/python3.10/lib2to3/__pycache__/__main__.cpython-310.pyc
ADDED
|
Binary file (470 Bytes). View file
|
|
|
deepseek/lib/python3.10/lib2to3/__pycache__/btm_matcher.cpython-310.pyc
ADDED
|
Binary file (5.15 kB). View file
|
|
|
deepseek/lib/python3.10/lib2to3/__pycache__/fixer_base.cpython-310.pyc
ADDED
|
Binary file (6.27 kB). View file
|
|
|
deepseek/lib/python3.10/lib2to3/__pycache__/pygram.cpython-310.pyc
ADDED
|
Binary file (1.52 kB). View file
|
|
|