gh-119174: Fix high DPI causes turtledemo(turtle-graphics examples) windows blurry (#119175)

------
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Wulian233 2024-05-21 11:32:00 +08:00 committed by GitHub
parent 172690227e
commit 538ed5e481
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 11 deletions

View File

@ -158,8 +158,9 @@ class IdleConf:
self.defaultCfg = {} self.defaultCfg = {}
self.userCfg = {} self.userCfg = {}
self.cfg = {} # TODO use to select userCfg vs defaultCfg 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'] # self.blink_off_time = <first editor text>['insertofftime']
# See https://bugs.python.org/issue4630#msg356516.
if not _utest: if not _utest:
self.CreateConfigHandlers() self.CreateConfigHandlers()

View File

@ -11,15 +11,9 @@ except ImportError:
"Your Python may not be configured for Tk. **", file=sys.__stderr__) "Your Python may not be configured for Tk. **", file=sys.__stderr__)
raise SystemExit(1) 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': if sys.platform == 'win32':
try: from idlelib.util import fix_win_hidpi
import ctypes fix_win_hidpi()
PROCESS_SYSTEM_DPI_AWARE = 1 # Int required.
ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
except (ImportError, AttributeError, OSError):
pass
from tkinter import messagebox from tkinter import messagebox

View File

@ -12,11 +12,26 @@ TODO:
* std streams (pyshell, run), * std streams (pyshell, run),
* warning stuff (pyshell, run). * warning stuff (pyshell, run).
""" """
import sys
# .pyw is for Windows; .pyi is for typing stub files. # .pyw is for Windows; .pyi is for typing stub files.
# The extension order is needed for iomenu open/save dialogs. # The extension order is needed for iomenu open/save dialogs.
py_extensions = ('.py', '.pyw', '.pyi') 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__': if __name__ == '__main__':
from unittest import main from unittest import main
main('idlelib.idle_test.test_util', verbosity=2) main('idlelib.idle_test.test_util', verbosity=2)

View File

@ -92,13 +92,15 @@ from tkinter import *
from idlelib.colorizer import ColorDelegator, color_config from idlelib.colorizer import ColorDelegator, color_config
from idlelib.percolator import Percolator from idlelib.percolator import Percolator
from idlelib.textview import view_text from idlelib.textview import view_text
import turtle
from turtledemo import __doc__ as about_turtledemo 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__)) demo_dir = os.path.dirname(os.path.abspath(__file__))
darwin = sys.platform == 'darwin' darwin = sys.platform == 'darwin'
STARTUP = 1 STARTUP = 1
READY = 2 READY = 2
RUNNING = 3 RUNNING = 3

View File

@ -0,0 +1,3 @@
Fix high DPI causes turtledemo(turtle-graphics examples) windows blurry
Patch by Wulian233 and Terry Jan Reedy