Commits

Manfred Moitzi  committed c1a9bd4

docs updated

  • Participants
  • Parent commits f71b419

Comments (0)

Files changed (18)

File doc/classes/group.rst

 :class:`Group` objects --- <g>
 ==============================
 
-.. autoclass:: svgwrite.Group
+.. autoclass:: svgwrite.shapes.Group

File doc/classes/hyperlink.rst

 :class:`Hyperlink` objects --- <a>
 ==================================
 
-.. autoclass:: svgwrite.Hyperlink
+.. autoclass:: svgwrite.container.Hyperlink

File doc/classes/image.rst

 :class:`Image` objects --- <image>
 ==================================
 
-.. autoclass:: svgwrite.Image
+.. autoclass:: svgwrite.container.Image

File doc/classes/path.rst

 :class:`Path` objects --- <path>
 ================================
 
-.. autoclass:: svgwrite.Path
+.. autoclass:: svgwrite.path.Path

File doc/classes/shapes.rst

 :class:`Line` objects --- <line>
 ================================
 
-.. autoclass:: svgwrite.Line
+.. autoclass:: svgwrite.shapes.Line
 
 :class:`Rect` objects --- <rect>
 ================================
 
-.. autoclass:: svgwrite.Rect
+.. autoclass:: svgwrite.shapes.Rect
 
 :class:`Circle` objects --- <circle>
 ====================================
 
-.. autoclass:: svgwrite.Circle
+.. autoclass:: svgwrite.shapes.Circle
 
 :class:`Ellipse` objects --- <ellipse>
 ======================================
 
-.. autoclass:: svgwrite.Ellipse
+.. autoclass:: svgwrite.shapes.Ellipse
 
 :class:`Polyline` objects --- <polyline>
 ========================================
 
-.. autoclass:: svgwrite.Polyline
+.. autoclass:: svgwrite.shapes.Polyline
 
 :class:`Polygon` objects --- <polygon>
 ======================================

File doc/classes/svg.rst

 :class:`SVG` objects --- <svg>
 ==============================
 
-.. autoclass:: svgwrite.SVG
+.. autoclass:: svgwrite.container.SVG

File doc/classes/text.rst

 :class:`Text` objects
 =====================
 
-.. autoclass:: svgwrite.Text
+.. autoclass:: svgwrite.text.Text
 
 :class:`TSpan` objects
 ======================
 
-.. autoclass:: svgwrite.TSpan
+.. autoclass:: svgwrite.text.TSpan
 
 :class:`TRef` objects
 =====================
 
-.. autoclass:: svgwrite.TRef
+.. autoclass:: svgwrite.text.TRef
 
 :class:`TextPath` objects
 =========================
 
-.. autoclass:: svgwrite.TextPath
+.. autoclass:: svgwrite.text.TextPath
 
+:class:`TextArea` objects
+=========================
 
+.. autoclass:: svgwrite.text.TextArea
+

File doc/classes/use.rst

 :class:`Use` objects --- <use>
 ===============================
 
-.. autoclass:: svgwrite.Use
+.. autoclass:: svgwrite.container.Use
 
 def base_shapes_drawing(name):
     dwg = svgwrite.Drawing(filename=name, debug=DEBUG)
-    hlines = dwg.g(id='hlines', stroke='green')
+    hlines = dwg.add(dwg.g(id='hlines', stroke='green'))
     for y in range(20):
         hlines.add(dwg.line(start=(2*cm, (2+y)*cm), end=(18*cm, (2+y)*cm)))
-    vlines = dwg.g(id='vline', stroke='blue')
+    vlines = dwg.add(dwg.g(id='vline', stroke='blue'))
     for x in range(17):
         vlines.add(dwg.line(start=((2+x)*cm, 2*cm), end=((2+x)*cm, 21*cm)))
