@@ -124,121 +124,6 @@ def get_registered_canvas_class(format):
124124 return backend_class
125125
126126
127- class _Backend (object ):
128- # A backend can be defined by using the following pattern:
129- #
130- # @_Backend.export
131- # class FooBackend(_Backend):
132- # # override the attributes and methods documented below.
133-
134- # The following attributes and methods must be overridden by subclasses.
135-
136- # The `FigureCanvas` and `FigureManager` classes must be defined.
137- FigureCanvas = None
138- FigureManager = None
139-
140- # The following methods must be left as None for non-interactive backends.
141- # For interactive backends, `trigger_manager_draw` should be a function
142- # taking a manager as argument and triggering a canvas draw, and `mainloop`
143- # should be a function taking no argument and starting the backend main
144- # loop.
145- trigger_manager_draw = None
146- mainloop = None
147-
148- # The following methods will be automatically defined and exported, but
149- # can be overridden.
150-
151- @classmethod
152- def new_figure_manager (cls , num , * args , ** kwargs ):
153- """Create a new figure manager instance.
154- """
155- # This import needs to happen here due to circular imports.
156- from matplotlib .figure import Figure
157- fig_cls = kwargs .pop ('FigureClass' , Figure )
158- fig = fig_cls (* args , ** kwargs )
159- return cls .new_figure_manager_given_figure (num , fig )
160-
161- @classmethod
162- def new_figure_manager_given_figure (cls , num , figure ):
163- """Create a new figure manager instance for the given figure.
164- """
165- canvas = cls .FigureCanvas (figure )
166- manager = cls .FigureManager (canvas , num )
167- return manager
168-
169- @classmethod
170- def draw_if_interactive (cls ):
171- if cls .trigger_manager_draw is not None and is_interactive ():
172- manager = Gcf .get_active ()
173- if manager :
174- cls .trigger_manager_draw (manager )
175-
176- @classmethod
177- def show (cls , block = None ):
178- """Show all figures.
179-
180- `show` blocks by calling `mainloop` if *block* is ``True``, or if it
181- is ``None`` and we are neither in IPython's ``%pylab`` mode, nor in
182- `interactive` mode.
183- """
184- managers = Gcf .get_all_fig_managers ()
185- if not managers :
186- return
187- for manager in managers :
188- # Emits a warning if the backend is non-interactive.
189- manager .canvas .figure .show ()
190- if cls .mainloop is None :
191- return
192- if block is None :
193- # Hack: Are we in IPython's pylab mode?
194- from matplotlib import pyplot
195- try :
196- # IPython versions >= 0.10 tack the _needmain attribute onto
197- # pyplot.show, and always set it to False, when in %pylab mode.
198- ipython_pylab = not pyplot .show ._needmain
199- except AttributeError :
200- ipython_pylab = False
201- block = not ipython_pylab and not is_interactive ()
202- # TODO: The above is a hack to get the WebAgg backend working with
203- # ipython's `%pylab` mode until proper integration is implemented.
204- if get_backend () == "WebAgg" :
205- block = True
206- if block :
207- cls .mainloop ()
208-
209- # This method is the one actually exporting the required methods.
210-
211- @staticmethod
212- def export (cls ):
213- for name in ["FigureCanvas" ,
214- "FigureManager" ,
215- "new_figure_manager" ,
216- "new_figure_manager_given_figure" ,
217- "draw_if_interactive" ,
218- "show" ]:
219- setattr (sys .modules [cls .__module__ ], name , getattr (cls , name ))
220-
221- # For back-compatibility, generate a shim `Show` class.
222-
223- class Show (ShowBase ):
224- def mainloop (self ):
225- return cls .mainloop ()
226-
227- setattr (sys .modules [cls .__module__ ], "Show" , Show )
228- return cls
229-
230-
231- class ShowBase (_Backend ):
232- """
233- Simple base class to generate a show() callable in backends.
234-
235- Subclass must override mainloop() method.
236- """
237-
238- def __call__ (self , block = None ):
239- return self .show (block = block )
240-
241-
242127class RendererBase (object ):
243128 """An abstract base class to handle drawing/rendering operations.
244129
@@ -3328,3 +3213,122 @@ def set_message(self, s):
33283213 Message text
33293214 """
33303215 pass
3216+
3217+
3218+ class _Backend (object ):
3219+ # A backend can be defined by using the following pattern:
3220+ #
3221+ # @_Backend.export
3222+ # class FooBackend(_Backend):
3223+ # # override the attributes and methods documented below.
3224+
3225+ # `backend_version` may be overridden by the subclass.
3226+ backend_version = "unknown"
3227+
3228+ # The `FigureCanvas` class must be defined.
3229+ FigureCanvas = None
3230+
3231+ # For interactive backends, the `FigureManager` class must be overridden.
3232+ FigureManager = FigureManagerBase
3233+
3234+ # The following methods must be left as None for non-interactive backends.
3235+ # For interactive backends, `trigger_manager_draw` should be a function
3236+ # taking a manager as argument and triggering a canvas draw, and `mainloop`
3237+ # should be a function taking no argument and starting the backend main
3238+ # loop.
3239+ trigger_manager_draw = None
3240+ mainloop = None
3241+
3242+ # The following methods will be automatically defined and exported, but
3243+ # can be overridden.
3244+
3245+ @classmethod
3246+ def new_figure_manager (cls , num , * args , ** kwargs ):
3247+ """Create a new figure manager instance.
3248+ """
3249+ # This import needs to happen here due to circular imports.
3250+ from matplotlib .figure import Figure
3251+ fig_cls = kwargs .pop ('FigureClass' , Figure )
3252+ fig = fig_cls (* args , ** kwargs )
3253+ return cls .new_figure_manager_given_figure (num , fig )
3254+
3255+ @classmethod
3256+ def new_figure_manager_given_figure (cls , num , figure ):
3257+ """Create a new figure manager instance for the given figure.
3258+ """
3259+ canvas = cls .FigureCanvas (figure )
3260+ manager = cls .FigureManager (canvas , num )
3261+ return manager
3262+
3263+ @classmethod
3264+ def draw_if_interactive (cls ):
3265+ if cls .trigger_manager_draw is not None and is_interactive ():
3266+ manager = Gcf .get_active ()
3267+ if manager :
3268+ cls .trigger_manager_draw (manager )
3269+
3270+ @classmethod
3271+ def show (cls , block = None ):
3272+ """Show all figures.
3273+
3274+ `show` blocks by calling `mainloop` if *block* is ``True``, or if it
3275+ is ``None`` and we are neither in IPython's ``%pylab`` mode, nor in
3276+ `interactive` mode.
3277+ """
3278+ managers = Gcf .get_all_fig_managers ()
3279+ if not managers :
3280+ return
3281+ for manager in managers :
3282+ # Emits a warning if the backend is non-interactive.
3283+ manager .canvas .figure .show ()
3284+ if cls .mainloop is None :
3285+ return
3286+ if block is None :
3287+ # Hack: Are we in IPython's pylab mode?
3288+ from matplotlib import pyplot
3289+ try :
3290+ # IPython versions >= 0.10 tack the _needmain attribute onto
3291+ # pyplot.show, and always set it to False, when in %pylab mode.
3292+ ipython_pylab = not pyplot .show ._needmain
3293+ except AttributeError :
3294+ ipython_pylab = False
3295+ block = not ipython_pylab and not is_interactive ()
3296+ # TODO: The above is a hack to get the WebAgg backend working with
3297+ # ipython's `%pylab` mode until proper integration is implemented.
3298+ if get_backend () == "WebAgg" :
3299+ block = True
3300+ if block :
3301+ cls .mainloop ()
3302+
3303+ # This method is the one actually exporting the required methods.
3304+
3305+ @staticmethod
3306+ def export (cls ):
3307+ for name in ["backend_version" ,
3308+ "FigureCanvas" ,
3309+ "FigureManager" ,
3310+ "new_figure_manager" ,
3311+ "new_figure_manager_given_figure" ,
3312+ "draw_if_interactive" ,
3313+ "show" ]:
3314+ setattr (sys .modules [cls .__module__ ], name , getattr (cls , name ))
3315+
3316+ # For back-compatibility, generate a shim `Show` class.
3317+
3318+ class Show (ShowBase ):
3319+ def mainloop (self ):
3320+ return cls .mainloop ()
3321+
3322+ setattr (sys .modules [cls .__module__ ], "Show" , Show )
3323+ return cls
3324+
3325+
3326+ class ShowBase (_Backend ):
3327+ """
3328+ Simple base class to generate a show() callable in backends.
3329+
3330+ Subclass must override mainloop() method.
3331+ """
3332+
3333+ def __call__ (self , block = None ):
3334+ return self .show (block = block )
0 commit comments