Revision: 5505
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5505&view=rev
Author:   mdboom
Date:     2008-06-13 07:40:39 -0700 (Fri, 13 Jun 2008)

Log Message:
-----------
Add "include-source" option.

Modified Paths:
--------------
    trunk/matplotlib/doc/sphinxext/plot_directive.py
    trunk/matplotlib/doc/users/annotations.rst
    trunk/matplotlib/doc/users/artists.rst
    trunk/matplotlib/doc/users/mathtext.rst
    trunk/matplotlib/doc/users/pyplot_tutorial.rst
    trunk/matplotlib/doc/users/text_intro.rst
    trunk/matplotlib/doc/users/text_props.rst

Modified: trunk/matplotlib/doc/sphinxext/plot_directive.py
===================================================================
--- trunk/matplotlib/doc/sphinxext/plot_directive.py    2008-06-13 14:24:40 UTC 
(rev 5504)
+++ trunk/matplotlib/doc/sphinxext/plot_directive.py    2008-06-13 14:40:39 UTC 
(rev 5505)
@@ -3,10 +3,14 @@
 Given a path to a .py file, it includes the source code inline, then:
 
 - On HTML, will include a .png with a link to a high-res .png.
-  Underneath that, a [source] link will go to a plain text .py of
-  the source.
 
 - On LaTeX, will include a .pdf