-    shapes = dwg.g(id='shapes', fill='red')
+    shapes = dwg.add(dwg.g(id='shapes', fill='red'))
     shapes.add(dwg.rect(insert=(5*cm, 5*cm), size=(45*mm, 45*mm)))
     shapes.add(dwg.circle(center=(15*cm, 8*cm), r='2.5cm', fill='blue'))
     shapes.add(dwg.ellipse(center=(10*cm, 15*cm), r=('5cm', '10mm')))
     w, h = '100%', '100%'
     dwg = svgwrite.Drawing(filename=name, size=(w, h), debug=DEBUG)
     dwg.add(dwg.rect(insert=(0,0), size=(w, h), fill='lightgray', stroke='black'))
-    g = dwg.defs.g(id='g001')
+    g = dwg.defs.add(dwg.g(id='g001'))
     unit=40
     g.add(dwg.rect((0,0), (unit, unit)))
     for y in range(10):
     # create a new drawing
     dwg = svgwrite.Drawing(name, (imgx, imgy), profile='tiny', debug=DEBUG)
 
-    # create a new <g /> element, wee will insert the snowflkae by the <use /> element
+    # create a new <g /> element, we will insert the snowflake by the <use /> element
     # here we set stroke, fill and stroke-width for all subelements
     # attention: 'stroke-width' is not a valid Python identifier, so use 'stroke_witdth'
     #   underlines '_' will be converted to dashes '-', this is true for all svg-keyword-attributs
     # if no 'id' is given ( like dwg.g(id="sflake") ), an automatic generated 'id' will be generated
     snowflake = dwg.g(stroke="blue", fill="rgb(90%,90%,100%)", stroke_width=0.25)
 
-    # don't use snowflake = dwg.group(...) this automatic adds the snowflake
-    # group to 'dwg.elements' list and not to 'dwg.defs' list!
-
     # add the <g /> element to the <defs /> element of the drawing
     dwg.defs.add(snowflake)
 
     # define a user coordinate system with viewbox()
     dwg.viewbox(0, 0, imgx, imgy)
 
-    mandelbrot_group = dwg.g(stroke_width=0, stroke='none')
+    mandelbrot_group = dwg.add(dwg.g(stroke_width=0, stroke='none'))
 
     # drawing area
     xa = -2.0
 
 def simple_text(name):
     dwg = svgwrite.Drawing(name, (200, 200), debug=DEBUG)
-    paragraph = dwg.g(font_size=14)
+    paragraph = dwg.add(dwg.g(font_size=14))
     paragraph.add(dwg.text("This is a Test!", (10,20)))
     # 'x', 'y', 'dx', 'dy' and 'rotate' has to be a <list> or a <tuple>!!!
     # 'param'[0] .. first letter, 'param'[1] .. second letter, and so on
     atext = dwg.text("A", insert=(10, 80))
 
     # text color is set by the 'fill' property and 'stroke sets the outline color.
-    atext.tspan(' Word', font_size='1.5em', fill='red')
-    atext.tspan(' is a Word!', dy=['1em'], font_size='0.7em', fill='green')
+    atext.add(dwg.tspan(' Word', font_size='1.5em', fill='red'))
+    atext.add(dwg.tspan(' is a Word!', dy=['1em'], font_size='0.7em', fill='green'))
     paragraph.add(atext)
     dwg.save()
 

File svgwrite/base.py

         if self.debug:
             self.validator.check_valid_children(self.elementname, element.elementname)
         self.elements.append(element)
+        return element
 
     def tostring(self):
         """ Get the XML representation as `string`.

File svgwrite/container.py

 
        `list` of SVG subelements
 
-    **Methods**
-
-    .. automethod:: svgwrite.Group.g(attributes)
-
     **Inherited Methods**
 
-    .. automethod:: svgwrite.Group.add(element)
+    .. automethod:: svgwrite.container.Group.add(element)
 
-    .. automethod:: svgwrite.Group.tostring()
+    .. automethod:: svgwrite.container.Group.tostring()
 
-    .. automethod:: svgwrite.Group.get_xml()
+    .. automethod:: svgwrite.container.Group.get_xml()
 
     **Supported Interfaces**
 
     """
     elementname = 'g'
 
