@@ -161,6 +161,7 @@ def _on_timer(self):
161
161
162
162
163
163
class FigureCanvasTk (FigureCanvasBase ):
164
+ manager_class = FigureManagerTk
164
165
required_interactive_framework = "tk"
165
166
166
167
def __init__ (self , figure = None , master = None ):
@@ -223,43 +224,6 @@ def _update_device_pixel_ratio(self, event=None):
223
224
w , h = self .get_width_height (physical = True )
224
225
self ._tkcanvas .configure (width = w , height = h )
225
226
226
- @classmethod
227
- def new_manager (cls , figure , num ):
228
- # docstring inherited
229
- with _restore_foreground_window_at_end ():
230
- if cbook ._get_running_interactive_framework () is None :
231
- cbook ._setup_new_guiapp ()
232
- _c_internal_utils .Win32_SetProcessDpiAwareness_max ()
233
- window = tk .Tk (className = "matplotlib" )
234
- window .withdraw ()
235
-
236
- # Put a Matplotlib icon on the window rather than the default tk
237
- # icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
238
- #
239
- # `ImageTk` can be replaced with `tk` whenever the minimum
240
- # supported Tk version is increased to 8.6, as Tk 8.6+ natively
241
- # supports PNG images.
242
- icon_fname = str (cbook ._get_data_path (
243
- 'images/matplotlib.png' ))
244
- icon_img = ImageTk .PhotoImage (file = icon_fname , master = window )
245
-
246
- icon_fname_large = str (cbook ._get_data_path (
247
- 'images/matplotlib_large.png' ))
248
- icon_img_large = ImageTk .PhotoImage (
249
- file = icon_fname_large , master = window )
250
- try :
251
- window .iconphoto (False , icon_img_large , icon_img )
252
- except Exception as exc :
253
- # log the failure (due e.g. to Tk version), but carry on
254
- _log .info ('Could not load matplotlib icon: %s' , exc )
255
-
256
- canvas = cls (figure , master = window )
257
- manager = FigureManagerTk (canvas , num , window )
258
- if mpl .is_interactive ():
259
- manager .show ()
260
- canvas .draw_idle ()
261
- return manager
262
-
263
227
def resize (self , event ):
264
228
width , height = event .width , event .height
265
229
@@ -468,6 +432,44 @@ def __init__(self, canvas, num, window):
468
432
469
433
self ._shown = False
470
434
435
+ @classmethod
436
+ def create_with_canvas (cls , canvas_class , figure , num ):
437
+
438
+ with _restore_foreground_window_at_end ():
439
+ if cbook ._get_running_interactive_framework () is None :
440
+ cbook ._setup_new_guiapp ()
441
+ _c_internal_utils .Win32_SetProcessDpiAwareness_max ()
442
+ window = tk .Tk (className = "matplotlib" )
443
+ window .withdraw ()
444
+
445
+ # Put a Matplotlib icon on the window rather than the default tk
446
+ # icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
447
+ #
448
+ # `ImageTk` can be replaced with `tk` whenever the minimum
449
+ # supported Tk version is increased to 8.6, as Tk 8.6+ natively
450
+ # supports PNG images.
451
+ icon_fname = str (cbook ._get_data_path (
452
+ 'images/matplotlib.png' ))
453
+ icon_img = ImageTk .PhotoImage (file = icon_fname , master = window )
454
+
455
+ icon_fname_large = str (cbook ._get_data_path (
456
+ 'images/matplotlib_large.png' ))
457
+ icon_img_large = ImageTk .PhotoImage (
458
+ file = icon_fname_large , master = window )
459
+ try :
460
+ window .iconphoto (False , icon_img_large , icon_img )
461
+ except Exception as exc :
462
+ # log the failure (due e.g. to Tk version), but carry on
463
+ _log .info ('Could not load matplotlib icon: %s' , exc )
464
+
465
+ canvas = canvas_class (figure , master = window )
466
+ manager = FigureManagerTk (canvas , num , window )
467
+ if mpl .is_interactive ():
468
+ manager .show ()
469
+ canvas .draw_idle ()
470
+ return manager
471
+
472
+
471
473
def _update_window_dpi (self , * args ):
472
474
newdpi = self ._window_dpi .get ()
473
475
self .window .call ('tk' , 'scaling' , newdpi / 72 )
0 commit comments