+
+This directive supports all of the options of the `image` directive,
+except for `target` (since plot will add its own target).
+
+Additionally, if the :include-source: option is provided, the literal
+source will be included inline, as well as a link to the source.
 """
 
 from docutils.parsers.rst import directives
@@ -25,9 +29,23 @@
            'width': directives.length_or_percentage_or_unitless,
            'scale': directives.nonnegative_int,
            'align': align,
-           'class': directives.class_option}
+           'class': directives.class_option,
+           'include-source': directives.flag }
 
-template = """
+template_no_source = """
+.. htmlonly::
+
+   .. image:: %(reference)s.png
+      :target: %(reference)s.hires.png
+%(options)s
+
+.. latexonly::
+   .. image:: %(reference)s.pdf
+%(options)s
+
+"""
+
+template_source = """
 .. literalinclude:: %(reference)s.py
 
 .. htmlonly::
@@ -36,7 +54,7 @@
       :target: %(reference)s.hires.png
 %(options)s
 
-   `[original %(basename)s.py] <%(reference)s.py>`_
+   `[%(basename)s.py] <%(reference)s.py>`_
 
 .. latexonly::
    .. image:: %(reference)s.pdf
@@ -46,8 +64,16 @@
 
 def run(arguments, options, state_machine, lineno):
     reference = directives.uri(arguments[0])
-    if reference.endswith('.py'):
-        reference = reference[:-3]
+    print reference
+    for ext in ('.py', '.png', '.pdf'):
+        if reference.endswith(ext):
+            reference = reference[:-len(ext)]
+            break
+    if options.has_key('include-source'):
+        template = template_source
+        del options['include-source']
+    else:
+        template = template_no_source
     options = ['      :%s: %s' % (key, val) for key, val in
                options.items()]
     options = "\n".join(options)

Modified: trunk/matplotlib/doc/users/annotations.rst
===================================================================
--- trunk/matplotlib/doc/users/annotations.rst  2008-06-13 14:24:40 UTC (rev 
5504)
+++ trunk/matplotlib/doc/users/annotations.rst  2008-06-13 14:40:39 UTC (rev 
5505)
@@ -13,6 +13,7 @@
 arguments are ``(x,y)`` tuples.
 
 .. plot:: figures/annotation_basic.py
+   :include-source:
    :scale: 75
 
 In this example, both the ``xy`` (arrow tip) and ``xytext`` locations
@@ -73,6 +74,7 @@
 
 .. plot:: figures/annotation_polar.py
    :scale: 75
+   :include-source:
 
 See the `annotations demo
 <http://matplotlib.sf.net/examples/pylab_examples/annotation_demo.py>`_ for 
more

Modified: trunk/matplotlib/doc/users/artists.rst
===================================================================
--- trunk/matplotlib/doc/users/artists.rst      2008-06-13 14:24:40 UTC (rev 
5504)
+++ trunk/matplotlib/doc/users/artists.rst      2008-06-13 14:40:39 UTC (rev 
5505)
@@ -135,7 +135,7 @@
 
 Try creating the figure below.
 
-.. image:: figures/fig_axes_labels_simple.png
+.. plot:: figures/fig_axes_labels_simple
    :scale: 75
 
 .. _customizing-artists:
@@ -326,7 +326,7 @@
 
     In [195]: fig.canvas.draw()
 
-.. image:: figures/fig_x.png
+.. plot:: figures/fig_x
    :scale: 75
 
 
@@ -606,6 +606,7 @@
 
 .. plot:: figures/fig_axes_customize_simple.py
    :scale: 75
+   :include-source:
 
 
 .. _tick-container:
@@ -643,3 +644,4 @@
 
 .. plot:: figures/dollar_ticks.py
    :scale: 75
+   :include-source:

Modified: trunk/matplotlib/doc/users/mathtext.rst
===================================================================
--- trunk/matplotlib/doc/users/mathtext.rst     2008-06-13 14:24:40 UTC (rev 
5504)
+++ trunk/matplotlib/doc/users/mathtext.rst     2008-06-13 14:40:39 UTC (rev 
5505)
@@ -273,6 +273,7 @@
 
 .. plot:: figures/pyplot_mathtext.py
    :scale: 75
+   :include-source:
 
 
 

Modified: trunk/matplotlib/doc/users/pyplot_tutorial.rst
===================================================================
--- trunk/matplotlib/doc/users/pyplot_tutorial.rst      2008-06-13 14:24:40 UTC 
(rev 5504)
+++ trunk/matplotlib/doc/users/pyplot_tutorial.rst      2008-06-13 14:40:39 UTC 
(rev 5505)
@@ -14,6 +14,7 @@
 
 .. plot:: figures/pyplot_simple
    :scale: 75
+   :include-source:
 
 You may be wondering why the x-axis ranges from 0-3 and the y-axis
 from 1-4.  If you provide a single list or array to the
@@ -38,6 +39,7 @@
 
 .. plot:: figures/pyplot_formatstr.py
    :scale: 75
+   :include-source:
 
 See the :func:`~matplotlib.pyplot.plot` documentation for a complete
 list of line styles and format strings.  The
@@ -54,6 +56,7 @@
 
 .. plot:: figures/pyplot_three.py
    :scale: 75
+   :include-source:
 
 .. _controlling-line-properties:
 
@@ -159,6 +162,7 @@
 
 .. plot:: figures/pyplot_two_subplots.py
    :scale: 75
+   :include-source:
 
 The :func:`~matplotlib.pyplot.figure` command here is optional because
 ``figure(1)`` will be created by default, just as a ``subplot(111)``
@@ -218,8 +222,8 @@
 
 .. plot:: figures/pyplot_text.py
    :scale: 75
+   :include-source:
 
-
 All of the :func:`~matplotlib.pyplot.text` commands return an
 :class:`matplotlib.text.Text` instance.  Just as with with lines
 above, you can customize the properties by passing keyword arguments
@@ -264,6 +268,7 @@
 
 .. plot:: figures/pyplot_annotate.py
    :scale: 75
+   :include-source:
 
 In this basic example, both the ``xy`` (arrow tip) and ``xytext``
 locations (text location) are in data coordinates.  There are a

Modified: trunk/matplotlib/doc/users/text_intro.rst
===================================================================
--- trunk/matplotlib/doc/users/text_intro.rst   2008-06-13 14:24:40 UTC (rev 
5504)
+++ trunk/matplotlib/doc/users/text_intro.rst   2008-06-13 14:40:39 UTC (rev 
5505)
@@ -57,4 +57,4 @@
 
 .. plot:: figures/text_commands.py
    :scale: 75
-
+   :include-source:

Modified: trunk/matplotlib/doc/users/text_props.rst
===================================================================
--- trunk/matplotlib/doc/users/text_props.rst   2008-06-13 14:24:40 UTC (rev 
5504)
+++ trunk/matplotlib/doc/users/text_props.rst   2008-06-13 14:40:39 UTC (rev 
5505)
@@ -59,3 +59,4 @@
 
 .. plot:: figures/text_layout.py
    :scale: 75
+   :include-source:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to