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

Commit 268392f

Browse filesBrowse files
committed
Set per-monitor awareness on MSW when matplotlib creates the wx application.
1 parent a96b4a1 commit 268392f
Copy full SHA for 268392f

File tree

Expand file treeCollapse file tree

1 file changed

+9
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-3
lines changed

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def _create_wxapp():
4343
wxapp = wx.App(False)
4444
wxapp.SetExitOnFrameDelete(True)
4545
cbook._setup_new_guiapp()
46+
if wx.Platform == '__WXMSW__':
47+
# Set per-process DPI awareness. See https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-process_dpi_awareness
48+
import ctypes
49+
ctypes.windll.shcore.SetProcessDpiAwareness(2)
4650
return wxapp
4751

4852

@@ -469,9 +473,11 @@ def __init__(self, parent, id, figure=None):
469473
"""
470474

471475
FigureCanvasBase.__init__(self, figure)
472-
w, h = map(math.ceil, self.figure.bbox.size)
476+
size = wx.Size(*map(math.ceil, self.figure.bbox.size))
477+
if wx.Platform != '__WXMSW__':
478+
size = parent.FromDIP(size)
473479
# Set preferred window size hint - helps the sizer, if one is connected
474-
wx.Panel.__init__(self, parent, id, size=parent.FromDIP(wx.Size(w, h)))
480+
wx.Panel.__init__(self, parent, id, size=size)
475481
self.bitmap = None
476482
self._isDrawn = False
477483
self._rubberband_rect = None
@@ -1132,7 +1138,7 @@ def save_figure(self, *args):
11321138

11331139
def draw_rubberband(self, event, x0, y0, x1, y1):
11341140
height = self.canvas.figure.bbox.height
1135-
sf = self.GetDPIScaleFactor()
1141+
sf = 1 if wx.Platform == '__WXMSW__' else self.GetDPIScaleFactor()
11361142
self.canvas._rubberband_rect = (x0/sf, (height - y0)/sf,
11371143
x1/sf, (height - y1)/sf)
11381144
self.canvas.Refresh()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.