-    def g(self, **attributes):
-        """ Create a new group with SVG *attributs* and add the new group as subelement.
-
-        :param attributes: SVG attributes as keyword arguments
-        :return: the new created group element
-
-        """
-        attributes.setdefault('factory', self) # set creator object to self
-        group = Group(**attributes)
-        self.add(group)
-        return group
-
 class Defs(Group):
     """ The <defs> element is a container element for referenced elements. For
     understandability and accessibility reasons, it is recommended that, whenever
     semantics. Documents that are rich in structure may be rendered graphically,
     as speech, or as braille, and thus promote accessibility.
 
-    **Methods**
-
-    .. automethod:: svgwrite.Symbol.g(attributes)
-
     **Inherited Attributes**
 
     .. attribute:: attribs
 
     **Inherited Methods**
 
-    .. automethod:: svgwrite.Symbol.add(element)
+    .. automethod:: svgwrite.container.Symbol.add(element)
 
-    .. automethod:: svgwrite.Symbol.tostring()
+    .. automethod:: svgwrite.container.Symbol.tostring()
 
-    .. automethod:: svgwrite.Symbol.get_xml()
+    .. automethod:: svgwrite.container.Symbol.get_xml()
 
     **Supported Interfaces**
 
     # ITransform interface is not valid for Symbol -> do not inherit from Group
     elementname = 'symbol'
 
-    def g(self, **attributes):
-        """ Create a new group with SVG *attributs* and add the new group as subelement.
-
-        :param attributes: SVG attributes as keyword arguments
-        :return: the new created group element
-
-        """
-        attributes.setdefault('factory', self) # set creator object to self
-        group = Group(**attributes)
-        self.add(group)
-        return group
-
 class SVG(Symbol):
     """ An SVG document fragment consists of any number of SVG elements contained
     within an <svg> element.
     a single SVG graphics element such as a <rect>, to a complex, deeply nested
     collection of container elements and graphics elements.
 
-    .. automethod:: svgwrite.SVG.__init__([insert=None, size=None, attribs=None, \*\*extra])
+    .. automethod:: svgwrite.container.SVG.__init__([insert=None, size=None, attribs=None, \*\*extra])
 
     **Attributes**
 
 
     **Inherited Methods**
 
-    .. automethod:: svgwrite.SVG.add(element)
+    .. automethod:: svgwrite.container.SVG.add(element)
 
-    .. automethod:: svgwrite.SVG.tostring()
+    .. automethod:: svgwrite.container.SVG.tostring()
 
-    .. automethod:: svgwrite.SVG.get_xml()
+    .. automethod:: svgwrite.container.SVG.get_xml()
 
     **Supported Interfaces**
 
         if size:
             self['width'] = size[0]
             self['height'] = size[1]
-        self.defs = Defs() # defs container
+
+        self.defs = Defs(factory=self) # defs container
         self.add(self.defs) # add defs as first element
 
 class Use(BaseElement, ITransform, IXLink):
     href-argument, if the given element has no *id* attribute it gets an
     automatic generated id.
 
-    .. automethod:: svgwrite.Use.__init__(href, [insert=None, size=None, attribs=None, \*\*extra])
+    .. automethod:: svgwrite.container.Use.__init__(href, [insert=None, size=None, attribs=None, \*\*extra])
 
     **Inherited Attributes**
 
 
     **Inherited Methods**
 
-    .. automethod:: svgwrite.Use.add(element)
+    .. automethod:: svgwrite.container.Use.add(element)
 
-    .. automethod:: svgwrite.Use.tostring()
+    .. automethod:: svgwrite.container.Use.tostring()
 
-    .. automethod:: svgwrite.Use.get_xml()
+    .. automethod:: svgwrite.container.Use.get_xml()
 
     **Supported Interfaces**
 
         return super(Use, self).get_xml()
 
 class Hyperlink(BaseElement, ITransform):
