
 m[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z d d l	 m
 Z
 m Z m Z m Z d d l m Z d e f d     YZ d	 e f d
     YZ d   Z d d  Z d   Z d   Z d e
 f d     YZ d e f d     YZ e Z e Z d S(   u  
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.  This syntax is also
recognized in the rc file and in the -d argument in pylab, e.g.,::

  python simple_plot.py -dmodule://my_backend

If your backend implements support for saving figures (i.e. has a print_xyz()
method) you can register it as the default handler for a given file type

  from matplotlib.backend_bases import register_backend
  register_backend('xyz', 'my_backend', 'XYZ File Format')
  ...
  plt.savefig("figure.xyz")

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

  * variables lower or lowerUpper

  * functions lower or underscore_separated

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   Gcf(   t   FigureCanvasBaset   FigureManagerBaset   GraphicsContextBaset   RendererBase(   t   Figuret   RendererTemplatec           B` sh   e  Z d  Z d   Z d
 d  Z d   Z e d
 d  Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(   u   
    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.
    c         C` s   | |  _  d  S(   N(   t   dpi(   t   selfR   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   __init__T   s    c         C` s   d  S(   N(    (   R   t   gct   patht	   transformt   rgbFace(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt	   draw_pathW   s    c         C` s   d  S(   N(    (   R   R   t   xt   yt   im(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt
   draw_imager   s    c	   	      C` s   d  S(   N(    (	   R   R   R   R   t   st   propt   anglet   ismatht   mtext(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt	   draw_textu   s    c         C` s   t  S(   N(   t   True(   R   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   flipyx   s    c         C` s   d S(   Nid   (   id   id   (    (   R   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   get_canvas_width_height{   s    c         C` s   d S(   Ni   (   i   i   i   (    (   R   R   R   R   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   get_text_width_height_descent~   s    c         C` s   t    S(   N(   t   GraphicsContextTemplate(   R   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   new_gc   s    c         C` s   | S(   N(    (   R   t   points(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   points_to_pixels   s    N(   t   __name__t
   __module__t   __doc__R   t   NoneR   R   t   FalseR   R   R   R    R"   R$   (    (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyR
   L   s   						R!   c           B` s   e  Z d  Z RS(   u  
    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, e.g., (0.5, 0.0, 1.0). You may need to map this to colors
    appropriate for your backend.
    (   R%   R&   R'   (    (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyR!      s   c           C` s   d S(   u   
    For image backends - is not required
    For GUI backends - this should be overridden if drawing should be done in
    interactive python mode
    N(    (    (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   draw_if_interactive   s    c         C` s   x t  j   D] } q Wd S(   u:  
    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(   R   t   get_all_fig_managers(   t   blockt   manager(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   show   s    c         O` s.   | j  d t  } | | |   } t |  |  S(   u.   
    Create a new figure manager instance
    u   FigureClass(   t   popR	   t   new_figure_manager_given_figure(   t   numt   argst   kwargst   FigureClasst   thisFig(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   new_figure_manager   s    
c         C` s   t  |  } t | |   } | S(   uD   
    Create a new figure manager instance for the given figure.
    (   t   FigureCanvasTemplatet   FigureManagerTemplate(   R1   t   figuret   canvasR-   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyR0      s    R7   c           B` sB   e  Z d  Z d   Z e j j   Z d e d <d   Z d   Z RS(   u/  
    The canvas the figure renders into.  Calls the draw and print fig
    methods, creates the renderers, etc...

    Note GUI templates will want to connect events for button presses,
    mouse movements and key presses to functions that call the base
    class methods button_press_event, button_release_event,
    motion_notify_event, key_press_event, and key_release_event.  See,
    e.g., backend_gtk.py, backend_wx.py and backend_tkagg.py

    Attributes
    ----------
    figure : `matplotlib.figure.Figure`
        A high-level Figure instance

    c         C` s&   t  |  j j  } |  j j |  d S(   u4   
        Draw the figure using the renderer
        N(   R
   R9   R   t   draw(   R   t   renderer(    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyR;      s    u   My magic Foo formatu   fooc         O` s   d S(   u   
        Write out format foo.  The dpi, facecolor and edgecolor are restored
        to their original values after this call, so you don't need to
        save and restore them.
        N(    (   R   t   filenameR2   R3   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt	   print_foo   s    c         C` s   d S(   Nu   foo(    (   R   (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   get_default_filetype  s    (	   R%   R&   R'   R;   R   t	   filetypest   copyR>   R?   (    (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyR7      s   	
	R8   c           B` s   e  Z d  Z RS(   u   
    Wrap everything up into a window for the pylab interface

    For non interactive backends, the base class does all the work
    (   R%   R&   R'   (    (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyR8     s   (   R'   t
   __future__R    R   R   R   t   sixt   matplotlib._pylab_helpersR   t   matplotlib.backend_basesR   R   R   R   t   matplotlib.figureR	   R
   R!   R*   R(   R.   R6   R0   R7   R8   t   FigureCanvast   FigureManager(    (    (    sC   lib/python2.7/site-packages/matplotlib/backends/backend_template.pyt   <module>?   s   ""A			
-