Ñò 8”tJc @ sñdZddklZddkZddklZddklZlZl Z l Z ddk l Z ddk lZdefd „ƒYZd efd „ƒYZd „Zd „Zd„Zde fd„ƒYZde fd„ƒYZeZdS(s© This is a fully functional do nothing backend to provide a template to backend writers. It is fully functional in that you can select it as a backend with import matplotlib matplotlib.use('Template') and your matplotlib scripts will (should!) run without error, though no output is produced. This provides a nice starting point for backend writers because you can selectively implement methods (draw_rectangle, draw_lines, etc...) and slowly see your figure come to life w/o having to have a full blown implementation before getting any results. Copy this to backend_xxx.py and replace all instances of 'template' with 'xxx'. Then implement the class methods and functions below, and add 'xxx' to the switchyard in matplotlib/backends/__init__.py and 'xxx' to the backends list in the validate_backend methon in matplotlib/__init__.py and you're off. You can use your backend with:: import matplotlib matplotlib.use('xxx') from pylab import * plot([1,2,3]) show() matplotlib also supports external backends, so you can place you can use any module in your PYTHONPATH with the syntax:: import matplotlib matplotlib.use('module://my_backend') where my_backend.py is your module name. Thus syntax is also recognized in the rc file and in the -d argument in pylab, eg:: python simple_plot.py -dmodule://my_backend The files that are most relevant to backend_writers are matplotlib/backends/backend_your_backend.py matplotlib/backend_bases.py matplotlib/backends/__init__.py matplotlib/__init__.py matplotlib/_pylab_helpers.py Naming Conventions * classes Upper or MixedUpperCase * varables lower or lowerUpper * functions lower or underscore_separated iÿÿÿÿ(tdivisionN(tGcf(t RendererBasetGraphicsContextBasetFigureManagerBasetFigureCanvasBase(tFigure(tBboxtRendererTemplatecB skeZdZd„Zd d„Zd d d„Zed„Zd„Z d„Z d„Z d„Z d „Z RS( sö The renderer handles drawing/rendering operations. This is a minimal do-nothing class that can be used to get started when writing a new backend. Refer to backend_bases.RendererBase for documentation of the classes methods. cC s ||_dS(N(tdpi(tselfR ((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyt__init__KscC sdS(N((R tgctpatht transformtrgbFace((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyt draw_pathNscC sdS(N((R txtytimtbboxtclippathtclippath_trans((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyt draw_imageiscC sdS(N((R R RRtstproptangletismath((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyt draw_textlscC stS(N(tTrue(R ((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytflipyoscC sdS(Nid(idid((R ((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytget_canvas_width_heightrscC sdS(Ni(iii((R RRR((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytget_text_width_height_descentuscC stƒS(N(tGraphicsContextTemplate(R ((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytnew_gcxscC s|S(N((R tpoints((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytpoints_to_pixels{sN(t__name__t __module__t__doc__R tNoneRRtFalseRRRR R"R$(((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyRCs       R!cB seZdZRS(sâ The graphics context provides the color, line styles, etc... See the gtk and postscript backends for examples of mapping the graphics context attributes (cap styles, join styles, line widths, colors) to a particular backend. In GTK this is done by wrapping a gtk.gdk.GC object and forwarding the appropriate calls to it using a dictionary mapping styles to gdk constants. In Postscript, all the work is done by the renderer, mapping line styles to postscript calls. If it's more appropriate to do the mapping at the renderer level (as in the postscript backend), you don't need to override any of the GC methods. If it's more appropriate to wrap an instance (as in the GTK backend) and do the mapping here, you'll need to override several of the setter methods. The base GraphicsContext stores colors as a RGB tuple on the unit interval, eg, (0.5, 0.0, 1.0). You may need to map this to colors appropriate for your backend. (R%R&R'(((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyR!„scC sdS(s— For image backends - is not required For GUI backends - this should be overriden if drawing should be done in interactive python mode N((((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytdraw_if_interactive£scC sxtiƒD]}q WdS(s: For image backends - is not required For GUI backends - show() is usually the last line of a pylab script and tells the backend that it is time to draw. In interactive mode, this may be a do nothing func. See the GTK backend for an example of how to handle interactive versus batch mode N(Rtget_all_fig_managers(tmanager((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytshow«s cO s@|idtƒ}|||Ž}t|ƒ}t||ƒ}|S(s. Create a new figure manager instance t FigureClass(tpopRtFigureCanvasTemplatetFigureManagerTemplate(tnumtargstkwargsR.tthisFigtcanvasR,((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pytnew_figure_manager¸s  R0cB sBeZdZd„ZeiiƒZded(((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyR0Çs    R1cB seZdZRS(s† Wrap everything up into a window for the pylab interface For non interactive backends, the base class does all the work (R%R&R'(((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyR1ñs(R't __future__Rt matplotlibtmatplotlib._pylab_helpersRtmatplotlib.backend_basesRRRRtmatplotlib.figureRtmatplotlib.transformsRRR!R*R-R7R0R1t FigureManager(((sJ/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_template.pyt7s "A  *