-    """ The <a> element indicate links (also known as :class:`Hyperlink`s or Web links).
+    """ The <a> element indicate links (also known as Hyperlinks or Web links).
 
     The remote resource (the destination for the link) is defined by a <IRI>
     specified by the XLink ``xlink:href`` attribute. The remote resource may be
     contained within the :class:`Hyperlink` class; add sublements as usual with
     the :meth:`add` method.
 
-    .. automethod:: svgwrite.Hyperlink.__init__(href, [target='_blank', attribs=None, \*\*extra])
+    .. automethod:: svgwrite.container.Hyperlink.__init__(href, [target='_blank', attribs=None, \*\*extra])
 
     **Inherited Attributes**
 
 
     **Inherited Methods**
 
-    .. automethod:: svgwrite.Hyperlink.add(element)
+    .. automethod:: svgwrite.container.Hyperlink.add(element)
 
-    .. automethod:: svgwrite.Hyperlink.tostring()
+    .. automethod:: svgwrite.container.Hyperlink.tostring()
 
-    .. automethod:: svgwrite.Hyperlink.get_xml()
+    .. automethod:: svgwrite.container.Hyperlink.get_xml()
 
     **Supported Interfaces**
 

File svgwrite/text.py

 class TSpan(BaseElement):
     """ Within a :class:`~svgwrite.Text` element, text and font properties
     and the current text position can be adjusted with absolute or relative
-    coordinate values by using the :class:`~svgwrite.TSpan` element.
+    coordinate values by using the :class:`~svgwrite.text.TSpan` element.
     The characters to be drawn are expressed as XML character data inside the
     <tspan> element.
 
-    :param 2-tuple insert: The *insert* parameter is the absolute insert point
-        of the text, don't use this parameter in combination with the *x* or the
-        *y* parameter.
+    .. automethod::  svgwrite.text.TSpan.__init__(text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], attribs=None, \*\*extra)
 
     **Attributes**
 
 
     **Methods**
 
-    .. automethod:: svgwrite.TSpan.__init__(text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], attribs=None, **extra)
-
-    .. automethod:: svgwrite.TSpan.tspan(text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], attribs=None, **extra)
+    .. automethod:: svgwrite.text.TSpan.__init__(text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], attribs=None, **extra)
 
     .. _TSpan-SVG-Attributes:
 
                  attribs=None, **extra):
         """
         :param string text: <tspan> content
-        :param 2-tuple insert: insert pos (x, y)
+        :param 2-tuple insert: The *insert* parameter is the absolute insert point
+                               of the text, don't use this parameter in combination
+                               with the *x* or the *y* parameter.
         :param list x: list of absolute x-axis values for characters
         :param list y: list of absolute y-axis values for characters
         :param list dx: list of relative x-axis values for characters
         if dy: self['dy'] = strlist(list(iterflatlist(dy)), ' ')
         if rotate: self['rotate'] = strlist(list(iterflatlist(rotate)), ' ')
 
-    def tspan(self, text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[],
-              attribs=None, **extra):
-        """
-        Add a <TSpan> object as subelement. Same params as :meth:`__init__`.
-
-        """
-        txt = TSpan(text, insert, x, y, dx, dy, rotate, attribs=None, **extra)
-        self.add(txt)
-        return txt
-
     def get_xml(self):
         xml = super(TSpan, self).get_xml()
         xml.text = unicode(self.text)
     referenced element, where the referencing is specified with a <tref>
     element.
 
-    .. automethod:: svgwrite.TRef.__init__(element, attribs=None, **extra)
+    .. automethod:: svgwrite.text.TRef.__init__(element, attribs=None, **extra)
 
-    .. automethod:: svgwrite.TRef.set_href(element)
+    .. automethod:: svgwrite.text.TRef.set_href(element)
 
     **SVG Attributes**
 
 
     **Methods**
 
-    .. automethod:: svgwrite.TextPath.__init__(path, text, startOffset=None, method='align', spacing='exact', attribs=None, **extra)
-
-    .. automethod:: svgwrite.TextPath.tspan(self, text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[], attribs=None, **extra)
+    .. automethod:: svgwrite.text.TextPath.__init__(path, text, startOffset=None, method='align', spacing='exact', attribs=None, **extra)
 
     **SVG Attributes**
 
             self['startOffset'] = startOffset
         self.set_href(path)
 
