Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move fixup code to util.fix_win_hidpi.
  • Loading branch information
terryjreedy committed May 20, 2024
commit ee146a7b7b52dcdb0349a4eefae7d3f9995a889f
3 changes: 2 additions & 1 deletion 3 Lib/idlelib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ def __init__(self, _utest=False):
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()
Expand Down
10 changes: 2 additions & 8 deletions 10 Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@
"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

Expand Down
15 changes: 15 additions & 0 deletions 15 Lib/idlelib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@
* 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)
16 changes: 4 additions & 12 deletions 16 Lib/turtledemo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@
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()

Wulian233 marked this conversation as resolved.
Show resolved Hide resolved
demo_dir = os.path.dirname(os.path.abspath(__file__))
darwin = sys.platform == 'darwin'
win32 = sys.platform == 'win32'

STARTUP = 1
READY = 2
RUNNING = 3
Expand Down Expand Up @@ -132,15 +133,6 @@ def __init__(self, filename=None):
root.title('Python turtle-graphics examples')
root.wm_protocol("WM_DELETE_WINDOW", self._destroy)

# See https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-process_dpi_awareness
if win32:
try:
import ctypes
PROCESS_SYSTEM_DPI_AWARE = 1 # Int required.
ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
except (ImportError, AttributeError, OSError):
pass

if darwin:
import subprocess
# Make sure we are the currently activated OS X application
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.