]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-119174: Fix high DPI causes turtledemo(turtle-graphics examples) windows...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 21 May 2024 04:09:30 +0000 (06:09 +0200)
committerGitHub <noreply@github.com>
Tue, 21 May 2024 04:09:30 +0000 (04:09 +0000)
gh-119174: Fix high DPI causes turtledemo(turtle-graphics examples) windows blurry (GH-119175)

------

(cherry picked from commit 538ed5e4818aa0d0aa759634e8bfa23e317434a1)

Co-authored-by: Wulian233 <71213467+Wulian233@users.noreply.github.com>
Lib/idlelib/config.py
Lib/idlelib/pyshell.py
Lib/idlelib/util.py
Lib/turtledemo/__main__.py
Misc/NEWS.d/next/Library/2024-05-19-18-49-04.gh-issue-119174.5GTv7d.rst [new file with mode: 0644]

index 7fc08ef97481821266a5ff809d7d99905e040299..6a5acac9be88886a959a518950c55eaf98c8d88b 100644 (file)
@@ -158,8 +158,9 @@ class IdleConf:
         self.defaultCfg = {}
         self.userCfg = {}
         self.cfg = {}  # TODO use to select userCfg vs defaultCfg
+
+        # See https://bugs.python.org/issue4630#msg356516 for following.
         # self.blink_off_time = <first editor text>['insertofftime']
-        # See https://bugs.python.org/issue4630#msg356516.
 
         if not _utest:
             self.CreateConfigHandlers()
index 1524fccd5d20f8e960af75d06b21fa74a1e7f976..d8b2652d5d7979c26069c75eee29b6fee3a7bfe5 100755 (executable)
@@ -11,15 +11,9 @@ except ImportError:
           "Your Python may not be configured for Tk. **", file=sys.__stderr__)
     raise SystemExit(1)
 
-# Valid arguments for the ...Awareness call below are defined in the following.
-# https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx
 if sys.platform == 'win32':
-    try:
-        import ctypes
-        PROCESS_SYSTEM_DPI_AWARE = 1  # Int required.
-        ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
-    except (ImportError, AttributeError, OSError):
-        pass
+    from idlelib.util import fix_win_hidpi
+    fix_win_hidpi()
 
 from tkinter import messagebox
 
index a7ae74b0579004a180a16f4817448034f71c36bd..e05604ab4853f6dbf342ccf874ba6ee9dd85d11b 100644 (file)
@@ -12,11 +12,26 @@ TODO:
     * std streams (pyshell, run),
     * warning stuff (pyshell, run).
 """
+import sys
 
 # .pyw is for Windows; .pyi is for typing stub files.
 # The extension order is needed for iomenu open/save dialogs.
 py_extensions = ('.py', '.pyw', '.pyi')
 
+
+# Fix for HiDPI screens on Windows.  CALL BEFORE ANY TK OPERATIONS!
+# URL for arguments for the ...Awareness call below.
+# https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx
+if sys.platform == 'win32':  # pragma: no cover
+    def fix_win_hidpi():  # Called in pyshell and turtledemo.
+        try:
+            import ctypes
+            PROCESS_SYSTEM_DPI_AWARE = 1  # Int required.
+            ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
+        except (ImportError, AttributeError, OSError):
+            pass
+
+
 if __name__ == '__main__':
     from unittest import main
     main('idlelib.idle_test.test_util', verbosity=2)
index 2ab6c15e2c079ee355eea4c07c3985179fb2f29c..731f98b02b17a72c64e021b67d001f696ebe0d9d 100755 (executable)
@@ -92,13 +92,15 @@ from tkinter import *
 from idlelib.colorizer import ColorDelegator, color_config
 from idlelib.percolator import Percolator
 from idlelib.textview import view_text
+import turtle
 from turtledemo import __doc__ as about_turtledemo
 
-import turtle
+if sys.platform == 'win32':
+    from idlelib.util import fix_win_hidpi
+    fix_win_hidpi()
 
 demo_dir = os.path.dirname(os.path.abspath(__file__))
 darwin = sys.platform == 'darwin'
-
 STARTUP = 1
 READY = 2
 RUNNING = 3
diff --git a/Misc/NEWS.d/next/Library/2024-05-19-18-49-04.gh-issue-119174.5GTv7d.rst b/Misc/NEWS.d/next/Library/2024-05-19-18-49-04.gh-issue-119174.5GTv7d.rst
new file mode 100644 (file)
index 0000000..7b467b9
--- /dev/null
@@ -0,0 +1,3 @@
+Fix high DPI causes turtledemo(turtle-graphics examples) windows blurry\r
+Patch by Wulian233 and Terry Jan Reedy\r
+\r