Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- evalkit_tf446/lib/python3.10/idlelib/CREDITS.txt +47 -0
- evalkit_tf446/lib/python3.10/idlelib/Icons/idle.ico +0 -0
- evalkit_tf446/lib/python3.10/idlelib/NEWS.txt +1321 -0
- evalkit_tf446/lib/python3.10/idlelib/NEWS2x.txt +660 -0
- evalkit_tf446/lib/python3.10/idlelib/TODO.txt +210 -0
- evalkit_tf446/lib/python3.10/idlelib/__init__.py +10 -0
- evalkit_tf446/lib/python3.10/idlelib/__main__.py +8 -0
- evalkit_tf446/lib/python3.10/idlelib/autocomplete_w.py +502 -0
- evalkit_tf446/lib/python3.10/idlelib/browser.py +258 -0
- evalkit_tf446/lib/python3.10/idlelib/calltip.py +205 -0
- evalkit_tf446/lib/python3.10/idlelib/codecontext.py +270 -0
- evalkit_tf446/lib/python3.10/idlelib/config-highlight.def +105 -0
- evalkit_tf446/lib/python3.10/idlelib/config-keys.def +309 -0
- evalkit_tf446/lib/python3.10/idlelib/config-main.def +93 -0
- evalkit_tf446/lib/python3.10/idlelib/config.py +911 -0
- evalkit_tf446/lib/python3.10/idlelib/debugobj_r.py +41 -0
- evalkit_tf446/lib/python3.10/idlelib/delegator.py +33 -0
- evalkit_tf446/lib/python3.10/idlelib/editor.py +1683 -0
- evalkit_tf446/lib/python3.10/idlelib/extend.txt +83 -0
- evalkit_tf446/lib/python3.10/idlelib/filelist.py +131 -0
- evalkit_tf446/lib/python3.10/idlelib/format.py +426 -0
- evalkit_tf446/lib/python3.10/idlelib/grep.py +221 -0
- evalkit_tf446/lib/python3.10/idlelib/help.html +1178 -0
- evalkit_tf446/lib/python3.10/idlelib/help.py +294 -0
- evalkit_tf446/lib/python3.10/idlelib/help_about.py +212 -0
- evalkit_tf446/lib/python3.10/idlelib/hyperparser.py +312 -0
- evalkit_tf446/lib/python3.10/idlelib/idle.bat +4 -0
- evalkit_tf446/lib/python3.10/idlelib/idle.py +14 -0
- evalkit_tf446/lib/python3.10/idlelib/idle.pyw +17 -0
- evalkit_tf446/lib/python3.10/idlelib/iomenu.py +437 -0
- evalkit_tf446/lib/python3.10/idlelib/macosx.py +301 -0
- evalkit_tf446/lib/python3.10/idlelib/mainmenu.py +126 -0
- evalkit_tf446/lib/python3.10/idlelib/outwin.py +187 -0
- evalkit_tf446/lib/python3.10/idlelib/percolator.py +118 -0
- evalkit_tf446/lib/python3.10/idlelib/pyshell.py +1713 -0
- evalkit_tf446/lib/python3.10/idlelib/redirector.py +174 -0
- evalkit_tf446/lib/python3.10/idlelib/runscript.py +213 -0
- evalkit_tf446/lib/python3.10/idlelib/scrolledlist.py +149 -0
- evalkit_tf446/lib/python3.10/idlelib/search.py +164 -0
- evalkit_tf446/lib/python3.10/idlelib/searchbase.py +210 -0
- evalkit_tf446/lib/python3.10/idlelib/searchengine.py +234 -0
- evalkit_tf446/lib/python3.10/idlelib/squeezer.py +345 -0
- evalkit_tf446/lib/python3.10/idlelib/stackviewer.py +155 -0
- evalkit_tf446/lib/python3.10/idlelib/textview.py +193 -0
- evalkit_tf446/lib/python3.10/idlelib/tooltip.py +186 -0
- evalkit_tf446/lib/python3.10/idlelib/tree.py +500 -0
- evalkit_tf446/lib/python3.10/idlelib/undo.py +366 -0
- evalkit_tf446/lib/python3.10/idlelib/util.py +21 -0
- evalkit_tf446/lib/python3.10/idlelib/window.py +98 -0
- evalkit_tf446/lib/python3.10/lib2to3/__pycache__/__init__.cpython-310.pyc +0 -0
evalkit_tf446/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 |
+
|
evalkit_tf446/lib/python3.10/idlelib/Icons/idle.ico
ADDED
|
|
evalkit_tf446/lib/python3.10/idlelib/NEWS.txt
ADDED
|
@@ -0,0 +1,1321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
What's New in IDLE 3.10.z
|
| 2 |
+
after 3.10.0 until 3.10.10?
|
| 3 |
+
Released 2023-04-03?
|
| 4 |
+
=========================
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
gh-97527: Fix a bug in the previous bugfix that caused IDLE to not
|
| 8 |
+
start when run with 3.10.8, 3.12.0a1, and at least Microsoft Python
|
| 9 |
+
3.10.2288.0 installed without the Lib/test package. 3.11.0 was never
|
| 10 |
+
affected.
|
| 11 |
+
|
| 12 |
+
gh-65802: Document handling of extensions in Save As dialogs.
|
| 13 |
+
|
| 14 |
+
gh-95191: Include prompts when saving Shell (interactive input/output).
|
| 15 |
+
|
| 16 |
+
gh-95511: Fix the Shell context menu copy-with-prompts bug of copying
|
| 17 |
+
an extra line when one selects whole lines.
|
| 18 |
+
|
| 19 |
+
gh-95471: Tweak Edit menu. Move 'Select All' above 'Cut' as it is used
|
| 20 |
+
with 'Cut' and 'Copy' but not 'Paste'. Add a separator between 'Replace'
|
| 21 |
+
and 'Go to Line' to help IDLE issue triagers.
|
| 22 |
+
|
| 23 |
+
gh-95411: Enable using IDLE's module browser with .pyw files.
|
| 24 |
+
|
| 25 |
+
gh-89610: Add .pyi as a recognized extension for IDLE on macOS. This allows
|
| 26 |
+
opening stub files by double clicking on them in the Finder.
|
| 27 |
+
|
| 28 |
+
bpo-28950: Apply IDLE syntax highlighting to `.pyi` files. Add util.py
|
| 29 |
+
for common components. Patch by Alex Waygood and Terry Jan Reedy.
|
| 30 |
+
|
| 31 |
+
bpo-46630: Make query dialogs on Windows start with a cursor in the
|
| 32 |
+
entry box.
|
| 33 |
+
|
| 34 |
+
bpo-46591: Make the IDLE doc URL on the About IDLE dialog clickable.
|
| 35 |
+
|
| 36 |
+
bpo-45296: Clarify close, quit, and exit in IDLE. In the File menu,
|
| 37 |
+
'Close' and 'Exit' are now 'Close Window' (the current one) and 'Exit'
|
| 38 |
+
is now 'Exit IDLE' (by closing all windows). In Shell, 'quit()' and
|
| 39 |
+
'exit()' mean 'close Shell'. If there are no other windows,
|
| 40 |
+
this also exits IDLE.
|
| 41 |
+
|
| 42 |
+
bpo-45495: Add context keywords 'case' and 'match' to completions list.
|
| 43 |
+
|
| 44 |
+
bpo-45296: On Windows, change exit/quit message to suggest Ctrl-D, which
|
| 45 |
+
works, instead of <Ctrl-Z Return>, which does not work in IDLE.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
What's New in IDLE 3.10.0
|
| 49 |
+
(since 3.9.0)
|
| 50 |
+
Released on 2021-10-04
|
| 51 |
+
=========================
|
| 52 |
+
|
| 53 |
+
bpo-45193: Make completion boxes appear on Ubuntu again.
|
| 54 |
+
|
| 55 |
+
bpo-40128: Mostly fix completions on macOS when not using tcl/tk 8.6.11
|
| 56 |
+
(as with 3.9).
|
| 57 |
+
|
| 58 |
+
bpo-33962: Move the indent space setting from the Font tab to the new Windows
|
| 59 |
+
tab. Patch by Mark Roseman and Terry Jan Reedy.
|
| 60 |
+
|
| 61 |
+
bpo-40468: Split the settings dialog General tab into Windows and Shell/Ed
|
| 62 |
+
tabs. Move help sources, which extend the Help menu, to the Extensions tab.
|
| 63 |
+
Make space for new options and shorten the dialog. The latter makes the
|
| 64 |
+
dialog better fit small screens.
|
| 65 |
+
|
| 66 |
+
bpo-44010: Highlight the new match statement's soft keywords: match, case,
|
| 67 |
+
and _. This highlighting is not perfect and will be incorrect in some rare
|
| 68 |
+
cases, especially for some _s in case patterns.
|
| 69 |
+
|
| 70 |
+
bpo-44026: Include interpreter's typo fix suggestions in message line
|
| 71 |
+
for NameErrors and AttributeErrors. Patch by E. Paine.
|
| 72 |
+
|
| 73 |
+
bpo-41611: Avoid occasional uncaught exceptions and freezing when using
|
| 74 |
+
completions on macOS.
|
| 75 |
+
|
| 76 |
+
bpo-37903: Add mouse actions to the shell sidebar. Left click and
|
| 77 |
+
optional drag selects one or more lines of text, as with the
|
| 78 |
+
editor line number sidebar. Right click after selecting text lines
|
| 79 |
+
displays a context menu with 'copy with prompts'. This zips together
|
| 80 |
+
prompts from the sidebar with lines from the selected text. This option
|
| 81 |
+
also appears on the context menu for the text.
|
| 82 |
+
|
| 83 |
+
bpo-43981: Fix reference leaks in test_sidebar and test_squeezer.
|
| 84 |
+
Patches by Terry Jan Reedy and Pablo Galindo
|
| 85 |
+
|
| 86 |
+
bpo-37892: Change Shell input indents from tabs to spaces. Shell input
|
| 87 |
+
now 'looks right'. Making this feasible motivated the shell sidebar.
|
| 88 |
+
|
| 89 |
+
bpo-37903: Move the Shell input prompt to a side bar.
|
| 90 |
+
|
| 91 |
+
bpo-43655: Make window managers on macOS and X Window recognize
|
| 92 |
+
IDLE dialog windows as dialogs.
|
| 93 |
+
|
| 94 |
+
bpo-42225: Document that IDLE can fail on Unix either from misconfigured IP
|
| 95 |
+
masquerade rules or failure displaying complex colored (non-ascii) characters.
|
| 96 |
+
|
| 97 |
+
bpo-43283: Document why printing to IDLE's Shell is often slower than
|
| 98 |
+
printing to a system terminal and that it can be made faster by
|
| 99 |
+
pre-formatting a single string before printing.
|
| 100 |
+
|
| 101 |
+
bpo-23544: Disable Debug=>Stack Viewer when user code is running or
|
| 102 |
+
Debugger is active, to prevent hang or crash. Patch by Zackery Spytz.
|
| 103 |
+
|
| 104 |
+
bpo-43008: Make IDLE invoke :func:`sys.excepthook` in normal,
|
| 105 |
+
2-process mode. User hooks were previously ignored.
|
| 106 |
+
Patch by Ken Hilton.
|
| 107 |
+
|
| 108 |
+
bpo-33065: Fix problem debugging user classes with __repr__ method.
|
| 109 |
+
|
| 110 |
+
bpo-32631: Finish zzdummy example extension module: make menu entries
|
| 111 |
+
work; add docstrings and tests with 100% coverage.
|
| 112 |
+
|
| 113 |
+
bpo-42508: Keep IDLE running on macOS. Remove obsolete workaround
|
| 114 |
+
that prevented running files with shortcuts when using new universal2
|
| 115 |
+
installers built on macOS 11.
|
| 116 |
+
|
| 117 |
+
bpo-42426: Fix reporting offset of the RE error in searchengine.
|
| 118 |
+
|
| 119 |
+
bpo-42416: Display docstrings in IDLE calltips in more cases,
|
| 120 |
+
by using inspect.getdoc.
|
| 121 |
+
|
| 122 |
+
bpo-33987: Mostly finish using ttk widgets, mainly for editor,
|
| 123 |
+
settings, and searches. Some patches by Mark Roseman.
|
| 124 |
+
|
| 125 |
+
bpo-40511: Stop unnecessary "flashing" when typing opening and closing
|
| 126 |
+
parentheses inside the parentheses of a function call.
|
| 127 |
+
|
| 128 |
+
bpo-38439: Add a 256x256 pixel IDLE icon to the Windows .ico file. Created by
|
| 129 |
+
Andrew Clover. Remove the low-color gif variations from the .ico file.
|
| 130 |
+
|
| 131 |
+
bpo-41775: Make 'IDLE Shell' the shell title.
|
| 132 |
+
|
| 133 |
+
bpo-35764: Rewrite the Calltips doc section.
|
| 134 |
+
|
| 135 |
+
bpo-40181: In calltips, stop reminding that '/' marks the end of
|
| 136 |
+
positional-only arguments.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
What's New in IDLE 3.9.0 (since 3.8.0)
|
| 140 |
+
Released on 2020-10-05?
|
| 141 |
+
======================================
|
| 142 |
+
|
| 143 |
+
bpo-41468: Improve IDLE run crash error message (which users should
|
| 144 |
+
never see).
|
| 145 |
+
|
| 146 |
+
bpo-41373: Save files loaded with no line ending, as when blank, or
|
| 147 |
+
different line endings, by setting its line ending to the system
|
| 148 |
+
default. Fix regression in 3.8.4 and 3.9.0b4.
|
| 149 |
+
|
| 150 |
+
bpo-41300: Save files with non-ascii chars. Fix regression in
|
| 151 |
+
3.9.0b4 and 3.8.4.
|
| 152 |
+
|
| 153 |
+
bpo-37765: Add keywords to module name completion list. Rewrite
|
| 154 |
+
Completions section of IDLE doc.
|
| 155 |
+
|
| 156 |
+
bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
|
| 157 |
+
is now always UTF-8.
|
| 158 |
+
|
| 159 |
+
bpo-41144: Make Open Module open a special module such as os.path.
|
| 160 |
+
|
| 161 |
+
bpo-40723: Make test_idle pass when run after import.
|
| 162 |
+
Patch by Florian Dahlitz.
|
| 163 |
+
|
| 164 |
+
bpo-38689: IDLE will no longer freeze when inspect.signature fails
|
| 165 |
+
when fetching a calltip.
|
| 166 |
+
|
| 167 |
+
bpo-27115: For 'Go to Line', use a Query entry box subclass with
|
| 168 |
+
IDLE standard behavior and improved error checking.
|
| 169 |
+
|
| 170 |
+
bpo-39885: When a context menu is invoked by right-clicking outside
|
| 171 |
+
of a selection, clear the selection and move the cursor. Cut and
|
| 172 |
+
Copy require that the click be within the selection.
|
| 173 |
+
|
| 174 |
+
bpo-39852: Edit "Go to line" now clears any selection, preventing
|
| 175 |
+
accidental deletion. It also updates Ln and Col on the status bar.
|
| 176 |
+
|
| 177 |
+
bpo-39781: Selecting code context lines no longer causes a jump.
|
| 178 |
+
|
| 179 |
+
bpo-39663: Add tests for pyparse find_good_parse_start().
|
| 180 |
+
|
| 181 |
+
bpo-39600: Remove duplicate font names from configuration list.
|
| 182 |
+
|
| 183 |
+
bpo-38792: Close a shell calltip if a :exc:`KeyboardInterrupt`
|
| 184 |
+
or shell restart occurs. Patch by Zackery Spytz.
|
| 185 |
+
|
| 186 |
+
bpo-30780: Add remaining configdialog tests for buttons and
|
| 187 |
+
highlights and keys tabs.
|
| 188 |
+
|
| 189 |
+
bpo-39388: Settings dialog Cancel button cancels pending changes.
|
| 190 |
+
|
| 191 |
+
bpo-39050: Settings dialog Help button again displays help text.
|
| 192 |
+
|
| 193 |
+
bpo-32989: Add tests for editor newline_and_indent_event method.
|
| 194 |
+
Remove unneeded arguments and dead code from pyparse
|
| 195 |
+
find_good_parse_start method.
|
| 196 |
+
|
| 197 |
+
bpo-38943: Fix autocomplete windows not always appearing on some
|
| 198 |
+
systems. Patch by Johnny Najera.
|
| 199 |
+
|
| 200 |
+
bpo-38944: Escape key now closes IDLE completion windows. Patch by
|
| 201 |
+
Johnny Najera.
|
| 202 |
+
|
| 203 |
+
bpo-38862: 'Strip Trailing Whitespace' on the Format menu removes extra
|
| 204 |
+
newlines at the end of non-shell files.
|
| 205 |
+
|
| 206 |
+
bpo-38636: Fix IDLE Format menu tab toggle and file indent width. These
|
| 207 |
+
functions (default shortcuts Alt-T and Alt-U) were mistakenly disabled
|
| 208 |
+
in 3.7.5 and 3.8.0.
|
| 209 |
+
|
| 210 |
+
bpo-4630: Add an option to toggle IDLE's cursor blink for shell,
|
| 211 |
+
editor, and output windows. See Settings, General, Window Preferences,
|
| 212 |
+
Cursor Blink. Patch by Zackery Spytz.
|
| 213 |
+
|
| 214 |
+
bpo-26353: Stop adding newline when saving an IDLE shell window.
|
| 215 |
+
|
| 216 |
+
bpo-38598: Do not try to compile IDLE shell or output windows.
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
What's New in IDLE 3.8.0 (since 3.7.0)
|
| 220 |
+
Released on 2019-10-14
|
| 221 |
+
======================================
|
| 222 |
+
|
| 223 |
+
bpo-36698: IDLE no longer fails when writing non-encodable characters
|
| 224 |
+
to stderr. It now escapes them with a backslash, like the regular
|
| 225 |
+
Python interpreter. Add an errors field to the standard streams.
|
| 226 |
+
|
| 227 |
+
bpo-13153: Improve tkinter's handing of non-BMP (astral) unicode
|
| 228 |
+
characters, such as 'rocket \U0001f680'. Whether a proper glyph or
|
| 229 |
+
replacement char is displayed depends on the OS and font. For IDLE,
|
| 230 |
+
astral chars in code interfere with editing.
|
| 231 |
+
|
| 232 |
+
bpo-35379: When exiting IDLE, catch any AttributeError. One happens
|
| 233 |
+
when EditorWindow.close is called twice. Printing a traceback, when
|
| 234 |
+
IDLE is run from a terminal, is useless and annoying.
|
| 235 |
+
|
| 236 |
+
bpo-38183: To avoid test issues, test_idle ignores the user config
|
| 237 |
+
directory. It no longer tries to create or access .idlerc or any files
|
| 238 |
+
within. Users must run IDLE to discover problems with saving settings.
|
| 239 |
+
|
| 240 |
+
bpo-38077: IDLE no longer adds 'argv' to the user namespace when
|
| 241 |
+
initializing it. This bug only affected 3.7.4 and 3.8.0b2 to 3.8.0b4.
|
| 242 |
+
|
| 243 |
+
bpo-38401: Shell restart lines now fill the window width, always start
|
| 244 |
+
with '=', and avoid wrapping unnecessarily. The line will still wrap
|
| 245 |
+
if the included file name is long relative to the width.
|
| 246 |
+
|
| 247 |
+
bpo-37092: Add mousewheel scrolling for IDLE module, path, and stack
|
| 248 |
+
browsers. Patch by George Zhang.
|
| 249 |
+
|
| 250 |
+
bpo-35771: To avoid occasional spurious test_idle failures on slower
|
| 251 |
+
machines, increase the ``hover_delay`` in test_tooltip.
|
| 252 |
+
|
| 253 |
+
bpo-37824: Properly handle user input warnings in IDLE shell.
|
| 254 |
+
Cease turning SyntaxWarnings into SyntaxErrors.
|
| 255 |
+
|
| 256 |
+
bpo-37929: IDLE Settings dialog now closes properly when there is no
|
| 257 |
+
shell window.
|
| 258 |
+
|
| 259 |
+
bpo-37849: Fix completions list appearing too high or low when shown
|
| 260 |
+
above the current line.
|
| 261 |
+
|
| 262 |
+
bpo-36419: Refactor autocompete and improve testing.
|
| 263 |
+
|
| 264 |
+
bpo-37748: Reorder the Run menu. Put the most common choice,
|
| 265 |
+
Run Module, at the top.
|
| 266 |
+
|
| 267 |
+
bpo-37692: Improve highlight config sample with example shell
|
| 268 |
+
interaction and better labels for shell elements.
|
| 269 |
+
|
| 270 |
+
bpo-37628: Settings dialog no longer expands with font size.
|
| 271 |
+
The font and highlight sample boxes gain scrollbars instead.
|
| 272 |
+
|
| 273 |
+
bpo-17535: Add optional line numbers for IDLE editor windows.
|
| 274 |
+
|
| 275 |
+
bpo-37627: Initialize the Customize Run dialog with the command line
|
| 276 |
+
arguments most recently entered before. The user can optionally edit
|
| 277 |
+
before submitting them.
|
| 278 |
+
|
| 279 |
+
bpo-33610: Code context always shows the correct context when toggled on.
|
| 280 |
+
|
| 281 |
+
bpo-36390: Gather Format menu functions into format.py. Combine
|
| 282 |
+
paragraph.py, rstrip.py, and format methods from editor.py.
|
| 283 |
+
|
| 284 |
+
bpo-37530: Optimize code context to reduce unneeded background activity.
|
| 285 |
+
Font and highlight changes now occur along with text changes instead
|
| 286 |
+
of after a random delay.
|
| 287 |
+
|
| 288 |
+
bpo-27452: Cleanup config.py by inlining RemoveFile and simplifying
|
| 289 |
+
the handling of __file__ in CreateConfigHandlers/
|
| 290 |
+
|
| 291 |
+
bpo-26806: To compensate for stack frames added by IDLE and avoid
|
| 292 |
+
possible problems with low recursion limits, add 30 to limits in the
|
| 293 |
+
user code execution process. Subtract 30 when reporting recursion
|
| 294 |
+
limits to make this addition mostly transparent.
|
| 295 |
+
|
| 296 |
+
bpo-37325: Fix tab focus traversal order for help source and custom
|
| 297 |
+
run dialogs.
|
| 298 |
+
|
| 299 |
+
bpo-37321: Both subprocess connection error messages now refer to
|
| 300 |
+
the 'Startup failure' section of the IDLE doc.
|
| 301 |
+
|
| 302 |
+
bpo-37177: Properly attach search dialogs to their main window so
|
| 303 |
+
that they behave like other dialogs and do not get hidden behind
|
| 304 |
+
their main window.
|
| 305 |
+
|
| 306 |
+
bpo-37039: Adjust "Zoom Height" to individual screens by momentarily
|
| 307 |
+
maximizing the window on first use with a particular screen. Changing
|
| 308 |
+
screen settings may invalidate the saved height. While a window is
|
| 309 |
+
maximized, "Zoom Height" has no effect.
|
| 310 |
+
|
| 311 |
+
bpo-35763: Make calltip reminder about '/' meaning positional-only less
|
| 312 |
+
obtrusive by only adding it when there is room on the first line.
|
| 313 |
+
|
| 314 |
+
bpo-5680: Add 'Run Customized' to the Run menu to run a module with
|
| 315 |
+
customized settings. Any command line arguments entered are added
|
| 316 |
+
to sys.argv. One can suppress the normal Shell main module restart.
|
| 317 |
+
|
| 318 |
+
bpo-35610: Replace now redundant editor.context_use_ps1 with
|
| 319 |
+
.prompt_last_line. This finishes change started in bpo-31858.
|
| 320 |
+
|
| 321 |
+
bpo-32411: Stop sorting dict created with desired line order.
|
| 322 |
+
|
| 323 |
+
bpo-37038: Make idlelib.run runnable; add test clause.
|
| 324 |
+
|
| 325 |
+
bpo-36958: Print any argument other than None or int passed to
|
| 326 |
+
SystemExit or sys.exit().
|
| 327 |
+
|
| 328 |
+
bpo-36807: When saving a file, call file.flush() and os.fsync()
|
| 329 |
+
so bits are flushed to e.g. a USB drive.
|
| 330 |
+
|
| 331 |
+
bpo-36429: Fix starting IDLE with pyshell.
|
| 332 |
+
Add idlelib.pyshell alias at top; remove pyshell alias at bottom.
|
| 333 |
+
Remove obsolete __name__=='__main__' command.
|
| 334 |
+
|
| 335 |
+
bpo-30348: Increase test coverage of idlelib.autocomplete by 30%.
|
| 336 |
+
Patch by Louie Lu.
|
| 337 |
+
|
| 338 |
+
bpo-23205: Add tests and refactor grep's findfiles.
|
| 339 |
+
|
| 340 |
+
bpo-36405: Use dict unpacking in idlelib.
|
| 341 |
+
|
| 342 |
+
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
|
| 343 |
+
This param was only used twice and changed the return type.
|
| 344 |
+
|
| 345 |
+
bpo-23216: IDLE: Add docstrings to search modules.
|
| 346 |
+
|
| 347 |
+
bpo-36176: Fix IDLE autocomplete & calltip popup colors.
|
| 348 |
+
Prevent conflicts with Linux dark themes
|
| 349 |
+
(and slightly darken calltip background).
|
| 350 |
+
|
| 351 |
+
bpo-36152: Remove colorizer.ColorDelegator.close_when_done and the
|
| 352 |
+
corresponding argument of .close(). In IDLE, both have always been
|
| 353 |
+
None or False since 2007.
|
| 354 |
+
|
| 355 |
+
bpo-36096: Make colorizer state variables instance-only.
|
| 356 |
+
|
| 357 |
+
bpo-32129: Avoid blurry IDLE application icon on macOS with Tk 8.6.
|
| 358 |
+
Patch by Kevin Walzer.
|
| 359 |
+
|
| 360 |
+
bpo-24310: Document settings dialog font tab sample.
|
| 361 |
+
|
| 362 |
+
bpo-35689: Add docstrings and tests for colorizer.
|
| 363 |
+
|
| 364 |
+
bpo-35833: Revise IDLE doc for control codes sent to Shell.
|
| 365 |
+
Add a code example block.
|
| 366 |
+
|
| 367 |
+
bpo-35770: IDLE macosx deletes Options => Configure IDLE.
|
| 368 |
+
It previously deleted Window => Zoom Height by mistake.
|
| 369 |
+
(Zoom Height is now on the Options menu). On Mac, the settings
|
| 370 |
+
dialog is accessed via Preferences on the IDLE menu.
|
| 371 |
+
|
| 372 |
+
bpo-35769: Change new file name from 'Untitled' to 'untitled'.
|
| 373 |
+
|
| 374 |
+
bpo-35660: Fix imports in window module.
|
| 375 |
+
|
| 376 |
+
bpo-35641: Properly format calltip for function without docstring.
|
| 377 |
+
|
| 378 |
+
bpo-33987: Use ttk Frame for ttk widgets.
|
| 379 |
+
|
| 380 |
+
bpo-34055: Fix erroneous 'smart' indents and newlines in IDLE Shell.
|
| 381 |
+
|
| 382 |
+
bpo-28097: Add Previous/Next History entries to Shell menu.
|
| 383 |
+
|
| 384 |
+
bpo-35591: Find Selection now works when selection not found.
|
| 385 |
+
|
| 386 |
+
bpo-35598: Update config_key: use PEP 8 names and ttk widgets,
|
| 387 |
+
make some objects global, and add tests.
|
| 388 |
+
|
| 389 |
+
bpo-35196: Speed up squeezer line counting.
|
| 390 |
+
|
| 391 |
+
bpo-35208: Squeezer now counts wrapped lines before newlines.
|
| 392 |
+
|
| 393 |
+
bpo-35555: Gray out Code Context menu entry when it's not applicable.
|
| 394 |
+
|
| 395 |
+
bpo-22703: Improve the Code Context and Zoom Height menu labels.
|
| 396 |
+
The Code Context menu label now toggles between Show/Hide Code Context.
|
| 397 |
+
The Zoom Height menu now toggles between Zoom/Restore Height.
|
| 398 |
+
Zoom Height has moved from the Window menu to the Options menu.
|
| 399 |
+
|
| 400 |
+
bpo-35521: Document the editor code context feature.
|
| 401 |
+
Add some internal references within the IDLE doc.
|
| 402 |
+
|
| 403 |
+
bpo-34864: When starting IDLE on MacOS, warn if the system setting
|
| 404 |
+
"Prefer tabs when opening documents" is "Always". As previous
|
| 405 |
+
documented for this issue, running IDLE with this setting causes
|
| 406 |
+
problems. If the setting is changed while IDLE is running,
|
| 407 |
+
there will be no warning until IDLE is restarted.
|
| 408 |
+
|
| 409 |
+
bpo-35213: Where appropriate, use 'macOS' in idlelib.
|
| 410 |
+
|
| 411 |
+
bpo-34864: Document two IDLE on MacOS issues. The System Preferences
|
| 412 |
+
Dock "prefer tabs always" setting disables some IDLE features.
|
| 413 |
+
Menus are a bit different than as described for Windows and Linux.
|
| 414 |
+
|
| 415 |
+
bpo-35202: Remove unused imports in idlelib.
|
| 416 |
+
|
| 417 |
+
bpo-33000: Document that IDLE's shell has no line limit.
|
| 418 |
+
A program that runs indefinitely can overfill memory.
|
| 419 |
+
|
| 420 |
+
bpo-23220: Explain how IDLE's Shell displays output.
|
| 421 |
+
Add new subsection "User output in Shell".
|
| 422 |
+
|
| 423 |
+
bpo-35099: Improve the doc about IDLE running user code.
|
| 424 |
+
"IDLE -- console differences" is renamed "Running user code".
|
| 425 |
+
It mostly covers the implications of using custom sys.stdxxx objects.
|
| 426 |
+
|
| 427 |
+
bpo-35097: Add IDLE doc subsection explaining editor windows.
|
| 428 |
+
Topics include opening, title and status bars, .py* extension, and running.
|
| 429 |
+
|
| 430 |
+
Issue 35093: Document the IDLE document viewer in the IDLE doc.
|
| 431 |
+
Add a paragraph in "Help and preferences", "Help sources" subsection.
|
| 432 |
+
|
| 433 |
+
bpo-1529353: Explain Shell text squeezing in the IDLE doc.
|
| 434 |
+
|
| 435 |
+
bpo-35088: Update idlelib.help.copy_string docstring.
|
| 436 |
+
We now use git and backporting instead of hg and forward merging.
|
| 437 |
+
|
| 438 |
+
bpo-35087: Update idlelib help files for the current doc build.
|
| 439 |
+
The main change is the elimination of chapter-section numbers.
|
| 440 |
+
|
| 441 |
+
bpo-1529353: Output over N lines (50 by default) is squeezed down to a button.
|
| 442 |
+
N can be changed in the PyShell section of the General page of the
|
| 443 |
+
Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
|
| 444 |
+
right clicking on the output. Squeezed output can be expanded in place
|
| 445 |
+
by double-clicking the button or into the clipboard or a separate window
|
| 446 |
+
by right-clicking the button.
|
| 447 |
+
|
| 448 |
+
bpo-34548: Use configured color theme for read-only text views.
|
| 449 |
+
|
| 450 |
+
bpo-33839: Refactor ToolTip and CallTip classes; add documentation
|
| 451 |
+
and tests.
|
| 452 |
+
|
| 453 |
+
bpo-34047: Fix mouse wheel scrolling direction on macOS.
|
| 454 |
+
|
| 455 |
+
bpo-34275: Make calltips always visible on Mac.
|
| 456 |
+
Patch by Kevin Walzer.
|
| 457 |
+
|
| 458 |
+
bpo-34120: Fix freezing after closing some dialogs on Mac.
|
| 459 |
+
This is one of multiple regressions from using newer tcl/tk.
|
| 460 |
+
|
| 461 |
+
bpo-33975: Avoid small type when running htests.
|
| 462 |
+
Since part of the purpose of human-viewed tests is to determine that
|
| 463 |
+
widgets look right, it is important that they look the same for
|
| 464 |
+
testing as when running IDLE.
|
| 465 |
+
|
| 466 |
+
bpo-33905: Add test for idlelib.stackview.StackBrowser.
|
| 467 |
+
|
| 468 |
+
bpo-33924: Change mainmenu.menudefs key 'windows' to 'window'.
|
| 469 |
+
Every other menudef key is the lowercase version of the
|
| 470 |
+
corresponding main menu entry (in this case, 'Window').
|
| 471 |
+
|
| 472 |
+
bpo-33906: Rename idlelib.windows as window
|
| 473 |
+
Match Window on the main menu and remove last plural module name.
|
| 474 |
+
Change imports, test, and attribute references to match new name.
|
| 475 |
+
|
| 476 |
+
bpo-33917: Fix and document idlelib/idle_test/template.py.
|
| 477 |
+
The revised file compiles, runs, and tests OK. idle_test/README.txt
|
| 478 |
+
explains how to use it to create new IDLE test files.
|
| 479 |
+
|
| 480 |
+
bpo-33904: In rstrip module, rename class RstripExtension as Rstrip.
|
| 481 |
+
|
| 482 |
+
bpo-33907: For consistency and clarity, rename calltip objects.
|
| 483 |
+
Module calltips and its class CallTips are now calltip and Calltip.
|
| 484 |
+
In module calltip_w, class CallTip is now CalltipWindow.
|
| 485 |
+
|
| 486 |
+
bpo-33855: Minimally test all IDLE modules.
|
| 487 |
+
Standardize the test file format. Add missing test files that import
|
| 488 |
+
the tested module and perform at least one test. Check and record the
|
| 489 |
+
coverage of each test.
|
| 490 |
+
|
| 491 |
+
bpo-33856: Add 'help' to Shell's initial welcome message.
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
What's New in IDLE 3.7.0 (since 3.6.0)
|
| 495 |
+
Released on 2018-06-27
|
| 496 |
+
======================================
|
| 497 |
+
|
| 498 |
+
bpo-33656: On Windows, add API call saying that tk scales for DPI.
|
| 499 |
+
On Windows 8.1+ or 10, with DPI compatibility properties of the Python
|
| 500 |
+
binary unchanged, and a monitor resolution greater than 96 DPI, this
|
| 501 |
+
should make text and lines sharper and some colors brighter.
|
| 502 |
+
On other systems, it should have no effect. If you have a custom theme,
|
| 503 |
+
you may want to adjust a color or two. If perchance it make text worse
|
| 504 |
+
on your monitor, you can disable the ctypes.OleDLL call near the top of
|
| 505 |
+
pyshell.py and report the problem on python-list or idle-dev@python.org.
|
| 506 |
+
|
| 507 |
+
bpo-33768: Clicking on a context line moves that line to the top
|
| 508 |
+
of the editor window.
|
| 509 |
+
|
| 510 |
+
bpo-33763: Replace the code context label widget with a text widget.
|
| 511 |
+
|
| 512 |
+
bpo-33664: Scroll IDLE editor text by lines.
|
| 513 |
+
(Previously, the mouse wheel and scrollbar slider moved text by a fixed
|
| 514 |
+
number of pixels, resulting in partial lines at the top of the editor
|
| 515 |
+
box.) This change also applies to the shell and grep output windows,
|
| 516 |
+
but currently not to read-only text views.
|
| 517 |
+
|
| 518 |
+
bpo-33679: Enable theme-specific color configuration for Code Context.
|
| 519 |
+
(Previously, there was one code context foreground and background font
|
| 520 |
+
color setting, default or custom, on the extensions tab, that applied
|
| 521 |
+
to all themes.) For built-in themes, the foreground is the same as
|
| 522 |
+
normal text and the background is a contrasting gray. Context colors for
|
| 523 |
+
custom themes are set on the Hightlights tab along with other colors.
|
| 524 |
+
When one starts IDLE from a console and loads a custom theme without
|
| 525 |
+
definitions for 'context', one will see a warning message on the
|
| 526 |
+
console.
|
| 527 |
+
|
| 528 |
+
bpo-33642: Display up to maxlines non-blank lines for Code Context.
|
| 529 |
+
If there is no current context, show a single blank line. (Previously,
|
| 530 |
+
the Code Contex had numlines lines, usually with some blank.) The use
|
| 531 |
+
of a new option, 'maxlines' (default 15), avoids possible interference
|
| 532 |
+
with user settings of the old option, 'numlines' (default 3).
|
| 533 |
+
|
| 534 |
+
bpo-33628: Cleanup codecontext.py and its test.
|
| 535 |
+
|
| 536 |
+
bpo-32831: Add docstrings and tests for codecontext.py.
|
| 537 |
+
Coverage is 100%. Patch by Cheryl Sabella.
|
| 538 |
+
|
| 539 |
+
bpo-33564: Code context now recognizes async as a block opener.
|
| 540 |
+
|
| 541 |
+
bpo-21474: Update word/identifier definition from ascii to unicode.
|
| 542 |
+
In text and entry boxes, this affects selection by double-click,
|
| 543 |
+
movement left/right by control-left/right, and deletion left/right
|
| 544 |
+
by control-BACKSPACE/DEL.
|
| 545 |
+
|
| 546 |
+
bpo-33204: Consistently color invalid string prefixes.
|
| 547 |
+
A 'u' string prefix cannot be paired with either 'r' or 'f'.
|
| 548 |
+
IDLE now consistently colors as much of the prefix, starting at the
|
| 549 |
+
right, as is valid. Revise and extend colorizer test.
|
| 550 |
+
|
| 551 |
+
bpo-32984: Set __file__ while running a startup file.
|
| 552 |
+
Like Python, IDLE optionally runs 1 startup file in the Shell window
|
| 553 |
+
before presenting the first interactive input prompt. For IDLE,
|
| 554 |
+
option -s runs a file named in environmental variable IDLESTARTUP or
|
| 555 |
+
PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup
|
| 556 |
+
file name before running the file and unsets it before the first
|
| 557 |
+
prompt. IDLE now does the same when run normally, without the -n
|
| 558 |
+
option.
|
| 559 |
+
|
| 560 |
+
bpo-32940: Replace StringTranslatePseudoMapping with faster code.
|
| 561 |
+
|
| 562 |
+
bpo-32916: Change 'str' to 'code' in idlelib.pyparse and users.
|
| 563 |
+
|
| 564 |
+
bpo-32905: Remove unused code in pyparse module.
|
| 565 |
+
|
| 566 |
+
bpo-32874: IDLE - add pyparse tests with 97% coverage.
|
| 567 |
+
|
| 568 |
+
bpo-32837: IDLE - require encoding argument for textview.view_file.
|
| 569 |
+
Using the system and place-dependent default encoding for open()
|
| 570 |
+
is a bad idea for IDLE's system and location-independent files.
|
| 571 |
+
|
| 572 |
+
bpo-32826: Add "encoding=utf-8" to open() in IDLE's test_help_about.
|
| 573 |
+
GUI test test_file_buttons() only looks at initial ascii-only lines,
|
| 574 |
+
but failed on systems where open() defaults to 'ascii' because
|
| 575 |
+
readline() internally reads and decodes far enough ahead to encounter
|
| 576 |
+
a non-ascii character in CREDITS.txt.
|
| 577 |
+
|
| 578 |
+
bpo-32765: Update configdialog General tab create page docstring.
|
| 579 |
+
Add new widgets to the widget list.
|
| 580 |
+
|
| 581 |
+
bpo-32207: Improve tk event exception tracebacks in IDLE.
|
| 582 |
+
When tk event handling is driven by IDLE's run loop, a confusing
|
| 583 |
+
and distracting queue.EMPTY traceback context is no longer added
|
| 584 |
+
to tk event exception tracebacks. The traceback is now the same
|
| 585 |
+
as when event handling is driven by user code. Patch based on
|
| 586 |
+
a suggestion by Serhiy Storchaka.
|
| 587 |
+
|
| 588 |
+
bpo-32164: Delete unused file idlelib/tabbedpages.py.
|
| 589 |
+
Use of TabbedPageSet in configdialog was replaced by ttk.Notebook.
|
| 590 |
+
|
| 591 |
+
bpo-32100: Fix old and new bugs in pathbrowser; improve tests.
|
| 592 |
+
Patch mostly by Cheryl Sabella.
|
| 593 |
+
|
| 594 |
+
bpo-31860: The font sample in the settings dialog is now editable.
|
| 595 |
+
Edits persist while IDLE remains open.
|
| 596 |
+
Patch by Serhiy Storchake and Terry Jan Reedy.
|
| 597 |
+
|
| 598 |
+
bpo-31858: Restrict shell prompt manipulation to the shell.
|
| 599 |
+
Editor and output windows only see an empty last prompt line. This
|
| 600 |
+
simplifies the code and fixes a minor bug when newline is inserted.
|
| 601 |
+
Sys.ps1, if present, is read on Shell start-up, but is not set or changed.
|
| 602 |
+
Patch by Terry Jan Reedy.
|
| 603 |
+
|
| 604 |
+
bpo-28603: Fix a TypeError that caused a shell restart when printing
|
| 605 |
+
a traceback that includes an exception that is unhashable.
|
| 606 |
+
Patch by Zane Bitter.
|
| 607 |
+
|
| 608 |
+
bpo-13802: Use non-Latin characters in the Font settings sample.
|
| 609 |
+
Even if one selects a font that defines a limited subset of the unicode
|
| 610 |
+
Basic Multilingual Plane, tcl/tk will use other fonts that define a
|
| 611 |
+
character. The expanded example give users of non-Latin characters
|
| 612 |
+
a better idea of what they might see in the shell and editors.
|
| 613 |
+
|
| 614 |
+
To make room for the expanded sample, frames on the Font tab are
|
| 615 |
+
re-arranged. The Font/Tabs help explains a bit about the additions.
|
| 616 |
+
Patch by Terry Jan Reedy
|
| 617 |
+
|
| 618 |
+
bpo-31460: Simplify the API of IDLE's Module Browser.
|
| 619 |
+
Passing a widget instead of an flist with a root widget opens the
|
| 620 |
+
option of creating a browser frame that is only part of a window.
|
| 621 |
+
Passing a full file name instead of pieces assumed to come from a
|
| 622 |
+
.py file opens the possibility of browsing python files that do not
|
| 623 |
+
end in .py.
|
| 624 |
+
|
| 625 |
+
bpo-31649: Make _htest and _utest parameters keyword-only.
|
| 626 |
+
These are used to adjust code for human and unit tests.
|
| 627 |
+
|
| 628 |
+
bpo-31459: Rename module browser from Class Browser to Module Browser.
|
| 629 |
+
The original module-level class and method browser became a module
|
| 630 |
+
browser, with the addition of module-level functions, years ago.
|
| 631 |
+
Nested classes and functions were added yesterday. For back-
|
| 632 |
+
compatibility, the virtual event <<open-class-browser>>, which
|
| 633 |
+
appears on the Keys tab of the Settings dialog, is not changed.
|
| 634 |
+
Patch by Cheryl Sabella.
|
| 635 |
+
|
| 636 |
+
bpo-1612262: Module browser now shows nested classes and functions.
|
| 637 |
+
Original patches for code and tests by Guilherme Polo and
|
| 638 |
+
Cheryl Sabella, respectively. Revisions by Terry Jan Reedy.
|
| 639 |
+
|
| 640 |
+
bpo-31500: Tk's default fonts now are scaled on HiDPI displays.
|
| 641 |
+
This affects all dialogs. Patch by Serhiy Storchaka.
|
| 642 |
+
|
| 643 |
+
bpo-31493: Fix code context update and font update timers.
|
| 644 |
+
Canceling timers prevents a warning message when test_idle completes.
|
| 645 |
+
|
| 646 |
+
bpo-31488: Update non-key options in former extension classes.
|
| 647 |
+
When applying configdialog changes, call .reload for each feature class.
|
| 648 |
+
Change ParenMatch so updated options affect existing instances attached
|
| 649 |
+
to existing editor windows.
|
| 650 |
+
|
| 651 |
+
bpo-31477: Improve rstrip entry in IDLE doc.
|
| 652 |
+
Strip Trailing Whitespace strips more than blank spaces.
|
| 653 |
+
Multiline string literals are not skipped.
|
| 654 |
+
|
| 655 |
+
bpo-31480: fix tests to pass with zzdummy extension disabled. (#3590)
|
| 656 |
+
To see the example in action, enable it on options extensions tab.
|
| 657 |
+
|
| 658 |
+
bpo-31421: Document how IDLE runs tkinter programs.
|
| 659 |
+
IDLE calls tcl/tk update in the background in order to make live
|
| 660 |
+
interaction and experimentation with tkinter applications much easier.
|
| 661 |
+
|
| 662 |
+
bpo-31414: Fix tk entry box tests by deleting first.
|
| 663 |
+
Adding to an int entry is not the same as deleting and inserting
|
| 664 |
+
because int('') will fail. Patch by Terry Jan Reedy.
|
| 665 |
+
|
| 666 |
+
bpo-27099: Convert IDLE's built-in 'extensions' to regular features.
|
| 667 |
+
About 10 IDLE features were implemented as supposedly optional
|
| 668 |
+
extensions. Their different behavior could be confusing or worse for
|
| 669 |
+
users and not good for maintenance. Hence the conversion.
|
| 670 |
+
The main difference for users is that user configurable key bindings
|
| 671 |
+
for builtin features are now handled uniformly. Now, editing a binding
|
| 672 |
+
in a keyset only affects its value in the keyset. All bindings are
|
| 673 |
+
defined together in the system-specific default keysets in config-
|
| 674 |
+
extensions.def. All custom keysets are saved as a whole in config-
|
| 675 |
+
extension.cfg. All take effect as soon as one clicks Apply or Ok.
|
| 676 |
+
The affected events are '<<force-open-completions>>',
|
| 677 |
+
'<<expand-word>>', '<<force-open-calltip>>', '<<flash-paren>>',
|
| 678 |
+
'<<format-paragraph>>', '<<run-module>>', '<<check-module>>', and
|
| 679 |
+
'<<zoom-height>>'. Any (global) customizations made before 3.6.3 will
|
| 680 |
+
not affect their keyset-specific customization after 3.6.3. and vice
|
| 681 |
+
versa.
|
| 682 |
+
Initial patch by Charles Wohlganger, revised by Terry Jan Reedy.
|
| 683 |
+
|
| 684 |
+
bpo-31051: Rearrange condigdialog General tab.
|
| 685 |
+
Sort non-Help options into Window (Shell+Editor) and Editor (only).
|
| 686 |
+
Leave room for the addition of new options.
|
| 687 |
+
Patch by Terry Jan Reedy.
|
| 688 |
+
|
| 689 |
+
bpo-30617: Add docstrings and tests for outwin subclass of editor.
|
| 690 |
+
Move some data and functions from the class to module level.
|
| 691 |
+
Patch by Cheryl Sabella.
|
| 692 |
+
|
| 693 |
+
bpo-31287: Do not modify tkinter.messagebox in test_configdialog.
|
| 694 |
+
Instead, mask it with an instance mock that can be deleted.
|
| 695 |
+
Patch by Terry Jan Reedy.
|
| 696 |
+
|
| 697 |
+
bpo-30781: Use ttk widgets in ConfigDialog pages.
|
| 698 |
+
These should especially look better on MacOSX.
|
| 699 |
+
Patches by Terry Jan Reedy and Cheryl Sabella.
|
| 700 |
+
|
| 701 |
+
bpo-31206: Factor HighPage(Frame) class from ConfigDialog.
|
| 702 |
+
Patch by Cheryl Sabella.
|
| 703 |
+
|
| 704 |
+
bp0-31001: Add tests for configdialog highlight tab.
|
| 705 |
+
Patch by Cheryl Sabella.
|
| 706 |
+
|
| 707 |
+
bpo-31205: Factor KeysPage(Frame) class from ConfigDialog.
|
| 708 |
+
The slightly modified tests continue to pass.
|
| 709 |
+
Patch by Cheryl Sabella.
|
| 710 |
+
|
| 711 |
+
bpo-31002: Add tests for configdialog keys tab.
|
| 712 |
+
Patch by Cheryl Sabella.
|
| 713 |
+
|
| 714 |
+
bpo-19903: Change calltipes to use inspect.signature.
|
| 715 |
+
Idlelib.calltips.get_argspec now uses inspect.signature instead of
|
| 716 |
+
inspect.getfullargspec, like help() does. This improves the signature
|
| 717 |
+
in the call tip in a few different cases, including builtins converted
|
| 718 |
+
to provide a signature. A message is added if the object is not
|
| 719 |
+
callable, has an invalid signature, or if it has positional-only
|
| 720 |
+
parameters. Patch by Louie Lu.
|
| 721 |
+
|
| 722 |
+
bop-31083: Add an outline of a TabPage class in configdialog.
|
| 723 |
+
Add template as comment. Update existing classes to match outline.
|
| 724 |
+
Initial patch by Cheryl Sabella.
|
| 725 |
+
|
| 726 |
+
bpo-31050: Factor GenPage(Frame) class from ConfigDialog.
|
| 727 |
+
The slightly modified tests for the General tab continue to pass.
|
| 728 |
+
Patch by Cheryl Sabella.
|
| 729 |
+
|
| 730 |
+
bpo-31004: Factor FontPage(Frame) class from ConfigDialog.
|
| 731 |
+
The slightly modified tests continue to pass. The General test
|
| 732 |
+
broken by the switch to ttk.Notebook is fixed.
|
| 733 |
+
Patch mostly by Cheryl Sabella.
|
| 734 |
+
|
| 735 |
+
bpo-30781: IDLE - Use ttk Notebook in ConfigDialog.
|
| 736 |
+
This improves navigation by tabbing.
|
| 737 |
+
Patch by Terry Jan Reedy.
|
| 738 |
+
|
| 739 |
+
bpo-31060: IDLE - Finish rearranging methods of ConfigDialog.
|
| 740 |
+
Grouping methods pertaining to each tab and the buttons will aid
|
| 741 |
+
writing tests and improving the tabs and will enable splitting the
|
| 742 |
+
groups into classes.
|
| 743 |
+
Patch by Terry Jan Reedy.
|
| 744 |
+
|
| 745 |
+
bpo-30853: IDLE -- Factor a VarTrace class out of ConfigDialog.
|
| 746 |
+
Instance tracers manages pairs consisting of a tk variable and a
|
| 747 |
+
callback function. When tracing is turned on, setting the variable
|
| 748 |
+
calls the function. Test coverage for the new class is 100%.
|
| 749 |
+
Patch by Terry Jan Reedy.
|
| 750 |
+
|
| 751 |
+
bpo-31003: IDLE: Add more tests for General tab.
|
| 752 |
+
Patch by Terry Jan Reedy.
|
| 753 |
+
|
| 754 |
+
bpo-30993: IDLE - Improve configdialog font page and tests.
|
| 755 |
+
*In configdialog: Document causal pathways in create_font_tab
|
| 756 |
+
docstring. Simplify some attribute names. Move set_samples calls to
|
| 757 |
+
var_changed_font (idea from Cheryl Sabella). Move related functions to
|
| 758 |
+
positions after the create widgets function.
|
| 759 |
+
* In test_configdialog: Fix test_font_set so not order dependent. Fix
|
| 760 |
+
renamed test_indent_scale so it tests the widget. Adjust tests for
|
| 761 |
+
movement of set_samples call. Add tests for load functions. Put all
|
| 762 |
+
font tests in one class and tab indent tests in another. Except for
|
| 763 |
+
two lines, these tests completely cover the related functions.
|
| 764 |
+
Patch by Terry Jan Reedy.
|
| 765 |
+
|
| 766 |
+
bpo-30981: IDLE -- Add more configdialog font page tests.
|
| 767 |
+
|
| 768 |
+
bpo-28523: IDLE: replace 'colour' with 'color' in configdialog.
|
| 769 |
+
|
| 770 |
+
bpo-30917: Add tests for idlelib.config.IdleConf.
|
| 771 |
+
Increase coverage from 46% to 96%.
|
| 772 |
+
Patch by Louie Lu.
|
| 773 |
+
|
| 774 |
+
bpo-30913: Document ConfigDialog tk Vars, methods, and widgets in docstrings
|
| 775 |
+
This will facilitate improving the dialog and splitting up the class.
|
| 776 |
+
Original patch by Cheryl Sabella.
|
| 777 |
+
|
| 778 |
+
bpo-30899: Add tests for ConfigParser subclasses in config.
|
| 779 |
+
Coverage is 100% for those classes and ConfigChanges.
|
| 780 |
+
Patch by Louie Lu.
|
| 781 |
+
|
| 782 |
+
bpo-30881: Add docstrings to browser.py.
|
| 783 |
+
Patch by Cheryl Sabella.
|
| 784 |
+
|
| 785 |
+
bpo-30851: Remove unused tk variables in configdialog.
|
| 786 |
+
One is a duplicate, one is set but cannot be altered by users.
|
| 787 |
+
Patch by Cheryl Sabella.
|
| 788 |
+
|
| 789 |
+
bpo-30870: Select font option with Up and Down keys, as well as with mouse.
|
| 790 |
+
Added test increases configdialog coverage to 60%
|
| 791 |
+
Patches mostly by Louie Lu.
|
| 792 |
+
|
| 793 |
+
bpo-8231: Call config.IdleConf.GetUserCfgDir only once per process.
|
| 794 |
+
|
| 795 |
+
bpo-30779: Factor ConfigChanges class from configdialog, put in config; test.
|
| 796 |
+
* In config, put dump test code in a function; run it and unittest in
|
| 797 |
+
'if __name__ == '__main__'.
|
| 798 |
+
* Add class config.ConfigChanges based on changes_class_v4.py on bpo issue.
|
| 799 |
+
* Add class test_config.ChangesTest, partly using configdialog_tests_v1.py.
|
| 800 |
+
* Revise configdialog to use ConfigChanges; see tracker msg297804.
|
| 801 |
+
* Revise test_configdialog to match configdialog changes.
|
| 802 |
+
* Remove configdialog functions unused or moved to ConfigChanges.
|
| 803 |
+
Cheryl Sabella contributed parts of the patch.
|
| 804 |
+
|
| 805 |
+
bpo-30777: Configdialog - add docstrings and improve comments.
|
| 806 |
+
Patch by Cheryl Sabella.
|
| 807 |
+
|
| 808 |
+
bpo-30495: Improve textview with docstrings, PEP8 names, and more tests.
|
| 809 |
+
Split TextViewer class into ViewWindow, ViewFrame, and TextFrame classes
|
| 810 |
+
so that instances of the latter two can be placed with other widgets
|
| 811 |
+
within a multiframe window.
|
| 812 |
+
Patches by Cheryl Sabella and Terry Jan Reedy.
|
| 813 |
+
|
| 814 |
+
bpo-30723: Make several improvements to parenmatch.
|
| 815 |
+
* Add 'parens' style to highlight both opener and closer.
|
| 816 |
+
* Make 'default' style, which is not default, a synonym for 'opener'.
|
| 817 |
+
* Make time-delay work the same with all styles.
|
| 818 |
+
* Add help for config dialog extensions tab, including parenmatch.
|
| 819 |
+
* Add new tests.
|
| 820 |
+
Original patch by Charles Wohlganger. Revisions by Terry Jan Reedy
|
| 821 |
+
|
| 822 |
+
bpo-30674: Grep -- Add docstrings. Patch by Cheryl Sabella.
|
| 823 |
+
|
| 824 |
+
bpo-21519: IDLE's basic custom key entry dialog now detects
|
| 825 |
+
duplicates properly. Original patch by Saimadhav Heblikar.
|
| 826 |
+
|
| 827 |
+
bpo-29910: IDLE no longer deletes a character after commenting out a
|
| 828 |
+
region by a key shortcut. Add "return 'break'" for this and other
|
| 829 |
+
potential conflicts between IDLE and default key bindings.
|
| 830 |
+
Patch by Serhiy Storchaka.
|
| 831 |
+
|
| 832 |
+
bpo-30728: Modernize idlelib.configdialog:
|
| 833 |
+
* replace import * with specific imports;
|
| 834 |
+
* lowercase method and attribute lines.
|
| 835 |
+
Patch by Cheryl Sabella.
|
| 836 |
+
|
| 837 |
+
bpo-6739: Verify user-entered key sequences by trying to bind them
|
| 838 |
+
with to a tk widget. Add tests for all 3 validation functions.
|
| 839 |
+
Original patch by G Polo. Tests added by Cheryl Sabella.
|
| 840 |
+
Code revised and more tests added by Terry Jan Reedy
|
| 841 |
+
|
| 842 |
+
bpo-24813: Add icon to help_about and make other changes.
|
| 843 |
+
|
| 844 |
+
bpo-15786: Fix several problems with IDLE's autocompletion box.
|
| 845 |
+
The following should now work: clicking on selection box items;
|
| 846 |
+
using the scrollbar; selecting an item by hitting Return.
|
| 847 |
+
Hangs on MacOSX should no longer happen. Patch by Louie Lu.
|
| 848 |
+
|
| 849 |
+
bpo-25514: Add doc subsubsection about IDLE failure to start.
|
| 850 |
+
Popup no-connection message directs users to this section.
|
| 851 |
+
|
| 852 |
+
bpo-30642: Fix reference leaks in IDLE tests.
|
| 853 |
+
Patches by Louie Lu and Terry Jan Reedy.
|
| 854 |
+
|
| 855 |
+
bpo-30495: Add docstrings for textview.py and use PEP8 names.
|
| 856 |
+
Patches by Cheryl Sabella and Terry Jan Reedy.
|
| 857 |
+
|
| 858 |
+
bpo-30290: Help-about: use pep8 names and add tests.
|
| 859 |
+
Increase coverage to 100%.
|
| 860 |
+
Patches by Louie Lu, Cheryl Sabella, and Terry Jan Reedy.
|
| 861 |
+
|
| 862 |
+
bpo-30303: Add _utest option to textview; add new tests.
|
| 863 |
+
Increase coverage to 100%.
|
| 864 |
+
Patches by Louie Lu and Terry Jan Reedy.
|
| 865 |
+
|
| 866 |
+
Issue #29071: IDLE colors f-string prefixes but not invalid ur prefixes.
|
| 867 |
+
|
| 868 |
+
Issue #28572: Add 10% to coverage of IDLE's test_configdialog.
|
| 869 |
+
Update and augment description of the configuration system.
|
| 870 |
+
|
| 871 |
+
|
| 872 |
+
What's New in IDLE 3.6.0 (since 3.5.0)
|
| 873 |
+
Released on 2016-12-23
|
| 874 |
+
======================================
|
| 875 |
+
|
| 876 |
+
- Issue #15308: Add 'interrupt execution' (^C) to Shell menu.
|
| 877 |
+
Patch by Roger Serwy, updated by Bayard Randel.
|
| 878 |
+
|
| 879 |
+
- Issue #27922: Stop IDLE tests from 'flashing' gui widgets on the screen.
|
| 880 |
+
|
| 881 |
+
- Issue #27891: Consistently group and sort imports within idlelib modules.
|
| 882 |
+
|
| 883 |
+
- Issue #17642: add larger font sizes for classroom projection.
|
| 884 |
+
|
| 885 |
+
- Add version to title of IDLE help window.
|
| 886 |
+
|
| 887 |
+
- Issue #25564: In section on IDLE -- console differences, mention that
|
| 888 |
+
using exec means that __builtins__ is defined for each statement.
|
| 889 |
+
|
| 890 |
+
- Issue #27821: Fix 3.6.0a3 regression that prevented custom key sets
|
| 891 |
+
from being selected when no custom theme was defined.
|
| 892 |
+
|
| 893 |
+
- Issue #27714: text_textview and test_autocomplete now pass when re-run
|
| 894 |
+
in the same process. This occurs when test_idle fails when run with the
|
| 895 |
+
-w option but without -jn. Fix warning from test_config.
|
| 896 |
+
|
| 897 |
+
- Issue #27621: Put query response validation error messages in the query
|
| 898 |
+
box itself instead of in a separate messagebox. Redo tests to match.
|
| 899 |
+
Add Mac OSX refinements. Original patch by Mark Roseman.
|
| 900 |
+
|
| 901 |
+
- Issue #27620: Escape key now closes Query box as cancelled.
|
| 902 |
+
|
| 903 |
+
- Issue #27609: IDLE: tab after initial whitespace should tab, not
|
| 904 |
+
autocomplete. This fixes problem with writing docstrings at least
|
| 905 |
+
twice indented.
|
| 906 |
+
|
| 907 |
+
- Issue #27609: Explicitly return None when there are also non-None
|
| 908 |
+
returns. In a few cases, reverse a condition and eliminate a return.
|
| 909 |
+
|
| 910 |
+
- Issue #25507: IDLE no longer runs buggy code because of its tkinter imports.
|
| 911 |
+
Users must include the same imports required to run directly in Python.
|
| 912 |
+
|
| 913 |
+
- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
|
| 914 |
+
Make the default key set depend on the platform.
|
| 915 |
+
Add tests for the changes to the config module.
|
| 916 |
+
|
| 917 |
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
|
| 918 |
+
|
| 919 |
+
- Issue #27477: IDLE search dialogs now use ttk widgets.
|
| 920 |
+
|
| 921 |
+
- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
|
| 922 |
+
Make the default key set depend on the platform.
|
| 923 |
+
Add tests for the changes to the config module.
|
| 924 |
+
|
| 925 |
+
- Issue #27452: make command line "idle-test> python test_help.py" work.
|
| 926 |
+
__file__ is relative when python is started in the file's directory.
|
| 927 |
+
|
| 928 |
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
|
| 929 |
+
|
| 930 |
+
- Issue #27380: IDLE: add query.py with base Query dialog and ttk widgets.
|
| 931 |
+
Module had subclasses SectionName, ModuleName, and HelpSource, which are
|
| 932 |
+
used to get information from users by configdialog and file =>Load Module.
|
| 933 |
+
Each subclass has itw own validity checks. Using ModuleName allows users
|
| 934 |
+
to edit bad module names instead of starting over.
|
| 935 |
+
Add tests and delete the two files combined into the new one.
|
| 936 |
+
|
| 937 |
+
- Issue #27372: Test_idle no longer changes the locale.
|
| 938 |
+
|
| 939 |
+
- Issue #27365: Allow non-ascii chars in IDLE NEWS.txt, for contributor names.
|
| 940 |
+
|
| 941 |
+
- Issue #27245: IDLE: Cleanly delete custom themes and key bindings.
|
| 942 |
+
Previously, when IDLE was started from a console or by import, a cascade
|
| 943 |
+
of warnings was emitted. Patch by Serhiy Storchaka.
|
| 944 |
+
|
| 945 |
+
- Issue #24137: Run IDLE, test_idle, and htest with tkinter default root disabled.
|
| 946 |
+
Fix code and tests that fail with this restriction.
|
| 947 |
+
Fix htests to not create a second and redundant root and mainloop.
|
| 948 |
+
|
| 949 |
+
- Issue #27310: Fix IDLE.app failure to launch on OS X due to vestigial import.
|
| 950 |
+
|
| 951 |
+
- Issue #5124: Paste with text selected now replaces the selection on X11.
|
| 952 |
+
This matches how paste works on Windows, Mac, most modern Linux apps,
|
| 953 |
+
and ttk widgets. Original patch by Serhiy Storchaka.
|
| 954 |
+
|
| 955 |
+
- Issue #24750: Switch all scrollbars in IDLE to ttk versions.
|
| 956 |
+
Where needed, minimal tests are added to cover changes.
|
| 957 |
+
|
| 958 |
+
- Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
|
| 959 |
+
Delete now unneeded tk version tests and code for older versions.
|
| 960 |
+
Add test for IDLE syntax colorizer.
|
| 961 |
+
|
| 962 |
+
- Issue #27239: idlelib.macosx.isXyzTk functions initialize as needed.
|
| 963 |
+
|
| 964 |
+
- Issue #27262: move Aqua unbinding code, which enable context menus, to macosx.
|
| 965 |
+
|
| 966 |
+
- Issue #24759: Make clear in idlelib.idle_test.__init__ that the directory
|
| 967 |
+
is a private implementation of test.test_idle and tool for maintainers.
|
| 968 |
+
|
| 969 |
+
- Issue #27196: Stop 'ThemeChanged' warnings when running IDLE tests.
|
| 970 |
+
These persisted after other warnings were suppressed in #20567.
|
| 971 |
+
Apply Serhiy Storchaka's update_idletasks solution to four test files.
|
| 972 |
+
Record this additional advice in idle_test/README.txt
|
| 973 |
+
|
| 974 |
+
- Issue #20567: Revise idle_test/README.txt with advice about avoiding
|
| 975 |
+
tk warning messages from tests. Apply advice to several IDLE tests.
|
| 976 |
+
|
| 977 |
+
- Issue # 24225: Update idlelib/README.txt with new file names
|
| 978 |
+
and event handlers.
|
| 979 |
+
|
| 980 |
+
- Issue #27156: Remove obsolete code not used by IDLE. Replacements:
|
| 981 |
+
1. help.txt, replaced by help.html, is out-of-date and should not be used.
|
| 982 |
+
Its dedicated viewer has be replaced by the html viewer in help.py.
|
| 983 |
+
2. 'import idlever; I = idlever.IDLE_VERSION' is the same as
|
| 984 |
+
'import sys; I = version[:version.index(' ')]'
|
| 985 |
+
3. After 'ob = stackviewer.VariablesTreeItem(*args)',
|
| 986 |
+
'ob.keys()' == 'list(ob.object.keys).
|
| 987 |
+
4. In macosc, runningAsOSXAPP == isAquaTk; idCarbonAquaTk == isCarbonTk
|
| 988 |
+
|
| 989 |
+
- Issue #27117: Make colorizer htest and turtledemo work with dark themes.
|
| 990 |
+
Move code for configuring text widget colors to a new function.
|
| 991 |
+
|
| 992 |
+
- Issue #24225: Rename many idlelib/*.py and idle_test/test_*.py files.
|
| 993 |
+
Edit files to replace old names with new names when the old name
|
| 994 |
+
referred to the module rather than the class it contained.
|
| 995 |
+
See the issue and IDLE section in What's New in 3.6 for more.
|
| 996 |
+
|
| 997 |
+
- Issue #26673: When tk reports font size as 0, change to size 10.
|
| 998 |
+
Such fonts on Linux prevented the configuration dialog from opening.
|
| 999 |
+
|
| 1000 |
+
- Issue #21939: Add test for IDLE's percolator.
|
| 1001 |
+
Original patch by Saimadhav Heblikar.
|
| 1002 |
+
|
| 1003 |
+
- Issue #21676: Add test for IDLE's replace dialog.
|
| 1004 |
+
Original patch by Saimadhav Heblikar.
|
| 1005 |
+
|
| 1006 |
+
- Issue #18410: Add test for IDLE's search dialog.
|
| 1007 |
+
Original patch by Westley Martínez.
|
| 1008 |
+
|
| 1009 |
+
- Issue #21703: Add test for undo delegator. Patch mostly by
|
| 1010 |
+
Saimadhav Heblikar .
|
| 1011 |
+
|
| 1012 |
+
- Issue #27044: Add ConfigDialog.remove_var_callbacks to stop memory leaks.
|
| 1013 |
+
|
| 1014 |
+
- Issue #23977: Add more asserts to test_delegator.
|
| 1015 |
+
|
| 1016 |
+
- Issue #20640: Add tests for idlelib.configHelpSourceEdit.
|
| 1017 |
+
Patch by Saimadhav Heblikar.
|
| 1018 |
+
|
| 1019 |
+
- In the 'IDLE-console differences' section of the IDLE doc, clarify
|
| 1020 |
+
how running with IDLE affects sys.modules and the standard streams.
|
| 1021 |
+
|
| 1022 |
+
- Issue #25507: fix incorrect change in IOBinding that prevented printing.
|
| 1023 |
+
Augment IOBinding htest to include all major IOBinding functions.
|
| 1024 |
+
|
| 1025 |
+
- Issue #25905: Revert unwanted conversion of ' to ’ RIGHT SINGLE QUOTATION
|
| 1026 |
+
MARK in README.txt and open this and NEWS.txt with 'ascii'.
|
| 1027 |
+
Re-encode CREDITS.txt to utf-8 and open it with 'utf-8'.
|
| 1028 |
+
|
| 1029 |
+
- Issue 15348: Stop the debugger engine (normally in a user process)
|
| 1030 |
+
before closing the debugger window (running in the IDLE process).
|
| 1031 |
+
This prevents the RuntimeErrors that were being caught and ignored.
|
| 1032 |
+
|
| 1033 |
+
- Issue #24455: Prevent IDLE from hanging when a) closing the shell while the
|
| 1034 |
+
debugger is active (15347); b) closing the debugger with the [X] button
|
| 1035 |
+
(15348); and c) activating the debugger when already active (24455).
|
| 1036 |
+
The patch by Mark Roseman does this by making two changes.
|
| 1037 |
+
1. Suspend and resume the gui.interaction method with the tcl vwait
|
| 1038 |
+
mechanism intended for this purpose (instead of root.mainloop & .quit).
|
| 1039 |
+
2. In gui.run, allow any existing interaction to terminate first.
|
| 1040 |
+
|
| 1041 |
+
- Change 'The program' to 'Your program' in an IDLE 'kill program?' message
|
| 1042 |
+
to make it clearer that the program referred to is the currently running
|
| 1043 |
+
user program, not IDLE itself.
|
| 1044 |
+
|
| 1045 |
+
- Issue #24750: Improve the appearance of the IDLE editor window status bar.
|
| 1046 |
+
Patch by Mark Roseman.
|
| 1047 |
+
|
| 1048 |
+
- Issue #25313: Change the handling of new built-in text color themes to better
|
| 1049 |
+
address the compatibility problem introduced by the addition of IDLE Dark.
|
| 1050 |
+
Consistently use the revised idleConf.CurrentTheme everywhere in idlelib.
|
| 1051 |
+
|
| 1052 |
+
- Issue #24782: Extension configuration is now a tab in the IDLE Preferences
|
| 1053 |
+
dialog rather than a separate dialog. The former tabs are now a sorted
|
| 1054 |
+
list. Patch by Mark Roseman.
|
| 1055 |
+
|
| 1056 |
+
- Issue #22726: Re-activate the config dialog help button with some content
|
| 1057 |
+
about the other buttons and the new IDLE Dark theme.
|
| 1058 |
+
|
| 1059 |
+
- Issue #24820: IDLE now has an 'IDLE Dark' built-in text color theme.
|
| 1060 |
+
It is more or less IDLE Classic inverted, with a cobalt blue background.
|
| 1061 |
+
Strings, comments, keywords, ... are still green, red, orange, ... .
|
| 1062 |
+
To use it with IDLEs released before November 2015, hit the
|
| 1063 |
+
'Save as New Custom Theme' button and enter a new name,
|
| 1064 |
+
such as 'Custom Dark'. The custom theme will work with any IDLE
|
| 1065 |
+
release, and can be modified.
|
| 1066 |
+
|
| 1067 |
+
- Issue #25224: README.txt is now an idlelib index for IDLE developers and
|
| 1068 |
+
curious users. The previous user content is now in the IDLE doc chapter.
|
| 1069 |
+
'IDLE' now means 'Integrated Development and Learning Environment'.
|
| 1070 |
+
|
| 1071 |
+
- Issue #24820: Users can now set breakpoint colors in
|
| 1072 |
+
Settings -> Custom Highlighting. Original patch by Mark Roseman.
|
| 1073 |
+
|
| 1074 |
+
- Issue #24972: Inactive selection background now matches active selection
|
| 1075 |
+
background, as configured by users, on all systems. Found items are now
|
| 1076 |
+
always highlighted on Windows. Initial patch by Mark Roseman.
|
| 1077 |
+
|
| 1078 |
+
- Issue #24570: Idle: make calltip and completion boxes appear on Macs
|
| 1079 |
+
affected by a tk regression. Initial patch by Mark Roseman.
|
| 1080 |
+
|
| 1081 |
+
- Issue #24988: Idle ScrolledList context menus (used in debugger)
|
| 1082 |
+
now work on Mac Aqua. Patch by Mark Roseman.
|
| 1083 |
+
|
| 1084 |
+
- Issue #24801: Make right-click for context menu work on Mac Aqua.
|
| 1085 |
+
Patch by Mark Roseman.
|
| 1086 |
+
|
| 1087 |
+
- Issue #25173: Associate tkinter messageboxes with a specific widget.
|
| 1088 |
+
For Mac OSX, make them a 'sheet'. Patch by Mark Roseman.
|
| 1089 |
+
|
| 1090 |
+
- Issue #25198: Enhance the initial html viewer now used for Idle Help.
|
| 1091 |
+
* Properly indent fixed-pitch text (patch by Mark Roseman).
|
| 1092 |
+
* Give code snippet a very Sphinx-like light blueish-gray background.
|
| 1093 |
+
* Re-use initial width and height set by users for shell and editor.
|
| 1094 |
+
* When the Table of Contents (TOC) menu is used, put the section header
|
| 1095 |
+
at the top of the screen.
|
| 1096 |
+
|
| 1097 |
+
- Issue #25225: Condense and rewrite Idle doc section on text colors.
|
| 1098 |
+
|
| 1099 |
+
- Issue #21995: Explain some differences between IDLE and console Python.
|
| 1100 |
+
|
| 1101 |
+
- Issue #22820: Explain need for *print* when running file from Idle editor.
|
| 1102 |
+
|
| 1103 |
+
- Issue #25224: Doc: augment Idle feature list and no-subprocess section.
|
| 1104 |
+
|
| 1105 |
+
- Issue #25219: Update doc for Idle command line options.
|
| 1106 |
+
Some were missing and notes were not correct.
|
| 1107 |
+
|
| 1108 |
+
- Issue #24861: Most of idlelib is private and subject to change.
|
| 1109 |
+
Use idleib.idle.* to start Idle. See idlelib.__init__.__doc__.
|
| 1110 |
+
|
| 1111 |
+
- Issue #25199: Idle: add synchronization comments for future maintainers.
|
| 1112 |
+
|
| 1113 |
+
- Issue #16893: Replace help.txt with help.html for Idle doc display.
|
| 1114 |
+
The new idlelib/help.html is rstripped Doc/build/html/library/idle.html.
|
| 1115 |
+
It looks better than help.txt and will better document Idle as released.
|
| 1116 |
+
The tkinter html viewer that works for this file was written by Mark Roseman.
|
| 1117 |
+
The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated.
|
| 1118 |
+
|
| 1119 |
+
- Issue #24199: Deprecate unused idlelib.idlever with possible removal in 3.6.
|
| 1120 |
+
|
| 1121 |
+
- Issue #24790: Remove extraneous code (which also create 2 & 3 conflicts).
|
| 1122 |
+
|
| 1123 |
+
|
| 1124 |
+
What's New in IDLE 3.5.0?
|
| 1125 |
+
=========================
|
| 1126 |
+
*Release date: 2015-09-13*
|
| 1127 |
+
|
| 1128 |
+
- Issue #23672: Allow Idle to edit and run files with astral chars in name.
|
| 1129 |
+
Patch by Mohd Sanad Zaki Rizvi.
|
| 1130 |
+
|
| 1131 |
+
- Issue 24745: Idle editor default font. Switch from Courier to
|
| 1132 |
+
platform-sensitive TkFixedFont. This should not affect current customized
|
| 1133 |
+
font selections. If there is a problem, edit $HOME/.idlerc/config-main.cfg
|
| 1134 |
+
and remove 'fontxxx' entries from [Editor Window]. Patch by Mark Roseman.
|
| 1135 |
+
|
| 1136 |
+
- Issue #21192: Idle editor. When a file is run, put its name in the restart bar.
|
| 1137 |
+
Do not print false prompts. Original patch by Adnan Umer.
|
| 1138 |
+
|
| 1139 |
+
- Issue #13884: Idle menus. Remove tearoff lines. Patch by Roger Serwy.
|
| 1140 |
+
|
| 1141 |
+
- Issue #23184: remove unused names and imports in idlelib.
|
| 1142 |
+
Initial patch by Al Sweigart.
|
| 1143 |
+
|
| 1144 |
+
- Issue #20577: Configuration of the max line length for the FormatParagraph
|
| 1145 |
+
extension has been moved from the General tab of the Idle preferences dialog
|
| 1146 |
+
to the FormatParagraph tab of the Config Extensions dialog.
|
| 1147 |
+
Patch by Tal Einat.
|
| 1148 |
+
|
| 1149 |
+
- Issue #16893: Update Idle doc chapter to match current Idle and add new
|
| 1150 |
+
information.
|
| 1151 |
+
|
| 1152 |
+
- Issue #3068: Add Idle extension configuration dialog to Options menu.
|
| 1153 |
+
Changes are written to HOME/.idlerc/config-extensions.cfg.
|
| 1154 |
+
Original patch by Tal Einat.
|
| 1155 |
+
|
| 1156 |
+
- Issue #16233: A module browser (File : Class Browser, Alt+C) requires an
|
| 1157 |
+
editor window with a filename. When Class Browser is requested otherwise,
|
| 1158 |
+
from a shell, output window, or 'Untitled' editor, Idle no longer displays
|
| 1159 |
+
an error box. It now pops up an Open Module box (Alt+M). If a valid name
|
| 1160 |
+
is entered and a module is opened, a corresponding browser is also opened.
|
| 1161 |
+
|
| 1162 |
+
- Issue #4832: Save As to type Python files automatically adds .py to the
|
| 1163 |
+
name you enter (even if your system does not display it). Some systems
|
| 1164 |
+
automatically add .txt when type is Text files.
|
| 1165 |
+
|
| 1166 |
+
- Issue #21986: Code objects are not normally pickled by the pickle module.
|
| 1167 |
+
To match this, they are no longer pickled when running under Idle.
|
| 1168 |
+
|
| 1169 |
+
- Issue #23180: Rename IDLE "Windows" menu item to "Window".
|
| 1170 |
+
Patch by Al Sweigart.
|
| 1171 |
+
|
| 1172 |
+
- Issue #17390: Adjust Editor window title; remove 'Python',
|
| 1173 |
+
move version to end.
|
| 1174 |
+
|
| 1175 |
+
- Issue #14105: Idle debugger breakpoints no longer disappear
|
| 1176 |
+
when inserting or deleting lines.
|
| 1177 |
+
|
| 1178 |
+
- Issue #17172: Turtledemo can now be run from Idle.
|
| 1179 |
+
Currently, the entry is on the Help menu, but it may move to Run.
|
| 1180 |
+
Patch by Ramchandra Apt and Lita Cho.
|
| 1181 |
+
|
| 1182 |
+
- Issue #21765: Add support for non-ascii identifiers to HyperParser.
|
| 1183 |
+
|
| 1184 |
+
- Issue #21940: Add unittest for WidgetRedirector. Initial patch by Saimadhav
|
| 1185 |
+
Heblikar.
|
| 1186 |
+
|
| 1187 |
+
- Issue #18592: Add unittest for SearchDialogBase. Patch by Phil Webster.
|
| 1188 |
+
|
| 1189 |
+
- Issue #21694: Add unittest for ParenMatch. Patch by Saimadhav Heblikar.
|
| 1190 |
+
|
| 1191 |
+
- Issue #21686: add unittest for HyperParser. Original patch by Saimadhav
|
| 1192 |
+
Heblikar.
|
| 1193 |
+
|
| 1194 |
+
- Issue #12387: Add missing upper(lower)case versions of default Windows key
|
| 1195 |
+
bindings for Idle so Caps Lock does not disable them. Patch by Roger Serwy.
|
| 1196 |
+
|
| 1197 |
+
- Issue #21695: Closing a Find-in-files output window while the search is
|
| 1198 |
+
still in progress no longer closes Idle.
|
| 1199 |
+
|
| 1200 |
+
- Issue #18910: Add unittest for textView. Patch by Phil Webster.
|
| 1201 |
+
|
| 1202 |
+
- Issue #18292: Add unittest for AutoExpand. Patch by Saihadhav Heblikar.
|
| 1203 |
+
|
| 1204 |
+
- Issue #18409: Add unittest for AutoComplete. Patch by Phil Webster.
|
| 1205 |
+
|
| 1206 |
+
- Issue #21477: htest.py - Improve framework, complete set of tests.
|
| 1207 |
+
Patches by Saimadhav Heblikar
|
| 1208 |
+
|
| 1209 |
+
- Issue #18104: Add idlelib/idle_test/htest.py with a few sample tests to begin
|
| 1210 |
+
consolidating and improving human-validated tests of Idle. Change other files
|
| 1211 |
+
as needed to work with htest. Running the module as __main__ runs all tests.
|
| 1212 |
+
|
| 1213 |
+
- Issue #21139: Change default paragraph width to 72, the PEP 8 recommendation.
|
| 1214 |
+
|
| 1215 |
+
- Issue #21284: Paragraph reformat test passes after user changes reformat width.
|
| 1216 |
+
|
| 1217 |
+
- Issue #17654: Ensure IDLE menus are customized properly on OS X for
|
| 1218 |
+
non-framework builds and for all variants of Tk.
|
| 1219 |
+
|
| 1220 |
+
|
| 1221 |
+
What's New in IDLE 3.4.0?
|
| 1222 |
+
=========================
|
| 1223 |
+
*Release date: 2014-03-16*
|
| 1224 |
+
|
| 1225 |
+
- Issue #17390: Display Python version on Idle title bar.
|
| 1226 |
+
Initial patch by Edmond Burnett.
|
| 1227 |
+
|
| 1228 |
+
- Issue #5066: Update IDLE docs. Patch by Todd Rovito.
|
| 1229 |
+
|
| 1230 |
+
- Issue #17625: Close the replace dialog after it is used.
|
| 1231 |
+
|
| 1232 |
+
- Issue #16226: Fix IDLE Path Browser crash.
|
| 1233 |
+
(Patch by Roger Serwy)
|
| 1234 |
+
|
| 1235 |
+
- Issue #15853: Prevent IDLE crash on OS X when opening Preferences menu
|
| 1236 |
+
with certain versions of Tk 8.5. Initial patch by Kevin Walzer.
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
+
What's New in IDLE 3.3.0?
|
| 1240 |
+
=========================
|
| 1241 |
+
*Release date: 2012-09-29*
|
| 1242 |
+
|
| 1243 |
+
- Issue #17625: Close the replace dialog after it is used.
|
| 1244 |
+
|
| 1245 |
+
- Issue #7163: Propagate return value of sys.stdout.write.
|
| 1246 |
+
|
| 1247 |
+
- Issue #15318: Prevent writing to sys.stdin.
|
| 1248 |
+
|
| 1249 |
+
- Issue #4832: Modify IDLE to save files with .py extension by
|
| 1250 |
+
default on Windows and OS X (Tk 8.5) as it already does with X11 Tk.
|
| 1251 |
+
|
| 1252 |
+
- Issue #13532, #15319: Check that arguments to sys.stdout.write are strings.
|
| 1253 |
+
|
| 1254 |
+
- Issue # 12510: Attempt to get certain tool tips no longer crashes IDLE.
|
| 1255 |
+
Erroneous tool tips have been corrected. Default added for callables.
|
| 1256 |
+
|
| 1257 |
+
- Issue #10365: File open dialog now works instead of crashing even when
|
| 1258 |
+
parent window is closed while dialog is open.
|
| 1259 |
+
|
| 1260 |
+
- Issue 14876: use user-selected font for highlight configuration.
|
| 1261 |
+
|
| 1262 |
+
- Issue #14937: Perform auto-completion of filenames in strings even for
|
| 1263 |
+
non-ASCII filenames. Likewise for identifiers.
|
| 1264 |
+
|
| 1265 |
+
- Issue #8515: Set __file__ when run file in IDLE.
|
| 1266 |
+
Initial patch by Bruce Frederiksen.
|
| 1267 |
+
|
| 1268 |
+
- IDLE can be launched as `python -m idlelib`
|
| 1269 |
+
|
| 1270 |
+
- Issue #14409: IDLE now properly executes commands in the Shell window
|
| 1271 |
+
when it cannot read the normal config files on startup and
|
| 1272 |
+
has to use the built-in default key bindings.
|
| 1273 |
+
There was previously a bug in one of the defaults.
|
| 1274 |
+
|
| 1275 |
+
- Issue #3573: IDLE hangs when passing invalid command line args
|
| 1276 |
+
(directory(ies) instead of file(s)).
|
| 1277 |
+
|
| 1278 |
+
- Issue #14018: Update checks for unstable system Tcl/Tk versions on OS X
|
| 1279 |
+
to include versions shipped with OS X 10.7 and 10.8 in addition to 10.6.
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
+
What's New in IDLE 3.2.1?
|
| 1283 |
+
=========================
|
| 1284 |
+
*Release date: 15-May-11*
|
| 1285 |
+
|
| 1286 |
+
- Issue #6378: Further adjust idle.bat to start associated Python
|
| 1287 |
+
|
| 1288 |
+
- Issue #11896: Save on Close failed despite selecting "Yes" in dialog.
|
| 1289 |
+
|
| 1290 |
+
- Issue #1028: Ctrl-space binding to show completions was causing IDLE to exit.
|
| 1291 |
+
Tk < 8.5 was sending invalid Unicode null; replaced with valid null.
|
| 1292 |
+
|
| 1293 |
+
- Issue #4676: <Home> toggle failing on Tk 8.5, causing IDLE exits and strange selection
|
| 1294 |
+
behavior. Improve selection extension behaviour.
|
| 1295 |
+
|
| 1296 |
+
- Issue #3851: <Home> toggle non-functional when NumLock set on Windows.
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
What's New in IDLE 3.1b1?
|
| 1300 |
+
=========================
|
| 1301 |
+
*Release date: 06-May-09*
|
| 1302 |
+
|
| 1303 |
+
- Issue #5707: Use of 'filter' in keybindingDialog.py was causing custom key assignment to
|
| 1304 |
+
fail. Patch by Amaury Forgeot d'Arc.
|
| 1305 |
+
|
| 1306 |
+
- Issue #4815: Offer conversion to UTF-8 if source files have
|
| 1307 |
+
no encoding declaration and are not encoded in UTF-8.
|
| 1308 |
+
|
| 1309 |
+
- Issue #4008: Fix problems with non-ASCII source files.
|
| 1310 |
+
|
| 1311 |
+
- Issue #4323: Always encode source as UTF-8 without asking
|
| 1312 |
+
the user (unless a different encoding is declared); remove
|
| 1313 |
+
user configuration of source encoding; all according to
|
| 1314 |
+
PEP 3120.
|
| 1315 |
+
|
| 1316 |
+
- Issue #2665: On Windows, an IDLE installation upgraded from an old version
|
| 1317 |
+
would not start if a custom theme was defined.
|
| 1318 |
+
|
| 1319 |
+
------------------------------------------------------------------------
|
| 1320 |
+
Refer to NEWS2x.txt and HISTORY.txt for information on earlier releases.
|
| 1321 |
+
------------------------------------------------------------------------
|
evalkit_tf446/lib/python3.10/idlelib/NEW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
+
- 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 |
+
--------------------------------------------------------------------
|
ev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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
|
evalkit_tf446/lib/python3.10/idlelib/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The idlelib package implements the Idle application.
|
| 2 |
+
|
| 3 |
+
Idle includes an interactive shell and editor.
|
| 4 |
+
Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
|
| 5 |
+
Use the files named idle.* to start Idle.
|
| 6 |
+
|
| 7 |
+
The other files are private implementations. Their details are subject to
|
| 8 |
+
change. See PEP 434 for more. Import them at your own risk.
|
| 9 |
+
"""
|
| 10 |
+
testing = False # Set True by test.test_idle.
|
evalkit_tf446/lib/python3.10/idlelib/__main__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IDLE main entry point
|
| 3 |
+
|
| 4 |
+
Run IDLE as python -m idlelib
|
| 5 |
+
"""
|
| 6 |
+
import idlelib.pyshell
|
| 7 |
+
idlelib.pyshell.main()
|
| 8 |
+
# This file does not work for 2.7; See issue 24212.
|
evalkit_tf446/lib/python3.10/idlelib/autocomplete_w.py
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
An auto-completion window for IDLE, used by the autocomplete extension
|
| 3 |
+
"""
|
| 4 |
+
import platform
|
| 5 |
+
|
| 6 |
+
from tkinter import *
|
| 7 |
+
from tkinter.ttk import Scrollbar
|
| 8 |
+
|
| 9 |
+
from idlelib.autocomplete import FILES, ATTRS
|
| 10 |
+
from idlelib.multicall import MC_SHIFT
|
| 11 |
+
|
| 12 |
+
HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
|
| 13 |
+
HIDE_FOCUS_OUT_SEQUENCE = "<FocusOut>"
|
| 14 |
+
HIDE_SEQUENCES = (HIDE_FOCUS_OUT_SEQUENCE, "<ButtonPress>")
|
| 15 |
+
KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
|
| 16 |
+
# We need to bind event beyond <Key> so that the function will be called
|
| 17 |
+
# before the default specific IDLE function
|
| 18 |
+
KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>", "<Key-Tab>",
|
| 19 |
+
"<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>",
|
| 20 |
+
"<Key-Prior>", "<Key-Next>", "<Key-Escape>")
|
| 21 |
+
KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
|
| 22 |
+
KEYRELEASE_SEQUENCE = "<KeyRelease>"
|
| 23 |
+
LISTUPDATE_SEQUENCE = "<B1-ButtonRelease>"
|
| 24 |
+
WINCONFIG_SEQUENCE = "<Configure>"
|
| 25 |
+
DOUBLECLICK_SEQUENCE = "<B1-Double-ButtonRelease>"
|
| 26 |
+
|
| 27 |
+
class AutoCompleteWindow:
|
| 28 |
+
|
| 29 |
+
def __init__(self, widget, tags):
|
| 30 |
+
# The widget (Text) on which we place the AutoCompleteWindow
|
| 31 |
+
self.widget = widget
|
| 32 |
+
# Tags to mark inserted text with
|
| 33 |
+
self.tags = tags
|
| 34 |
+
# The widgets we create
|
| 35 |
+
self.autocompletewindow = self.listbox = self.scrollbar = None
|
| 36 |
+
# The default foreground and background of a selection. Saved because
|
| 37 |
+
# they are changed to the regular colors of list items when the
|
| 38 |
+
# completion start is not a prefix of the selected completion
|
| 39 |
+
self.origselforeground = self.origselbackground = None
|
| 40 |
+
# The list of completions
|
| 41 |
+
self.completions = None
|
| 42 |
+
# A list with more completions, or None
|
| 43 |
+
self.morecompletions = None
|
| 44 |
+
# The completion mode, either autocomplete.ATTRS or .FILES.
|
| 45 |
+
self.mode = None
|
| 46 |
+
# The current completion start, on the text box (a string)
|
| 47 |
+
self.start = None
|
| 48 |
+
# The index of the start of the completion
|
| 49 |
+
self.startindex = None
|
| 50 |
+
# The last typed start, used so that when the selection changes,
|
| 51 |
+
# the new start will be as close as possible to the last typed one.
|
| 52 |
+
self.lasttypedstart = None
|
| 53 |
+
# Do we have an indication that the user wants the completion window
|
| 54 |
+
# (for example, he clicked the list)
|
| 55 |
+
self.userwantswindow = None
|
| 56 |
+
# event ids
|
| 57 |
+
self.hideid = self.keypressid = self.listupdateid = \
|
| 58 |
+
self.winconfigid = self.keyreleaseid = self.doubleclickid = None
|
| 59 |
+
# Flag set if last keypress was a tab
|
| 60 |
+
self.lastkey_was_tab = False
|
| 61 |
+
# Flag set to avoid recursive <Configure> callback invocations.
|
| 62 |
+
self.is_configuring = False
|
| 63 |
+
|
| 64 |
+
def _change_start(self, newstart):
|
| 65 |
+
min_len = min(len(self.start), len(newstart))
|
| 66 |
+
i = 0
|
| 67 |
+
while i < min_len and self.start[i] == newstart[i]:
|
| 68 |
+
i += 1
|
| 69 |
+
if i < len(self.start):
|
| 70 |
+
self.widget.delete("%s+%dc" % (self.startindex, i),
|
| 71 |
+
"%s+%dc" % (self.startindex, len(self.start)))
|
| 72 |
+
if i < len(newstart):
|
| 73 |
+
self.widget.insert("%s+%dc" % (self.startindex, i),
|
| 74 |
+
newstart[i:],
|
| 75 |
+
self.tags)
|
| 76 |
+
self.start = newstart
|
| 77 |
+
|
| 78 |
+
def _binary_search(self, s):
|
| 79 |
+
"""Find the first index in self.completions where completions[i] is
|
| 80 |
+
greater or equal to s, or the last index if there is no such.
|
| 81 |
+
"""
|
| 82 |
+
i = 0; j = len(self.completions)
|
| 83 |
+
while j > i:
|
| 84 |
+
m = (i + j) // 2
|
| 85 |
+
if self.completions[m] >= s:
|
| 86 |
+
j = m
|
| 87 |
+
else:
|
| 88 |
+
i = m + 1
|
| 89 |
+
return min(i, len(self.completions)-1)
|
| 90 |
+
|
| 91 |
+
def _complete_string(self, s):
|
| 92 |
+
"""Assuming that s is the prefix of a string in self.completions,
|
| 93 |
+
return the longest string which is a prefix of all the strings which
|
| 94 |
+
s is a prefix of them. If s is not a prefix of a string, return s.
|
| 95 |
+
"""
|
| 96 |
+
first = self._binary_search(s)
|
| 97 |
+
if self.completions[first][:len(s)] != s:
|
| 98 |
+
# There is not even one completion which s is a prefix of.
|
| 99 |
+
return s
|
| 100 |
+
# Find the end of the range of completions where s is a prefix of.
|
| 101 |
+
i = first + 1
|
| 102 |
+
j = len(self.completions)
|
| 103 |
+
while j > i:
|
| 104 |
+
m = (i + j) // 2
|
| 105 |
+
if self.completions[m][:len(s)] != s:
|
| 106 |
+
j = m
|
| 107 |
+
else:
|
| 108 |
+
i = m + 1
|
| 109 |
+
last = i-1
|
| 110 |
+
|
| 111 |
+
if first == last: # only one possible completion
|
| 112 |
+
return self.completions[first]
|
| 113 |
+
|
| 114 |
+
# We should return the maximum prefix of first and last
|
| 115 |
+
first_comp = self.completions[first]
|
| 116 |
+
last_comp = self.completions[last]
|
| 117 |
+
min_len = min(len(first_comp), len(last_comp))
|
| 118 |
+
i = len(s)
|
| 119 |
+
while i < min_len and first_comp[i] == last_comp[i]:
|
| 120 |
+
i += 1
|
| 121 |
+
return first_comp[:i]
|
| 122 |
+
|
| 123 |
+
def _selection_changed(self):
|
| 124 |
+
"""Call when the selection of the Listbox has changed.
|
| 125 |
+
|
| 126 |
+
Updates the Listbox display and calls _change_start.
|
| 127 |
+
"""
|
| 128 |
+
cursel = int(self.listbox.curselection()[0])
|
| 129 |
+
|
| 130 |
+
self.listbox.see(cursel)
|
| 131 |
+
|
| 132 |
+
lts = self.lasttypedstart
|
| 133 |
+
selstart = self.completions[cursel]
|
| 134 |
+
if self._binary_search(lts) == cursel:
|
| 135 |
+
newstart = lts
|
| 136 |
+
else:
|
| 137 |
+
min_len = min(len(lts), len(selstart))
|
| 138 |
+
i = 0
|
| 139 |
+
while i < min_len and lts[i] == selstart[i]:
|
| 140 |
+
i += 1
|
| 141 |
+
newstart = selstart[:i]
|
| 142 |
+
self._change_start(newstart)
|
| 143 |
+
|
| 144 |
+
if self.completions[cursel][:len(self.start)] == self.start:
|
| 145 |
+
# start is a prefix of the selected completion
|
| 146 |
+
self.listbox.configure(selectbackground=self.origselbackground,
|
| 147 |
+
selectforeground=self.origselforeground)
|
| 148 |
+
else:
|
| 149 |
+
self.listbox.configure(selectbackground=self.listbox.cget("bg"),
|
| 150 |
+
selectforeground=self.listbox.cget("fg"))
|
| 151 |
+
# If there are more completions, show them, and call me again.
|
| 152 |
+
if self.morecompletions:
|
| 153 |
+
self.completions = self.morecompletions
|
| 154 |
+
self.morecompletions = None
|
| 155 |
+
self.listbox.delete(0, END)
|
| 156 |
+
for item in self.completions:
|
| 157 |
+
self.listbox.insert(END, item)
|
| 158 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 159 |
+
self._selection_changed()
|
| 160 |
+
|
| 161 |
+
def show_window(self, comp_lists, index, complete, mode, userWantsWin):
|
| 162 |
+
"""Show the autocomplete list, bind events.
|
| 163 |
+
|
| 164 |
+
If complete is True, complete the text, and if there is exactly
|
| 165 |
+
one matching completion, don't open a list.
|
| 166 |
+
"""
|
| 167 |
+
# Handle the start we already have
|
| 168 |
+
self.completions, self.morecompletions = comp_lists
|
| 169 |
+
self.mode = mode
|
| 170 |
+
self.startindex = self.widget.index(index)
|
| 171 |
+
self.start = self.widget.get(self.startindex, "insert")
|
| 172 |
+
if complete:
|
| 173 |
+
completed = self._complete_string(self.start)
|
| 174 |
+
start = self.start
|
| 175 |
+
self._change_start(completed)
|
| 176 |
+
i = self._binary_search(completed)
|
| 177 |
+
if self.completions[i] == completed and \
|
| 178 |
+
(i == len(self.completions)-1 or
|
| 179 |
+
self.completions[i+1][:len(completed)] != completed):
|
| 180 |
+
# There is exactly one matching completion
|
| 181 |
+
return completed == start
|
| 182 |
+
self.userwantswindow = userWantsWin
|
| 183 |
+
self.lasttypedstart = self.start
|
| 184 |
+
|
| 185 |
+
# Put widgets in place
|
| 186 |
+
self.autocompletewindow = acw = Toplevel(self.widget)
|
| 187 |
+
# Put it in a position so that it is not seen.
|
| 188 |
+
acw.wm_geometry("+10000+10000")
|
| 189 |
+
# Make it float
|
| 190 |
+
acw.wm_overrideredirect(1)
|
| 191 |
+
try:
|
| 192 |
+
# This command is only needed and available on Tk >= 8.4.0 for OSX
|
| 193 |
+
# Without it, call tips intrude on the typing process by grabbing
|
| 194 |
+
# the focus.
|
| 195 |
+
acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
|
| 196 |
+
"help", "noActivates")
|
| 197 |
+
except TclError:
|
| 198 |
+
pass
|
| 199 |
+
self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
|
| 200 |
+
self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
|
| 201 |
+
exportselection=False)
|
| 202 |
+
for item in self.completions:
|
| 203 |
+
listbox.insert(END, item)
|
| 204 |
+
self.origselforeground = listbox.cget("selectforeground")
|
| 205 |
+
self.origselbackground = listbox.cget("selectbackground")
|
| 206 |
+
scrollbar.config(command=listbox.yview)
|
| 207 |
+
scrollbar.pack(side=RIGHT, fill=Y)
|
| 208 |
+
listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
| 209 |
+
#acw.update_idletasks() # Need for tk8.6.8 on macOS: #40128.
|
| 210 |
+
acw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
|
| 211 |
+
|
| 212 |
+
# Initialize the listbox selection
|
| 213 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 214 |
+
self._selection_changed()
|
| 215 |
+
|
| 216 |
+
# bind events
|
| 217 |
+
self.hideaid = acw.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 218 |
+
self.hidewid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 219 |
+
acw.event_add(HIDE_VIRTUAL_EVENT_NAME, HIDE_FOCUS_OUT_SEQUENCE)
|
| 220 |
+
for seq in HIDE_SEQUENCES:
|
| 221 |
+
self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 222 |
+
|
| 223 |
+
self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,
|
| 224 |
+
self.keypress_event)
|
| 225 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 226 |
+
self.widget.event_add(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 227 |
+
self.keyreleaseid = self.widget.bind(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 228 |
+
self.keyrelease_event)
|
| 229 |
+
self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
|
| 230 |
+
self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
|
| 231 |
+
self.listselect_event)
|
| 232 |
+
self.is_configuring = False
|
| 233 |
+
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
|
| 234 |
+
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
|
| 235 |
+
self.doubleclick_event)
|
| 236 |
+
return None
|
| 237 |
+
|
| 238 |
+
def winconfig_event(self, event):
|
| 239 |
+
if self.is_configuring:
|
| 240 |
+
# Avoid running on recursive <Configure> callback invocations.
|
| 241 |
+
return
|
| 242 |
+
|
| 243 |
+
self.is_configuring = True
|
| 244 |
+
if not self.is_active():
|
| 245 |
+
return
|
| 246 |
+
|
| 247 |
+
# Since the <Configure> event may occur after the completion window is gone,
|
| 248 |
+
# catch potential TclError exceptions when accessing acw. See: bpo-41611.
|
| 249 |
+
try:
|
| 250 |
+
# Position the completion list window
|
| 251 |
+
text = self.widget
|
| 252 |
+
text.see(self.startindex)
|
| 253 |
+
x, y, cx, cy = text.bbox(self.startindex)
|
| 254 |
+
acw = self.autocompletewindow
|
| 255 |
+
if platform.system().startswith('Windows'):
|
| 256 |
+
# On Windows an update() call is needed for the completion
|
| 257 |
+
# list window to be created, so that we can fetch its width
|
| 258 |
+
# and height. However, this is not needed on other platforms
|
| 259 |
+
# (tested on Ubuntu and macOS) but at one point began
|
| 260 |
+
# causing freezes on macOS. See issues 37849 and 41611.
|
| 261 |
+
acw.update()
|
| 262 |
+
acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
|
| 263 |
+
text_width, text_height = text.winfo_width(), text.winfo_height()
|
| 264 |
+
new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
|
| 265 |
+
new_y = text.winfo_rooty() + y
|
| 266 |
+
if (text_height - (y + cy) >= acw_height # enough height below
|
| 267 |
+
or y < acw_height): # not enough height above
|
| 268 |
+
# place acw below current line
|
| 269 |
+
new_y += cy
|
| 270 |
+
else:
|
| 271 |
+
# place acw above current line
|
| 272 |
+
new_y -= acw_height
|
| 273 |
+
acw.wm_geometry("+%d+%d" % (new_x, new_y))
|
| 274 |
+
acw.update_idletasks()
|
| 275 |
+
except TclError:
|
| 276 |
+
pass
|
| 277 |
+
|
| 278 |
+
if platform.system().startswith('Windows'):
|
| 279 |
+
# See issue 15786. When on Windows platform, Tk will misbehave
|
| 280 |
+
# to call winconfig_event multiple times, we need to prevent this,
|
| 281 |
+
# otherwise mouse button double click will not be able to used.
|
| 282 |
+
try:
|
| 283 |
+
acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 284 |
+
except TclError:
|
| 285 |
+
pass
|
| 286 |
+
self.winconfigid = None
|
| 287 |
+
|
| 288 |
+
self.is_configuring = False
|
| 289 |
+
|
| 290 |
+
def _hide_event_check(self):
|
| 291 |
+
if not self.autocompletewindow:
|
| 292 |
+
return
|
| 293 |
+
|
| 294 |
+
try:
|
| 295 |
+
if not self.autocompletewindow.focus_get():
|
| 296 |
+
self.hide_window()
|
| 297 |
+
except KeyError:
|
| 298 |
+
# See issue 734176, when user click on menu, acw.focus_get()
|
| 299 |
+
# will get KeyError.
|
| 300 |
+
self.hide_window()
|
| 301 |
+
|
| 302 |
+
def hide_event(self, event):
|
| 303 |
+
# Hide autocomplete list if it exists and does not have focus or
|
| 304 |
+
# mouse click on widget / text area.
|
| 305 |
+
if self.is_active():
|
| 306 |
+
if event.type == EventType.FocusOut:
|
| 307 |
+
# On Windows platform, it will need to delay the check for
|
| 308 |
+
# acw.focus_get() when click on acw, otherwise it will return
|
| 309 |
+
# None and close the window
|
| 310 |
+
self.widget.after(1, self._hide_event_check)
|
| 311 |
+
elif event.type == EventType.ButtonPress:
|
| 312 |
+
# ButtonPress event only bind to self.widget
|
| 313 |
+
self.hide_window()
|
| 314 |
+
|
| 315 |
+
def listselect_event(self, event):
|
| 316 |
+
if self.is_active():
|
| 317 |
+
self.userwantswindow = True
|
| 318 |
+
cursel = int(self.listbox.curselection()[0])
|
| 319 |
+
self._change_start(self.completions[cursel])
|
| 320 |
+
|
| 321 |
+
def doubleclick_event(self, event):
|
| 322 |
+
# Put the selected completion in the text, and close the list
|
| 323 |
+
cursel = int(self.listbox.curselection()[0])
|
| 324 |
+
self._change_start(self.completions[cursel])
|
| 325 |
+
self.hide_window()
|
| 326 |
+
|
| 327 |
+
def keypress_event(self, event):
|
| 328 |
+
if not self.is_active():
|
| 329 |
+
return None
|
| 330 |
+
keysym = event.keysym
|
| 331 |
+
if hasattr(event, "mc_state"):
|
| 332 |
+
state = event.mc_state
|
| 333 |
+
else:
|
| 334 |
+
state = 0
|
| 335 |
+
if keysym != "Tab":
|
| 336 |
+
self.lastkey_was_tab = False
|
| 337 |
+
if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
|
| 338 |
+
or (self.mode == FILES and keysym in
|
| 339 |
+
("period", "minus"))) \
|
| 340 |
+
and not (state & ~MC_SHIFT):
|
| 341 |
+
# Normal editing of text
|
| 342 |
+
if len(keysym) == 1:
|
| 343 |
+
self._change_start(self.start + keysym)
|
| 344 |
+
elif keysym == "underscore":
|
| 345 |
+
self._change_start(self.start + '_')
|
| 346 |
+
elif keysym == "period":
|
| 347 |
+
self._change_start(self.start + '.')
|
| 348 |
+
elif keysym == "minus":
|
| 349 |
+
self._change_start(self.start + '-')
|
| 350 |
+
else:
|
| 351 |
+
# keysym == "BackSpace"
|
| 352 |
+
if len(self.start) == 0:
|
| 353 |
+
self.hide_window()
|
| 354 |
+
return None
|
| 355 |
+
self._change_start(self.start[:-1])
|
| 356 |
+
self.lasttypedstart = self.start
|
| 357 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 358 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 359 |
+
self._selection_changed()
|
| 360 |
+
return "break"
|
| 361 |
+
|
| 362 |
+
elif keysym == "Return":
|
| 363 |
+
self.complete()
|
| 364 |
+
self.hide_window()
|
| 365 |
+
return 'break'
|
| 366 |
+
|
| 367 |
+
elif (self.mode == ATTRS and keysym in
|
| 368 |
+
("period", "space", "parenleft", "parenright", "bracketleft",
|
| 369 |
+
"bracketright")) or \
|
| 370 |
+
(self.mode == FILES and keysym in
|
| 371 |
+
("slash", "backslash", "quotedbl", "apostrophe")) \
|
| 372 |
+
and not (state & ~MC_SHIFT):
|
| 373 |
+
# If start is a prefix of the selection, but is not '' when
|
| 374 |
+
# completing file names, put the whole
|
| 375 |
+
# selected completion. Anyway, close the list.
|
| 376 |
+
cursel = int(self.listbox.curselection()[0])
|
| 377 |
+
if self.completions[cursel][:len(self.start)] == self.start \
|
| 378 |
+
and (self.mode == ATTRS or self.start):
|
| 379 |
+
self._change_start(self.completions[cursel])
|
| 380 |
+
self.hide_window()
|
| 381 |
+
return None
|
| 382 |
+
|
| 383 |
+
elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
|
| 384 |
+
not state:
|
| 385 |
+
# Move the selection in the listbox
|
| 386 |
+
self.userwantswindow = True
|
| 387 |
+
cursel = int(self.listbox.curselection()[0])
|
| 388 |
+
if keysym == "Home":
|
| 389 |
+
newsel = 0
|
| 390 |
+
elif keysym == "End":
|
| 391 |
+
newsel = len(self.completions)-1
|
| 392 |
+
elif keysym in ("Prior", "Next"):
|
| 393 |
+
jump = self.listbox.nearest(self.listbox.winfo_height()) - \
|
| 394 |
+
self.listbox.nearest(0)
|
| 395 |
+
if keysym == "Prior":
|
| 396 |
+
newsel = max(0, cursel-jump)
|
| 397 |
+
else:
|
| 398 |
+
assert keysym == "Next"
|
| 399 |
+
newsel = min(len(self.completions)-1, cursel+jump)
|
| 400 |
+
elif keysym == "Up":
|
| 401 |
+
newsel = max(0, cursel-1)
|
| 402 |
+
else:
|
| 403 |
+
assert keysym == "Down"
|
| 404 |
+
newsel = min(len(self.completions)-1, cursel+1)
|
| 405 |
+
self.listbox.select_clear(cursel)
|
| 406 |
+
self.listbox.select_set(newsel)
|
| 407 |
+
self._selection_changed()
|
| 408 |
+
self._change_start(self.completions[newsel])
|
| 409 |
+
return "break"
|
| 410 |
+
|
| 411 |
+
elif (keysym == "Tab" and not state):
|
| 412 |
+
if self.lastkey_was_tab:
|
| 413 |
+
# two tabs in a row; insert current selection and close acw
|
| 414 |
+
cursel = int(self.listbox.curselection()[0])
|
| 415 |
+
self._change_start(self.completions[cursel])
|
| 416 |
+
self.hide_window()
|
| 417 |
+
return "break"
|
| 418 |
+
else:
|
| 419 |
+
# first tab; let AutoComplete handle the completion
|
| 420 |
+
self.userwantswindow = True
|
| 421 |
+
self.lastkey_was_tab = True
|
| 422 |
+
return None
|
| 423 |
+
|
| 424 |
+
elif any(s in keysym for s in ("Shift", "Control", "Alt",
|
| 425 |
+
"Meta", "Command", "Option")):
|
| 426 |
+
# A modifier key, so ignore
|
| 427 |
+
return None
|
| 428 |
+
|
| 429 |
+
elif event.char and event.char >= ' ':
|
| 430 |
+
# Regular character with a non-length-1 keycode
|
| 431 |
+
self._change_start(self.start + event.char)
|
| 432 |
+
self.lasttypedstart = self.start
|
| 433 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 434 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 435 |
+
self._selection_changed()
|
| 436 |
+
return "break"
|
| 437 |
+
|
| 438 |
+
else:
|
| 439 |
+
# Unknown event, close the window and let it through.
|
| 440 |
+
self.hide_window()
|
| 441 |
+
return None
|
| 442 |
+
|
| 443 |
+
def keyrelease_event(self, event):
|
| 444 |
+
if not self.is_active():
|
| 445 |
+
return
|
| 446 |
+
if self.widget.index("insert") != \
|
| 447 |
+
self.widget.index("%s+%dc" % (self.startindex, len(self.start))):
|
| 448 |
+
# If we didn't catch an event which moved the insert, close window
|
| 449 |
+
self.hide_window()
|
| 450 |
+
|
| 451 |
+
def is_active(self):
|
| 452 |
+
return self.autocompletewindow is not None
|
| 453 |
+
|
| 454 |
+
def complete(self):
|
| 455 |
+
self._change_start(self._complete_string(self.start))
|
| 456 |
+
# The selection doesn't change.
|
| 457 |
+
|
| 458 |
+
def hide_window(self):
|
| 459 |
+
if not self.is_active():
|
| 460 |
+
return
|
| 461 |
+
|
| 462 |
+
# unbind events
|
| 463 |
+
self.autocompletewindow.event_delete(HIDE_VIRTUAL_EVENT_NAME,
|
| 464 |
+
HIDE_FOCUS_OUT_SEQUENCE)
|
| 465 |
+
for seq in HIDE_SEQUENCES:
|
| 466 |
+
self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 467 |
+
|
| 468 |
+
self.autocompletewindow.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideaid)
|
| 469 |
+
self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hidewid)
|
| 470 |
+
self.hideaid = None
|
| 471 |
+
self.hidewid = None
|
| 472 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 473 |
+
self.widget.event_delete(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 474 |
+
self.widget.unbind(KEYPRESS_VIRTUAL_EVENT_NAME, self.keypressid)
|
| 475 |
+
self.keypressid = None
|
| 476 |
+
self.widget.event_delete(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 477 |
+
KEYRELEASE_SEQUENCE)
|
| 478 |
+
self.widget.unbind(KEYRELEASE_VIRTUAL_EVENT_NAME, self.keyreleaseid)
|
| 479 |
+
self.keyreleaseid = None
|
| 480 |
+
self.listbox.unbind(LISTUPDATE_SEQUENCE, self.listupdateid)
|
| 481 |
+
self.listupdateid = None
|
| 482 |
+
if self.winconfigid:
|
| 483 |
+
self.autocompletewindow.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 484 |
+
self.winconfigid = None
|
| 485 |
+
|
| 486 |
+
# Re-focusOn frame.text (See issue #15786)
|
| 487 |
+
self.widget.focus_set()
|
| 488 |
+
|
| 489 |
+
# destroy widgets
|
| 490 |
+
self.scrollbar.destroy()
|
| 491 |
+
self.scrollbar = None
|
| 492 |
+
self.listbox.destroy()
|
| 493 |
+
self.listbox = None
|
| 494 |
+
self.autocompletewindow.destroy()
|
| 495 |
+
self.autocompletewindow = None
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
if __name__ == '__main__':
|
| 499 |
+
from unittest import main
|
| 500 |
+
main('idlelib.idle_test.test_autocomplete_w', verbosity=2, exit=False)
|
| 501 |
+
|
| 502 |
+
# TODO: autocomplete/w htest here
|
evalkit_tf446/lib/python3.10/idlelib/browser.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module browser.
|
| 2 |
+
|
| 3 |
+
XXX TO DO:
|
| 4 |
+
|
| 5 |
+
- reparse when source changed (maybe just a button would be OK?)
|
| 6 |
+
(or recheck on window popup)
|
| 7 |
+
- add popup menu with more options (e.g. doc strings, base classes, imports)
|
| 8 |
+
- add base classes to class browser tree
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import pyclbr
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
from idlelib.config import idleConf
|
| 16 |
+
from idlelib import pyshell
|
| 17 |
+
from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
|
| 18 |
+
from idlelib.util import py_extensions
|
| 19 |
+
from idlelib.window import ListedToplevel
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
file_open = None # Method...Item and Class...Item use this.
|
| 23 |
+
# Normally pyshell.flist.open, but there is no pyshell.flist for htest.
|
| 24 |
+
|
| 25 |
+
# The browser depends on pyclbr and importlib which do not support .pyi files.
|
| 26 |
+
browseable_extension_blocklist = ('.pyi',)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def is_browseable_extension(path):
|
| 30 |
+
_, ext = os.path.splitext(path)
|
| 31 |
+
ext = os.path.normcase(ext)
|
| 32 |
+
return ext in py_extensions and ext not in browseable_extension_blocklist
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def transform_children(child_dict, modname=None):
|
| 36 |
+
"""Transform a child dictionary to an ordered sequence of objects.
|
| 37 |
+
|
| 38 |
+
The dictionary maps names to pyclbr information objects.
|
| 39 |
+
Filter out imported objects.
|
| 40 |
+
Augment class names with bases.
|
| 41 |
+
The insertion order of the dictionary is assumed to have been in line
|
| 42 |
+
number order, so sorting is not necessary.
|
| 43 |
+
|
| 44 |
+
The current tree only calls this once per child_dict as it saves
|
| 45 |
+
TreeItems once created. A future tree and tests might violate this,
|
| 46 |
+
so a check prevents multiple in-place augmentations.
|
| 47 |
+
"""
|
| 48 |
+
obs = [] # Use list since values should already be sorted.
|
| 49 |
+
for key, obj in child_dict.items():
|
| 50 |
+
if modname is None or obj.module == modname:
|
| 51 |
+
if hasattr(obj, 'super') and obj.super and obj.name == key:
|
| 52 |
+
# If obj.name != key, it has already been suffixed.
|
| 53 |
+
supers = []
|
| 54 |
+
for sup in obj.super:
|
| 55 |
+
if isinstance(sup, str):
|
| 56 |
+
sname = sup
|
| 57 |
+
else:
|
| 58 |
+
sname = sup.name
|
| 59 |
+
if sup.module != obj.module:
|
| 60 |
+
sname = f'{sup.module}.{sname}'
|
| 61 |
+
supers.append(sname)
|
| 62 |
+
obj.name += '({})'.format(', '.join(supers))
|
| 63 |
+
obs.append(obj)
|
| 64 |
+
return obs
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class ModuleBrowser:
|
| 68 |
+
"""Browse module classes and functions in IDLE.
|
| 69 |
+
"""
|
| 70 |
+
# This class is also the base class for pathbrowser.PathBrowser.
|
| 71 |
+
# Init and close are inherited, other methods are overridden.
|
| 72 |
+
# PathBrowser.__init__ does not call __init__ below.
|
| 73 |
+
|
| 74 |
+
def __init__(self, master, path, *, _htest=False, _utest=False):
|
| 75 |
+
"""Create a window for browsing a module's structure.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
master: parent for widgets.
|
| 79 |
+
path: full path of file to browse.
|
| 80 |
+
_htest - bool; change box location when running htest.
|
| 81 |
+
-utest - bool; suppress contents when running unittest.
|
| 82 |
+
|
| 83 |
+
Global variables:
|
| 84 |
+
file_open: Function used for opening a file.
|
| 85 |
+
|
| 86 |
+
Instance variables:
|
| 87 |
+
name: Module name.
|
| 88 |
+
file: Full path and module with supported extension.
|
| 89 |
+
Used in creating ModuleBrowserTreeItem as the rootnode for
|
| 90 |
+
the tree and subsequently in the children.
|
| 91 |
+
"""
|
| 92 |
+
self.master = master
|
| 93 |
+
self.path = path
|
| 94 |
+
self._htest = _htest
|
| 95 |
+
self._utest = _utest
|
| 96 |
+
self.init()
|
| 97 |
+
|
| 98 |
+
def close(self, event=None):
|
| 99 |
+
"Dismiss the window and the tree nodes."
|
| 100 |
+
self.top.destroy()
|
| 101 |
+
self.node.destroy()
|
| 102 |
+
|
| 103 |
+
def init(self):
|
| 104 |
+
"Create browser tkinter widgets, including the tree."
|
| 105 |
+
global file_open
|
| 106 |
+
root = self.master
|
| 107 |
+
flist = (pyshell.flist if not (self._htest or self._utest)
|
| 108 |
+
else pyshell.PyShellFileList(root))
|
| 109 |
+
file_open = flist.open
|
| 110 |
+
pyclbr._modules.clear()
|
| 111 |
+
|
| 112 |
+
# create top
|
| 113 |
+
self.top = top = ListedToplevel(root)
|
| 114 |
+
top.protocol("WM_DELETE_WINDOW", self.close)
|
| 115 |
+
top.bind("<Escape>", self.close)
|
| 116 |
+
if self._htest: # place dialog below parent if running htest
|
| 117 |
+
top.geometry("+%d+%d" %
|
| 118 |
+
(root.winfo_rootx(), root.winfo_rooty() + 200))
|
| 119 |
+
self.settitle()
|
| 120 |
+
top.focus_set()
|
| 121 |
+
|
| 122 |
+
# create scrolled canvas
|
| 123 |
+
theme = idleConf.CurrentTheme()
|
| 124 |
+
background = idleConf.GetHighlight(theme, 'normal')['background']
|
| 125 |
+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0,
|
| 126 |
+
takefocus=1)
|
| 127 |
+
sc.frame.pack(expand=1, fill="both")
|
| 128 |
+
item = self.rootnode()
|
| 129 |
+
self.node = node = TreeNode(sc.canvas, None, item)
|
| 130 |
+
if not self._utest:
|
| 131 |
+
node.update()
|
| 132 |
+
node.expand()
|
| 133 |
+
|
| 134 |
+
def settitle(self):
|
| 135 |
+
"Set the window title."
|
| 136 |
+
self.top.wm_title("Module Browser - " + os.path.basename(self.path))
|
| 137 |
+
self.top.wm_iconname("Module Browser")
|
| 138 |
+
|
| 139 |
+
def rootnode(self):
|
| 140 |
+
"Return a ModuleBrowserTreeItem as the root of the tree."
|
| 141 |
+
return ModuleBrowserTreeItem(self.path)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class ModuleBrowserTreeItem(TreeItem):
|
| 145 |
+
"""Browser tree for Python module.
|
| 146 |
+
|
| 147 |
+
Uses TreeItem as the basis for the structure of the tree.
|
| 148 |
+
Used by both browsers.
|
| 149 |
+
"""
|
| 150 |
+
|
| 151 |
+
def __init__(self, file):
|
| 152 |
+
"""Create a TreeItem for the file.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
file: Full path and module name.
|
| 156 |
+
"""
|
| 157 |
+
self.file = file
|
| 158 |
+
|
| 159 |
+
def GetText(self):
|
| 160 |
+
"Return the module name as the text string to display."
|
| 161 |
+
return os.path.basename(self.file)
|
| 162 |
+
|
| 163 |
+
def GetIconName(self):
|
| 164 |
+
"Return the name of the icon to display."
|
| 165 |
+
return "python"
|
| 166 |
+
|
| 167 |
+
def GetSubList(self):
|
| 168 |
+
"Return ChildBrowserTreeItems for children."
|
| 169 |
+
return [ChildBrowserTreeItem(obj) for obj in self.listchildren()]
|
| 170 |
+
|
| 171 |
+
def OnDoubleClick(self):
|
| 172 |
+
"Open a module in an editor window when double clicked."
|
| 173 |
+
if not is_browseable_extension(self.file):
|
| 174 |
+
return
|
| 175 |
+
if not os.path.exists(self.file):
|
| 176 |
+
return
|
| 177 |
+
file_open(self.file)
|
| 178 |
+
|
| 179 |
+
def IsExpandable(self):
|
| 180 |
+
"Return True if Python file."
|
| 181 |
+
return is_browseable_extension(self.file)
|
| 182 |
+
|
| 183 |
+
def listchildren(self):
|
| 184 |
+
"Return sequenced classes and functions in the module."
|
| 185 |
+
if not is_browseable_extension(self.file):
|
| 186 |
+
return []
|
| 187 |
+
dir, base = os.path.split(self.file)
|
| 188 |
+
name, _ = os.path.splitext(base)
|
| 189 |
+
try:
|
| 190 |
+
tree = pyclbr.readmodule_ex(name, [dir] + sys.path)
|
| 191 |
+
except ImportError:
|
| 192 |
+
return []
|
| 193 |
+
return transform_children(tree, name)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class ChildBrowserTreeItem(TreeItem):
|
| 197 |
+
"""Browser tree for child nodes within the module.
|
| 198 |
+
|
| 199 |
+
Uses TreeItem as the basis for the structure of the tree.
|
| 200 |
+
"""
|
| 201 |
+
|
| 202 |
+
def __init__(self, obj):
|
| 203 |
+
"Create a TreeItem for a pyclbr class/function object."
|
| 204 |
+
self.obj = obj
|
| 205 |
+
self.name = obj.name
|
| 206 |
+
self.isfunction = isinstance(obj, pyclbr.Function)
|
| 207 |
+
|
| 208 |
+
def GetText(self):
|
| 209 |
+
"Return the name of the function/class to display."
|
| 210 |
+
name = self.name
|
| 211 |
+
if self.isfunction:
|
| 212 |
+
return "def " + name + "(...)"
|
| 213 |
+
else:
|
| 214 |
+
return "class " + name
|
| 215 |
+
|
| 216 |
+
def GetIconName(self):
|
| 217 |
+
"Return the name of the icon to display."
|
| 218 |
+
if self.isfunction:
|
| 219 |
+
return "python"
|
| 220 |
+
else:
|
| 221 |
+
return "folder"
|
| 222 |
+
|
| 223 |
+
def IsExpandable(self):
|
| 224 |
+
"Return True if self.obj has nested objects."
|
| 225 |
+
return self.obj.children != {}
|
| 226 |
+
|
| 227 |
+
def GetSubList(self):
|
| 228 |
+
"Return ChildBrowserTreeItems for children."
|
| 229 |
+
return [ChildBrowserTreeItem(obj)
|
| 230 |
+
for obj in transform_children(self.obj.children)]
|
| 231 |
+
|
| 232 |
+
def OnDoubleClick(self):
|
| 233 |
+
"Open module with file_open and position to lineno."
|
| 234 |
+
try:
|
| 235 |
+
edit = file_open(self.obj.file)
|
| 236 |
+
edit.gotoline(self.obj.lineno)
|
| 237 |
+
except (OSError, AttributeError):
|
| 238 |
+
pass
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def _module_browser(parent): # htest #
|
| 242 |
+
if len(sys.argv) > 1: # If pass file on command line.
|
| 243 |
+
file = sys.argv[1]
|
| 244 |
+
else:
|
| 245 |
+
file = __file__
|
| 246 |
+
# Add nested objects for htest.
|
| 247 |
+
class Nested_in_func(TreeNode):
|
| 248 |
+
def nested_in_class(): pass
|
| 249 |
+
def closure():
|
| 250 |
+
class Nested_in_closure: pass
|
| 251 |
+
ModuleBrowser(parent, file, _htest=True)
|
| 252 |
+
|
| 253 |
+
if __name__ == "__main__":
|
| 254 |
+
if len(sys.argv) == 1: # If pass file on command line, unittest fails.
|
| 255 |
+
from unittest import main
|
| 256 |
+
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
|
| 257 |
+
from idlelib.idle_test.htest import run
|
| 258 |
+
run(_module_browser)
|
evalkit_tf446/lib/python3.10/idlelib/calltip.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pop up a reminder of how to call a function.
|
| 2 |
+
|
| 3 |
+
Call Tips are floating windows which display function, class, and method
|
| 4 |
+
parameter and docstring information when you type an opening parenthesis, and
|
| 5 |
+
which disappear when you type a closing parenthesis.
|
| 6 |
+
"""
|
| 7 |
+
import __main__
|
| 8 |
+
import inspect
|
| 9 |
+
import re
|
| 10 |
+
import sys
|
| 11 |
+
import textwrap
|
| 12 |
+
import types
|
| 13 |
+
|
| 14 |
+
from idlelib import calltip_w
|
| 15 |
+
from idlelib.hyperparser import HyperParser
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Calltip:
|
| 19 |
+
|
| 20 |
+
def __init__(self, editwin=None):
|
| 21 |
+
if editwin is None: # subprocess and test
|
| 22 |
+
self.editwin = None
|
| 23 |
+
else:
|
| 24 |
+
self.editwin = editwin
|
| 25 |
+
self.text = editwin.text
|
| 26 |
+
self.active_calltip = None
|
| 27 |
+
self._calltip_window = self._make_tk_calltip_window
|
| 28 |
+
|
| 29 |
+
def close(self):
|
| 30 |
+
self._calltip_window = None
|
| 31 |
+
|
| 32 |
+
def _make_tk_calltip_window(self):
|
| 33 |
+
# See __init__ for usage
|
| 34 |
+
return calltip_w.CalltipWindow(self.text)
|
| 35 |
+
|
| 36 |
+
def remove_calltip_window(self, event=None):
|
| 37 |
+
if self.active_calltip:
|
| 38 |
+
self.active_calltip.hidetip()
|
| 39 |
+
self.active_calltip = None
|
| 40 |
+
|
| 41 |
+
def force_open_calltip_event(self, event):
|
| 42 |
+
"The user selected the menu entry or hotkey, open the tip."
|
| 43 |
+
self.open_calltip(True)
|
| 44 |
+
return "break"
|
| 45 |
+
|
| 46 |
+
def try_open_calltip_event(self, event):
|
| 47 |
+
"""Happens when it would be nice to open a calltip, but not really
|
| 48 |
+
necessary, for example after an opening bracket, so function calls
|
| 49 |
+
won't be made.
|
| 50 |
+
"""
|
| 51 |
+
self.open_calltip(False)
|
| 52 |
+
|
| 53 |
+
def refresh_calltip_event(self, event):
|
| 54 |
+
if self.active_calltip and self.active_calltip.tipwindow:
|
| 55 |
+
self.open_calltip(False)
|
| 56 |
+
|
| 57 |
+
def open_calltip(self, evalfuncs):
|
| 58 |
+
"""Maybe close an existing calltip and maybe open a new calltip.
|
| 59 |
+
|
| 60 |
+
Called from (force_open|try_open|refresh)_calltip_event functions.
|
| 61 |
+
"""
|
| 62 |
+
hp = HyperParser(self.editwin, "insert")
|
| 63 |
+
sur_paren = hp.get_surrounding_brackets('(')
|
| 64 |
+
|
| 65 |
+
# If not inside parentheses, no calltip.
|
| 66 |
+
if not sur_paren:
|
| 67 |
+
self.remove_calltip_window()
|
| 68 |
+
return
|
| 69 |
+
|
| 70 |
+
# If a calltip is shown for the current parentheses, do
|
| 71 |
+
# nothing.
|
| 72 |
+
if self.active_calltip:
|
| 73 |
+
opener_line, opener_col = map(int, sur_paren[0].split('.'))
|
| 74 |
+
if (
|
| 75 |
+
(opener_line, opener_col) ==
|
| 76 |
+
(self.active_calltip.parenline, self.active_calltip.parencol)
|
| 77 |
+
):
|
| 78 |
+
return
|
| 79 |
+
|
| 80 |
+
hp.set_index(sur_paren[0])
|
| 81 |
+
try:
|
| 82 |
+
expression = hp.get_expression()
|
| 83 |
+
except ValueError:
|
| 84 |
+
expression = None
|
| 85 |
+
if not expression:
|
| 86 |
+
# No expression before the opening parenthesis, e.g.
|
| 87 |
+
# because it's in a string or the opener for a tuple:
|
| 88 |
+
# Do nothing.
|
| 89 |
+
return
|
| 90 |
+
|
| 91 |
+
# At this point, the current index is after an opening
|
| 92 |
+
# parenthesis, in a section of code, preceded by a valid
|
| 93 |
+
# expression. If there is a calltip shown, it's not for the
|
| 94 |
+
# same index and should be closed.
|
| 95 |
+
self.remove_calltip_window()
|
| 96 |
+
|
| 97 |
+
# Simple, fast heuristic: If the preceding expression includes
|
| 98 |
+
# an opening parenthesis, it likely includes a function call.
|
| 99 |
+
if not evalfuncs and (expression.find('(') != -1):
|
| 100 |
+
return
|
| 101 |
+
|
| 102 |
+
argspec = self.fetch_tip(expression)
|
| 103 |
+
if not argspec:
|
| 104 |
+
return
|
| 105 |
+
self.active_calltip = self._calltip_window()
|
| 106 |
+
self.active_calltip.showtip(argspec, sur_paren[0], sur_paren[1])
|
| 107 |
+
|
| 108 |
+
def fetch_tip(self, expression):
|
| 109 |
+
"""Return the argument list and docstring of a function or class.
|
| 110 |
+
|
| 111 |
+
If there is a Python subprocess, get the calltip there. Otherwise,
|
| 112 |
+
either this fetch_tip() is running in the subprocess or it was
|
| 113 |
+
called in an IDLE running without the subprocess.
|
| 114 |
+
|
| 115 |
+
The subprocess environment is that of the most recently run script. If
|
| 116 |
+
two unrelated modules are being edited some calltips in the current
|
| 117 |
+
module may be inoperative if the module was not the last to run.
|
| 118 |
+
|
| 119 |
+
To find methods, fetch_tip must be fed a fully qualified name.
|
| 120 |
+
|
| 121 |
+
"""
|
| 122 |
+
try:
|
| 123 |
+
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
|
| 124 |
+
except AttributeError:
|
| 125 |
+
rpcclt = None
|
| 126 |
+
if rpcclt:
|
| 127 |
+
return rpcclt.remotecall("exec", "get_the_calltip",
|
| 128 |
+
(expression,), {})
|
| 129 |
+
else:
|
| 130 |
+
return get_argspec(get_entity(expression))
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def get_entity(expression):
|
| 134 |
+
"""Return the object corresponding to expression evaluated
|
| 135 |
+
in a namespace spanning sys.modules and __main.dict__.
|
| 136 |
+
"""
|
| 137 |
+
if expression:
|
| 138 |
+
namespace = {**sys.modules, **__main__.__dict__}
|
| 139 |
+
try:
|
| 140 |
+
return eval(expression, namespace) # Only protect user code.
|
| 141 |
+
except BaseException:
|
| 142 |
+
# An uncaught exception closes idle, and eval can raise any
|
| 143 |
+
# exception, especially if user classes are involved.
|
| 144 |
+
return None
|
| 145 |
+
|
| 146 |
+
# The following are used in get_argspec and some in tests
|
| 147 |
+
_MAX_COLS = 85
|
| 148 |
+
_MAX_LINES = 5 # enough for bytes
|
| 149 |
+
_INDENT = ' '*4 # for wrapped signatures
|
| 150 |
+
_first_param = re.compile(r'(?<=\()\w*\,?\s*')
|
| 151 |
+
_default_callable_argspec = "See source or doc"
|
| 152 |
+
_invalid_method = "invalid method signature"
|
| 153 |
+
|
| 154 |
+
def get_argspec(ob):
|
| 155 |
+
'''Return a string describing the signature of a callable object, or ''.
|
| 156 |
+
|
| 157 |
+
For Python-coded functions and methods, the first line is introspected.
|
| 158 |
+
Delete 'self' parameter for classes (.__init__) and bound methods.
|
| 159 |
+
The next lines are the first lines of the doc string up to the first
|
| 160 |
+
empty line or _MAX_LINES. For builtins, this typically includes
|
| 161 |
+
the arguments in addition to the return value.
|
| 162 |
+
'''
|
| 163 |
+
# Determine function object fob to inspect.
|
| 164 |
+
try:
|
| 165 |
+
ob_call = ob.__call__
|
| 166 |
+
except BaseException: # Buggy user object could raise anything.
|
| 167 |
+
return '' # No popup for non-callables.
|
| 168 |
+
# For Get_argspecTest.test_buggy_getattr_class, CallA() & CallB().
|
| 169 |
+
fob = ob_call if isinstance(ob_call, types.MethodType) else ob
|
| 170 |
+
|
| 171 |
+
# Initialize argspec and wrap it to get lines.
|
| 172 |
+
try:
|
| 173 |
+
argspec = str(inspect.signature(fob))
|
| 174 |
+
except Exception as err:
|
| 175 |
+
msg = str(err)
|
| 176 |
+
if msg.startswith(_invalid_method):
|
| 177 |
+
return _invalid_method
|
| 178 |
+
else:
|
| 179 |
+
argspec = ''
|
| 180 |
+
|
| 181 |
+
if isinstance(fob, type) and argspec == '()':
|
| 182 |
+
# If fob has no argument, use default callable argspec.
|
| 183 |
+
argspec = _default_callable_argspec
|
| 184 |
+
|
| 185 |
+
lines = (textwrap.wrap(argspec, _MAX_COLS, subsequent_indent=_INDENT)
|
| 186 |
+
if len(argspec) > _MAX_COLS else [argspec] if argspec else [])
|
| 187 |
+
|
| 188 |
+
# Augment lines from docstring, if any, and join to get argspec.
|
| 189 |
+
doc = inspect.getdoc(ob)
|
| 190 |
+
if doc:
|
| 191 |
+
for line in doc.split('\n', _MAX_LINES)[:_MAX_LINES]:
|
| 192 |
+
line = line.strip()
|
| 193 |
+
if not line:
|
| 194 |
+
break
|
| 195 |
+
if len(line) > _MAX_COLS:
|
| 196 |
+
line = line[: _MAX_COLS - 3] + '...'
|
| 197 |
+
lines.append(line)
|
| 198 |
+
argspec = '\n'.join(lines)
|
| 199 |
+
|
| 200 |
+
return argspec or _default_callable_argspec
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
if __name__ == '__main__':
|
| 204 |
+
from unittest import main
|
| 205 |
+
main('idlelib.idle_test.test_calltip', verbosity=2)
|
evalkit_tf446/lib/python3.10/idlelib/codecontext.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""codecontext - display the block context above the edit window
|
| 2 |
+
|
| 3 |
+
Once code has scrolled off the top of a window, it can be difficult to
|
| 4 |
+
determine which block you are in. This extension implements a pane at the top
|
| 5 |
+
of each IDLE edit window which provides block structure hints. These hints are
|
| 6 |
+
the lines which contain the block opening keywords, e.g. 'if', for the
|
| 7 |
+
enclosing block. The number of hint lines is determined by the maxlines
|
| 8 |
+
variable in the codecontext section of config-extensions.def. Lines which do
|
| 9 |
+
not open blocks are not shown in the context hints pane.
|
| 10 |
+
|
| 11 |
+
For EditorWindows, <<toggle-code-context>> is bound to CodeContext(self).
|
| 12 |
+
toggle_code_context_event.
|
| 13 |
+
"""
|
| 14 |
+
import re
|
| 15 |
+
from sys import maxsize as INFINITY
|
| 16 |
+
|
| 17 |
+
from tkinter import Frame, Text, TclError
|
| 18 |
+
from tkinter.constants import NSEW, SUNKEN
|
| 19 |
+
|
| 20 |
+
from idlelib.config import idleConf
|
| 21 |
+
|
| 22 |
+
BLOCKOPENERS = {'class', 'def', 'if', 'elif', 'else', 'while', 'for',
|
| 23 |
+
'try', 'except', 'finally', 'with', 'async'}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def get_spaces_firstword(codeline, c=re.compile(r"^(\s*)(\w*)")):
|
| 27 |
+
"Extract the beginning whitespace and first word from codeline."
|
| 28 |
+
return c.match(codeline).groups()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def get_line_info(codeline):
|
| 32 |
+
"""Return tuple of (line indent value, codeline, block start keyword).
|
| 33 |
+
|
| 34 |
+
The indentation of empty lines (or comment lines) is INFINITY.
|
| 35 |
+
If the line does not start a block, the keyword value is False.
|
| 36 |
+
"""
|
| 37 |
+
spaces, firstword = get_spaces_firstword(codeline)
|
| 38 |
+
indent = len(spaces)
|
| 39 |
+
if len(codeline) == indent or codeline[indent] == '#':
|
| 40 |
+
indent = INFINITY
|
| 41 |
+
opener = firstword in BLOCKOPENERS and firstword
|
| 42 |
+
return indent, codeline, opener
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class CodeContext:
|
| 46 |
+
"Display block context above the edit window."
|
| 47 |
+
UPDATEINTERVAL = 100 # millisec
|
| 48 |
+
|
| 49 |
+
def __init__(self, editwin):
|
| 50 |
+
"""Initialize settings for context block.
|
| 51 |
+
|
| 52 |
+
editwin is the Editor window for the context block.
|
| 53 |
+
self.text is the editor window text widget.
|
| 54 |
+
|
| 55 |
+
self.context displays the code context text above the editor text.
|
| 56 |
+
Initially None, it is toggled via <<toggle-code-context>>.
|
| 57 |
+
self.topvisible is the number of the top text line displayed.
|
| 58 |
+
self.info is a list of (line number, indent level, line text,
|
| 59 |
+
block keyword) tuples for the block structure above topvisible.
|
| 60 |
+
self.info[0] is initialized with a 'dummy' line which
|
| 61 |
+
starts the toplevel 'block' of the module.
|
| 62 |
+
|
| 63 |
+
self.t1 and self.t2 are two timer events on the editor text widget to
|
| 64 |
+
monitor for changes to the context text or editor font.
|
| 65 |
+
"""
|
| 66 |
+
self.editwin = editwin
|
| 67 |
+
self.text = editwin.text
|
| 68 |
+
self._reset()
|
| 69 |
+
|
| 70 |
+
def _reset(self):
|
| 71 |
+
self.context = None
|
| 72 |
+
self.cell00 = None
|
| 73 |
+
self.t1 = None
|
| 74 |
+
self.topvisible = 1
|
| 75 |
+
self.info = [(0, -1, "", False)]
|
| 76 |
+
|
| 77 |
+
@classmethod
|
| 78 |
+
def reload(cls):
|
| 79 |
+
"Load class variables from config."
|
| 80 |
+
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
|
| 81 |
+
"maxlines", type="int",
|
| 82 |
+
default=15)
|
| 83 |
+
|
| 84 |
+
def __del__(self):
|
| 85 |
+
"Cancel scheduled events."
|
| 86 |
+
if self.t1 is not None:
|
| 87 |
+
try:
|
| 88 |
+
self.text.after_cancel(self.t1)
|
| 89 |
+
except TclError: # pragma: no cover
|
| 90 |
+
pass
|
| 91 |
+
self.t1 = None
|
| 92 |
+
|
| 93 |
+
def toggle_code_context_event(self, event=None):
|
| 94 |
+
"""Toggle code context display.
|
| 95 |
+
|
| 96 |
+
If self.context doesn't exist, create it to match the size of the editor
|
| 97 |
+
window text (toggle on). If it does exist, destroy it (toggle off).
|
| 98 |
+
Return 'break' to complete the processing of the binding.
|
| 99 |
+
"""
|
| 100 |
+
if self.context is None:
|
| 101 |
+
# Calculate the border width and horizontal padding required to
|
| 102 |
+
# align the context with the text in the main Text widget.
|
| 103 |
+
#
|
| 104 |
+
# All values are passed through getint(), since some
|
| 105 |
+
# values may be pixel objects, which can't simply be added to ints.
|
| 106 |
+
widgets = self.editwin.text, self.editwin.text_frame
|
| 107 |
+
# Calculate the required horizontal padding and border width.
|
| 108 |
+
padx = 0
|
| 109 |
+
border = 0
|
| 110 |
+
for widget in widgets:
|
| 111 |
+
info = (widget.grid_info()
|
| 112 |
+
if widget is self.editwin.text
|
| 113 |
+
else widget.pack_info())
|
| 114 |
+
padx += widget.tk.getint(info['padx'])
|
| 115 |
+
padx += widget.tk.getint(widget.cget('padx'))
|
| 116 |
+
border += widget.tk.getint(widget.cget('border'))
|
| 117 |
+
context = self.context = Text(
|
| 118 |
+
self.editwin.text_frame,
|
| 119 |
+
height=1,
|
| 120 |
+
width=1, # Don't request more than we get.
|
| 121 |
+
highlightthickness=0,
|
| 122 |
+
padx=padx, border=border, relief=SUNKEN, state='disabled')
|
| 123 |
+
self.update_font()
|
| 124 |
+
self.update_highlight_colors()
|
| 125 |
+
context.bind('<ButtonRelease-1>', self.jumptoline)
|
| 126 |
+
# Get the current context and initiate the recurring update event.
|
| 127 |
+
self.timer_event()
|
| 128 |
+
# Grid the context widget above the text widget.
|
| 129 |
+
context.grid(row=0, column=1, sticky=NSEW)
|
| 130 |
+
|
| 131 |
+
line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 132 |
+
'linenumber')
|
| 133 |
+
self.cell00 = Frame(self.editwin.text_frame,
|
| 134 |
+
bg=line_number_colors['background'])
|
| 135 |
+
self.cell00.grid(row=0, column=0, sticky=NSEW)
|
| 136 |
+
menu_status = 'Hide'
|
| 137 |
+
else:
|
| 138 |
+
self.context.destroy()
|
| 139 |
+
self.context = None
|
| 140 |
+
self.cell00.destroy()
|
| 141 |
+
self.cell00 = None
|
| 142 |
+
self.text.after_cancel(self.t1)
|
| 143 |
+
self._reset()
|
| 144 |
+
menu_status = 'Show'
|
| 145 |
+
self.editwin.update_menu_label(menu='options', index='*ode*ontext',
|
| 146 |
+
label=f'{menu_status} Code Context')
|
| 147 |
+
return "break"
|
| 148 |
+
|
| 149 |
+
def get_context(self, new_topvisible, stopline=1, stopindent=0):
|
| 150 |
+
"""Return a list of block line tuples and the 'last' indent.
|
| 151 |
+
|
| 152 |
+
The tuple fields are (linenum, indent, text, opener).
|
| 153 |
+
The list represents header lines from new_topvisible back to
|
| 154 |
+
stopline with successively shorter indents > stopindent.
|
| 155 |
+
The list is returned ordered by line number.
|
| 156 |
+
Last indent returned is the smallest indent observed.
|
| 157 |
+
"""
|
| 158 |
+
assert stopline > 0
|
| 159 |
+
lines = []
|
| 160 |
+
# The indentation level we are currently in.
|
| 161 |
+
lastindent = INFINITY
|
| 162 |
+
# For a line to be interesting, it must begin with a block opening
|
| 163 |
+
# keyword, and have less indentation than lastindent.
|
| 164 |
+
for linenum in range(new_topvisible, stopline-1, -1):
|
| 165 |
+
codeline = self.text.get(f'{linenum}.0', f'{linenum}.end')
|
| 166 |
+
indent, text, opener = get_line_info(codeline)
|
| 167 |
+
if indent < lastindent:
|
| 168 |
+
lastindent = indent
|
| 169 |
+
if opener in ("else", "elif"):
|
| 170 |
+
# Also show the if statement.
|
| 171 |
+
lastindent += 1
|
| 172 |
+
if opener and linenum < new_topvisible and indent >= stopindent:
|
| 173 |
+
lines.append((linenum, indent, text, opener))
|
| 174 |
+
if lastindent <= stopindent:
|
| 175 |
+
break
|
| 176 |
+
lines.reverse()
|
| 177 |
+
return lines, lastindent
|
| 178 |
+
|
| 179 |
+
def update_code_context(self):
|
| 180 |
+
"""Update context information and lines visible in the context pane.
|
| 181 |
+
|
| 182 |
+
No update is done if the text hasn't been scrolled. If the text
|
| 183 |
+
was scrolled, the lines that should be shown in the context will
|
| 184 |
+
be retrieved and the context area will be updated with the code,
|
| 185 |
+
up to the number of maxlines.
|
| 186 |
+
"""
|
| 187 |
+
new_topvisible = self.editwin.getlineno("@0,0")
|
| 188 |
+
if self.topvisible == new_topvisible: # Haven't scrolled.
|
| 189 |
+
return
|
| 190 |
+
if self.topvisible < new_topvisible: # Scroll down.
|
| 191 |
+
lines, lastindent = self.get_context(new_topvisible,
|
| 192 |
+
self.topvisible)
|
| 193 |
+
# Retain only context info applicable to the region
|
| 194 |
+
# between topvisible and new_topvisible.
|
| 195 |
+
while self.info[-1][1] >= lastindent:
|
| 196 |
+
del self.info[-1]
|
| 197 |
+
else: # self.topvisible > new_topvisible: # Scroll up.
|
| 198 |
+
stopindent = self.info[-1][1] + 1
|
| 199 |
+
# Retain only context info associated
|
| 200 |
+
# with lines above new_topvisible.
|
| 201 |
+
while self.info[-1][0] >= new_topvisible:
|
| 202 |
+
stopindent = self.info[-1][1]
|
| 203 |
+
del self.info[-1]
|
| 204 |
+
lines, lastindent = self.get_context(new_topvisible,
|
| 205 |
+
self.info[-1][0]+1,
|
| 206 |
+
stopindent)
|
| 207 |
+
self.info.extend(lines)
|
| 208 |
+
self.topvisible = new_topvisible
|
| 209 |
+
# Last context_depth context lines.
|
| 210 |
+
context_strings = [x[2] for x in self.info[-self.context_depth:]]
|
| 211 |
+
showfirst = 0 if context_strings[0] else 1
|
| 212 |
+
# Update widget.
|
| 213 |
+
self.context['height'] = len(context_strings) - showfirst
|
| 214 |
+
self.context['state'] = 'normal'
|
| 215 |
+
self.context.delete('1.0', 'end')
|
| 216 |
+
self.context.insert('end', '\n'.join(context_strings[showfirst:]))
|
| 217 |
+
self.context['state'] = 'disabled'
|
| 218 |
+
|
| 219 |
+
def jumptoline(self, event=None):
|
| 220 |
+
""" Show clicked context line at top of editor.
|
| 221 |
+
|
| 222 |
+
If a selection was made, don't jump; allow copying.
|
| 223 |
+
If no visible context, show the top line of the file.
|
| 224 |
+
"""
|
| 225 |
+
try:
|
| 226 |
+
self.context.index("sel.first")
|
| 227 |
+
except TclError:
|
| 228 |
+
lines = len(self.info)
|
| 229 |
+
if lines == 1: # No context lines are showing.
|
| 230 |
+
newtop = 1
|
| 231 |
+
else:
|
| 232 |
+
# Line number clicked.
|
| 233 |
+
contextline = int(float(self.context.index('insert')))
|
| 234 |
+
# Lines not displayed due to maxlines.
|
| 235 |
+
offset = max(1, lines - self.context_depth) - 1
|
| 236 |
+
newtop = self.info[offset + contextline][0]
|
| 237 |
+
self.text.yview(f'{newtop}.0')
|
| 238 |
+
self.update_code_context()
|
| 239 |
+
|
| 240 |
+
def timer_event(self):
|
| 241 |
+
"Event on editor text widget triggered every UPDATEINTERVAL ms."
|
| 242 |
+
if self.context is not None:
|
| 243 |
+
self.update_code_context()
|
| 244 |
+
self.t1 = self.text.after(self.UPDATEINTERVAL, self.timer_event)
|
| 245 |
+
|
| 246 |
+
def update_font(self):
|
| 247 |
+
if self.context is not None:
|
| 248 |
+
font = idleConf.GetFont(self.text, 'main', 'EditorWindow')
|
| 249 |
+
self.context['font'] = font
|
| 250 |
+
|
| 251 |
+
def update_highlight_colors(self):
|
| 252 |
+
if self.context is not None:
|
| 253 |
+
colors = idleConf.GetHighlight(idleConf.CurrentTheme(), 'context')
|
| 254 |
+
self.context['background'] = colors['background']
|
| 255 |
+
self.context['foreground'] = colors['foreground']
|
| 256 |
+
|
| 257 |
+
if self.cell00 is not None:
|
| 258 |
+
line_number_colors = idleConf.GetHighlight(idleConf.CurrentTheme(),
|
| 259 |
+
'linenumber')
|
| 260 |
+
self.cell00.config(bg=line_number_colors['background'])
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
CodeContext.reload()
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
if __name__ == "__main__":
|
| 267 |
+
from unittest import main
|
| 268 |
+
main('idlelib.idle_test.test_codecontext', verbosity=2, exit=False)
|
| 269 |
+
|
| 270 |
+
# Add htest.
|
evalkit_tf446/lib/python3.10/idlelib/config-highlight.def
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle highlight theme settings.
|
| 3 |
+
|
| 4 |
+
[IDLE Classic]
|
| 5 |
+
normal-foreground= #000000
|
| 6 |
+
normal-background= #ffffff
|
| 7 |
+
keyword-foreground= #ff7700
|
| 8 |
+
keyword-background= #ffffff
|
| 9 |
+
builtin-foreground= #900090
|
| 10 |
+
builtin-background= #ffffff
|
| 11 |
+
comment-foreground= #dd0000
|
| 12 |
+
comment-background= #ffffff
|
| 13 |
+
string-foreground= #00aa00
|
| 14 |
+
string-background= #ffffff
|
| 15 |
+
definition-foreground= #0000ff
|
| 16 |
+
definition-background= #ffffff
|
| 17 |
+
hilite-foreground= #000000
|
| 18 |
+
hilite-background= gray
|
| 19 |
+
break-foreground= black
|
| 20 |
+
break-background= #ffff55
|
| 21 |
+
hit-foreground= #ffffff
|
| 22 |
+
hit-background= #000000
|
| 23 |
+
error-foreground= #000000
|
| 24 |
+
error-background= #ff7777
|
| 25 |
+
context-foreground= #000000
|
| 26 |
+
context-background= lightgray
|
| 27 |
+
linenumber-foreground= gray
|
| 28 |
+
linenumber-background= #ffffff
|
| 29 |
+
#cursor (only foreground can be set, restart IDLE)
|
| 30 |
+
cursor-foreground= black
|
| 31 |
+
#shell window
|
| 32 |
+
stdout-foreground= blue
|
| 33 |
+
stdout-background= #ffffff
|
| 34 |
+
stderr-foreground= red
|
| 35 |
+
stderr-background= #ffffff
|
| 36 |
+
console-foreground= #770000
|
| 37 |
+
console-background= #ffffff
|
| 38 |
+
|
| 39 |
+
[IDLE New]
|
| 40 |
+
normal-foreground= #000000
|
| 41 |
+
normal-background= #ffffff
|
| 42 |
+
keyword-foreground= #ff7700
|
| 43 |
+
keyword-background= #ffffff
|
| 44 |
+
builtin-foreground= #900090
|
| 45 |
+
builtin-background= #ffffff
|
| 46 |
+
comment-foreground= #dd0000
|
| 47 |
+
comment-background= #ffffff
|
| 48 |
+
string-foreground= #00aa00
|
| 49 |
+
string-background= #ffffff
|
| 50 |
+
definition-foreground= #0000ff
|
| 51 |
+
definition-background= #ffffff
|
| 52 |
+
hilite-foreground= #000000
|
| 53 |
+
hilite-background= gray
|
| 54 |
+
break-foreground= black
|
| 55 |
+
break-background= #ffff55
|
| 56 |
+
hit-foreground= #ffffff
|
| 57 |
+
hit-background= #000000
|
| 58 |
+
error-foreground= #000000
|
| 59 |
+
error-background= #ff7777
|
| 60 |
+
context-foreground= #000000
|
| 61 |
+
context-background= lightgray
|
| 62 |
+
linenumber-foreground= gray
|
| 63 |
+
linenumber-background= #ffffff
|
| 64 |
+
#cursor (only foreground can be set, restart IDLE)
|
| 65 |
+
cursor-foreground= black
|
| 66 |
+
#shell window
|
| 67 |
+
stdout-foreground= blue
|
| 68 |
+
stdout-background= #ffffff
|
| 69 |
+
stderr-foreground= red
|
| 70 |
+
stderr-background= #ffffff
|
| 71 |
+
console-foreground= #770000
|
| 72 |
+
console-background= #ffffff
|
| 73 |
+
|
| 74 |
+
[IDLE Dark]
|
| 75 |
+
comment-foreground = #dd0000
|
| 76 |
+
console-foreground = #ff4d4d
|
| 77 |
+
error-foreground = #FFFFFF
|
| 78 |
+
hilite-background = #7e7e7e
|
| 79 |
+
string-foreground = #02ff02
|
| 80 |
+
stderr-background = #002240
|
| 81 |
+
stderr-foreground = #ffb3b3
|
| 82 |
+
console-background = #002240
|
| 83 |
+
hit-background = #fbfbfb
|
| 84 |
+
string-background = #002240
|
| 85 |
+
normal-background = #002240
|
| 86 |
+
hilite-foreground = #FFFFFF
|
| 87 |
+
keyword-foreground = #ff8000
|
| 88 |
+
error-background = #c86464
|
| 89 |
+
keyword-background = #002240
|
| 90 |
+
builtin-background = #002240
|
| 91 |
+
break-background = #808000
|
| 92 |
+
builtin-foreground = #ff00ff
|
| 93 |
+
definition-foreground = #5e5eff
|
| 94 |
+
stdout-foreground = #c2d1fa
|
| 95 |
+
definition-background = #002240
|
| 96 |
+
normal-foreground = #FFFFFF
|
| 97 |
+
cursor-foreground = #ffffff
|
| 98 |
+
stdout-background = #002240
|
| 99 |
+
hit-foreground = #002240
|
| 100 |
+
comment-background = #002240
|
| 101 |
+
break-foreground = #FFFFFF
|
| 102 |
+
context-foreground= #ffffff
|
| 103 |
+
context-background= #454545
|
| 104 |
+
linenumber-foreground= gray
|
| 105 |
+
linenumber-background= #002240
|
evalkit_tf446/lib/python3.10/idlelib/config-keys.def
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle key binding settings.
|
| 3 |
+
# Where multiple keys are specified for an action: if they are separated
|
| 4 |
+
# by a space (eg. action=<key1> <key2>) then the keys are alternatives, if
|
| 5 |
+
# there is no space (eg. action=<key1><key2>) then the keys comprise a
|
| 6 |
+
# single 'emacs style' multi-keystoke binding. The tk event specifier 'Key'
|
| 7 |
+
# is used in all cases, for consistency in auto key conflict checking in the
|
| 8 |
+
# configuration gui.
|
| 9 |
+
|
| 10 |
+
[IDLE Classic Windows]
|
| 11 |
+
copy=<Control-Key-c> <Control-Key-C>
|
| 12 |
+
cut=<Control-Key-x> <Control-Key-X>
|
| 13 |
+
paste=<Control-Key-v> <Control-Key-V>
|
| 14 |
+
beginning-of-line= <Key-Home>
|
| 15 |
+
center-insert=<Control-Key-l> <Control-Key-L>
|
| 16 |
+
close-all-windows=<Control-Key-q> <Control-Key-Q>
|
| 17 |
+
close-window=<Alt-Key-F4> <Meta-Key-F4>
|
| 18 |
+
do-nothing=<Control-Key-F12>
|
| 19 |
+
end-of-file=<Control-Key-d> <Control-Key-D>
|
| 20 |
+
python-docs=<Key-F1>
|
| 21 |
+
python-context-help=<Shift-Key-F1>
|
| 22 |
+
history-next=<Alt-Key-n> <Meta-Key-n> <Alt-Key-N> <Meta-Key-N>
|
| 23 |
+
history-previous=<Alt-Key-p> <Meta-Key-p> <Alt-Key-P> <Meta-Key-P>
|
| 24 |
+
interrupt-execution=<Control-Key-c> <Control-Key-C>
|
| 25 |
+
view-restart=<Key-F6>
|
| 26 |
+
restart-shell=<Control-Key-F6>
|
| 27 |
+
open-class-browser=<Alt-Key-c> <Meta-Key-c> <Alt-Key-C> <Meta-Key-C>
|
| 28 |
+
open-module=<Alt-Key-m> <Meta-Key-m> <Alt-Key-M> <Meta-Key-M>
|
| 29 |
+
open-new-window=<Control-Key-n> <Control-Key-N>
|
| 30 |
+
open-window-from-file=<Control-Key-o> <Control-Key-O>
|
| 31 |
+
plain-newline-and-indent=<Control-Key-j> <Control-Key-J>
|
| 32 |
+
print-window=<Control-Key-p> <Control-Key-P>
|
| 33 |
+
redo=<Control-Shift-Key-Z> <Control-Shift-Key-z>
|
| 34 |
+
remove-selection=<Key-Escape>
|
| 35 |
+
save-copy-of-window-as-file=<Alt-Shift-Key-S> <Alt-Shift-Key-s>
|
| 36 |
+
save-window-as-file=<Control-Shift-Key-S> <Control-Shift-Key-s>
|
| 37 |
+
save-window=<Control-Key-s> <Control-Key-S>
|
| 38 |
+
select-all=<Control-Key-a> <Control-Key-A>
|
| 39 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 40 |
+
undo=<Control-Key-z> <Control-Key-Z>
|
| 41 |
+
find=<Control-Key-f> <Control-Key-F>
|
| 42 |
+
find-again=<Control-Key-g> <Key-F3> <Control-Key-G>
|
| 43 |
+
find-in-files=<Alt-Key-F3> <Meta-Key-F3>
|
| 44 |
+
find-selection=<Control-Key-F3>
|
| 45 |
+
replace=<Control-Key-h> <Control-Key-H>
|
| 46 |
+
goto-line=<Alt-Key-g> <Meta-Key-g> <Alt-Key-G> <Meta-Key-G>
|
| 47 |
+
smart-backspace=<Key-BackSpace>
|
| 48 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 49 |
+
smart-indent=<Key-Tab>
|
| 50 |
+
indent-region=<Control-Key-bracketright>
|
| 51 |
+
dedent-region=<Control-Key-bracketleft>
|
| 52 |
+
comment-region=<Alt-Key-3> <Meta-Key-3>
|
| 53 |
+
uncomment-region=<Alt-Key-4> <Meta-Key-4>
|
| 54 |
+
tabify-region=<Alt-Key-5> <Meta-Key-5>
|
| 55 |
+
untabify-region=<Alt-Key-6> <Meta-Key-6>
|
| 56 |
+
toggle-tabs=<Alt-Key-t> <Meta-Key-t> <Alt-Key-T> <Meta-Key-T>
|
| 57 |
+
change-indentwidth=<Alt-Key-u> <Meta-Key-u> <Alt-Key-U> <Meta-Key-U>
|
| 58 |
+
del-word-left=<Control-Key-BackSpace>
|
| 59 |
+
del-word-right=<Control-Key-Delete>
|
| 60 |
+
force-open-completions= <Control-Key-space>
|
| 61 |
+
expand-word= <Alt-Key-slash>
|
| 62 |
+
force-open-calltip= <Control-Key-backslash>
|
| 63 |
+
format-paragraph= <Alt-Key-q>
|
| 64 |
+
flash-paren= <Control-Key-0>
|
| 65 |
+
run-module= <Key-F5>
|
| 66 |
+
run-custom= <Shift-Key-F5>
|
| 67 |
+
check-module= <Alt-Key-x>
|
| 68 |
+
zoom-height= <Alt-Key-2>
|
| 69 |
+
|
| 70 |
+
[IDLE Classic Unix]
|
| 71 |
+
copy=<Alt-Key-w> <Meta-Key-w>
|
| 72 |
+
cut=<Control-Key-w>
|
| 73 |
+
paste=<Control-Key-y>
|
| 74 |
+
beginning-of-line=<Control-Key-a> <Key-Home>
|
| 75 |
+
center-insert=<Control-Key-l>
|
| 76 |
+
close-all-windows=<Control-Key-x><Control-Key-c>
|
| 77 |
+
close-window=<Control-Key-x><Control-Key-0>
|
| 78 |
+
do-nothing=<Control-Key-x>
|
| 79 |
+
end-of-file=<Control-Key-d>
|
| 80 |
+
history-next=<Alt-Key-n> <Meta-Key-n>
|
| 81 |
+
history-previous=<Alt-Key-p> <Meta-Key-p>
|
| 82 |
+
interrupt-execution=<Control-Key-c>
|
| 83 |
+
view-restart=<Key-F6>
|
| 84 |
+
restart-shell=<Control-Key-F6>
|
| 85 |
+
open-class-browser=<Control-Key-x><Control-Key-b>
|
| 86 |
+
open-module=<Control-Key-x><Control-Key-m>
|
| 87 |
+
open-new-window=<Control-Key-x><Control-Key-n>
|
| 88 |
+
open-window-from-file=<Control-Key-x><Control-Key-f>
|
| 89 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 90 |
+
print-window=<Control-x><Control-Key-p>
|
| 91 |
+
python-docs=<Control-Key-h>
|
| 92 |
+
python-context-help=<Control-Shift-Key-H>
|
| 93 |
+
redo=<Alt-Key-z> <Meta-Key-z>
|
| 94 |
+
remove-selection=<Key-Escape>
|
| 95 |
+
save-copy-of-window-as-file=<Control-Key-x><Control-Key-y>
|
| 96 |
+
save-window-as-file=<Control-Key-x><Control-Key-w>
|
| 97 |
+
save-window=<Control-Key-x><Control-Key-s>
|
| 98 |
+
select-all=<Alt-Key-a> <Meta-Key-a>
|
| 99 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 100 |
+
undo=<Control-Key-z>
|
| 101 |
+
find=<Control-Key-u><Control-Key-u><Control-Key-s>
|
| 102 |
+
find-again=<Control-Key-u><Control-Key-s>
|
| 103 |
+
find-in-files=<Alt-Key-s> <Meta-Key-s>
|
| 104 |
+
find-selection=<Control-Key-s>
|
| 105 |
+
replace=<Control-Key-r>
|
| 106 |
+
goto-line=<Alt-Key-g> <Meta-Key-g>
|
| 107 |
+
smart-backspace=<Key-BackSpace>
|
| 108 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 109 |
+
smart-indent=<Key-Tab>
|
| 110 |
+
indent-region=<Control-Key-bracketright>
|
| 111 |
+
dedent-region=<Control-Key-bracketleft>
|
| 112 |
+
comment-region=<Alt-Key-3>
|
| 113 |
+
uncomment-region=<Alt-Key-4>
|
| 114 |
+
tabify-region=<Alt-Key-5>
|
| 115 |
+
untabify-region=<Alt-Key-6>
|
| 116 |
+
toggle-tabs=<Alt-Key-t>
|
| 117 |
+
change-indentwidth=<Alt-Key-u>
|
| 118 |
+
del-word-left=<Alt-Key-BackSpace>
|
| 119 |
+
del-word-right=<Alt-Key-d>
|
| 120 |
+
force-open-completions= <Control-Key-space>
|
| 121 |
+
expand-word= <Alt-Key-slash>
|
| 122 |
+
force-open-calltip= <Control-Key-backslash>
|
| 123 |
+
format-paragraph= <Alt-Key-q>
|
| 124 |
+
flash-paren= <Control-Key-0>
|
| 125 |
+
run-module= <Key-F5>
|
| 126 |
+
run-custom= <Shift-Key-F5>
|
| 127 |
+
check-module= <Alt-Key-x>
|
| 128 |
+
zoom-height= <Alt-Key-2>
|
| 129 |
+
|
| 130 |
+
[IDLE Modern Unix]
|
| 131 |
+
copy = <Control-Shift-Key-C> <Control-Key-Insert>
|
| 132 |
+
cut = <Control-Key-x> <Shift-Key-Delete>
|
| 133 |
+
paste = <Control-Key-v> <Shift-Key-Insert>
|
| 134 |
+
beginning-of-line = <Key-Home>
|
| 135 |
+
center-insert = <Control-Key-l>
|
| 136 |
+
close-all-windows = <Control-Key-q>
|
| 137 |
+
close-window = <Control-Key-w> <Control-Shift-Key-W>
|
| 138 |
+
do-nothing = <Control-Key-F12>
|
| 139 |
+
end-of-file = <Control-Key-d>
|
| 140 |
+
history-next = <Alt-Key-n> <Meta-Key-n>
|
| 141 |
+
history-previous = <Alt-Key-p> <Meta-Key-p>
|
| 142 |
+
interrupt-execution = <Control-Key-c>
|
| 143 |
+
view-restart = <Key-F6>
|
| 144 |
+
restart-shell = <Control-Key-F6>
|
| 145 |
+
open-class-browser = <Control-Key-b>
|
| 146 |
+
open-module = <Control-Key-m>
|
| 147 |
+
open-new-window = <Control-Key-n>
|
| 148 |
+
open-window-from-file = <Control-Key-o>
|
| 149 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 150 |
+
print-window = <Control-Key-p>
|
| 151 |
+
python-context-help = <Shift-Key-F1>
|
| 152 |
+
python-docs = <Key-F1>
|
| 153 |
+
redo = <Control-Shift-Key-Z>
|
| 154 |
+
remove-selection = <Key-Escape>
|
| 155 |
+
save-copy-of-window-as-file = <Alt-Shift-Key-S>
|
| 156 |
+
save-window-as-file = <Control-Shift-Key-S>
|
| 157 |
+
save-window = <Control-Key-s>
|
| 158 |
+
select-all = <Control-Key-a>
|
| 159 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 160 |
+
undo = <Control-Key-z>
|
| 161 |
+
find = <Control-Key-f>
|
| 162 |
+
find-again = <Key-F3>
|
| 163 |
+
find-in-files = <Control-Shift-Key-f>
|
| 164 |
+
find-selection = <Control-Key-h>
|
| 165 |
+
replace = <Control-Key-r>
|
| 166 |
+
goto-line = <Control-Key-g>
|
| 167 |
+
smart-backspace = <Key-BackSpace>
|
| 168 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 169 |
+
smart-indent = <Key-Tab>
|
| 170 |
+
indent-region = <Control-Key-bracketright>
|
| 171 |
+
dedent-region = <Control-Key-bracketleft>
|
| 172 |
+
comment-region = <Control-Key-d>
|
| 173 |
+
uncomment-region = <Control-Shift-Key-D>
|
| 174 |
+
tabify-region = <Alt-Key-5>
|
| 175 |
+
untabify-region = <Alt-Key-6>
|
| 176 |
+
toggle-tabs = <Control-Key-T>
|
| 177 |
+
change-indentwidth = <Alt-Key-u>
|
| 178 |
+
del-word-left = <Control-Key-BackSpace>
|
| 179 |
+
del-word-right = <Control-Key-Delete>
|
| 180 |
+
force-open-completions= <Control-Key-space>
|
| 181 |
+
expand-word= <Alt-Key-slash>
|
| 182 |
+
force-open-calltip= <Control-Key-backslash>
|
| 183 |
+
format-paragraph= <Alt-Key-q>
|
| 184 |
+
flash-paren= <Control-Key-0>
|
| 185 |
+
run-module= <Key-F5>
|
| 186 |
+
run-custom= <Shift-Key-F5>
|
| 187 |
+
check-module= <Alt-Key-x>
|
| 188 |
+
zoom-height= <Alt-Key-2>
|
| 189 |
+
|
| 190 |
+
[IDLE Classic Mac]
|
| 191 |
+
copy=<Command-Key-c>
|
| 192 |
+
cut=<Command-Key-x>
|
| 193 |
+
paste=<Command-Key-v>
|
| 194 |
+
beginning-of-line= <Key-Home>
|
| 195 |
+
center-insert=<Control-Key-l>
|
| 196 |
+
close-all-windows=<Command-Key-q>
|
| 197 |
+
close-window=<Command-Key-w>
|
| 198 |
+
do-nothing=<Control-Key-F12>
|
| 199 |
+
end-of-file=<Control-Key-d>
|
| 200 |
+
python-docs=<Key-F1>
|
| 201 |
+
python-context-help=<Shift-Key-F1>
|
| 202 |
+
history-next=<Control-Key-n>
|
| 203 |
+
history-previous=<Control-Key-p>
|
| 204 |
+
interrupt-execution=<Control-Key-c>
|
| 205 |
+
view-restart=<Key-F6>
|
| 206 |
+
restart-shell=<Control-Key-F6>
|
| 207 |
+
open-class-browser=<Command-Key-b>
|
| 208 |
+
open-module=<Command-Key-m>
|
| 209 |
+
open-new-window=<Command-Key-n>
|
| 210 |
+
open-window-from-file=<Command-Key-o>
|
| 211 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 212 |
+
print-window=<Command-Key-p>
|
| 213 |
+
redo=<Shift-Command-Key-Z>
|
| 214 |
+
remove-selection=<Key-Escape>
|
| 215 |
+
save-window-as-file=<Shift-Command-Key-S>
|
| 216 |
+
save-window=<Command-Key-s>
|
| 217 |
+
save-copy-of-window-as-file=<Option-Command-Key-s>
|
| 218 |
+
select-all=<Command-Key-a>
|
| 219 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 220 |
+
undo=<Command-Key-z>
|
| 221 |
+
find=<Command-Key-f>
|
| 222 |
+
find-again=<Command-Key-g> <Key-F3>
|
| 223 |
+
find-in-files=<Command-Key-F3>
|
| 224 |
+
find-selection=<Shift-Command-Key-F3>
|
| 225 |
+
replace=<Command-Key-r>
|
| 226 |
+
goto-line=<Command-Key-j>
|
| 227 |
+
smart-backspace=<Key-BackSpace>
|
| 228 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 229 |
+
smart-indent=<Key-Tab>
|
| 230 |
+
indent-region=<Command-Key-bracketright>
|
| 231 |
+
dedent-region=<Command-Key-bracketleft>
|
| 232 |
+
comment-region=<Control-Key-3>
|
| 233 |
+
uncomment-region=<Control-Key-4>
|
| 234 |
+
tabify-region=<Control-Key-5>
|
| 235 |
+
untabify-region=<Control-Key-6>
|
| 236 |
+
toggle-tabs=<Control-Key-t>
|
| 237 |
+
change-indentwidth=<Control-Key-u>
|
| 238 |
+
del-word-left=<Control-Key-BackSpace>
|
| 239 |
+
del-word-right=<Control-Key-Delete>
|
| 240 |
+
force-open-completions= <Control-Key-space>
|
| 241 |
+
expand-word= <Option-Key-slash>
|
| 242 |
+
force-open-calltip= <Control-Key-backslash>
|
| 243 |
+
format-paragraph= <Option-Key-q>
|
| 244 |
+
flash-paren= <Control-Key-0>
|
| 245 |
+
run-module= <Key-F5>
|
| 246 |
+
run-custom= <Shift-Key-F5>
|
| 247 |
+
check-module= <Option-Key-x>
|
| 248 |
+
zoom-height= <Option-Key-0>
|
| 249 |
+
|
| 250 |
+
[IDLE Classic OSX]
|
| 251 |
+
toggle-tabs = <Control-Key-t>
|
| 252 |
+
interrupt-execution = <Control-Key-c>
|
| 253 |
+
untabify-region = <Control-Key-6>
|
| 254 |
+
remove-selection = <Key-Escape>
|
| 255 |
+
print-window = <Command-Key-p>
|
| 256 |
+
replace = <Command-Key-r>
|
| 257 |
+
goto-line = <Command-Key-j>
|
| 258 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 259 |
+
history-previous = <Control-Key-p>
|
| 260 |
+
beginning-of-line = <Control-Key-Left>
|
| 261 |
+
end-of-line = <Control-Key-Right>
|
| 262 |
+
comment-region = <Control-Key-3>
|
| 263 |
+
redo = <Shift-Command-Key-Z>
|
| 264 |
+
close-window = <Command-Key-w>
|
| 265 |
+
restart-shell = <Control-Key-F6>
|
| 266 |
+
save-window-as-file = <Shift-Command-Key-S>
|
| 267 |
+
close-all-windows = <Command-Key-q>
|
| 268 |
+
view-restart = <Key-F6>
|
| 269 |
+
tabify-region = <Control-Key-5>
|
| 270 |
+
find-again = <Command-Key-g> <Key-F3>
|
| 271 |
+
find = <Command-Key-f>
|
| 272 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 273 |
+
select-all = <Command-Key-a>
|
| 274 |
+
smart-backspace = <Key-BackSpace>
|
| 275 |
+
change-indentwidth = <Control-Key-u>
|
| 276 |
+
do-nothing = <Control-Key-F12>
|
| 277 |
+
smart-indent = <Key-Tab>
|
| 278 |
+
center-insert = <Control-Key-l>
|
| 279 |
+
history-next = <Control-Key-n>
|
| 280 |
+
del-word-right = <Option-Key-Delete>
|
| 281 |
+
undo = <Command-Key-z>
|
| 282 |
+
save-window = <Command-Key-s>
|
| 283 |
+
uncomment-region = <Control-Key-4>
|
| 284 |
+
cut = <Command-Key-x>
|
| 285 |
+
find-in-files = <Command-Key-F3>
|
| 286 |
+
dedent-region = <Command-Key-bracketleft>
|
| 287 |
+
copy = <Command-Key-c>
|
| 288 |
+
paste = <Command-Key-v>
|
| 289 |
+
indent-region = <Command-Key-bracketright>
|
| 290 |
+
del-word-left = <Option-Key-BackSpace> <Option-Command-Key-BackSpace>
|
| 291 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 292 |
+
end-of-file = <Control-Key-d>
|
| 293 |
+
open-class-browser = <Command-Key-b>
|
| 294 |
+
open-new-window = <Command-Key-n>
|
| 295 |
+
open-module = <Command-Key-m>
|
| 296 |
+
find-selection = <Shift-Command-Key-F3>
|
| 297 |
+
python-context-help = <Shift-Key-F1>
|
| 298 |
+
save-copy-of-window-as-file = <Option-Command-Key-s>
|
| 299 |
+
open-window-from-file = <Command-Key-o>
|
| 300 |
+
python-docs = <Key-F1>
|
| 301 |
+
force-open-completions= <Control-Key-space>
|
| 302 |
+
expand-word= <Option-Key-slash>
|
| 303 |
+
force-open-calltip= <Control-Key-backslash>
|
| 304 |
+
format-paragraph= <Option-Key-q>
|
| 305 |
+
flash-paren= <Control-Key-0>
|
| 306 |
+
run-module= <Key-F5>
|
| 307 |
+
run-custom= <Shift-Key-F5>
|
| 308 |
+
check-module= <Option-Key-x>
|
| 309 |
+
zoom-height= <Option-Key-0>
|
evalkit_tf446/lib/python3.10/idlelib/config-main.def
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for general idle settings.
|
| 3 |
+
#
|
| 4 |
+
# When IDLE starts, it will look in
|
| 5 |
+
# the following two sets of files, in order:
|
| 6 |
+
#
|
| 7 |
+
# default configuration files in idlelib
|
| 8 |
+
# --------------------------------------
|
| 9 |
+
# config-main.def default general config file
|
| 10 |
+
# config-extensions.def default extension config file
|
| 11 |
+
# config-highlight.def default highlighting config file
|
| 12 |
+
# config-keys.def default keybinding config file
|
| 13 |
+
#
|
| 14 |
+
# user configuration files in ~/.idlerc
|
| 15 |
+
# -------------------------------------
|
| 16 |
+
# config-main.cfg user general config file
|
| 17 |
+
# config-extensions.cfg user extension config file
|
| 18 |
+
# config-highlight.cfg user highlighting config file
|
| 19 |
+
# config-keys.cfg user keybinding config file
|
| 20 |
+
#
|
| 21 |
+
# On Windows, the default location of the home directory ('~' above)
|
| 22 |
+
# depends on the version. For Windows 10, it is C:\Users\<username>.
|
| 23 |
+
#
|
| 24 |
+
# Any options the user saves through the config dialog will be saved to
|
| 25 |
+
# the relevant user config file. Reverting any general or extension
|
| 26 |
+
# setting to the default causes that entry to be wiped from the user
|
| 27 |
+
# file and re-read from the default file. This rule applies to each
|
| 28 |
+
# item, except that the three editor font items are saved as a group.
|
| 29 |
+
#
|
| 30 |
+
# User highlighting themes and keybinding sets must have (section) names
|
| 31 |
+
# distinct from the default names. All items are added and saved as a
|
| 32 |
+
# group. They are retained unless specifically deleted within the config
|
| 33 |
+
# dialog. Choosing one of the default themes or keysets just applies the
|
| 34 |
+
# relevant settings from the default file.
|
| 35 |
+
#
|
| 36 |
+
# Additional help sources are listed in the [HelpFiles] section below
|
| 37 |
+
# and should be viewable by a web browser (or the Windows Help viewer in
|
| 38 |
+
# the case of .chm files). These sources will be listed on the Help
|
| 39 |
+
# menu. The pattern, and two examples, are:
|
| 40 |
+
#
|
| 41 |
+
# <sequence_number = menu item;/path/to/help/source>
|
| 42 |
+
# 1 = IDLE;C:/Programs/Python36/Lib/idlelib/help.html
|
| 43 |
+
# 2 = Pillow;https://pillow.readthedocs.io/en/latest/
|
| 44 |
+
#
|
| 45 |
+
# You can't use a semi-colon in a menu item or path. The path will be
|
| 46 |
+
# platform specific because of path separators, drive specs etc.
|
| 47 |
+
#
|
| 48 |
+
# The default files should not be edited except to add new sections to
|
| 49 |
+
# config-extensions.def for added extensions. The user files should be
|
| 50 |
+
# modified through the Settings dialog.
|
| 51 |
+
|
| 52 |
+
[General]
|
| 53 |
+
editor-on-startup= 0
|
| 54 |
+
autosave= 0
|
| 55 |
+
print-command-posix=lpr %%s
|
| 56 |
+
print-command-win=start /min notepad /p %%s
|
| 57 |
+
delete-exitfunc= 1
|
| 58 |
+
|
| 59 |
+
[EditorWindow]
|
| 60 |
+
width= 80
|
| 61 |
+
height= 40
|
| 62 |
+
cursor-blink= 1
|
| 63 |
+
font= TkFixedFont
|
| 64 |
+
# For TkFixedFont, the actual size and boldness are obtained from tk
|
| 65 |
+
# and override 10 and 0. See idlelib.config.IdleConf.GetFont
|
| 66 |
+
font-size= 10
|
| 67 |
+
font-bold= 0
|
| 68 |
+
encoding= none
|
| 69 |
+
line-numbers-default= 0
|
| 70 |
+
|
| 71 |
+
[PyShell]
|
| 72 |
+
auto-squeeze-min-lines= 50
|
| 73 |
+
|
| 74 |
+
[Indent]
|
| 75 |
+
use-spaces= 1
|
| 76 |
+
num-spaces= 4
|
| 77 |
+
|
| 78 |
+
[Theme]
|
| 79 |
+
default= 1
|
| 80 |
+
name= IDLE Classic
|
| 81 |
+
name2=
|
| 82 |
+
# name2 set in user config-main.cfg for themes added after 2015 Oct 1
|
| 83 |
+
|
| 84 |
+
[Keys]
|
| 85 |
+
default= 1
|
| 86 |
+
name=
|
| 87 |
+
name2=
|
| 88 |
+
# name2 set in user config-main.cfg for keys added after 2016 July 1
|
| 89 |
+
|
| 90 |
+
[History]
|
| 91 |
+
cyclic=1
|
| 92 |
+
|
| 93 |
+
[HelpFiles]
|
evalkit_tf446/lib/python3.10/idlelib/config.py
ADDED
|
@@ -0,0 +1,911 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
"""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?
|
evalkit_tf446/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)
|
evalkit_tf446/lib/python3.10/idlelib/delegator.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Delegator:
|
| 2 |
+
|
| 3 |
+
def __init__(self, delegate=None):
|
| 4 |
+
self.delegate = delegate
|
| 5 |
+
self.__cache = set()
|
| 6 |
+
# Cache is used to only remove added attributes
|
| 7 |
+
# when changing the delegate.
|
| 8 |
+
|
| 9 |
+
def __getattr__(self, name):
|
| 10 |
+
attr = getattr(self.delegate, name) # May raise AttributeError
|
| 11 |
+
setattr(self, name, attr)
|
| 12 |
+
self.__cache.add(name)
|
| 13 |
+
return attr
|
| 14 |
+
|
| 15 |
+
def resetcache(self):
|
| 16 |
+
"Removes added attributes while leaving original attributes."
|
| 17 |
+
# Function is really about resetting delegator dict
|
| 18 |
+
# to original state. Cache is just a means
|
| 19 |
+
for key in self.__cache:
|
| 20 |
+
try:
|
| 21 |
+
delattr(self, key)
|
| 22 |
+
except AttributeError:
|
| 23 |
+
pass
|
| 24 |
+
self.__cache.clear()
|
| 25 |
+
|
| 26 |
+
def setdelegate(self, delegate):
|
| 27 |
+
"Reset attributes and change delegate."
|
| 28 |
+
self.resetcache()
|
| 29 |
+
self.delegate = delegate
|
| 30 |
+
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
from unittest import main
|
| 33 |
+
main('idlelib.idle_test.test_delegator', verbosity=2)
|
evalkit_tf446/lib/python3.10/idlelib/editor.py
ADDED
|
@@ -0,0 +1,1683 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.abc
|
| 2 |
+
import importlib.util
|
| 3 |
+
import os
|
| 4 |
+
import platform
|
| 5 |
+
import re
|
| 6 |
+
import string
|
| 7 |
+
import sys
|
| 8 |
+
import tokenize
|
| 9 |
+
import traceback
|
| 10 |
+
import webbrowser
|
| 11 |
+
|
| 12 |
+
from tkinter import *
|
| 13 |
+
from tkinter.font import Font
|
| 14 |
+
from tkinter.ttk import Scrollbar
|
| 15 |
+
from tkinter import simpledialog
|
| 16 |
+
from tkinter import messagebox
|
| 17 |
+
|
| 18 |
+
from idlelib.config import idleConf
|
| 19 |
+
from idlelib import configdialog
|
| 20 |
+
from idlelib import grep
|
| 21 |
+
from idlelib import help
|
| 22 |
+
from idlelib import help_about
|
| 23 |
+
from idlelib import macosx
|
| 24 |
+
from idlelib.multicall import MultiCallCreator
|
| 25 |
+
from idlelib import pyparse
|
| 26 |
+
from idlelib import query
|
| 27 |
+
from idlelib import replace
|
| 28 |
+
from idlelib import search
|
| 29 |
+
from idlelib.tree import wheel_event
|
| 30 |
+
from idlelib.util import py_extensions
|
| 31 |
+
from idlelib import window
|
| 32 |
+
|
| 33 |
+
# The default tab setting for a Text widget, in average-width characters.
|
| 34 |
+
TK_TABWIDTH_DEFAULT = 8
|
| 35 |
+
_py_version = ' (%s)' % platform.python_version()
|
| 36 |
+
darwin = sys.platform == 'darwin'
|
| 37 |
+
|
| 38 |
+
def _sphinx_version():
|
| 39 |
+
"Format sys.version_info to produce the Sphinx version string used to install the chm docs"
|
| 40 |
+
major, minor, micro, level, serial = sys.version_info
|
| 41 |
+
release = '%s%s' % (major, minor)
|
| 42 |
+
release += '%s' % (micro,)
|
| 43 |
+
if level == 'candidate':
|
| 44 |
+
release += 'rc%s' % (serial,)
|
| 45 |
+
elif level != 'final':
|
| 46 |
+
release += '%s%s' % (level[0], serial)
|
| 47 |
+
return release
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class EditorWindow:
|
| 51 |
+
from idlelib.percolator import Percolator
|
| 52 |
+
from idlelib.colorizer import ColorDelegator, color_config
|
| 53 |
+
from idlelib.undo import UndoDelegator
|
| 54 |
+
from idlelib.iomenu import IOBinding, encoding
|
| 55 |
+
from idlelib import mainmenu
|
| 56 |
+
from idlelib.statusbar import MultiStatusBar
|
| 57 |
+
from idlelib.autocomplete import AutoComplete
|
| 58 |
+
from idlelib.autoexpand import AutoExpand
|
| 59 |
+
from idlelib.calltip import Calltip
|
| 60 |
+
from idlelib.codecontext import CodeContext
|
| 61 |
+
from idlelib.sidebar import LineNumbers
|
| 62 |
+
from idlelib.format import FormatParagraph, FormatRegion, Indents, Rstrip
|
| 63 |
+
from idlelib.parenmatch import ParenMatch
|
| 64 |
+
from idlelib.zoomheight import ZoomHeight
|
| 65 |
+
|
| 66 |
+
filesystemencoding = sys.getfilesystemencoding() # for file names
|
| 67 |
+
help_url = None
|
| 68 |
+
|
| 69 |
+
allow_code_context = True
|
| 70 |
+
allow_line_numbers = True
|
| 71 |
+
user_input_insert_tags = None
|
| 72 |
+
|
| 73 |
+
def __init__(self, flist=None, filename=None, key=None, root=None):
|
| 74 |
+
# Delay import: runscript imports pyshell imports EditorWindow.
|
| 75 |
+
from idlelib.runscript import ScriptBinding
|
| 76 |
+
|
| 77 |
+
if EditorWindow.help_url is None:
|
| 78 |
+
dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html')
|
| 79 |
+
if sys.platform.count('linux'):
|
| 80 |
+
# look for html docs in a couple of standard places
|
| 81 |
+
pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3]
|
| 82 |
+
if os.path.isdir('/var/www/html/python/'): # "python2" rpm
|
| 83 |
+
dochome = '/var/www/html/python/index.html'
|
| 84 |
+
else:
|
| 85 |
+
basepath = '/usr/share/doc/' # standard location
|
| 86 |
+
dochome = os.path.join(basepath, pyver,
|
| 87 |
+
'Doc', 'index.html')
|
| 88 |
+
elif sys.platform[:3] == 'win':
|
| 89 |
+
import winreg # Windows only, block only executed once.
|
| 90 |
+
docfile = ''
|
| 91 |
+
KEY = (rf"Software\Python\PythonCore\{sys.winver}"
|
| 92 |
+
r"\Help\Main Python Documentation")
|
| 93 |
+
try:
|
| 94 |
+
docfile = winreg.QueryValue(winreg.HKEY_CURRENT_USER, KEY)
|
| 95 |
+
except FileNotFoundError:
|
| 96 |
+
try:
|
| 97 |
+
docfile = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
|
| 98 |
+
KEY)
|
| 99 |
+
except FileNotFoundError:
|
| 100 |
+
pass
|
| 101 |
+
if os.path.isfile(docfile):
|
| 102 |
+
dochome = docfile
|
| 103 |
+
elif sys.platform == 'darwin':
|
| 104 |
+
# documentation may be stored inside a python framework
|
| 105 |
+
dochome = os.path.join(sys.base_prefix,
|
| 106 |
+
'Resources/English.lproj/Documentation/index.html')
|
| 107 |
+
dochome = os.path.normpath(dochome)
|
| 108 |
+
if os.path.isfile(dochome):
|
| 109 |
+
EditorWindow.help_url = dochome
|
| 110 |
+
if sys.platform == 'darwin':
|
| 111 |
+
# Safari requires real file:-URLs
|
| 112 |
+
EditorWindow.help_url = 'file://' + EditorWindow.help_url
|
| 113 |
+
else:
|
| 114 |
+
EditorWindow.help_url = ("https://docs.python.org/%d.%d/"
|
| 115 |
+
% sys.version_info[:2])
|
| 116 |
+
self.flist = flist
|
| 117 |
+
root = root or flist.root
|
| 118 |
+
self.root = root
|
| 119 |
+
self.menubar = Menu(root)
|
| 120 |
+
self.top = top = window.ListedToplevel(root, menu=self.menubar)
|
| 121 |
+
if flist:
|
| 122 |
+
self.tkinter_vars = flist.vars
|
| 123 |
+
#self.top.instance_dict makes flist.inversedict available to
|
| 124 |
+
#configdialog.py so it can access all EditorWindow instances
|
| 125 |
+
self.top.instance_dict = flist.inversedict
|
| 126 |
+
else:
|
| 127 |
+
self.tkinter_vars = {} # keys: Tkinter event names
|
| 128 |
+
# values: Tkinter variable instances
|
| 129 |
+
self.top.instance_dict = {}
|
| 130 |
+
self.recent_files_path = idleConf.userdir and os.path.join(
|
| 131 |
+
idleConf.userdir, 'recent-files.lst')
|
| 132 |
+
|
| 133 |
+
self.prompt_last_line = '' # Override in PyShell
|
| 134 |
+
self.text_frame = text_frame = Frame(top)
|
| 135 |
+
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
|
| 136 |
+
width = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 137 |
+
text_options = {
|
| 138 |
+
'name': 'text',
|
| 139 |
+
'padx': 5,
|
| 140 |
+
'wrap': 'none',
|
| 141 |
+
'highlightthickness': 0,
|
| 142 |
+
'width': width,
|
| 143 |
+
'tabstyle': 'wordprocessor', # new in 8.5
|
| 144 |
+
'height': idleConf.GetOption(
|
| 145 |
+
'main', 'EditorWindow', 'height', type='int'),
|
| 146 |
+
}
|
| 147 |
+
self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
|
| 148 |
+
self.top.focused_widget = self.text
|
| 149 |
+
|
| 150 |
+
self.createmenubar()
|
| 151 |
+
self.apply_bindings()
|
| 152 |
+
|
| 153 |
+
self.top.protocol("WM_DELETE_WINDOW", self.close)
|
| 154 |
+
self.top.bind("<<close-window>>", self.close_event)
|
| 155 |
+
if macosx.isAquaTk():
|
| 156 |
+
# Command-W on editor windows doesn't work without this.
|
| 157 |
+
text.bind('<<close-window>>', self.close_event)
|
| 158 |
+
# Some OS X systems have only one mouse button, so use
|
| 159 |
+
# control-click for popup context menus there. For two
|
| 160 |
+
# buttons, AquaTk defines <2> as the right button, not <3>.
|
| 161 |
+
text.bind("<Control-Button-1>",self.right_menu_event)
|
| 162 |
+
text.bind("<2>", self.right_menu_event)
|
| 163 |
+
else:
|
| 164 |
+
# Elsewhere, use right-click for popup menus.
|
| 165 |
+
text.bind("<3>",self.right_menu_event)
|
| 166 |
+
|
| 167 |
+
text.bind('<MouseWheel>', wheel_event)
|
| 168 |
+
text.bind('<Button-4>', wheel_event)
|
| 169 |
+
text.bind('<Button-5>', wheel_event)
|
| 170 |
+
text.bind('<Configure>', self.handle_winconfig)
|
| 171 |
+
text.bind("<<cut>>", self.cut)
|
| 172 |
+
text.bind("<<copy>>", self.copy)
|
| 173 |
+
text.bind("<<paste>>", self.paste)
|
| 174 |
+
text.bind("<<center-insert>>", self.center_insert_event)
|
| 175 |
+
text.bind("<<help>>", self.help_dialog)
|
| 176 |
+
text.bind("<<python-docs>>", self.python_docs)
|
| 177 |
+
text.bind("<<about-idle>>", self.about_dialog)
|
| 178 |
+
text.bind("<<open-config-dialog>>", self.config_dialog)
|
| 179 |
+
text.bind("<<open-module>>", self.open_module_event)
|
| 180 |
+
text.bind("<<do-nothing>>", lambda event: "break")
|
| 181 |
+
text.bind("<<select-all>>", self.select_all)
|
| 182 |
+
text.bind("<<remove-selection>>", self.remove_selection)
|
| 183 |
+
text.bind("<<find>>", self.find_event)
|
| 184 |
+
text.bind("<<find-again>>", self.find_again_event)
|
| 185 |
+
text.bind("<<find-in-files>>", self.find_in_files_event)
|
| 186 |
+
text.bind("<<find-selection>>", self.find_selection_event)
|
| 187 |
+
text.bind("<<replace>>", self.replace_event)
|
| 188 |
+
text.bind("<<goto-line>>", self.goto_line_event)
|
| 189 |
+
text.bind("<<smart-backspace>>",self.smart_backspace_event)
|
| 190 |
+
text.bind("<<newline-and-indent>>",self.newline_and_indent_event)
|
| 191 |
+
text.bind("<<smart-indent>>",self.smart_indent_event)
|
| 192 |
+
self.fregion = fregion = self.FormatRegion(self)
|
| 193 |
+
# self.fregion used in smart_indent_event to access indent_region.
|
| 194 |
+
text.bind("<<indent-region>>", fregion.indent_region_event)
|
| 195 |
+
text.bind("<<dedent-region>>", fregion.dedent_region_event)
|
| 196 |
+
text.bind("<<comment-region>>", fregion.comment_region_event)
|
| 197 |
+
text.bind("<<uncomment-region>>", fregion.uncomment_region_event)
|
| 198 |
+
text.bind("<<tabify-region>>", fregion.tabify_region_event)
|
| 199 |
+
text.bind("<<untabify-region>>", fregion.untabify_region_event)
|
| 200 |
+
indents = self.Indents(self)
|
| 201 |
+
text.bind("<<toggle-tabs>>", indents.toggle_tabs_event)
|
| 202 |
+
text.bind("<<change-indentwidth>>", indents.change_indentwidth_event)
|
| 203 |
+
text.bind("<Left>", self.move_at_edge_if_selection(0))
|
| 204 |
+
text.bind("<Right>", self.move_at_edge_if_selection(1))
|
| 205 |
+
text.bind("<<del-word-left>>", self.del_word_left)
|
| 206 |
+
text.bind("<<del-word-right>>", self.del_word_right)
|
| 207 |
+
text.bind("<<beginning-of-line>>", self.home_callback)
|
| 208 |
+
|
| 209 |
+
if flist:
|
| 210 |
+
flist.inversedict[self] = key
|
| 211 |
+
if key:
|
| 212 |
+
flist.dict[key] = self
|
| 213 |
+
text.bind("<<open-new-window>>", self.new_callback)
|
| 214 |
+
text.bind("<<close-all-windows>>", self.flist.close_all_callback)
|
| 215 |
+
text.bind("<<open-class-browser>>", self.open_module_browser)
|
| 216 |
+
text.bind("<<open-path-browser>>", self.open_path_browser)
|
| 217 |
+
text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
|
| 218 |
+
|
| 219 |
+
self.set_status_bar()
|
| 220 |
+
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
|
| 221 |
+
text_frame.rowconfigure(1, weight=1)
|
| 222 |
+
text_frame.columnconfigure(1, weight=1)
|
| 223 |
+
vbar['command'] = self.handle_yview
|
| 224 |
+
vbar.grid(row=1, column=2, sticky=NSEW)
|
| 225 |
+
text['yscrollcommand'] = vbar.set
|
| 226 |
+
text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow')
|
| 227 |
+
text.grid(row=1, column=1, sticky=NSEW)
|
| 228 |
+
text.focus_set()
|
| 229 |
+
self.set_width()
|
| 230 |
+
|
| 231 |
+
# usetabs true -> literal tab characters are used by indent and
|
| 232 |
+
# dedent cmds, possibly mixed with spaces if
|
| 233 |
+
# indentwidth is not a multiple of tabwidth,
|
| 234 |
+
# which will cause Tabnanny to nag!
|
| 235 |
+
# false -> tab characters are converted to spaces by indent
|
| 236 |
+
# and dedent cmds, and ditto TAB keystrokes
|
| 237 |
+
# Although use-spaces=0 can be configured manually in config-main.def,
|
| 238 |
+
# configuration of tabs v. spaces is not supported in the configuration
|
| 239 |
+
# dialog. IDLE promotes the preferred Python indentation: use spaces!
|
| 240 |
+
usespaces = idleConf.GetOption('main', 'Indent',
|
| 241 |
+
'use-spaces', type='bool')
|
| 242 |
+
self.usetabs = not usespaces
|
| 243 |
+
|
| 244 |
+
# tabwidth is the display width of a literal tab character.
|
| 245 |
+
# CAUTION: telling Tk to use anything other than its default
|
| 246 |
+
# tab setting causes it to use an entirely different tabbing algorithm,
|
| 247 |
+
# treating tab stops as fixed distances from the left margin.
|
| 248 |
+
# Nobody expects this, so for now tabwidth should never be changed.
|
| 249 |
+
self.tabwidth = 8 # must remain 8 until Tk is fixed.
|
| 250 |
+
|
| 251 |
+
# indentwidth is the number of screen characters per indent level.
|
| 252 |
+
# The recommended Python indentation is four spaces.
|
| 253 |
+
self.indentwidth = self.tabwidth
|
| 254 |
+
self.set_notabs_indentwidth()
|
| 255 |
+
|
| 256 |
+
# Store the current value of the insertofftime now so we can restore
|
| 257 |
+
# it if needed.
|
| 258 |
+
if not hasattr(idleConf, 'blink_off_time'):
|
| 259 |
+
idleConf.blink_off_time = self.text['insertofftime']
|
| 260 |
+
self.update_cursor_blink()
|
| 261 |
+
|
| 262 |
+
# When searching backwards for a reliable place to begin parsing,
|
| 263 |
+
# first start num_context_lines[0] lines back, then
|
| 264 |
+
# num_context_lines[1] lines back if that didn't work, and so on.
|
| 265 |
+
# The last value should be huge (larger than the # of lines in a
|
| 266 |
+
# conceivable file).
|
| 267 |
+
# Making the initial values larger slows things down more often.
|
| 268 |
+
self.num_context_lines = 50, 500, 5000000
|
| 269 |
+
self.per = per = self.Percolator(text)
|
| 270 |
+
self.undo = undo = self.UndoDelegator()
|
| 271 |
+
per.insertfilter(undo)
|
| 272 |
+
text.undo_block_start = undo.undo_block_start
|
| 273 |
+
text.undo_block_stop = undo.undo_block_stop
|
| 274 |
+
undo.set_saved_change_hook(self.saved_change_hook)
|
| 275 |
+
# IOBinding implements file I/O and printing functionality
|
| 276 |
+
self.io = io = self.IOBinding(self)
|
| 277 |
+
io.set_filename_change_hook(self.filename_change_hook)
|
| 278 |
+
self.good_load = False
|
| 279 |
+
self.set_indentation_params(False)
|
| 280 |
+
self.color = None # initialized below in self.ResetColorizer
|
| 281 |
+
self.code_context = None # optionally initialized later below
|
| 282 |
+
self.line_numbers = None # optionally initialized later below
|
| 283 |
+
if filename:
|
| 284 |
+
if os.path.exists(filename) and not os.path.isdir(filename):
|
| 285 |
+
if io.loadfile(filename):
|
| 286 |
+
self.good_load = True
|
| 287 |
+
is_py_src = self.ispythonsource(filename)
|
| 288 |
+
self.set_indentation_params(is_py_src)
|
| 289 |
+
else:
|
| 290 |
+
io.set_filename(filename)
|
| 291 |
+
self.good_load = True
|
| 292 |
+
|
| 293 |
+
self.ResetColorizer()
|
| 294 |
+
self.saved_change_hook()
|
| 295 |
+
self.update_recent_files_list()
|
| 296 |
+
self.load_extensions()
|
| 297 |
+
menu = self.menudict.get('window')
|
| 298 |
+
if menu:
|
| 299 |
+
end = menu.index("end")
|
| 300 |
+
if end is None:
|
| 301 |
+
end = -1
|
| 302 |
+
if end >= 0:
|
| 303 |
+
menu.add_separator()
|
| 304 |
+
end = end + 1
|
| 305 |
+
self.wmenu_end = end
|
| 306 |
+
window.register_callback(self.postwindowsmenu)
|
| 307 |
+
|
| 308 |
+
# Some abstractions so IDLE extensions are cross-IDE
|
| 309 |
+
self.askinteger = simpledialog.askinteger
|
| 310 |
+
self.askyesno = messagebox.askyesno
|
| 311 |
+
self.showerror = messagebox.showerror
|
| 312 |
+
|
| 313 |
+
# Add pseudoevents for former extension fixed keys.
|
| 314 |
+
# (This probably needs to be done once in the process.)
|
| 315 |
+
text.event_add('<<autocomplete>>', '<Key-Tab>')
|
| 316 |
+
text.event_add('<<try-open-completions>>', '<KeyRelease-period>',
|
| 317 |
+
'<KeyRelease-slash>', '<KeyRelease-backslash>')
|
| 318 |
+
text.event_add('<<try-open-calltip>>', '<KeyRelease-parenleft>')
|
| 319 |
+
text.event_add('<<refresh-calltip>>', '<KeyRelease-parenright>')
|
| 320 |
+
text.event_add('<<paren-closed>>', '<KeyRelease-parenright>',
|
| 321 |
+
'<KeyRelease-bracketright>', '<KeyRelease-braceright>')
|
| 322 |
+
|
| 323 |
+
# Former extension bindings depends on frame.text being packed
|
| 324 |
+
# (called from self.ResetColorizer()).
|
| 325 |
+
autocomplete = self.AutoComplete(self, self.user_input_insert_tags)
|
| 326 |
+
text.bind("<<autocomplete>>", autocomplete.autocomplete_event)
|
| 327 |
+
text.bind("<<try-open-completions>>",
|
| 328 |
+
autocomplete.try_open_completions_event)
|
| 329 |
+
text.bind("<<force-open-completions>>",
|
| 330 |
+
autocomplete.force_open_completions_event)
|
| 331 |
+
text.bind("<<expand-word>>", self.AutoExpand(self).expand_word_event)
|
| 332 |
+
text.bind("<<format-paragraph>>",
|
| 333 |
+
self.FormatParagraph(self).format_paragraph_event)
|
| 334 |
+
parenmatch = self.ParenMatch(self)
|
| 335 |
+
text.bind("<<flash-paren>>", parenmatch.flash_paren_event)
|
| 336 |
+
text.bind("<<paren-closed>>", parenmatch.paren_closed_event)
|
| 337 |
+
scriptbinding = ScriptBinding(self)
|
| 338 |
+
text.bind("<<check-module>>", scriptbinding.check_module_event)
|
| 339 |
+
text.bind("<<run-module>>", scriptbinding.run_module_event)
|
| 340 |
+
text.bind("<<run-custom>>", scriptbinding.run_custom_event)
|
| 341 |
+
text.bind("<<do-rstrip>>", self.Rstrip(self).do_rstrip)
|
| 342 |
+
self.ctip = ctip = self.Calltip(self)
|
| 343 |
+
text.bind("<<try-open-calltip>>", ctip.try_open_calltip_event)
|
| 344 |
+
#refresh-calltip must come after paren-closed to work right
|
| 345 |
+
text.bind("<<refresh-calltip>>", ctip.refresh_calltip_event)
|
| 346 |
+
text.bind("<<force-open-calltip>>", ctip.force_open_calltip_event)
|
| 347 |
+
text.bind("<<zoom-height>>", self.ZoomHeight(self).zoom_height_event)
|
| 348 |
+
if self.allow_code_context:
|
| 349 |
+
self.code_context = self.CodeContext(self)
|
| 350 |
+
text.bind("<<toggle-code-context>>",
|
| 351 |
+
self.code_context.toggle_code_context_event)
|
| 352 |
+
else:
|
| 353 |
+
self.update_menu_state('options', '*ode*ontext', 'disabled')
|
| 354 |
+
if self.allow_line_numbers:
|
| 355 |
+
self.line_numbers = self.LineNumbers(self)
|
| 356 |
+
if idleConf.GetOption('main', 'EditorWindow',
|
| 357 |
+
'line-numbers-default', type='bool'):
|
| 358 |
+
self.toggle_line_numbers_event()
|
| 359 |
+
text.bind("<<toggle-line-numbers>>", self.toggle_line_numbers_event)
|
| 360 |
+
else:
|
| 361 |
+
self.update_menu_state('options', '*ine*umbers', 'disabled')
|
| 362 |
+
|
| 363 |
+
def handle_winconfig(self, event=None):
|
| 364 |
+
self.set_width()
|
| 365 |
+
|
| 366 |
+
def set_width(self):
|
| 367 |
+
text = self.text
|
| 368 |
+
inner_padding = sum(map(text.tk.getint, [text.cget('border'),
|
| 369 |
+
text.cget('padx')]))
|
| 370 |
+
pixel_width = text.winfo_width() - 2 * inner_padding
|
| 371 |
+
|
| 372 |
+
# Divide the width of the Text widget by the font width,
|
| 373 |
+
# which is taken to be the width of '0' (zero).
|
| 374 |
+
# http://www.tcl.tk/man/tcl8.6/TkCmd/text.htm#M21
|
| 375 |
+
zero_char_width = \
|
| 376 |
+
Font(text, font=text.cget('font')).measure('0')
|
| 377 |
+
self.width = pixel_width // zero_char_width
|
| 378 |
+
|
| 379 |
+
def new_callback(self, event):
|
| 380 |
+
dirname, basename = self.io.defaultfilename()
|
| 381 |
+
self.flist.new(dirname)
|
| 382 |
+
return "break"
|
| 383 |
+
|
| 384 |
+
def home_callback(self, event):
|
| 385 |
+
if (event.state & 4) != 0 and event.keysym == "Home":
|
| 386 |
+
# state&4==Control. If <Control-Home>, use the Tk binding.
|
| 387 |
+
return None
|
| 388 |
+
if self.text.index("iomark") and \
|
| 389 |
+
self.text.compare("iomark", "<=", "insert lineend") and \
|
| 390 |
+
self.text.compare("insert linestart", "<=", "iomark"):
|
| 391 |
+
# In Shell on input line, go to just after prompt
|
| 392 |
+
insertpt = int(self.text.index("iomark").split(".")[1])
|
| 393 |
+
else:
|
| 394 |
+
line = self.text.get("insert linestart", "insert lineend")
|
| 395 |
+
for insertpt in range(len(line)):
|
| 396 |
+
if line[insertpt] not in (' ','\t'):
|
| 397 |
+
break
|
| 398 |
+
else:
|
| 399 |
+
insertpt=len(line)
|
| 400 |
+
lineat = int(self.text.index("insert").split('.')[1])
|
| 401 |
+
if insertpt == lineat:
|
| 402 |
+
insertpt = 0
|
| 403 |
+
dest = "insert linestart+"+str(insertpt)+"c"
|
| 404 |
+
if (event.state&1) == 0:
|
| 405 |
+
# shift was not pressed
|
| 406 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 407 |
+
else:
|
| 408 |
+
if not self.text.index("sel.first"):
|
| 409 |
+
# there was no previous selection
|
| 410 |
+
self.text.mark_set("my_anchor", "insert")
|
| 411 |
+
else:
|
| 412 |
+
if self.text.compare(self.text.index("sel.first"), "<",
|
| 413 |
+
self.text.index("insert")):
|
| 414 |
+
self.text.mark_set("my_anchor", "sel.first") # extend back
|
| 415 |
+
else:
|
| 416 |
+
self.text.mark_set("my_anchor", "sel.last") # extend forward
|
| 417 |
+
first = self.text.index(dest)
|
| 418 |
+
last = self.text.index("my_anchor")
|
| 419 |
+
if self.text.compare(first,">",last):
|
| 420 |
+
first,last = last,first
|
| 421 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 422 |
+
self.text.tag_add("sel", first, last)
|
| 423 |
+
self.text.mark_set("insert", dest)
|
| 424 |
+
self.text.see("insert")
|
| 425 |
+
return "break"
|
| 426 |
+
|
| 427 |
+
def set_status_bar(self):
|
| 428 |
+
self.status_bar = self.MultiStatusBar(self.top)
|
| 429 |
+
sep = Frame(self.top, height=1, borderwidth=1, background='grey75')
|
| 430 |
+
if sys.platform == "darwin":
|
| 431 |
+
# Insert some padding to avoid obscuring some of the statusbar
|
| 432 |
+
# by the resize widget.
|
| 433 |
+
self.status_bar.set_label('_padding1', ' ', side=RIGHT)
|
| 434 |
+
self.status_bar.set_label('column', 'Col: ?', side=RIGHT)
|
| 435 |
+
self.status_bar.set_label('line', 'Ln: ?', side=RIGHT)
|
| 436 |
+
self.status_bar.pack(side=BOTTOM, fill=X)
|
| 437 |
+
sep.pack(side=BOTTOM, fill=X)
|
| 438 |
+
self.text.bind("<<set-line-and-column>>", self.set_line_and_column)
|
| 439 |
+
self.text.event_add("<<set-line-and-column>>",
|
| 440 |
+
"<KeyRelease>", "<ButtonRelease>")
|
| 441 |
+
self.text.after_idle(self.set_line_and_column)
|
| 442 |
+
|
| 443 |
+
def set_line_and_column(self, event=None):
|
| 444 |
+
line, column = self.text.index(INSERT).split('.')
|
| 445 |
+
self.status_bar.set_label('column', 'Col: %s' % column)
|
| 446 |
+
self.status_bar.set_label('line', 'Ln: %s' % line)
|
| 447 |
+
|
| 448 |
+
menu_specs = [
|
| 449 |
+
("file", "_File"),
|
| 450 |
+
("edit", "_Edit"),
|
| 451 |
+
("format", "F_ormat"),
|
| 452 |
+
("run", "_Run"),
|
| 453 |
+
("options", "_Options"),
|
| 454 |
+
("window", "_Window"),
|
| 455 |
+
("help", "_Help"),
|
| 456 |
+
]
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
def createmenubar(self):
|
| 460 |
+
mbar = self.menubar
|
| 461 |
+
self.menudict = menudict = {}
|
| 462 |
+
for name, label in self.menu_specs:
|
| 463 |
+
underline, label = prepstr(label)
|
| 464 |
+
postcommand = getattr(self, f'{name}_menu_postcommand', None)
|
| 465 |
+
menudict[name] = menu = Menu(mbar, name=name, tearoff=0,
|
| 466 |
+
postcommand=postcommand)
|
| 467 |
+
mbar.add_cascade(label=label, menu=menu, underline=underline)
|
| 468 |
+
if macosx.isCarbonTk():
|
| 469 |
+
# Insert the application menu
|
| 470 |
+
menudict['application'] = menu = Menu(mbar, name='apple',
|
| 471 |
+
tearoff=0)
|
| 472 |
+
mbar.add_cascade(label='IDLE', menu=menu)
|
| 473 |
+
self.fill_menus()
|
| 474 |
+
self.recent_files_menu = Menu(self.menubar, tearoff=0)
|
| 475 |
+
self.menudict['file'].insert_cascade(3, label='Recent Files',
|
| 476 |
+
underline=0,
|
| 477 |
+
menu=self.recent_files_menu)
|
| 478 |
+
self.base_helpmenu_length = self.menudict['help'].index(END)
|
| 479 |
+
self.reset_help_menu_entries()
|
| 480 |
+
|
| 481 |
+
def postwindowsmenu(self):
|
| 482 |
+
# Only called when Window menu exists
|
| 483 |
+
menu = self.menudict['window']
|
| 484 |
+
end = menu.index("end")
|
| 485 |
+
if end is None:
|
| 486 |
+
end = -1
|
| 487 |
+
if end > self.wmenu_end:
|
| 488 |
+
menu.delete(self.wmenu_end+1, end)
|
| 489 |
+
window.add_windows_to_menu(menu)
|
| 490 |
+
|
| 491 |
+
def update_menu_label(self, menu, index, label):
|
| 492 |
+
"Update label for menu item at index."
|
| 493 |
+
menuitem = self.menudict[menu]
|
| 494 |
+
menuitem.entryconfig(index, label=label)
|
| 495 |
+
|
| 496 |
+
def update_menu_state(self, menu, index, state):
|
| 497 |
+
"Update state for menu item at index."
|
| 498 |
+
menuitem = self.menudict[menu]
|
| 499 |
+
menuitem.entryconfig(index, state=state)
|
| 500 |
+
|
| 501 |
+
def handle_yview(self, event, *args):
|
| 502 |
+
"Handle scrollbar."
|
| 503 |
+
if event == 'moveto':
|
| 504 |
+
fraction = float(args[0])
|
| 505 |
+
lines = (round(self.getlineno('end') * fraction) -
|
| 506 |
+
self.getlineno('@0,0'))
|
| 507 |
+
event = 'scroll'
|
| 508 |
+
args = (lines, 'units')
|
| 509 |
+
self.text.yview(event, *args)
|
| 510 |
+
return 'break'
|
| 511 |
+
|
| 512 |
+
rmenu = None
|
| 513 |
+
|
| 514 |
+
def right_menu_event(self, event):
|
| 515 |
+
text = self.text
|
| 516 |
+
newdex = text.index(f'@{event.x},{event.y}')
|
| 517 |
+
try:
|
| 518 |
+
in_selection = (text.compare('sel.first', '<=', newdex) and
|
| 519 |
+
text.compare(newdex, '<=', 'sel.last'))
|
| 520 |
+
except TclError:
|
| 521 |
+
in_selection = False
|
| 522 |
+
if not in_selection:
|
| 523 |
+
text.tag_remove("sel", "1.0", "end")
|
| 524 |
+
text.mark_set("insert", newdex)
|
| 525 |
+
if not self.rmenu:
|
| 526 |
+
self.make_rmenu()
|
| 527 |
+
rmenu = self.rmenu
|
| 528 |
+
self.event = event
|
| 529 |
+
iswin = sys.platform[:3] == 'win'
|
| 530 |
+
if iswin:
|
| 531 |
+
text.config(cursor="arrow")
|
| 532 |
+
|
| 533 |
+
for item in self.rmenu_specs:
|
| 534 |
+
try:
|
| 535 |
+
label, eventname, verify_state = item
|
| 536 |
+
except ValueError: # see issue1207589
|
| 537 |
+
continue
|
| 538 |
+
|
| 539 |
+
if verify_state is None:
|
| 540 |
+
continue
|
| 541 |
+
state = getattr(self, verify_state)()
|
| 542 |
+
rmenu.entryconfigure(label, state=state)
|
| 543 |
+
|
| 544 |
+
rmenu.tk_popup(event.x_root, event.y_root)
|
| 545 |
+
if iswin:
|
| 546 |
+
self.text.config(cursor="ibeam")
|
| 547 |
+
return "break"
|
| 548 |
+
|
| 549 |
+
rmenu_specs = [
|
| 550 |
+
# ("Label", "<<virtual-event>>", "statefuncname"), ...
|
| 551 |
+
("Close", "<<close-window>>", None), # Example
|
| 552 |
+
]
|
| 553 |
+
|
| 554 |
+
def make_rmenu(self):
|
| 555 |
+
rmenu = Menu(self.text, tearoff=0)
|
| 556 |
+
for item in self.rmenu_specs:
|
| 557 |
+
label, eventname = item[0], item[1]
|
| 558 |
+
if label is not None:
|
| 559 |
+
def command(text=self.text, eventname=eventname):
|
| 560 |
+
text.event_generate(eventname)
|
| 561 |
+
rmenu.add_command(label=label, command=command)
|
| 562 |
+
else:
|
| 563 |
+
rmenu.add_separator()
|
| 564 |
+
self.rmenu = rmenu
|
| 565 |
+
|
| 566 |
+
def rmenu_check_cut(self):
|
| 567 |
+
return self.rmenu_check_copy()
|
| 568 |
+
|
| 569 |
+
def rmenu_check_copy(self):
|
| 570 |
+
try:
|
| 571 |
+
indx = self.text.index('sel.first')
|
| 572 |
+
except TclError:
|
| 573 |
+
return 'disabled'
|
| 574 |
+
else:
|
| 575 |
+
return 'normal' if indx else 'disabled'
|
| 576 |
+
|
| 577 |
+
def rmenu_check_paste(self):
|
| 578 |
+
try:
|
| 579 |
+
self.text.tk.call('tk::GetSelection', self.text, 'CLIPBOARD')
|
| 580 |
+
except TclError:
|
| 581 |
+
return 'disabled'
|
| 582 |
+
else:
|
| 583 |
+
return 'normal'
|
| 584 |
+
|
| 585 |
+
def about_dialog(self, event=None):
|
| 586 |
+
"Handle Help 'About IDLE' event."
|
| 587 |
+
# Synchronize with macosx.overrideRootMenu.about_dialog.
|
| 588 |
+
help_about.AboutDialog(self.top)
|
| 589 |
+
return "break"
|
| 590 |
+
|
| 591 |
+
def config_dialog(self, event=None):
|
| 592 |
+
"Handle Options 'Configure IDLE' event."
|
| 593 |
+
# Synchronize with macosx.overrideRootMenu.config_dialog.
|
| 594 |
+
configdialog.ConfigDialog(self.top,'Settings')
|
| 595 |
+
return "break"
|
| 596 |
+
|
| 597 |
+
def help_dialog(self, event=None):
|
| 598 |
+
"Handle Help 'IDLE Help' event."
|
| 599 |
+
# Synchronize with macosx.overrideRootMenu.help_dialog.
|
| 600 |
+
if self.root:
|
| 601 |
+
parent = self.root
|
| 602 |
+
else:
|
| 603 |
+
parent = self.top
|
| 604 |
+
help.show_idlehelp(parent)
|
| 605 |
+
return "break"
|
| 606 |
+
|
| 607 |
+
def python_docs(self, event=None):
|
| 608 |
+
if sys.platform[:3] == 'win':
|
| 609 |
+
try:
|
| 610 |
+
os.startfile(self.help_url)
|
| 611 |
+
except OSError as why:
|
| 612 |
+
messagebox.showerror(title='Document Start Failure',
|
| 613 |
+
message=str(why), parent=self.text)
|
| 614 |
+
else:
|
| 615 |
+
webbrowser.open(self.help_url)
|
| 616 |
+
return "break"
|
| 617 |
+
|
| 618 |
+
def cut(self,event):
|
| 619 |
+
self.text.event_generate("<<Cut>>")
|
| 620 |
+
return "break"
|
| 621 |
+
|
| 622 |
+
def copy(self,event):
|
| 623 |
+
if not self.text.tag_ranges("sel"):
|
| 624 |
+
# There is no selection, so do nothing and maybe interrupt.
|
| 625 |
+
return None
|
| 626 |
+
self.text.event_generate("<<Copy>>")
|
| 627 |
+
return "break"
|
| 628 |
+
|
| 629 |
+
def paste(self,event):
|
| 630 |
+
self.text.event_generate("<<Paste>>")
|
| 631 |
+
self.text.see("insert")
|
| 632 |
+
return "break"
|
| 633 |
+
|
| 634 |
+
def select_all(self, event=None):
|
| 635 |
+
self.text.tag_add("sel", "1.0", "end-1c")
|
| 636 |
+
self.text.mark_set("insert", "1.0")
|
| 637 |
+
self.text.see("insert")
|
| 638 |
+
return "break"
|
| 639 |
+
|
| 640 |
+
def remove_selection(self, event=None):
|
| 641 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 642 |
+
self.text.see("insert")
|
| 643 |
+
return "break"
|
| 644 |
+
|
| 645 |
+
def move_at_edge_if_selection(self, edge_index):
|
| 646 |
+
"""Cursor move begins at start or end of selection
|
| 647 |
+
|
| 648 |
+
When a left/right cursor key is pressed create and return to Tkinter a
|
| 649 |
+
function which causes a cursor move from the associated edge of the
|
| 650 |
+
selection.
|
| 651 |
+
|
| 652 |
+
"""
|
| 653 |
+
self_text_index = self.text.index
|
| 654 |
+
self_text_mark_set = self.text.mark_set
|
| 655 |
+
edges_table = ("sel.first+1c", "sel.last-1c")
|
| 656 |
+
def move_at_edge(event):
|
| 657 |
+
if (event.state & 5) == 0: # no shift(==1) or control(==4) pressed
|
| 658 |
+
try:
|
| 659 |
+
self_text_index("sel.first")
|
| 660 |
+
self_text_mark_set("insert", edges_table[edge_index])
|
| 661 |
+
except TclError:
|
| 662 |
+
pass
|
| 663 |
+
return move_at_edge
|
| 664 |
+
|
| 665 |
+
def del_word_left(self, event):
|
| 666 |
+
self.text.event_generate('<Meta-Delete>')
|
| 667 |
+
return "break"
|
| 668 |
+
|
| 669 |
+
def del_word_right(self, event):
|
| 670 |
+
self.text.event_generate('<Meta-d>')
|
| 671 |
+
return "break"
|
| 672 |
+
|
| 673 |
+
def find_event(self, event):
|
| 674 |
+
search.find(self.text)
|
| 675 |
+
return "break"
|
| 676 |
+
|
| 677 |
+
def find_again_event(self, event):
|
| 678 |
+
search.find_again(self.text)
|
| 679 |
+
return "break"
|
| 680 |
+
|
| 681 |
+
def find_selection_event(self, event):
|
| 682 |
+
search.find_selection(self.text)
|
| 683 |
+
return "break"
|
| 684 |
+
|
| 685 |
+
def find_in_files_event(self, event):
|
| 686 |
+
grep.grep(self.text, self.io, self.flist)
|
| 687 |
+
return "break"
|
| 688 |
+
|
| 689 |
+
def replace_event(self, event):
|
| 690 |
+
replace.replace(self.text)
|
| 691 |
+
return "break"
|
| 692 |
+
|
| 693 |
+
def goto_line_event(self, event):
|
| 694 |
+
text = self.text
|
| 695 |
+
lineno = query.Goto(
|
| 696 |
+
text, "Go To Line",
|
| 697 |
+
"Enter a positive integer\n"
|
| 698 |
+
"('big' = end of file):"
|
| 699 |
+
).result
|
| 700 |
+
if lineno is not None:
|
| 701 |
+
text.tag_remove("sel", "1.0", "end")
|
| 702 |
+
text.mark_set("insert", f'{lineno}.0')
|
| 703 |
+
text.see("insert")
|
| 704 |
+
self.set_line_and_column()
|
| 705 |
+
return "break"
|
| 706 |
+
|
| 707 |
+
def open_module(self):
|
| 708 |
+
"""Get module name from user and open it.
|
| 709 |
+
|
| 710 |
+
Return module path or None for calls by open_module_browser
|
| 711 |
+
when latter is not invoked in named editor window.
|
| 712 |
+
"""
|
| 713 |
+
# XXX This, open_module_browser, and open_path_browser
|
| 714 |
+
# would fit better in iomenu.IOBinding.
|
| 715 |
+
try:
|
| 716 |
+
name = self.text.get("sel.first", "sel.last").strip()
|
| 717 |
+
except TclError:
|
| 718 |
+
name = ''
|
| 719 |
+
file_path = query.ModuleName(
|
| 720 |
+
self.text, "Open Module",
|
| 721 |
+
"Enter the name of a Python module\n"
|
| 722 |
+
"to search on sys.path and open:",
|
| 723 |
+
name).result
|
| 724 |
+
if file_path is not None:
|
| 725 |
+
if self.flist:
|
| 726 |
+
self.flist.open(file_path)
|
| 727 |
+
else:
|
| 728 |
+
self.io.loadfile(file_path)
|
| 729 |
+
return file_path
|
| 730 |
+
|
| 731 |
+
def open_module_event(self, event):
|
| 732 |
+
self.open_module()
|
| 733 |
+
return "break"
|
| 734 |
+
|
| 735 |
+
def open_module_browser(self, event=None):
|
| 736 |
+
filename = self.io.filename
|
| 737 |
+
if not (self.__class__.__name__ == 'PyShellEditorWindow'
|
| 738 |
+
and filename):
|
| 739 |
+
filename = self.open_module()
|
| 740 |
+
if filename is None:
|
| 741 |
+
return "break"
|
| 742 |
+
from idlelib import browser
|
| 743 |
+
browser.ModuleBrowser(self.root, filename)
|
| 744 |
+
return "break"
|
| 745 |
+
|
| 746 |
+
def open_path_browser(self, event=None):
|
| 747 |
+
from idlelib import pathbrowser
|
| 748 |
+
pathbrowser.PathBrowser(self.root)
|
| 749 |
+
return "break"
|
| 750 |
+
|
| 751 |
+
def open_turtle_demo(self, event = None):
|
| 752 |
+
import subprocess
|
| 753 |
+
|
| 754 |
+
cmd = [sys.executable,
|
| 755 |
+
'-c',
|
| 756 |
+
'from turtledemo.__main__ import main; main()']
|
| 757 |
+
subprocess.Popen(cmd, shell=False)
|
| 758 |
+
return "break"
|
| 759 |
+
|
| 760 |
+
def gotoline(self, lineno):
|
| 761 |
+
if lineno is not None and lineno > 0:
|
| 762 |
+
self.text.mark_set("insert", "%d.0" % lineno)
|
| 763 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 764 |
+
self.text.tag_add("sel", "insert", "insert +1l")
|
| 765 |
+
self.center()
|
| 766 |
+
|
| 767 |
+
def ispythonsource(self, filename):
|
| 768 |
+
if not filename or os.path.isdir(filename):
|
| 769 |
+
return True
|
| 770 |
+
base, ext = os.path.splitext(os.path.basename(filename))
|
| 771 |
+
if os.path.normcase(ext) in py_extensions:
|
| 772 |
+
return True
|
| 773 |
+
line = self.text.get('1.0', '1.0 lineend')
|
| 774 |
+
return line.startswith('#!') and 'python' in line
|
| 775 |
+
|
| 776 |
+
def close_hook(self):
|
| 777 |
+
if self.flist:
|
| 778 |
+
self.flist.unregister_maybe_terminate(self)
|
| 779 |
+
self.flist = None
|
| 780 |
+
|
| 781 |
+
def set_close_hook(self, close_hook):
|
| 782 |
+
self.close_hook = close_hook
|
| 783 |
+
|
| 784 |
+
def filename_change_hook(self):
|
| 785 |
+
if self.flist:
|
| 786 |
+
self.flist.filename_changed_edit(self)
|
| 787 |
+
self.saved_change_hook()
|
| 788 |
+
self.top.update_windowlist_registry(self)
|
| 789 |
+
self.ResetColorizer()
|
| 790 |
+
|
| 791 |
+
def _addcolorizer(self):
|
| 792 |
+
if self.color:
|
| 793 |
+
return
|
| 794 |
+
if self.ispythonsource(self.io.filename):
|
| 795 |
+
self.color = self.ColorDelegator()
|
| 796 |
+
# can add more colorizers here...
|
| 797 |
+
if self.color:
|
| 798 |
+
self.per.insertfilterafter(filter=self.color, after=self.undo)
|
| 799 |
+
|
| 800 |
+
def _rmcolorizer(self):
|
| 801 |
+
if not self.color:
|
| 802 |
+
return
|
| 803 |
+
self.color.removecolors()
|
| 804 |
+
self.per.removefilter(self.color)
|
| 805 |
+
self.color = None
|
| 806 |
+
|
| 807 |
+
def ResetColorizer(self):
|
| 808 |
+
"Update the color theme"
|
| 809 |
+
# Called from self.filename_change_hook and from configdialog.py
|
| 810 |
+
self._rmcolorizer()
|
| 811 |
+
self._addcolorizer()
|
| 812 |
+
EditorWindow.color_config(self.text)
|
| 813 |
+
|
| 814 |
+
if self.code_context is not None:
|
| 815 |
+
self.code_context.update_highlight_colors()
|
| 816 |
+
|
| 817 |
+
if self.line_numbers is not None:
|
| 818 |
+
self.line_numbers.update_colors()
|
| 819 |
+
|
| 820 |
+
IDENTCHARS = string.ascii_letters + string.digits + "_"
|
| 821 |
+
|
| 822 |
+
def colorize_syntax_error(self, text, pos):
|
| 823 |
+
text.tag_add("ERROR", pos)
|
| 824 |
+
char = text.get(pos)
|
| 825 |
+
if char and char in self.IDENTCHARS:
|
| 826 |
+
text.tag_add("ERROR", pos + " wordstart", pos)
|
| 827 |
+
if '\n' == text.get(pos): # error at line end
|
| 828 |
+
text.mark_set("insert", pos)
|
| 829 |
+
else:
|
| 830 |
+
text.mark_set("insert", pos + "+1c")
|
| 831 |
+
text.see(pos)
|
| 832 |
+
|
| 833 |
+
def update_cursor_blink(self):
|
| 834 |
+
"Update the cursor blink configuration."
|
| 835 |
+
cursorblink = idleConf.GetOption(
|
| 836 |
+
'main', 'EditorWindow', 'cursor-blink', type='bool')
|
| 837 |
+
if not cursorblink:
|
| 838 |
+
self.text['insertofftime'] = 0
|
| 839 |
+
else:
|
| 840 |
+
# Restore the original value
|
| 841 |
+
self.text['insertofftime'] = idleConf.blink_off_time
|
| 842 |
+
|
| 843 |
+
def ResetFont(self):
|
| 844 |
+
"Update the text widgets' font if it is changed"
|
| 845 |
+
# Called from configdialog.py
|
| 846 |
+
|
| 847 |
+
# Update the code context widget first, since its height affects
|
| 848 |
+
# the height of the text widget. This avoids double re-rendering.
|
| 849 |
+
if self.code_context is not None:
|
| 850 |
+
self.code_context.update_font()
|
| 851 |
+
# Next, update the line numbers widget, since its width affects
|
| 852 |
+
# the width of the text widget.
|
| 853 |
+
if self.line_numbers is not None:
|
| 854 |
+
self.line_numbers.update_font()
|
| 855 |
+
# Finally, update the main text widget.
|
| 856 |
+
new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow')
|
| 857 |
+
self.text['font'] = new_font
|
| 858 |
+
self.set_width()
|
| 859 |
+
|
| 860 |
+
def RemoveKeybindings(self):
|
| 861 |
+
"Remove the keybindings before they are changed."
|
| 862 |
+
# Called from configdialog.py
|
| 863 |
+
self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
|
| 864 |
+
for event, keylist in keydefs.items():
|
| 865 |
+
self.text.event_delete(event, *keylist)
|
| 866 |
+
for extensionName in self.get_standard_extension_names():
|
| 867 |
+
xkeydefs = idleConf.GetExtensionBindings(extensionName)
|
| 868 |
+
if xkeydefs:
|
| 869 |
+
for event, keylist in xkeydefs.items():
|
| 870 |
+
self.text.event_delete(event, *keylist)
|
| 871 |
+
|
| 872 |
+
def ApplyKeybindings(self):
|
| 873 |
+
"Update the keybindings after they are changed"
|
| 874 |
+
# Called from configdialog.py
|
| 875 |
+
self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
|
| 876 |
+
self.apply_bindings()
|
| 877 |
+
for extensionName in self.get_standard_extension_names():
|
| 878 |
+
xkeydefs = idleConf.GetExtensionBindings(extensionName)
|
| 879 |
+
if xkeydefs:
|
| 880 |
+
self.apply_bindings(xkeydefs)
|
| 881 |
+
#update menu accelerators
|
| 882 |
+
menuEventDict = {}
|
| 883 |
+
for menu in self.mainmenu.menudefs:
|
| 884 |
+
menuEventDict[menu[0]] = {}
|
| 885 |
+
for item in menu[1]:
|
| 886 |
+
if item:
|
| 887 |
+
menuEventDict[menu[0]][prepstr(item[0])[1]] = item[1]
|
| 888 |
+
for menubarItem in self.menudict:
|
| 889 |
+
menu = self.menudict[menubarItem]
|
| 890 |
+
end = menu.index(END)
|
| 891 |
+
if end is None:
|
| 892 |
+
# Skip empty menus
|
| 893 |
+
continue
|
| 894 |
+
end += 1
|
| 895 |
+
for index in range(0, end):
|
| 896 |
+
if menu.type(index) == 'command':
|
| 897 |
+
accel = menu.entrycget(index, 'accelerator')
|
| 898 |
+
if accel:
|
| 899 |
+
itemName = menu.entrycget(index, 'label')
|
| 900 |
+
event = ''
|
| 901 |
+
if menubarItem in menuEventDict:
|
| 902 |
+
if itemName in menuEventDict[menubarItem]:
|
| 903 |
+
event = menuEventDict[menubarItem][itemName]
|
| 904 |
+
if event:
|
| 905 |
+
accel = get_accelerator(keydefs, event)
|
| 906 |
+
menu.entryconfig(index, accelerator=accel)
|
| 907 |
+
|
| 908 |
+
def set_notabs_indentwidth(self):
|
| 909 |
+
"Update the indentwidth if changed and not using tabs in this window"
|
| 910 |
+
# Called from configdialog.py
|
| 911 |
+
if not self.usetabs:
|
| 912 |
+
self.indentwidth = idleConf.GetOption('main', 'Indent','num-spaces',
|
| 913 |
+
type='int')
|
| 914 |
+
|
| 915 |
+
def reset_help_menu_entries(self):
|
| 916 |
+
"Update the additional help entries on the Help menu"
|
| 917 |
+
help_list = idleConf.GetAllExtraHelpSourcesList()
|
| 918 |
+
helpmenu = self.menudict['help']
|
| 919 |
+
# first delete the extra help entries, if any
|
| 920 |
+
helpmenu_length = helpmenu.index(END)
|
| 921 |
+
if helpmenu_length > self.base_helpmenu_length:
|
| 922 |
+
helpmenu.delete((self.base_helpmenu_length + 1), helpmenu_length)
|
| 923 |
+
# then rebuild them
|
| 924 |
+
if help_list:
|
| 925 |
+
helpmenu.add_separator()
|
| 926 |
+
for entry in help_list:
|
| 927 |
+
cmd = self.__extra_help_callback(entry[1])
|
| 928 |
+
helpmenu.add_command(label=entry[0], command=cmd)
|
| 929 |
+
# and update the menu dictionary
|
| 930 |
+
self.menudict['help'] = helpmenu
|
| 931 |
+
|
| 932 |
+
def __extra_help_callback(self, helpfile):
|
| 933 |
+
"Create a callback with the helpfile value frozen at definition time"
|
| 934 |
+
def display_extra_help(helpfile=helpfile):
|
| 935 |
+
if not helpfile.startswith(('www', 'http')):
|
| 936 |
+
helpfile = os.path.normpath(helpfile)
|
| 937 |
+
if sys.platform[:3] == 'win':
|
| 938 |
+
try:
|
| 939 |
+
os.startfile(helpfile)
|
| 940 |
+
except OSError as why:
|
| 941 |
+
messagebox.showerror(title='Document Start Failure',
|
| 942 |
+
message=str(why), parent=self.text)
|
| 943 |
+
else:
|
| 944 |
+
webbrowser.open(helpfile)
|
| 945 |
+
return display_extra_help
|
| 946 |
+
|
| 947 |
+
def update_recent_files_list(self, new_file=None):
|
| 948 |
+
"Load and update the recent files list and menus"
|
| 949 |
+
# TODO: move to iomenu.
|
| 950 |
+
rf_list = []
|
| 951 |
+
file_path = self.recent_files_path
|
| 952 |
+
if file_path and os.path.exists(file_path):
|
| 953 |
+
with open(file_path, 'r',
|
| 954 |
+
encoding='utf_8', errors='replace') as rf_list_file:
|
| 955 |
+
rf_list = rf_list_file.readlines()
|
| 956 |
+
if new_file:
|
| 957 |
+
new_file = os.path.abspath(new_file) + '\n'
|
| 958 |
+
if new_file in rf_list:
|
| 959 |
+
rf_list.remove(new_file) # move to top
|
| 960 |
+
rf_list.insert(0, new_file)
|
| 961 |
+
# clean and save the recent files list
|
| 962 |
+
bad_paths = []
|
| 963 |
+
for path in rf_list:
|
| 964 |
+
if '\0' in path or not os.path.exists(path[0:-1]):
|
| 965 |
+
bad_paths.append(path)
|
| 966 |
+
rf_list = [path for path in rf_list if path not in bad_paths]
|
| 967 |
+
ulchars = "1234567890ABCDEFGHIJK"
|
| 968 |
+
rf_list = rf_list[0:len(ulchars)]
|
| 969 |
+
if file_path:
|
| 970 |
+
try:
|
| 971 |
+
with open(file_path, 'w',
|
| 972 |
+
encoding='utf_8', errors='replace') as rf_file:
|
| 973 |
+
rf_file.writelines(rf_list)
|
| 974 |
+
except OSError as err:
|
| 975 |
+
if not getattr(self.root, "recentfiles_message", False):
|
| 976 |
+
self.root.recentfiles_message = True
|
| 977 |
+
messagebox.showwarning(title='IDLE Warning',
|
| 978 |
+
message="Cannot save Recent Files list to disk.\n"
|
| 979 |
+
f" {err}\n"
|
| 980 |
+
"Select OK to continue.",
|
| 981 |
+
parent=self.text)
|
| 982 |
+
# for each edit window instance, construct the recent files menu
|
| 983 |
+
for instance in self.top.instance_dict:
|
| 984 |
+
menu = instance.recent_files_menu
|
| 985 |
+
menu.delete(0, END) # clear, and rebuild:
|
| 986 |
+
for i, file_name in enumerate(rf_list):
|
| 987 |
+
file_name = file_name.rstrip() # zap \n
|
| 988 |
+
callback = instance.__recent_file_callback(file_name)
|
| 989 |
+
menu.add_command(label=ulchars[i] + " " + file_name,
|
| 990 |
+
command=callback,
|
| 991 |
+
underline=0)
|
| 992 |
+
|
| 993 |
+
def __recent_file_callback(self, file_name):
|
| 994 |
+
def open_recent_file(fn_closure=file_name):
|
| 995 |
+
self.io.open(editFile=fn_closure)
|
| 996 |
+
return open_recent_file
|
| 997 |
+
|
| 998 |
+
def saved_change_hook(self):
|
| 999 |
+
short = self.short_title()
|
| 1000 |
+
long = self.long_title()
|
| 1001 |
+
if short and long:
|
| 1002 |
+
title = short + " - " + long + _py_version
|
| 1003 |
+
elif short:
|
| 1004 |
+
title = short
|
| 1005 |
+
elif long:
|
| 1006 |
+
title = long
|
| 1007 |
+
else:
|
| 1008 |
+
title = "untitled"
|
| 1009 |
+
icon = short or long or title
|
| 1010 |
+
if not self.get_saved():
|
| 1011 |
+
title = "*%s*" % title
|
| 1012 |
+
icon = "*%s" % icon
|
| 1013 |
+
self.top.wm_title(title)
|
| 1014 |
+
self.top.wm_iconname(icon)
|
| 1015 |
+
|
| 1016 |
+
def get_saved(self):
|
| 1017 |
+
return self.undo.get_saved()
|
| 1018 |
+
|
| 1019 |
+
def set_saved(self, flag):
|
| 1020 |
+
self.undo.set_saved(flag)
|
| 1021 |
+
|
| 1022 |
+
def reset_undo(self):
|
| 1023 |
+
self.undo.reset_undo()
|
| 1024 |
+
|
| 1025 |
+
def short_title(self):
|
| 1026 |
+
filename = self.io.filename
|
| 1027 |
+
return os.path.basename(filename) if filename else "untitled"
|
| 1028 |
+
|
| 1029 |
+
def long_title(self):
|
| 1030 |
+
return self.io.filename or ""
|
| 1031 |
+
|
| 1032 |
+
def center_insert_event(self, event):
|
| 1033 |
+
self.center()
|
| 1034 |
+
return "break"
|
| 1035 |
+
|
| 1036 |
+
def center(self, mark="insert"):
|
| 1037 |
+
text = self.text
|
| 1038 |
+
top, bot = self.getwindowlines()
|
| 1039 |
+
lineno = self.getlineno(mark)
|
| 1040 |
+
height = bot - top
|
| 1041 |
+
newtop = max(1, lineno - height//2)
|
| 1042 |
+
text.yview(float(newtop))
|
| 1043 |
+
|
| 1044 |
+
def getwindowlines(self):
|
| 1045 |
+
text = self.text
|
| 1046 |
+
top = self.getlineno("@0,0")
|
| 1047 |
+
bot = self.getlineno("@0,65535")
|
| 1048 |
+
if top == bot and text.winfo_height() == 1:
|
| 1049 |
+
# Geometry manager hasn't run yet
|
| 1050 |
+
height = int(text['height'])
|
| 1051 |
+
bot = top + height - 1
|
| 1052 |
+
return top, bot
|
| 1053 |
+
|
| 1054 |
+
def getlineno(self, mark="insert"):
|
| 1055 |
+
text = self.text
|
| 1056 |
+
return int(float(text.index(mark)))
|
| 1057 |
+
|
| 1058 |
+
def get_geometry(self):
|
| 1059 |
+
"Return (width, height, x, y)"
|
| 1060 |
+
geom = self.top.wm_geometry()
|
| 1061 |
+
m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
|
| 1062 |
+
return list(map(int, m.groups()))
|
| 1063 |
+
|
| 1064 |
+
def close_event(self, event):
|
| 1065 |
+
self.close()
|
| 1066 |
+
return "break"
|
| 1067 |
+
|
| 1068 |
+
def maybesave(self):
|
| 1069 |
+
if self.io:
|
| 1070 |
+
if not self.get_saved():
|
| 1071 |
+
if self.top.state()!='normal':
|
| 1072 |
+
self.top.deiconify()
|
| 1073 |
+
self.top.lower()
|
| 1074 |
+
self.top.lift()
|
| 1075 |
+
return self.io.maybesave()
|
| 1076 |
+
|
| 1077 |
+
def close(self):
|
| 1078 |
+
try:
|
| 1079 |
+
reply = self.maybesave()
|
| 1080 |
+
if str(reply) != "cancel":
|
| 1081 |
+
self._close()
|
| 1082 |
+
return reply
|
| 1083 |
+
except AttributeError: # bpo-35379: close called twice
|
| 1084 |
+
pass
|
| 1085 |
+
|
| 1086 |
+
def _close(self):
|
| 1087 |
+
if self.io.filename:
|
| 1088 |
+
self.update_recent_files_list(new_file=self.io.filename)
|
| 1089 |
+
window.unregister_callback(self.postwindowsmenu)
|
| 1090 |
+
self.unload_extensions()
|
| 1091 |
+
self.io.close()
|
| 1092 |
+
self.io = None
|
| 1093 |
+
self.undo = None
|
| 1094 |
+
if self.color:
|
| 1095 |
+
self.color.close()
|
| 1096 |
+
self.color = None
|
| 1097 |
+
self.text = None
|
| 1098 |
+
self.tkinter_vars = None
|
| 1099 |
+
self.per.close()
|
| 1100 |
+
self.per = None
|
| 1101 |
+
self.top.destroy()
|
| 1102 |
+
if self.close_hook:
|
| 1103 |
+
# unless override: unregister from flist, terminate if last window
|
| 1104 |
+
self.close_hook()
|
| 1105 |
+
|
| 1106 |
+
def load_extensions(self):
|
| 1107 |
+
self.extensions = {}
|
| 1108 |
+
self.load_standard_extensions()
|
| 1109 |
+
|
| 1110 |
+
def unload_extensions(self):
|
| 1111 |
+
for ins in list(self.extensions.values()):
|
| 1112 |
+
if hasattr(ins, "close"):
|
| 1113 |
+
ins.close()
|
| 1114 |
+
self.extensions = {}
|
| 1115 |
+
|
| 1116 |
+
def load_standard_extensions(self):
|
| 1117 |
+
for name in self.get_standard_extension_names():
|
| 1118 |
+
try:
|
| 1119 |
+
self.load_extension(name)
|
| 1120 |
+
except:
|
| 1121 |
+
print("Failed to load extension", repr(name))
|
| 1122 |
+
traceback.print_exc()
|
| 1123 |
+
|
| 1124 |
+
def get_standard_extension_names(self):
|
| 1125 |
+
return idleConf.GetExtensions(editor_only=True)
|
| 1126 |
+
|
| 1127 |
+
extfiles = { # Map built-in config-extension section names to file names.
|
| 1128 |
+
'ZzDummy': 'zzdummy',
|
| 1129 |
+
}
|
| 1130 |
+
|
| 1131 |
+
def load_extension(self, name):
|
| 1132 |
+
fname = self.extfiles.get(name, name)
|
| 1133 |
+
try:
|
| 1134 |
+
try:
|
| 1135 |
+
mod = importlib.import_module('.' + fname, package=__package__)
|
| 1136 |
+
except (ImportError, TypeError):
|
| 1137 |
+
mod = importlib.import_module(fname)
|
| 1138 |
+
except ImportError:
|
| 1139 |
+
print("\nFailed to import extension: ", name)
|
| 1140 |
+
raise
|
| 1141 |
+
cls = getattr(mod, name)
|
| 1142 |
+
keydefs = idleConf.GetExtensionBindings(name)
|
| 1143 |
+
if hasattr(cls, "menudefs"):
|
| 1144 |
+
self.fill_menus(cls.menudefs, keydefs)
|
| 1145 |
+
ins = cls(self)
|
| 1146 |
+
self.extensions[name] = ins
|
| 1147 |
+
if keydefs:
|
| 1148 |
+
self.apply_bindings(keydefs)
|
| 1149 |
+
for vevent in keydefs:
|
| 1150 |
+
methodname = vevent.replace("-", "_")
|
| 1151 |
+
while methodname[:1] == '<':
|
| 1152 |
+
methodname = methodname[1:]
|
| 1153 |
+
while methodname[-1:] == '>':
|
| 1154 |
+
methodname = methodname[:-1]
|
| 1155 |
+
methodname = methodname + "_event"
|
| 1156 |
+
if hasattr(ins, methodname):
|
| 1157 |
+
self.text.bind(vevent, getattr(ins, methodname))
|
| 1158 |
+
|
| 1159 |
+
def apply_bindings(self, keydefs=None):
|
| 1160 |
+
if keydefs is None:
|
| 1161 |
+
keydefs = self.mainmenu.default_keydefs
|
| 1162 |
+
text = self.text
|
| 1163 |
+
text.keydefs = keydefs
|
| 1164 |
+
for event, keylist in keydefs.items():
|
| 1165 |
+
if keylist:
|
| 1166 |
+
text.event_add(event, *keylist)
|
| 1167 |
+
|
| 1168 |
+
def fill_menus(self, menudefs=None, keydefs=None):
|
| 1169 |
+
"""Add appropriate entries to the menus and submenus
|
| 1170 |
+
|
| 1171 |
+
Menus that are absent or None in self.menudict are ignored.
|
| 1172 |
+
"""
|
| 1173 |
+
if menudefs is None:
|
| 1174 |
+
menudefs = self.mainmenu.menudefs
|
| 1175 |
+
if keydefs is None:
|
| 1176 |
+
keydefs = self.mainmenu.default_keydefs
|
| 1177 |
+
menudict = self.menudict
|
| 1178 |
+
text = self.text
|
| 1179 |
+
for mname, entrylist in menudefs:
|
| 1180 |
+
menu = menudict.get(mname)
|
| 1181 |
+
if not menu:
|
| 1182 |
+
continue
|
| 1183 |
+
for entry in entrylist:
|
| 1184 |
+
if not entry:
|
| 1185 |
+
menu.add_separator()
|
| 1186 |
+
else:
|
| 1187 |
+
label, eventname = entry
|
| 1188 |
+
checkbutton = (label[:1] == '!')
|
| 1189 |
+
if checkbutton:
|
| 1190 |
+
label = label[1:]
|
| 1191 |
+
underline, label = prepstr(label)
|
| 1192 |
+
accelerator = get_accelerator(keydefs, eventname)
|
| 1193 |
+
def command(text=text, eventname=eventname):
|
| 1194 |
+
text.event_generate(eventname)
|
| 1195 |
+
if checkbutton:
|
| 1196 |
+
var = self.get_var_obj(eventname, BooleanVar)
|
| 1197 |
+
menu.add_checkbutton(label=label, underline=underline,
|
| 1198 |
+
command=command, accelerator=accelerator,
|
| 1199 |
+
variable=var)
|
| 1200 |
+
else:
|
| 1201 |
+
menu.add_command(label=label, underline=underline,
|
| 1202 |
+
command=command,
|
| 1203 |
+
accelerator=accelerator)
|
| 1204 |
+
|
| 1205 |
+
def getvar(self, name):
|
| 1206 |
+
var = self.get_var_obj(name)
|
| 1207 |
+
if var:
|
| 1208 |
+
value = var.get()
|
| 1209 |
+
return value
|
| 1210 |
+
else:
|
| 1211 |
+
raise NameError(name)
|
| 1212 |
+
|
| 1213 |
+
def setvar(self, name, value, vartype=None):
|
| 1214 |
+
var = self.get_var_obj(name, vartype)
|
| 1215 |
+
if var:
|
| 1216 |
+
var.set(value)
|
| 1217 |
+
else:
|
| 1218 |
+
raise NameError(name)
|
| 1219 |
+
|
| 1220 |
+
def get_var_obj(self, name, vartype=None):
|
| 1221 |
+
var = self.tkinter_vars.get(name)
|
| 1222 |
+
if not var and vartype:
|
| 1223 |
+
# create a Tkinter variable object with self.text as master:
|
| 1224 |
+
self.tkinter_vars[name] = var = vartype(self.text)
|
| 1225 |
+
return var
|
| 1226 |
+
|
| 1227 |
+
# Tk implementations of "virtual text methods" -- each platform
|
| 1228 |
+
# reusing IDLE's support code needs to define these for its GUI's
|
| 1229 |
+
# flavor of widget.
|
| 1230 |
+
|
| 1231 |
+
# Is character at text_index in a Python string? Return 0 for
|
| 1232 |
+
# "guaranteed no", true for anything else. This info is expensive
|
| 1233 |
+
# to compute ab initio, but is probably already known by the
|
| 1234 |
+
# platform's colorizer.
|
| 1235 |
+
|
| 1236 |
+
def is_char_in_string(self, text_index):
|
| 1237 |
+
if self.color:
|
| 1238 |
+
# Return true iff colorizer hasn't (re)gotten this far
|
| 1239 |
+
# yet, or the character is tagged as being in a string
|
| 1240 |
+
return self.text.tag_prevrange("TODO", text_index) or \
|
| 1241 |
+
"STRING" in self.text.tag_names(text_index)
|
| 1242 |
+
else:
|
| 1243 |
+
# The colorizer is missing: assume the worst
|
| 1244 |
+
return 1
|
| 1245 |
+
|
| 1246 |
+
# If a selection is defined in the text widget, return (start,
|
| 1247 |
+
# end) as Tkinter text indices, otherwise return (None, None)
|
| 1248 |
+
def get_selection_indices(self):
|
| 1249 |
+
try:
|
| 1250 |
+
first = self.text.index("sel.first")
|
| 1251 |
+
last = self.text.index("sel.last")
|
| 1252 |
+
return first, last
|
| 1253 |
+
except TclError:
|
| 1254 |
+
return None, None
|
| 1255 |
+
|
| 1256 |
+
# Return the text widget's current view of what a tab stop means
|
| 1257 |
+
# (equivalent width in spaces).
|
| 1258 |
+
|
| 1259 |
+
def get_tk_tabwidth(self):
|
| 1260 |
+
current = self.text['tabs'] or TK_TABWIDTH_DEFAULT
|
| 1261 |
+
return int(current)
|
| 1262 |
+
|
| 1263 |
+
# Set the text widget's current view of what a tab stop means.
|
| 1264 |
+
|
| 1265 |
+
def set_tk_tabwidth(self, newtabwidth):
|
| 1266 |
+
text = self.text
|
| 1267 |
+
if self.get_tk_tabwidth() != newtabwidth:
|
| 1268 |
+
# Set text widget tab width
|
| 1269 |
+
pixels = text.tk.call("font", "measure", text["font"],
|
| 1270 |
+
"-displayof", text.master,
|
| 1271 |
+
"n" * newtabwidth)
|
| 1272 |
+
text.configure(tabs=pixels)
|
| 1273 |
+
|
| 1274 |
+
### begin autoindent code ### (configuration was moved to beginning of class)
|
| 1275 |
+
|
| 1276 |
+
def set_indentation_params(self, is_py_src, guess=True):
|
| 1277 |
+
if is_py_src and guess:
|
| 1278 |
+
i = self.guess_indent()
|
| 1279 |
+
if 2 <= i <= 8:
|
| 1280 |
+
self.indentwidth = i
|
| 1281 |
+
if self.indentwidth != self.tabwidth:
|
| 1282 |
+
self.usetabs = False
|
| 1283 |
+
self.set_tk_tabwidth(self.tabwidth)
|
| 1284 |
+
|
| 1285 |
+
def smart_backspace_event(self, event):
|
| 1286 |
+
text = self.text
|
| 1287 |
+
first, last = self.get_selection_indices()
|
| 1288 |
+
if first and last:
|
| 1289 |
+
text.delete(first, last)
|
| 1290 |
+
text.mark_set("insert", first)
|
| 1291 |
+
return "break"
|
| 1292 |
+
# Delete whitespace left, until hitting a real char or closest
|
| 1293 |
+
# preceding virtual tab stop.
|
| 1294 |
+
chars = text.get("insert linestart", "insert")
|
| 1295 |
+
if chars == '':
|
| 1296 |
+
if text.compare("insert", ">", "1.0"):
|
| 1297 |
+
# easy: delete preceding newline
|
| 1298 |
+
text.delete("insert-1c")
|
| 1299 |
+
else:
|
| 1300 |
+
text.bell() # at start of buffer
|
| 1301 |
+
return "break"
|
| 1302 |
+
if chars[-1] not in " \t":
|
| 1303 |
+
# easy: delete preceding real char
|
| 1304 |
+
text.delete("insert-1c")
|
| 1305 |
+
return "break"
|
| 1306 |
+
# Ick. It may require *inserting* spaces if we back up over a
|
| 1307 |
+
# tab character! This is written to be clear, not fast.
|
| 1308 |
+
tabwidth = self.tabwidth
|
| 1309 |
+
have = len(chars.expandtabs(tabwidth))
|
| 1310 |
+
assert have > 0
|
| 1311 |
+
want = ((have - 1) // self.indentwidth) * self.indentwidth
|
| 1312 |
+
# Debug prompt is multilined....
|
| 1313 |
+
ncharsdeleted = 0
|
| 1314 |
+
while True:
|
| 1315 |
+
chars = chars[:-1]
|
| 1316 |
+
ncharsdeleted = ncharsdeleted + 1
|
| 1317 |
+
have = len(chars.expandtabs(tabwidth))
|
| 1318 |
+
if have <= want or chars[-1] not in " \t":
|
| 1319 |
+
break
|
| 1320 |
+
text.undo_block_start()
|
| 1321 |
+
text.delete("insert-%dc" % ncharsdeleted, "insert")
|
| 1322 |
+
if have < want:
|
| 1323 |
+
text.insert("insert", ' ' * (want - have),
|
| 1324 |
+
self.user_input_insert_tags)
|
| 1325 |
+
text.undo_block_stop()
|
| 1326 |
+
return "break"
|
| 1327 |
+
|
| 1328 |
+
def smart_indent_event(self, event):
|
| 1329 |
+
# if intraline selection:
|
| 1330 |
+
# delete it
|
| 1331 |
+
# elif multiline selection:
|
| 1332 |
+
# do indent-region
|
| 1333 |
+
# else:
|
| 1334 |
+
# indent one level
|
| 1335 |
+
text = self.text
|
| 1336 |
+
first, last = self.get_selection_indices()
|
| 1337 |
+
text.undo_block_start()
|
| 1338 |
+
try:
|
| 1339 |
+
if first and last:
|
| 1340 |
+
if index2line(first) != index2line(last):
|
| 1341 |
+
return self.fregion.indent_region_event(event)
|
| 1342 |
+
text.delete(first, last)
|
| 1343 |
+
text.mark_set("insert", first)
|
| 1344 |
+
prefix = text.get("insert linestart", "insert")
|
| 1345 |
+
raw, effective = get_line_indent(prefix, self.tabwidth)
|
| 1346 |
+
if raw == len(prefix):
|
| 1347 |
+
# only whitespace to the left
|
| 1348 |
+
self.reindent_to(effective + self.indentwidth)
|
| 1349 |
+
else:
|
| 1350 |
+
# tab to the next 'stop' within or to right of line's text:
|
| 1351 |
+
if self.usetabs:
|
| 1352 |
+
pad = '\t'
|
| 1353 |
+
else:
|
| 1354 |
+
effective = len(prefix.expandtabs(self.tabwidth))
|
| 1355 |
+
n = self.indentwidth
|
| 1356 |
+
pad = ' ' * (n - effective % n)
|
| 1357 |
+
text.insert("insert", pad, self.user_input_insert_tags)
|
| 1358 |
+
text.see("insert")
|
| 1359 |
+
return "break"
|
| 1360 |
+
finally:
|
| 1361 |
+
text.undo_block_stop()
|
| 1362 |
+
|
| 1363 |
+
def newline_and_indent_event(self, event):
|
| 1364 |
+
"""Insert a newline and indentation after Enter keypress event.
|
| 1365 |
+
|
| 1366 |
+
Properly position the cursor on the new line based on information
|
| 1367 |
+
from the current line. This takes into account if the current line
|
| 1368 |
+
is a shell prompt, is empty, has selected text, contains a block
|
| 1369 |
+
opener, contains a block closer, is a continuation line, or
|
| 1370 |
+
is inside a string.
|
| 1371 |
+
"""
|
| 1372 |
+
text = self.text
|
| 1373 |
+
first, last = self.get_selection_indices()
|
| 1374 |
+
text.undo_block_start()
|
| 1375 |
+
try: # Close undo block and expose new line in finally clause.
|
| 1376 |
+
if first and last:
|
| 1377 |
+
text.delete(first, last)
|
| 1378 |
+
text.mark_set("insert", first)
|
| 1379 |
+
line = text.get("insert linestart", "insert")
|
| 1380 |
+
|
| 1381 |
+
# Count leading whitespace for indent size.
|
| 1382 |
+
i, n = 0, len(line)
|
| 1383 |
+
while i < n and line[i] in " \t":
|
| 1384 |
+
i += 1
|
| 1385 |
+
if i == n:
|
| 1386 |
+
# The cursor is in or at leading indentation in a continuation
|
| 1387 |
+
# line; just inject an empty line at the start.
|
| 1388 |
+
text.insert("insert linestart", '\n',
|
| 1389 |
+
self.user_input_insert_tags)
|
| 1390 |
+
return "break"
|
| 1391 |
+
indent = line[:i]
|
| 1392 |
+
|
| 1393 |
+
# Strip whitespace before insert point unless it's in the prompt.
|
| 1394 |
+
i = 0
|
| 1395 |
+
while line and line[-1] in " \t":
|
| 1396 |
+
line = line[:-1]
|
| 1397 |
+
i += 1
|
| 1398 |
+
if i:
|
| 1399 |
+
text.delete("insert - %d chars" % i, "insert")
|
| 1400 |
+
|
| 1401 |
+
# Strip whitespace after insert point.
|
| 1402 |
+
while text.get("insert") in " \t":
|
| 1403 |
+
text.delete("insert")
|
| 1404 |
+
|
| 1405 |
+
# Insert new line.
|
| 1406 |
+
text.insert("insert", '\n', self.user_input_insert_tags)
|
| 1407 |
+
|
| 1408 |
+
# Adjust indentation for continuations and block open/close.
|
| 1409 |
+
# First need to find the last statement.
|
| 1410 |
+
lno = index2line(text.index('insert'))
|
| 1411 |
+
y = pyparse.Parser(self.indentwidth, self.tabwidth)
|
| 1412 |
+
if not self.prompt_last_line:
|
| 1413 |
+
for context in self.num_context_lines:
|
| 1414 |
+
startat = max(lno - context, 1)
|
| 1415 |
+
startatindex = repr(startat) + ".0"
|
| 1416 |
+
rawtext = text.get(startatindex, "insert")
|
| 1417 |
+
y.set_code(rawtext)
|
| 1418 |
+
bod = y.find_good_parse_start(
|
| 1419 |
+
self._build_char_in_string_func(startatindex))
|
| 1420 |
+
if bod is not None or startat == 1:
|
| 1421 |
+
break
|
| 1422 |
+
y.set_lo(bod or 0)
|
| 1423 |
+
else:
|
| 1424 |
+
r = text.tag_prevrange("console", "insert")
|
| 1425 |
+
if r:
|
| 1426 |
+
startatindex = r[1]
|
| 1427 |
+
else:
|
| 1428 |
+
startatindex = "1.0"
|
| 1429 |
+
rawtext = text.get(startatindex, "insert")
|
| 1430 |
+
y.set_code(rawtext)
|
| 1431 |
+
y.set_lo(0)
|
| 1432 |
+
|
| 1433 |
+
c = y.get_continuation_type()
|
| 1434 |
+
if c != pyparse.C_NONE:
|
| 1435 |
+
# The current statement hasn't ended yet.
|
| 1436 |
+
if c == pyparse.C_STRING_FIRST_LINE:
|
| 1437 |
+
# After the first line of a string do not indent at all.
|
| 1438 |
+
pass
|
| 1439 |
+
elif c == pyparse.C_STRING_NEXT_LINES:
|
| 1440 |
+
# Inside a string which started before this line;
|
| 1441 |
+
# just mimic the current indent.
|
| 1442 |
+
text.insert("insert", indent, self.user_input_insert_tags)
|
| 1443 |
+
elif c == pyparse.C_BRACKET:
|
| 1444 |
+
# Line up with the first (if any) element of the
|
| 1445 |
+
# last open bracket structure; else indent one
|
| 1446 |
+
# level beyond the indent of the line with the
|
| 1447 |
+
# last open bracket.
|
| 1448 |
+
self.reindent_to(y.compute_bracket_indent())
|
| 1449 |
+
elif c == pyparse.C_BACKSLASH:
|
| 1450 |
+
# If more than one line in this statement already, just
|
| 1451 |
+
# mimic the current indent; else if initial line
|
| 1452 |
+
# has a start on an assignment stmt, indent to
|
| 1453 |
+
# beyond leftmost =; else to beyond first chunk of
|
| 1454 |
+
# non-whitespace on initial line.
|
| 1455 |
+
if y.get_num_lines_in_stmt() > 1:
|
| 1456 |
+
text.insert("insert", indent,
|
| 1457 |
+
self.user_input_insert_tags)
|
| 1458 |
+
else:
|
| 1459 |
+
self.reindent_to(y.compute_backslash_indent())
|
| 1460 |
+
else:
|
| 1461 |
+
assert 0, "bogus continuation type %r" % (c,)
|
| 1462 |
+
return "break"
|
| 1463 |
+
|
| 1464 |
+
# This line starts a brand new statement; indent relative to
|
| 1465 |
+
# indentation of initial line of closest preceding
|
| 1466 |
+
# interesting statement.
|
| 1467 |
+
indent = y.get_base_indent_string()
|
| 1468 |
+
text.insert("insert", indent, self.user_input_insert_tags)
|
| 1469 |
+
if y.is_block_opener():
|
| 1470 |
+
self.smart_indent_event(event)
|
| 1471 |
+
elif indent and y.is_block_closer():
|
| 1472 |
+
self.smart_backspace_event(event)
|
| 1473 |
+
return "break"
|
| 1474 |
+
finally:
|
| 1475 |
+
text.see("insert")
|
| 1476 |
+
text.undo_block_stop()
|
| 1477 |
+
|
| 1478 |
+
# Our editwin provides an is_char_in_string function that works
|
| 1479 |
+
# with a Tk text index, but PyParse only knows about offsets into
|
| 1480 |
+
# a string. This builds a function for PyParse that accepts an
|
| 1481 |
+
# offset.
|
| 1482 |
+
|
| 1483 |
+
def _build_char_in_string_func(self, startindex):
|
| 1484 |
+
def inner(offset, _startindex=startindex,
|
| 1485 |
+
_icis=self.is_char_in_string):
|
| 1486 |
+
return _icis(_startindex + "+%dc" % offset)
|
| 1487 |
+
return inner
|
| 1488 |
+
|
| 1489 |
+
# XXX this isn't bound to anything -- see tabwidth comments
|
| 1490 |
+
## def change_tabwidth_event(self, event):
|
| 1491 |
+
## new = self._asktabwidth()
|
| 1492 |
+
## if new != self.tabwidth:
|
| 1493 |
+
## self.tabwidth = new
|
| 1494 |
+
## self.set_indentation_params(0, guess=0)
|
| 1495 |
+
## return "break"
|
| 1496 |
+
|
| 1497 |
+
# Make string that displays as n leading blanks.
|
| 1498 |
+
|
| 1499 |
+
def _make_blanks(self, n):
|
| 1500 |
+
if self.usetabs:
|
| 1501 |
+
ntabs, nspaces = divmod(n, self.tabwidth)
|
| 1502 |
+
return '\t' * ntabs + ' ' * nspaces
|
| 1503 |
+
else:
|
| 1504 |
+
return ' ' * n
|
| 1505 |
+
|
| 1506 |
+
# Delete from beginning of line to insert point, then reinsert
|
| 1507 |
+
# column logical (meaning use tabs if appropriate) spaces.
|
| 1508 |
+
|
| 1509 |
+
def reindent_to(self, column):
|
| 1510 |
+
text = self.text
|
| 1511 |
+
text.undo_block_start()
|
| 1512 |
+
if text.compare("insert linestart", "!=", "insert"):
|
| 1513 |
+
text.delete("insert linestart", "insert")
|
| 1514 |
+
if column:
|
| 1515 |
+
text.insert("insert", self._make_blanks(column),
|
| 1516 |
+
self.user_input_insert_tags)
|
| 1517 |
+
text.undo_block_stop()
|
| 1518 |
+
|
| 1519 |
+
# Guess indentwidth from text content.
|
| 1520 |
+
# Return guessed indentwidth. This should not be believed unless
|
| 1521 |
+
# it's in a reasonable range (e.g., it will be 0 if no indented
|
| 1522 |
+
# blocks are found).
|
| 1523 |
+
|
| 1524 |
+
def guess_indent(self):
|
| 1525 |
+
opener, indented = IndentSearcher(self.text, self.tabwidth).run()
|
| 1526 |
+
if opener and indented:
|
| 1527 |
+
raw, indentsmall = get_line_indent(opener, self.tabwidth)
|
| 1528 |
+
raw, indentlarge = get_line_indent(indented, self.tabwidth)
|
| 1529 |
+
else:
|
| 1530 |
+
indentsmall = indentlarge = 0
|
| 1531 |
+
return indentlarge - indentsmall
|
| 1532 |
+
|
| 1533 |
+
def toggle_line_numbers_event(self, event=None):
|
| 1534 |
+
if self.line_numbers is None:
|
| 1535 |
+
return
|
| 1536 |
+
|
| 1537 |
+
if self.line_numbers.is_shown:
|
| 1538 |
+
self.line_numbers.hide_sidebar()
|
| 1539 |
+
menu_label = "Show"
|
| 1540 |
+
else:
|
| 1541 |
+
self.line_numbers.show_sidebar()
|
| 1542 |
+
menu_label = "Hide"
|
| 1543 |
+
self.update_menu_label(menu='options', index='*ine*umbers',
|
| 1544 |
+
label=f'{menu_label} Line Numbers')
|
| 1545 |
+
|
| 1546 |
+
# "line.col" -> line, as an int
|
| 1547 |
+
def index2line(index):
|
| 1548 |
+
return int(float(index))
|
| 1549 |
+
|
| 1550 |
+
|
| 1551 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 1552 |
+
def get_line_indent(line, tabwidth):
|
| 1553 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 1554 |
+
|
| 1555 |
+
The effective # of spaces is the length after properly "expanding"
|
| 1556 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 1557 |
+
"""
|
| 1558 |
+
m = _line_indent_re.match(line)
|
| 1559 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 1560 |
+
|
| 1561 |
+
|
| 1562 |
+
class IndentSearcher:
|
| 1563 |
+
|
| 1564 |
+
# .run() chews over the Text widget, looking for a block opener
|
| 1565 |
+
# and the stmt following it. Returns a pair,
|
| 1566 |
+
# (line containing block opener, line containing stmt)
|
| 1567 |
+
# Either or both may be None.
|
| 1568 |
+
|
| 1569 |
+
def __init__(self, text, tabwidth):
|
| 1570 |
+
self.text = text
|
| 1571 |
+
self.tabwidth = tabwidth
|
| 1572 |
+
self.i = self.finished = 0
|
| 1573 |
+
self.blkopenline = self.indentedline = None
|
| 1574 |
+
|
| 1575 |
+
def readline(self):
|
| 1576 |
+
if self.finished:
|
| 1577 |
+
return ""
|
| 1578 |
+
i = self.i = self.i + 1
|
| 1579 |
+
mark = repr(i) + ".0"
|
| 1580 |
+
if self.text.compare(mark, ">=", "end"):
|
| 1581 |
+
return ""
|
| 1582 |
+
return self.text.get(mark, mark + " lineend+1c")
|
| 1583 |
+
|
| 1584 |
+
def tokeneater(self, type, token, start, end, line,
|
| 1585 |
+
INDENT=tokenize.INDENT,
|
| 1586 |
+
NAME=tokenize.NAME,
|
| 1587 |
+
OPENERS=('class', 'def', 'for', 'if', 'try', 'while')):
|
| 1588 |
+
if self.finished:
|
| 1589 |
+
pass
|
| 1590 |
+
elif type == NAME and token in OPENERS:
|
| 1591 |
+
self.blkopenline = line
|
| 1592 |
+
elif type == INDENT and self.blkopenline:
|
| 1593 |
+
self.indentedline = line
|
| 1594 |
+
self.finished = 1
|
| 1595 |
+
|
| 1596 |
+
def run(self):
|
| 1597 |
+
save_tabsize = tokenize.tabsize
|
| 1598 |
+
tokenize.tabsize = self.tabwidth
|
| 1599 |
+
try:
|
| 1600 |
+
try:
|
| 1601 |
+
tokens = tokenize.generate_tokens(self.readline)
|
| 1602 |
+
for token in tokens:
|
| 1603 |
+
self.tokeneater(*token)
|
| 1604 |
+
except (tokenize.TokenError, SyntaxError):
|
| 1605 |
+
# since we cut off the tokenizer early, we can trigger
|
| 1606 |
+
# spurious errors
|
| 1607 |
+
pass
|
| 1608 |
+
finally:
|
| 1609 |
+
tokenize.tabsize = save_tabsize
|
| 1610 |
+
return self.blkopenline, self.indentedline
|
| 1611 |
+
|
| 1612 |
+
### end autoindent code ###
|
| 1613 |
+
|
| 1614 |
+
def prepstr(s):
|
| 1615 |
+
# Helper to extract the underscore from a string, e.g.
|
| 1616 |
+
# prepstr("Co_py") returns (2, "Copy").
|
| 1617 |
+
i = s.find('_')
|
| 1618 |
+
if i >= 0:
|
| 1619 |
+
s = s[:i] + s[i+1:]
|
| 1620 |
+
return i, s
|
| 1621 |
+
|
| 1622 |
+
|
| 1623 |
+
keynames = {
|
| 1624 |
+
'bracketleft': '[',
|
| 1625 |
+
'bracketright': ']',
|
| 1626 |
+
'slash': '/',
|
| 1627 |
+
}
|
| 1628 |
+
|
| 1629 |
+
def get_accelerator(keydefs, eventname):
|
| 1630 |
+
keylist = keydefs.get(eventname)
|
| 1631 |
+
# issue10940: temporary workaround to prevent hang with OS X Cocoa Tk 8.5
|
| 1632 |
+
# if not keylist:
|
| 1633 |
+
if (not keylist) or (macosx.isCocoaTk() and eventname in {
|
| 1634 |
+
"<<open-module>>",
|
| 1635 |
+
"<<goto-line>>",
|
| 1636 |
+
"<<change-indentwidth>>"}):
|
| 1637 |
+
return ""
|
| 1638 |
+
s = keylist[0]
|
| 1639 |
+
s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
|
| 1640 |
+
s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
|
| 1641 |
+
s = re.sub("Key-", "", s)
|
| 1642 |
+
s = re.sub("Cancel","Ctrl-Break",s) # dscherer@cmu.edu
|
| 1643 |
+
s = re.sub("Control-", "Ctrl-", s)
|
| 1644 |
+
s = re.sub("-", "+", s)
|
| 1645 |
+
s = re.sub("><", " ", s)
|
| 1646 |
+
s = re.sub("<", "", s)
|
| 1647 |
+
s = re.sub(">", "", s)
|
| 1648 |
+
return s
|
| 1649 |
+
|
| 1650 |
+
|
| 1651 |
+
def fixwordbreaks(root):
|
| 1652 |
+
# On Windows, tcl/tk breaks 'words' only on spaces, as in Command Prompt.
|
| 1653 |
+
# We want Motif style everywhere. See #21474, msg218992 and followup.
|
| 1654 |
+
tk = root.tk
|
| 1655 |
+
tk.call('tcl_wordBreakAfter', 'a b', 0) # make sure word.tcl is loaded
|
| 1656 |
+
tk.call('set', 'tcl_wordchars', r'\w')
|
| 1657 |
+
tk.call('set', 'tcl_nonwordchars', r'\W')
|
| 1658 |
+
|
| 1659 |
+
|
| 1660 |
+
def _editor_window(parent): # htest #
|
| 1661 |
+
# error if close master window first - timer event, after script
|
| 1662 |
+
root = parent
|
| 1663 |
+
fixwordbreaks(root)
|
| 1664 |
+
if sys.argv[1:]:
|
| 1665 |
+
filename = sys.argv[1]
|
| 1666 |
+
else:
|
| 1667 |
+
filename = None
|
| 1668 |
+
macosx.setupApp(root, None)
|
| 1669 |
+
edit = EditorWindow(root=root, filename=filename)
|
| 1670 |
+
text = edit.text
|
| 1671 |
+
text['height'] = 10
|
| 1672 |
+
for i in range(20):
|
| 1673 |
+
text.insert('insert', ' '*i + str(i) + '\n')
|
| 1674 |
+
# text.bind("<<close-all-windows>>", edit.close_event)
|
| 1675 |
+
# Does not stop error, neither does following
|
| 1676 |
+
# edit.text.bind("<<close-window>>", edit.close_event)
|
| 1677 |
+
|
| 1678 |
+
if __name__ == '__main__':
|
| 1679 |
+
from unittest import main
|
| 1680 |
+
main('idlelib.idle_test.test_editor', verbosity=2, exit=False)
|
| 1681 |
+
|
| 1682 |
+
from idlelib.idle_test.htest import run
|
| 1683 |
+
run(_editor_window)
|
evalkit_tf446/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.
|
evalkit_tf446/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()
|
evalkit_tf446/lib/python3.10/idlelib/format.py
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Format all or a selected region (line slice) of text.
|
| 2 |
+
|
| 3 |
+
Region formatting options: paragraph, comment block, indent, deindent,
|
| 4 |
+
comment, uncomment, tabify, and untabify.
|
| 5 |
+
|
| 6 |
+
File renamed from paragraph.py with functions added from editor.py.
|
| 7 |
+
"""
|
| 8 |
+
import re
|
| 9 |
+
from tkinter.messagebox import askyesno
|
| 10 |
+
from tkinter.simpledialog import askinteger
|
| 11 |
+
from idlelib.config import idleConf
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class FormatParagraph:
|
| 15 |
+
"""Format a paragraph, comment block, or selection to a max width.
|
| 16 |
+
|
| 17 |
+
Does basic, standard text formatting, and also understands Python
|
| 18 |
+
comment blocks. Thus, for editing Python source code, this
|
| 19 |
+
extension is really only suitable for reformatting these comment
|
| 20 |
+
blocks or triple-quoted strings.
|
| 21 |
+
|
| 22 |
+
Known problems with comment reformatting:
|
| 23 |
+
* If there is a selection marked, and the first line of the
|
| 24 |
+
selection is not complete, the block will probably not be detected
|
| 25 |
+
as comments, and will have the normal "text formatting" rules
|
| 26 |
+
applied.
|
| 27 |
+
* If a comment block has leading whitespace that mixes tabs and
|
| 28 |
+
spaces, they will not be considered part of the same block.
|
| 29 |
+
* Fancy comments, like this bulleted list, aren't handled :-)
|
| 30 |
+
"""
|
| 31 |
+
def __init__(self, editwin):
|
| 32 |
+
self.editwin = editwin
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def reload(cls):
|
| 36 |
+
cls.max_width = idleConf.GetOption('extensions', 'FormatParagraph',
|
| 37 |
+
'max-width', type='int', default=72)
|
| 38 |
+
|
| 39 |
+
def close(self):
|
| 40 |
+
self.editwin = None
|
| 41 |
+
|
| 42 |
+
def format_paragraph_event(self, event, limit=None):
|
| 43 |
+
"""Formats paragraph to a max width specified in idleConf.
|
| 44 |
+
|
| 45 |
+
If text is selected, format_paragraph_event will start breaking lines
|
| 46 |
+
at the max width, starting from the beginning selection.
|
| 47 |
+
|
| 48 |
+
If no text is selected, format_paragraph_event uses the current
|
| 49 |
+
cursor location to determine the paragraph (lines of text surrounded
|
| 50 |
+
by blank lines) and formats it.
|
| 51 |
+
|
| 52 |
+
The length limit parameter is for testing with a known value.
|
| 53 |
+
"""
|
| 54 |
+
limit = self.max_width if limit is None else limit
|
| 55 |
+
text = self.editwin.text
|
| 56 |
+
first, last = self.editwin.get_selection_indices()
|
| 57 |
+
if first and last:
|
| 58 |
+
data = text.get(first, last)
|
| 59 |
+
comment_header = get_comment_header(data)
|
| 60 |
+
else:
|
| 61 |
+
first, last, comment_header, data = \
|
| 62 |
+
find_paragraph(text, text.index("insert"))
|
| 63 |
+
if comment_header:
|
| 64 |
+
newdata = reformat_comment(data, limit, comment_header)
|
| 65 |
+
else:
|
| 66 |
+
newdata = reformat_paragraph(data, limit)
|
| 67 |
+
text.tag_remove("sel", "1.0", "end")
|
| 68 |
+
|
| 69 |
+
if newdata != data:
|
| 70 |
+
text.mark_set("insert", first)
|
| 71 |
+
text.undo_block_start()
|
| 72 |
+
text.delete(first, last)
|
| 73 |
+
text.insert(first, newdata)
|
| 74 |
+
text.undo_block_stop()
|
| 75 |
+
else:
|
| 76 |
+
text.mark_set("insert", last)
|
| 77 |
+
text.see("insert")
|
| 78 |
+
return "break"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
FormatParagraph.reload()
|
| 82 |
+
|
| 83 |
+
def find_paragraph(text, mark):
|
| 84 |
+
"""Returns the start/stop indices enclosing the paragraph that mark is in.
|
| 85 |
+
|
| 86 |
+
Also returns the comment format string, if any, and paragraph of text
|
| 87 |
+
between the start/stop indices.
|
| 88 |
+
"""
|
| 89 |
+
lineno, col = map(int, mark.split("."))
|
| 90 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 91 |
+
|
| 92 |
+
# Look for start of next paragraph if the index passed in is a blank line
|
| 93 |
+
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
|
| 94 |
+
lineno = lineno + 1
|
| 95 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 96 |
+
first_lineno = lineno
|
| 97 |
+
comment_header = get_comment_header(line)
|
| 98 |
+
comment_header_len = len(comment_header)
|
| 99 |
+
|
| 100 |
+
# Once start line found, search for end of paragraph (a blank line)
|
| 101 |
+
while get_comment_header(line)==comment_header and \
|
| 102 |
+
not is_all_white(line[comment_header_len:]):
|
| 103 |
+
lineno = lineno + 1
|
| 104 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 105 |
+
last = "%d.0" % lineno
|
| 106 |
+
|
| 107 |
+
# Search back to beginning of paragraph (first blank line before)
|
| 108 |
+
lineno = first_lineno - 1
|
| 109 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 110 |
+
while lineno > 0 and \
|
| 111 |
+
get_comment_header(line)==comment_header and \
|
| 112 |
+
not is_all_white(line[comment_header_len:]):
|
| 113 |
+
lineno = lineno - 1
|
| 114 |
+
line = text.get("%d.0" % lineno, "%d.end" % lineno)
|
| 115 |
+
first = "%d.0" % (lineno+1)
|
| 116 |
+
|
| 117 |
+
return first, last, comment_header, text.get(first, last)
|
| 118 |
+
|
| 119 |
+
# This should perhaps be replaced with textwrap.wrap
|
| 120 |
+
def reformat_paragraph(data, limit):
|
| 121 |
+
"""Return data reformatted to specified width (limit)."""
|
| 122 |
+
lines = data.split("\n")
|
| 123 |
+
i = 0
|
| 124 |
+
n = len(lines)
|
| 125 |
+
while i < n and is_all_white(lines[i]):
|
| 126 |
+
i = i+1
|
| 127 |
+
if i >= n:
|
| 128 |
+
return data
|
| 129 |
+
indent1 = get_indent(lines[i])
|
| 130 |
+
if i+1 < n and not is_all_white(lines[i+1]):
|
| 131 |
+
indent2 = get_indent(lines[i+1])
|
| 132 |
+
else:
|
| 133 |
+
indent2 = indent1
|
| 134 |
+
new = lines[:i]
|
| 135 |
+
partial = indent1
|
| 136 |
+
while i < n and not is_all_white(lines[i]):
|
| 137 |
+
# XXX Should take double space after period (etc.) into account
|
| 138 |
+
words = re.split(r"(\s+)", lines[i])
|
| 139 |
+
for j in range(0, len(words), 2):
|
| 140 |
+
word = words[j]
|
| 141 |
+
if not word:
|
| 142 |
+
continue # Can happen when line ends in whitespace
|
| 143 |
+
if len((partial + word).expandtabs()) > limit and \
|
| 144 |
+
partial != indent1:
|
| 145 |
+
new.append(partial.rstrip())
|
| 146 |
+
partial = indent2
|
| 147 |
+
partial = partial + word + " "
|
| 148 |
+
if j+1 < len(words) and words[j+1] != " ":
|
| 149 |
+
partial = partial + " "
|
| 150 |
+
i = i+1
|
| 151 |
+
new.append(partial.rstrip())
|
| 152 |
+
# XXX Should reformat remaining paragraphs as well
|
| 153 |
+
new.extend(lines[i:])
|
| 154 |
+
return "\n".join(new)
|
| 155 |
+
|
| 156 |
+
def reformat_comment(data, limit, comment_header):
|
| 157 |
+
"""Return data reformatted to specified width with comment header."""
|
| 158 |
+
|
| 159 |
+
# Remove header from the comment lines
|
| 160 |
+
lc = len(comment_header)
|
| 161 |
+
data = "\n".join(line[lc:] for line in data.split("\n"))
|
| 162 |
+
# Reformat to maxformatwidth chars or a 20 char width,
|
| 163 |
+
# whichever is greater.
|
| 164 |
+
format_width = max(limit - len(comment_header), 20)
|
| 165 |
+
newdata = reformat_paragraph(data, format_width)
|
| 166 |
+
# re-split and re-insert the comment header.
|
| 167 |
+
newdata = newdata.split("\n")
|
| 168 |
+
# If the block ends in a \n, we don't want the comment prefix
|
| 169 |
+
# inserted after it. (Im not sure it makes sense to reformat a
|
| 170 |
+
# comment block that is not made of complete lines, but whatever!)
|
| 171 |
+
# Can't think of a clean solution, so we hack away
|
| 172 |
+
block_suffix = ""
|
| 173 |
+
if not newdata[-1]:
|
| 174 |
+
block_suffix = "\n"
|
| 175 |
+
newdata = newdata[:-1]
|
| 176 |
+
return '\n'.join(comment_header+line for line in newdata) + block_suffix
|
| 177 |
+
|
| 178 |
+
def is_all_white(line):
|
| 179 |
+
"""Return True if line is empty or all whitespace."""
|
| 180 |
+
|
| 181 |
+
return re.match(r"^\s*$", line) is not None
|
| 182 |
+
|
| 183 |
+
def get_indent(line):
|
| 184 |
+
"""Return the initial space or tab indent of line."""
|
| 185 |
+
return re.match(r"^([ \t]*)", line).group()
|
| 186 |
+
|
| 187 |
+
def get_comment_header(line):
|
| 188 |
+
"""Return string with leading whitespace and '#' from line or ''.
|
| 189 |
+
|
| 190 |
+
A null return indicates that the line is not a comment line. A non-
|
| 191 |
+
null return, such as ' #', will be used to find the other lines of
|
| 192 |
+
a comment block with the same indent.
|
| 193 |
+
"""
|
| 194 |
+
m = re.match(r"^([ \t]*#*)", line)
|
| 195 |
+
if m is None: return ""
|
| 196 |
+
return m.group(1)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Copied from editor.py; importing it would cause an import cycle.
|
| 200 |
+
_line_indent_re = re.compile(r'[ \t]*')
|
| 201 |
+
|
| 202 |
+
def get_line_indent(line, tabwidth):
|
| 203 |
+
"""Return a line's indentation as (# chars, effective # of spaces).
|
| 204 |
+
|
| 205 |
+
The effective # of spaces is the length after properly "expanding"
|
| 206 |
+
the tabs into spaces, as done by str.expandtabs(tabwidth).
|
| 207 |
+
"""
|
| 208 |
+
m = _line_indent_re.match(line)
|
| 209 |
+
return m.end(), len(m.group().expandtabs(tabwidth))
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class FormatRegion:
|
| 213 |
+
"Format selected text (region)."
|
| 214 |
+
|
| 215 |
+
def __init__(self, editwin):
|
| 216 |
+
self.editwin = editwin
|
| 217 |
+
|
| 218 |
+
def get_region(self):
|
| 219 |
+
"""Return line information about the selected text region.
|
| 220 |
+
|
| 221 |
+
If text is selected, the first and last indices will be
|
| 222 |
+
for the selection. If there is no text selected, the
|
| 223 |
+
indices will be the current cursor location.
|
| 224 |
+
|
| 225 |
+
Return a tuple containing (first index, last index,
|
| 226 |
+
string representation of text, list of text lines).
|
| 227 |
+
"""
|
| 228 |
+
text = self.editwin.text
|
| 229 |
+
first, last = self.editwin.get_selection_indices()
|
| 230 |
+
if first and last:
|
| 231 |
+
head = text.index(first + " linestart")
|
| 232 |
+
tail = text.index(last + "-1c lineend +1c")
|
| 233 |
+
else:
|
| 234 |
+
head = text.index("insert linestart")
|
| 235 |
+
tail = text.index("insert lineend +1c")
|
| 236 |
+
chars = text.get(head, tail)
|
| 237 |
+
lines = chars.split("\n")
|
| 238 |
+
return head, tail, chars, lines
|
| 239 |
+
|
| 240 |
+
def set_region(self, head, tail, chars, lines):
|
| 241 |
+
"""Replace the text between the given indices.
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
head: Starting index of text to replace.
|
| 245 |
+
tail: Ending index of text to replace.
|
| 246 |
+
chars: Expected to be string of current text
|
| 247 |
+
between head and tail.
|
| 248 |
+
lines: List of new lines to insert between head
|
| 249 |
+
and tail.
|
| 250 |
+
"""
|
| 251 |
+
text = self.editwin.text
|
| 252 |
+
newchars = "\n".join(lines)
|
| 253 |
+
if newchars == chars:
|
| 254 |
+
text.bell()
|
| 255 |
+
return
|
| 256 |
+
text.tag_remove("sel", "1.0", "end")
|
| 257 |
+
text.mark_set("insert", head)
|
| 258 |
+
text.undo_block_start()
|
| 259 |
+
text.delete(head, tail)
|
| 260 |
+
text.insert(head, newchars)
|
| 261 |
+
text.undo_block_stop()
|
| 262 |
+
text.tag_add("sel", head, "insert")
|
| 263 |
+
|
| 264 |
+
def indent_region_event(self, event=None):
|
| 265 |
+
"Indent region by indentwidth spaces."
|
| 266 |
+
head, tail, chars, lines = self.get_region()
|
| 267 |
+
for pos in range(len(lines)):
|
| 268 |
+
line = lines[pos]
|
| 269 |
+
if line:
|
| 270 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 271 |
+
effective = effective + self.editwin.indentwidth
|
| 272 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 273 |
+
self.set_region(head, tail, chars, lines)
|
| 274 |
+
return "break"
|
| 275 |
+
|
| 276 |
+
def dedent_region_event(self, event=None):
|
| 277 |
+
"Dedent region by indentwidth spaces."
|
| 278 |
+
head, tail, chars, lines = self.get_region()
|
| 279 |
+
for pos in range(len(lines)):
|
| 280 |
+
line = lines[pos]
|
| 281 |
+
if line:
|
| 282 |
+
raw, effective = get_line_indent(line, self.editwin.tabwidth)
|
| 283 |
+
effective = max(effective - self.editwin.indentwidth, 0)
|
| 284 |
+
lines[pos] = self.editwin._make_blanks(effective) + line[raw:]
|
| 285 |
+
self.set_region(head, tail, chars, lines)
|
| 286 |
+
return "break"
|
| 287 |
+
|
| 288 |
+
def comment_region_event(self, event=None):
|
| 289 |
+
"""Comment out each line in region.
|
| 290 |
+
|
| 291 |
+
## is appended to the beginning of each line to comment it out.
|
| 292 |
+
"""
|
| 293 |
+
head, tail, chars, lines = self.get_region()
|
| 294 |
+
for pos in range(len(lines) - 1):
|
| 295 |
+
line = lines[pos]
|
| 296 |
+
lines[pos] = '##' + line
|
| 297 |
+
self.set_region(head, tail, chars, lines)
|
| 298 |
+
return "break"
|
| 299 |
+
|
| 300 |
+
def uncomment_region_event(self, event=None):
|
| 301 |
+
"""Uncomment each line in region.
|
| 302 |
+
|
| 303 |
+
Remove ## or # in the first positions of a line. If the comment
|
| 304 |
+
is not in the beginning position, this command will have no effect.
|
| 305 |
+
"""
|
| 306 |
+
head, tail, chars, lines = self.get_region()
|
| 307 |
+
for pos in range(len(lines)):
|
| 308 |
+
line = lines[pos]
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if line[:2] == '##':
|
| 312 |
+
line = line[2:]
|
| 313 |
+
elif line[:1] == '#':
|
| 314 |
+
line = line[1:]
|
| 315 |
+
lines[pos] = line
|
| 316 |
+
self.set_region(head, tail, chars, lines)
|
| 317 |
+
return "break"
|
| 318 |
+
|
| 319 |
+
def tabify_region_event(self, event=None):
|
| 320 |
+
"Convert leading spaces to tabs for each line in selected region."
|
| 321 |
+
head, tail, chars, lines = self.get_region()
|
| 322 |
+
tabwidth = self._asktabwidth()
|
| 323 |
+
if tabwidth is None:
|
| 324 |
+
return
|
| 325 |
+
for pos in range(len(lines)):
|
| 326 |
+
line = lines[pos]
|
| 327 |
+
if line:
|
| 328 |
+
raw, effective = get_line_indent(line, tabwidth)
|
| 329 |
+
ntabs, nspaces = divmod(effective, tabwidth)
|
| 330 |
+
lines[pos] = '\t' * ntabs + ' ' * nspaces + line[raw:]
|
| 331 |
+
self.set_region(head, tail, chars, lines)
|
| 332 |
+
return "break"
|
| 333 |
+
|
| 334 |
+
def untabify_region_event(self, event=None):
|
| 335 |
+
"Expand tabs to spaces for each line in region."
|
| 336 |
+
head, tail, chars, lines = self.get_region()
|
| 337 |
+
tabwidth = self._asktabwidth()
|
| 338 |
+
if tabwidth is None:
|
| 339 |
+
return
|
| 340 |
+
for pos in range(len(lines)):
|
| 341 |
+
lines[pos] = lines[pos].expandtabs(tabwidth)
|
| 342 |
+
self.set_region(head, tail, chars, lines)
|
| 343 |
+
return "break"
|
| 344 |
+
|
| 345 |
+
def _asktabwidth(self):
|
| 346 |
+
"Return value for tab width."
|
| 347 |
+
return askinteger(
|
| 348 |
+
"Tab width",
|
| 349 |
+
"Columns per tab? (2-16)",
|
| 350 |
+
parent=self.editwin.text,
|
| 351 |
+
initialvalue=self.editwin.indentwidth,
|
| 352 |
+
minvalue=2,
|
| 353 |
+
maxvalue=16)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
class Indents:
|
| 357 |
+
"Change future indents."
|
| 358 |
+
|
| 359 |
+
def __init__(self, editwin):
|
| 360 |
+
self.editwin = editwin
|
| 361 |
+
|
| 362 |
+
def toggle_tabs_event(self, event):
|
| 363 |
+
editwin = self.editwin
|
| 364 |
+
usetabs = editwin.usetabs
|
| 365 |
+
if askyesno(
|
| 366 |
+
"Toggle tabs",
|
| 367 |
+
"Turn tabs " + ("on", "off")[usetabs] +
|
| 368 |
+
"?\nIndent width " +
|
| 369 |
+
("will be", "remains at")[usetabs] + " 8." +
|
| 370 |
+
"\n Note: a tab is always 8 columns",
|
| 371 |
+
parent=editwin.text):
|
| 372 |
+
editwin.usetabs = not usetabs
|
| 373 |
+
# Try to prevent inconsistent indentation.
|
| 374 |
+
# User must change indent width manually after using tabs.
|
| 375 |
+
editwin.indentwidth = 8
|
| 376 |
+
return "break"
|
| 377 |
+
|
| 378 |
+
def change_indentwidth_event(self, event):
|
| 379 |
+
editwin = self.editwin
|
| 380 |
+
new = askinteger(
|
| 381 |
+
"Indent width",
|
| 382 |
+
"New indent width (2-16)\n(Always use 8 when using tabs)",
|
| 383 |
+
parent=editwin.text,
|
| 384 |
+
initialvalue=editwin.indentwidth,
|
| 385 |
+
minvalue=2,
|
| 386 |
+
maxvalue=16)
|
| 387 |
+
if new and new != editwin.indentwidth and not editwin.usetabs:
|
| 388 |
+
editwin.indentwidth = new
|
| 389 |
+
return "break"
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
class Rstrip: # 'Strip Trailing Whitespace" on "Format" menu.
|
| 393 |
+
def __init__(self, editwin):
|
| 394 |
+
self.editwin = editwin
|
| 395 |
+
|
| 396 |
+
def do_rstrip(self, event=None):
|
| 397 |
+
text = self.editwin.text
|
| 398 |
+
undo = self.editwin.undo
|
| 399 |
+
undo.undo_block_start()
|
| 400 |
+
|
| 401 |
+
end_line = int(float(text.index('end')))
|
| 402 |
+
for cur in range(1, end_line):
|
| 403 |
+
txt = text.get('%i.0' % cur, '%i.end' % cur)
|
| 404 |
+
raw = len(txt)
|
| 405 |
+
cut = len(txt.rstrip())
|
| 406 |
+
# Since text.delete() marks file as changed, even if not,
|
| 407 |
+
# only call it when needed to actually delete something.
|
| 408 |
+
if cut < raw:
|
| 409 |
+
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
|
| 410 |
+
|
| 411 |
+
if (text.get('end-2c') == '\n' # File ends with at least 1 newline;
|
| 412 |
+
and not hasattr(self.editwin, 'interp')): # & is not Shell.
|
| 413 |
+
# Delete extra user endlines.
|
| 414 |
+
while (text.index('end-1c') > '1.0' # Stop if file empty.
|
| 415 |
+
and text.get('end-3c') == '\n'):
|
| 416 |
+
text.delete('end-3c')
|
| 417 |
+
# Because tk indexes are slice indexes and never raise,
|
| 418 |
+
# a file with only newlines will be emptied.
|
| 419 |
+
# patchcheck.py does the same.
|
| 420 |
+
|
| 421 |
+
undo.undo_block_stop()
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
if __name__ == "__main__":
|
| 425 |
+
from unittest import main
|
| 426 |
+
main('idlelib.idle_test.test_format', verbosity=2, exit=False)
|
evalkit_tf446/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)
|
evalkit_tf446/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>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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" help.py: Implement the Idle help menu.
|
| 2 |
+
Contents are subject to revision at any time, without notice.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
Help => About IDLE: display About Idle dialog
|
| 6 |
+
|
| 7 |
+
<to be moved here from help_about.py>
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Help => IDLE Help: Display help.html with proper formatting.
|
| 11 |
+
Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html
|
| 12 |
+
(help.copy_strip)=> Lib/idlelib/help.html
|
| 13 |
+
|
| 14 |
+
HelpParser - Parse help.html and render to tk Text.
|
| 15 |
+
|
| 16 |
+
HelpText - Display formatted help.html.
|
| 17 |
+
|
| 18 |
+
HelpFrame - Contain text, scrollbar, and table-of-contents.
|
| 19 |
+
(This will be needed for display in a future tabbed window.)
|
| 20 |
+
|
| 21 |
+
HelpWindow - Display HelpFrame in a standalone window.
|
| 22 |
+
|
| 23 |
+
copy_strip - Copy idle.html to help.html, rstripping each line.
|
| 24 |
+
|
| 25 |
+
show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
|
| 26 |
+
"""
|
| 27 |
+
from html.parser import HTMLParser
|
| 28 |
+
from os.path import abspath, dirname, isfile, join
|
| 29 |
+
from platform import python_version
|
| 30 |
+
|
| 31 |
+
from tkinter import Toplevel, Text, Menu
|
| 32 |
+
from tkinter.ttk import Frame, Menubutton, Scrollbar, Style
|
| 33 |
+
from tkinter import font as tkfont
|
| 34 |
+
|
| 35 |
+
from idlelib.config import idleConf
|
| 36 |
+
|
| 37 |
+
## About IDLE ##
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## IDLE Help ##
|
| 41 |
+
|
| 42 |
+
class HelpParser(HTMLParser):
|
| 43 |
+
"""Render help.html into a text widget.
|
| 44 |
+
|
| 45 |
+
The overridden handle_xyz methods handle a subset of html tags.
|
| 46 |
+
The supplied text should have the needed tag configurations.
|
| 47 |
+
The behavior for unsupported tags, such as table, is undefined.
|
| 48 |
+
If the tags generated by Sphinx change, this class, especially
|
| 49 |
+
the handle_starttag and handle_endtags methods, might have to also.
|
| 50 |
+
"""
|
| 51 |
+
def __init__(self, text):
|
| 52 |
+
HTMLParser.__init__(self, convert_charrefs=True)
|
| 53 |
+
self.text = text # Text widget we're rendering into.
|
| 54 |
+
self.tags = '' # Current block level text tags to apply.
|
| 55 |
+
self.chartags = '' # Current character level text tags.
|
| 56 |
+
self.show = False # Exclude html page navigation.
|
| 57 |
+
self.hdrlink = False # Exclude html header links.
|
| 58 |
+
self.level = 0 # Track indentation level.
|
| 59 |
+
self.pre = False # Displaying preformatted text?
|
| 60 |
+
self.hprefix = '' # Heading prefix (like '25.5'?) to remove.
|
| 61 |
+
self.nested_dl = False # In a nested <dl>?
|
| 62 |
+
self.simplelist = False # In a simple list (no double spacing)?
|
| 63 |
+
self.toc = [] # Pair headers with text indexes for toc.
|
| 64 |
+
self.header = '' # Text within header tags for toc.
|
| 65 |
+
self.prevtag = None # Previous tag info (opener?, tag).
|
| 66 |
+
|
| 67 |
+
def indent(self, amt=1):
|
| 68 |
+
"Change indent (+1, 0, -1) and tags."
|
| 69 |
+
self.level += amt
|
| 70 |
+
self.tags = '' if self.level == 0 else 'l'+str(self.level)
|
| 71 |
+
|
| 72 |
+
def handle_starttag(self, tag, attrs):
|
| 73 |
+
"Handle starttags in help.html."
|
| 74 |
+
class_ = ''
|
| 75 |
+
for a, v in attrs:
|
| 76 |
+
if a == 'class':
|
| 77 |
+
class_ = v
|
| 78 |
+
s = ''
|
| 79 |
+
if tag == 'section' and attrs == [('id', 'idle')]:
|
| 80 |
+
self.show = True # Start main content.
|
| 81 |
+
elif tag == 'div' and class_ == 'clearer':
|
| 82 |
+
self.show = False # End main content.
|
| 83 |
+
elif tag == 'p' and self.prevtag and not self.prevtag[0]:
|
| 84 |
+
# Begin a new block for <p> tags after a closed tag.
|
| 85 |
+
# Avoid extra lines, e.g. after <pre> tags.
|
| 86 |
+
lastline = self.text.get('end-1c linestart', 'end-1c')
|
| 87 |
+
s = '\n\n' if lastline and not lastline.isspace() else '\n'
|
| 88 |
+
elif tag == 'span' and class_ == 'pre':
|
| 89 |
+
self.chartags = 'pre'
|
| 90 |
+
elif tag == 'span' and class_ == 'versionmodified':
|
| 91 |
+
self.chartags = 'em'
|
| 92 |
+
elif tag == 'em':
|
| 93 |
+
self.chartags = 'em'
|
| 94 |
+
elif tag in ['ul', 'ol']:
|
| 95 |
+
if class_.find('simple') != -1:
|
| 96 |
+
s = '\n'
|
| 97 |
+
self.simplelist = True
|
| 98 |
+
else:
|
| 99 |
+
self.simplelist = False
|
| 100 |
+
self.indent()
|
| 101 |
+
elif tag == 'dl':
|
| 102 |
+
if self.level > 0:
|
| 103 |
+
self.nested_dl = True
|
| 104 |
+
elif tag == 'li':
|
| 105 |
+
s = '\n* ' if self.simplelist else '\n\n* '
|
| 106 |
+
elif tag == 'dt':
|
| 107 |
+
s = '\n\n' if not self.nested_dl else '\n' # Avoid extra line.
|
| 108 |
+
self.nested_dl = False
|
| 109 |
+
elif tag == 'dd':
|
| 110 |
+
self.indent()
|
| 111 |
+
s = '\n'
|
| 112 |
+
elif tag == 'pre':
|
| 113 |
+
self.pre = True
|
| 114 |
+
if self.show:
|
| 115 |
+
self.text.insert('end', '\n\n')
|
| 116 |
+
self.tags = 'preblock'
|
| 117 |
+
elif tag == 'a' and class_ == 'headerlink':
|
| 118 |
+
self.hdrlink = True
|
| 119 |
+
elif tag == 'h1':
|
| 120 |
+
self.tags = tag
|
| 121 |
+
elif tag in ['h2', 'h3']:
|
| 122 |
+
if self.show:
|
| 123 |
+
self.header = ''
|
| 124 |
+
self.text.insert('end', '\n\n')
|
| 125 |
+
self.tags = tag
|
| 126 |
+
if self.show:
|
| 127 |
+
self.text.insert('end', s, (self.tags, self.chartags))
|
| 128 |
+
self.prevtag = (True, tag)
|
| 129 |
+
|
| 130 |
+
def handle_endtag(self, tag):
|
| 131 |
+
"Handle endtags in help.html."
|
| 132 |
+
if tag in ['h1', 'h2', 'h3']:
|
| 133 |
+
assert self.level == 0
|
| 134 |
+
if self.show:
|
| 135 |
+
indent = (' ' if tag == 'h3' else
|
| 136 |
+
' ' if tag == 'h2' else
|
| 137 |
+
'')
|
| 138 |
+
self.toc.append((indent+self.header, self.text.index('insert')))
|
| 139 |
+
self.tags = ''
|
| 140 |
+
elif tag in ['span', 'em']:
|
| 141 |
+
self.chartags = ''
|
| 142 |
+
elif tag == 'a':
|
| 143 |
+
self.hdrlink = False
|
| 144 |
+
elif tag == 'pre':
|
| 145 |
+
self.pre = False
|
| 146 |
+
self.tags = ''
|
| 147 |
+
elif tag in ['ul', 'dd', 'ol']:
|
| 148 |
+
self.indent(-1)
|
| 149 |
+
self.prevtag = (False, tag)
|
| 150 |
+
|
| 151 |
+
def handle_data(self, data):
|
| 152 |
+
"Handle date segments in help.html."
|
| 153 |
+
if self.show and not self.hdrlink:
|
| 154 |
+
d = data if self.pre else data.replace('\n', ' ')
|
| 155 |
+
if self.tags == 'h1':
|
| 156 |
+
try:
|
| 157 |
+
self.hprefix = d[0:d.index(' ')]
|
| 158 |
+
except ValueError:
|
| 159 |
+
self.hprefix = ''
|
| 160 |
+
if self.tags in ['h1', 'h2', 'h3']:
|
| 161 |
+
if (self.hprefix != '' and
|
| 162 |
+
d[0:len(self.hprefix)] == self.hprefix):
|
| 163 |
+
d = d[len(self.hprefix):]
|
| 164 |
+
self.header += d.strip()
|
| 165 |
+
self.text.insert('end', d, (self.tags, self.chartags))
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class HelpText(Text):
|
| 169 |
+
"Display help.html."
|
| 170 |
+
def __init__(self, parent, filename):
|
| 171 |
+
"Configure tags and feed file to parser."
|
| 172 |
+
uwide = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
|
| 173 |
+
uhigh = idleConf.GetOption('main', 'EditorWindow', 'height', type='int')
|
| 174 |
+
uhigh = 3 * uhigh // 4 # Lines average 4/3 of editor line height.
|
| 175 |
+
Text.__init__(self, parent, wrap='word', highlightthickness=0,
|
| 176 |
+
padx=5, borderwidth=0, width=uwide, height=uhigh)
|
| 177 |
+
|
| 178 |
+
normalfont = self.findfont(['TkDefaultFont', 'arial', 'helvetica'])
|
| 179 |
+
fixedfont = self.findfont(['TkFixedFont', 'monaco', 'courier'])
|
| 180 |
+
self['font'] = (normalfont, 12)
|
| 181 |
+
self.tag_configure('em', font=(normalfont, 12, 'italic'))
|
| 182 |
+
self.tag_configure('h1', font=(normalfont, 20, 'bold'))
|
| 183 |
+
self.tag_configure('h2', font=(normalfont, 18, 'bold'))
|
| 184 |
+
self.tag_configure('h3', font=(normalfont, 15, 'bold'))
|
| 185 |
+
self.tag_configure('pre', font=(fixedfont, 12), background='#f6f6ff')
|
| 186 |
+
self.tag_configure('preblock', font=(fixedfont, 10), lmargin1=25,
|
| 187 |
+
borderwidth=1, relief='solid', background='#eeffcc')
|
| 188 |
+
self.tag_configure('l1', lmargin1=25, lmargin2=25)
|
| 189 |
+
self.tag_configure('l2', lmargin1=50, lmargin2=50)
|
| 190 |
+
self.tag_configure('l3', lmargin1=75, lmargin2=75)
|
| 191 |
+
self.tag_configure('l4', lmargin1=100, lmargin2=100)
|
| 192 |
+
|
| 193 |
+
self.parser = HelpParser(self)
|
| 194 |
+
with open(filename, encoding='utf-8') as f:
|
| 195 |
+
contents = f.read()
|
| 196 |
+
self.parser.feed(contents)
|
| 197 |
+
self['state'] = 'disabled'
|
| 198 |
+
|
| 199 |
+
def findfont(self, names):
|
| 200 |
+
"Return name of first font family derived from names."
|
| 201 |
+
for name in names:
|
| 202 |
+
if name.lower() in (x.lower() for x in tkfont.names(root=self)):
|
| 203 |
+
font = tkfont.Font(name=name, exists=True, root=self)
|
| 204 |
+
return font.actual()['family']
|
| 205 |
+
elif name.lower() in (x.lower()
|
| 206 |
+
for x in tkfont.families(root=self)):
|
| 207 |
+
return name
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
class HelpFrame(Frame):
|
| 211 |
+
"Display html text, scrollbar, and toc."
|
| 212 |
+
def __init__(self, parent, filename):
|
| 213 |
+
Frame.__init__(self, parent)
|
| 214 |
+
self.text = text = HelpText(self, filename)
|
| 215 |
+
self.style = Style(parent)
|
| 216 |
+
self['style'] = 'helpframe.TFrame'
|
| 217 |
+
self.style.configure('helpframe.TFrame', background=text['background'])
|
| 218 |
+
self.toc = toc = self.toc_menu(text)
|
| 219 |
+
self.scroll = scroll = Scrollbar(self, command=text.yview)
|
| 220 |
+
text['yscrollcommand'] = scroll.set
|
| 221 |
+
|
| 222 |
+
self.rowconfigure(0, weight=1)
|
| 223 |
+
self.columnconfigure(1, weight=1) # Only expand the text widget.
|
| 224 |
+
toc.grid(row=0, column=0, sticky='nw')
|
| 225 |
+
text.grid(row=0, column=1, sticky='nsew')
|
| 226 |
+
scroll.grid(row=0, column=2, sticky='ns')
|
| 227 |
+
|
| 228 |
+
def toc_menu(self, text):
|
| 229 |
+
"Create table of contents as drop-down menu."
|
| 230 |
+
toc = Menubutton(self, text='TOC')
|
| 231 |
+
drop = Menu(toc, tearoff=False)
|
| 232 |
+
for lbl, dex in text.parser.toc:
|
| 233 |
+
drop.add_command(label=lbl, command=lambda dex=dex:text.yview(dex))
|
| 234 |
+
toc['menu'] = drop
|
| 235 |
+
return toc
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
class HelpWindow(Toplevel):
|
| 239 |
+
"Display frame with rendered html."
|
| 240 |
+
def __init__(self, parent, filename, title):
|
| 241 |
+
Toplevel.__init__(self, parent)
|
| 242 |
+
self.wm_title(title)
|
| 243 |
+
self.protocol("WM_DELETE_WINDOW", self.destroy)
|
| 244 |
+
HelpFrame(self, filename).grid(column=0, row=0, sticky='nsew')
|
| 245 |
+
self.grid_columnconfigure(0, weight=1)
|
| 246 |
+
self.grid_rowconfigure(0, weight=1)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def copy_strip():
|
| 250 |
+
"""Copy idle.html to idlelib/help.html, stripping trailing whitespace.
|
| 251 |
+
|
| 252 |
+
Files with trailing whitespace cannot be pushed to the git cpython
|
| 253 |
+
repository. For 3.x (on Windows), help.html is generated, after
|
| 254 |
+
editing idle.rst on the master branch, with
|
| 255 |
+
sphinx-build -bhtml . build/html
|
| 256 |
+
python_d.exe -c "from idlelib.help import copy_strip; copy_strip()"
|
| 257 |
+
Check build/html/library/idle.html, the help.html diff, and the text
|
| 258 |
+
displayed by Help => IDLE Help. Add a blurb and create a PR.
|
| 259 |
+
|
| 260 |
+
It can be worthwhile to occasionally generate help.html without
|
| 261 |
+
touching idle.rst. Changes to the master version and to the doc
|
| 262 |
+
build system may result in changes that should not changed
|
| 263 |
+
the displayed text, but might break HelpParser.
|
| 264 |
+
|
| 265 |
+
As long as master and maintenance versions of idle.rst remain the
|
| 266 |
+
same, help.html can be backported. The internal Python version
|
| 267 |
+
number is not displayed. If maintenance idle.rst diverges from
|
| 268 |
+
the master version, then instead of backporting help.html from
|
| 269 |
+
master, repeat the procedure above to generate a maintenance
|
| 270 |
+
version.
|
| 271 |
+
"""
|
| 272 |
+
src = join(abspath(dirname(dirname(dirname(__file__)))),
|
| 273 |
+
'Doc', 'build', 'html', 'library', 'idle.html')
|
| 274 |
+
dst = join(abspath(dirname(__file__)), 'help.html')
|
| 275 |
+
with open(src, 'rb') as inn,\
|
| 276 |
+
open(dst, 'wb') as out:
|
| 277 |
+
for line in inn:
|
| 278 |
+
out.write(line.rstrip() + b'\n')
|
| 279 |
+
print(f'{src} copied to {dst}')
|
| 280 |
+
|
| 281 |
+
def show_idlehelp(parent):
|
| 282 |
+
"Create HelpWindow; called from Idle Help event handler."
|
| 283 |
+
filename = join(abspath(dirname(__file__)), 'help.html')
|
| 284 |
+
if not isfile(filename):
|
| 285 |
+
# Try copy_strip, present message.
|
| 286 |
+
return
|
| 287 |
+
HelpWindow(parent, filename, 'IDLE Help (%s)' % python_version())
|
| 288 |
+
|
| 289 |
+
if __name__ == '__main__':
|
| 290 |
+
from unittest import main
|
| 291 |
+
main('idlelib.idle_test.test_help', verbosity=2, exit=False)
|
| 292 |
+
|
| 293 |
+
from idlelib.idle_test.htest import run
|
| 294 |
+
run(show_idlehelp)
|
evalkit_tf446/lib/python3.10/idlelib/help_about.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""About Dialog for IDLE
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import webbrowser
|
| 7 |
+
from platform import python_version, architecture
|
| 8 |
+
|
| 9 |
+
from tkinter import Toplevel, Frame, Label, Button, PhotoImage
|
| 10 |
+
from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E
|
| 11 |
+
|
| 12 |
+
from idlelib import textview
|
| 13 |
+
|
| 14 |
+
version = python_version()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def build_bits():
|
| 18 |
+
"Return bits for platform."
|
| 19 |
+
if sys.platform == 'darwin':
|
| 20 |
+
return '64' if sys.maxsize > 2**32 else '32'
|
| 21 |
+
else:
|
| 22 |
+
return architecture()[0][:2]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class AboutDialog(Toplevel):
|
| 26 |
+
"""Modal about dialog for idle
|
| 27 |
+
|
| 28 |
+
"""
|
| 29 |
+
def __init__(self, parent, title=None, *, _htest=False, _utest=False):
|
| 30 |
+
"""Create popup, do not return until tk widget destroyed.
|
| 31 |
+
|
| 32 |
+
parent - parent of this dialog
|
| 33 |
+
title - string which is title of popup dialog
|
| 34 |
+
_htest - bool, change box location when running htest
|
| 35 |
+
_utest - bool, don't wait_window when running unittest
|
| 36 |
+
"""
|
| 37 |
+
Toplevel.__init__(self, parent)
|
| 38 |
+
self.configure(borderwidth=5)
|
| 39 |
+
# place dialog below parent if running htest
|
| 40 |
+
self.geometry("+%d+%d" % (
|
| 41 |
+
parent.winfo_rootx()+30,
|
| 42 |
+
parent.winfo_rooty()+(30 if not _htest else 100)))
|
| 43 |
+
self.bg = "#bbbbbb"
|
| 44 |
+
self.fg = "#000000"
|
| 45 |
+
self.create_widgets()
|
| 46 |
+
self.resizable(height=False, width=False)
|
| 47 |
+
self.title(title or
|
| 48 |
+
f'About IDLE {version} ({build_bits()} bit)')
|
| 49 |
+
self.transient(parent)
|
| 50 |
+
self.grab_set()
|
| 51 |
+
self.protocol("WM_DELETE_WINDOW", self.ok)
|
| 52 |
+
self.parent = parent
|
| 53 |
+
self.button_ok.focus_set()
|
| 54 |
+
self.bind('<Return>', self.ok) # dismiss dialog
|
| 55 |
+
self.bind('<Escape>', self.ok) # dismiss dialog
|
| 56 |
+
self._current_textview = None
|
| 57 |
+
self._utest = _utest
|
| 58 |
+
|
| 59 |
+
if not _utest:
|
| 60 |
+
self.deiconify()
|
| 61 |
+
self.wait_window()
|
| 62 |
+
|
| 63 |
+
def create_widgets(self):
|
| 64 |
+
frame = Frame(self, borderwidth=2, relief=SUNKEN)
|
| 65 |
+
frame_buttons = Frame(self)
|
| 66 |
+
frame_buttons.pack(side=BOTTOM, fill=X)
|
| 67 |
+
frame.pack(side=TOP, expand=True, fill=BOTH)
|
| 68 |
+
self.button_ok = Button(frame_buttons, text='Close',
|
| 69 |
+
command=self.ok)
|
| 70 |
+
self.button_ok.pack(padx=5, pady=5)
|
| 71 |
+
|
| 72 |
+
frame_background = Frame(frame, bg=self.bg)
|
| 73 |
+
frame_background.pack(expand=True, fill=BOTH)
|
| 74 |
+
|
| 75 |
+
header = Label(frame_background, text='IDLE', fg=self.fg,
|
| 76 |
+
bg=self.bg, font=('courier', 24, 'bold'))
|
| 77 |
+
header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
|
| 78 |
+
|
| 79 |
+
tk_patchlevel = self.tk.call('info', 'patchlevel')
|
| 80 |
+
ext = '.png' if tk_patchlevel >= '8.6' else '.gif'
|
| 81 |
+
icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
| 82 |
+
'Icons', f'idle_48{ext}')
|
| 83 |
+
self.icon_image = PhotoImage(master=self._root(), file=icon)
|
| 84 |
+
logo = Label(frame_background, image=self.icon_image, bg=self.bg)
|
| 85 |
+
logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
|
| 86 |
+
|
| 87 |
+
byline_text = "Python's Integrated Development\nand Learning Environment" + 5*'\n'
|
| 88 |
+
byline = Label(frame_background, text=byline_text, justify=LEFT,
|
| 89 |
+
fg=self.fg, bg=self.bg)
|
| 90 |
+
byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
|
| 91 |
+
email = Label(frame_background, text='email: idle-dev@python.org',
|
| 92 |
+
justify=LEFT, fg=self.fg, bg=self.bg)
|
| 93 |
+
email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
|
| 94 |
+
docs_url = ("https://docs.python.org/%d.%d/library/idle.html" %
|
| 95 |
+
sys.version_info[:2])
|
| 96 |
+
docs = Label(frame_background, text=docs_url,
|
| 97 |
+
justify=LEFT, fg=self.fg, bg=self.bg)
|
| 98 |
+
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
|
| 99 |
+
docs.bind("<Button-1>", lambda event: webbrowser.open(docs['text']))
|
| 100 |
+
|
| 101 |
+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
| 102 |
+
height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
|
| 103 |
+
columnspan=3, padx=5, pady=5)
|
| 104 |
+
|
| 105 |
+
pyver = Label(frame_background,
|
| 106 |
+
text='Python version: ' + version,
|
| 107 |
+
fg=self.fg, bg=self.bg)
|
| 108 |
+
pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0)
|
| 109 |
+
tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel,
|
| 110 |
+
fg=self.fg, bg=self.bg)
|
| 111 |
+
tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0)
|
| 112 |
+
py_buttons = Frame(frame_background, bg=self.bg)
|
| 113 |
+
py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
|
| 114 |
+
self.py_license = Button(py_buttons, text='License', width=8,
|
| 115 |
+
highlightbackground=self.bg,
|
| 116 |
+
command=self.show_py_license)
|
| 117 |
+
self.py_license.pack(side=LEFT, padx=10, pady=10)
|
| 118 |
+
self.py_copyright = Button(py_buttons, text='Copyright', width=8,
|
| 119 |
+
highlightbackground=self.bg,
|
| 120 |
+
command=self.show_py_copyright)
|
| 121 |
+
self.py_copyright.pack(side=LEFT, padx=10, pady=10)
|
| 122 |
+
self.py_credits = Button(py_buttons, text='Credits', width=8,
|
| 123 |
+
highlightbackground=self.bg,
|
| 124 |
+
command=self.show_py_credits)
|
| 125 |
+
self.py_credits.pack(side=LEFT, padx=10, pady=10)
|
| 126 |
+
|
| 127 |
+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
| 128 |
+
height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
|
| 129 |
+
columnspan=3, padx=5, pady=5)
|
| 130 |
+
|
| 131 |
+
idlever = Label(frame_background,
|
| 132 |
+
text='IDLE version: ' + version,
|
| 133 |
+
fg=self.fg, bg=self.bg)
|
| 134 |
+
idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
|
| 135 |
+
idle_buttons = Frame(frame_background, bg=self.bg)
|
| 136 |
+
idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
|
| 137 |
+
self.readme = Button(idle_buttons, text='README', width=8,
|
| 138 |
+
highlightbackground=self.bg,
|
| 139 |
+
command=self.show_readme)
|
| 140 |
+
self.readme.pack(side=LEFT, padx=10, pady=10)
|
| 141 |
+
self.idle_news = Button(idle_buttons, text='NEWS', width=8,
|
| 142 |
+
highlightbackground=self.bg,
|
| 143 |
+
command=self.show_idle_news)
|
| 144 |
+
self.idle_news.pack(side=LEFT, padx=10, pady=10)
|
| 145 |
+
self.idle_credits = Button(idle_buttons, text='Credits', width=8,
|
| 146 |
+
highlightbackground=self.bg,
|
| 147 |
+
command=self.show_idle_credits)
|
| 148 |
+
self.idle_credits.pack(side=LEFT, padx=10, pady=10)
|
| 149 |
+
|
| 150 |
+
# License, copyright, and credits are of type _sitebuiltins._Printer
|
| 151 |
+
def show_py_license(self):
|
| 152 |
+
"Handle License button event."
|
| 153 |
+
self.display_printer_text('About - License', license)
|
| 154 |
+
|
| 155 |
+
def show_py_copyright(self):
|
| 156 |
+
"Handle Copyright button event."
|
| 157 |
+
self.display_printer_text('About - Copyright', copyright)
|
| 158 |
+
|
| 159 |
+
def show_py_credits(self):
|
| 160 |
+
"Handle Python Credits button event."
|
| 161 |
+
self.display_printer_text('About - Python Credits', credits)
|
| 162 |
+
|
| 163 |
+
# Encode CREDITS.txt to utf-8 for proper version of Loewis.
|
| 164 |
+
# Specify others as ascii until need utf-8, so catch errors.
|
| 165 |
+
def show_idle_credits(self):
|
| 166 |
+
"Handle Idle Credits button event."
|
| 167 |
+
self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
|
| 168 |
+
|
| 169 |
+
def show_readme(self):
|
| 170 |
+
"Handle Readme button event."
|
| 171 |
+
self.display_file_text('About - Readme', 'README.txt', 'ascii')
|
| 172 |
+
|
| 173 |
+
def show_idle_news(self):
|
| 174 |
+
"Handle News button event."
|
| 175 |
+
self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
|
| 176 |
+
|
| 177 |
+
def display_printer_text(self, title, printer):
|
| 178 |
+
"""Create textview for built-in constants.
|
| 179 |
+
|
| 180 |
+
Built-in constants have type _sitebuiltins._Printer. The
|
| 181 |
+
text is extracted from the built-in and then sent to a text
|
| 182 |
+
viewer with self as the parent and title as the title of
|
| 183 |
+
the popup.
|
| 184 |
+
"""
|
| 185 |
+
printer._Printer__setup()
|
| 186 |
+
text = '\n'.join(printer._Printer__lines)
|
| 187 |
+
self._current_textview = textview.view_text(
|
| 188 |
+
self, title, text, _utest=self._utest)
|
| 189 |
+
|
| 190 |
+
def display_file_text(self, title, filename, encoding=None):
|
| 191 |
+
"""Create textview for filename.
|
| 192 |
+
|
| 193 |
+
The filename needs to be in the current directory. The path
|
| 194 |
+
is sent to a text viewer with self as the parent, title as
|
| 195 |
+
the title of the popup, and the file encoding.
|
| 196 |
+
"""
|
| 197 |
+
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
|
| 198 |
+
self._current_textview = textview.view_file(
|
| 199 |
+
self, title, fn, encoding, _utest=self._utest)
|
| 200 |
+
|
| 201 |
+
def ok(self, event=None):
|
| 202 |
+
"Dismiss help_about dialog."
|
| 203 |
+
self.grab_release()
|
| 204 |
+
self.destroy()
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
if __name__ == '__main__':
|
| 208 |
+
from unittest import main
|
| 209 |
+
main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
|
| 210 |
+
|
| 211 |
+
from idlelib.idle_test.htest import run
|
| 212 |
+
run(AboutDialog)
|
evalkit_tf446/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)
|
evalkit_tf446/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
|
evalkit_tf446/lib/python3.10/idlelib/idle.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os.path
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Enable running IDLE with idlelib in a non-standard location.
|
| 6 |
+
# This was once used to run development versions of IDLE.
|
| 7 |
+
# Because PEP 434 declared idle.py a public interface,
|
| 8 |
+
# removal should require deprecation.
|
| 9 |
+
idlelib_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 10 |
+
if idlelib_dir not in sys.path:
|
| 11 |
+
sys.path.insert(0, idlelib_dir)
|
| 12 |
+
|
| 13 |
+
from idlelib.pyshell import main # This is subject to change
|
| 14 |
+
main()
|
evalkit_tf446/lib/python3.10/idlelib/idle.pyw
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import idlelib.pyshell
|
| 3 |
+
except ImportError:
|
| 4 |
+
# IDLE is not installed, but maybe pyshell is on sys.path:
|
| 5 |
+
from . import pyshell
|
| 6 |
+
import os
|
| 7 |
+
idledir = os.path.dirname(os.path.abspath(pyshell.__file__))
|
| 8 |
+
if idledir != os.getcwd():
|
| 9 |
+
# We're not in the IDLE directory, help the subprocess find run.py
|
| 10 |
+
pypath = os.environ.get('PYTHONPATH', '')
|
| 11 |
+
if pypath:
|
| 12 |
+
os.environ['PYTHONPATH'] = pypath + ':' + idledir
|
| 13 |
+
else:
|
| 14 |
+
os.environ['PYTHONPATH'] = idledir
|
| 15 |
+
pyshell.main()
|
| 16 |
+
else:
|
| 17 |
+
idlelib.pyshell.main()
|
evalkit_tf446/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)
|
evalkit_tf446/lib/python3.10/idlelib/macosx.py
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A number of functions that enhance IDLE on macOS.
|
| 3 |
+
"""
|
| 4 |
+
from os.path import expanduser
|
| 5 |
+
import plistlib
|
| 6 |
+
from sys import platform # Used in _init_tk_type, changed by test.
|
| 7 |
+
|
| 8 |
+
import tkinter
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
## Define functions that query the Mac graphics type.
|
| 12 |
+
## _tk_type and its initializer are private to this section.
|
| 13 |
+
|
| 14 |
+
_tk_type = None
|
| 15 |
+
|
| 16 |
+
def _init_tk_type():
|
| 17 |
+
""" Initialize _tk_type for isXyzTk functions.
|
| 18 |
+
|
| 19 |
+
This function is only called once, when _tk_type is still None.
|
| 20 |
+
"""
|
| 21 |
+
global _tk_type
|
| 22 |
+
if platform == 'darwin':
|
| 23 |
+
|
| 24 |
+
# When running IDLE, GUI is present, test/* may not be.
|
| 25 |
+
# When running tests, test/* is present, GUI may not be.
|
| 26 |
+
# If not, guess most common. Does not matter for testing.
|
| 27 |
+
from idlelib.__init__ import testing
|
| 28 |
+
if testing:
|
| 29 |
+
from test.support import requires, ResourceDenied
|
| 30 |
+
try:
|
| 31 |
+
requires('gui')
|
| 32 |
+
except ResourceDenied:
|
| 33 |
+
_tk_type = "cocoa"
|
| 34 |
+
return
|
| 35 |
+
|
| 36 |
+
root = tkinter.Tk()
|
| 37 |
+
ws = root.tk.call('tk', 'windowingsystem')
|
| 38 |
+
if 'x11' in ws:
|
| 39 |
+
_tk_type = "xquartz"
|
| 40 |
+
elif 'aqua' not in ws:
|
| 41 |
+
_tk_type = "other"
|
| 42 |
+
elif 'AppKit' in root.tk.call('winfo', 'server', '.'):
|
| 43 |
+
_tk_type = "cocoa"
|
| 44 |
+
else:
|
| 45 |
+
_tk_type = "carbon"
|
| 46 |
+
root.destroy()
|
| 47 |
+
else:
|
| 48 |
+
_tk_type = "other"
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
def isAquaTk():
|
| 52 |
+
"""
|
| 53 |
+
Returns True if IDLE is using a native OS X Tk (Cocoa or Carbon).
|
| 54 |
+
"""
|
| 55 |
+
if not _tk_type:
|
| 56 |
+
_init_tk_type()
|
| 57 |
+
return _tk_type == "cocoa" or _tk_type == "carbon"
|
| 58 |
+
|
| 59 |
+
def isCarbonTk():
|
| 60 |
+
"""
|
| 61 |
+
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
|
| 62 |
+
newer Cocoa Aqua Tk).
|
| 63 |
+
"""
|
| 64 |
+
if not _tk_type:
|
| 65 |
+
_init_tk_type()
|
| 66 |
+
return _tk_type == "carbon"
|
| 67 |
+
|
| 68 |
+
def isCocoaTk():
|
| 69 |
+
"""
|
| 70 |
+
Returns True if IDLE is using a Cocoa Aqua Tk.
|
| 71 |
+
"""
|
| 72 |
+
if not _tk_type:
|
| 73 |
+
_init_tk_type()
|
| 74 |
+
return _tk_type == "cocoa"
|
| 75 |
+
|
| 76 |
+
def isXQuartz():
|
| 77 |
+
"""
|
| 78 |
+
Returns True if IDLE is using an OS X X11 Tk.
|
| 79 |
+
"""
|
| 80 |
+
if not _tk_type:
|
| 81 |
+
_init_tk_type()
|
| 82 |
+
return _tk_type == "xquartz"
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def tkVersionWarning(root):
|
| 86 |
+
"""
|
| 87 |
+
Returns a string warning message if the Tk version in use appears to
|
| 88 |
+
be one known to cause problems with IDLE.
|
| 89 |
+
1. Apple Cocoa-based Tk 8.5.7 shipped with Mac OS X 10.6 is unusable.
|
| 90 |
+
2. Apple Cocoa-based Tk 8.5.9 in OS X 10.7 and 10.8 is better but
|
| 91 |
+
can still crash unexpectedly.
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
if isCocoaTk():
|
| 95 |
+
patchlevel = root.tk.call('info', 'patchlevel')
|
| 96 |
+
if patchlevel not in ('8.5.7', '8.5.9'):
|
| 97 |
+
return False
|
| 98 |
+
return ("WARNING: The version of Tcl/Tk ({0}) in use may"
|
| 99 |
+
" be unstable.\n"
|
| 100 |
+
"Visit https://www.python.org/download/mac/tcltk/"
|
| 101 |
+
" for current information.".format(patchlevel))
|
| 102 |
+
else:
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def readSystemPreferences():
|
| 107 |
+
"""
|
| 108 |
+
Fetch the macOS system preferences.
|
| 109 |
+
"""
|
| 110 |
+
if platform != 'darwin':
|
| 111 |
+
return None
|
| 112 |
+
|
| 113 |
+
plist_path = expanduser('~/Library/Preferences/.GlobalPreferences.plist')
|
| 114 |
+
try:
|
| 115 |
+
with open(plist_path, 'rb') as plist_file:
|
| 116 |
+
return plistlib.load(plist_file)
|
| 117 |
+
except OSError:
|
| 118 |
+
return None
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def preferTabsPreferenceWarning():
|
| 122 |
+
"""
|
| 123 |
+
Warn if "Prefer tabs when opening documents" is set to "Always".
|
| 124 |
+
"""
|
| 125 |
+
if platform != 'darwin':
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
+
prefs = readSystemPreferences()
|
| 129 |
+
if prefs and prefs.get('AppleWindowTabbingMode') == 'always':
|
| 130 |
+
return (
|
| 131 |
+
'WARNING: The system preference "Prefer tabs when opening'
|
| 132 |
+
' documents" is set to "Always". This will cause various problems'
|
| 133 |
+
' with IDLE. For the best experience, change this setting when'
|
| 134 |
+
' running IDLE (via System Preferences -> Dock).'
|
| 135 |
+
)
|
| 136 |
+
return None
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
## Fix the menu and related functions.
|
| 140 |
+
|
| 141 |
+
def addOpenEventSupport(root, flist):
|
| 142 |
+
"""
|
| 143 |
+
This ensures that the application will respond to open AppleEvents, which
|
| 144 |
+
makes is feasible to use IDLE as the default application for python files.
|
| 145 |
+
"""
|
| 146 |
+
def doOpenFile(*args):
|
| 147 |
+
for fn in args:
|
| 148 |
+
flist.open(fn)
|
| 149 |
+
|
| 150 |
+
# The command below is a hook in aquatk that is called whenever the app
|
| 151 |
+
# receives a file open event. The callback can have multiple arguments,
|
| 152 |
+
# one for every file that should be opened.
|
| 153 |
+
root.createcommand("::tk::mac::OpenDocument", doOpenFile)
|
| 154 |
+
|
| 155 |
+
def hideTkConsole(root):
|
| 156 |
+
try:
|
| 157 |
+
root.tk.call('console', 'hide')
|
| 158 |
+
except tkinter.TclError:
|
| 159 |
+
# Some versions of the Tk framework don't have a console object
|
| 160 |
+
pass
|
| 161 |
+
|
| 162 |
+
def overrideRootMenu(root, flist):
|
| 163 |
+
"""
|
| 164 |
+
Replace the Tk root menu by something that is more appropriate for
|
| 165 |
+
IDLE with an Aqua Tk.
|
| 166 |
+
"""
|
| 167 |
+
# The menu that is attached to the Tk root (".") is also used by AquaTk for
|
| 168 |
+
# all windows that don't specify a menu of their own. The default menubar
|
| 169 |
+
# contains a number of menus, none of which are appropriate for IDLE. The
|
| 170 |
+
# Most annoying of those is an 'About Tck/Tk...' menu in the application
|
| 171 |
+
# menu.
|
| 172 |
+
#
|
| 173 |
+
# This function replaces the default menubar by a mostly empty one, it
|
| 174 |
+
# should only contain the correct application menu and the window menu.
|
| 175 |
+
#
|
| 176 |
+
# Due to a (mis-)feature of TkAqua the user will also see an empty Help
|
| 177 |
+
# menu.
|
| 178 |
+
from tkinter import Menu
|
| 179 |
+
from idlelib import mainmenu
|
| 180 |
+
from idlelib import window
|
| 181 |
+
|
| 182 |
+
closeItem = mainmenu.menudefs[0][1][-2]
|
| 183 |
+
|
| 184 |
+
# Remove the last 3 items of the file menu: a separator, close window and
|
| 185 |
+
# quit. Close window will be reinserted just above the save item, where
|
| 186 |
+
# it should be according to the HIG. Quit is in the application menu.
|
| 187 |
+
del mainmenu.menudefs[0][1][-3:]
|
| 188 |
+
mainmenu.menudefs[0][1].insert(6, closeItem)
|
| 189 |
+
|
| 190 |
+
# Remove the 'About' entry from the help menu, it is in the application
|
| 191 |
+
# menu
|
| 192 |
+
del mainmenu.menudefs[-1][1][0:2]
|
| 193 |
+
# Remove the 'Configure Idle' entry from the options menu, it is in the
|
| 194 |
+
# application menu as 'Preferences'
|
| 195 |
+
del mainmenu.menudefs[-3][1][0:2]
|
| 196 |
+
menubar = Menu(root)
|
| 197 |
+
root.configure(menu=menubar)
|
| 198 |
+
menudict = {}
|
| 199 |
+
|
| 200 |
+
menudict['window'] = menu = Menu(menubar, name='window', tearoff=0)
|
| 201 |
+
menubar.add_cascade(label='Window', menu=menu, underline=0)
|
| 202 |
+
|
| 203 |
+
def postwindowsmenu(menu=menu):
|
| 204 |
+
end = menu.index('end')
|
| 205 |
+
if end is None:
|
| 206 |
+
end = -1
|
| 207 |
+
|
| 208 |
+
if end > 0:
|
| 209 |
+
menu.delete(0, end)
|
| 210 |
+
window.add_windows_to_menu(menu)
|
| 211 |
+
window.register_callback(postwindowsmenu)
|
| 212 |
+
|
| 213 |
+
def about_dialog(event=None):
|
| 214 |
+
"Handle Help 'About IDLE' event."
|
| 215 |
+
# Synchronize with editor.EditorWindow.about_dialog.
|
| 216 |
+
from idlelib import help_about
|
| 217 |
+
help_about.AboutDialog(root)
|
| 218 |
+
|
| 219 |
+
def config_dialog(event=None):
|
| 220 |
+
"Handle Options 'Configure IDLE' event."
|
| 221 |
+
# Synchronize with editor.EditorWindow.config_dialog.
|
| 222 |
+
from idlelib import configdialog
|
| 223 |
+
|
| 224 |
+
# Ensure that the root object has an instance_dict attribute,
|
| 225 |
+
# mirrors code in EditorWindow (although that sets the attribute
|
| 226 |
+
# on an EditorWindow instance that is then passed as the first
|
| 227 |
+
# argument to ConfigDialog)
|
| 228 |
+
root.instance_dict = flist.inversedict
|
| 229 |
+
configdialog.ConfigDialog(root, 'Settings')
|
| 230 |
+
|
| 231 |
+
def help_dialog(event=None):
|
| 232 |
+
"Handle Help 'IDLE Help' event."
|
| 233 |
+
# Synchronize with editor.EditorWindow.help_dialog.
|
| 234 |
+
from idlelib import help
|
| 235 |
+
help.show_idlehelp(root)
|
| 236 |
+
|
| 237 |
+
root.bind('<<about-idle>>', about_dialog)
|
| 238 |
+
root.bind('<<open-config-dialog>>', config_dialog)
|
| 239 |
+
root.createcommand('::tk::mac::ShowPreferences', config_dialog)
|
| 240 |
+
if flist:
|
| 241 |
+
root.bind('<<close-all-windows>>', flist.close_all_callback)
|
| 242 |
+
|
| 243 |
+
# The binding above doesn't reliably work on all versions of Tk
|
| 244 |
+
# on macOS. Adding command definition below does seem to do the
|
| 245 |
+
# right thing for now.
|
| 246 |
+
root.createcommand('exit', flist.close_all_callback)
|
| 247 |
+
|
| 248 |
+
if isCarbonTk():
|
| 249 |
+
# for Carbon AquaTk, replace the default Tk apple menu
|
| 250 |
+
menudict['application'] = menu = Menu(menubar, name='apple',
|
| 251 |
+
tearoff=0)
|
| 252 |
+
menubar.add_cascade(label='IDLE', menu=menu)
|
| 253 |
+
mainmenu.menudefs.insert(0,
|
| 254 |
+
('application', [
|
| 255 |
+
('About IDLE', '<<about-idle>>'),
|
| 256 |
+
None,
|
| 257 |
+
]))
|
| 258 |
+
if isCocoaTk():
|
| 259 |
+
# replace default About dialog with About IDLE one
|
| 260 |
+
root.createcommand('tkAboutDialog', about_dialog)
|
| 261 |
+
# replace default "Help" item in Help menu
|
| 262 |
+
root.createcommand('::tk::mac::ShowHelp', help_dialog)
|
| 263 |
+
# remove redundant "IDLE Help" from menu
|
| 264 |
+
del mainmenu.menudefs[-1][1][0]
|
| 265 |
+
|
| 266 |
+
def fixb2context(root):
|
| 267 |
+
'''Removed bad AquaTk Button-2 (right) and Paste bindings.
|
| 268 |
+
|
| 269 |
+
They prevent context menu access and seem to be gone in AquaTk8.6.
|
| 270 |
+
See issue #24801.
|
| 271 |
+
'''
|
| 272 |
+
root.unbind_class('Text', '<B2>')
|
| 273 |
+
root.unbind_class('Text', '<B2-Motion>')
|
| 274 |
+
root.unbind_class('Text', '<<PasteSelection>>')
|
| 275 |
+
|
| 276 |
+
def setupApp(root, flist):
|
| 277 |
+
"""
|
| 278 |
+
Perform initial OS X customizations if needed.
|
| 279 |
+
Called from pyshell.main() after initial calls to Tk()
|
| 280 |
+
|
| 281 |
+
There are currently three major versions of Tk in use on OS X:
|
| 282 |
+
1. Aqua Cocoa Tk (native default since OS X 10.6)
|
| 283 |
+
2. Aqua Carbon Tk (original native, 32-bit only, deprecated)
|
| 284 |
+
3. X11 (supported by some third-party distributors, deprecated)
|
| 285 |
+
There are various differences among the three that affect IDLE
|
| 286 |
+
behavior, primarily with menus, mouse key events, and accelerators.
|
| 287 |
+
Some one-time customizations are performed here.
|
| 288 |
+
Others are dynamically tested throughout idlelib by calls to the
|
| 289 |
+
isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
|
| 290 |
+
are initialized here as well.
|
| 291 |
+
"""
|
| 292 |
+
if isAquaTk():
|
| 293 |
+
hideTkConsole(root)
|
| 294 |
+
overrideRootMenu(root, flist)
|
| 295 |
+
addOpenEventSupport(root, flist)
|
| 296 |
+
fixb2context(root)
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
if __name__ == '__main__':
|
| 300 |
+
from unittest import main
|
| 301 |
+
main('idlelib.idle_test.test_macosx', verbosity=2)
|
evalkit_tf446/lib/python3.10/idlelib/mainmenu.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define the menu contents, hotkeys, and event bindings.
|
| 2 |
+
|
| 3 |
+
There is additional configuration information in the EditorWindow class (and
|
| 4 |
+
subclasses): the menus are created there based on the menu_specs (class)
|
| 5 |
+
variable, and menus not created are silently skipped in the code here. This
|
| 6 |
+
makes it possible, for example, to define a Debug menu which is only present in
|
| 7 |
+
the PythonShell window, and a Format menu which is only present in the Editor
|
| 8 |
+
windows.
|
| 9 |
+
|
| 10 |
+
"""
|
| 11 |
+
from importlib.util import find_spec
|
| 12 |
+
|
| 13 |
+
from idlelib.config import idleConf
|
| 14 |
+
|
| 15 |
+
# Warning: menudefs is altered in macosx.overrideRootMenu()
|
| 16 |
+
# after it is determined that an OS X Aqua Tk is in use,
|
| 17 |
+
# which cannot be done until after Tk() is first called.
|
| 18 |
+
# Do not alter the 'file', 'options', or 'help' cascades here
|
| 19 |
+
# without altering overrideRootMenu() as well.
|
| 20 |
+
# TODO: Make this more robust
|
| 21 |
+
|
| 22 |
+
menudefs = [
|
| 23 |
+
# underscore prefixes character to underscore
|
| 24 |
+
('file', [
|
| 25 |
+
('_New File', '<<open-new-window>>'),
|
| 26 |
+
('_Open...', '<<open-window-from-file>>'),
|
| 27 |
+
('Open _Module...', '<<open-module>>'),
|
| 28 |
+
('Module _Browser', '<<open-class-browser>>'),
|
| 29 |
+
('_Path Browser', '<<open-path-browser>>'),
|
| 30 |
+
None,
|
| 31 |
+
('_Save', '<<save-window>>'),
|
| 32 |
+
('Save _As...', '<<save-window-as-file>>'),
|
| 33 |
+
('Save Cop_y As...', '<<save-copy-of-window-as-file>>'),
|
| 34 |
+
None,
|
| 35 |
+
('Prin_t Window', '<<print-window>>'),
|
| 36 |
+
None,
|
| 37 |
+
('_Close Window', '<<close-window>>'),
|
| 38 |
+
('E_xit IDLE', '<<close-all-windows>>'),
|
| 39 |
+
]),
|
| 40 |
+
|
| 41 |
+
('edit', [
|
| 42 |
+
('_Undo', '<<undo>>'),
|
| 43 |
+
('_Redo', '<<redo>>'),
|
| 44 |
+
None,
|
| 45 |
+
('Select _All', '<<select-all>>'),
|
| 46 |
+
('Cu_t', '<<cut>>'),
|
| 47 |
+
('_Copy', '<<copy>>'),
|
| 48 |
+
('_Paste', '<<paste>>'),
|
| 49 |
+
None,
|
| 50 |
+
('_Find...', '<<find>>'),
|
| 51 |
+
('Find A_gain', '<<find-again>>'),
|
| 52 |
+
('Find _Selection', '<<find-selection>>'),
|
| 53 |
+
('Find in Files...', '<<find-in-files>>'),
|
| 54 |
+
('R_eplace...', '<<replace>>'),
|
| 55 |
+
None,
|
| 56 |
+
('Go to _Line', '<<goto-line>>'),
|
| 57 |
+
('S_how Completions', '<<force-open-completions>>'),
|
| 58 |
+
('E_xpand Word', '<<expand-word>>'),
|
| 59 |
+
('Show C_all Tip', '<<force-open-calltip>>'),
|
| 60 |
+
('Show Surrounding P_arens', '<<flash-paren>>'),
|
| 61 |
+
]),
|
| 62 |
+
|
| 63 |
+
('format', [
|
| 64 |
+
('F_ormat Paragraph', '<<format-paragraph>>'),
|
| 65 |
+
('_Indent Region', '<<indent-region>>'),
|
| 66 |
+
('_Dedent Region', '<<dedent-region>>'),
|
| 67 |
+
('Comment _Out Region', '<<comment-region>>'),
|
| 68 |
+
('U_ncomment Region', '<<uncomment-region>>'),
|
| 69 |
+
('Tabify Region', '<<tabify-region>>'),
|
| 70 |
+
('Untabify Region', '<<untabify-region>>'),
|
| 71 |
+
('Toggle Tabs', '<<toggle-tabs>>'),
|
| 72 |
+
('New Indent Width', '<<change-indentwidth>>'),
|
| 73 |
+
('S_trip Trailing Whitespace', '<<do-rstrip>>'),
|
| 74 |
+
]),
|
| 75 |
+
|
| 76 |
+
('run', [
|
| 77 |
+
('R_un Module', '<<run-module>>'),
|
| 78 |
+
('Run... _Customized', '<<run-custom>>'),
|
| 79 |
+
('C_heck Module', '<<check-module>>'),
|
| 80 |
+
('Python Shell', '<<open-python-shell>>'),
|
| 81 |
+
]),
|
| 82 |
+
|
| 83 |
+
('shell', [
|
| 84 |
+
('_View Last Restart', '<<view-restart>>'),
|
| 85 |
+
('_Restart Shell', '<<restart-shell>>'),
|
| 86 |
+
None,
|
| 87 |
+
('_Previous History', '<<history-previous>>'),
|
| 88 |
+
('_Next History', '<<history-next>>'),
|
| 89 |
+
None,
|
| 90 |
+
('_Interrupt Execution', '<<interrupt-execution>>'),
|
| 91 |
+
]),
|
| 92 |
+
|
| 93 |
+
('debug', [
|
| 94 |
+
('_Go to File/Line', '<<goto-file-line>>'),
|
| 95 |
+
('!_Debugger', '<<toggle-debugger>>'),
|
| 96 |
+
('_Stack Viewer', '<<open-stack-viewer>>'),
|
| 97 |
+
('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
|
| 98 |
+
]),
|
| 99 |
+
|
| 100 |
+
('options', [
|
| 101 |
+
('Configure _IDLE', '<<open-config-dialog>>'),
|
| 102 |
+
None,
|
| 103 |
+
('Show _Code Context', '<<toggle-code-context>>'),
|
| 104 |
+
('Show _Line Numbers', '<<toggle-line-numbers>>'),
|
| 105 |
+
('_Zoom Height', '<<zoom-height>>'),
|
| 106 |
+
]),
|
| 107 |
+
|
| 108 |
+
('window', [
|
| 109 |
+
]),
|
| 110 |
+
|
| 111 |
+
('help', [
|
| 112 |
+
('_About IDLE', '<<about-idle>>'),
|
| 113 |
+
None,
|
| 114 |
+
('_IDLE Doc', '<<help>>'),
|
| 115 |
+
('Python _Docs', '<<python-docs>>'),
|
| 116 |
+
]),
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
if find_spec('turtledemo'):
|
| 120 |
+
menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
|
| 121 |
+
|
| 122 |
+
default_keydefs = idleConf.GetCurrentKeySet()
|
| 123 |
+
|
| 124 |
+
if __name__ == '__main__':
|
| 125 |
+
from unittest import main
|
| 126 |
+
main('idlelib.idle_test.test_mainmenu', verbosity=2)
|
evalkit_tf446/lib/python3.10/idlelib/outwin.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Editor window that can serve as an output file.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from tkinter import messagebox
|
| 7 |
+
|
| 8 |
+
from idlelib.editor import EditorWindow
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
file_line_pats = [
|
| 12 |
+
# order of patterns matters
|
| 13 |
+
r'file "([^"]*)", line (\d+)',
|
| 14 |
+
r'([^\s]+)\((\d+)\)',
|
| 15 |
+
r'^(\s*\S.*?):\s*(\d+):', # Win filename, maybe starting with spaces
|
| 16 |
+
r'([^\s]+):\s*(\d+):', # filename or path, ltrim
|
| 17 |
+
r'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
file_line_progs = None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def compile_progs():
|
| 24 |
+
"Compile the patterns for matching to file name and line number."
|
| 25 |
+
global file_line_progs
|
| 26 |
+
file_line_progs = [re.compile(pat, re.IGNORECASE)
|
| 27 |
+
for pat in file_line_pats]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def file_line_helper(line):
|
| 31 |
+
"""Extract file name and line number from line of text.
|
| 32 |
+
|
| 33 |
+
Check if line of text contains one of the file/line patterns.
|
| 34 |
+
If it does and if the file and line are valid, return
|
| 35 |
+
a tuple of the file name and line number. If it doesn't match
|
| 36 |
+
or if the file or line is invalid, return None.
|
| 37 |
+
"""
|
| 38 |
+
if not file_line_progs:
|
| 39 |
+
compile_progs()
|
| 40 |
+
for prog in file_line_progs:
|
| 41 |
+
match = prog.search(line)
|
| 42 |
+
if match:
|
| 43 |
+
filename, lineno = match.group(1, 2)
|
| 44 |
+
try:
|
| 45 |
+
f = open(filename, "r")
|
| 46 |
+
f.close()
|
| 47 |
+
break
|
| 48 |
+
except OSError:
|
| 49 |
+
continue
|
| 50 |
+
else:
|
| 51 |
+
return None
|
| 52 |
+
try:
|
| 53 |
+
return filename, int(lineno)
|
| 54 |
+
except TypeError:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class OutputWindow(EditorWindow):
|
| 59 |
+
"""An editor window that can serve as an output file.
|
| 60 |
+
|
| 61 |
+
Also the future base class for the Python shell window.
|
| 62 |
+
This class has no input facilities.
|
| 63 |
+
|
| 64 |
+
Adds binding to open a file at a line to the text widget.
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
# Our own right-button menu
|
| 68 |
+
rmenu_specs = [
|
| 69 |
+
("Cut", "<<cut>>", "rmenu_check_cut"),
|
| 70 |
+
("Copy", "<<copy>>", "rmenu_check_copy"),
|
| 71 |
+
("Paste", "<<paste>>", "rmenu_check_paste"),
|
| 72 |
+
(None, None, None),
|
| 73 |
+
("Go to file/line", "<<goto-file-line>>", None),
|
| 74 |
+
]
|
| 75 |
+
|
| 76 |
+
allow_code_context = False
|
| 77 |
+
|
| 78 |
+
def __init__(self, *args):
|
| 79 |
+
EditorWindow.__init__(self, *args)
|
| 80 |
+
self.text.bind("<<goto-file-line>>", self.goto_file_line)
|
| 81 |
+
|
| 82 |
+
# Customize EditorWindow
|
| 83 |
+
def ispythonsource(self, filename):
|
| 84 |
+
"Python source is only part of output: do not colorize."
|
| 85 |
+
return False
|
| 86 |
+
|
| 87 |
+
def short_title(self):
|
| 88 |
+
"Customize EditorWindow title."
|
| 89 |
+
return "Output"
|
| 90 |
+
|
| 91 |
+
def maybesave(self):
|
| 92 |
+
"Customize EditorWindow to not display save file messagebox."
|
| 93 |
+
return 'yes' if self.get_saved() else 'no'
|
| 94 |
+
|
| 95 |
+
# Act as output file
|
| 96 |
+
def write(self, s, tags=(), mark="insert"):
|
| 97 |
+
"""Write text to text widget.
|
| 98 |
+
|
| 99 |
+
The text is inserted at the given index with the provided
|
| 100 |
+
tags. The text widget is then scrolled to make it visible
|
| 101 |
+
and updated to display it, giving the effect of seeing each
|
| 102 |
+
line as it is added.
|
| 103 |
+
|
| 104 |
+
Args:
|
| 105 |
+
s: Text to insert into text widget.
|
| 106 |
+
tags: Tuple of tag strings to apply on the insert.
|
| 107 |
+
mark: Index for the insert.
|
| 108 |
+
|
| 109 |
+
Return:
|
| 110 |
+
Length of text inserted.
|
| 111 |
+
"""
|
| 112 |
+
assert isinstance(s, str)
|
| 113 |
+
self.text.insert(mark, s, tags)
|
| 114 |
+
self.text.see(mark)
|
| 115 |
+
self.text.update()
|
| 116 |
+
return len(s)
|
| 117 |
+
|
| 118 |
+
def writelines(self, lines):
|
| 119 |
+
"Write each item in lines iterable."
|
| 120 |
+
for line in lines:
|
| 121 |
+
self.write(line)
|
| 122 |
+
|
| 123 |
+
def flush(self):
|
| 124 |
+
"No flushing needed as write() directly writes to widget."
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
def showerror(self, *args, **kwargs):
|
| 128 |
+
messagebox.showerror(*args, **kwargs)
|
| 129 |
+
|
| 130 |
+
def goto_file_line(self, event=None):
|
| 131 |
+
"""Handle request to open file/line.
|
| 132 |
+
|
| 133 |
+
If the selected or previous line in the output window
|
| 134 |
+
contains a file name and line number, then open that file
|
| 135 |
+
name in a new window and position on the line number.
|
| 136 |
+
|
| 137 |
+
Otherwise, display an error messagebox.
|
| 138 |
+
"""
|
| 139 |
+
line = self.text.get("insert linestart", "insert lineend")
|
| 140 |
+
result = file_line_helper(line)
|
| 141 |
+
if not result:
|
| 142 |
+
# Try the previous line. This is handy e.g. in tracebacks,
|
| 143 |
+
# where you tend to right-click on the displayed source line
|
| 144 |
+
line = self.text.get("insert -1line linestart",
|
| 145 |
+
"insert -1line lineend")
|
| 146 |
+
result = file_line_helper(line)
|
| 147 |
+
if not result:
|
| 148 |
+
self.showerror(
|
| 149 |
+
"No special line",
|
| 150 |
+
"The line you point at doesn't look like "
|
| 151 |
+
"a valid file name followed by a line number.",
|
| 152 |
+
parent=self.text)
|
| 153 |
+
return
|
| 154 |
+
filename, lineno = result
|
| 155 |
+
self.flist.gotofileline(filename, lineno)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
# These classes are currently not used but might come in handy
|
| 159 |
+
class OnDemandOutputWindow:
|
| 160 |
+
|
| 161 |
+
tagdefs = {
|
| 162 |
+
# XXX Should use IdlePrefs.ColorPrefs
|
| 163 |
+
"stdout": {"foreground": "blue"},
|
| 164 |
+
"stderr": {"foreground": "#007700"},
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
def __init__(self, flist):
|
| 168 |
+
self.flist = flist
|
| 169 |
+
self.owin = None
|
| 170 |
+
|
| 171 |
+
def write(self, s, tags, mark):
|
| 172 |
+
if not self.owin:
|
| 173 |
+
self.setup()
|
| 174 |
+
self.owin.write(s, tags, mark)
|
| 175 |
+
|
| 176 |
+
def setup(self):
|
| 177 |
+
self.owin = owin = OutputWindow(self.flist)
|
| 178 |
+
text = owin.text
|
| 179 |
+
for tag, cnf in self.tagdefs.items():
|
| 180 |
+
if cnf:
|
| 181 |
+
text.tag_configure(tag, **cnf)
|
| 182 |
+
text.tag_raise('sel')
|
| 183 |
+
self.write = self.owin.write
|
| 184 |
+
|
| 185 |
+
if __name__ == '__main__':
|
| 186 |
+
from unittest import main
|
| 187 |
+
main('idlelib.idle_test.test_outwin', verbosity=2, exit=False)
|
evalkit_tf446/lib/python3.10/idlelib/percolator.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from idlelib.delegator import Delegator
|
| 2 |
+
from idlelib.redirector import WidgetRedirector
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class Percolator:
|
| 6 |
+
|
| 7 |
+
def __init__(self, text):
|
| 8 |
+
# XXX would be nice to inherit from Delegator
|
| 9 |
+
self.text = text
|
| 10 |
+
self.redir = WidgetRedirector(text)
|
| 11 |
+
self.top = self.bottom = Delegator(text)
|
| 12 |
+
self.bottom.insert = self.redir.register("insert", self.insert)
|
| 13 |
+
self.bottom.delete = self.redir.register("delete", self.delete)
|
| 14 |
+
self.filters = []
|
| 15 |
+
|
| 16 |
+
def close(self):
|
| 17 |
+
while self.top is not self.bottom:
|
| 18 |
+
self.removefilter(self.top)
|
| 19 |
+
self.top = None
|
| 20 |
+
self.bottom.setdelegate(None)
|
| 21 |
+
self.bottom = None
|
| 22 |
+
self.redir.close()
|
| 23 |
+
self.redir = None
|
| 24 |
+
self.text = None
|
| 25 |
+
|
| 26 |
+
def insert(self, index, chars, tags=None):
|
| 27 |
+
# Could go away if inheriting from Delegator
|
| 28 |
+
self.top.insert(index, chars, tags)
|
| 29 |
+
|
| 30 |
+
def delete(self, index1, index2=None):
|
| 31 |
+
# Could go away if inheriting from Delegator
|
| 32 |
+
self.top.delete(index1, index2)
|
| 33 |
+
|
| 34 |
+
def insertfilter(self, filter):
|
| 35 |
+
# Perhaps rename to pushfilter()?
|
| 36 |
+
assert isinstance(filter, Delegator)
|
| 37 |
+
assert filter.delegate is None
|
| 38 |
+
filter.setdelegate(self.top)
|
| 39 |
+
self.top = filter
|
| 40 |
+
|
| 41 |
+
def insertfilterafter(self, filter, after):
|
| 42 |
+
assert isinstance(filter, Delegator)
|
| 43 |
+
assert isinstance(after, Delegator)
|
| 44 |
+
assert filter.delegate is None
|
| 45 |
+
|
| 46 |
+
f = self.top
|
| 47 |
+
f.resetcache()
|
| 48 |
+
while f is not after:
|
| 49 |
+
assert f is not self.bottom
|
| 50 |
+
f = f.delegate
|
| 51 |
+
f.resetcache()
|
| 52 |
+
|
| 53 |
+
filter.setdelegate(f.delegate)
|
| 54 |
+
f.setdelegate(filter)
|
| 55 |
+
|
| 56 |
+
def removefilter(self, filter):
|
| 57 |
+
# XXX Perhaps should only support popfilter()?
|
| 58 |
+
assert isinstance(filter, Delegator)
|
| 59 |
+
assert filter.delegate is not None
|
| 60 |
+
f = self.top
|
| 61 |
+
if f is filter:
|
| 62 |
+
self.top = filter.delegate
|
| 63 |
+
filter.setdelegate(None)
|
| 64 |
+
else:
|
| 65 |
+
while f.delegate is not filter:
|
| 66 |
+
assert f is not self.bottom
|
| 67 |
+
f.resetcache()
|
| 68 |
+
f = f.delegate
|
| 69 |
+
f.setdelegate(filter.delegate)
|
| 70 |
+
filter.setdelegate(None)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _percolator(parent): # htest #
|
| 74 |
+
import tkinter as tk
|
| 75 |
+
|
| 76 |
+
class Tracer(Delegator):
|
| 77 |
+
def __init__(self, name):
|
| 78 |
+
self.name = name
|
| 79 |
+
Delegator.__init__(self, None)
|
| 80 |
+
|
| 81 |
+
def insert(self, *args):
|
| 82 |
+
print(self.name, ": insert", args)
|
| 83 |
+
self.delegate.insert(*args)
|
| 84 |
+
|
| 85 |
+
def delete(self, *args):
|
| 86 |
+
print(self.name, ": delete", args)
|
| 87 |
+
self.delegate.delete(*args)
|
| 88 |
+
|
| 89 |
+
box = tk.Toplevel(parent)
|
| 90 |
+
box.title("Test Percolator")
|
| 91 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 92 |
+
box.geometry("+%d+%d" % (x, y + 175))
|
| 93 |
+
text = tk.Text(box)
|
| 94 |
+
p = Percolator(text)
|
| 95 |
+
pin = p.insertfilter
|
| 96 |
+
pout = p.removefilter
|
| 97 |
+
t1 = Tracer("t1")
|
| 98 |
+
t2 = Tracer("t2")
|
| 99 |
+
|
| 100 |
+
def toggle1():
|
| 101 |
+
(pin if var1.get() else pout)(t1)
|
| 102 |
+
def toggle2():
|
| 103 |
+
(pin if var2.get() else pout)(t2)
|
| 104 |
+
|
| 105 |
+
text.pack()
|
| 106 |
+
var1 = tk.IntVar(parent)
|
| 107 |
+
cb1 = tk.Checkbutton(box, text="Tracer1", command=toggle1, variable=var1)
|
| 108 |
+
cb1.pack()
|
| 109 |
+
var2 = tk.IntVar(parent)
|
| 110 |
+
cb2 = tk.Checkbutton(box, text="Tracer2", command=toggle2, variable=var2)
|
| 111 |
+
cb2.pack()
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
from unittest import main
|
| 115 |
+
main('idlelib.idle_test.test_percolator', verbosity=2, exit=False)
|
| 116 |
+
|
| 117 |
+
from idlelib.idle_test.htest import run
|
| 118 |
+
run(_percolator)
|
evalkit_tf446/lib/python3.10/idlelib/pyshell.py
ADDED
|
@@ -0,0 +1,1713 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#! /usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
if __name__ == "__main__":
|
| 5 |
+
sys.modules['idlelib.pyshell'] = sys.modules['__main__']
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
from tkinter import *
|
| 9 |
+
except ImportError:
|
| 10 |
+
print("** IDLE can't import Tkinter.\n"
|
| 11 |
+
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
|
| 12 |
+
raise SystemExit(1)
|
| 13 |
+
|
| 14 |
+
# Valid arguments for the ...Awareness call below are defined in the following.
|
| 15 |
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx
|
| 16 |
+
if sys.platform == 'win32':
|
| 17 |
+
try:
|
| 18 |
+
import ctypes
|
| 19 |
+
PROCESS_SYSTEM_DPI_AWARE = 1 # Int required.
|
| 20 |
+
ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
|
| 21 |
+
except (ImportError, AttributeError, OSError):
|
| 22 |
+
pass
|
| 23 |
+
|
| 24 |
+
from tkinter import messagebox
|
| 25 |
+
if TkVersion < 8.5:
|
| 26 |
+
root = Tk() # otherwise create root in main
|
| 27 |
+
root.withdraw()
|
| 28 |
+
from idlelib.run import fix_scaling
|
| 29 |
+
fix_scaling(root)
|
| 30 |
+
messagebox.showerror("Idle Cannot Start",
|
| 31 |
+
"Idle requires tcl/tk 8.5+, not %s." % TkVersion,
|
| 32 |
+
parent=root)
|
| 33 |
+
raise SystemExit(1)
|
| 34 |
+
|
| 35 |
+
from code import InteractiveInterpreter
|
| 36 |
+
import itertools
|
| 37 |
+
import linecache
|
| 38 |
+
import os
|
| 39 |
+
import os.path
|
| 40 |
+
from platform import python_version
|
| 41 |
+
import re
|
| 42 |
+
import socket
|
| 43 |
+
import subprocess
|
| 44 |
+
from textwrap import TextWrapper
|
| 45 |
+
import threading
|
| 46 |
+
import time
|
| 47 |
+
import tokenize
|
| 48 |
+
import warnings
|
| 49 |
+
|
| 50 |
+
from idlelib.colorizer import ColorDelegator
|
| 51 |
+
from idlelib.config import idleConf
|
| 52 |
+
from idlelib.delegator import Delegator
|
| 53 |
+
from idlelib import debugger
|
| 54 |
+
from idlelib import debugger_r
|
| 55 |
+
from idlelib.editor import EditorWindow, fixwordbreaks
|
| 56 |
+
from idlelib.filelist import FileList
|
| 57 |
+
from idlelib.outwin import OutputWindow
|
| 58 |
+
from idlelib import replace
|
| 59 |
+
from idlelib import rpc
|
| 60 |
+
from idlelib.run import idle_formatwarning, StdInputFile, StdOutputFile
|
| 61 |
+
from idlelib.undo import UndoDelegator
|
| 62 |
+
|
| 63 |
+
# Default for testing; defaults to True in main() for running.
|
| 64 |
+
use_subprocess = False
|
| 65 |
+
|
| 66 |
+
HOST = '127.0.0.1' # python execution server on localhost loopback
|
| 67 |
+
PORT = 0 # someday pass in host, port for remote debug capability
|
| 68 |
+
|
| 69 |
+
try: # In case IDLE started with -n.
|
| 70 |
+
eof = 'Ctrl-D (end-of-file)'
|
| 71 |
+
exit.eof = eof
|
| 72 |
+
quit.eof = eof
|
| 73 |
+
except NameError: # In case python started with -S.
|
| 74 |
+
pass
|
| 75 |
+
|
| 76 |
+
# Override warnings module to write to warning_stream. Initialize to send IDLE
|
| 77 |
+
# internal warnings to the console. ScriptBinding.check_syntax() will
|
| 78 |
+
# temporarily redirect the stream to the shell window to display warnings when
|
| 79 |
+
# checking user's code.
|
| 80 |
+
warning_stream = sys.__stderr__ # None, at least on Windows, if no console.
|
| 81 |
+
|
| 82 |
+
def idle_showwarning(
|
| 83 |
+
message, category, filename, lineno, file=None, line=None):
|
| 84 |
+
"""Show Idle-format warning (after replacing warnings.showwarning).
|
| 85 |
+
|
| 86 |
+
The differences are the formatter called, the file=None replacement,
|
| 87 |
+
which can be None, the capture of the consequence AttributeError,
|
| 88 |
+
and the output of a hard-coded prompt.
|
| 89 |
+
"""
|
| 90 |
+
if file is None:
|
| 91 |
+
file = warning_stream
|
| 92 |
+
try:
|
| 93 |
+
file.write(idle_formatwarning(
|
| 94 |
+
message, category, filename, lineno, line=line))
|
| 95 |
+
file.write(">>> ")
|
| 96 |
+
except (AttributeError, OSError):
|
| 97 |
+
pass # if file (probably __stderr__) is invalid, skip warning.
|
| 98 |
+
|
| 99 |
+
_warnings_showwarning = None
|
| 100 |
+
|
| 101 |
+
def capture_warnings(capture):
|
| 102 |
+
"Replace warning.showwarning with idle_showwarning, or reverse."
|
| 103 |
+
|
| 104 |
+
global _warnings_showwarning
|
| 105 |
+
if capture:
|
| 106 |
+
if _warnings_showwarning is None:
|
| 107 |
+
_warnings_showwarning = warnings.showwarning
|
| 108 |
+
warnings.showwarning = idle_showwarning
|
| 109 |
+
else:
|
| 110 |
+
if _warnings_showwarning is not None:
|
| 111 |
+
warnings.showwarning = _warnings_showwarning
|
| 112 |
+
_warnings_showwarning = None
|
| 113 |
+
|
| 114 |
+
capture_warnings(True)
|
| 115 |
+
|
| 116 |
+
def extended_linecache_checkcache(filename=None,
|
| 117 |
+
orig_checkcache=linecache.checkcache):
|
| 118 |
+
"""Extend linecache.checkcache to preserve the <pyshell#...> entries
|
| 119 |
+
|
| 120 |
+
Rather than repeating the linecache code, patch it to save the
|
| 121 |
+
<pyshell#...> entries, call the original linecache.checkcache()
|
| 122 |
+
(skipping them), and then restore the saved entries.
|
| 123 |
+
|
| 124 |
+
orig_checkcache is bound at definition time to the original
|
| 125 |
+
method, allowing it to be patched.
|
| 126 |
+
"""
|
| 127 |
+
cache = linecache.cache
|
| 128 |
+
save = {}
|
| 129 |
+
for key in list(cache):
|
| 130 |
+
if key[:1] + key[-1:] == '<>':
|
| 131 |
+
save[key] = cache.pop(key)
|
| 132 |
+
orig_checkcache(filename)
|
| 133 |
+
cache.update(save)
|
| 134 |
+
|
| 135 |
+
# Patch linecache.checkcache():
|
| 136 |
+
linecache.checkcache = extended_linecache_checkcache
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class PyShellEditorWindow(EditorWindow):
|
| 140 |
+
"Regular text edit window in IDLE, supports breakpoints"
|
| 141 |
+
|
| 142 |
+
def __init__(self, *args):
|
| 143 |
+
self.breakpoints = []
|
| 144 |
+
EditorWindow.__init__(self, *args)
|
| 145 |
+
self.text.bind("<<set-breakpoint-here>>", self.set_breakpoint_here)
|
| 146 |
+
self.text.bind("<<clear-breakpoint-here>>", self.clear_breakpoint_here)
|
| 147 |
+
self.text.bind("<<open-python-shell>>", self.flist.open_shell)
|
| 148 |
+
|
| 149 |
+
#TODO: don't read/write this from/to .idlerc when testing
|
| 150 |
+
self.breakpointPath = os.path.join(
|
| 151 |
+
idleConf.userdir, 'breakpoints.lst')
|
| 152 |
+
# whenever a file is changed, restore breakpoints
|
| 153 |
+
def filename_changed_hook(old_hook=self.io.filename_change_hook,
|
| 154 |
+
self=self):
|
| 155 |
+
self.restore_file_breaks()
|
| 156 |
+
old_hook()
|
| 157 |
+
self.io.set_filename_change_hook(filename_changed_hook)
|
| 158 |
+
if self.io.filename:
|
| 159 |
+
self.restore_file_breaks()
|
| 160 |
+
self.color_breakpoint_text()
|
| 161 |
+
|
| 162 |
+
rmenu_specs = [
|
| 163 |
+
("Cut", "<<cut>>", "rmenu_check_cut"),
|
| 164 |
+
("Copy", "<<copy>>", "rmenu_check_copy"),
|
| 165 |
+
("Paste", "<<paste>>", "rmenu_check_paste"),
|
| 166 |
+
(None, None, None),
|
| 167 |
+
("Set Breakpoint", "<<set-breakpoint-here>>", None),
|
| 168 |
+
("Clear Breakpoint", "<<clear-breakpoint-here>>", None)
|
| 169 |
+
]
|
| 170 |
+
|
| 171 |
+
def color_breakpoint_text(self, color=True):
|
| 172 |
+
"Turn colorizing of breakpoint text on or off"
|
| 173 |
+
if self.io is None:
|
| 174 |
+
# possible due to update in restore_file_breaks
|
| 175 |
+
return
|
| 176 |
+
if color:
|
| 177 |
+
theme = idleConf.CurrentTheme()
|
| 178 |
+
cfg = idleConf.GetHighlight(theme, "break")
|
| 179 |
+
else:
|
| 180 |
+
cfg = {'foreground': '', 'background': ''}
|
| 181 |
+
self.text.tag_config('BREAK', cfg)
|
| 182 |
+
|
| 183 |
+
def set_breakpoint(self, lineno):
|
| 184 |
+
text = self.text
|
| 185 |
+
filename = self.io.filename
|
| 186 |
+
text.tag_add("BREAK", "%d.0" % lineno, "%d.0" % (lineno+1))
|
| 187 |
+
try:
|
| 188 |
+
self.breakpoints.index(lineno)
|
| 189 |
+
except ValueError: # only add if missing, i.e. do once
|
| 190 |
+
self.breakpoints.append(lineno)
|
| 191 |
+
try: # update the subprocess debugger
|
| 192 |
+
debug = self.flist.pyshell.interp.debugger
|
| 193 |
+
debug.set_breakpoint_here(filename, lineno)
|
| 194 |
+
except: # but debugger may not be active right now....
|
| 195 |
+
pass
|
| 196 |
+
|
| 197 |
+
def set_breakpoint_here(self, event=None):
|
| 198 |
+
text = self.text
|
| 199 |
+
filename = self.io.filename
|
| 200 |
+
if not filename:
|
| 201 |
+
text.bell()
|
| 202 |
+
return
|
| 203 |
+
lineno = int(float(text.index("insert")))
|
| 204 |
+
self.set_breakpoint(lineno)
|
| 205 |
+
|
| 206 |
+
def clear_breakpoint_here(self, event=None):
|
| 207 |
+
text = self.text
|
| 208 |
+
filename = self.io.filename
|
| 209 |
+
if not filename:
|
| 210 |
+
text.bell()
|
| 211 |
+
return
|
| 212 |
+
lineno = int(float(text.index("insert")))
|
| 213 |
+
try:
|
| 214 |
+
self.breakpoints.remove(lineno)
|
| 215 |
+
except:
|
| 216 |
+
pass
|
| 217 |
+
text.tag_remove("BREAK", "insert linestart",\
|
| 218 |
+
"insert lineend +1char")
|
| 219 |
+
try:
|
| 220 |
+
debug = self.flist.pyshell.interp.debugger
|
| 221 |
+
debug.clear_breakpoint_here(filename, lineno)
|
| 222 |
+
except:
|
| 223 |
+
pass
|
| 224 |
+
|
| 225 |
+
def clear_file_breaks(self):
|
| 226 |
+
if self.breakpoints:
|
| 227 |
+
text = self.text
|
| 228 |
+
filename = self.io.filename
|
| 229 |
+
if not filename:
|
| 230 |
+
text.bell()
|
| 231 |
+
return
|
| 232 |
+
self.breakpoints = []
|
| 233 |
+
text.tag_remove("BREAK", "1.0", END)
|
| 234 |
+
try:
|
| 235 |
+
debug = self.flist.pyshell.interp.debugger
|
| 236 |
+
debug.clear_file_breaks(filename)
|
| 237 |
+
except:
|
| 238 |
+
pass
|
| 239 |
+
|
| 240 |
+
def store_file_breaks(self):
|
| 241 |
+
"Save breakpoints when file is saved"
|
| 242 |
+
# XXX 13 Dec 2002 KBK Currently the file must be saved before it can
|
| 243 |
+
# be run. The breaks are saved at that time. If we introduce
|
| 244 |
+
# a temporary file save feature the save breaks functionality
|
| 245 |
+
# needs to be re-verified, since the breaks at the time the
|
| 246 |
+
# temp file is created may differ from the breaks at the last
|
| 247 |
+
# permanent save of the file. Currently, a break introduced
|
| 248 |
+
# after a save will be effective, but not persistent.
|
| 249 |
+
# This is necessary to keep the saved breaks synched with the
|
| 250 |
+
# saved file.
|
| 251 |
+
#
|
| 252 |
+
# Breakpoints are set as tagged ranges in the text.
|
| 253 |
+
# Since a modified file has to be saved before it is
|
| 254 |
+
# run, and since self.breakpoints (from which the subprocess
|
| 255 |
+
# debugger is loaded) is updated during the save, the visible
|
| 256 |
+
# breaks stay synched with the subprocess even if one of these
|
| 257 |
+
# unexpected breakpoint deletions occurs.
|
| 258 |
+
breaks = self.breakpoints
|
| 259 |
+
filename = self.io.filename
|
| 260 |
+
try:
|
| 261 |
+
with open(self.breakpointPath, "r") as fp:
|
| 262 |
+
lines = fp.readlines()
|
| 263 |
+
except OSError:
|
| 264 |
+
lines = []
|
| 265 |
+
try:
|
| 266 |
+
with open(self.breakpointPath, "w") as new_file:
|
| 267 |
+
for line in lines:
|
| 268 |
+
if not line.startswith(filename + '='):
|
| 269 |
+
new_file.write(line)
|
| 270 |
+
self.update_breakpoints()
|
| 271 |
+
breaks = self.breakpoints
|
| 272 |
+
if breaks:
|
| 273 |
+
new_file.write(filename + '=' + str(breaks) + '\n')
|
| 274 |
+
except OSError as err:
|
| 275 |
+
if not getattr(self.root, "breakpoint_error_displayed", False):
|
| 276 |
+
self.root.breakpoint_error_displayed = True
|
| 277 |
+
messagebox.showerror(title='IDLE Error',
|
| 278 |
+
message='Unable to update breakpoint list:\n%s'
|
| 279 |
+
% str(err),
|
| 280 |
+
parent=self.text)
|
| 281 |
+
|
| 282 |
+
def restore_file_breaks(self):
|
| 283 |
+
self.text.update() # this enables setting "BREAK" tags to be visible
|
| 284 |
+
if self.io is None:
|
| 285 |
+
# can happen if IDLE closes due to the .update() call
|
| 286 |
+
return
|
| 287 |
+
filename = self.io.filename
|
| 288 |
+
if filename is None:
|
| 289 |
+
return
|
| 290 |
+
if os.path.isfile(self.breakpointPath):
|
| 291 |
+
with open(self.breakpointPath, "r") as fp:
|
| 292 |
+
lines = fp.readlines()
|
| 293 |
+
for line in lines:
|
| 294 |
+
if line.startswith(filename + '='):
|
| 295 |
+
breakpoint_linenumbers = eval(line[len(filename)+1:])
|
| 296 |
+
for breakpoint_linenumber in breakpoint_linenumbers:
|
| 297 |
+
self.set_breakpoint(breakpoint_linenumber)
|
| 298 |
+
|
| 299 |
+
def update_breakpoints(self):
|
| 300 |
+
"Retrieves all the breakpoints in the current window"
|
| 301 |
+
text = self.text
|
| 302 |
+
ranges = text.tag_ranges("BREAK")
|
| 303 |
+
linenumber_list = self.ranges_to_linenumbers(ranges)
|
| 304 |
+
self.breakpoints = linenumber_list
|
| 305 |
+
|
| 306 |
+
def ranges_to_linenumbers(self, ranges):
|
| 307 |
+
lines = []
|
| 308 |
+
for index in range(0, len(ranges), 2):
|
| 309 |
+
lineno = int(float(ranges[index].string))
|
| 310 |
+
end = int(float(ranges[index+1].string))
|
| 311 |
+
while lineno < end:
|
| 312 |
+
lines.append(lineno)
|
| 313 |
+
lineno += 1
|
| 314 |
+
return lines
|
| 315 |
+
|
| 316 |
+
# XXX 13 Dec 2002 KBK Not used currently
|
| 317 |
+
# def saved_change_hook(self):
|
| 318 |
+
# "Extend base method - clear breaks if module is modified"
|
| 319 |
+
# if not self.get_saved():
|
| 320 |
+
# self.clear_file_breaks()
|
| 321 |
+
# EditorWindow.saved_change_hook(self)
|
| 322 |
+
|
| 323 |
+
def _close(self):
|
| 324 |
+
"Extend base method - clear breaks when module is closed"
|
| 325 |
+
self.clear_file_breaks()
|
| 326 |
+
EditorWindow._close(self)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
class PyShellFileList(FileList):
|
| 330 |
+
"Extend base class: IDLE supports a shell and breakpoints"
|
| 331 |
+
|
| 332 |
+
# override FileList's class variable, instances return PyShellEditorWindow
|
| 333 |
+
# instead of EditorWindow when new edit windows are created.
|
| 334 |
+
EditorWindow = PyShellEditorWindow
|
| 335 |
+
|
| 336 |
+
pyshell = None
|
| 337 |
+
|
| 338 |
+
def open_shell(self, event=None):
|
| 339 |
+
if self.pyshell:
|
| 340 |
+
self.pyshell.top.wakeup()
|
| 341 |
+
else:
|
| 342 |
+
self.pyshell = PyShell(self)
|
| 343 |
+
if self.pyshell:
|
| 344 |
+
if not self.pyshell.begin():
|
| 345 |
+
return None
|
| 346 |
+
return self.pyshell
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
class ModifiedColorDelegator(ColorDelegator):
|
| 350 |
+
"Extend base class: colorizer for the shell window itself"
|
| 351 |
+
def recolorize_main(self):
|
| 352 |
+
self.tag_remove("TODO", "1.0", "iomark")
|
| 353 |
+
self.tag_add("SYNC", "1.0", "iomark")
|
| 354 |
+
ColorDelegator.recolorize_main(self)
|
| 355 |
+
|
| 356 |
+
def removecolors(self):
|
| 357 |
+
# Don't remove shell color tags before "iomark"
|
| 358 |
+
for tag in self.tagdefs:
|
| 359 |
+
self.tag_remove(tag, "iomark", "end")
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class ModifiedUndoDelegator(UndoDelegator):
|
| 363 |
+
"Extend base class: forbid insert/delete before the I/O mark"
|
| 364 |
+
def insert(self, index, chars, tags=None):
|
| 365 |
+
try:
|
| 366 |
+
if self.delegate.compare(index, "<", "iomark"):
|
| 367 |
+
self.delegate.bell()
|
| 368 |
+
return
|
| 369 |
+
except TclError:
|
| 370 |
+
pass
|
| 371 |
+
UndoDelegator.insert(self, index, chars, tags)
|
| 372 |
+
|
| 373 |
+
def delete(self, index1, index2=None):
|
| 374 |
+
try:
|
| 375 |
+
if self.delegate.compare(index1, "<", "iomark"):
|
| 376 |
+
self.delegate.bell()
|
| 377 |
+
return
|
| 378 |
+
except TclError:
|
| 379 |
+
pass
|
| 380 |
+
UndoDelegator.delete(self, index1, index2)
|
| 381 |
+
|
| 382 |
+
def undo_event(self, event):
|
| 383 |
+
# Temporarily monkey-patch the delegate's .insert() method to
|
| 384 |
+
# always use the "stdin" tag. This is needed for undo-ing
|
| 385 |
+
# deletions to preserve the "stdin" tag, because UndoDelegator
|
| 386 |
+
# doesn't preserve tags for deleted text.
|
| 387 |
+
orig_insert = self.delegate.insert
|
| 388 |
+
self.delegate.insert = \
|
| 389 |
+
lambda index, chars: orig_insert(index, chars, "stdin")
|
| 390 |
+
try:
|
| 391 |
+
super().undo_event(event)
|
| 392 |
+
finally:
|
| 393 |
+
self.delegate.insert = orig_insert
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
class UserInputTaggingDelegator(Delegator):
|
| 397 |
+
"""Delegator used to tag user input with "stdin"."""
|
| 398 |
+
def insert(self, index, chars, tags=None):
|
| 399 |
+
if tags is None:
|
| 400 |
+
tags = "stdin"
|
| 401 |
+
self.delegate.insert(index, chars, tags)
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
class MyRPCClient(rpc.RPCClient):
|
| 405 |
+
|
| 406 |
+
def handle_EOF(self):
|
| 407 |
+
"Override the base class - just re-raise EOFError"
|
| 408 |
+
raise EOFError
|
| 409 |
+
|
| 410 |
+
def restart_line(width, filename): # See bpo-38141.
|
| 411 |
+
"""Return width long restart line formatted with filename.
|
| 412 |
+
|
| 413 |
+
Fill line with balanced '='s, with any extras and at least one at
|
| 414 |
+
the beginning. Do not end with a trailing space.
|
| 415 |
+
"""
|
| 416 |
+
tag = f"= RESTART: {filename or 'Shell'} ="
|
| 417 |
+
if width >= len(tag):
|
| 418 |
+
div, mod = divmod((width -len(tag)), 2)
|
| 419 |
+
return f"{(div+mod)*'='}{tag}{div*'='}"
|
| 420 |
+
else:
|
| 421 |
+
return tag[:-2] # Remove ' ='.
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
class ModifiedInterpreter(InteractiveInterpreter):
|
| 425 |
+
|
| 426 |
+
def __init__(self, tkconsole):
|
| 427 |
+
self.tkconsole = tkconsole
|
| 428 |
+
locals = sys.modules['__main__'].__dict__
|
| 429 |
+
InteractiveInterpreter.__init__(self, locals=locals)
|
| 430 |
+
self.restarting = False
|
| 431 |
+
self.subprocess_arglist = None
|
| 432 |
+
self.port = PORT
|
| 433 |
+
self.original_compiler_flags = self.compile.compiler.flags
|
| 434 |
+
|
| 435 |
+
_afterid = None
|
| 436 |
+
rpcclt = None
|
| 437 |
+
rpcsubproc = None
|
| 438 |
+
|
| 439 |
+
def spawn_subprocess(self):
|
| 440 |
+
if self.subprocess_arglist is None:
|
| 441 |
+
self.subprocess_arglist = self.build_subprocess_arglist()
|
| 442 |
+
self.rpcsubproc = subprocess.Popen(self.subprocess_arglist)
|
| 443 |
+
|
| 444 |
+
def build_subprocess_arglist(self):
|
| 445 |
+
assert (self.port!=0), (
|
| 446 |
+
"Socket should have been assigned a port number.")
|
| 447 |
+
w = ['-W' + s for s in sys.warnoptions]
|
| 448 |
+
# Maybe IDLE is installed and is being accessed via sys.path,
|
| 449 |
+
# or maybe it's not installed and the idle.py script is being
|
| 450 |
+
# run from the IDLE source directory.
|
| 451 |
+
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
|
| 452 |
+
default=False, type='bool')
|
| 453 |
+
command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,)
|
| 454 |
+
return [sys.executable] + w + ["-c", command, str(self.port)]
|
| 455 |
+
|
| 456 |
+
def start_subprocess(self):
|
| 457 |
+
addr = (HOST, self.port)
|
| 458 |
+
# GUI makes several attempts to acquire socket, listens for connection
|
| 459 |
+
for i in range(3):
|
| 460 |
+
time.sleep(i)
|
| 461 |
+
try:
|
| 462 |
+
self.rpcclt = MyRPCClient(addr)
|
| 463 |
+
break
|
| 464 |
+
except OSError:
|
| 465 |
+
pass
|
| 466 |
+
else:
|
| 467 |
+
self.display_port_binding_error()
|
| 468 |
+
return None
|
| 469 |
+
# if PORT was 0, system will assign an 'ephemeral' port. Find it out:
|
| 470 |
+
self.port = self.rpcclt.listening_sock.getsockname()[1]
|
| 471 |
+
# if PORT was not 0, probably working with a remote execution server
|
| 472 |
+
if PORT != 0:
|
| 473 |
+
# To allow reconnection within the 2MSL wait (cf. Stevens TCP
|
| 474 |
+
# V1, 18.6), set SO_REUSEADDR. Note that this can be problematic
|
| 475 |
+
# on Windows since the implementation allows two active sockets on
|
| 476 |
+
# the same address!
|
| 477 |
+
self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET,
|
| 478 |
+
socket.SO_REUSEADDR, 1)
|
| 479 |
+
self.spawn_subprocess()
|
| 480 |
+
#time.sleep(20) # test to simulate GUI not accepting connection
|
| 481 |
+
# Accept the connection from the Python execution server
|
| 482 |
+
self.rpcclt.listening_sock.settimeout(10)
|
| 483 |
+
try:
|
| 484 |
+
self.rpcclt.accept()
|
| 485 |
+
except TimeoutError:
|
| 486 |
+
self.display_no_subprocess_error()
|
| 487 |
+
return None
|
| 488 |
+
self.rpcclt.register("console", self.tkconsole)
|
| 489 |
+
self.rpcclt.register("stdin", self.tkconsole.stdin)
|
| 490 |
+
self.rpcclt.register("stdout", self.tkconsole.stdout)
|
| 491 |
+
self.rpcclt.register("stderr", self.tkconsole.stderr)
|
| 492 |
+
self.rpcclt.register("flist", self.tkconsole.flist)
|
| 493 |
+
self.rpcclt.register("linecache", linecache)
|
| 494 |
+
self.rpcclt.register("interp", self)
|
| 495 |
+
self.transfer_path(with_cwd=True)
|
| 496 |
+
self.poll_subprocess()
|
| 497 |
+
return self.rpcclt
|
| 498 |
+
|
| 499 |
+
def restart_subprocess(self, with_cwd=False, filename=''):
|
| 500 |
+
if self.restarting:
|
| 501 |
+
return self.rpcclt
|
| 502 |
+
self.restarting = True
|
| 503 |
+
# close only the subprocess debugger
|
| 504 |
+
debug = self.getdebugger()
|
| 505 |
+
if debug:
|
| 506 |
+
try:
|
| 507 |
+
# Only close subprocess debugger, don't unregister gui_adap!
|
| 508 |
+
debugger_r.close_subprocess_debugger(self.rpcclt)
|
| 509 |
+
except:
|
| 510 |
+
pass
|
| 511 |
+
# Kill subprocess, spawn a new one, accept connection.
|
| 512 |
+
self.rpcclt.close()
|
| 513 |
+
self.terminate_subprocess()
|
| 514 |
+
console = self.tkconsole
|
| 515 |
+
was_executing = console.executing
|
| 516 |
+
console.executing = False
|
| 517 |
+
self.spawn_subprocess()
|
| 518 |
+
try:
|
| 519 |
+
self.rpcclt.accept()
|
| 520 |
+
except TimeoutError:
|
| 521 |
+
self.display_no_subprocess_error()
|
| 522 |
+
return None
|
| 523 |
+
self.transfer_path(with_cwd=with_cwd)
|
| 524 |
+
console.stop_readline()
|
| 525 |
+
# annotate restart in shell window and mark it
|
| 526 |
+
console.text.delete("iomark", "end-1c")
|
| 527 |
+
console.write('\n')
|
| 528 |
+
console.write(restart_line(console.width, filename))
|
| 529 |
+
console.text.mark_set("restart", "end-1c")
|
| 530 |
+
console.text.mark_gravity("restart", "left")
|
| 531 |
+
if not filename:
|
| 532 |
+
console.showprompt()
|
| 533 |
+
# restart subprocess debugger
|
| 534 |
+
if debug:
|
| 535 |
+
# Restarted debugger connects to current instance of debug GUI
|
| 536 |
+
debugger_r.restart_subprocess_debugger(self.rpcclt)
|
| 537 |
+
# reload remote debugger breakpoints for all PyShellEditWindows
|
| 538 |
+
debug.load_breakpoints()
|
| 539 |
+
self.compile.compiler.flags = self.original_compiler_flags
|
| 540 |
+
self.restarting = False
|
| 541 |
+
return self.rpcclt
|
| 542 |
+
|
| 543 |
+
def __request_interrupt(self):
|
| 544 |
+
self.rpcclt.remotecall("exec", "interrupt_the_server", (), {})
|
| 545 |
+
|
| 546 |
+
def interrupt_subprocess(self):
|
| 547 |
+
threading.Thread(target=self.__request_interrupt).start()
|
| 548 |
+
|
| 549 |
+
def kill_subprocess(self):
|
| 550 |
+
if self._afterid is not None:
|
| 551 |
+
self.tkconsole.text.after_cancel(self._afterid)
|
| 552 |
+
try:
|
| 553 |
+
self.rpcclt.listening_sock.close()
|
| 554 |
+
except AttributeError: # no socket
|
| 555 |
+
pass
|
| 556 |
+
try:
|
| 557 |
+
self.rpcclt.close()
|
| 558 |
+
except AttributeError: # no socket
|
| 559 |
+
pass
|
| 560 |
+
self.terminate_subprocess()
|
| 561 |
+
self.tkconsole.executing = False
|
| 562 |
+
self.rpcclt = None
|
| 563 |
+
|
| 564 |
+
def terminate_subprocess(self):
|
| 565 |
+
"Make sure subprocess is terminated"
|
| 566 |
+
try:
|
| 567 |
+
self.rpcsubproc.kill()
|
| 568 |
+
except OSError:
|
| 569 |
+
# process already terminated
|
| 570 |
+
return
|
| 571 |
+
else:
|
| 572 |
+
try:
|
| 573 |
+
self.rpcsubproc.wait()
|
| 574 |
+
except OSError:
|
| 575 |
+
return
|
| 576 |
+
|
| 577 |
+
def transfer_path(self, with_cwd=False):
|
| 578 |
+
if with_cwd: # Issue 13506
|
| 579 |
+
path = [''] # include Current Working Directory
|
| 580 |
+
path.extend(sys.path)
|
| 581 |
+
else:
|
| 582 |
+
path = sys.path
|
| 583 |
+
|
| 584 |
+
self.runcommand("""if 1:
|
| 585 |
+
import sys as _sys
|
| 586 |
+
_sys.path = %r
|
| 587 |
+
del _sys
|
| 588 |
+
\n""" % (path,))
|
| 589 |
+
|
| 590 |
+
active_seq = None
|
| 591 |
+
|
| 592 |
+
def poll_subprocess(self):
|
| 593 |
+
clt = self.rpcclt
|
| 594 |
+
if clt is None:
|
| 595 |
+
return
|
| 596 |
+
try:
|
| 597 |
+
response = clt.pollresponse(self.active_seq, wait=0.05)
|
| 598 |
+
except (EOFError, OSError, KeyboardInterrupt):
|
| 599 |
+
# lost connection or subprocess terminated itself, restart
|
| 600 |
+
# [the KBI is from rpc.SocketIO.handle_EOF()]
|
| 601 |
+
if self.tkconsole.closing:
|
| 602 |
+
return
|
| 603 |
+
response = None
|
| 604 |
+
self.restart_subprocess()
|
| 605 |
+
if response:
|
| 606 |
+
self.tkconsole.resetoutput()
|
| 607 |
+
self.active_seq = None
|
| 608 |
+
how, what = response
|
| 609 |
+
console = self.tkconsole.console
|
| 610 |
+
if how == "OK":
|
| 611 |
+
if what is not None:
|
| 612 |
+
print(repr(what), file=console)
|
| 613 |
+
elif how == "EXCEPTION":
|
| 614 |
+
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
|
| 615 |
+
self.remote_stack_viewer()
|
| 616 |
+
elif how == "ERROR":
|
| 617 |
+
errmsg = "pyshell.ModifiedInterpreter: Subprocess ERROR:\n"
|
| 618 |
+
print(errmsg, what, file=sys.__stderr__)
|
| 619 |
+
print(errmsg, what, file=console)
|
| 620 |
+
# we received a response to the currently active seq number:
|
| 621 |
+
try:
|
| 622 |
+
self.tkconsole.endexecuting()
|
| 623 |
+
except AttributeError: # shell may have closed
|
| 624 |
+
pass
|
| 625 |
+
# Reschedule myself
|
| 626 |
+
if not self.tkconsole.closing:
|
| 627 |
+
self._afterid = self.tkconsole.text.after(
|
| 628 |
+
self.tkconsole.pollinterval, self.poll_subprocess)
|
| 629 |
+
|
| 630 |
+
debugger = None
|
| 631 |
+
|
| 632 |
+
def setdebugger(self, debugger):
|
| 633 |
+
self.debugger = debugger
|
| 634 |
+
|
| 635 |
+
def getdebugger(self):
|
| 636 |
+
return self.debugger
|
| 637 |
+
|
| 638 |
+
def open_remote_stack_viewer(self):
|
| 639 |
+
"""Initiate the remote stack viewer from a separate thread.
|
| 640 |
+
|
| 641 |
+
This method is called from the subprocess, and by returning from this
|
| 642 |
+
method we allow the subprocess to unblock. After a bit the shell
|
| 643 |
+
requests the subprocess to open the remote stack viewer which returns a
|
| 644 |
+
static object looking at the last exception. It is queried through
|
| 645 |
+
the RPC mechanism.
|
| 646 |
+
|
| 647 |
+
"""
|
| 648 |
+
self.tkconsole.text.after(300, self.remote_stack_viewer)
|
| 649 |
+
return
|
| 650 |
+
|
| 651 |
+
def remote_stack_viewer(self):
|
| 652 |
+
from idlelib import debugobj_r
|
| 653 |
+
oid = self.rpcclt.remotequeue("exec", "stackviewer", ("flist",), {})
|
| 654 |
+
if oid is None:
|
| 655 |
+
self.tkconsole.root.bell()
|
| 656 |
+
return
|
| 657 |
+
item = debugobj_r.StubObjectTreeItem(self.rpcclt, oid)
|
| 658 |
+
from idlelib.tree import ScrolledCanvas, TreeNode
|
| 659 |
+
top = Toplevel(self.tkconsole.root)
|
| 660 |
+
theme = idleConf.CurrentTheme()
|
| 661 |
+
background = idleConf.GetHighlight(theme, 'normal')['background']
|
| 662 |
+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0)
|
| 663 |
+
sc.frame.pack(expand=1, fill="both")
|
| 664 |
+
node = TreeNode(sc.canvas, None, item)
|
| 665 |
+
node.expand()
|
| 666 |
+
# XXX Should GC the remote tree when closing the window
|
| 667 |
+
|
| 668 |
+
gid = 0
|
| 669 |
+
|
| 670 |
+
def execsource(self, source):
|
| 671 |
+
"Like runsource() but assumes complete exec source"
|
| 672 |
+
filename = self.stuffsource(source)
|
| 673 |
+
self.execfile(filename, source)
|
| 674 |
+
|
| 675 |
+
def execfile(self, filename, source=None):
|
| 676 |
+
"Execute an existing file"
|
| 677 |
+
if source is None:
|
| 678 |
+
with tokenize.open(filename) as fp:
|
| 679 |
+
source = fp.read()
|
| 680 |
+
if use_subprocess:
|
| 681 |
+
source = (f"__file__ = r'''{os.path.abspath(filename)}'''\n"
|
| 682 |
+
+ source + "\ndel __file__")
|
| 683 |
+
try:
|
| 684 |
+
code = compile(source, filename, "exec")
|
| 685 |
+
except (OverflowError, SyntaxError):
|
| 686 |
+
self.tkconsole.resetoutput()
|
| 687 |
+
print('*** Error in script or command!\n'
|
| 688 |
+
'Traceback (most recent call last):',
|
| 689 |
+
file=self.tkconsole.stderr)
|
| 690 |
+
InteractiveInterpreter.showsyntaxerror(self, filename)
|
| 691 |
+
self.tkconsole.showprompt()
|
| 692 |
+
else:
|
| 693 |
+
self.runcode(code)
|
| 694 |
+
|
| 695 |
+
def runsource(self, source):
|
| 696 |
+
"Extend base class method: Stuff the source in the line cache first"
|
| 697 |
+
filename = self.stuffsource(source)
|
| 698 |
+
# at the moment, InteractiveInterpreter expects str
|
| 699 |
+
assert isinstance(source, str)
|
| 700 |
+
# InteractiveInterpreter.runsource() calls its runcode() method,
|
| 701 |
+
# which is overridden (see below)
|
| 702 |
+
return InteractiveInterpreter.runsource(self, source, filename)
|
| 703 |
+
|
| 704 |
+
def stuffsource(self, source):
|
| 705 |
+
"Stuff source in the filename cache"
|
| 706 |
+
filename = "<pyshell#%d>" % self.gid
|
| 707 |
+
self.gid = self.gid + 1
|
| 708 |
+
lines = source.split("\n")
|
| 709 |
+
linecache.cache[filename] = len(source)+1, 0, lines, filename
|
| 710 |
+
return filename
|
| 711 |
+
|
| 712 |
+
def prepend_syspath(self, filename):
|
| 713 |
+
"Prepend sys.path with file's directory if not already included"
|
| 714 |
+
self.runcommand("""if 1:
|
| 715 |
+
_filename = %r
|
| 716 |
+
import sys as _sys
|
| 717 |
+
from os.path import dirname as _dirname
|
| 718 |
+
_dir = _dirname(_filename)
|
| 719 |
+
if not _dir in _sys.path:
|
| 720 |
+
_sys.path.insert(0, _dir)
|
| 721 |
+
del _filename, _sys, _dirname, _dir
|
| 722 |
+
\n""" % (filename,))
|
| 723 |
+
|
| 724 |
+
def showsyntaxerror(self, filename=None):
|
| 725 |
+
"""Override Interactive Interpreter method: Use Colorizing
|
| 726 |
+
|
| 727 |
+
Color the offending position instead of printing it and pointing at it
|
| 728 |
+
with a caret.
|
| 729 |
+
|
| 730 |
+
"""
|
| 731 |
+
tkconsole = self.tkconsole
|
| 732 |
+
text = tkconsole.text
|
| 733 |
+
text.tag_remove("ERROR", "1.0", "end")
|
| 734 |
+
type, value, tb = sys.exc_info()
|
| 735 |
+
msg = getattr(value, 'msg', '') or value or "<no detail available>"
|
| 736 |
+
lineno = getattr(value, 'lineno', '') or 1
|
| 737 |
+
offset = getattr(value, 'offset', '') or 0
|
| 738 |
+
if offset == 0:
|
| 739 |
+
lineno += 1 #mark end of offending line
|
| 740 |
+
if lineno == 1:
|
| 741 |
+
pos = "iomark + %d chars" % (offset-1)
|
| 742 |
+
else:
|
| 743 |
+
pos = "iomark linestart + %d lines + %d chars" % \
|
| 744 |
+
(lineno-1, offset-1)
|
| 745 |
+
tkconsole.colorize_syntax_error(text, pos)
|
| 746 |
+
tkconsole.resetoutput()
|
| 747 |
+
self.write("SyntaxError: %s\n" % msg)
|
| 748 |
+
tkconsole.showprompt()
|
| 749 |
+
|
| 750 |
+
def showtraceback(self):
|
| 751 |
+
"Extend base class method to reset output properly"
|
| 752 |
+
self.tkconsole.resetoutput()
|
| 753 |
+
self.checklinecache()
|
| 754 |
+
InteractiveInterpreter.showtraceback(self)
|
| 755 |
+
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
|
| 756 |
+
self.tkconsole.open_stack_viewer()
|
| 757 |
+
|
| 758 |
+
def checklinecache(self):
|
| 759 |
+
c = linecache.cache
|
| 760 |
+
for key in list(c.keys()):
|
| 761 |
+
if key[:1] + key[-1:] != "<>":
|
| 762 |
+
del c[key]
|
| 763 |
+
|
| 764 |
+
def runcommand(self, code):
|
| 765 |
+
"Run the code without invoking the debugger"
|
| 766 |
+
# The code better not raise an exception!
|
| 767 |
+
if self.tkconsole.executing:
|
| 768 |
+
self.display_executing_dialog()
|
| 769 |
+
return 0
|
| 770 |
+
if self.rpcclt:
|
| 771 |
+
self.rpcclt.remotequeue("exec", "runcode", (code,), {})
|
| 772 |
+
else:
|
| 773 |
+
exec(code, self.locals)
|
| 774 |
+
return 1
|
| 775 |
+
|
| 776 |
+
def runcode(self, code):
|
| 777 |
+
"Override base class method"
|
| 778 |
+
if self.tkconsole.executing:
|
| 779 |
+
self.restart_subprocess()
|
| 780 |
+
self.checklinecache()
|
| 781 |
+
debugger = self.debugger
|
| 782 |
+
try:
|
| 783 |
+
self.tkconsole.beginexecuting()
|
| 784 |
+
if not debugger and self.rpcclt is not None:
|
| 785 |
+
self.active_seq = self.rpcclt.asyncqueue("exec", "runcode",
|
| 786 |
+
(code,), {})
|
| 787 |
+
elif debugger:
|
| 788 |
+
debugger.run(code, self.locals)
|
| 789 |
+
else:
|
| 790 |
+
exec(code, self.locals)
|
| 791 |
+
except SystemExit:
|
| 792 |
+
if not self.tkconsole.closing:
|
| 793 |
+
if messagebox.askyesno(
|
| 794 |
+
"Exit?",
|
| 795 |
+
"Do you want to exit altogether?",
|
| 796 |
+
default="yes",
|
| 797 |
+
parent=self.tkconsole.text):
|
| 798 |
+
raise
|
| 799 |
+
else:
|
| 800 |
+
self.showtraceback()
|
| 801 |
+
else:
|
| 802 |
+
raise
|
| 803 |
+
except:
|
| 804 |
+
if use_subprocess:
|
| 805 |
+
print("IDLE internal error in runcode()",
|
| 806 |
+
file=self.tkconsole.stderr)
|
| 807 |
+
self.showtraceback()
|
| 808 |
+
self.tkconsole.endexecuting()
|
| 809 |
+
else:
|
| 810 |
+
if self.tkconsole.canceled:
|
| 811 |
+
self.tkconsole.canceled = False
|
| 812 |
+
print("KeyboardInterrupt", file=self.tkconsole.stderr)
|
| 813 |
+
else:
|
| 814 |
+
self.showtraceback()
|
| 815 |
+
finally:
|
| 816 |
+
if not use_subprocess:
|
| 817 |
+
try:
|
| 818 |
+
self.tkconsole.endexecuting()
|
| 819 |
+
except AttributeError: # shell may have closed
|
| 820 |
+
pass
|
| 821 |
+
|
| 822 |
+
def write(self, s):
|
| 823 |
+
"Override base class method"
|
| 824 |
+
return self.tkconsole.stderr.write(s)
|
| 825 |
+
|
| 826 |
+
def display_port_binding_error(self):
|
| 827 |
+
messagebox.showerror(
|
| 828 |
+
"Port Binding Error",
|
| 829 |
+
"IDLE can't bind to a TCP/IP port, which is necessary to "
|
| 830 |
+
"communicate with its Python execution server. This might be "
|
| 831 |
+
"because no networking is installed on this computer. "
|
| 832 |
+
"Run IDLE with the -n command line switch to start without a "
|
| 833 |
+
"subprocess and refer to Help/IDLE Help 'Running without a "
|
| 834 |
+
"subprocess' for further details.",
|
| 835 |
+
parent=self.tkconsole.text)
|
| 836 |
+
|
| 837 |
+
def display_no_subprocess_error(self):
|
| 838 |
+
messagebox.showerror(
|
| 839 |
+
"Subprocess Connection Error",
|
| 840 |
+
"IDLE's subprocess didn't make connection.\n"
|
| 841 |
+
"See the 'Startup failure' section of the IDLE doc, online at\n"
|
| 842 |
+
"https://docs.python.org/3/library/idle.html#startup-failure",
|
| 843 |
+
parent=self.tkconsole.text)
|
| 844 |
+
|
| 845 |
+
def display_executing_dialog(self):
|
| 846 |
+
messagebox.showerror(
|
| 847 |
+
"Already executing",
|
| 848 |
+
"The Python Shell window is already executing a command; "
|
| 849 |
+
"please wait until it is finished.",
|
| 850 |
+
parent=self.tkconsole.text)
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
class PyShell(OutputWindow):
|
| 854 |
+
from idlelib.squeezer import Squeezer
|
| 855 |
+
|
| 856 |
+
shell_title = "IDLE Shell " + python_version()
|
| 857 |
+
|
| 858 |
+
# Override classes
|
| 859 |
+
ColorDelegator = ModifiedColorDelegator
|
| 860 |
+
UndoDelegator = ModifiedUndoDelegator
|
| 861 |
+
|
| 862 |
+
# Override menus
|
| 863 |
+
menu_specs = [
|
| 864 |
+
("file", "_File"),
|
| 865 |
+
("edit", "_Edit"),
|
| 866 |
+
("debug", "_Debug"),
|
| 867 |
+
("options", "_Options"),
|
| 868 |
+
("window", "_Window"),
|
| 869 |
+
("help", "_Help"),
|
| 870 |
+
]
|
| 871 |
+
|
| 872 |
+
# Extend right-click context menu
|
| 873 |
+
rmenu_specs = OutputWindow.rmenu_specs + [
|
| 874 |
+
("Squeeze", "<<squeeze-current-text>>"),
|
| 875 |
+
]
|
| 876 |
+
_idx = 1 + len(list(itertools.takewhile(
|
| 877 |
+
lambda rmenu_item: rmenu_item[0] != "Copy", rmenu_specs)
|
| 878 |
+
))
|
| 879 |
+
rmenu_specs.insert(_idx, ("Copy with prompts",
|
| 880 |
+
"<<copy-with-prompts>>",
|
| 881 |
+
"rmenu_check_copy"))
|
| 882 |
+
del _idx
|
| 883 |
+
|
| 884 |
+
allow_line_numbers = False
|
| 885 |
+
user_input_insert_tags = "stdin"
|
| 886 |
+
|
| 887 |
+
# New classes
|
| 888 |
+
from idlelib.history import History
|
| 889 |
+
from idlelib.sidebar import ShellSidebar
|
| 890 |
+
|
| 891 |
+
def __init__(self, flist=None):
|
| 892 |
+
if use_subprocess:
|
| 893 |
+
ms = self.menu_specs
|
| 894 |
+
if ms[2][0] != "shell":
|
| 895 |
+
ms.insert(2, ("shell", "She_ll"))
|
| 896 |
+
self.interp = ModifiedInterpreter(self)
|
| 897 |
+
if flist is None:
|
| 898 |
+
root = Tk()
|
| 899 |
+
fixwordbreaks(root)
|
| 900 |
+
root.withdraw()
|
| 901 |
+
flist = PyShellFileList(root)
|
| 902 |
+
|
| 903 |
+
self.shell_sidebar = None # initialized below
|
| 904 |
+
|
| 905 |
+
OutputWindow.__init__(self, flist, None, None)
|
| 906 |
+
|
| 907 |
+
self.usetabs = False
|
| 908 |
+
# indentwidth must be 8 when using tabs. See note in EditorWindow:
|
| 909 |
+
self.indentwidth = 4
|
| 910 |
+
|
| 911 |
+
self.sys_ps1 = sys.ps1 if hasattr(sys, 'ps1') else '>>>\n'
|
| 912 |
+
self.prompt_last_line = self.sys_ps1.split('\n')[-1]
|
| 913 |
+
self.prompt = self.sys_ps1 # Changes when debug active
|
| 914 |
+
|
| 915 |
+
text = self.text
|
| 916 |
+
text.configure(wrap="char")
|
| 917 |
+
text.bind("<<newline-and-indent>>", self.enter_callback)
|
| 918 |
+
text.bind("<<plain-newline-and-indent>>", self.linefeed_callback)
|
| 919 |
+
text.bind("<<interrupt-execution>>", self.cancel_callback)
|
| 920 |
+
text.bind("<<end-of-file>>", self.eof_callback)
|
| 921 |
+
text.bind("<<open-stack-viewer>>", self.open_stack_viewer)
|
| 922 |
+
text.bind("<<toggle-debugger>>", self.toggle_debugger)
|
| 923 |
+
text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer)
|
| 924 |
+
text.bind("<<copy-with-prompts>>", self.copy_with_prompts_callback)
|
| 925 |
+
if use_subprocess:
|
| 926 |
+
text.bind("<<view-restart>>", self.view_restart_mark)
|
| 927 |
+
text.bind("<<restart-shell>>", self.restart_shell)
|
| 928 |
+
self.squeezer = self.Squeezer(self)
|
| 929 |
+
text.bind("<<squeeze-current-text>>",
|
| 930 |
+
self.squeeze_current_text_event)
|
| 931 |
+
|
| 932 |
+
self.save_stdout = sys.stdout
|
| 933 |
+
self.save_stderr = sys.stderr
|
| 934 |
+
self.save_stdin = sys.stdin
|
| 935 |
+
from idlelib import iomenu
|
| 936 |
+
self.stdin = StdInputFile(self, "stdin",
|
| 937 |
+
iomenu.encoding, iomenu.errors)
|
| 938 |
+
self.stdout = StdOutputFile(self, "stdout",
|
| 939 |
+
iomenu.encoding, iomenu.errors)
|
| 940 |
+
self.stderr = StdOutputFile(self, "stderr",
|
| 941 |
+
iomenu.encoding, "backslashreplace")
|
| 942 |
+
self.console = StdOutputFile(self, "console",
|
| 943 |
+
iomenu.encoding, iomenu.errors)
|
| 944 |
+
if not use_subprocess:
|
| 945 |
+
sys.stdout = self.stdout
|
| 946 |
+
sys.stderr = self.stderr
|
| 947 |
+
sys.stdin = self.stdin
|
| 948 |
+
try:
|
| 949 |
+
# page help() text to shell.
|
| 950 |
+
import pydoc # import must be done here to capture i/o rebinding.
|
| 951 |
+
# XXX KBK 27Dec07 use text viewer someday, but must work w/o subproc
|
| 952 |
+
pydoc.pager = pydoc.plainpager
|
| 953 |
+
except:
|
| 954 |
+
sys.stderr = sys.__stderr__
|
| 955 |
+
raise
|
| 956 |
+
#
|
| 957 |
+
self.history = self.History(self.text)
|
| 958 |
+
#
|
| 959 |
+
self.pollinterval = 50 # millisec
|
| 960 |
+
|
| 961 |
+
self.shell_sidebar = self.ShellSidebar(self)
|
| 962 |
+
|
| 963 |
+
# Insert UserInputTaggingDelegator at the top of the percolator,
|
| 964 |
+
# but make calls to text.insert() skip it. This causes only insert
|
| 965 |
+
# events generated in Tcl/Tk to go through this delegator.
|
| 966 |
+
self.text.insert = self.per.top.insert
|
| 967 |
+
self.per.insertfilter(UserInputTaggingDelegator())
|
| 968 |
+
|
| 969 |
+
def ResetFont(self):
|
| 970 |
+
super().ResetFont()
|
| 971 |
+
|
| 972 |
+
if self.shell_sidebar is not None:
|
| 973 |
+
self.shell_sidebar.update_font()
|
| 974 |
+
|
| 975 |
+
def ResetColorizer(self):
|
| 976 |
+
super().ResetColorizer()
|
| 977 |
+
|
| 978 |
+
theme = idleConf.CurrentTheme()
|
| 979 |
+
tag_colors = {
|
| 980 |
+
"stdin": {'background': None, 'foreground': None},
|
| 981 |
+
"stdout": idleConf.GetHighlight(theme, "stdout"),
|
| 982 |
+
"stderr": idleConf.GetHighlight(theme, "stderr"),
|
| 983 |
+
"console": idleConf.GetHighlight(theme, "normal"),
|
| 984 |
+
}
|
| 985 |
+
for tag, tag_colors_config in tag_colors.items():
|
| 986 |
+
self.text.tag_configure(tag, **tag_colors_config)
|
| 987 |
+
|
| 988 |
+
if self.shell_sidebar is not None:
|
| 989 |
+
self.shell_sidebar.update_colors()
|
| 990 |
+
|
| 991 |
+
def replace_event(self, event):
|
| 992 |
+
replace.replace(self.text, insert_tags="stdin")
|
| 993 |
+
return "break"
|
| 994 |
+
|
| 995 |
+
def get_standard_extension_names(self):
|
| 996 |
+
return idleConf.GetExtensions(shell_only=True)
|
| 997 |
+
|
| 998 |
+
def get_prompt_text(self, first, last):
|
| 999 |
+
"""Return text between first and last with prompts added."""
|
| 1000 |
+
text = self.text.get(first, last)
|
| 1001 |
+
lineno_range = range(
|
| 1002 |
+
int(float(first)),
|
| 1003 |
+
int(float(last))
|
| 1004 |
+
)
|
| 1005 |
+
prompts = [
|
| 1006 |
+
self.shell_sidebar.line_prompts.get(lineno)
|
| 1007 |
+
for lineno in lineno_range
|
| 1008 |
+
]
|
| 1009 |
+
return "\n".join(
|
| 1010 |
+
line if prompt is None else f"{prompt} {line}"
|
| 1011 |
+
for prompt, line in zip(prompts, text.splitlines())
|
| 1012 |
+
) + "\n"
|
| 1013 |
+
|
| 1014 |
+
|
| 1015 |
+
def copy_with_prompts_callback(self, event=None):
|
| 1016 |
+
"""Copy selected lines to the clipboard, with prompts.
|
| 1017 |
+
|
| 1018 |
+
This makes the copied text useful for doc-tests and interactive
|
| 1019 |
+
shell code examples.
|
| 1020 |
+
|
| 1021 |
+
This always copies entire lines, even if only part of the first
|
| 1022 |
+
and/or last lines is selected.
|
| 1023 |
+
"""
|
| 1024 |
+
text = self.text
|
| 1025 |
+
selfirst = text.index('sel.first linestart')
|
| 1026 |
+
if selfirst is None: # Should not be possible.
|
| 1027 |
+
return # No selection, do nothing.
|
| 1028 |
+
sellast = text.index('sel.last')
|
| 1029 |
+
if sellast[-1] != '0':
|
| 1030 |
+
sellast = text.index("sel.last+1line linestart")
|
| 1031 |
+
text.clipboard_clear()
|
| 1032 |
+
prompt_text = self.get_prompt_text(selfirst, sellast)
|
| 1033 |
+
text.clipboard_append(prompt_text)
|
| 1034 |
+
|
| 1035 |
+
reading = False
|
| 1036 |
+
executing = False
|
| 1037 |
+
canceled = False
|
| 1038 |
+
endoffile = False
|
| 1039 |
+
closing = False
|
| 1040 |
+
_stop_readline_flag = False
|
| 1041 |
+
|
| 1042 |
+
def set_warning_stream(self, stream):
|
| 1043 |
+
global warning_stream
|
| 1044 |
+
warning_stream = stream
|
| 1045 |
+
|
| 1046 |
+
def get_warning_stream(self):
|
| 1047 |
+
return warning_stream
|
| 1048 |
+
|
| 1049 |
+
def toggle_debugger(self, event=None):
|
| 1050 |
+
if self.executing:
|
| 1051 |
+
messagebox.showerror("Don't debug now",
|
| 1052 |
+
"You can only toggle the debugger when idle",
|
| 1053 |
+
parent=self.text)
|
| 1054 |
+
self.set_debugger_indicator()
|
| 1055 |
+
return "break"
|
| 1056 |
+
else:
|
| 1057 |
+
db = self.interp.getdebugger()
|
| 1058 |
+
if db:
|
| 1059 |
+
self.close_debugger()
|
| 1060 |
+
else:
|
| 1061 |
+
self.open_debugger()
|
| 1062 |
+
|
| 1063 |
+
def set_debugger_indicator(self):
|
| 1064 |
+
db = self.interp.getdebugger()
|
| 1065 |
+
self.setvar("<<toggle-debugger>>", not not db)
|
| 1066 |
+
|
| 1067 |
+
def toggle_jit_stack_viewer(self, event=None):
|
| 1068 |
+
pass # All we need is the variable
|
| 1069 |
+
|
| 1070 |
+
def close_debugger(self):
|
| 1071 |
+
db = self.interp.getdebugger()
|
| 1072 |
+
if db:
|
| 1073 |
+
self.interp.setdebugger(None)
|
| 1074 |
+
db.close()
|
| 1075 |
+
if self.interp.rpcclt:
|
| 1076 |
+
debugger_r.close_remote_debugger(self.interp.rpcclt)
|
| 1077 |
+
self.resetoutput()
|
| 1078 |
+
self.console.write("[DEBUG OFF]\n")
|
| 1079 |
+
self.prompt = self.sys_ps1
|
| 1080 |
+
self.showprompt()
|
| 1081 |
+
self.set_debugger_indicator()
|
| 1082 |
+
|
| 1083 |
+
def open_debugger(self):
|
| 1084 |
+
if self.interp.rpcclt:
|
| 1085 |
+
dbg_gui = debugger_r.start_remote_debugger(self.interp.rpcclt,
|
| 1086 |
+
self)
|
| 1087 |
+
else:
|
| 1088 |
+
dbg_gui = debugger.Debugger(self)
|
| 1089 |
+
self.interp.setdebugger(dbg_gui)
|
| 1090 |
+
dbg_gui.load_breakpoints()
|
| 1091 |
+
self.prompt = "[DEBUG ON]\n" + self.sys_ps1
|
| 1092 |
+
self.showprompt()
|
| 1093 |
+
self.set_debugger_indicator()
|
| 1094 |
+
|
| 1095 |
+
def debug_menu_postcommand(self):
|
| 1096 |
+
state = 'disabled' if self.executing else 'normal'
|
| 1097 |
+
self.update_menu_state('debug', '*tack*iewer', state)
|
| 1098 |
+
|
| 1099 |
+
def beginexecuting(self):
|
| 1100 |
+
"Helper for ModifiedInterpreter"
|
| 1101 |
+
self.resetoutput()
|
| 1102 |
+
self.executing = True
|
| 1103 |
+
|
| 1104 |
+
def endexecuting(self):
|
| 1105 |
+
"Helper for ModifiedInterpreter"
|
| 1106 |
+
self.executing = False
|
| 1107 |
+
self.canceled = False
|
| 1108 |
+
self.showprompt()
|
| 1109 |
+
|
| 1110 |
+
def close(self):
|
| 1111 |
+
"Extend EditorWindow.close()"
|
| 1112 |
+
if self.executing:
|
| 1113 |
+
response = messagebox.askokcancel(
|
| 1114 |
+
"Kill?",
|
| 1115 |
+
"Your program is still running!\n Do you want to kill it?",
|
| 1116 |
+
default="ok",
|
| 1117 |
+
parent=self.text)
|
| 1118 |
+
if response is False:
|
| 1119 |
+
return "cancel"
|
| 1120 |
+
self.stop_readline()
|
| 1121 |
+
self.canceled = True
|
| 1122 |
+
self.closing = True
|
| 1123 |
+
return EditorWindow.close(self)
|
| 1124 |
+
|
| 1125 |
+
def _close(self):
|
| 1126 |
+
"Extend EditorWindow._close(), shut down debugger and execution server"
|
| 1127 |
+
self.close_debugger()
|
| 1128 |
+
if use_subprocess:
|
| 1129 |
+
self.interp.kill_subprocess()
|
| 1130 |
+
# Restore std streams
|
| 1131 |
+
sys.stdout = self.save_stdout
|
| 1132 |
+
sys.stderr = self.save_stderr
|
| 1133 |
+
sys.stdin = self.save_stdin
|
| 1134 |
+
# Break cycles
|
| 1135 |
+
self.interp = None
|
| 1136 |
+
self.console = None
|
| 1137 |
+
self.flist.pyshell = None
|
| 1138 |
+
self.history = None
|
| 1139 |
+
EditorWindow._close(self)
|
| 1140 |
+
|
| 1141 |
+
def ispythonsource(self, filename):
|
| 1142 |
+
"Override EditorWindow method: never remove the colorizer"
|
| 1143 |
+
return True
|
| 1144 |
+
|
| 1145 |
+
def short_title(self):
|
| 1146 |
+
return self.shell_title
|
| 1147 |
+
|
| 1148 |
+
COPYRIGHT = \
|
| 1149 |
+
'Type "help", "copyright", "credits" or "license()" for more information.'
|
| 1150 |
+
|
| 1151 |
+
def begin(self):
|
| 1152 |
+
self.text.mark_set("iomark", "insert")
|
| 1153 |
+
self.resetoutput()
|
| 1154 |
+
if use_subprocess:
|
| 1155 |
+
nosub = ''
|
| 1156 |
+
client = self.interp.start_subprocess()
|
| 1157 |
+
if not client:
|
| 1158 |
+
self.close()
|
| 1159 |
+
return False
|
| 1160 |
+
else:
|
| 1161 |
+
nosub = ("==== No Subprocess ====\n\n" +
|
| 1162 |
+
"WARNING: Running IDLE without a Subprocess is deprecated\n" +
|
| 1163 |
+
"and will be removed in a later version. See Help/IDLE Help\n" +
|
| 1164 |
+
"for details.\n\n")
|
| 1165 |
+
sys.displayhook = rpc.displayhook
|
| 1166 |
+
|
| 1167 |
+
self.write("Python %s on %s\n%s\n%s" %
|
| 1168 |
+
(sys.version, sys.platform, self.COPYRIGHT, nosub))
|
| 1169 |
+
self.text.focus_force()
|
| 1170 |
+
self.showprompt()
|
| 1171 |
+
# User code should use separate default Tk root window
|
| 1172 |
+
import tkinter
|
| 1173 |
+
tkinter._support_default_root = True
|
| 1174 |
+
tkinter._default_root = None
|
| 1175 |
+
return True
|
| 1176 |
+
|
| 1177 |
+
def stop_readline(self):
|
| 1178 |
+
if not self.reading: # no nested mainloop to exit.
|
| 1179 |
+
return
|
| 1180 |
+
self._stop_readline_flag = True
|
| 1181 |
+
self.top.quit()
|
| 1182 |
+
|
| 1183 |
+
def readline(self):
|
| 1184 |
+
save = self.reading
|
| 1185 |
+
try:
|
| 1186 |
+
self.reading = True
|
| 1187 |
+
self.top.mainloop() # nested mainloop()
|
| 1188 |
+
finally:
|
| 1189 |
+
self.reading = save
|
| 1190 |
+
if self._stop_readline_flag:
|
| 1191 |
+
self._stop_readline_flag = False
|
| 1192 |
+
return ""
|
| 1193 |
+
line = self.text.get("iomark", "end-1c")
|
| 1194 |
+
if len(line) == 0: # may be EOF if we quit our mainloop with Ctrl-C
|
| 1195 |
+
line = "\n"
|
| 1196 |
+
self.resetoutput()
|
| 1197 |
+
if self.canceled:
|
| 1198 |
+
self.canceled = False
|
| 1199 |
+
if not use_subprocess:
|
| 1200 |
+
raise KeyboardInterrupt
|
| 1201 |
+
if self.endoffile:
|
| 1202 |
+
self.endoffile = False
|
| 1203 |
+
line = ""
|
| 1204 |
+
return line
|
| 1205 |
+
|
| 1206 |
+
def isatty(self):
|
| 1207 |
+
return True
|
| 1208 |
+
|
| 1209 |
+
def cancel_callback(self, event=None):
|
| 1210 |
+
try:
|
| 1211 |
+
if self.text.compare("sel.first", "!=", "sel.last"):
|
| 1212 |
+
return # Active selection -- always use default binding
|
| 1213 |
+
except:
|
| 1214 |
+
pass
|
| 1215 |
+
if not (self.executing or self.reading):
|
| 1216 |
+
self.resetoutput()
|
| 1217 |
+
self.interp.write("KeyboardInterrupt\n")
|
| 1218 |
+
self.showprompt()
|
| 1219 |
+
return "break"
|
| 1220 |
+
self.endoffile = False
|
| 1221 |
+
self.canceled = True
|
| 1222 |
+
if (self.executing and self.interp.rpcclt):
|
| 1223 |
+
if self.interp.getdebugger():
|
| 1224 |
+
self.interp.restart_subprocess()
|
| 1225 |
+
else:
|
| 1226 |
+
self.interp.interrupt_subprocess()
|
| 1227 |
+
if self.reading:
|
| 1228 |
+
self.top.quit() # exit the nested mainloop() in readline()
|
| 1229 |
+
return "break"
|
| 1230 |
+
|
| 1231 |
+
def eof_callback(self, event):
|
| 1232 |
+
if self.executing and not self.reading:
|
| 1233 |
+
return # Let the default binding (delete next char) take over
|
| 1234 |
+
if not (self.text.compare("iomark", "==", "insert") and
|
| 1235 |
+
self.text.compare("insert", "==", "end-1c")):
|
| 1236 |
+
return # Let the default binding (delete next char) take over
|
| 1237 |
+
if not self.executing:
|
| 1238 |
+
self.resetoutput()
|
| 1239 |
+
self.close()
|
| 1240 |
+
else:
|
| 1241 |
+
self.canceled = False
|
| 1242 |
+
self.endoffile = True
|
| 1243 |
+
self.top.quit()
|
| 1244 |
+
return "break"
|
| 1245 |
+
|
| 1246 |
+
def linefeed_callback(self, event):
|
| 1247 |
+
# Insert a linefeed without entering anything (still autoindented)
|
| 1248 |
+
if self.reading:
|
| 1249 |
+
self.text.insert("insert", "\n")
|
| 1250 |
+
self.text.see("insert")
|
| 1251 |
+
else:
|
| 1252 |
+
self.newline_and_indent_event(event)
|
| 1253 |
+
return "break"
|
| 1254 |
+
|
| 1255 |
+
def enter_callback(self, event):
|
| 1256 |
+
if self.executing and not self.reading:
|
| 1257 |
+
return # Let the default binding (insert '\n') take over
|
| 1258 |
+
# If some text is selected, recall the selection
|
| 1259 |
+
# (but only if this before the I/O mark)
|
| 1260 |
+
try:
|
| 1261 |
+
sel = self.text.get("sel.first", "sel.last")
|
| 1262 |
+
if sel:
|
| 1263 |
+
if self.text.compare("sel.last", "<=", "iomark"):
|
| 1264 |
+
self.recall(sel, event)
|
| 1265 |
+
return "break"
|
| 1266 |
+
except:
|
| 1267 |
+
pass
|
| 1268 |
+
# If we're strictly before the line containing iomark, recall
|
| 1269 |
+
# the current line, less a leading prompt, less leading or
|
| 1270 |
+
# trailing whitespace
|
| 1271 |
+
if self.text.compare("insert", "<", "iomark linestart"):
|
| 1272 |
+
# Check if there's a relevant stdin range -- if so, use it.
|
| 1273 |
+
# Note: "stdin" blocks may include several successive statements,
|
| 1274 |
+
# so look for "console" tags on the newline before each statement
|
| 1275 |
+
# (and possibly on prompts).
|
| 1276 |
+
prev = self.text.tag_prevrange("stdin", "insert")
|
| 1277 |
+
if (
|
| 1278 |
+
prev and
|
| 1279 |
+
self.text.compare("insert", "<", prev[1]) and
|
| 1280 |
+
# The following is needed to handle empty statements.
|
| 1281 |
+
"console" not in self.text.tag_names("insert")
|
| 1282 |
+
):
|
| 1283 |
+
prev_cons = self.text.tag_prevrange("console", "insert")
|
| 1284 |
+
if prev_cons and self.text.compare(prev_cons[1], ">=", prev[0]):
|
| 1285 |
+
prev = (prev_cons[1], prev[1])
|
| 1286 |
+
next_cons = self.text.tag_nextrange("console", "insert")
|
| 1287 |
+
if next_cons and self.text.compare(next_cons[0], "<", prev[1]):
|
| 1288 |
+
prev = (prev[0], self.text.index(next_cons[0] + "+1c"))
|
| 1289 |
+
self.recall(self.text.get(prev[0], prev[1]), event)
|
| 1290 |
+
return "break"
|
| 1291 |
+
next = self.text.tag_nextrange("stdin", "insert")
|
| 1292 |
+
if next and self.text.compare("insert lineend", ">=", next[0]):
|
| 1293 |
+
next_cons = self.text.tag_nextrange("console", "insert lineend")
|
| 1294 |
+
if next_cons and self.text.compare(next_cons[0], "<", next[1]):
|
| 1295 |
+
next = (next[0], self.text.index(next_cons[0] + "+1c"))
|
| 1296 |
+
self.recall(self.text.get(next[0], next[1]), event)
|
| 1297 |
+
return "break"
|
| 1298 |
+
# No stdin mark -- just get the current line, less any prompt
|
| 1299 |
+
indices = self.text.tag_nextrange("console", "insert linestart")
|
| 1300 |
+
if indices and \
|
| 1301 |
+
self.text.compare(indices[0], "<=", "insert linestart"):
|
| 1302 |
+
self.recall(self.text.get(indices[1], "insert lineend"), event)
|
| 1303 |
+
else:
|
| 1304 |
+
self.recall(self.text.get("insert linestart", "insert lineend"), event)
|
| 1305 |
+
return "break"
|
| 1306 |
+
# If we're between the beginning of the line and the iomark, i.e.
|
| 1307 |
+
# in the prompt area, move to the end of the prompt
|
| 1308 |
+
if self.text.compare("insert", "<", "iomark"):
|
| 1309 |
+
self.text.mark_set("insert", "iomark")
|
| 1310 |
+
# If we're in the current input and there's only whitespace
|
| 1311 |
+
# beyond the cursor, erase that whitespace first
|
| 1312 |
+
s = self.text.get("insert", "end-1c")
|
| 1313 |
+
if s and not s.strip():
|
| 1314 |
+
self.text.delete("insert", "end-1c")
|
| 1315 |
+
# If we're in the current input before its last line,
|
| 1316 |
+
# insert a newline right at the insert point
|
| 1317 |
+
if self.text.compare("insert", "<", "end-1c linestart"):
|
| 1318 |
+
self.newline_and_indent_event(event)
|
| 1319 |
+
return "break"
|
| 1320 |
+
# We're in the last line; append a newline and submit it
|
| 1321 |
+
self.text.mark_set("insert", "end-1c")
|
| 1322 |
+
if self.reading:
|
| 1323 |
+
self.text.insert("insert", "\n")
|
| 1324 |
+
self.text.see("insert")
|
| 1325 |
+
else:
|
| 1326 |
+
self.newline_and_indent_event(event)
|
| 1327 |
+
self.text.update_idletasks()
|
| 1328 |
+
if self.reading:
|
| 1329 |
+
self.top.quit() # Break out of recursive mainloop()
|
| 1330 |
+
else:
|
| 1331 |
+
self.runit()
|
| 1332 |
+
return "break"
|
| 1333 |
+
|
| 1334 |
+
def recall(self, s, event):
|
| 1335 |
+
# remove leading and trailing empty or whitespace lines
|
| 1336 |
+
s = re.sub(r'^\s*\n', '', s)
|
| 1337 |
+
s = re.sub(r'\n\s*$', '', s)
|
| 1338 |
+
lines = s.split('\n')
|
| 1339 |
+
self.text.undo_block_start()
|
| 1340 |
+
try:
|
| 1341 |
+
self.text.tag_remove("sel", "1.0", "end")
|
| 1342 |
+
self.text.mark_set("insert", "end-1c")
|
| 1343 |
+
prefix = self.text.get("insert linestart", "insert")
|
| 1344 |
+
if prefix.rstrip().endswith(':'):
|
| 1345 |
+
self.newline_and_indent_event(event)
|
| 1346 |
+
prefix = self.text.get("insert linestart", "insert")
|
| 1347 |
+
self.text.insert("insert", lines[0].strip(),
|
| 1348 |
+
self.user_input_insert_tags)
|
| 1349 |
+
if len(lines) > 1:
|
| 1350 |
+
orig_base_indent = re.search(r'^([ \t]*)', lines[0]).group(0)
|
| 1351 |
+
new_base_indent = re.search(r'^([ \t]*)', prefix).group(0)
|
| 1352 |
+
for line in lines[1:]:
|
| 1353 |
+
if line.startswith(orig_base_indent):
|
| 1354 |
+
# replace orig base indentation with new indentation
|
| 1355 |
+
line = new_base_indent + line[len(orig_base_indent):]
|
| 1356 |
+
self.text.insert('insert', '\n' + line.rstrip(),
|
| 1357 |
+
self.user_input_insert_tags)
|
| 1358 |
+
finally:
|
| 1359 |
+
self.text.see("insert")
|
| 1360 |
+
self.text.undo_block_stop()
|
| 1361 |
+
|
| 1362 |
+
_last_newline_re = re.compile(r"[ \t]*(\n[ \t]*)?\Z")
|
| 1363 |
+
def runit(self):
|
| 1364 |
+
index_before = self.text.index("end-2c")
|
| 1365 |
+
line = self.text.get("iomark", "end-1c")
|
| 1366 |
+
# Strip off last newline and surrounding whitespace.
|
| 1367 |
+
# (To allow you to hit return twice to end a statement.)
|
| 1368 |
+
line = self._last_newline_re.sub("", line)
|
| 1369 |
+
input_is_complete = self.interp.runsource(line)
|
| 1370 |
+
if not input_is_complete:
|
| 1371 |
+
if self.text.get(index_before) == '\n':
|
| 1372 |
+
self.text.tag_remove(self.user_input_insert_tags, index_before)
|
| 1373 |
+
self.shell_sidebar.update_sidebar()
|
| 1374 |
+
|
| 1375 |
+
def open_stack_viewer(self, event=None):
|
| 1376 |
+
if self.interp.rpcclt:
|
| 1377 |
+
return self.interp.remote_stack_viewer()
|
| 1378 |
+
try:
|
| 1379 |
+
sys.last_traceback
|
| 1380 |
+
except:
|
| 1381 |
+
messagebox.showerror("No stack trace",
|
| 1382 |
+
"There is no stack trace yet.\n"
|
| 1383 |
+
"(sys.last_traceback is not defined)",
|
| 1384 |
+
parent=self.text)
|
| 1385 |
+
return
|
| 1386 |
+
from idlelib.stackviewer import StackBrowser
|
| 1387 |
+
StackBrowser(self.root, self.flist)
|
| 1388 |
+
|
| 1389 |
+
def view_restart_mark(self, event=None):
|
| 1390 |
+
self.text.see("iomark")
|
| 1391 |
+
self.text.see("restart")
|
| 1392 |
+
|
| 1393 |
+
def restart_shell(self, event=None):
|
| 1394 |
+
"Callback for Run/Restart Shell Cntl-F6"
|
| 1395 |
+
self.interp.restart_subprocess(with_cwd=True)
|
| 1396 |
+
|
| 1397 |
+
def showprompt(self):
|
| 1398 |
+
self.resetoutput()
|
| 1399 |
+
|
| 1400 |
+
prompt = self.prompt
|
| 1401 |
+
if self.sys_ps1 and prompt.endswith(self.sys_ps1):
|
| 1402 |
+
prompt = prompt[:-len(self.sys_ps1)]
|
| 1403 |
+
self.text.tag_add("console", "iomark-1c")
|
| 1404 |
+
self.console.write(prompt)
|
| 1405 |
+
|
| 1406 |
+
self.shell_sidebar.update_sidebar()
|
| 1407 |
+
self.text.mark_set("insert", "end-1c")
|
| 1408 |
+
self.set_line_and_column()
|
| 1409 |
+
self.io.reset_undo()
|
| 1410 |
+
|
| 1411 |
+
def show_warning(self, msg):
|
| 1412 |
+
width = self.interp.tkconsole.width
|
| 1413 |
+
wrapper = TextWrapper(width=width, tabsize=8, expand_tabs=True)
|
| 1414 |
+
wrapped_msg = '\n'.join(wrapper.wrap(msg))
|
| 1415 |
+
if not wrapped_msg.endswith('\n'):
|
| 1416 |
+
wrapped_msg += '\n'
|
| 1417 |
+
self.per.bottom.insert("iomark linestart", wrapped_msg, "stderr")
|
| 1418 |
+
|
| 1419 |
+
def resetoutput(self):
|
| 1420 |
+
source = self.text.get("iomark", "end-1c")
|
| 1421 |
+
if self.history:
|
| 1422 |
+
self.history.store(source)
|
| 1423 |
+
if self.text.get("end-2c") != "\n":
|
| 1424 |
+
self.text.insert("end-1c", "\n")
|
| 1425 |
+
self.text.mark_set("iomark", "end-1c")
|
| 1426 |
+
self.set_line_and_column()
|
| 1427 |
+
self.ctip.remove_calltip_window()
|
| 1428 |
+
|
| 1429 |
+
def write(self, s, tags=()):
|
| 1430 |
+
try:
|
| 1431 |
+
self.text.mark_gravity("iomark", "right")
|
| 1432 |
+
count = OutputWindow.write(self, s, tags, "iomark")
|
| 1433 |
+
self.text.mark_gravity("iomark", "left")
|
| 1434 |
+
except:
|
| 1435 |
+
raise ###pass # ### 11Aug07 KBK if we are expecting exceptions
|
| 1436 |
+
# let's find out what they are and be specific.
|
| 1437 |
+
if self.canceled:
|
| 1438 |
+
self.canceled = False
|
| 1439 |
+
if not use_subprocess:
|
| 1440 |
+
raise KeyboardInterrupt
|
| 1441 |
+
return count
|
| 1442 |
+
|
| 1443 |
+
def rmenu_check_cut(self):
|
| 1444 |
+
try:
|
| 1445 |
+
if self.text.compare('sel.first', '<', 'iomark'):
|
| 1446 |
+
return 'disabled'
|
| 1447 |
+
except TclError: # no selection, so the index 'sel.first' doesn't exist
|
| 1448 |
+
return 'disabled'
|
| 1449 |
+
return super().rmenu_check_cut()
|
| 1450 |
+
|
| 1451 |
+
def rmenu_check_paste(self):
|
| 1452 |
+
if self.text.compare('insert','<','iomark'):
|
| 1453 |
+
return 'disabled'
|
| 1454 |
+
return super().rmenu_check_paste()
|
| 1455 |
+
|
| 1456 |
+
def squeeze_current_text_event(self, event=None):
|
| 1457 |
+
self.squeezer.squeeze_current_text()
|
| 1458 |
+
self.shell_sidebar.update_sidebar()
|
| 1459 |
+
|
| 1460 |
+
def on_squeezed_expand(self, index, text, tags):
|
| 1461 |
+
self.shell_sidebar.update_sidebar()
|
| 1462 |
+
|
| 1463 |
+
|
| 1464 |
+
def fix_x11_paste(root):
|
| 1465 |
+
"Make paste replace selection on x11. See issue #5124."
|
| 1466 |
+
if root._windowingsystem == 'x11':
|
| 1467 |
+
for cls in 'Text', 'Entry', 'Spinbox':
|
| 1468 |
+
root.bind_class(
|
| 1469 |
+
cls,
|
| 1470 |
+
'<<Paste>>',
|
| 1471 |
+
'catch {%W delete sel.first sel.last}\n' +
|
| 1472 |
+
root.bind_class(cls, '<<Paste>>'))
|
| 1473 |
+
|
| 1474 |
+
|
| 1475 |
+
usage_msg = """\
|
| 1476 |
+
|
| 1477 |
+
USAGE: idle [-deins] [-t title] [file]*
|
| 1478 |
+
idle [-dns] [-t title] (-c cmd | -r file) [arg]*
|
| 1479 |
+
idle [-dns] [-t title] - [arg]*
|
| 1480 |
+
|
| 1481 |
+
-h print this help message and exit
|
| 1482 |
+
-n run IDLE without a subprocess (DEPRECATED,
|
| 1483 |
+
see Help/IDLE Help for details)
|
| 1484 |
+
|
| 1485 |
+
The following options will override the IDLE 'settings' configuration:
|
| 1486 |
+
|
| 1487 |
+
-e open an edit window
|
| 1488 |
+
-i open a shell window
|
| 1489 |
+
|
| 1490 |
+
The following options imply -i and will open a shell:
|
| 1491 |
+
|
| 1492 |
+
-c cmd run the command in a shell, or
|
| 1493 |
+
-r file run script from file
|
| 1494 |
+
|
| 1495 |
+
-d enable the debugger
|
| 1496 |
+
-s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
|
| 1497 |
+
-t title set title of shell window
|
| 1498 |
+
|
| 1499 |
+
A default edit window will be bypassed when -c, -r, or - are used.
|
| 1500 |
+
|
| 1501 |
+
[arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].
|
| 1502 |
+
|
| 1503 |
+
Examples:
|
| 1504 |
+
|
| 1505 |
+
idle
|
| 1506 |
+
Open an edit window or shell depending on IDLE's configuration.
|
| 1507 |
+
|
| 1508 |
+
idle foo.py foobar.py
|
| 1509 |
+
Edit the files, also open a shell if configured to start with shell.
|
| 1510 |
+
|
| 1511 |
+
idle -est "Baz" foo.py
|
| 1512 |
+
Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
|
| 1513 |
+
window with the title "Baz".
|
| 1514 |
+
|
| 1515 |
+
idle -c "import sys; print(sys.argv)" "foo"
|
| 1516 |
+
Open a shell window and run the command, passing "-c" in sys.argv[0]
|
| 1517 |
+
and "foo" in sys.argv[1].
|
| 1518 |
+
|
| 1519 |
+
idle -d -s -r foo.py "Hello World"
|
| 1520 |
+
Open a shell window, run a startup script, enable the debugger, and
|
| 1521 |
+
run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
|
| 1522 |
+
sys.argv[1].
|
| 1523 |
+
|
| 1524 |
+
echo "import sys; print(sys.argv)" | idle - "foobar"
|
| 1525 |
+
Open a shell window, run the script piped in, passing '' in sys.argv[0]
|
| 1526 |
+
and "foobar" in sys.argv[1].
|
| 1527 |
+
"""
|
| 1528 |
+
|
| 1529 |
+
def main():
|
| 1530 |
+
import getopt
|
| 1531 |
+
from platform import system
|
| 1532 |
+
from idlelib import testing # bool value
|
| 1533 |
+
from idlelib import macosx
|
| 1534 |
+
|
| 1535 |
+
global flist, root, use_subprocess
|
| 1536 |
+
|
| 1537 |
+
capture_warnings(True)
|
| 1538 |
+
use_subprocess = True
|
| 1539 |
+
enable_shell = False
|
| 1540 |
+
enable_edit = False
|
| 1541 |
+
debug = False
|
| 1542 |
+
cmd = None
|
| 1543 |
+
script = None
|
| 1544 |
+
startup = False
|
| 1545 |
+
try:
|
| 1546 |
+
opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:")
|
| 1547 |
+
except getopt.error as msg:
|
| 1548 |
+
print("Error: %s\n%s" % (msg, usage_msg), file=sys.stderr)
|
| 1549 |
+
sys.exit(2)
|
| 1550 |
+
for o, a in opts:
|
| 1551 |
+
if o == '-c':
|
| 1552 |
+
cmd = a
|
| 1553 |
+
enable_shell = True
|
| 1554 |
+
if o == '-d':
|
| 1555 |
+
debug = True
|
| 1556 |
+
enable_shell = True
|
| 1557 |
+
if o == '-e':
|
| 1558 |
+
enable_edit = True
|
| 1559 |
+
if o == '-h':
|
| 1560 |
+
sys.stdout.write(usage_msg)
|
| 1561 |
+
sys.exit()
|
| 1562 |
+
if o == '-i':
|
| 1563 |
+
enable_shell = True
|
| 1564 |
+
if o == '-n':
|
| 1565 |
+
print(" Warning: running IDLE without a subprocess is deprecated.",
|
| 1566 |
+
file=sys.stderr)
|
| 1567 |
+
use_subprocess = False
|
| 1568 |
+
if o == '-r':
|
| 1569 |
+
script = a
|
| 1570 |
+
if os.path.isfile(script):
|
| 1571 |
+
pass
|
| 1572 |
+
else:
|
| 1573 |
+
print("No script file: ", script)
|
| 1574 |
+
sys.exit()
|
| 1575 |
+
enable_shell = True
|
| 1576 |
+
if o == '-s':
|
| 1577 |
+
startup = True
|
| 1578 |
+
enable_shell = True
|
| 1579 |
+
if o == '-t':
|
| 1580 |
+
PyShell.shell_title = a
|
| 1581 |
+
enable_shell = True
|
| 1582 |
+
if args and args[0] == '-':
|
| 1583 |
+
cmd = sys.stdin.read()
|
| 1584 |
+
enable_shell = True
|
| 1585 |
+
# process sys.argv and sys.path:
|
| 1586 |
+
for i in range(len(sys.path)):
|
| 1587 |
+
sys.path[i] = os.path.abspath(sys.path[i])
|
| 1588 |
+
if args and args[0] == '-':
|
| 1589 |
+
sys.argv = [''] + args[1:]
|
| 1590 |
+
elif cmd:
|
| 1591 |
+
sys.argv = ['-c'] + args
|
| 1592 |
+
elif script:
|
| 1593 |
+
sys.argv = [script] + args
|
| 1594 |
+
elif args:
|
| 1595 |
+
enable_edit = True
|
| 1596 |
+
pathx = []
|
| 1597 |
+
for filename in args:
|
| 1598 |
+
pathx.append(os.path.dirname(filename))
|
| 1599 |
+
for dir in pathx:
|
| 1600 |
+
dir = os.path.abspath(dir)
|
| 1601 |
+
if not dir in sys.path:
|
| 1602 |
+
sys.path.insert(0, dir)
|
| 1603 |
+
else:
|
| 1604 |
+
dir = os.getcwd()
|
| 1605 |
+
if dir not in sys.path:
|
| 1606 |
+
sys.path.insert(0, dir)
|
| 1607 |
+
# check the IDLE settings configuration (but command line overrides)
|
| 1608 |
+
edit_start = idleConf.GetOption('main', 'General',
|
| 1609 |
+
'editor-on-startup', type='bool')
|
| 1610 |
+
enable_edit = enable_edit or edit_start
|
| 1611 |
+
enable_shell = enable_shell or not enable_edit
|
| 1612 |
+
|
| 1613 |
+
# Setup root. Don't break user code run in IDLE process.
|
| 1614 |
+
# Don't change environment when testing.
|
| 1615 |
+
if use_subprocess and not testing:
|
| 1616 |
+
NoDefaultRoot()
|
| 1617 |
+
root = Tk(className="Idle")
|
| 1618 |
+
root.withdraw()
|
| 1619 |
+
from idlelib.run import fix_scaling
|
| 1620 |
+
fix_scaling(root)
|
| 1621 |
+
|
| 1622 |
+
# set application icon
|
| 1623 |
+
icondir = os.path.join(os.path.dirname(__file__), 'Icons')
|
| 1624 |
+
if system() == 'Windows':
|
| 1625 |
+
iconfile = os.path.join(icondir, 'idle.ico')
|
| 1626 |
+
root.wm_iconbitmap(default=iconfile)
|
| 1627 |
+
elif not macosx.isAquaTk():
|
| 1628 |
+
if TkVersion >= 8.6:
|
| 1629 |
+
ext = '.png'
|
| 1630 |
+
sizes = (16, 32, 48, 256)
|
| 1631 |
+
else:
|
| 1632 |
+
ext = '.gif'
|
| 1633 |
+
sizes = (16, 32, 48)
|
| 1634 |
+
iconfiles = [os.path.join(icondir, 'idle_%d%s' % (size, ext))
|
| 1635 |
+
for size in sizes]
|
| 1636 |
+
icons = [PhotoImage(master=root, file=iconfile)
|
| 1637 |
+
for iconfile in iconfiles]
|
| 1638 |
+
root.wm_iconphoto(True, *icons)
|
| 1639 |
+
|
| 1640 |
+
# start editor and/or shell windows:
|
| 1641 |
+
fixwordbreaks(root)
|
| 1642 |
+
fix_x11_paste(root)
|
| 1643 |
+
flist = PyShellFileList(root)
|
| 1644 |
+
macosx.setupApp(root, flist)
|
| 1645 |
+
|
| 1646 |
+
if enable_edit:
|
| 1647 |
+
if not (cmd or script):
|
| 1648 |
+
for filename in args[:]:
|
| 1649 |
+
if flist.open(filename) is None:
|
| 1650 |
+
# filename is a directory actually, disconsider it
|
| 1651 |
+
args.remove(filename)
|
| 1652 |
+
if not args:
|
| 1653 |
+
flist.new()
|
| 1654 |
+
|
| 1655 |
+
if enable_shell:
|
| 1656 |
+
shell = flist.open_shell()
|
| 1657 |
+
if not shell:
|
| 1658 |
+
return # couldn't open shell
|
| 1659 |
+
if macosx.isAquaTk() and flist.dict:
|
| 1660 |
+
# On OSX: when the user has double-clicked on a file that causes
|
| 1661 |
+
# IDLE to be launched the shell window will open just in front of
|
| 1662 |
+
# the file she wants to see. Lower the interpreter window when
|
| 1663 |
+
# there are open files.
|
| 1664 |
+
shell.top.lower()
|
| 1665 |
+
else:
|
| 1666 |
+
shell = flist.pyshell
|
| 1667 |
+
|
| 1668 |
+
# Handle remaining options. If any of these are set, enable_shell
|
| 1669 |
+
# was set also, so shell must be true to reach here.
|
| 1670 |
+
if debug:
|
| 1671 |
+
shell.open_debugger()
|
| 1672 |
+
if startup:
|
| 1673 |
+
filename = os.environ.get("IDLESTARTUP") or \
|
| 1674 |
+
os.environ.get("PYTHONSTARTUP")
|
| 1675 |
+
if filename and os.path.isfile(filename):
|
| 1676 |
+
shell.interp.execfile(filename)
|
| 1677 |
+
if cmd or script:
|
| 1678 |
+
shell.interp.runcommand("""if 1:
|
| 1679 |
+
import sys as _sys
|
| 1680 |
+
_sys.argv = %r
|
| 1681 |
+
del _sys
|
| 1682 |
+
\n""" % (sys.argv,))
|
| 1683 |
+
if cmd:
|
| 1684 |
+
shell.interp.execsource(cmd)
|
| 1685 |
+
elif script:
|
| 1686 |
+
shell.interp.prepend_syspath(script)
|
| 1687 |
+
shell.interp.execfile(script)
|
| 1688 |
+
elif shell:
|
| 1689 |
+
# If there is a shell window and no cmd or script in progress,
|
| 1690 |
+
# check for problematic issues and print warning message(s) in
|
| 1691 |
+
# the IDLE shell window; this is less intrusive than always
|
| 1692 |
+
# opening a separate window.
|
| 1693 |
+
|
| 1694 |
+
# Warn if using a problematic OS X Tk version.
|
| 1695 |
+
tkversionwarning = macosx.tkVersionWarning(root)
|
| 1696 |
+
if tkversionwarning:
|
| 1697 |
+
shell.show_warning(tkversionwarning)
|
| 1698 |
+
|
| 1699 |
+
# Warn if the "Prefer tabs when opening documents" system
|
| 1700 |
+
# preference is set to "Always".
|
| 1701 |
+
prefer_tabs_preference_warning = macosx.preferTabsPreferenceWarning()
|
| 1702 |
+
if prefer_tabs_preference_warning:
|
| 1703 |
+
shell.show_warning(prefer_tabs_preference_warning)
|
| 1704 |
+
|
| 1705 |
+
while flist.inversedict: # keep IDLE running while files are open.
|
| 1706 |
+
root.mainloop()
|
| 1707 |
+
root.destroy()
|
| 1708 |
+
capture_warnings(False)
|
| 1709 |
+
|
| 1710 |
+
if __name__ == "__main__":
|
| 1711 |
+
main()
|
| 1712 |
+
|
| 1713 |
+
capture_warnings(False) # Make sure turned off; see issue 18081
|
evalkit_tf446/lib/python3.10/idlelib/redirector.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tkinter import TclError
|
| 2 |
+
|
| 3 |
+
class WidgetRedirector:
|
| 4 |
+
"""Support for redirecting arbitrary widget subcommands.
|
| 5 |
+
|
| 6 |
+
Some Tk operations don't normally pass through tkinter. For example, if a
|
| 7 |
+
character is inserted into a Text widget by pressing a key, a default Tk
|
| 8 |
+
binding to the widget's 'insert' operation is activated, and the Tk library
|
| 9 |
+
processes the insert without calling back into tkinter.
|
| 10 |
+
|
| 11 |
+
Although a binding to <Key> could be made via tkinter, what we really want
|
| 12 |
+
to do is to hook the Tk 'insert' operation itself. For one thing, we want
|
| 13 |
+
a text.insert call in idle code to have the same effect as a key press.
|
| 14 |
+
|
| 15 |
+
When a widget is instantiated, a Tcl command is created whose name is the
|
| 16 |
+
same as the pathname widget._w. This command is used to invoke the various
|
| 17 |
+
widget operations, e.g. insert (for a Text widget). We are going to hook
|
| 18 |
+
this command and provide a facility ('register') to intercept the widget
|
| 19 |
+
operation. We will also intercept method calls on the tkinter class
|
| 20 |
+
instance that represents the tk widget.
|
| 21 |
+
|
| 22 |
+
In IDLE, WidgetRedirector is used in Percolator to intercept Text
|
| 23 |
+
commands. The function being registered provides access to the top
|
| 24 |
+
of a Percolator chain. At the bottom of the chain is a call to the
|
| 25 |
+
original Tk widget operation.
|
| 26 |
+
"""
|
| 27 |
+
def __init__(self, widget):
|
| 28 |
+
'''Initialize attributes and setup redirection.
|
| 29 |
+
|
| 30 |
+
_operations: dict mapping operation name to new function.
|
| 31 |
+
widget: the widget whose tcl command is to be intercepted.
|
| 32 |
+
tk: widget.tk, a convenience attribute, probably not needed.
|
| 33 |
+
orig: new name of the original tcl command.
|
| 34 |
+
|
| 35 |
+
Since renaming to orig fails with TclError when orig already
|
| 36 |
+
exists, only one WidgetDirector can exist for a given widget.
|
| 37 |
+
'''
|
| 38 |
+
self._operations = {}
|
| 39 |
+
self.widget = widget # widget instance
|
| 40 |
+
self.tk = tk = widget.tk # widget's root
|
| 41 |
+
w = widget._w # widget's (full) Tk pathname
|
| 42 |
+
self.orig = w + "_orig"
|
| 43 |
+
# Rename the Tcl command within Tcl:
|
| 44 |
+
tk.call("rename", w, self.orig)
|
| 45 |
+
# Create a new Tcl command whose name is the widget's pathname, and
|
| 46 |
+
# whose action is to dispatch on the operation passed to the widget:
|
| 47 |
+
tk.createcommand(w, self.dispatch)
|
| 48 |
+
|
| 49 |
+
def __repr__(self):
|
| 50 |
+
return "%s(%s<%s>)" % (self.__class__.__name__,
|
| 51 |
+
self.widget.__class__.__name__,
|
| 52 |
+
self.widget._w)
|
| 53 |
+
|
| 54 |
+
def close(self):
|
| 55 |
+
"Unregister operations and revert redirection created by .__init__."
|
| 56 |
+
for operation in list(self._operations):
|
| 57 |
+
self.unregister(operation)
|
| 58 |
+
widget = self.widget
|
| 59 |
+
tk = widget.tk
|
| 60 |
+
w = widget._w
|
| 61 |
+
# Restore the original widget Tcl command.
|
| 62 |
+
tk.deletecommand(w)
|
| 63 |
+
tk.call("rename", self.orig, w)
|
| 64 |
+
del self.widget, self.tk # Should not be needed
|
| 65 |
+
# if instance is deleted after close, as in Percolator.
|
| 66 |
+
|
| 67 |
+
def register(self, operation, function):
|
| 68 |
+
'''Return OriginalCommand(operation) after registering function.
|
| 69 |
+
|
| 70 |
+
Registration adds an operation: function pair to ._operations.
|
| 71 |
+
It also adds a widget function attribute that masks the tkinter
|
| 72 |
+
class instance method. Method masking operates independently
|
| 73 |
+
from command dispatch.
|
| 74 |
+
|
| 75 |
+
If a second function is registered for the same operation, the
|
| 76 |
+
first function is replaced in both places.
|
| 77 |
+
'''
|
| 78 |
+
self._operations[operation] = function
|
| 79 |
+
setattr(self.widget, operation, function)
|
| 80 |
+
return OriginalCommand(self, operation)
|
| 81 |
+
|
| 82 |
+
def unregister(self, operation):
|
| 83 |
+
'''Return the function for the operation, or None.
|
| 84 |
+
|
| 85 |
+
Deleting the instance attribute unmasks the class attribute.
|
| 86 |
+
'''
|
| 87 |
+
if operation in self._operations:
|
| 88 |
+
function = self._operations[operation]
|
| 89 |
+
del self._operations[operation]
|
| 90 |
+
try:
|
| 91 |
+
delattr(self.widget, operation)
|
| 92 |
+
except AttributeError:
|
| 93 |
+
pass
|
| 94 |
+
return function
|
| 95 |
+
else:
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
def dispatch(self, operation, *args):
|
| 99 |
+
'''Callback from Tcl which runs when the widget is referenced.
|
| 100 |
+
|
| 101 |
+
If an operation has been registered in self._operations, apply the
|
| 102 |
+
associated function to the args passed into Tcl. Otherwise, pass the
|
| 103 |
+
operation through to Tk via the original Tcl function.
|
| 104 |
+
|
| 105 |
+
Note that if a registered function is called, the operation is not
|
| 106 |
+
passed through to Tk. Apply the function returned by self.register()
|
| 107 |
+
to *args to accomplish that. For an example, see colorizer.py.
|
| 108 |
+
|
| 109 |
+
'''
|
| 110 |
+
m = self._operations.get(operation)
|
| 111 |
+
try:
|
| 112 |
+
if m:
|
| 113 |
+
return m(*args)
|
| 114 |
+
else:
|
| 115 |
+
return self.tk.call((self.orig, operation) + args)
|
| 116 |
+
except TclError:
|
| 117 |
+
return ""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class OriginalCommand:
|
| 121 |
+
'''Callable for original tk command that has been redirected.
|
| 122 |
+
|
| 123 |
+
Returned by .register; can be used in the function registered.
|
| 124 |
+
redir = WidgetRedirector(text)
|
| 125 |
+
def my_insert(*args):
|
| 126 |
+
print("insert", args)
|
| 127 |
+
original_insert(*args)
|
| 128 |
+
original_insert = redir.register("insert", my_insert)
|
| 129 |
+
'''
|
| 130 |
+
|
| 131 |
+
def __init__(self, redir, operation):
|
| 132 |
+
'''Create .tk_call and .orig_and_operation for .__call__ method.
|
| 133 |
+
|
| 134 |
+
.redir and .operation store the input args for __repr__.
|
| 135 |
+
.tk and .orig copy attributes of .redir (probably not needed).
|
| 136 |
+
'''
|
| 137 |
+
self.redir = redir
|
| 138 |
+
self.operation = operation
|
| 139 |
+
self.tk = redir.tk # redundant with self.redir
|
| 140 |
+
self.orig = redir.orig # redundant with self.redir
|
| 141 |
+
# These two could be deleted after checking recipient code.
|
| 142 |
+
self.tk_call = redir.tk.call
|
| 143 |
+
self.orig_and_operation = (redir.orig, operation)
|
| 144 |
+
|
| 145 |
+
def __repr__(self):
|
| 146 |
+
return "%s(%r, %r)" % (self.__class__.__name__,
|
| 147 |
+
self.redir, self.operation)
|
| 148 |
+
|
| 149 |
+
def __call__(self, *args):
|
| 150 |
+
return self.tk_call(self.orig_and_operation + args)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def _widget_redirector(parent): # htest #
|
| 154 |
+
from tkinter import Toplevel, Text
|
| 155 |
+
|
| 156 |
+
top = Toplevel(parent)
|
| 157 |
+
top.title("Test WidgetRedirector")
|
| 158 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 159 |
+
top.geometry("+%d+%d" % (x, y + 175))
|
| 160 |
+
text = Text(top)
|
| 161 |
+
text.pack()
|
| 162 |
+
text.focus_set()
|
| 163 |
+
redir = WidgetRedirector(text)
|
| 164 |
+
def my_insert(*args):
|
| 165 |
+
print("insert", args)
|
| 166 |
+
original_insert(*args)
|
| 167 |
+
original_insert = redir.register("insert", my_insert)
|
| 168 |
+
|
| 169 |
+
if __name__ == "__main__":
|
| 170 |
+
from unittest import main
|
| 171 |
+
main('idlelib.idle_test.test_redirector', verbosity=2, exit=False)
|
| 172 |
+
|
| 173 |
+
from idlelib.idle_test.htest import run
|
| 174 |
+
run(_widget_redirector)
|
evalkit_tf446/lib/python3.10/idlelib/runscript.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Execute code from an editor.
|
| 2 |
+
|
| 3 |
+
Check module: do a full syntax check of the current module.
|
| 4 |
+
Also run the tabnanny to catch any inconsistent tabs.
|
| 5 |
+
|
| 6 |
+
Run module: also execute the module's code in the __main__ namespace.
|
| 7 |
+
The window must have been saved previously. The module is added to
|
| 8 |
+
sys.modules, and is also added to the __main__ namespace.
|
| 9 |
+
|
| 10 |
+
TODO: Specify command line arguments in a dialog box.
|
| 11 |
+
"""
|
| 12 |
+
import os
|
| 13 |
+
import tabnanny
|
| 14 |
+
import time
|
| 15 |
+
import tokenize
|
| 16 |
+
|
| 17 |
+
from tkinter import messagebox
|
| 18 |
+
|
| 19 |
+
from idlelib.config import idleConf
|
| 20 |
+
from idlelib import macosx
|
| 21 |
+
from idlelib import pyshell
|
| 22 |
+
from idlelib.query import CustomRun
|
| 23 |
+
from idlelib import outwin
|
| 24 |
+
|
| 25 |
+
indent_message = """Error: Inconsistent indentation detected!
|
| 26 |
+
|
| 27 |
+
1) Your indentation is outright incorrect (easy to fix), OR
|
| 28 |
+
|
| 29 |
+
2) Your indentation mixes tabs and spaces.
|
| 30 |
+
|
| 31 |
+
To fix case 2, change all tabs to spaces by using Edit->Select All followed \
|
| 32 |
+
by Format->Untabify Region and specify the number of columns used by each tab.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class ScriptBinding:
|
| 37 |
+
|
| 38 |
+
def __init__(self, editwin):
|
| 39 |
+
self.editwin = editwin
|
| 40 |
+
# Provide instance variables referenced by debugger
|
| 41 |
+
# XXX This should be done differently
|
| 42 |
+
self.flist = self.editwin.flist
|
| 43 |
+
self.root = self.editwin.root
|
| 44 |
+
# cli_args is list of strings that extends sys.argv
|
| 45 |
+
self.cli_args = []
|
| 46 |
+
self.perf = 0.0 # Workaround for macOS 11 Uni2; see bpo-42508.
|
| 47 |
+
|
| 48 |
+
def check_module_event(self, event):
|
| 49 |
+
if isinstance(self.editwin, outwin.OutputWindow):
|
| 50 |
+
self.editwin.text.bell()
|
| 51 |
+
return 'break'
|
| 52 |
+
filename = self.getfilename()
|
| 53 |
+
if not filename:
|
| 54 |
+
return 'break'
|
| 55 |
+
if not self.checksyntax(filename):
|
| 56 |
+
return 'break'
|
| 57 |
+
if not self.tabnanny(filename):
|
| 58 |
+
return 'break'
|
| 59 |
+
return "break"
|
| 60 |
+
|
| 61 |
+
def tabnanny(self, filename):
|
| 62 |
+
# XXX: tabnanny should work on binary files as well
|
| 63 |
+
with tokenize.open(filename) as f:
|
| 64 |
+
try:
|
| 65 |
+
tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
|
| 66 |
+
except tokenize.TokenError as msg:
|
| 67 |
+
msgtxt, (lineno, start) = msg.args
|
| 68 |
+
self.editwin.gotoline(lineno)
|
| 69 |
+
self.errorbox("Tabnanny Tokenizing Error",
|
| 70 |
+
"Token Error: %s" % msgtxt)
|
| 71 |
+
return False
|
| 72 |
+
except tabnanny.NannyNag as nag:
|
| 73 |
+
# The error messages from tabnanny are too confusing...
|
| 74 |
+
self.editwin.gotoline(nag.get_lineno())
|
| 75 |
+
self.errorbox("Tab/space error", indent_message)
|
| 76 |
+
return False
|
| 77 |
+
return True
|
| 78 |
+
|
| 79 |
+
def checksyntax(self, filename):
|
| 80 |
+
self.shell = shell = self.flist.open_shell()
|
| 81 |
+
saved_stream = shell.get_warning_stream()
|
| 82 |
+
shell.set_warning_stream(shell.stderr)
|
| 83 |
+
with open(filename, 'rb') as f:
|
| 84 |
+
source = f.read()
|
| 85 |
+
if b'\r' in source:
|
| 86 |
+
source = source.replace(b'\r\n', b'\n')
|
| 87 |
+
source = source.replace(b'\r', b'\n')
|
| 88 |
+
if source and source[-1] != ord(b'\n'):
|
| 89 |
+
source = source + b'\n'
|
| 90 |
+
editwin = self.editwin
|
| 91 |
+
text = editwin.text
|
| 92 |
+
text.tag_remove("ERROR", "1.0", "end")
|
| 93 |
+
try:
|
| 94 |
+
# If successful, return the compiled code
|
| 95 |
+
return compile(source, filename, "exec")
|
| 96 |
+
except (SyntaxError, OverflowError, ValueError) as value:
|
| 97 |
+
msg = getattr(value, 'msg', '') or value or "<no detail available>"
|
| 98 |
+
lineno = getattr(value, 'lineno', '') or 1
|
| 99 |
+
offset = getattr(value, 'offset', '') or 0
|
| 100 |
+
if offset == 0:
|
| 101 |
+
lineno += 1 #mark end of offending line
|
| 102 |
+
pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)
|
| 103 |
+
editwin.colorize_syntax_error(text, pos)
|
| 104 |
+
self.errorbox("SyntaxError", "%-20s" % msg)
|
| 105 |
+
return False
|
| 106 |
+
finally:
|
| 107 |
+
shell.set_warning_stream(saved_stream)
|
| 108 |
+
|
| 109 |
+
def run_custom_event(self, event):
|
| 110 |
+
return self.run_module_event(event, customize=True)
|
| 111 |
+
|
| 112 |
+
def run_module_event(self, event, *, customize=False):
|
| 113 |
+
"""Run the module after setting up the environment.
|
| 114 |
+
|
| 115 |
+
First check the syntax. Next get customization. If OK, make
|
| 116 |
+
sure the shell is active and then transfer the arguments, set
|
| 117 |
+
the run environment's working directory to the directory of the
|
| 118 |
+
module being executed and also add that directory to its
|
| 119 |
+
sys.path if not already included.
|
| 120 |
+
"""
|
| 121 |
+
if macosx.isCocoaTk() and (time.perf_counter() - self.perf < .05):
|
| 122 |
+
return 'break'
|
| 123 |
+
if isinstance(self.editwin, outwin.OutputWindow):
|
| 124 |
+
self.editwin.text.bell()
|
| 125 |
+
return 'break'
|
| 126 |
+
filename = self.getfilename()
|
| 127 |
+
if not filename:
|
| 128 |
+
return 'break'
|
| 129 |
+
code = self.checksyntax(filename)
|
| 130 |
+
if not code:
|
| 131 |
+
return 'break'
|
| 132 |
+
if not self.tabnanny(filename):
|
| 133 |
+
return 'break'
|
| 134 |
+
if customize:
|
| 135 |
+
title = f"Customize {self.editwin.short_title()} Run"
|
| 136 |
+
run_args = CustomRun(self.shell.text, title,
|
| 137 |
+
cli_args=self.cli_args).result
|
| 138 |
+
if not run_args: # User cancelled.
|
| 139 |
+
return 'break'
|
| 140 |
+
self.cli_args, restart = run_args if customize else ([], True)
|
| 141 |
+
interp = self.shell.interp
|
| 142 |
+
if pyshell.use_subprocess and restart:
|
| 143 |
+
interp.restart_subprocess(
|
| 144 |
+
with_cwd=False, filename=filename)
|
| 145 |
+
dirname = os.path.dirname(filename)
|
| 146 |
+
argv = [filename]
|
| 147 |
+
if self.cli_args:
|
| 148 |
+
argv += self.cli_args
|
| 149 |
+
interp.runcommand(f"""if 1:
|
| 150 |
+
__file__ = {filename!r}
|
| 151 |
+
import sys as _sys
|
| 152 |
+
from os.path import basename as _basename
|
| 153 |
+
argv = {argv!r}
|
| 154 |
+
if (not _sys.argv or
|
| 155 |
+
_basename(_sys.argv[0]) != _basename(__file__) or
|
| 156 |
+
len(argv) > 1):
|
| 157 |
+
_sys.argv = argv
|
| 158 |
+
import os as _os
|
| 159 |
+
_os.chdir({dirname!r})
|
| 160 |
+
del _sys, argv, _basename, _os
|
| 161 |
+
\n""")
|
| 162 |
+
interp.prepend_syspath(filename)
|
| 163 |
+
# XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
|
| 164 |
+
# go to __stderr__. With subprocess, they go to the shell.
|
| 165 |
+
# Need to change streams in pyshell.ModifiedInterpreter.
|
| 166 |
+
interp.runcode(code)
|
| 167 |
+
return 'break'
|
| 168 |
+
|
| 169 |
+
def getfilename(self):
|
| 170 |
+
"""Get source filename. If not saved, offer to save (or create) file
|
| 171 |
+
|
| 172 |
+
The debugger requires a source file. Make sure there is one, and that
|
| 173 |
+
the current version of the source buffer has been saved. If the user
|
| 174 |
+
declines to save or cancels the Save As dialog, return None.
|
| 175 |
+
|
| 176 |
+
If the user has configured IDLE for Autosave, the file will be
|
| 177 |
+
silently saved if it already exists and is dirty.
|
| 178 |
+
|
| 179 |
+
"""
|
| 180 |
+
filename = self.editwin.io.filename
|
| 181 |
+
if not self.editwin.get_saved():
|
| 182 |
+
autosave = idleConf.GetOption('main', 'General',
|
| 183 |
+
'autosave', type='bool')
|
| 184 |
+
if autosave and filename:
|
| 185 |
+
self.editwin.io.save(None)
|
| 186 |
+
else:
|
| 187 |
+
confirm = self.ask_save_dialog()
|
| 188 |
+
self.editwin.text.focus_set()
|
| 189 |
+
if confirm:
|
| 190 |
+
self.editwin.io.save(None)
|
| 191 |
+
filename = self.editwin.io.filename
|
| 192 |
+
else:
|
| 193 |
+
filename = None
|
| 194 |
+
return filename
|
| 195 |
+
|
| 196 |
+
def ask_save_dialog(self):
|
| 197 |
+
msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?"
|
| 198 |
+
confirm = messagebox.askokcancel(title="Save Before Run or Check",
|
| 199 |
+
message=msg,
|
| 200 |
+
default=messagebox.OK,
|
| 201 |
+
parent=self.editwin.text)
|
| 202 |
+
return confirm
|
| 203 |
+
|
| 204 |
+
def errorbox(self, title, message):
|
| 205 |
+
# XXX This should really be a function of EditorWindow...
|
| 206 |
+
messagebox.showerror(title, message, parent=self.editwin.text)
|
| 207 |
+
self.editwin.text.focus_set()
|
| 208 |
+
self.perf = time.perf_counter()
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
if __name__ == "__main__":
|
| 212 |
+
from unittest import main
|
| 213 |
+
main('idlelib.idle_test.test_runscript', verbosity=2,)
|
evalkit_tf446/lib/python3.10/idlelib/scrolledlist.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tkinter import *
|
| 2 |
+
from tkinter.ttk import Frame, Scrollbar
|
| 3 |
+
|
| 4 |
+
from idlelib import macosx
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ScrolledList:
|
| 8 |
+
|
| 9 |
+
default = "(None)"
|
| 10 |
+
|
| 11 |
+
def __init__(self, master, **options):
|
| 12 |
+
# Create top frame, with scrollbar and listbox
|
| 13 |
+
self.master = master
|
| 14 |
+
self.frame = frame = Frame(master)
|
| 15 |
+
self.frame.pack(fill="both", expand=1)
|
| 16 |
+
self.vbar = vbar = Scrollbar(frame, name="vbar")
|
| 17 |
+
self.vbar.pack(side="right", fill="y")
|
| 18 |
+
self.listbox = listbox = Listbox(frame, exportselection=0,
|
| 19 |
+
background="white")
|
| 20 |
+
if options:
|
| 21 |
+
listbox.configure(options)
|
| 22 |
+
listbox.pack(expand=1, fill="both")
|
| 23 |
+
# Tie listbox and scrollbar together
|
| 24 |
+
vbar["command"] = listbox.yview
|
| 25 |
+
listbox["yscrollcommand"] = vbar.set
|
| 26 |
+
# Bind events to the list box
|
| 27 |
+
listbox.bind("<ButtonRelease-1>", self.click_event)
|
| 28 |
+
listbox.bind("<Double-ButtonRelease-1>", self.double_click_event)
|
| 29 |
+
if macosx.isAquaTk():
|
| 30 |
+
listbox.bind("<ButtonPress-2>", self.popup_event)
|
| 31 |
+
listbox.bind("<Control-Button-1>", self.popup_event)
|
| 32 |
+
else:
|
| 33 |
+
listbox.bind("<ButtonPress-3>", self.popup_event)
|
| 34 |
+
listbox.bind("<Key-Up>", self.up_event)
|
| 35 |
+
listbox.bind("<Key-Down>", self.down_event)
|
| 36 |
+
# Mark as empty
|
| 37 |
+
self.clear()
|
| 38 |
+
|
| 39 |
+
def close(self):
|
| 40 |
+
self.frame.destroy()
|
| 41 |
+
|
| 42 |
+
def clear(self):
|
| 43 |
+
self.listbox.delete(0, "end")
|
| 44 |
+
self.empty = 1
|
| 45 |
+
self.listbox.insert("end", self.default)
|
| 46 |
+
|
| 47 |
+
def append(self, item):
|
| 48 |
+
if self.empty:
|
| 49 |
+
self.listbox.delete(0, "end")
|
| 50 |
+
self.empty = 0
|
| 51 |
+
self.listbox.insert("end", str(item))
|
| 52 |
+
|
| 53 |
+
def get(self, index):
|
| 54 |
+
return self.listbox.get(index)
|
| 55 |
+
|
| 56 |
+
def click_event(self, event):
|
| 57 |
+
self.listbox.activate("@%d,%d" % (event.x, event.y))
|
| 58 |
+
index = self.listbox.index("active")
|
| 59 |
+
self.select(index)
|
| 60 |
+
self.on_select(index)
|
| 61 |
+
return "break"
|
| 62 |
+
|
| 63 |
+
def double_click_event(self, event):
|
| 64 |
+
index = self.listbox.index("active")
|
| 65 |
+
self.select(index)
|
| 66 |
+
self.on_double(index)
|
| 67 |
+
return "break"
|
| 68 |
+
|
| 69 |
+
menu = None
|
| 70 |
+
|
| 71 |
+
def popup_event(self, event):
|
| 72 |
+
if not self.menu:
|
| 73 |
+
self.make_menu()
|
| 74 |
+
menu = self.menu
|
| 75 |
+
self.listbox.activate("@%d,%d" % (event.x, event.y))
|
| 76 |
+
index = self.listbox.index("active")
|
| 77 |
+
self.select(index)
|
| 78 |
+
menu.tk_popup(event.x_root, event.y_root)
|
| 79 |
+
return "break"
|
| 80 |
+
|
| 81 |
+
def make_menu(self):
|
| 82 |
+
menu = Menu(self.listbox, tearoff=0)
|
| 83 |
+
self.menu = menu
|
| 84 |
+
self.fill_menu()
|
| 85 |
+
|
| 86 |
+
def up_event(self, event):
|
| 87 |
+
index = self.listbox.index("active")
|
| 88 |
+
if self.listbox.selection_includes(index):
|
| 89 |
+
index = index - 1
|
| 90 |
+
else:
|
| 91 |
+
index = self.listbox.size() - 1
|
| 92 |
+
if index < 0:
|
| 93 |
+
self.listbox.bell()
|
| 94 |
+
else:
|
| 95 |
+
self.select(index)
|
| 96 |
+
self.on_select(index)
|
| 97 |
+
return "break"
|
| 98 |
+
|
| 99 |
+
def down_event(self, event):
|
| 100 |
+
index = self.listbox.index("active")
|
| 101 |
+
if self.listbox.selection_includes(index):
|
| 102 |
+
index = index + 1
|
| 103 |
+
else:
|
| 104 |
+
index = 0
|
| 105 |
+
if index >= self.listbox.size():
|
| 106 |
+
self.listbox.bell()
|
| 107 |
+
else:
|
| 108 |
+
self.select(index)
|
| 109 |
+
self.on_select(index)
|
| 110 |
+
return "break"
|
| 111 |
+
|
| 112 |
+
def select(self, index):
|
| 113 |
+
self.listbox.focus_set()
|
| 114 |
+
self.listbox.activate(index)
|
| 115 |
+
self.listbox.selection_clear(0, "end")
|
| 116 |
+
self.listbox.selection_set(index)
|
| 117 |
+
self.listbox.see(index)
|
| 118 |
+
|
| 119 |
+
# Methods to override for specific actions
|
| 120 |
+
|
| 121 |
+
def fill_menu(self):
|
| 122 |
+
pass
|
| 123 |
+
|
| 124 |
+
def on_select(self, index):
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
def on_double(self, index):
|
| 128 |
+
pass
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _scrolled_list(parent): # htest #
|
| 132 |
+
top = Toplevel(parent)
|
| 133 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 134 |
+
top.geometry("+%d+%d" % (x+200, y + 175))
|
| 135 |
+
class MyScrolledList(ScrolledList):
|
| 136 |
+
def fill_menu(self): self.menu.add_command(label="right click")
|
| 137 |
+
def on_select(self, index): print("select", self.get(index))
|
| 138 |
+
def on_double(self, index): print("double", self.get(index))
|
| 139 |
+
|
| 140 |
+
scrolled_list = MyScrolledList(top)
|
| 141 |
+
for i in range(30):
|
| 142 |
+
scrolled_list.append("Item %02d" % i)
|
| 143 |
+
|
| 144 |
+
if __name__ == '__main__':
|
| 145 |
+
from unittest import main
|
| 146 |
+
main('idlelib.idle_test.test_scrolledlist', verbosity=2,)
|
| 147 |
+
|
| 148 |
+
from idlelib.idle_test.htest import run
|
| 149 |
+
run(_scrolled_list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
|
|
|
|
|
|
|
|
|
|
| 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)
|
evalkit_tf446/lib/python3.10/idlelib/searchbase.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Define SearchDialogBase used by Search, Replace, and Grep dialogs.'''
|
| 2 |
+
|
| 3 |
+
from tkinter import Toplevel
|
| 4 |
+
from tkinter.ttk import Frame, Entry, Label, Button, Checkbutton, Radiobutton
|
| 5 |
+
from tkinter.simpledialog import _setup_dialog
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class SearchDialogBase:
|
| 9 |
+
'''Create most of a 3 or 4 row, 3 column search dialog.
|
| 10 |
+
|
| 11 |
+
The left and wide middle column contain:
|
| 12 |
+
1 or 2 labeled text entry lines (make_entry, create_entries);
|
| 13 |
+
a row of standard Checkbuttons (make_frame, create_option_buttons),
|
| 14 |
+
each of which corresponds to a search engine Variable;
|
| 15 |
+
a row of dialog-specific Check/Radiobuttons (create_other_buttons).
|
| 16 |
+
|
| 17 |
+
The narrow right column contains command buttons
|
| 18 |
+
(make_button, create_command_buttons).
|
| 19 |
+
These are bound to functions that execute the command.
|
| 20 |
+
|
| 21 |
+
Except for command buttons, this base class is not limited to items
|
| 22 |
+
common to all three subclasses. Rather, it is the Find dialog minus
|
| 23 |
+
the "Find Next" command, its execution function, and the
|
| 24 |
+
default_command attribute needed in create_widgets. The other
|
| 25 |
+
dialogs override attributes and methods, the latter to replace and
|
| 26 |
+
add widgets.
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
title = "Search Dialog" # replace in subclasses
|
| 30 |
+
icon = "Search"
|
| 31 |
+
needwrapbutton = 1 # not in Find in Files
|
| 32 |
+
|
| 33 |
+
def __init__(self, root, engine):
|
| 34 |
+
'''Initialize root, engine, and top attributes.
|
| 35 |
+
|
| 36 |
+
top (level widget): set in create_widgets() called from open().
|
| 37 |
+
frame: container for all widgets in dialog.
|
| 38 |
+
text (Text searched): set in open(), only used in subclasses().
|
| 39 |
+
ent (ry): created in make_entry() called from create_entry().
|
| 40 |
+
row (of grid): 0 in create_widgets(), +1 in make_entry/frame().
|
| 41 |
+
default_command: set in subclasses, used in create_widgets().
|
| 42 |
+
|
| 43 |
+
title (of dialog): class attribute, override in subclasses.
|
| 44 |
+
icon (of dialog): ditto, use unclear if cannot minimize dialog.
|
| 45 |
+
'''
|
| 46 |
+
self.root = root
|
| 47 |
+
self.bell = root.bell
|
| 48 |
+
self.engine = engine
|
| 49 |
+
self.top = None
|
| 50 |
+
|
| 51 |
+
def open(self, text, searchphrase=None):
|
| 52 |
+
"Make dialog visible on top of others and ready to use."
|
| 53 |
+
self.text = text
|
| 54 |
+
if not self.top:
|
| 55 |
+
self.create_widgets()
|
| 56 |
+
else:
|
| 57 |
+
self.top.deiconify()
|
| 58 |
+
self.top.tkraise()
|
| 59 |
+
self.top.transient(text.winfo_toplevel())
|
| 60 |
+
if searchphrase:
|
| 61 |
+
self.ent.delete(0,"end")
|
| 62 |
+
self.ent.insert("end",searchphrase)
|
| 63 |
+
self.ent.focus_set()
|
| 64 |
+
self.ent.selection_range(0, "end")
|
| 65 |
+
self.ent.icursor(0)
|
| 66 |
+
self.top.grab_set()
|
| 67 |
+
|
| 68 |
+
def close(self, event=None):
|
| 69 |
+
"Put dialog away for later use."
|
| 70 |
+
if self.top:
|
| 71 |
+
self.top.grab_release()
|
| 72 |
+
self.top.transient('')
|
| 73 |
+
self.top.withdraw()
|
| 74 |
+
|
| 75 |
+
def create_widgets(self):
|
| 76 |
+
'''Create basic 3 row x 3 col search (find) dialog.
|
| 77 |
+
|
| 78 |
+
Other dialogs override subsidiary create_x methods as needed.
|
| 79 |
+
Replace and Find-in-Files add another entry row.
|
| 80 |
+
'''
|
| 81 |
+
top = Toplevel(self.root)
|
| 82 |
+
top.bind("<Return>", self.default_command)
|
| 83 |
+
top.bind("<Escape>", self.close)
|
| 84 |
+
top.protocol("WM_DELETE_WINDOW", self.close)
|
| 85 |
+
top.wm_title(self.title)
|
| 86 |
+
top.wm_iconname(self.icon)
|
| 87 |
+
_setup_dialog(top)
|
| 88 |
+
self.top = top
|
| 89 |
+
self.frame = Frame(top, padding="5px")
|
| 90 |
+
self.frame.grid(sticky="nwes")
|
| 91 |
+
top.grid_columnconfigure(0, weight=100)
|
| 92 |
+
top.grid_rowconfigure(0, weight=100)
|
| 93 |
+
|
| 94 |
+
self.row = 0
|
| 95 |
+
self.frame.grid_columnconfigure(0, pad=2, weight=0)
|
| 96 |
+
self.frame.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
|
| 97 |
+
|
| 98 |
+
self.create_entries() # row 0 (and maybe 1), cols 0, 1
|
| 99 |
+
self.create_option_buttons() # next row, cols 0, 1
|
| 100 |
+
self.create_other_buttons() # next row, cols 0, 1
|
| 101 |
+
self.create_command_buttons() # col 2, all rows
|
| 102 |
+
|
| 103 |
+
def make_entry(self, label_text, var):
|
| 104 |
+
'''Return (entry, label), .
|
| 105 |
+
|
| 106 |
+
entry - gridded labeled Entry for text entry.
|
| 107 |
+
label - Label widget, returned for testing.
|
| 108 |
+
'''
|
| 109 |
+
label = Label(self.frame, text=label_text)
|
| 110 |
+
label.grid(row=self.row, column=0, sticky="nw")
|
| 111 |
+
entry = Entry(self.frame, textvariable=var, exportselection=0)
|
| 112 |
+
entry.grid(row=self.row, column=1, sticky="nwe")
|
| 113 |
+
self.row = self.row + 1
|
| 114 |
+
return entry, label
|
| 115 |
+
|
| 116 |
+
def create_entries(self):
|
| 117 |
+
"Create one or more entry lines with make_entry."
|
| 118 |
+
self.ent = self.make_entry("Find:", self.engine.patvar)[0]
|
| 119 |
+
|
| 120 |
+
def make_frame(self,labeltext=None):
|
| 121 |
+
'''Return (frame, label).
|
| 122 |
+
|
| 123 |
+
frame - gridded labeled Frame for option or other buttons.
|
| 124 |
+
label - Label widget, returned for testing.
|
| 125 |
+
'''
|
| 126 |
+
if labeltext:
|
| 127 |
+
label = Label(self.frame, text=labeltext)
|
| 128 |
+
label.grid(row=self.row, column=0, sticky="nw")
|
| 129 |
+
else:
|
| 130 |
+
label = ''
|
| 131 |
+
frame = Frame(self.frame)
|
| 132 |
+
frame.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
|
| 133 |
+
self.row = self.row + 1
|
| 134 |
+
return frame, label
|
| 135 |
+
|
| 136 |
+
def create_option_buttons(self):
|
| 137 |
+
'''Return (filled frame, options) for testing.
|
| 138 |
+
|
| 139 |
+
Options is a list of searchengine booleanvar, label pairs.
|
| 140 |
+
A gridded frame from make_frame is filled with a Checkbutton
|
| 141 |
+
for each pair, bound to the var, with the corresponding label.
|
| 142 |
+
'''
|
| 143 |
+
frame = self.make_frame("Options")[0]
|
| 144 |
+
engine = self.engine
|
| 145 |
+
options = [(engine.revar, "Regular expression"),
|
| 146 |
+
(engine.casevar, "Match case"),
|
| 147 |
+
(engine.wordvar, "Whole word")]
|
| 148 |
+
if self.needwrapbutton:
|
| 149 |
+
options.append((engine.wrapvar, "Wrap around"))
|
| 150 |
+
for var, label in options:
|
| 151 |
+
btn = Checkbutton(frame, variable=var, text=label)
|
| 152 |
+
btn.pack(side="left", fill="both")
|
| 153 |
+
return frame, options
|
| 154 |
+
|
| 155 |
+
def create_other_buttons(self):
|
| 156 |
+
'''Return (frame, others) for testing.
|
| 157 |
+
|
| 158 |
+
Others is a list of value, label pairs.
|
| 159 |
+
A gridded frame from make_frame is filled with radio buttons.
|
| 160 |
+
'''
|
| 161 |
+
frame = self.make_frame("Direction")[0]
|
| 162 |
+
var = self.engine.backvar
|
| 163 |
+
others = [(1, 'Up'), (0, 'Down')]
|
| 164 |
+
for val, label in others:
|
| 165 |
+
btn = Radiobutton(frame, variable=var, value=val, text=label)
|
| 166 |
+
btn.pack(side="left", fill="both")
|
| 167 |
+
return frame, others
|
| 168 |
+
|
| 169 |
+
def make_button(self, label, command, isdef=0):
|
| 170 |
+
"Return command button gridded in command frame."
|
| 171 |
+
b = Button(self.buttonframe,
|
| 172 |
+
text=label, command=command,
|
| 173 |
+
default=isdef and "active" or "normal")
|
| 174 |
+
cols,rows=self.buttonframe.grid_size()
|
| 175 |
+
b.grid(pady=1,row=rows,column=0,sticky="ew")
|
| 176 |
+
self.buttonframe.grid(rowspan=rows+1)
|
| 177 |
+
return b
|
| 178 |
+
|
| 179 |
+
def create_command_buttons(self):
|
| 180 |
+
"Place buttons in vertical command frame gridded on right."
|
| 181 |
+
f = self.buttonframe = Frame(self.frame)
|
| 182 |
+
f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)
|
| 183 |
+
|
| 184 |
+
b = self.make_button("Close", self.close)
|
| 185 |
+
b.lower()
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class _searchbase(SearchDialogBase): # htest #
|
| 189 |
+
"Create auto-opening dialog with no text connection."
|
| 190 |
+
|
| 191 |
+
def __init__(self, parent):
|
| 192 |
+
import re
|
| 193 |
+
from idlelib import searchengine
|
| 194 |
+
|
| 195 |
+
self.root = parent
|
| 196 |
+
self.engine = searchengine.get(parent)
|
| 197 |
+
self.create_widgets()
|
| 198 |
+
print(parent.geometry())
|
| 199 |
+
width,height, x,y = list(map(int, re.split('[x+]', parent.geometry())))
|
| 200 |
+
self.top.geometry("+%d+%d" % (x + 40, y + 175))
|
| 201 |
+
|
| 202 |
+
def default_command(self, dummy): pass
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
if __name__ == '__main__':
|
| 206 |
+
from unittest import main
|
| 207 |
+
main('idlelib.idle_test.test_searchbase', verbosity=2, exit=False)
|
| 208 |
+
|
| 209 |
+
from idlelib.idle_test.htest import run
|
| 210 |
+
run(_searchbase)
|
evalkit_tf446/lib/python3.10/idlelib/searchengine.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Define SearchEngine for search dialogs.'''
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
from tkinter import StringVar, BooleanVar, TclError
|
| 5 |
+
from tkinter import messagebox
|
| 6 |
+
|
| 7 |
+
def get(root):
|
| 8 |
+
'''Return the singleton SearchEngine instance for the process.
|
| 9 |
+
|
| 10 |
+
The single SearchEngine saves settings between dialog instances.
|
| 11 |
+
If there is not a SearchEngine already, make one.
|
| 12 |
+
'''
|
| 13 |
+
if not hasattr(root, "_searchengine"):
|
| 14 |
+
root._searchengine = SearchEngine(root)
|
| 15 |
+
# This creates a cycle that persists until root is deleted.
|
| 16 |
+
return root._searchengine
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SearchEngine:
|
| 20 |
+
"""Handles searching a text widget for Find, Replace, and Grep."""
|
| 21 |
+
|
| 22 |
+
def __init__(self, root):
|
| 23 |
+
'''Initialize Variables that save search state.
|
| 24 |
+
|
| 25 |
+
The dialogs bind these to the UI elements present in the dialogs.
|
| 26 |
+
'''
|
| 27 |
+
self.root = root # need for report_error()
|
| 28 |
+
self.patvar = StringVar(root, '') # search pattern
|
| 29 |
+
self.revar = BooleanVar(root, False) # regular expression?
|
| 30 |
+
self.casevar = BooleanVar(root, False) # match case?
|
| 31 |
+
self.wordvar = BooleanVar(root, False) # match whole word?
|
| 32 |
+
self.wrapvar = BooleanVar(root, True) # wrap around buffer?
|
| 33 |
+
self.backvar = BooleanVar(root, False) # search backwards?
|
| 34 |
+
|
| 35 |
+
# Access methods
|
| 36 |
+
|
| 37 |
+
def getpat(self):
|
| 38 |
+
return self.patvar.get()
|
| 39 |
+
|
| 40 |
+
def setpat(self, pat):
|
| 41 |
+
self.patvar.set(pat)
|
| 42 |
+
|
| 43 |
+
def isre(self):
|
| 44 |
+
return self.revar.get()
|
| 45 |
+
|
| 46 |
+
def iscase(self):
|
| 47 |
+
return self.casevar.get()
|
| 48 |
+
|
| 49 |
+
def isword(self):
|
| 50 |
+
return self.wordvar.get()
|
| 51 |
+
|
| 52 |
+
def iswrap(self):
|
| 53 |
+
return self.wrapvar.get()
|
| 54 |
+
|
| 55 |
+
def isback(self):
|
| 56 |
+
return self.backvar.get()
|
| 57 |
+
|
| 58 |
+
# Higher level access methods
|
| 59 |
+
|
| 60 |
+
def setcookedpat(self, pat):
|
| 61 |
+
"Set pattern after escaping if re."
|
| 62 |
+
# called only in search.py: 66
|
| 63 |
+
if self.isre():
|
| 64 |
+
pat = re.escape(pat)
|
| 65 |
+
self.setpat(pat)
|
| 66 |
+
|
| 67 |
+
def getcookedpat(self):
|
| 68 |
+
pat = self.getpat()
|
| 69 |
+
if not self.isre(): # if True, see setcookedpat
|
| 70 |
+
pat = re.escape(pat)
|
| 71 |
+
if self.isword():
|
| 72 |
+
pat = r"\b%s\b" % pat
|
| 73 |
+
return pat
|
| 74 |
+
|
| 75 |
+
def getprog(self):
|
| 76 |
+
"Return compiled cooked search pattern."
|
| 77 |
+
pat = self.getpat()
|
| 78 |
+
if not pat:
|
| 79 |
+
self.report_error(pat, "Empty regular expression")
|
| 80 |
+
return None
|
| 81 |
+
pat = self.getcookedpat()
|
| 82 |
+
flags = 0
|
| 83 |
+
if not self.iscase():
|
| 84 |
+
flags = flags | re.IGNORECASE
|
| 85 |
+
try:
|
| 86 |
+
prog = re.compile(pat, flags)
|
| 87 |
+
except re.error as e:
|
| 88 |
+
self.report_error(pat, e.msg, e.pos)
|
| 89 |
+
return None
|
| 90 |
+
return prog
|
| 91 |
+
|
| 92 |
+
def report_error(self, pat, msg, col=None):
|
| 93 |
+
# Derived class could override this with something fancier
|
| 94 |
+
msg = "Error: " + str(msg)
|
| 95 |
+
if pat:
|
| 96 |
+
msg = msg + "\nPattern: " + str(pat)
|
| 97 |
+
if col is not None:
|
| 98 |
+
msg = msg + "\nOffset: " + str(col)
|
| 99 |
+
messagebox.showerror("Regular expression error",
|
| 100 |
+
msg, master=self.root)
|
| 101 |
+
|
| 102 |
+
def search_text(self, text, prog=None, ok=0):
|
| 103 |
+
'''Return (lineno, matchobj) or None for forward/backward search.
|
| 104 |
+
|
| 105 |
+
This function calls the right function with the right arguments.
|
| 106 |
+
It directly return the result of that call.
|
| 107 |
+
|
| 108 |
+
Text is a text widget. Prog is a precompiled pattern.
|
| 109 |
+
The ok parameter is a bit complicated as it has two effects.
|
| 110 |
+
|
| 111 |
+
If there is a selection, the search begin at either end,
|
| 112 |
+
depending on the direction setting and ok, with ok meaning that
|
| 113 |
+
the search starts with the selection. Otherwise, search begins
|
| 114 |
+
at the insert mark.
|
| 115 |
+
|
| 116 |
+
To aid progress, the search functions do not return an empty
|
| 117 |
+
match at the starting position unless ok is True.
|
| 118 |
+
'''
|
| 119 |
+
|
| 120 |
+
if not prog:
|
| 121 |
+
prog = self.getprog()
|
| 122 |
+
if not prog:
|
| 123 |
+
return None # Compilation failed -- stop
|
| 124 |
+
wrap = self.wrapvar.get()
|
| 125 |
+
first, last = get_selection(text)
|
| 126 |
+
if self.isback():
|
| 127 |
+
if ok:
|
| 128 |
+
start = last
|
| 129 |
+
else:
|
| 130 |
+
start = first
|
| 131 |
+
line, col = get_line_col(start)
|
| 132 |
+
res = self.search_backward(text, prog, line, col, wrap, ok)
|
| 133 |
+
else:
|
| 134 |
+
if ok:
|
| 135 |
+
start = first
|
| 136 |
+
else:
|
| 137 |
+
start = last
|
| 138 |
+
line, col = get_line_col(start)
|
| 139 |
+
res = self.search_forward(text, prog, line, col, wrap, ok)
|
| 140 |
+
return res
|
| 141 |
+
|
| 142 |
+
def search_forward(self, text, prog, line, col, wrap, ok=0):
|
| 143 |
+
wrapped = 0
|
| 144 |
+
startline = line
|
| 145 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 146 |
+
while chars:
|
| 147 |
+
m = prog.search(chars[:-1], col)
|
| 148 |
+
if m:
|
| 149 |
+
if ok or m.end() > col:
|
| 150 |
+
return line, m
|
| 151 |
+
line = line + 1
|
| 152 |
+
if wrapped and line > startline:
|
| 153 |
+
break
|
| 154 |
+
col = 0
|
| 155 |
+
ok = 1
|
| 156 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 157 |
+
if not chars and wrap:
|
| 158 |
+
wrapped = 1
|
| 159 |
+
wrap = 0
|
| 160 |
+
line = 1
|
| 161 |
+
chars = text.get("1.0", "2.0")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
def search_backward(self, text, prog, line, col, wrap, ok=0):
|
| 165 |
+
wrapped = 0
|
| 166 |
+
startline = line
|
| 167 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 168 |
+
while True:
|
| 169 |
+
m = search_reverse(prog, chars[:-1], col)
|
| 170 |
+
if m:
|
| 171 |
+
if ok or m.start() < col:
|
| 172 |
+
return line, m
|
| 173 |
+
line = line - 1
|
| 174 |
+
if wrapped and line < startline:
|
| 175 |
+
break
|
| 176 |
+
ok = 1
|
| 177 |
+
if line <= 0:
|
| 178 |
+
if not wrap:
|
| 179 |
+
break
|
| 180 |
+
wrapped = 1
|
| 181 |
+
wrap = 0
|
| 182 |
+
pos = text.index("end-1c")
|
| 183 |
+
line, col = map(int, pos.split("."))
|
| 184 |
+
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
| 185 |
+
col = len(chars) - 1
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def search_reverse(prog, chars, col):
|
| 190 |
+
'''Search backwards and return an re match object or None.
|
| 191 |
+
|
| 192 |
+
This is done by searching forwards until there is no match.
|
| 193 |
+
Prog: compiled re object with a search method returning a match.
|
| 194 |
+
Chars: line of text, without \\n.
|
| 195 |
+
Col: stop index for the search; the limit for match.end().
|
| 196 |
+
'''
|
| 197 |
+
m = prog.search(chars)
|
| 198 |
+
if not m:
|
| 199 |
+
return None
|
| 200 |
+
found = None
|
| 201 |
+
i, j = m.span() # m.start(), m.end() == match slice indexes
|
| 202 |
+
while i < col and j <= col:
|
| 203 |
+
found = m
|
| 204 |
+
if i == j:
|
| 205 |
+
j = j+1
|
| 206 |
+
m = prog.search(chars, j)
|
| 207 |
+
if not m:
|
| 208 |
+
break
|
| 209 |
+
i, j = m.span()
|
| 210 |
+
return found
|
| 211 |
+
|
| 212 |
+
def get_selection(text):
|
| 213 |
+
'''Return tuple of 'line.col' indexes from selection or insert mark.
|
| 214 |
+
'''
|
| 215 |
+
try:
|
| 216 |
+
first = text.index("sel.first")
|
| 217 |
+
last = text.index("sel.last")
|
| 218 |
+
except TclError:
|
| 219 |
+
first = last = None
|
| 220 |
+
if not first:
|
| 221 |
+
first = text.index("insert")
|
| 222 |
+
if not last:
|
| 223 |
+
last = first
|
| 224 |
+
return first, last
|
| 225 |
+
|
| 226 |
+
def get_line_col(index):
|
| 227 |
+
'''Return (line, col) tuple of ints from 'line.col' string.'''
|
| 228 |
+
line, col = map(int, index.split(".")) # Fails on invalid index
|
| 229 |
+
return line, col
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
if __name__ == "__main__":
|
| 233 |
+
from unittest import main
|
| 234 |
+
main('idlelib.idle_test.test_searchengine', verbosity=2)
|
evalkit_tf446/lib/python3.10/idlelib/squeezer.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""An IDLE extension to avoid having very long texts printed in the shell.
|
| 2 |
+
|
| 3 |
+
A common problem in IDLE's interactive shell is printing of large amounts of
|
| 4 |
+
text into the shell. This makes looking at the previous history difficult.
|
| 5 |
+
Worse, this can cause IDLE to become very slow, even to the point of being
|
| 6 |
+
completely unusable.
|
| 7 |
+
|
| 8 |
+
This extension will automatically replace long texts with a small button.
|
| 9 |
+
Double-clicking this button will remove it and insert the original text instead.
|
| 10 |
+
Middle-clicking will copy the text to the clipboard. Right-clicking will open
|
| 11 |
+
the text in a separate viewing window.
|
| 12 |
+
|
| 13 |
+
Additionally, any output can be manually "squeezed" by the user. This includes
|
| 14 |
+
output written to the standard error stream ("stderr"), such as exception
|
| 15 |
+
messages and their tracebacks.
|
| 16 |
+
"""
|
| 17 |
+
import re
|
| 18 |
+
|
| 19 |
+
import tkinter as tk
|
| 20 |
+
from tkinter import messagebox
|
| 21 |
+
|
| 22 |
+
from idlelib.config import idleConf
|
| 23 |
+
from idlelib.textview import view_text
|
| 24 |
+
from idlelib.tooltip import Hovertip
|
| 25 |
+
from idlelib import macosx
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def count_lines_with_wrapping(s, linewidth=80):
|
| 29 |
+
"""Count the number of lines in a given string.
|
| 30 |
+
|
| 31 |
+
Lines are counted as if the string was wrapped so that lines are never over
|
| 32 |
+
linewidth characters long.
|
| 33 |
+
|
| 34 |
+
Tabs are considered tabwidth characters long.
|
| 35 |
+
"""
|
| 36 |
+
tabwidth = 8 # Currently always true in Shell.
|
| 37 |
+
pos = 0
|
| 38 |
+
linecount = 1
|
| 39 |
+
current_column = 0
|
| 40 |
+
|
| 41 |
+
for m in re.finditer(r"[\t\n]", s):
|
| 42 |
+
# Process the normal chars up to tab or newline.
|
| 43 |
+
numchars = m.start() - pos
|
| 44 |
+
pos += numchars
|
| 45 |
+
current_column += numchars
|
| 46 |
+
|
| 47 |
+
# Deal with tab or newline.
|
| 48 |
+
if s[pos] == '\n':
|
| 49 |
+
# Avoid the `current_column == 0` edge-case, and while we're
|
| 50 |
+
# at it, don't bother adding 0.
|
| 51 |
+
if current_column > linewidth:
|
| 52 |
+
# If the current column was exactly linewidth, divmod
|
| 53 |
+
# would give (1,0), even though a new line hadn't yet
|
| 54 |
+
# been started. The same is true if length is any exact
|
| 55 |
+
# multiple of linewidth. Therefore, subtract 1 before
|
| 56 |
+
# dividing a non-empty line.
|
| 57 |
+
linecount += (current_column - 1) // linewidth
|
| 58 |
+
linecount += 1
|
| 59 |
+
current_column = 0
|
| 60 |
+
else:
|
| 61 |
+
assert s[pos] == '\t'
|
| 62 |
+
current_column += tabwidth - (current_column % tabwidth)
|
| 63 |
+
|
| 64 |
+
# If a tab passes the end of the line, consider the entire
|
| 65 |
+
# tab as being on the next line.
|
| 66 |
+
if current_column > linewidth:
|
| 67 |
+
linecount += 1
|
| 68 |
+
current_column = tabwidth
|
| 69 |
+
|
| 70 |
+
pos += 1 # After the tab or newline.
|
| 71 |
+
|
| 72 |
+
# Process remaining chars (no more tabs or newlines).
|
| 73 |
+
current_column += len(s) - pos
|
| 74 |
+
# Avoid divmod(-1, linewidth).
|
| 75 |
+
if current_column > 0:
|
| 76 |
+
linecount += (current_column - 1) // linewidth
|
| 77 |
+
else:
|
| 78 |
+
# Text ended with newline; don't count an extra line after it.
|
| 79 |
+
linecount -= 1
|
| 80 |
+
|
| 81 |
+
return linecount
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class ExpandingButton(tk.Button):
|
| 85 |
+
"""Class for the "squeezed" text buttons used by Squeezer
|
| 86 |
+
|
| 87 |
+
These buttons are displayed inside a Tk Text widget in place of text. A
|
| 88 |
+
user can then use the button to replace it with the original text, copy
|
| 89 |
+
the original text to the clipboard or view the original text in a separate
|
| 90 |
+
window.
|
| 91 |
+
|
| 92 |
+
Each button is tied to a Squeezer instance, and it knows to update the
|
| 93 |
+
Squeezer instance when it is expanded (and therefore removed).
|
| 94 |
+
"""
|
| 95 |
+
def __init__(self, s, tags, numoflines, squeezer):
|
| 96 |
+
self.s = s
|
| 97 |
+
self.tags = tags
|
| 98 |
+
self.numoflines = numoflines
|
| 99 |
+
self.squeezer = squeezer
|
| 100 |
+
self.editwin = editwin = squeezer.editwin
|
| 101 |
+
self.text = text = editwin.text
|
| 102 |
+
# The base Text widget is needed to change text before iomark.
|
| 103 |
+
self.base_text = editwin.per.bottom
|
| 104 |
+
|
| 105 |
+
line_plurality = "lines" if numoflines != 1 else "line"
|
| 106 |
+
button_text = f"Squeezed text ({numoflines} {line_plurality})."
|
| 107 |
+
tk.Button.__init__(self, text, text=button_text,
|
| 108 |
+
background="#FFFFC0", activebackground="#FFFFE0")
|
| 109 |
+
|
| 110 |
+
button_tooltip_text = (
|
| 111 |
+
"Double-click to expand, right-click for more options."
|
| 112 |
+
)
|
| 113 |
+
Hovertip(self, button_tooltip_text, hover_delay=80)
|
| 114 |
+
|
| 115 |
+
self.bind("<Double-Button-1>", self.expand)
|
| 116 |
+
if macosx.isAquaTk():
|
| 117 |
+
# AquaTk defines <2> as the right button, not <3>.
|
| 118 |
+
self.bind("<Button-2>", self.context_menu_event)
|
| 119 |
+
else:
|
| 120 |
+
self.bind("<Button-3>", self.context_menu_event)
|
| 121 |
+
self.selection_handle( # X windows only.
|
| 122 |
+
lambda offset, length: s[int(offset):int(offset) + int(length)])
|
| 123 |
+
|
| 124 |
+
self.is_dangerous = None
|
| 125 |
+
self.after_idle(self.set_is_dangerous)
|
| 126 |
+
|
| 127 |
+
def set_is_dangerous(self):
|
| 128 |
+
dangerous_line_len = 50 * self.text.winfo_width()
|
| 129 |
+
self.is_dangerous = (
|
| 130 |
+
self.numoflines > 1000 or
|
| 131 |
+
len(self.s) > 50000 or
|
| 132 |
+
any(
|
| 133 |
+
len(line_match.group(0)) >= dangerous_line_len
|
| 134 |
+
for line_match in re.finditer(r'[^\n]+', self.s)
|
| 135 |
+
)
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
def expand(self, event=None):
|
| 139 |
+
"""expand event handler
|
| 140 |
+
|
| 141 |
+
This inserts the original text in place of the button in the Text
|
| 142 |
+
widget, removes the button and updates the Squeezer instance.
|
| 143 |
+
|
| 144 |
+
If the original text is dangerously long, i.e. expanding it could
|
| 145 |
+
cause a performance degradation, ask the user for confirmation.
|
| 146 |
+
"""
|
| 147 |
+
if self.is_dangerous is None:
|
| 148 |
+
self.set_is_dangerous()
|
| 149 |
+
if self.is_dangerous:
|
| 150 |
+
confirm = messagebox.askokcancel(
|
| 151 |
+
title="Expand huge output?",
|
| 152 |
+
message="\n\n".join([
|
| 153 |
+
"The squeezed output is very long: %d lines, %d chars.",
|
| 154 |
+
"Expanding it could make IDLE slow or unresponsive.",
|
| 155 |
+
"It is recommended to view or copy the output instead.",
|
| 156 |
+
"Really expand?"
|
| 157 |
+
]) % (self.numoflines, len(self.s)),
|
| 158 |
+
default=messagebox.CANCEL,
|
| 159 |
+
parent=self.text)
|
| 160 |
+
if not confirm:
|
| 161 |
+
return "break"
|
| 162 |
+
|
| 163 |
+
index = self.text.index(self)
|
| 164 |
+
self.base_text.insert(index, self.s, self.tags)
|
| 165 |
+
self.base_text.delete(self)
|
| 166 |
+
self.editwin.on_squeezed_expand(index, self.s, self.tags)
|
| 167 |
+
self.squeezer.expandingbuttons.remove(self)
|
| 168 |
+
|
| 169 |
+
def copy(self, event=None):
|
| 170 |
+
"""copy event handler
|
| 171 |
+
|
| 172 |
+
Copy the original text to the clipboard.
|
| 173 |
+
"""
|
| 174 |
+
self.clipboard_clear()
|
| 175 |
+
self.clipboard_append(self.s)
|
| 176 |
+
|
| 177 |
+
def view(self, event=None):
|
| 178 |
+
"""view event handler
|
| 179 |
+
|
| 180 |
+
View the original text in a separate text viewer window.
|
| 181 |
+
"""
|
| 182 |
+
view_text(self.text, "Squeezed Output Viewer", self.s,
|
| 183 |
+
modal=False, wrap='none')
|
| 184 |
+
|
| 185 |
+
rmenu_specs = (
|
| 186 |
+
# Item structure: (label, method_name).
|
| 187 |
+
('copy', 'copy'),
|
| 188 |
+
('view', 'view'),
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
def context_menu_event(self, event):
|
| 192 |
+
self.text.mark_set("insert", "@%d,%d" % (event.x, event.y))
|
| 193 |
+
rmenu = tk.Menu(self.text, tearoff=0)
|
| 194 |
+
for label, method_name in self.rmenu_specs:
|
| 195 |
+
rmenu.add_command(label=label, command=getattr(self, method_name))
|
| 196 |
+
rmenu.tk_popup(event.x_root, event.y_root)
|
| 197 |
+
return "break"
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class Squeezer:
|
| 201 |
+
"""Replace long outputs in the shell with a simple button.
|
| 202 |
+
|
| 203 |
+
This avoids IDLE's shell slowing down considerably, and even becoming
|
| 204 |
+
completely unresponsive, when very long outputs are written.
|
| 205 |
+
"""
|
| 206 |
+
@classmethod
|
| 207 |
+
def reload(cls):
|
| 208 |
+
"""Load class variables from config."""
|
| 209 |
+
cls.auto_squeeze_min_lines = idleConf.GetOption(
|
| 210 |
+
"main", "PyShell", "auto-squeeze-min-lines",
|
| 211 |
+
type="int", default=50,
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
def __init__(self, editwin):
|
| 215 |
+
"""Initialize settings for Squeezer.
|
| 216 |
+
|
| 217 |
+
editwin is the shell's Editor window.
|
| 218 |
+
self.text is the editor window text widget.
|
| 219 |
+
self.base_test is the actual editor window Tk text widget, rather than
|
| 220 |
+
EditorWindow's wrapper.
|
| 221 |
+
self.expandingbuttons is the list of all buttons representing
|
| 222 |
+
"squeezed" output.
|
| 223 |
+
"""
|
| 224 |
+
self.editwin = editwin
|
| 225 |
+
self.text = text = editwin.text
|
| 226 |
+
|
| 227 |
+
# Get the base Text widget of the PyShell object, used to change
|
| 228 |
+
# text before the iomark. PyShell deliberately disables changing
|
| 229 |
+
# text before the iomark via its 'text' attribute, which is
|
| 230 |
+
# actually a wrapper for the actual Text widget. Squeezer,
|
| 231 |
+
# however, needs to make such changes.
|
| 232 |
+
self.base_text = editwin.per.bottom
|
| 233 |
+
|
| 234 |
+
# Twice the text widget's border width and internal padding;
|
| 235 |
+
# pre-calculated here for the get_line_width() method.
|
| 236 |
+
self.window_width_delta = 2 * (
|
| 237 |
+
int(text.cget('border')) +
|
| 238 |
+
int(text.cget('padx'))
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
self.expandingbuttons = []
|
| 242 |
+
|
| 243 |
+
# Replace the PyShell instance's write method with a wrapper,
|
| 244 |
+
# which inserts an ExpandingButton instead of a long text.
|
| 245 |
+
def mywrite(s, tags=(), write=editwin.write):
|
| 246 |
+
# Only auto-squeeze text which has just the "stdout" tag.
|
| 247 |
+
if tags != "stdout":
|
| 248 |
+
return write(s, tags)
|
| 249 |
+
|
| 250 |
+
# Only auto-squeeze text with at least the minimum
|
| 251 |
+
# configured number of lines.
|
| 252 |
+
auto_squeeze_min_lines = self.auto_squeeze_min_lines
|
| 253 |
+
# First, a very quick check to skip very short texts.
|
| 254 |
+
if len(s) < auto_squeeze_min_lines:
|
| 255 |
+
return write(s, tags)
|
| 256 |
+
# Now the full line-count check.
|
| 257 |
+
numoflines = self.count_lines(s)
|
| 258 |
+
if numoflines < auto_squeeze_min_lines:
|
| 259 |
+
return write(s, tags)
|
| 260 |
+
|
| 261 |
+
# Create an ExpandingButton instance.
|
| 262 |
+
expandingbutton = ExpandingButton(s, tags, numoflines, self)
|
| 263 |
+
|
| 264 |
+
# Insert the ExpandingButton into the Text widget.
|
| 265 |
+
text.mark_gravity("iomark", tk.RIGHT)
|
| 266 |
+
text.window_create("iomark", window=expandingbutton,
|
| 267 |
+
padx=3, pady=5)
|
| 268 |
+
text.see("iomark")
|
| 269 |
+
text.update()
|
| 270 |
+
text.mark_gravity("iomark", tk.LEFT)
|
| 271 |
+
|
| 272 |
+
# Add the ExpandingButton to the Squeezer's list.
|
| 273 |
+
self.expandingbuttons.append(expandingbutton)
|
| 274 |
+
|
| 275 |
+
editwin.write = mywrite
|
| 276 |
+
|
| 277 |
+
def count_lines(self, s):
|
| 278 |
+
"""Count the number of lines in a given text.
|
| 279 |
+
|
| 280 |
+
Before calculation, the tab width and line length of the text are
|
| 281 |
+
fetched, so that up-to-date values are used.
|
| 282 |
+
|
| 283 |
+
Lines are counted as if the string was wrapped so that lines are never
|
| 284 |
+
over linewidth characters long.
|
| 285 |
+
|
| 286 |
+
Tabs are considered tabwidth characters long.
|
| 287 |
+
"""
|
| 288 |
+
return count_lines_with_wrapping(s, self.editwin.width)
|
| 289 |
+
|
| 290 |
+
def squeeze_current_text(self):
|
| 291 |
+
"""Squeeze the text block where the insertion cursor is.
|
| 292 |
+
|
| 293 |
+
If the cursor is not in a squeezable block of text, give the
|
| 294 |
+
user a small warning and do nothing.
|
| 295 |
+
"""
|
| 296 |
+
# Set tag_name to the first valid tag found on the "insert" cursor.
|
| 297 |
+
tag_names = self.text.tag_names(tk.INSERT)
|
| 298 |
+
for tag_name in ("stdout", "stderr"):
|
| 299 |
+
if tag_name in tag_names:
|
| 300 |
+
break
|
| 301 |
+
else:
|
| 302 |
+
# The insert cursor doesn't have a "stdout" or "stderr" tag.
|
| 303 |
+
self.text.bell()
|
| 304 |
+
return "break"
|
| 305 |
+
|
| 306 |
+
# Find the range to squeeze.
|
| 307 |
+
start, end = self.text.tag_prevrange(tag_name, tk.INSERT + "+1c")
|
| 308 |
+
s = self.text.get(start, end)
|
| 309 |
+
|
| 310 |
+
# If the last char is a newline, remove it from the range.
|
| 311 |
+
if len(s) > 0 and s[-1] == '\n':
|
| 312 |
+
end = self.text.index("%s-1c" % end)
|
| 313 |
+
s = s[:-1]
|
| 314 |
+
|
| 315 |
+
# Delete the text.
|
| 316 |
+
self.base_text.delete(start, end)
|
| 317 |
+
|
| 318 |
+
# Prepare an ExpandingButton.
|
| 319 |
+
numoflines = self.count_lines(s)
|
| 320 |
+
expandingbutton = ExpandingButton(s, tag_name, numoflines, self)
|
| 321 |
+
|
| 322 |
+
# insert the ExpandingButton to the Text
|
| 323 |
+
self.text.window_create(start, window=expandingbutton,
|
| 324 |
+
padx=3, pady=5)
|
| 325 |
+
|
| 326 |
+
# Insert the ExpandingButton to the list of ExpandingButtons,
|
| 327 |
+
# while keeping the list ordered according to the position of
|
| 328 |
+
# the buttons in the Text widget.
|
| 329 |
+
i = len(self.expandingbuttons)
|
| 330 |
+
while i > 0 and self.text.compare(self.expandingbuttons[i-1],
|
| 331 |
+
">", expandingbutton):
|
| 332 |
+
i -= 1
|
| 333 |
+
self.expandingbuttons.insert(i, expandingbutton)
|
| 334 |
+
|
| 335 |
+
return "break"
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
Squeezer.reload()
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
if __name__ == "__main__":
|
| 342 |
+
from unittest import main
|
| 343 |
+
main('idlelib.idle_test.test_squeezer', verbosity=2, exit=False)
|
| 344 |
+
|
| 345 |
+
# Add htest.
|
evalkit_tf446/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)
|
evalkit_tf446/lib/python3.10/idlelib/textview.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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DLE
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
from tkinter import Toplevel, Text, TclError,\
|
| 5 |
+
HORIZONTAL, VERTICAL, NS, EW, NSEW, NONE, WORD, SUNKEN
|
| 6 |
+
from tkinter.ttk import Frame, Scrollbar, Button
|
| 7 |
+
from tkinter.messagebox import showerror
|
| 8 |
+
|
| 9 |
+
from idlelib.colorizer import color_config
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class AutoHideScrollbar(Scrollbar):
|
| 13 |
+
"""A scrollbar that is automatically hidden when not needed.
|
| 14 |
+
|
| 15 |
+
Only the grid geometry manager is supported.
|
| 16 |
+
"""
|
| 17 |
+
def set(self, lo, hi):
|
| 18 |
+
if float(lo) > 0.0 or float(hi) < 1.0:
|
| 19 |
+
self.grid()
|
| 20 |
+
else:
|
| 21 |
+
self.grid_remove()
|
| 22 |
+
super().set(lo, hi)
|
| 23 |
+
|
| 24 |
+
def pack(self, **kwargs):
|
| 25 |
+
raise TclError(f'{self.__class__.__name__} does not support "pack"')
|
| 26 |
+
|
| 27 |
+
def place(self, **kwargs):
|
| 28 |
+
raise TclError(f'{self.__class__.__name__} does not support "place"')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ScrollableTextFrame(Frame):
|
| 32 |
+
"""Display text with scrollbar(s)."""
|
| 33 |
+
|
| 34 |
+
def __init__(self, master, wrap=NONE, **kwargs):
|
| 35 |
+
"""Create a frame for Textview.
|
| 36 |
+
|
| 37 |
+
master - master widget for this frame
|
| 38 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 39 |
+
|
| 40 |
+
All parameters except for 'wrap' are passed to Frame.__init__().
|
| 41 |
+
|
| 42 |
+
The Text widget is accessible via the 'text' attribute.
|
| 43 |
+
|
| 44 |
+
Note: Changing the wrapping mode of the text widget after
|
| 45 |
+
instantiation is not supported.
|
| 46 |
+
"""
|
| 47 |
+
super().__init__(master, **kwargs)
|
| 48 |
+
|
| 49 |
+
text = self.text = Text(self, wrap=wrap)
|
| 50 |
+
text.grid(row=0, column=0, sticky=NSEW)
|
| 51 |
+
self.grid_rowconfigure(0, weight=1)
|
| 52 |
+
self.grid_columnconfigure(0, weight=1)
|
| 53 |
+
|
| 54 |
+
# vertical scrollbar
|
| 55 |
+
self.yscroll = AutoHideScrollbar(self, orient=VERTICAL,
|
| 56 |
+
takefocus=False,
|
| 57 |
+
command=text.yview)
|
| 58 |
+
self.yscroll.grid(row=0, column=1, sticky=NS)
|
| 59 |
+
text['yscrollcommand'] = self.yscroll.set
|
| 60 |
+
|
| 61 |
+
# horizontal scrollbar - only when wrap is set to NONE
|
| 62 |
+
if wrap == NONE:
|
| 63 |
+
self.xscroll = AutoHideScrollbar(self, orient=HORIZONTAL,
|
| 64 |
+
takefocus=False,
|
| 65 |
+
command=text.xview)
|
| 66 |
+
self.xscroll.grid(row=1, column=0, sticky=EW)
|
| 67 |
+
text['xscrollcommand'] = self.xscroll.set
|
| 68 |
+
else:
|
| 69 |
+
self.xscroll = None
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class ViewFrame(Frame):
|
| 73 |
+
"Display TextFrame and Close button."
|
| 74 |
+
def __init__(self, parent, contents, wrap='word'):
|
| 75 |
+
"""Create a frame for viewing text with a "Close" button.
|
| 76 |
+
|
| 77 |
+
parent - parent widget for this frame
|
| 78 |
+
contents - text to display
|
| 79 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 80 |
+
|
| 81 |
+
The Text widget is accessible via the 'text' attribute.
|
| 82 |
+
"""
|
| 83 |
+
super().__init__(parent)
|
| 84 |
+
self.parent = parent
|
| 85 |
+
self.bind('<Return>', self.ok)
|
| 86 |
+
self.bind('<Escape>', self.ok)
|
| 87 |
+
self.textframe = ScrollableTextFrame(self, relief=SUNKEN, height=700)
|
| 88 |
+
|
| 89 |
+
text = self.text = self.textframe.text
|
| 90 |
+
text.insert('1.0', contents)
|
| 91 |
+
text.configure(wrap=wrap, highlightthickness=0, state='disabled')
|
| 92 |
+
color_config(text)
|
| 93 |
+
text.focus_set()
|
| 94 |
+
|
| 95 |
+
self.button_ok = button_ok = Button(
|
| 96 |
+
self, text='Close', command=self.ok, takefocus=False)
|
| 97 |
+
self.textframe.pack(side='top', expand=True, fill='both')
|
| 98 |
+
button_ok.pack(side='bottom')
|
| 99 |
+
|
| 100 |
+
def ok(self, event=None):
|
| 101 |
+
"""Dismiss text viewer dialog."""
|
| 102 |
+
self.parent.destroy()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class ViewWindow(Toplevel):
|
| 106 |
+
"A simple text viewer dialog for IDLE."
|
| 107 |
+
|
| 108 |
+
def __init__(self, parent, title, contents, modal=True, wrap=WORD,
|
| 109 |
+
*, _htest=False, _utest=False):
|
| 110 |
+
"""Show the given text in a scrollable window with a 'close' button.
|
| 111 |
+
|
| 112 |
+
If modal is left True, users cannot interact with other windows
|
| 113 |
+
until the textview window is closed.
|
| 114 |
+
|
| 115 |
+
parent - parent of this dialog
|
| 116 |
+
title - string which is title of popup dialog
|
| 117 |
+
contents - text to display in dialog
|
| 118 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 119 |
+
_htest - bool; change box location when running htest.
|
| 120 |
+
_utest - bool; don't wait_window when running unittest.
|
| 121 |
+
"""
|
| 122 |
+
super().__init__(parent)
|
| 123 |
+
self['borderwidth'] = 5
|
| 124 |
+
# Place dialog below parent if running htest.
|
| 125 |
+
x = parent.winfo_rootx() + 10
|
| 126 |
+
y = parent.winfo_rooty() + (10 if not _htest else 100)
|
| 127 |
+
self.geometry(f'=750x500+{x}+{y}')
|
| 128 |
+
|
| 129 |
+
self.title(title)
|
| 130 |
+
self.viewframe = ViewFrame(self, contents, wrap=wrap)
|
| 131 |
+
self.protocol("WM_DELETE_WINDOW", self.ok)
|
| 132 |
+
self.button_ok = button_ok = Button(self, text='Close',
|
| 133 |
+
command=self.ok, takefocus=False)
|
| 134 |
+
self.viewframe.pack(side='top', expand=True, fill='both')
|
| 135 |
+
|
| 136 |
+
self.is_modal = modal
|
| 137 |
+
if self.is_modal:
|
| 138 |
+
self.transient(parent)
|
| 139 |
+
self.grab_set()
|
| 140 |
+
if not _utest:
|
| 141 |
+
self.wait_window()
|
| 142 |
+
|
| 143 |
+
def ok(self, event=None):
|
| 144 |
+
"""Dismiss text viewer dialog."""
|
| 145 |
+
if self.is_modal:
|
| 146 |
+
self.grab_release()
|
| 147 |
+
self.destroy()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def view_text(parent, title, contents, modal=True, wrap='word', _utest=False):
|
| 151 |
+
"""Create text viewer for given text.
|
| 152 |
+
|
| 153 |
+
parent - parent of this dialog
|
| 154 |
+
title - string which is the title of popup dialog
|
| 155 |
+
contents - text to display in this dialog
|
| 156 |
+
wrap - type of text wrapping to use ('word', 'char' or 'none')
|
| 157 |
+
modal - controls if users can interact with other windows while this
|
| 158 |
+
dialog is displayed
|
| 159 |
+
_utest - bool; controls wait_window on unittest
|
| 160 |
+
"""
|
| 161 |
+
return ViewWindow(parent, title, contents, modal, wrap=wrap, _utest=_utest)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def view_file(parent, title, filename, encoding, modal=True, wrap='word',
|
| 165 |
+
_utest=False):
|
| 166 |
+
"""Create text viewer for text in filename.
|
| 167 |
+
|
| 168 |
+
Return error message if file cannot be read. Otherwise calls view_text
|
| 169 |
+
with contents of the file.
|
| 170 |
+
"""
|
| 171 |
+
try:
|
| 172 |
+
with open(filename, 'r', encoding=encoding) as file:
|
| 173 |
+
contents = file.read()
|
| 174 |
+
except OSError:
|
| 175 |
+
showerror(title='File Load Error',
|
| 176 |
+
message=f'Unable to load file {filename!r} .',
|
| 177 |
+
parent=parent)
|
| 178 |
+
except UnicodeDecodeError as err:
|
| 179 |
+
showerror(title='Unicode Decode Error',
|
| 180 |
+
message=str(err),
|
| 181 |
+
parent=parent)
|
| 182 |
+
else:
|
| 183 |
+
return view_text(parent, title, contents, modal, wrap=wrap,
|
| 184 |
+
_utest=_utest)
|
| 185 |
+
return None
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
if __name__ == '__main__':
|
| 189 |
+
from unittest import main
|
| 190 |
+
main('idlelib.idle_test.test_textview', verbosity=2, exit=False)
|
| 191 |
+
|
| 192 |
+
from idlelib.idle_test.htest import run
|
| 193 |
+
run(ViewWindow)
|
evalkit_tf446/lib/python3.10/idlelib/tooltip.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tools for displaying tool-tips.
|
| 2 |
+
|
| 3 |
+
This includes:
|
| 4 |
+
* an abstract base-class for different kinds of tooltips
|
| 5 |
+
* a simple text-only Tooltip class
|
| 6 |
+
"""
|
| 7 |
+
from tkinter import *
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TooltipBase:
|
| 11 |
+
"""abstract base class for tooltips"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, anchor_widget):
|
| 14 |
+
"""Create a tooltip.
|
| 15 |
+
|
| 16 |
+
anchor_widget: the widget next to which the tooltip will be shown
|
| 17 |
+
|
| 18 |
+
Note that a widget will only be shown when showtip() is called.
|
| 19 |
+
"""
|
| 20 |
+
self.anchor_widget = anchor_widget
|
| 21 |
+
self.tipwindow = None
|
| 22 |
+
|
| 23 |
+
def __del__(self):
|
| 24 |
+
self.hidetip()
|
| 25 |
+
|
| 26 |
+
def showtip(self):
|
| 27 |
+
"""display the tooltip"""
|
| 28 |
+
if self.tipwindow:
|
| 29 |
+
return
|
| 30 |
+
self.tipwindow = tw = Toplevel(self.anchor_widget)
|
| 31 |
+
# show no border on the top level window
|
| 32 |
+
tw.wm_overrideredirect(1)
|
| 33 |
+
try:
|
| 34 |
+
# This command is only needed and available on Tk >= 8.4.0 for OSX.
|
| 35 |
+
# Without it, call tips intrude on the typing process by grabbing
|
| 36 |
+
# the focus.
|
| 37 |
+
tw.tk.call("::tk::unsupported::MacWindowStyle", "style", tw._w,
|
| 38 |
+
"help", "noActivates")
|
| 39 |
+
except TclError:
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
self.position_window()
|
| 43 |
+
self.showcontents()
|
| 44 |
+
self.tipwindow.update_idletasks() # Needed on MacOS -- see #34275.
|
| 45 |
+
self.tipwindow.lift() # work around bug in Tk 8.5.18+ (issue #24570)
|
| 46 |
+
|
| 47 |
+
def position_window(self):
|
| 48 |
+
"""(re)-set the tooltip's screen position"""
|
| 49 |
+
x, y = self.get_position()
|
| 50 |
+
root_x = self.anchor_widget.winfo_rootx() + x
|
| 51 |
+
root_y = self.anchor_widget.winfo_rooty() + y
|
| 52 |
+
self.tipwindow.wm_geometry("+%d+%d" % (root_x, root_y))
|
| 53 |
+
|
| 54 |
+
def get_position(self):
|
| 55 |
+
"""choose a screen position for the tooltip"""
|
| 56 |
+
# The tip window must be completely outside the anchor widget;
|
| 57 |
+
# otherwise when the mouse enters the tip window we get
|
| 58 |
+
# a leave event and it disappears, and then we get an enter
|
| 59 |
+
# event and it reappears, and so on forever :-(
|
| 60 |
+
#
|
| 61 |
+
# Note: This is a simplistic implementation; sub-classes will likely
|
| 62 |
+
# want to override this.
|
| 63 |
+
return 20, self.anchor_widget.winfo_height() + 1
|
| 64 |
+
|
| 65 |
+
def showcontents(self):
|
| 66 |
+
"""content display hook for sub-classes"""
|
| 67 |
+
# See ToolTip for an example
|
| 68 |
+
raise NotImplementedError
|
| 69 |
+
|
| 70 |
+
def hidetip(self):
|
| 71 |
+
"""hide the tooltip"""
|
| 72 |
+
# Note: This is called by __del__, so careful when overriding/extending
|
| 73 |
+
tw = self.tipwindow
|
| 74 |
+
self.tipwindow = None
|
| 75 |
+
if tw:
|
| 76 |
+
try:
|
| 77 |
+
tw.destroy()
|
| 78 |
+
except TclError: # pragma: no cover
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class OnHoverTooltipBase(TooltipBase):
|
| 83 |
+
"""abstract base class for tooltips, with delayed on-hover display"""
|
| 84 |
+
|
| 85 |
+
def __init__(self, anchor_widget, hover_delay=1000):
|
| 86 |
+
"""Create a tooltip with a mouse hover delay.
|
| 87 |
+
|
| 88 |
+
anchor_widget: the widget next to which the tooltip will be shown
|
| 89 |
+
hover_delay: time to delay before showing the tooltip, in milliseconds
|
| 90 |
+
|
| 91 |
+
Note that a widget will only be shown when showtip() is called,
|
| 92 |
+
e.g. after hovering over the anchor widget with the mouse for enough
|
| 93 |
+
time.
|
| 94 |
+
"""
|
| 95 |
+
super(OnHoverTooltipBase, self).__init__(anchor_widget)
|
| 96 |
+
self.hover_delay = hover_delay
|
| 97 |
+
|
| 98 |
+
self._after_id = None
|
| 99 |
+
self._id1 = self.anchor_widget.bind("<Enter>", self._show_event)
|
| 100 |
+
self._id2 = self.anchor_widget.bind("<Leave>", self._hide_event)
|
| 101 |
+
self._id3 = self.anchor_widget.bind("<Button>", self._hide_event)
|
| 102 |
+
|
| 103 |
+
def __del__(self):
|
| 104 |
+
try:
|
| 105 |
+
self.anchor_widget.unbind("<Enter>", self._id1)
|
| 106 |
+
self.anchor_widget.unbind("<Leave>", self._id2) # pragma: no cover
|
| 107 |
+
self.anchor_widget.unbind("<Button>", self._id3) # pragma: no cover
|
| 108 |
+
except TclError:
|
| 109 |
+
pass
|
| 110 |
+
super(OnHoverTooltipBase, self).__del__()
|
| 111 |
+
|
| 112 |
+
def _show_event(self, event=None):
|
| 113 |
+
"""event handler to display the tooltip"""
|
| 114 |
+
if self.hover_delay:
|
| 115 |
+
self.schedule()
|
| 116 |
+
else:
|
| 117 |
+
self.showtip()
|
| 118 |
+
|
| 119 |
+
def _hide_event(self, event=None):
|
| 120 |
+
"""event handler to hide the tooltip"""
|
| 121 |
+
self.hidetip()
|
| 122 |
+
|
| 123 |
+
def schedule(self):
|
| 124 |
+
"""schedule the future display of the tooltip"""
|
| 125 |
+
self.unschedule()
|
| 126 |
+
self._after_id = self.anchor_widget.after(self.hover_delay,
|
| 127 |
+
self.showtip)
|
| 128 |
+
|
| 129 |
+
def unschedule(self):
|
| 130 |
+
"""cancel the future display of the tooltip"""
|
| 131 |
+
after_id = self._after_id
|
| 132 |
+
self._after_id = None
|
| 133 |
+
if after_id:
|
| 134 |
+
self.anchor_widget.after_cancel(after_id)
|
| 135 |
+
|
| 136 |
+
def hidetip(self):
|
| 137 |
+
"""hide the tooltip"""
|
| 138 |
+
try:
|
| 139 |
+
self.unschedule()
|
| 140 |
+
except TclError: # pragma: no cover
|
| 141 |
+
pass
|
| 142 |
+
super(OnHoverTooltipBase, self).hidetip()
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class Hovertip(OnHoverTooltipBase):
|
| 146 |
+
"A tooltip that pops up when a mouse hovers over an anchor widget."
|
| 147 |
+
def __init__(self, anchor_widget, text, hover_delay=1000):
|
| 148 |
+
"""Create a text tooltip with a mouse hover delay.
|
| 149 |
+
|
| 150 |
+
anchor_widget: the widget next to which the tooltip will be shown
|
| 151 |
+
hover_delay: time to delay before showing the tooltip, in milliseconds
|
| 152 |
+
|
| 153 |
+
Note that a widget will only be shown when showtip() is called,
|
| 154 |
+
e.g. after hovering over the anchor widget with the mouse for enough
|
| 155 |
+
time.
|
| 156 |
+
"""
|
| 157 |
+
super(Hovertip, self).__init__(anchor_widget, hover_delay=hover_delay)
|
| 158 |
+
self.text = text
|
| 159 |
+
|
| 160 |
+
def showcontents(self):
|
| 161 |
+
label = Label(self.tipwindow, text=self.text, justify=LEFT,
|
| 162 |
+
background="#ffffe0", relief=SOLID, borderwidth=1)
|
| 163 |
+
label.pack()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _tooltip(parent): # htest #
|
| 167 |
+
top = Toplevel(parent)
|
| 168 |
+
top.title("Test tooltip")
|
| 169 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 170 |
+
top.geometry("+%d+%d" % (x, y + 150))
|
| 171 |
+
label = Label(top, text="Place your mouse over buttons")
|
| 172 |
+
label.pack()
|
| 173 |
+
button1 = Button(top, text="Button 1 -- 1/2 second hover delay")
|
| 174 |
+
button1.pack()
|
| 175 |
+
Hovertip(button1, "This is tooltip text for button1.", hover_delay=500)
|
| 176 |
+
button2 = Button(top, text="Button 2 -- no hover delay")
|
| 177 |
+
button2.pack()
|
| 178 |
+
Hovertip(button2, "This is tooltip\ntext for button2.", hover_delay=None)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
from unittest import main
|
| 183 |
+
main('idlelib.idle_test.test_tooltip', verbosity=2, exit=False)
|
| 184 |
+
|
| 185 |
+
from idlelib.idle_test.htest import run
|
| 186 |
+
run(_tooltip)
|
evalkit_tf446/lib/python3.10/idlelib/tree.py
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# XXX TO DO:
|
| 2 |
+
# - popup menu
|
| 3 |
+
# - support partial or total redisplay
|
| 4 |
+
# - key bindings (instead of quick-n-dirty bindings on Canvas):
|
| 5 |
+
# - up/down arrow keys to move focus around
|
| 6 |
+
# - ditto for page up/down, home/end
|
| 7 |
+
# - left/right arrows to expand/collapse & move out/in
|
| 8 |
+
# - more doc strings
|
| 9 |
+
# - add icons for "file", "module", "class", "method"; better "python" icon
|
| 10 |
+
# - callback for selection???
|
| 11 |
+
# - multiple-item selection
|
| 12 |
+
# - tooltips
|
| 13 |
+
# - redo geometry without magic numbers
|
| 14 |
+
# - keep track of object ids to allow more careful cleaning
|
| 15 |
+
# - optimize tree redraw after expand of subnode
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
|
| 19 |
+
from tkinter import *
|
| 20 |
+
from tkinter.ttk import Frame, Scrollbar
|
| 21 |
+
|
| 22 |
+
from idlelib.config import idleConf
|
| 23 |
+
from idlelib import zoomheight
|
| 24 |
+
|
| 25 |
+
ICONDIR = "Icons"
|
| 26 |
+
|
| 27 |
+
# Look for Icons subdirectory in the same directory as this module
|
| 28 |
+
try:
|
| 29 |
+
_icondir = os.path.join(os.path.dirname(__file__), ICONDIR)
|
| 30 |
+
except NameError:
|
| 31 |
+
_icondir = ICONDIR
|
| 32 |
+
if os.path.isdir(_icondir):
|
| 33 |
+
ICONDIR = _icondir
|
| 34 |
+
elif not os.path.isdir(ICONDIR):
|
| 35 |
+
raise RuntimeError("can't find icon directory (%r)" % (ICONDIR,))
|
| 36 |
+
|
| 37 |
+
def listicons(icondir=ICONDIR):
|
| 38 |
+
"""Utility to display the available icons."""
|
| 39 |
+
root = Tk()
|
| 40 |
+
import glob
|
| 41 |
+
list = glob.glob(os.path.join(glob.escape(icondir), "*.gif"))
|
| 42 |
+
list.sort()
|
| 43 |
+
images = []
|
| 44 |
+
row = column = 0
|
| 45 |
+
for file in list:
|
| 46 |
+
name = os.path.splitext(os.path.basename(file))[0]
|
| 47 |
+
image = PhotoImage(file=file, master=root)
|
| 48 |
+
images.append(image)
|
| 49 |
+
label = Label(root, image=image, bd=1, relief="raised")
|
| 50 |
+
label.grid(row=row, column=column)
|
| 51 |
+
label = Label(root, text=name)
|
| 52 |
+
label.grid(row=row+1, column=column)
|
| 53 |
+
column = column + 1
|
| 54 |
+
if column >= 10:
|
| 55 |
+
row = row+2
|
| 56 |
+
column = 0
|
| 57 |
+
root.images = images
|
| 58 |
+
|
| 59 |
+
def wheel_event(event, widget=None):
|
| 60 |
+
"""Handle scrollwheel event.
|
| 61 |
+
|
| 62 |
+
For wheel up, event.delta = 120*n on Windows, -1*n on darwin,
|
| 63 |
+
where n can be > 1 if one scrolls fast. Flicking the wheel
|
| 64 |
+
generates up to maybe 20 events with n up to 10 or more 1.
|
| 65 |
+
Macs use wheel down (delta = 1*n) to scroll up, so positive
|
| 66 |
+
delta means to scroll up on both systems.
|
| 67 |
+
|
| 68 |
+
X-11 sends Control-Button-4,5 events instead.
|
| 69 |
+
|
| 70 |
+
The widget parameter is needed so browser label bindings can pass
|
| 71 |
+
the underlying canvas.
|
| 72 |
+
|
| 73 |
+
This function depends on widget.yview to not be overridden by
|
| 74 |
+
a subclass.
|
| 75 |
+
"""
|
| 76 |
+
up = {EventType.MouseWheel: event.delta > 0,
|
| 77 |
+
EventType.ButtonPress: event.num == 4}
|
| 78 |
+
lines = -5 if up[event.type] else 5
|
| 79 |
+
widget = event.widget if widget is None else widget
|
| 80 |
+
widget.yview(SCROLL, lines, 'units')
|
| 81 |
+
return 'break'
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class TreeNode:
|
| 85 |
+
|
| 86 |
+
def __init__(self, canvas, parent, item):
|
| 87 |
+
self.canvas = canvas
|
| 88 |
+
self.parent = parent
|
| 89 |
+
self.item = item
|
| 90 |
+
self.state = 'collapsed'
|
| 91 |
+
self.selected = False
|
| 92 |
+
self.children = []
|
| 93 |
+
self.x = self.y = None
|
| 94 |
+
self.iconimages = {} # cache of PhotoImage instances for icons
|
| 95 |
+
|
| 96 |
+
def destroy(self):
|
| 97 |
+
for c in self.children[:]:
|
| 98 |
+
self.children.remove(c)
|
| 99 |
+
c.destroy()
|
| 100 |
+
self.parent = None
|
| 101 |
+
|
| 102 |
+
def geticonimage(self, name):
|
| 103 |
+
try:
|
| 104 |
+
return self.iconimages[name]
|
| 105 |
+
except KeyError:
|
| 106 |
+
pass
|
| 107 |
+
file, ext = os.path.splitext(name)
|
| 108 |
+
ext = ext or ".gif"
|
| 109 |
+
fullname = os.path.join(ICONDIR, file + ext)
|
| 110 |
+
image = PhotoImage(master=self.canvas, file=fullname)
|
| 111 |
+
self.iconimages[name] = image
|
| 112 |
+
return image
|
| 113 |
+
|
| 114 |
+
def select(self, event=None):
|
| 115 |
+
if self.selected:
|
| 116 |
+
return
|
| 117 |
+
self.deselectall()
|
| 118 |
+
self.selected = True
|
| 119 |
+
self.canvas.delete(self.image_id)
|
| 120 |
+
self.drawicon()
|
| 121 |
+
self.drawtext()
|
| 122 |
+
|
| 123 |
+
def deselect(self, event=None):
|
| 124 |
+
if not self.selected:
|
| 125 |
+
return
|
| 126 |
+
self.selected = False
|
| 127 |
+
self.canvas.delete(self.image_id)
|
| 128 |
+
self.drawicon()
|
| 129 |
+
self.drawtext()
|
| 130 |
+
|
| 131 |
+
def deselectall(self):
|
| 132 |
+
if self.parent:
|
| 133 |
+
self.parent.deselectall()
|
| 134 |
+
else:
|
| 135 |
+
self.deselecttree()
|
| 136 |
+
|
| 137 |
+
def deselecttree(self):
|
| 138 |
+
if self.selected:
|
| 139 |
+
self.deselect()
|
| 140 |
+
for child in self.children:
|
| 141 |
+
child.deselecttree()
|
| 142 |
+
|
| 143 |
+
def flip(self, event=None):
|
| 144 |
+
if self.state == 'expanded':
|
| 145 |
+
self.collapse()
|
| 146 |
+
else:
|
| 147 |
+
self.expand()
|
| 148 |
+
self.item.OnDoubleClick()
|
| 149 |
+
return "break"
|
| 150 |
+
|
| 151 |
+
def expand(self, event=None):
|
| 152 |
+
if not self.item._IsExpandable():
|
| 153 |
+
return
|
| 154 |
+
if self.state != 'expanded':
|
| 155 |
+
self.state = 'expanded'
|
| 156 |
+
self.update()
|
| 157 |
+
self.view()
|
| 158 |
+
|
| 159 |
+
def collapse(self, event=None):
|
| 160 |
+
if self.state != 'collapsed':
|
| 161 |
+
self.state = 'collapsed'
|
| 162 |
+
self.update()
|
| 163 |
+
|
| 164 |
+
def view(self):
|
| 165 |
+
top = self.y - 2
|
| 166 |
+
bottom = self.lastvisiblechild().y + 17
|
| 167 |
+
height = bottom - top
|
| 168 |
+
visible_top = self.canvas.canvasy(0)
|
| 169 |
+
visible_height = self.canvas.winfo_height()
|
| 170 |
+
visible_bottom = self.canvas.canvasy(visible_height)
|
| 171 |
+
if visible_top <= top and bottom <= visible_bottom:
|
| 172 |
+
return
|
| 173 |
+
x0, y0, x1, y1 = self.canvas._getints(self.canvas['scrollregion'])
|
| 174 |
+
if top >= visible_top and height <= visible_height:
|
| 175 |
+
fraction = top + height - visible_height
|
| 176 |
+
else:
|
| 177 |
+
fraction = top
|
| 178 |
+
fraction = float(fraction) / y1
|
| 179 |
+
self.canvas.yview_moveto(fraction)
|
| 180 |
+
|
| 181 |
+
def lastvisiblechild(self):
|
| 182 |
+
if self.children and self.state == 'expanded':
|
| 183 |
+
return self.children[-1].lastvisiblechild()
|
| 184 |
+
else:
|
| 185 |
+
return self
|
| 186 |
+
|
| 187 |
+
def update(self):
|
| 188 |
+
if self.parent:
|
| 189 |
+
self.parent.update()
|
| 190 |
+
else:
|
| 191 |
+
oldcursor = self.canvas['cursor']
|
| 192 |
+
self.canvas['cursor'] = "watch"
|
| 193 |
+
self.canvas.update()
|
| 194 |
+
self.canvas.delete(ALL) # XXX could be more subtle
|
| 195 |
+
self.draw(7, 2)
|
| 196 |
+
x0, y0, x1, y1 = self.canvas.bbox(ALL)
|
| 197 |
+
self.canvas.configure(scrollregion=(0, 0, x1, y1))
|
| 198 |
+
self.canvas['cursor'] = oldcursor
|
| 199 |
+
|
| 200 |
+
def draw(self, x, y):
|
| 201 |
+
# XXX This hard-codes too many geometry constants!
|
| 202 |
+
dy = 20
|
| 203 |
+
self.x, self.y = x, y
|
| 204 |
+
self.drawicon()
|
| 205 |
+
self.drawtext()
|
| 206 |
+
if self.state != 'expanded':
|
| 207 |
+
return y + dy
|
| 208 |
+
# draw children
|
| 209 |
+
if not self.children:
|
| 210 |
+
sublist = self.item._GetSubList()
|
| 211 |
+
if not sublist:
|
| 212 |
+
# _IsExpandable() was mistaken; that's allowed
|
| 213 |
+
return y+17
|
| 214 |
+
for item in sublist:
|
| 215 |
+
child = self.__class__(self.canvas, self, item)
|
| 216 |
+
self.children.append(child)
|
| 217 |
+
cx = x+20
|
| 218 |
+
cy = y + dy
|
| 219 |
+
cylast = 0
|
| 220 |
+
for child in self.children:
|
| 221 |
+
cylast = cy
|
| 222 |
+
self.canvas.create_line(x+9, cy+7, cx, cy+7, fill="gray50")
|
| 223 |
+
cy = child.draw(cx, cy)
|
| 224 |
+
if child.item._IsExpandable():
|
| 225 |
+
if child.state == 'expanded':
|
| 226 |
+
iconname = "minusnode"
|
| 227 |
+
callback = child.collapse
|
| 228 |
+
else:
|
| 229 |
+
iconname = "plusnode"
|
| 230 |
+
callback = child.expand
|
| 231 |
+
image = self.geticonimage(iconname)
|
| 232 |
+
id = self.canvas.create_image(x+9, cylast+7, image=image)
|
| 233 |
+
# XXX This leaks bindings until canvas is deleted:
|
| 234 |
+
self.canvas.tag_bind(id, "<1>", callback)
|
| 235 |
+
self.canvas.tag_bind(id, "<Double-1>", lambda x: None)
|
| 236 |
+
id = self.canvas.create_line(x+9, y+10, x+9, cylast+7,
|
| 237 |
+
##stipple="gray50", # XXX Seems broken in Tk 8.0.x
|
| 238 |
+
fill="gray50")
|
| 239 |
+
self.canvas.tag_lower(id) # XXX .lower(id) before Python 1.5.2
|
| 240 |
+
return cy
|
| 241 |
+
|
| 242 |
+
def drawicon(self):
|
| 243 |
+
if self.selected:
|
| 244 |
+
imagename = (self.item.GetSelectedIconName() or
|
| 245 |
+
self.item.GetIconName() or
|
| 246 |
+
"openfolder")
|
| 247 |
+
else:
|
| 248 |
+
imagename = self.item.GetIconName() or "folder"
|
| 249 |
+
image = self.geticonimage(imagename)
|
| 250 |
+
id = self.canvas.create_image(self.x, self.y, anchor="nw", image=image)
|
| 251 |
+
self.image_id = id
|
| 252 |
+
self.canvas.tag_bind(id, "<1>", self.select)
|
| 253 |
+
self.canvas.tag_bind(id, "<Double-1>", self.flip)
|
| 254 |
+
|
| 255 |
+
def drawtext(self):
|
| 256 |
+
textx = self.x+20-1
|
| 257 |
+
texty = self.y-4
|
| 258 |
+
labeltext = self.item.GetLabelText()
|
| 259 |
+
if labeltext:
|
| 260 |
+
id = self.canvas.create_text(textx, texty, anchor="nw",
|
| 261 |
+
text=labeltext)
|
| 262 |
+
self.canvas.tag_bind(id, "<1>", self.select)
|
| 263 |
+
self.canvas.tag_bind(id, "<Double-1>", self.flip)
|
| 264 |
+
x0, y0, x1, y1 = self.canvas.bbox(id)
|
| 265 |
+
textx = max(x1, 200) + 10
|
| 266 |
+
text = self.item.GetText() or "<no text>"
|
| 267 |
+
try:
|
| 268 |
+
self.entry
|
| 269 |
+
except AttributeError:
|
| 270 |
+
pass
|
| 271 |
+
else:
|
| 272 |
+
self.edit_finish()
|
| 273 |
+
try:
|
| 274 |
+
self.label
|
| 275 |
+
except AttributeError:
|
| 276 |
+
# padding carefully selected (on Windows) to match Entry widget:
|
| 277 |
+
self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
|
| 278 |
+
theme = idleConf.CurrentTheme()
|
| 279 |
+
if self.selected:
|
| 280 |
+
self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
|
| 281 |
+
else:
|
| 282 |
+
self.label.configure(idleConf.GetHighlight(theme, 'normal'))
|
| 283 |
+
id = self.canvas.create_window(textx, texty,
|
| 284 |
+
anchor="nw", window=self.label)
|
| 285 |
+
self.label.bind("<1>", self.select_or_edit)
|
| 286 |
+
self.label.bind("<Double-1>", self.flip)
|
| 287 |
+
self.label.bind("<MouseWheel>", lambda e: wheel_event(e, self.canvas))
|
| 288 |
+
self.label.bind("<Button-4>", lambda e: wheel_event(e, self.canvas))
|
| 289 |
+
self.label.bind("<Button-5>", lambda e: wheel_event(e, self.canvas))
|
| 290 |
+
self.text_id = id
|
| 291 |
+
|
| 292 |
+
def select_or_edit(self, event=None):
|
| 293 |
+
if self.selected and self.item.IsEditable():
|
| 294 |
+
self.edit(event)
|
| 295 |
+
else:
|
| 296 |
+
self.select(event)
|
| 297 |
+
|
| 298 |
+
def edit(self, event=None):
|
| 299 |
+
self.entry = Entry(self.label, bd=0, highlightthickness=1, width=0)
|
| 300 |
+
self.entry.insert(0, self.label['text'])
|
| 301 |
+
self.entry.selection_range(0, END)
|
| 302 |
+
self.entry.pack(ipadx=5)
|
| 303 |
+
self.entry.focus_set()
|
| 304 |
+
self.entry.bind("<Return>", self.edit_finish)
|
| 305 |
+
self.entry.bind("<Escape>", self.edit_cancel)
|
| 306 |
+
|
| 307 |
+
def edit_finish(self, event=None):
|
| 308 |
+
try:
|
| 309 |
+
entry = self.entry
|
| 310 |
+
del self.entry
|
| 311 |
+
except AttributeError:
|
| 312 |
+
return
|
| 313 |
+
text = entry.get()
|
| 314 |
+
entry.destroy()
|
| 315 |
+
if text and text != self.item.GetText():
|
| 316 |
+
self.item.SetText(text)
|
| 317 |
+
text = self.item.GetText()
|
| 318 |
+
self.label['text'] = text
|
| 319 |
+
self.drawtext()
|
| 320 |
+
self.canvas.focus_set()
|
| 321 |
+
|
| 322 |
+
def edit_cancel(self, event=None):
|
| 323 |
+
try:
|
| 324 |
+
entry = self.entry
|
| 325 |
+
del self.entry
|
| 326 |
+
except AttributeError:
|
| 327 |
+
return
|
| 328 |
+
entry.destroy()
|
| 329 |
+
self.drawtext()
|
| 330 |
+
self.canvas.focus_set()
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
class TreeItem:
|
| 334 |
+
|
| 335 |
+
"""Abstract class representing tree items.
|
| 336 |
+
|
| 337 |
+
Methods should typically be overridden, otherwise a default action
|
| 338 |
+
is used.
|
| 339 |
+
|
| 340 |
+
"""
|
| 341 |
+
|
| 342 |
+
def __init__(self):
|
| 343 |
+
"""Constructor. Do whatever you need to do."""
|
| 344 |
+
|
| 345 |
+
def GetText(self):
|
| 346 |
+
"""Return text string to display."""
|
| 347 |
+
|
| 348 |
+
def GetLabelText(self):
|
| 349 |
+
"""Return label text string to display in front of text (if any)."""
|
| 350 |
+
|
| 351 |
+
expandable = None
|
| 352 |
+
|
| 353 |
+
def _IsExpandable(self):
|
| 354 |
+
"""Do not override! Called by TreeNode."""
|
| 355 |
+
if self.expandable is None:
|
| 356 |
+
self.expandable = self.IsExpandable()
|
| 357 |
+
return self.expandable
|
| 358 |
+
|
| 359 |
+
def IsExpandable(self):
|
| 360 |
+
"""Return whether there are subitems."""
|
| 361 |
+
return 1
|
| 362 |
+
|
| 363 |
+
def _GetSubList(self):
|
| 364 |
+
"""Do not override! Called by TreeNode."""
|
| 365 |
+
if not self.IsExpandable():
|
| 366 |
+
return []
|
| 367 |
+
sublist = self.GetSubList()
|
| 368 |
+
if not sublist:
|
| 369 |
+
self.expandable = 0
|
| 370 |
+
return sublist
|
| 371 |
+
|
| 372 |
+
def IsEditable(self):
|
| 373 |
+
"""Return whether the item's text may be edited."""
|
| 374 |
+
|
| 375 |
+
def SetText(self, text):
|
| 376 |
+
"""Change the item's text (if it is editable)."""
|
| 377 |
+
|
| 378 |
+
def GetIconName(self):
|
| 379 |
+
"""Return name of icon to be displayed normally."""
|
| 380 |
+
|
| 381 |
+
def GetSelectedIconName(self):
|
| 382 |
+
"""Return name of icon to be displayed when selected."""
|
| 383 |
+
|
| 384 |
+
def GetSubList(self):
|
| 385 |
+
"""Return list of items forming sublist."""
|
| 386 |
+
|
| 387 |
+
def OnDoubleClick(self):
|
| 388 |
+
"""Called on a double-click on the item."""
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
# Example application
|
| 392 |
+
|
| 393 |
+
class FileTreeItem(TreeItem):
|
| 394 |
+
|
| 395 |
+
"""Example TreeItem subclass -- browse the file system."""
|
| 396 |
+
|
| 397 |
+
def __init__(self, path):
|
| 398 |
+
self.path = path
|
| 399 |
+
|
| 400 |
+
def GetText(self):
|
| 401 |
+
return os.path.basename(self.path) or self.path
|
| 402 |
+
|
| 403 |
+
def IsEditable(self):
|
| 404 |
+
return os.path.basename(self.path) != ""
|
| 405 |
+
|
| 406 |
+
def SetText(self, text):
|
| 407 |
+
newpath = os.path.dirname(self.path)
|
| 408 |
+
newpath = os.path.join(newpath, text)
|
| 409 |
+
if os.path.dirname(newpath) != os.path.dirname(self.path):
|
| 410 |
+
return
|
| 411 |
+
try:
|
| 412 |
+
os.rename(self.path, newpath)
|
| 413 |
+
self.path = newpath
|
| 414 |
+
except OSError:
|
| 415 |
+
pass
|
| 416 |
+
|
| 417 |
+
def GetIconName(self):
|
| 418 |
+
if not self.IsExpandable():
|
| 419 |
+
return "python" # XXX wish there was a "file" icon
|
| 420 |
+
|
| 421 |
+
def IsExpandable(self):
|
| 422 |
+
return os.path.isdir(self.path)
|
| 423 |
+
|
| 424 |
+
def GetSubList(self):
|
| 425 |
+
try:
|
| 426 |
+
names = os.listdir(self.path)
|
| 427 |
+
except OSError:
|
| 428 |
+
return []
|
| 429 |
+
names.sort(key = os.path.normcase)
|
| 430 |
+
sublist = []
|
| 431 |
+
for name in names:
|
| 432 |
+
item = FileTreeItem(os.path.join(self.path, name))
|
| 433 |
+
sublist.append(item)
|
| 434 |
+
return sublist
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
# A canvas widget with scroll bars and some useful bindings
|
| 438 |
+
|
| 439 |
+
class ScrolledCanvas:
|
| 440 |
+
|
| 441 |
+
def __init__(self, master, **opts):
|
| 442 |
+
if 'yscrollincrement' not in opts:
|
| 443 |
+
opts['yscrollincrement'] = 17
|
| 444 |
+
self.master = master
|
| 445 |
+
self.frame = Frame(master)
|
| 446 |
+
self.frame.rowconfigure(0, weight=1)
|
| 447 |
+
self.frame.columnconfigure(0, weight=1)
|
| 448 |
+
self.canvas = Canvas(self.frame, **opts)
|
| 449 |
+
self.canvas.grid(row=0, column=0, sticky="nsew")
|
| 450 |
+
self.vbar = Scrollbar(self.frame, name="vbar")
|
| 451 |
+
self.vbar.grid(row=0, column=1, sticky="nse")
|
| 452 |
+
self.hbar = Scrollbar(self.frame, name="hbar", orient="horizontal")
|
| 453 |
+
self.hbar.grid(row=1, column=0, sticky="ews")
|
| 454 |
+
self.canvas['yscrollcommand'] = self.vbar.set
|
| 455 |
+
self.vbar['command'] = self.canvas.yview
|
| 456 |
+
self.canvas['xscrollcommand'] = self.hbar.set
|
| 457 |
+
self.hbar['command'] = self.canvas.xview
|
| 458 |
+
self.canvas.bind("<Key-Prior>", self.page_up)
|
| 459 |
+
self.canvas.bind("<Key-Next>", self.page_down)
|
| 460 |
+
self.canvas.bind("<Key-Up>", self.unit_up)
|
| 461 |
+
self.canvas.bind("<Key-Down>", self.unit_down)
|
| 462 |
+
self.canvas.bind("<MouseWheel>", wheel_event)
|
| 463 |
+
self.canvas.bind("<Button-4>", wheel_event)
|
| 464 |
+
self.canvas.bind("<Button-5>", wheel_event)
|
| 465 |
+
#if isinstance(master, Toplevel) or isinstance(master, Tk):
|
| 466 |
+
self.canvas.bind("<Alt-Key-2>", self.zoom_height)
|
| 467 |
+
self.canvas.focus_set()
|
| 468 |
+
def page_up(self, event):
|
| 469 |
+
self.canvas.yview_scroll(-1, "page")
|
| 470 |
+
return "break"
|
| 471 |
+
def page_down(self, event):
|
| 472 |
+
self.canvas.yview_scroll(1, "page")
|
| 473 |
+
return "break"
|
| 474 |
+
def unit_up(self, event):
|
| 475 |
+
self.canvas.yview_scroll(-1, "unit")
|
| 476 |
+
return "break"
|
| 477 |
+
def unit_down(self, event):
|
| 478 |
+
self.canvas.yview_scroll(1, "unit")
|
| 479 |
+
return "break"
|
| 480 |
+
def zoom_height(self, event):
|
| 481 |
+
zoomheight.zoom_height(self.master)
|
| 482 |
+
return "break"
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def _tree_widget(parent): # htest #
|
| 486 |
+
top = Toplevel(parent)
|
| 487 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 488 |
+
top.geometry("+%d+%d" % (x+50, y+175))
|
| 489 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
| 490 |
+
sc.frame.pack(expand=1, fill="both", side=LEFT)
|
| 491 |
+
item = FileTreeItem(ICONDIR)
|
| 492 |
+
node = TreeNode(sc.canvas, None, item)
|
| 493 |
+
node.expand()
|
| 494 |
+
|
| 495 |
+
if __name__ == '__main__':
|
| 496 |
+
from unittest import main
|
| 497 |
+
main('idlelib.idle_test.test_tree', verbosity=2, exit=False)
|
| 498 |
+
|
| 499 |
+
from idlelib.idle_test.htest import run
|
| 500 |
+
run(_tree_widget)
|
evalkit_tf446/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)
|
evalkit_tf446/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)
|
evalkit_tf446/lib/python3.10/idlelib/window.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tkinter import Toplevel, TclError
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class WindowList:
|
| 6 |
+
|
| 7 |
+
def __init__(self):
|
| 8 |
+
self.dict = {}
|
| 9 |
+
self.callbacks = []
|
| 10 |
+
|
| 11 |
+
def add(self, window):
|
| 12 |
+
window.after_idle(self.call_callbacks)
|
| 13 |
+
self.dict[str(window)] = window
|
| 14 |
+
|
| 15 |
+
def delete(self, window):
|
| 16 |
+
try:
|
| 17 |
+
del self.dict[str(window)]
|
| 18 |
+
except KeyError:
|
| 19 |
+
# Sometimes, destroy() is called twice
|
| 20 |
+
pass
|
| 21 |
+
self.call_callbacks()
|
| 22 |
+
|
| 23 |
+
def add_windows_to_menu(self, menu):
|
| 24 |
+
list = []
|
| 25 |
+
for key in self.dict:
|
| 26 |
+
window = self.dict[key]
|
| 27 |
+
try:
|
| 28 |
+
title = window.get_title()
|
| 29 |
+
except TclError:
|
| 30 |
+
continue
|
| 31 |
+
list.append((title, key, window))
|
| 32 |
+
list.sort()
|
| 33 |
+
for title, key, window in list:
|
| 34 |
+
menu.add_command(label=title, command=window.wakeup)
|
| 35 |
+
|
| 36 |
+
def register_callback(self, callback):
|
| 37 |
+
self.callbacks.append(callback)
|
| 38 |
+
|
| 39 |
+
def unregister_callback(self, callback):
|
| 40 |
+
try:
|
| 41 |
+
self.callbacks.remove(callback)
|
| 42 |
+
except ValueError:
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
def call_callbacks(self):
|
| 46 |
+
for callback in self.callbacks:
|
| 47 |
+
try:
|
| 48 |
+
callback()
|
| 49 |
+
except:
|
| 50 |
+
t, v, tb = sys.exc_info()
|
| 51 |
+
print("warning: callback failed in WindowList", t, ":", v)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
registry = WindowList()
|
| 55 |
+
|
| 56 |
+
add_windows_to_menu = registry.add_windows_to_menu
|
| 57 |
+
register_callback = registry.register_callback
|
| 58 |
+
unregister_callback = registry.unregister_callback
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class ListedToplevel(Toplevel):
|
| 62 |
+
|
| 63 |
+
def __init__(self, master, **kw):
|
| 64 |
+
Toplevel.__init__(self, master, kw)
|
| 65 |
+
registry.add(self)
|
| 66 |
+
self.focused_widget = self
|
| 67 |
+
|
| 68 |
+
def destroy(self):
|
| 69 |
+
registry.delete(self)
|
| 70 |
+
Toplevel.destroy(self)
|
| 71 |
+
# If this is Idle's last window then quit the mainloop
|
| 72 |
+
# (Needed for clean exit on Windows 98)
|
| 73 |
+
if not registry.dict:
|
| 74 |
+
self.quit()
|
| 75 |
+
|
| 76 |
+
def update_windowlist_registry(self, window):
|
| 77 |
+
registry.call_callbacks()
|
| 78 |
+
|
| 79 |
+
def get_title(self):
|
| 80 |
+
# Subclass can override
|
| 81 |
+
return self.wm_title()
|
| 82 |
+
|
| 83 |
+
def wakeup(self):
|
| 84 |
+
try:
|
| 85 |
+
if self.wm_state() == "iconic":
|
| 86 |
+
self.wm_withdraw()
|
| 87 |
+
self.wm_deiconify()
|
| 88 |
+
self.tkraise()
|
| 89 |
+
self.focused_widget.focus_set()
|
| 90 |
+
except TclError:
|
| 91 |
+
# This can happen when the Window menu was torn off.
|
| 92 |
+
# Simply ignore it.
|
| 93 |
+
pass
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
from unittest import main
|
| 98 |
+
main('idlelib.idle_test.test_window', verbosity=2)
|
evalkit_tf446/lib/python3.10/lib2to3/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (557 Bytes). View file
|
|
|