Skip to content

Commit 538ed5e

Browse files
authored
gh-119174: Fix high DPI causes turtledemo(turtle-graphics examples) windows blurry (#119175)
------ Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 1726902 commit 538ed5e

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Diff for: Lib/idlelib/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ def __init__(self, _utest=False):
158158
self.defaultCfg = {}
159159
self.userCfg = {}
160160
self.cfg = {} # TODO use to select userCfg vs defaultCfg
161+
162+
# See https://bugs.python.org/issue4630#msg356516 for following.
161163
# self.blink_off_time = <first editor text>['insertofftime']
162-
# See https://bugs.python.org/issue4630#msg356516.
163164

164165
if not _utest:
165166
self.CreateConfigHandlers()

Diff for: Lib/idlelib/pyshell.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
1212
raise SystemExit(1)
1313

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
1614
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
15+
from idlelib.util import fix_win_hidpi
16+
fix_win_hidpi()
2317

2418
from tkinter import messagebox
2519

Diff for: Lib/idlelib/util.py

+15
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,26 @@
1212
* std streams (pyshell, run),
1313
* warning stuff (pyshell, run).
1414
"""
15+
import sys
1516

1617
# .pyw is for Windows; .pyi is for typing stub files.
1718
# The extension order is needed for iomenu open/save dialogs.
1819
py_extensions = ('.py', '.pyw', '.pyi')
1920

21+
22+
# Fix for HiDPI screens on Windows. CALL BEFORE ANY TK OPERATIONS!
23+
# URL for arguments for the ...Awareness call below.
24+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx
25+
if sys.platform == 'win32': # pragma: no cover
26+
def fix_win_hidpi(): # Called in pyshell and turtledemo.
27+
try:
28+
import ctypes
29+
PROCESS_SYSTEM_DPI_AWARE = 1 # Int required.
30+
ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
31+
except (ImportError, AttributeError, OSError):
32+
pass
33+
34+
2035
if __name__ == '__main__':
2136
from unittest import main
2237
main('idlelib.idle_test.test_util', verbosity=2)

Diff for: Lib/turtledemo/__main__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@
9292
from idlelib.colorizer import ColorDelegator, color_config
9393
from idlelib.percolator import Percolator
9494
from idlelib.textview import view_text
95+
import turtle
9596
from turtledemo import __doc__ as about_turtledemo
9697

97-
import turtle
98+
if sys.platform == 'win32':
99+
from idlelib.util import fix_win_hidpi
100+
fix_win_hidpi()
98101

99102
demo_dir = os.path.dirname(os.path.abspath(__file__))
100103
darwin = sys.platform == 'darwin'
101-
102104
STARTUP = 1
103105
READY = 2
104106
RUNNING = 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix high DPI causes turtledemo(turtle-graphics examples) windows blurry
2+
Patch by Wulian233 and Terry Jan Reedy
3+

0 commit comments

Comments
 (0)