-    def tspan(self, text, insert=None, x=[], y=[], dx=[], dy=[], rotate=[],
-              attribs=None, **extra):
-        """
-        Add a <TSpan> object as subelement.
-
-        :param string text: <tspan> content
-        :param 2-tuple insert: insert pos (x, y)
-        :param list x: list of absolute x-axis values for characters
-        :param list y: list of absolute y-axis values for characters
-        :param list dx: list of relative x-axis values for characters
-        :param list dy: list of relative y-axis values for characters
-        :param list rotate: list of rotation-values for characters (in degrees)
-
-        """
-        txt = TSpan(text, insert, x, y, dx, dy, rotate, attribs=None, **extra)
-        self.add(txt)
-        return txt
-
     def get_xml(self):
         self.update_id() # if href is an object - 'id' - attribute may be changed!
         xml = super(TextPath, self).get_xml()
         raise NotImplementedError("add() not supported by TBreak class.")
 
 class TextArea(BaseElement, ITransform):
-    #TODO: testing for TestArea
     """
     At this time <textArea> is only available for SVG 1.2 Tiny profile.
 
 
     **Methods**
 
-    .. automethod:: svgwrite.TextArea.write(text, \*\*extra)
+    .. automethod:: svgwrite.text.TextArea.write(text, \*\*extra)
 
     **SVG Attributes**
 
         """
         Add *text* as <tspan> elements, with extra-params for the <tspan> element.
 
-        Use the '\n' character for line breaks.
+        Use the '\\\\n' character for line breaks.
         """
         if '\n' not in text:
             self.add(TSpan(text, **extra))

File tests/test_defs.py

 
     def test_add_group(self):
         defs = Defs(id='defs')
-        group = defs.g(id='group') # implicit call of add
+        group = defs.add(Group(id='group')) # implicit call of add
         self.assertEqual(defs.tostring(), '<defs id="defs"><g id="group" /></defs>')
 
-
 if __name__=='__main__':
     unittest.main()

File tests/test_drawing.py

 class TestDefs(unittest.TestCase):
     def test_simple_defs(self):
         dwg = Drawing()
-        g = dwg.defs.g(id='test')
-        inner_g = g.g(id='innerTest')
+        g = dwg.defs.add(Group(id='test'))
+        inner_g = g.add(Group(id='innerTest'))
         result = dwg.tostring()
         self.assertEqual(result, '<svg baseProfile="full" height="100%" version="1.1" '\
             'width="100%" xmlns="http://www.w3.org/2000/svg" '\

File tests/test_group.py

 
     def test_add_group(self):
         group = Group(id='group')
-        subgroup = group.g(id='subgroup') # implicit call of add
+        subgroup = group.add(Group(id='subgroup'))
         self.assertEqual(group.tostring(), '<g id="group"><g id="subgroup" /></g>')
 
 

File tests/test_symbol.py

 
     def test_add_group(self):
         symbol = Symbol(id='symbol')
-        group = symbol.g(id='group') # implicit call of add
+        group = symbol.add(Group(id='group')) # implicit call of add
         self.assertEqual(symbol.tostring(), '<symbol id="symbol"><g id="group" /></symbol>')
 
 if __name__=='__main__':

File tests/test_text.py

 
     def test_subelement_tspan(self):
         txt = TSpan('text')
-        txt.tspan('subtext')
+        txt.add(TSpan('subtext'))
         self.assertEqual(txt.tostring(), '<tspan>text<tspan>subtext</tspan></tspan>')
 
 

File tests/test_utils.py

 
 class TestAutoID(unittest.TestCase):
     def test_nextid(self):
-        getter = AutoID()
+        getter = AutoID(1)
         self.assertEqual('id1', getter.nextid())
         getter = AutoID()
         self.assertEqual('id2', getter.nextid())