@@ -43,6 +43,10 @@ def _create_wxapp():
43
43
wxapp = wx .App (False )
44
44
wxapp .SetExitOnFrameDelete (True )
45
45
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 )
46
50
return wxapp
47
51
48
52
@@ -469,9 +473,11 @@ def __init__(self, parent, id, figure=None):
469
473
"""
470
474
471
475
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 )
473
479
# 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 )
475
481
self .bitmap = None
476
482
self ._isDrawn = False
477
483
self ._rubberband_rect = None
@@ -1132,7 +1138,7 @@ def save_figure(self, *args):
1132
1138
1133
1139
def draw_rubberband (self , event , x0 , y0 , x1 , y1 ):
1134
1140
height = self .canvas .figure .bbox .height
1135
- sf = self .GetDPIScaleFactor ()
1141
+ sf = 1 if wx . Platform == '__WXMSW__' else self .GetDPIScaleFactor ()
1136
1142
self .canvas ._rubberband_rect = (x0 / sf , (height - y0 )/ sf ,
1137
1143
x1 / sf , (height - y1 )/ sf )
1138
1144
self .canvas .Refresh ()
0 commit comments