|
16 | 16 | Copy this to backend_xxx.py and replace all instances of 'template' |
17 | 17 | with 'xxx'. Then implement the class methods and functions below, and |
18 | 18 | add 'xxx' to the switchyard in matplotlib/backends/__init__.py and |
19 | | -'xxx' to the backends list in the validate_backend methon in |
| 19 | +'xxx' to the backends list in the validate_backend method in |
20 | 20 | matplotlib/__init__.py and you're off. You can use your backend with:: |
21 | 21 |
|
22 | 22 | import matplotlib |
|
25 | 25 | plot([1,2,3]) |
26 | 26 | show() |
27 | 27 |
|
28 | | -matplotlib also supports external backends, so you can place you can |
29 | | -use any module in your PYTHONPATH with the syntax:: |
| 28 | +matplotlib also supports external backends, by placing |
| 29 | +any module in your PYTHONPATH and then using the syntax:: |
30 | 30 |
|
31 | 31 | import matplotlib |
32 | 32 | matplotlib.use('module://my_backend') |
33 | 33 |
|
34 | 34 | where my_backend.py is your module name. This syntax is also |
35 | | -recognized in the rc file and in the -d argument in pylab, e.g.,:: |
| 35 | +recognized in the rc file and also with the -d argument in pylab, e.g.,:: |
36 | 36 |
|
37 | 37 | python simple_plot.py -dmodule://my_backend |
38 | 38 |
|
|
48 | 48 |
|
49 | 49 | matplotlib/backends/backend_your_backend.py |
50 | 50 | matplotlib/backend_bases.py |
| 51 | + matplotlib/backend_managers.py |
51 | 52 | matplotlib/backends/__init__.py |
52 | 53 | matplotlib/__init__.py |
53 | 54 | matplotlib/_pylab_helpers.py |
|
68 | 69 | import six |
69 | 70 |
|
70 | 71 | import matplotlib |
71 | | -from matplotlib._pylab_helpers import Gcf |
72 | 72 | from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\ |
73 | | - FigureManagerBase, FigureCanvasBase |
| 73 | + WindowBase, FigureCanvasBase, MainLoopBase, ToolbarBase |
| 74 | +from matplotlib import backend_tools |
74 | 75 | from matplotlib.figure import Figure |
75 | 76 | from matplotlib.transforms import Bbox |
76 | 77 |
|
@@ -178,41 +179,6 @@ def draw_if_interactive(): |
178 | 179 | """ |
179 | 180 | pass |
180 | 181 |
|
181 | | -def show(): |
182 | | - """ |
183 | | - For image backends - is not required |
184 | | - For GUI backends - show() is usually the last line of a pylab script and |
185 | | - tells the backend that it is time to draw. In interactive mode, this may |
186 | | - be a do nothing func. See the GTK backend for an example of how to handle |
187 | | - interactive versus batch mode |
188 | | - """ |
189 | | - for manager in Gcf.get_all_fig_managers(): |
190 | | - # do something to display the GUI |
191 | | - pass |
192 | | - |
193 | | - |
194 | | -def new_figure_manager(num, *args, **kwargs): |
195 | | - """ |
196 | | - Create a new figure manager instance |
197 | | - """ |
198 | | - # if a main-level app must be created, this (and |
199 | | - # new_figure_manager_given_figure) is the usual place to |
200 | | - # do it -- see backend_wx, backend_wxagg and backend_tkagg for |
201 | | - # examples. Not all GUIs require explicit instantiation of a |
202 | | - # main-level app (egg backend_gtk, backend_gtkagg) for pylab |
203 | | - FigureClass = kwargs.pop('FigureClass', Figure) |
204 | | - thisFig = FigureClass(*args, **kwargs) |
205 | | - return new_figure_manager_given_figure(num, thisFig) |
206 | | - |
207 | | - |
208 | | -def new_figure_manager_given_figure(num, figure): |
209 | | - """ |
210 | | - Create a new figure manager instance for the given figure. |
211 | | - """ |
212 | | - canvas = FigureCanvasTemplate(figure) |
213 | | - manager = FigureManagerTemplate(canvas, num) |
214 | | - return manager |
215 | | - |
216 | 182 |
|
217 | 183 | class FigureCanvasTemplate(FigureCanvasBase): |
218 | 184 | """ |
@@ -256,19 +222,29 @@ def print_foo(self, filename, *args, **kwargs): |
256 | 222 | def get_default_filetype(self): |
257 | 223 | return 'foo' |
258 | 224 |
|
259 | | -class FigureManagerTemplate(FigureManagerBase): |
260 | | - """ |
261 | | - Wrap everything up into a window for the pylab interface |
262 | 225 |
|
263 | | - For non interactive backends, the base class does all the work |
264 | | - """ |
| 226 | +class WindowTemplate(WindowBase): |
| 227 | + def show(self): |
| 228 | + pass |
| 229 | + |
| 230 | + |
| 231 | +class RubberbandTemplate(backend_tools.RubberbandBase): |
| 232 | + pass |
| 233 | + |
| 234 | + |
| 235 | +class SetCursorTemplate(backend_tools.SetCursorBase): |
265 | 236 | pass |
266 | 237 |
|
267 | 238 | ######################################################################## |
268 | 239 | # |
269 | | -# Now just provide the standard names that backend.__init__ is expecting |
| 240 | +# Now just provide the standard names that backend.__init__ expects |
270 | 241 | # |
271 | 242 | ######################################################################## |
272 | 243 |
|
273 | 244 | FigureCanvas = FigureCanvasTemplate |
274 | | -FigureManager = FigureManagerTemplate |
| 245 | + |
| 246 | +# Needed for a GUI |
| 247 | +MainLoop = MainLoopBase |
| 248 | +Window = WindowTemplate |
| 249 | +ToolRubberband = RubberbandTemplate |
| 250 | +ToolSetCursor = SetCursorTemplate |
0 commit comments