Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9288a0c

Browse files
committed
Rewrite manager creation [skip ci]
1 parent8bb2bb1 commit9288a0c

File tree

9 files changed

+78
-87
lines changed

9 files changed

+78
-87
lines changed

‎lib/matplotlib/backend_bases.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,8 @@ class FigureCanvasBase:
15761576
A high-level figure instance.
15771577
"""
15781578

1579+
manager_class=FigureManagerBase
1580+
15791581
# Set to one of {"qt", "gtk3", "gtk4", "wx", "tk", "macosx"} if an
15801582
# interactive framework is required, or None otherwise.
15811583
required_interactive_framework=None
@@ -1670,7 +1672,7 @@ def new_manager(cls, figure, num):
16701672
Backends should override this method to instantiate the correct figure
16711673
manager subclass, and perform any additional setup that may be needed.
16721674
"""
1673-
returnFigureManagerBase(cls(figure),num)
1675+
returncls.manager_class.create_with_canvas(cls,figure,num)
16741676

16751677
@contextmanager
16761678
def_idle_draw_cntx(self):
@@ -2769,6 +2771,11 @@ def notify_axes_change(fig):
27692771
ifself.toolmanagerisNoneandself.toolbarisnotNone:
27702772
self.toolbar.update()
27712773

2774+
@classmethod
2775+
defcreate_with_canvas(cls,canvas_class,figure,num):
2776+
canvas=canvas_class(figure)
2777+
returncls(canvas,num)
2778+
27722779
defshow(self):
27732780
"""
27742781
For GUI backends, show the figure window and redraw.

‎lib/matplotlib/backends/_backend_tk.py‎

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def _on_timer(self):
161161

162162

163163
classFigureCanvasTk(FigureCanvasBase):
164+
manager_class=FigureManagerTk
164165
required_interactive_framework="tk"
165166

166167
def__init__(self,figure=None,master=None):
@@ -223,43 +224,6 @@ def _update_device_pixel_ratio(self, event=None):
223224
w,h=self.get_width_height(physical=True)
224225
self._tkcanvas.configure(width=w,height=h)
225226

226-
@classmethod
227-
defnew_manager(cls,figure,num):
228-
# docstring inherited
229-
with_restore_foreground_window_at_end():
230-
ifcbook._get_running_interactive_framework()isNone:
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-
exceptExceptionasexc:
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-
ifmpl.is_interactive():
259-
manager.show()
260-
canvas.draw_idle()
261-
returnmanager
262-
263227
defresize(self,event):
264228
width,height=event.width,event.height
265229

@@ -468,6 +432,44 @@ def __init__(self, canvas, num, window):
468432

469433
self._shown=False
470434

435+
@classmethod
436+
defcreate_with_canvas(cls,canvas_class,figure,num):
437+
438+
with_restore_foreground_window_at_end():
439+
ifcbook._get_running_interactive_framework()isNone:
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+
exceptExceptionasexc:
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+
ifmpl.is_interactive():
468+
manager.show()
469+
canvas.draw_idle()
470+
returnmanager
471+
472+
471473
def_update_window_dpi(self,*args):
472474
newdpi=self._window_dpi.get()
473475
self.window.call('tk','scaling',newdpi/72)

‎lib/matplotlib/backends/backend_gtk3.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _mpl_to_gtk_cursor(mpl_cursor):
7171
classFigureCanvasGTK3(Gtk.DrawingArea,FigureCanvasBase):
7272
required_interactive_framework="gtk3"
7373
_timer_cls=TimerGTK3
74+
manager_class=FigureManagerGTK3
7475
# Setting this as a static constant prevents
7576
# this resulting expression from leaking
7677
event_mask= (Gdk.EventMask.BUTTON_PRESS_MASK
@@ -115,11 +116,6 @@ def __init__(self, figure=None):
115116
style_ctx.add_provider(css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
116117
style_ctx.add_class("matplotlib-canvas")
117118

118-
@classmethod
119-
defnew_manager(cls,figure,num):
120-
# docstring inherited
121-
returnFigureManagerGTK3(cls(figure),num)
122-
123119
defdestroy(self):
124120
self.close_event()
125121

‎lib/matplotlib/backends/backend_gtk4.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class FigureCanvasGTK4(Gtk.DrawingArea, FigureCanvasBase):
3333
required_interactive_framework="gtk4"
3434
supports_blit=False
3535
_timer_cls=TimerGTK4
36+
manager_class=FigureManagerGTK4
3637
_context_is_scaled=False
3738

3839
def__init__(self,figure=None):
@@ -78,11 +79,6 @@ def __init__(self, figure=None):
7879
style_ctx.add_provider(css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
7980
style_ctx.add_class("matplotlib-canvas")
8081

81-
@classmethod
82-
defnew_manager(cls,figure,num):
83-
# docstring inherited
84-
returnFigureManagerGTK4(cls(figure),num)
85-
8682
defpick(self,mouseevent):
8783
# GtkWidget defines pick in GTK4, so we need to override here to work
8884
# with the base implementation we want.

‎lib/matplotlib/backends/backend_macosx.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class FigureCanvasMac(_macosx.FigureCanvas, FigureCanvasAgg):
2525

2626
required_interactive_framework="macosx"
2727
_timer_cls=TimerMac
28+
manager_class=FigureManagerMac
2829

2930
def__init__(self,figure):
3031
FigureCanvasBase.__init__(self,figure)
@@ -33,11 +34,6 @@ def __init__(self, figure):
3334
self._draw_pending=False
3435
self._is_drawing=False
3536

36-
@classmethod
37-
defnew_manager(cls,figure,num):
38-
# docstring inherited
39-
returnFigureManagerMac(cls(figure),num)
40-
4137
defset_cursor(self,cursor):
4238
# docstring inherited
4339
_macosx.set_cursor(cursor)

‎lib/matplotlib/backends/backend_nbagg.py‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ def __init__(self, canvas, num):
7878
self._shown=False
7979
super().__init__(canvas,num)
8080

81+
defcreate_with_canvas(self,canvas_class,figure,num):
82+
canvas=canvas_class(figure)
83+
manager=FigureManagerNbAgg(canvas,num)
84+
ifis_interactive():
85+
manager.show()
86+
figure.canvas.draw_idle()
87+
88+
defdestroy(event):
89+
canvas.mpl_disconnect(cid)
90+
Gcf.destroy(manager)
91+
92+
cid=canvas.mpl_connect('close_event',destroy)
93+
returnmanager
94+
8195
defdisplay_js(self):
8296
# XXX How to do this just once? It has to deal with multiple
8397
# browser instances using the same kernel (require.js - but the
@@ -143,20 +157,7 @@ def remove_comm(self, comm_id):
143157

144158

145159
classFigureCanvasNbAgg(FigureCanvasWebAggCore):
146-
@classmethod
147-
defnew_manager(cls,figure,num):
148-
canvas=cls(figure)
149-
manager=FigureManagerNbAgg(canvas,num)
150-
ifis_interactive():
151-
manager.show()
152-
figure.canvas.draw_idle()
153-
154-
defdestroy(event):
155-
canvas.mpl_disconnect(cid)
156-
Gcf.destroy(manager)
157-
158-
cid=canvas.mpl_connect('close_event',destroy)
159-
returnmanager
160+
manager_class=FigureManagerNbAgg
160161

161162

162163
classCommSocket:

‎lib/matplotlib/backends/backend_qt.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def _timer_stop(self):
232232
classFigureCanvasQT(QtWidgets.QWidget,FigureCanvasBase):
233233
required_interactive_framework="qt"
234234
_timer_cls=TimerQT
235+
manager_class=FigureManagerQT
235236

236237
buttond= {
237238
getattr(_enum("QtCore.Qt.MouseButton"),k):vfork,vin [
@@ -260,11 +261,6 @@ def __init__(self, figure=None):
260261
palette=QtGui.QPalette(QtGui.QColor("white"))
261262
self.setPalette(palette)
262263

263-
@classmethod
264-
defnew_manager(cls,figure,num):
265-
# docstring inherited
266-
returnFigureManagerQT(cls(figure),num)
267-
268264
def_update_pixel_ratio(self):
269265
ifself._set_device_pixel_ratio(_devicePixelRatioF(self)):
270266
# The easiest way to resize the canvas is to emit a resizeEvent

‎lib/matplotlib/backends/backend_webagg.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ def run(self):
4949

5050

5151
classFigureCanvasWebAgg(core.FigureCanvasWebAggCore):
52-
@classmethod
53-
defnew_manager(cls,figure,num):
54-
# docstring inherited
55-
returncore.FigureManagerWebAgg(cls(figure),num)
52+
manager_class=core.FigureManagerWebAgg
5653

5754

5855
classFigureManagerWebAgg(core.FigureManagerWebAgg):

‎lib/matplotlib/backends/backend_wx.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel):
427427

428428
required_interactive_framework="wx"
429429
_timer_cls=TimerWx
430+
manager_class=FigureManagerWx
430431

431432
keyvald= {
432433
wx.WXK_CONTROL:'control',
@@ -537,17 +538,6 @@ def __init__(self, parent, id, figure=None):
537538
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)# Reduce flicker.
538539
self.SetBackgroundColour(wx.WHITE)
539540

540-
@classmethod
541-
defnew_manager(cls,figure,num):
542-
# docstring inherited
543-
wxapp=wx.GetApp()or_create_wxapp()
544-
frame=FigureFrameWx(num,figure,canvas_class=cls)
545-
figmgr=frame.get_figure_manager()
546-
ifmpl.is_interactive():
547-
figmgr.frame.Show()
548-
figure.canvas.draw_idle()
549-
returnfigmgr
550-
551541
defCopy_to_Clipboard(self,event=None):
552542
"""Copy bitmap of canvas to system clipboard."""
553543
bmp_obj=wx.BitmapDataObject()
@@ -990,6 +980,16 @@ def __init__(self, canvas, num, frame):
990980
self.frame=self.window=frame
991981
super().__init__(canvas,num)
992982

983+
@classmethod
984+
defcreate_with_canvas(cls,canvas_class,figure,num):
985+
wxapp=wx.GetApp()or_create_wxapp()
986+
frame=FigureFrameWx(num,figure,canvas_class=canvas_class)
987+
figmgr=frame.get_figure_manager()
988+
ifmpl.is_interactive():
989+
figmgr.frame.Show()
990+
figure.canvas.draw_idle()
991+
returnfigmgr
992+
993993
defshow(self):
994994
# docstring inherited
995995
self.frame.Show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp