GeezerVison is showing github.com — [3.14] gh-152728: IDLE - move 3 toplevel fix_xyz functions to idlelb.… · python/cpython@b6ae32c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/News3.txt +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,9 @@ Released after 2025-10-07 | 4 | 4 | ========================= | 5 | 5 |
| 6 | 6 |
| | 7 | +gh-152728: Move functions run.fix_scaling, editor.fixwordbreaks (as fix_word_breaks) | | 8 | +and pyshell.fix_x11_paste to module util. Patch by Terry J. Reedy. | | 9 | + | 7 | 10 | gh-85320: IDLE now reads and writes its configuration files and the | 8 | 11 | breakpoints file using UTF-8 instead of the locale encoding. | 9 | 12 | Files with non-ASCII characters and non-UTF-8 encoding may need | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/editor.py +4-13Lines changed: 4 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1685,19 +1685,10 @@ def get_accelerator(keydefs, eventname): | 1685 | 1685 | return s | 1686 | 1686 |
| 1687 | 1687 |
| 1688 | | -def fixwordbreaks(root): | 1689 | | - # On Windows, tcl/tk breaks 'words' only on spaces, as in Command Prompt. | 1690 | | - # We want Motif style everywhere. See #21474, msg218992 and followup. | 1691 | | - tk = root.tk | 1692 | | - tk.call('tcl_wordBreakAfter', 'a b', 0) # make sure word.tcl is loaded | 1693 | | - tk.call('set', 'tcl_wordchars', r'\w') | 1694 | | - tk.call('set', 'tcl_nonwordchars', r'\W') | 1695 | | - | 1696 | | - | 1697 | | -def _editor_window(parent): # htest # | 1698 | | - # error if close master window first - timer event, after script | 1699 | | - root = parent | 1700 | | - fixwordbreaks(root) | | 1688 | +def _editor_window(root): # htest # | | 1689 | + # Error if close master window first - timer event, after script | | 1690 | + from util import fix_word_breaks | | 1691 | + fix_word_breaks(root) | 1701 | 1692 | if sys.argv[1:]: | 1702 | 1693 | filename = sys.argv[1] | 1703 | 1694 | else: | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/filelist.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,12 +112,12 @@ def canonize(self, filename): | 112 | 112 |
| 113 | 113 |
| 114 | 114 | def _test(): # TODO check and convert to htest | | 115 | + # Maybe redundant with test_filelist.FileListTest.test_new_empty. | 115 | 116 | from tkinter import Tk | 116 | | - from idlelib.editor import fixwordbreaks | 117 | | - from idlelib.run import fix_scaling | | 117 | + from idlelib.util import fix_scaling, fix_word_breaks | 118 | 118 | root = Tk() | 119 | 119 | fix_scaling(root) | 120 | | - fixwordbreaks(root) | | 120 | + fix_word_breaks(root) | 121 | 121 | root.withdraw() | 122 | 122 | flist = FileList(root) | 123 | 123 | flist.new() | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/idle_test/test_editmenu.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | import tkinter as tk | 8 | 8 | from tkinter import ttk | 9 | 9 | import unittest | 10 | | -from idlelib import pyshell | | 10 | +from idlelib.util import fix_x11_paste | 11 | 11 |
| 12 | 12 | class PasteTest(unittest.TestCase): | 13 | 13 | '''Test pasting into widgets that allow pasting. | @@ -18,7 +18,7 @@ class PasteTest(unittest.TestCase): | 18 | 18 | def setUpClass(cls): | 19 | 19 | cls.root = root = tk.Tk() | 20 | 20 | cls.root.withdraw() | 21 | | - pyshell.fix_x11_paste(root) | | 21 | + fix_x11_paste(root) | 22 | 22 | cls.text = tk.Text(root) | 23 | 23 | cls.entry = tk.Entry(root) | 24 | 24 | cls.tentry = ttk.Entry(root) | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/idle_test/test_sidebar.py +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | from idlelib.idle_test.tkinter_testing_utils import run_in_tk_mainloop | 12 | 12 |
| 13 | 13 | from idlelib.delegator import Delegator | 14 | | -from idlelib.editor import fixwordbreaks | 15 | 14 | from idlelib.percolator import Percolator | 16 | 15 | import idlelib.pyshell | 17 | | -from idlelib.pyshell import fix_x11_paste, PyShell, PyShellFileList | 18 | | -from idlelib.run import fix_scaling | | 16 | +from idlelib.pyshell import PyShell, PyShellFileList | | 17 | +from idlelib.util import fix_scaling, fix_word_breaks, fix_x11_paste | 19 | 18 | import idlelib.sidebar | 20 | 19 | from idlelib.sidebar import get_end_linenumber, get_lineno | 21 | 20 |
| @@ -403,7 +402,7 @@ def setUpClass(cls): | 403 | 402 | root.withdraw() | 404 | 403 |
| 405 | 404 | fix_scaling(root) | 406 | | - fixwordbreaks(root) | | 405 | + fix_word_breaks(root) | 407 | 406 | fix_x11_paste(root) | 408 | 407 |
| 409 | 408 | cls.flist = flist = PyShellFileList(root) | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/pyshell.py +6-16Lines changed: 6 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 36 | 36 | from idlelib.delegator import Delegator | 37 | 37 | from idlelib import debugger | 38 | 38 | from idlelib import debugger_r | 39 | | -from idlelib.editor import EditorWindow, fixwordbreaks | | 39 | +from idlelib.editor import EditorWindow | 40 | 40 | from idlelib.filelist import FileList | 41 | 41 | from idlelib.outwin import OutputWindow | 42 | 42 | from idlelib import replace | 43 | 43 | from idlelib import rpc | 44 | 44 | from idlelib.run import idle_formatwarning, StdInputFile, StdOutputFile | 45 | 45 | from idlelib.undo import UndoDelegator | | 46 | +from idlelib.util import fix_word_breaks | 46 | 47 |
| 47 | 48 | # Default for testing; defaults to True in main() for running. | 48 | 49 | use_subprocess = False | @@ -882,9 +883,9 @@ def __init__(self, flist=None): | 882 | 883 | if ms[2][0] != "shell": | 883 | 884 | ms.insert(2, ("shell", "She_ll")) | 884 | 885 | self.interp = ModifiedInterpreter(self) | 885 | | - if flist is None: | | 886 | + if flist is None: # TODO possible? root and flist in main. | 886 | 887 | root = Tk() | 887 | | - fixwordbreaks(root) | | 888 | + fix_word_breaks(root) | 888 | 889 | root.withdraw() | 889 | 890 | flist = PyShellFileList(root) | 890 | 891 |
| @@ -1453,17 +1454,6 @@ def on_squeezed_expand(self, index, text, tags): | 1453 | 1454 | self.shell_sidebar.update_sidebar() | 1454 | 1455 |
| 1455 | 1456 |
| 1456 | | -def fix_x11_paste(root): | 1457 | | - "Make paste replace selection on x11. See issue #5124." | 1458 | | - if root._windowingsystem == 'x11': | 1459 | | - for cls in 'Text', 'Entry', 'Spinbox': | 1460 | | - root.bind_class( | 1461 | | - cls, | 1462 | | - '<<Paste>>', | 1463 | | - 'catch {%W delete sel.first sel.last}\n' + | 1464 | | - root.bind_class(cls, '<<Paste>>')) | 1465 | | - | 1466 | | - | 1467 | 1457 | usage_msg = """\ | 1468 | 1458 |
| 1469 | 1459 | USAGE: idle [-deins] [-t title] [file]* | @@ -1523,6 +1513,7 @@ def main(): | 1523 | 1513 | from platform import system | 1524 | 1514 | from idlelib import testing # bool value | 1525 | 1515 | from idlelib import macosx | | 1516 | + from idlelib.util import fix_scaling, fix_x11_paste | 1526 | 1517 |
| 1527 | 1518 | global flist, root, use_subprocess | 1528 | 1519 |
| @@ -1608,7 +1599,6 @@ def main(): | 1608 | 1599 | NoDefaultRoot() | 1609 | 1600 | root = Tk(className="Idle") | 1610 | 1601 | root.withdraw() | 1611 | | - from idlelib.run import fix_scaling | 1612 | 1602 | fix_scaling(root) | 1613 | 1603 |
| 1614 | 1604 | # set application icon | @@ -1630,7 +1620,7 @@ def main(): | 1630 | 1620 | root.wm_iconphoto(True, *icons) | 1631 | 1621 |
| 1632 | 1622 | # start editor and/or shell windows: | 1633 | | - fixwordbreaks(root) | | 1623 | + fix_word_breaks(root) | 1634 | 1624 | fix_x11_paste(root) | 1635 | 1625 | flist = PyShellFileList(root) | 1636 | 1626 | macosx.setupApp(root, flist) | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/run.py +2-11Lines changed: 2 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | from idlelib import iomenu # encoding | 26 | 26 | from idlelib import rpc # multiple objects | 27 | 27 | from idlelib import stackviewer # StackTreeItem | | 28 | +from idlelib import util # fix_scaling | 28 | 29 | import __main__ | 29 | 30 |
| 30 | 31 | import tkinter # Use tcl and, if startup fails, messagebox. | @@ -216,7 +217,7 @@ def show_socket_error(err, address): | 216 | 217 | import tkinter | 217 | 218 | from tkinter.messagebox import showerror | 218 | 219 | root = tkinter.Tk() | 219 | | - fix_scaling(root) | | 220 | + util.fix_scaling(root) | 220 | 221 | root.withdraw() | 221 | 222 | showerror( | 222 | 223 | "Subprocess Connection Error", | @@ -326,16 +327,6 @@ def exit(): | 326 | 327 | sys.exit(0) | 327 | 328 |
| 328 | 329 |
| 329 | | -def fix_scaling(root): | 330 | | - """Scale fonts on HiDPI displays.""" | 331 | | - import tkinter.font | 332 | | - scaling = float(root.tk.call('tk', 'scaling')) | 333 | | - if scaling > 1.4: | 334 | | - for name in tkinter.font.names(root): | 335 | | - font = tkinter.font.Font(root=root, name=name, exists=True) | 336 | | - size = int(font['size']) | 337 | | - if size < 0: | 338 | | - font['size'] = round(-0.75*size) | 339 | 330 |
| 340 | 331 |
| 341 | 332 | def fixdoc(fun, text): | |
Collapse file Copy file name to clipboardExpand all lines: Lib/idlelib/util.py +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | py_extensions = ('.py', '.pyw', '.pyi') | 20 | 20 |
| 21 | 21 |
| | 22 | +# fix_x functions seem only needed once per process. | | 23 | + | | 24 | +def fix_scaling(root): # Called in filelist _test, pyshell, and run. | | 25 | + """Scale fonts on HiDPI displays, once per process.""" | | 26 | + import tkinter.font | | 27 | + scaling = float(root.tk.call('tk', 'scaling')) | | 28 | + if scaling > 1.4: | | 29 | + for name in tkinter.font.names(root): | | 30 | + font = tkinter.font.Font(root=root, name=name, exists=True) | | 31 | + size = int(font['size']) | | 32 | + if size < 0: | | 33 | + font['size'] = round(-0.75*size) | | 34 | + | | 35 | + | 22 | 36 | # Fix for HiDPI screens on Windows. CALL BEFORE ANY TK OPERATIONS! | 23 | 37 | # URL for arguments for the ...Awareness call below. | 24 | 38 | # https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx | @@ -31,6 +45,25 @@ def fix_win_hidpi(): # Called in pyshell and turtledemo. | 31 | 45 | except (ImportError, AttributeError, OSError): | 32 | 46 | pass | 33 | 47 |
| | 48 | +def fix_word_breaks(root): # Called in editor htest, filelist _test, pyshell. | | 49 | + # On Windows, tcl/tk breaks 'words' only on spaces, as in Command Prompt. | | 50 | + # We want Motif style everywhere. See #21474, msg218992 and followup. | | 51 | + tk = root.tk | | 52 | + tk.call('tcl_wordBreakAfter', 'a b', 0) # make sure word.tcl is loaded | | 53 | + tk.call('set', 'tcl_wordchars', r'\w') | | 54 | + tk.call('set', 'tcl_nonwordchars', r'\W') | | 55 | + | | 56 | + | | 57 | +def fix_x11_paste(root): | | 58 | + "Make paste replace selection on x11. See issue #5124." | | 59 | + if root._windowingsystem == 'x11': | | 60 | + for cls in 'Text', 'Entry', 'Spinbox': | | 61 | + root.bind_class( | | 62 | + cls, | | 63 | + '<<Paste>>', | | 64 | + 'catch {%W delete sel.first sel.last}\n' + | | 65 | + root.bind_class(cls, '<<Paste>>')) | | 66 | + | 34 | 67 |
| 35 | 68 | if __name__ == '__main__': | 36 | 69 | from unittest import main | |
Collapse file Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Move functions run.fix_scaling, editor.fixwordbreaks (as fix_word_breaks) | | 2 | +and pyshell.fix_x11_paste to idlelib.util. |
|